feat: 企标新增-自动生成标准编号
This commit is contained in:
@@ -95,4 +95,13 @@ public class FieldCommon {
|
||||
// SELECTIONS
|
||||
public static final String SELECTIONS = "selections";
|
||||
|
||||
// 企业标准代号(数据库对应字段)
|
||||
public static final String ENTERPRISE_STANDARD_CODE = "standard_code";
|
||||
|
||||
// 企业名称代号(数据库对应字段)
|
||||
public static final String ENTERPRISE_NAME_CODE= "name_code";
|
||||
|
||||
// 标准类别代号(数据库对应字段)
|
||||
public static final String STANDARD_CATEGORY_CODE = "category_code";
|
||||
|
||||
}
|
||||
|
||||
+14
-5
@@ -17,8 +17,8 @@ import com.jero.modules.laws.common.mapper.LawsCommonMapper;
|
||||
import com.jero.modules.laws.common.service.ILawsCommonService;
|
||||
import com.jero.modules.laws.common.vo.ManyStandardSelectionBox;
|
||||
import com.jero.modules.laws.common.vo.ManyStandardSelectionBoxVO;
|
||||
import com.jero.modules.laws.enterprise.util.EnterpriseStandardUtil;
|
||||
import com.jero.modules.laws.standard.entity.LawsNodeRelation;
|
||||
import com.jero.modules.laws.standard.entity.LawsStandardFile;
|
||||
import com.jero.modules.laws.standard.service.ILawsNodeRelationService;
|
||||
import com.jero.modules.laws.standard.service.ILawsReplacedStandardService;
|
||||
import com.jero.modules.laws.standard.service.ILawsStandardFileService;
|
||||
@@ -50,6 +50,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
@@ -93,6 +94,8 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
||||
private ILawsReplacedStandardService lawsReplacedStandardService;
|
||||
@Autowired
|
||||
private ILawsStandardFileService lawsStandardFileService;
|
||||
@Resource
|
||||
private EnterpriseStandardUtil esUtil;
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
@@ -437,6 +440,15 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
||||
@Override
|
||||
@Transactional
|
||||
public String commonAdd(Map<String, Object> parameterMap) {
|
||||
// 获取操作模块
|
||||
String module = (String) parameterMap.get(FieldCommon.MODULE);
|
||||
|
||||
// 企标需要自动拼装标准号
|
||||
if (module.equals(TableNameEnum.ENTERPRISE_STANDARDS.getValue())) {
|
||||
String standardNumber = esUtil.generateStandardNumber(parameterMap);
|
||||
parameterMap.put(FieldCommon.STANDARD_NUMBER, standardNumber);
|
||||
}
|
||||
|
||||
// 法规编号不能为空
|
||||
String standardNumber = (String) parameterMap.get(FieldCommon.STANDARD_NUMBER);
|
||||
if (StringUtils.isBlank(standardNumber)) {
|
||||
@@ -462,9 +474,6 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
||||
// 处理新增和编辑时的代替标准、引用标准
|
||||
processReplaced(parameterMap, standardNumber);
|
||||
|
||||
// 获取操作模块
|
||||
String module = (String) parameterMap.get(FieldCommon.MODULE);
|
||||
|
||||
// 获取要操作的表名
|
||||
String tableName = TableNameEnum.getTableName(module);
|
||||
// 获取全部字段
|
||||
@@ -936,7 +945,7 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
||||
|
||||
// 准备ZIP
|
||||
// 获取编码后的文件名
|
||||
String encodedZipName = URLEncoder.encode(fileName, "UTF-8");
|
||||
String encodedZipName = URLEncoder.encode(fileName + ".zip", "UTF-8");
|
||||
response.setContentType("application/zip");
|
||||
response.setHeader("Content-Disposition", "attachment; filename=" + encodedZipName);
|
||||
response.setHeader("Content-Transfer-Encoding", "binary");
|
||||
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
package com.jero.modules.laws.enterprise.util;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jero.common.system.api.ISysBaseAPI;
|
||||
import com.jero.common.system.vo.DictModel;
|
||||
import com.jero.modules.laws.common.constant.FieldCommon;
|
||||
import com.jero.modules.laws.standard.entity.LawsEnterpriseStandard;
|
||||
import com.jero.modules.laws.standard.service.ILawsEnterpriseStandardService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author: Mzaxd
|
||||
* @Date: 2023/9/22 14:05
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class EnterpriseStandardUtil {
|
||||
|
||||
@Resource
|
||||
private ISysBaseAPI sysBaseAPI;
|
||||
|
||||
@Resource
|
||||
private ILawsEnterpriseStandardService enterpriseStandardService;
|
||||
|
||||
/**
|
||||
* 生成新序列号
|
||||
* @param esCodeDictValue
|
||||
* @param esNameCodeDictValue
|
||||
* @param categoryCodeDictValue
|
||||
* @return
|
||||
*/
|
||||
public String generateNewSequenceNumber(String esCodeDictValue, String esNameCodeDictValue, String categoryCodeDictValue) {
|
||||
String sequenceNumber = "0001";
|
||||
// 根据 标准代号/名称代号/标准类别 的相关性生成顺序号
|
||||
LambdaQueryWrapper<LawsEnterpriseStandard> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(LawsEnterpriseStandard::getStandardCode, esCodeDictValue);
|
||||
lambdaQueryWrapper.eq(LawsEnterpriseStandard::getNameCode, esNameCodeDictValue);
|
||||
lambdaQueryWrapper.eq(LawsEnterpriseStandard::getCategoryCode, categoryCodeDictValue);
|
||||
lambdaQueryWrapper.eq(LawsEnterpriseStandard::getDelFlag, 0);
|
||||
List<LawsEnterpriseStandard> esList = enterpriseStandardService.list(lambdaQueryWrapper);
|
||||
|
||||
List<String> dbSequenceNumberList = esList.stream().map(LawsEnterpriseStandard::getStandardNumber)
|
||||
.map(EnterpriseStandardUtil::getSequenceNoFromStandardNo).collect(Collectors.toList());
|
||||
|
||||
// 获取最大的序列号
|
||||
Optional<String> maxSequence = dbSequenceNumberList.stream().max(Comparator.naturalOrder());
|
||||
if (maxSequence.isPresent()) {
|
||||
int maxNumber = Integer.parseInt(maxSequence.get());
|
||||
int newNumber = maxNumber + 1;
|
||||
sequenceNumber = String.format("%04d", newNumber);
|
||||
}
|
||||
return sequenceNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成企标编号
|
||||
* @param parameterMap
|
||||
* @return
|
||||
*/
|
||||
public synchronized String generateStandardNumber(Map<String, Object> parameterMap) {
|
||||
// 标准类别
|
||||
String esCodeDictValue = (String) parameterMap.get(FieldCommon.ENTERPRISE_STANDARD_CODE);
|
||||
String esNameCodeDictValue = (String) parameterMap.get(FieldCommon.ENTERPRISE_NAME_CODE);
|
||||
String categoryCodeDictValue = (String) parameterMap.get(FieldCommon.STANDARD_CATEGORY_CODE);
|
||||
|
||||
// 根据 标准代号/名称代号/标准类别 的相关性生成顺序号
|
||||
String sequenceNumber = this.generateNewSequenceNumber(esCodeDictValue, esNameCodeDictValue, categoryCodeDictValue);
|
||||
|
||||
String esCode = this.transEsCode(esCodeDictValue);
|
||||
String esNameCode = this.transEsNameCode(esNameCodeDictValue);
|
||||
String categoryCode = this.transCategoryCode(categoryCodeDictValue);
|
||||
|
||||
String yearNumber = (String) parameterMap.get(FieldCommon.YEAR_NUMBER);
|
||||
|
||||
// 最后生成的企标编号
|
||||
String standardNumber = esCode + "/" + esNameCode + " " + categoryCode + sequenceNumber + "-" + yearNumber;
|
||||
log.info("生成企标标准号:{}", standardNumber);
|
||||
return standardNumber;
|
||||
}
|
||||
|
||||
private String transEsCode(String esCode){
|
||||
if (StringUtils.isNotBlank(esCode)) {
|
||||
List<DictModel> esCodeDictModelList = sysBaseAPI.getDictItems("enterprise_standard_code");
|
||||
List<DictModel> collect = esCodeDictModelList.stream().filter(e -> esCode.equals(e.getValue())).collect(Collectors.toList());
|
||||
if (!collect.isEmpty()) {
|
||||
return collect.get(0).getText();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private String transEsNameCode(String esNameCode){
|
||||
if (StringUtils.isNotBlank(esNameCode)) {
|
||||
List<DictModel> esCodeDictModelList = sysBaseAPI.getDictItems("enterprise_name_code");
|
||||
List<DictModel> collect = esCodeDictModelList.stream().filter(e -> esNameCode.equals(e.getValue())).collect(Collectors.toList());
|
||||
if (!collect.isEmpty()) {
|
||||
return collect.get(0).getText();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private String transCategoryCode(String categoryCode){
|
||||
if (StringUtils.isNotBlank(categoryCode)) {
|
||||
List<DictModel> esCodeDictModelList = sysBaseAPI.getDictItems("standard_category_code");
|
||||
List<DictModel> collect = esCodeDictModelList.stream().filter(e -> categoryCode.equals(e.getValue())).collect(Collectors.toList());
|
||||
if (!collect.isEmpty()) {
|
||||
return collect.get(0).getText();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取序列号
|
||||
* @param standardNo
|
||||
* @return
|
||||
*/
|
||||
public static String getSequenceNoFromStandardNo(String standardNo) {
|
||||
if (standardNo == null) {
|
||||
return null; // 或者可以抛出异常,根据你的需求
|
||||
}
|
||||
|
||||
int dashIndex = standardNo.lastIndexOf('-');
|
||||
if (dashIndex < 4) {
|
||||
return null; // 如果没有找到'-',或者'-'前面的字符少于4个
|
||||
}
|
||||
|
||||
return standardNo.substring(dashIndex - 4, dashIndex);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user