Commit bb7753c7 by lijingjing

修改进场物资编码问题;

parent 62ee1f91
......@@ -2,22 +2,20 @@ package com.patzn.cloud.service.lims.hmhj.controller;
import com.baomidou.kisso.annotation.Action;
import com.baomidou.kisso.annotation.Login;
import com.patzn.cloud.service.hmhj.entity.CodeRule;
import com.patzn.cloud.service.lims.base.dto.CodeTypeDTO;
import com.patzn.cloud.service.lims.base.enums.CodeTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.plugins.Page;
import com.patzn.cloud.commons.api.RestConstants;
import com.patzn.cloud.commons.api.RestResult;
import com.patzn.cloud.commons.controller.ServiceController;
import com.patzn.cloud.service.hmhj.entity.CodeRule;
import com.patzn.cloud.service.lims.base.dto.CodeTypeDTO;
import com.patzn.cloud.service.lims.base.enums.CodeTypeEnum;
import com.patzn.cloud.service.lims.hmhj.service.ICodeRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
......@@ -44,6 +42,7 @@ public class CodeRuleController extends ServiceController {
})
@PostMapping("/page")
public RestResult<Page<CodeRule>> getPage(CodeRule codeRule) {
codeRule.setRecessive(0);
return success(codeRuleService.page(getPage(), codeRule));
}
......
package com.patzn.cloud.service.lims.hmhj.mapper;
import com.patzn.cloud.commons.mapper.BatchMapper;
import com.patzn.cloud.service.hmhj.entity.Identifier;
/**
* <p>
* Mapper 接口
* </p>
*
* @author meazty
* @since 2021-10-09
*/
public interface IdentifierMapper extends BatchMapper<Identifier> {
}
......@@ -23,4 +23,6 @@ public interface ICodeRuleService extends IBaseService<CodeRule> {
String getCodeKey(CodeTypeDTO dto);
String getKey(Integer codeType, String codeName, BaseEntity entity);
String getKey(String prefix, String rule, BaseEntity entity);
}
......@@ -130,4 +130,5 @@ public interface IEntrustSampleService extends IBaseService<EntrustSample> {
Page<EntrustSampleIndexVO> getPageSampleIndex(Page<EntrustSampleIndexVO> page, EntrustSampleIndexVO sampleIndexVO);
void exportSampleIndex(Long entrustId, Account account, HttpServletResponse response);
}
package com.patzn.cloud.service.lims.hmhj.service;
import com.baomidou.mybatisplus.plugins.Page;
import com.patzn.cloud.commons.service.IBaseService;
import com.patzn.cloud.service.hmhj.entity.Identifier;
import java.util.List;
/**
* 服务类
*
* @author meazty
* @since 2021-10-09
*/
public interface IIdentifierService extends IBaseService<Identifier> {
Page<Identifier> page(Page<Identifier> page, Identifier identifier);
boolean removeByIds(List<Long> ids);
String getNextSN(String type);
}
package com.patzn.cloud.service.lims.hmhj.service.impl;
import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.patzn.cloud.commons.api.RestAssert;
import com.patzn.cloud.commons.constant.CommonConstants;
import com.patzn.cloud.commons.service.impl.BaseServiceImpl;
import com.patzn.cloud.commons.toolkit.CodeKeyUtils;
import com.patzn.cloud.commons.toolkit.FreemarkerUtils;
import com.patzn.cloud.commons.toolkit.JacksonUtils;
......@@ -12,18 +16,14 @@ import com.patzn.cloud.service.CodeRuleHelper;
import com.patzn.cloud.service.hmhj.entity.CodeRule;
import com.patzn.cloud.service.lims.base.dto.CodeTypeDTO;
import com.patzn.cloud.service.lims.base.entity.LmsBaseDict;
import com.patzn.cloud.service.lims.base.entity.LmsCodeRule;
import com.patzn.cloud.service.lims.common.StringHandleUtils;
import com.patzn.cloud.service.lims.hmhj.mapper.CodeRuleMapper;
import com.patzn.cloud.service.lims.hmhj.service.ICodeRuleRecordService;
import com.patzn.cloud.service.lims.hmhj.service.ICodeRuleService;
import com.patzn.cloud.commons.service.impl.BaseServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
......@@ -71,6 +71,10 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul
}
CodeRule codeRule = super.getOne(Condition.create().eq("type", codeType).last("LIMIT 1"));
return getCodeKey(codeRule, codeName, entity);
}
private String getCodeKey(CodeRule codeRule, String codeName, BaseEntity entity) {
if (null == codeRule) {
RestAssert.fail(codeName + "不存在请配置规则");
}
......@@ -114,9 +118,9 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul
LmsBaseDict baseDict = new LmsBaseDict();
baseDict.setType(dictArr[0]);
baseDict.setName( FreemarkerUtils.process(dictArr[1], model));
LmsBaseDict dict = lmsBaseDictClient.getDictByNameType(baseDict).serviceData();
if (null!=dict){
baseDict.setName(FreemarkerUtils.process(dictArr[1], model));
LmsBaseDict dict = lmsBaseDictClient.getDictByNameType(baseDict).serviceData();
if (null != dict) {
key.append(dict.getCode());
}
}
......@@ -165,4 +169,13 @@ public class CodeRuleServiceImpl extends BaseServiceImpl<CodeRuleMapper, CodeRul
}
return next;
}
@Override
public String getKey(String prefix, String rule, BaseEntity entity) {
RestAssert.fail(StringUtils.isBlank(rule), "配置的规则为空");
RestAssert.fail(StringUtils.isBlank(prefix), "配置的规则前缀为空");
CodeRule codeRule = super.getOne(Condition.create().eq("pre", prefix).eq("rule", rule).last("LIMIT 1"));
RestAssert.fail(null == codeRule, "隐性编号规则不存在");
return getCodeKey(codeRule, "隐性规则" + prefix, entity);
}
}
......@@ -111,9 +111,6 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
private OssClient ossClient;
@Autowired
private IIdentifierService identifierService;
@Autowired
private IMaterialService materialService;
......@@ -345,7 +342,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
type = HmConst.SECOND_PERIOD.equals(period) ? "A" : "B";
}
type = type + (abbr.length() > 2 ? abbr : abbr + "0");
String code = identifierService.getNextSN(type.toUpperCase());
String code = codeRuleService.getKey(type.toUpperCase(), "SN&@yyMMdd", sample);
return code;
}
......@@ -1595,4 +1592,5 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
public Page<EntrustVO> getPageReportProduct(Page<EntrustVO> page, EntrustVO entrust) {
return page.setRecords(baseMapper.selectVOList(page, entrust));
}
}
package com.patzn.cloud.service.lims.hmhj.service.impl;
import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.patzn.cloud.commons.api.RestAssert;
import com.patzn.cloud.commons.constant.CommonConstants;
import com.patzn.cloud.commons.exception.PatznException;
import com.patzn.cloud.commons.service.impl.BaseServiceImpl;
import com.patzn.cloud.commons.toolkit.FreemarkerUtils;
import com.patzn.cloud.service.hmhj.entity.Identifier;
import com.patzn.cloud.service.lims.common.StringHandleUtils;
import com.patzn.cloud.service.lims.hmhj.mapper.IdentifierMapper;
import com.patzn.cloud.service.lims.hmhj.service.IIdentifierService;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 服务实现类
*
* @author meazty
* @since 2021-10-09
*/
@Service
public class IdentifierServiceImpl extends BaseServiceImpl<IdentifierMapper, Identifier> implements IIdentifierService {
@Override
public Page<Identifier> page(Page<Identifier> page, Identifier identifier) {
Wrapper wrapper = new EntityWrapper<>(identifier);
return this.page(page, wrapper);
}
@Override
public boolean removeByIds(List<Long> ids) {
return baseMapper.deleteBatchIds(ids) > 0;
}
@Transactional(rollbackFor = Exception.class)
@Override
public String getNextSN(String type) {
if (StringUtils.isBlank(type)) {
throw new PatznException("编号类型不能为空");
}
Identifier identifier = super.getOne(Condition.create().eq("type", type).last("LIMIT 1"));
if (null == identifier) {
throw new PatznException("请配置编号规则");
}
StringBuilder key = new StringBuilder();
// 前缀规则
if (null != identifier.getPrefix()) {
key.append(identifier.getPrefix());
}
String[] rules = identifier.getRule().split("&");
Map<String, Object> model = new HashMap<>(2);
for (String rule : rules) {
// 日期规则
if (rule.contains("@")) {
if ("@YY".equalsIgnoreCase(rule)) {
key.append(new DateTime().toString("YYYY").substring(2));
} else {
key.append(new DateTime().toString(rule.substring(1)));
}
} else if (rule.contains("%")) {
String myRules = rule.replace("%", "").replace("{", "").replace("}", "");
String[] dictArr = myRules.split("\\.");
if (null != dictArr[1]) {
key.append(StringHandleUtils.getFieldValueByFieldName(dictArr[1], model.get("et")));
}
}
// 属性规则
else if (rule.contains("$")) {
try {
key.append(FreemarkerUtils.process(rule, model));
} catch (Exception e) {
RestAssert.fail("编号生成异常,请联系管理员");
}
}
// SN 序列号
else if ("SN".equals(rule)) {
key.append(CommonConstants.SN);
}
// 原样输出
else {
key.append(rule);
}
}
// 更新SN,限定长度最高9位
String sn = "";
StringBuilder sb = new StringBuilder("0");
int snInt = null == identifier.getSn() ? 0 : identifier.getSn(),
lens = null == identifier.getLength() ? 1 : identifier.getLength();
while (sb.length() < lens) {
sb.append("0");
}
String defZero = sb.toString();
sn = defZero.substring(0, defZero.length() - Integer.toString(snInt).length());
snInt += 1;
if (Integer.toString(snInt).length() > lens) {
identifier.setLength(++lens);
}
identifier.setSn(snInt);
updateById(identifier);
return key.toString().replaceAll(CommonConstants.SN, sn);
}
}
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