Commit cbb7dac2 authored by 刘林's avatar 刘林

fix(jg):证打印标记功能开发

parent e086c80b
package com.yeejoin.amos.boot.module.jg.api.dto;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.biz.common.dto.BaseDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
......@@ -147,4 +148,7 @@ public class JgUseRegistrationManageDto extends BaseDto {
@ApiModelProperty("使用单位seq")
private String useUnitSeq;
@ApiModelProperty("证书是否打印标记")
private JSONObject certificatePrintTag;
}
package com.yeejoin.amos.boot.module.jg.api.entity;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
......@@ -240,4 +241,10 @@ public class JgUseRegistrationManage extends BaseEntity {
*/
@TableField("is_do_business")
private String isDoBusiness;
/**
* 证书是否打印标记
*/
@TableField("certificate_print_tag")
private JSONObject certificatePrintTag;
}
......@@ -226,7 +226,7 @@ public class JgUseRegistrationController extends BaseController {
public void exportSummaryBasicInfo(HttpServletResponse response,
@RequestParam("sequenceNbr") String sequenceNbr,
@RequestParam("category") String category) {
jgUseRegistrationServiceImpl.exportSummaryBasicInfo(Collections.singletonList(Long.valueOf(sequenceNbr)), response, category);
jgUseRegistrationServiceImpl.exportSummaryBasicInfo(Collections.singletonList(Long.valueOf(sequenceNbr)), response, category, null);
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
......
......@@ -710,7 +710,7 @@ public class JgInstallationNoticeServiceImpl extends BaseService<JgInstallationN
//获取告知单信息
byte[] templateToPdfData = WordTemplateUtils.getTemplateToPdfData(tempFileName, "installation-notification-report.ftl", map);
//获取管道和气瓶的基本信息汇总表
List<CompletableFuture<byte[]>> exportSummaryBasicInfoData = jgUseRegistrationService.getExportSummaryBasicInfoData(Collections.singletonList(Long.valueOf(sequenceNbr)), jgInstallationNotice.getEquCategoryCode(), "安装告知", Boolean.TRUE);
List<CompletableFuture<byte[]>> exportSummaryBasicInfoData = jgUseRegistrationService.getExportSummaryBasicInfoData(Collections.singletonList(Long.valueOf(sequenceNbr)), jgInstallationNotice.getEquCategoryCode(), "安装告知", Boolean.TRUE, null);
toZipFileByData(response, exportSummaryBasicInfoData, templateToPdfData, jgInstallationNotice.getApplyNo());
}else {
WordTemplateUtils.templateToPdfDownload(tempFileName, "installation-notification-report.ftl", map, response);
......
......@@ -88,7 +88,11 @@ import static com.yeejoin.amos.boot.module.jg.biz.service.impl.JgUseRegistration
*/
@Service
public class JgUseRegistrationManageServiceImpl extends BaseService<JgUseRegistrationManageDto, JgUseRegistrationManage, JgUseRegistrationManageMapper> implements IJgUseRegistrationManageService {
public static final String CERTIFICATE_NORMAL = "certificateNormalPrint";
public static final String CERTIFICATE_NESTED = "certificateNestedPrint";
public static final String USE_FLAG_NORMAL = "useFlagNormalPrint";
public static final String USE_FLAG_NESTED = "useFlagNestedPrint";
public static final String EXPORT_SUMMARY_TABLE = "exportSummaryTable";
@Autowired
RestHighLevelClient restHighLevelClient;
......@@ -582,132 +586,124 @@ public class JgUseRegistrationManageServiceImpl extends BaseService<JgUseRegistr
* @param certificateSeq 使用登记证的seq
*/
public void printCertificate(HttpServletResponse response, String printType, String certificateSeq) {
if (StringUtils.isEmpty(printType) || StringUtils.isEmpty(certificateSeq)) {
throw new BadRequest("打印失败,请联系管理员!");
}
JgUseRegistrationManage manage = this.baseMapper.selectById(certificateSeq);
String useRegistrationCode = manage.getUseRegistrationCode();
String equCategoryCode = manage.getEquCategoryCode();
switch (printType) {
case "certificateNormalPrint":// 使用登记证 普打
case "certificateNestedPrint":// 使用登记证 套打
case "useFlagNormalPrint":// 使用标志 普打
case "useFlagNestedPrint":// 使用标志 套打
this.exportUseRegistrationCertificate(manage, response, getPrintTypeCode(printType));
break;
case "exportSummaryTable":// 工业管道和气瓶 汇总表下载
List<JgUseRegistration> jgUseRegistrations = jgUseRegistrationService.getBaseMapper().selectList(new LambdaQueryWrapper<JgUseRegistration>()
.eq(JgUseRegistration::getUseRegistrationCode, useRegistrationCode)
.eq(JgUseRegistration::getStatus, "已完成"));
List<Long> useRegistrationSeqs = jgUseRegistrations.stream().map(JgUseRegistration::getSequenceNbr).collect(Collectors.toList());
jgUseRegistrationService.exportSummaryBasicInfo(useRegistrationSeqs, response, equCategoryCode);
break;
default:
break;
if (manage == null) {
throw new BadRequest("未找到对应的使用登记信息!");
}
if (EXPORT_SUMMARY_TABLE.equals(printType)) {
//打印汇总表
handleExportSummaryTable(response, manage);
} else {
exportUseRegistrationCertificate(manage, response, printType);
}
private String getPrintTypeCode(String printType) {
switch (printType) {
case "certificateNormalPrint":
return "0";
case "certificateNestedPrint":
return "1";
case "useFlagNormalPrint":
return "2";
case "useFlagNestedPrint":
return "3";
default:
return "";
this.updateById(manage);
}
private void handleExportSummaryTable(HttpServletResponse response, JgUseRegistrationManage manage) {
JSONObject tagJson = Optional.ofNullable(manage.getCertificatePrintTag()).orElse(new JSONObject());
tagJson.put(EXPORT_SUMMARY_TABLE, 2);
manage.setCertificatePrintTag(tagJson);
List<JgUseRegistration> registrations = jgUseRegistrationService.getBaseMapper().selectList(
new LambdaQueryWrapper<JgUseRegistration>()
.eq(JgUseRegistration::getUseRegistrationCode, manage.getUseRegistrationCode())
.eq(JgUseRegistration::getStatus, "已完成")
);
List<Long> seqs = registrations.stream().map(JgUseRegistration::getSequenceNbr).collect(Collectors.toList());
Set<String> projectIds = registrations.stream().map(JgUseRegistration::getProjectContraptionId).collect(Collectors.toSet());
jgUseRegistrationService.exportSummaryBasicInfo(seqs, response, manage.getEquCategoryCode(), projectIds);
}
public void exportUseRegistrationCertificate(JgUseRegistrationManage manage, HttpServletResponse response, String printType) {
Map<String, Object> exportParamsMap = new HashMap<>();
// 查询使用登记详情
List<JSONObject> deviceList = this.queryEquByCertificate(manage);
if (ValidationUtil.isEmpty(manage) || ValidationUtil.isEmpty(deviceList)) {
throw new BadRequest("使用登记证导出失败,请稍后重试!");
if (ValidationUtil.isEmpty(manage)) {
throw new BadRequest("使用登记信息为空,导出失败!");
}
// 登记机关
if (ValidationUtil.isEmpty(manage.getReceiveOrgName())) {
throw new BadRequest("使用登记证导出失败,登记机关为空!");
List<JSONObject> deviceList = this.queryEquByCertificate(manage);
if (ValidationUtil.isEmpty(deviceList)) {
throw new BadRequest("设备信息为空,导出失败!");
}
exportParamsMap.put("receiveOrgName", manage.getReceiveOrgName());
// 使用登记证编号
if (ValidationUtil.isEmpty(manage.getUseRegistrationCode())) {
throw new BadRequest("使用登记证导出失败,使用登记证编号为空!");
Map<String, Object> params = buildExportParams(manage, deviceList);
JSONObject tagJson = new JSONObject(manage.getCertificatePrintTag());
switch (printType) {
case CERTIFICATE_NORMAL://证 普打
commonService.generateCertificateReport(params, response);
tagJson.put(CERTIFICATE_NORMAL, 2);
break;
case CERTIFICATE_NESTED://证 套打
commonService.generateCertificateReportDoc(params, response);
tagJson.put(CERTIFICATE_NESTED, 2);
break;
case USE_FLAG_NORMAL://标志 普打
commonService.useFlagGenerate(this.buildUseFlagParamDto(deviceList, manage, params), response);
tagJson.put(USE_FLAG_NORMAL, 2);
break;
case USE_FLAG_NESTED://标志 套打
commonService.fightUseFlagGenerate(this.buildUseFlagParamDto(deviceList, manage, params), response);
tagJson.put(USE_FLAG_NESTED, 2);
break;
default:
throw new BadRequest("无效的打印类型!");
}
exportParamsMap.put("useRegistrationCode", manage.getUseRegistrationCode());
// 使用单位名称
if (ValidationUtil.isEmpty(manage.getUseUnitName())) {
throw new BadRequest("使用登记证导出失败,使用单位名称为空!");
manage.setCertificatePrintTag(tagJson);
}
exportParamsMap.put("useUnitName", manage.getUseUnitName());
// 监管码
if (ValidationUtil.isEmpty(deviceList.get(0))) {
throw new BadRequest("使用登记证导出失败,监管码为空!");
private Map<String, Object> buildExportParams(JgUseRegistrationManage manage, List<JSONObject> deviceList) {
Map<String, Object> map = new HashMap<>();
if (ValidationUtil.isEmpty(manage.getReceiveOrgName()) ||
ValidationUtil.isEmpty(manage.getUseRegistrationCode()) ||
ValidationUtil.isEmpty(manage.getUseUnitName())) {
throw new BadRequest("导出失败,登记机关、编号或单位名称为空!");
}
map.put("receiveOrgName", manage.getReceiveOrgName());
map.put("useRegistrationCode", manage.getUseRegistrationCode());
map.put("useUnitName", manage.getUseUnitName());
map.put("supervisoryCode", deviceList.get(0).get("SUPERVISORY_CODE"));
if ("1".equals(manage.getIsOverDesign())) {
exportParamsMap.put("overDesign", "超设计使用年限");
}
exportParamsMap.put("supervisoryCode", deviceList.get(0).get("SUPERVISORY_CODE"));
getAuditPassedDate(manage.getAuditPassDate(), exportParamsMap);
getReissueDate(manage.getReissueDate(), exportParamsMap);
exportParamsMap.put("equList", manage.getEquList());
exportParamsMap.put("equCategory", manage.getEquCategory());
exportParamsMap.put("equDefine", manage.getEquDefine());
exportParamsMap.put("manageType", manage.getManageType());
if (BusinessTypeEnum.JG_VEHICLE_GAS_APPLICATION.getName().equals(manage.getRegType())){
exportParamsMap.put("fullAddress", manage.getUseUnitAddress());
exportParamsMap.put("manageType", "");
exportParamsMap.put("equDefineCode", "23T0");
exportParamsMap.put("equCode", deviceList.stream()
.map(equ -> String.valueOf(equ.get("EQU_CODE")))
.filter(Objects::nonNull)
.collect(Collectors.joining(", ")));
exportParamsMap.put("factoryNum", deviceList.stream()
.map(equ -> String.valueOf(equ.get("FACTORY_NUM")))
map.put("overDesign", "超设计使用年限");
}
getAuditPassedDate(manage.getAuditPassDate(), map);
getReissueDate(manage.getReissueDate(), map);
map.put("equList", manage.getEquList());
map.put("equCategory", manage.getEquCategory());
map.put("equDefine", manage.getEquDefine());
map.put("manageType", manage.getManageType());
if (BusinessTypeEnum.JG_VEHICLE_GAS_APPLICATION.getName().equals(manage.getRegType())) {
map.put("fullAddress", manage.getUseUnitAddress());
map.put("manageType", "");
map.put("equDefineCode", "23T0");
map.put("equCode", joinDeviceField(deviceList, "EQU_CODE"));
map.put("factoryNum", joinDeviceField(deviceList, "FACTORY_NUM"));
map.put("useInnerCode", joinDeviceFieldDistinct(deviceList, "USE_INNER_CODE"));
} else {
map.put("fullAddress", "unit".equals(manage.getManageType()) ? manage.getUseUnitAddress() : manage.getEquUseAddress());
map.put("equCode", deviceList.get(0).get("EQU_CODE"));
map.put("factoryNum", deviceList.get(0).get("FACTORY_NUM"));
map.put("useInnerCode", deviceList.get(0).get("USE_INNER_CODE"));
}
map.put("certificateNo", manage.getCertificateNo());
map.put("applyNo", manage.getCertificateNo());
map.put("version", String.valueOf(manage.getVersion()));
map.put("carNumber", manage.getCarNumber());
map.put("equListCode", manage.getEquListCode());
return map;
}
private String joinDeviceField(List<JSONObject> devices, String field) {
return devices.stream()
.map(obj -> String.valueOf(obj.get(field)))
.filter(Objects::nonNull)
.collect(Collectors.joining(", ")));
exportParamsMap.put("useInnerCode", deviceList.stream()
.map(equ -> String.valueOf(equ.get("USE_INNER_CODE")))
.collect(Collectors.joining(", "));
}
private String joinDeviceFieldDistinct(List<JSONObject> devices, String field) {
return devices.stream()
.map(obj -> String.valueOf(obj.get(field)))
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.joining(", ")));
}else{
exportParamsMap.put("fullAddress", manage.getEquUseAddress());
exportParamsMap.put("equCode", deviceList.get(0).get("EQU_CODE"));
exportParamsMap.put("factoryNum", deviceList.get(0).get("FACTORY_NUM"));
exportParamsMap.put("useInnerCode", deviceList.get(0).get("USE_INNER_CODE"));
if ("unit".equals(manage.getManageType())) {
exportParamsMap.put("fullAddress", manage.getUseUnitAddress());
}
}
// 调整为证编号 全库唯一
exportParamsMap.put("certificateNo", manage.getCertificateNo());
// 与certificateNo一样,冗余字段防止漏调整
exportParamsMap.put("applyNo", manage.getCertificateNo());
exportParamsMap.put("version", manage.getVersion() + "");
exportParamsMap.put("carNumber", manage.getCarNumber());
exportParamsMap.put("equListCode", manage.getEquListCode());
if ("0".equals(printType)) {
// 调用生成使用登记证
commonService.generateCertificateReport(exportParamsMap, response);
} else if ("1".equals(printType)) {
// 套打
commonService.generateCertificateReportDoc(exportParamsMap, response);
} else if ("2".equals(printType)) {
// 使用标志普通打印
commonService.useFlagGenerate(this.buildUseFlagParamDto(deviceList, manage, exportParamsMap), response);
} else if ("3".equals(printType)) {
// 使用标志套打
commonService.fightUseFlagGenerate(this.buildUseFlagParamDto(deviceList, manage, exportParamsMap), response);
}
.collect(Collectors.joining(", "));
}
/**
......
......@@ -1167,7 +1167,7 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
boolean isFirstMerge = jgProjectContraption.getIsFirstMerge();
mapData.put("isFirstMerge", isFirstMerge);
// 装置表写入使用登记证编号、将装置名称写入到使用登记表
updateRegAndProjectContraption(jgUseRegistration, mapData, jgProjectContraption);
this.updateRegAndProjectContraption(jgUseRegistration, mapData, jgProjectContraption);
// 首次合并 + 特殊登记,给工程装置生成设备代码和监管码
if (isFirstMerge || "2".equals(jgUseRegistration.getRegType())) {
Map<String, Object> createCodeMap = new HashMap<>();
......@@ -2556,13 +2556,52 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
}
/**
* 获取装置下的管道信息(根据整个记录去重)
*
* @param projectContraptionList 装置 ID 列表
* @return 去重后的管道信息 JSON 数组
*/
public List<Map<String, Object>> queryPipelineList(Set<String> projectContraptionList) {
if (CollectionUtils.isEmpty(projectContraptionList)) {
return Collections.emptyList();
}
Set<String> result = new HashSet<>();
return projectContraptionList.stream()
.filter(Objects::nonNull)
.map(jgProjectContraptionService.getBaseMapper()::selectEquipList)
.filter(Objects::nonNull)
.flatMap(List::stream)
.peek(map -> map.put("productName", map.get("pipeName")))
.filter(map -> result.add(JSONObject.toJSONString(map)))
.collect(Collectors.toList());
}
public List<Map<String, Object>> getEquipInfoList(List<Long> useRegistrationSeqs, String category, Set<String> projectContraptionIdList) {
LambdaQueryWrapper<JgUseRegistrationEq> lambda = new QueryWrapper<JgUseRegistrationEq>().lambda();
lambda.in(JgUseRegistrationEq::getEquipTransferId, useRegistrationSeqs);
lambda.select(JgUseRegistrationEq::getEquId);
List<JgUseRegistrationEq> eqs = jgUseRegistrationEqService.getBaseMapper().selectList(lambda);
List<String> records = eqs.stream().map(JgUseRegistrationEq::getEquId).collect(toList());
if (!"2300".equals(category)) {
return this.queryPipelineList(projectContraptionIdList);
} else {
List<DictionarieValueModel> fillingMedium = Systemctl.dictionarieClient.dictValues("FILLING_MEDIUM").getResult();
Map<String, Object> fillingMediumMap = fillingMedium.stream().collect(Collectors.toMap(DictionarieValueModel::getDictDataKey, DictionarieValueModel::getDictDataValue));
List<Map<String, Object>> tableData = jgUseRegistrationMapper.queryForUnitVesselEquipment(records);
tableData.forEach(i -> i.put("chargingMedium", fillingMediumMap.get(i.get("chargingMedium"))));
return tableData;
}
}
/**
* 获取导出基本信息数据
* @param useRegistrationSeqs
* @param category
* @param whetherToFilterStatus 是否过滤设备状态 是:true(过滤设备状态为在用),否:false(所有的)
* @return
*/
public List<CompletableFuture<byte[]>> getExportSummaryBasicInfoData(List<Long> useRegistrationSeqs, String category, String type, Boolean whetherToFilterStatus) {
public List<CompletableFuture<byte[]>> getExportSummaryBasicInfoData(List<Long> useRegistrationSeqs, String category, String type,
Boolean whetherToFilterStatus, Set<String> projectContraptionIdList) {
List<CompletableFuture<byte[]>> futureList = new ArrayList<>();
// 总数
double total;
......@@ -2575,26 +2614,38 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
throw new BadRequest("没有查询到汇总信息!");
}
JSONArray allEquipment = new JSONArray();
// 用Set存储已添加的equCode,防止重复添加
Set<String> addedEquCodes = new HashSet<>();
registrationHistoryList.forEach(historyList -> {
JSONObject jsonObject = JSONObject.parseObject(historyList.getChangeData());
JSONArray equipmentLists = "安装告知".equals(type)
? (JSONArray) jsonObject.get("deviceList")
: (JSONArray) jsonObject.get("equipmentLists");
final String useDateValue = jsonObject.getString("useDate");
if (CollectionUtils.isNotEmpty(equipmentLists)) {
equipmentLists.stream()
.map(obj -> (JSONObject) obj)
.filter(equipmentItem -> whetherToFilterStatus || this.checkEquStatusInUse(equipmentItem.getString("record")))
.forEach(item -> {
item.put("useDate", timeToMonths(useDateValue));
if (!"安装告知".equals(type)) {
List<Map<String, Object>> equipmentList = getEquipInfoList(useRegistrationSeqs, category, projectContraptionIdList);
if (CollectionUtils.isNotEmpty(equipmentList)) {
equipmentList.forEach(map -> {
String record = (String) map.get("record");
if ((whetherToFilterStatus || this.checkEquStatusInUse(record))) {
allEquipment.add(new JSONObject(map));
}
});
}
} else {
registrationHistoryList.forEach(history -> {
JSONObject jsonObject = JSONObject.parseObject(history.getChangeData());
String useDate = jsonObject.getString("useDate");
List<Map<String, Object>> deviceList = (List<Map<String, Object>>) jsonObject.get("deviceList");
if (CollectionUtils.isNotEmpty(deviceList)) {
deviceList.forEach(map -> {
JSONObject item = new JSONObject(map);
String equCode = item.getString("equCode");
String record = item.getString("record");
if ((whetherToFilterStatus || this.checkEquStatusInUse(record)) && addedEquCodes.add(equCode)) {
item.put("useDate", timeToMonths(useDate));
allEquipment.add(item);
addedEquCodes.add(item.getString("equCode"));
}
});
}
});
}
total = allEquipment.size();
AgencyUserModel result = new AgencyUserModel();
// 暂时拿第一条的 监管部门和安全管理人员
......@@ -2661,10 +2712,10 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
* @param useRegistrationSeqs
* @param response
*/
public void exportSummaryBasicInfo(List<Long> useRegistrationSeqs, HttpServletResponse response, String category) {
public void exportSummaryBasicInfo(List<Long> useRegistrationSeqs, HttpServletResponse response, String category, Set<String> projectContraptionIdList) {
JgUseRegistration jgUseRegistration = jgUseRegistrationMapper.selectOne(new QueryWrapper<JgUseRegistration>().lambda()
.eq(JgUseRegistration::getSequenceNbr, useRegistrationSeqs.get(0)).eq(JgUseRegistration::getIsDelete, false));
List<CompletableFuture<byte[]>> futures = getExportSummaryBasicInfoData(useRegistrationSeqs, category, "", Boolean.FALSE);
List<CompletableFuture<byte[]>> futures = getExportSummaryBasicInfoData(useRegistrationSeqs, category, "", Boolean.FALSE, projectContraptionIdList);
if ("8300".equals(category) || "8200".equals(category) || "8100".equals(category)) {
// 文件名前缀
String filePrefix = "压力管道基本信息汇总表_";
......@@ -2680,7 +2731,6 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
// byte[]压缩zip
toZipFile(response, futures, filePrefix, customFileName);
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment