Commit 57ad5dd4 by lijingjing

对碳素原料原辅料、铝侧原料原辅料编码处理;

parent 4de59f48
package com.patzn.cloud.service.lims.hmhj.controller;
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.QualityInspectionCode;
import com.patzn.cloud.service.lims.hmhj.service.IQualityInspectionCodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* 用户质检编码基础数据 前端控制器
*
* @author meazty
* @since 2021-06-20
*/
@Api(tags = "用户质检编码基础数据")
@RestController
@RequestMapping("/v1/quality_inspection_code")
public class QualityInspectionCodeController extends ServiceController {
@Resource
private IQualityInspectionCodeService qualityInspectionCodeService;
@ApiOperation("分页列表")
@ApiImplicitParams({
@ApiImplicitParam(name = RestConstants.PAGE_PAGE, value = "请求数据的页码", required = true, paramType = "query", dataTypeClass = Integer.class),
@ApiImplicitParam(name = RestConstants.PAGE_ROWS, value = "每页条数", required = true, paramType = "query", dataTypeClass = Integer.class),
})
@PostMapping("/page")
public RestResult<Page<QualityInspectionCode>> getPage(QualityInspectionCode qualityInspectionCode) {
return success(qualityInspectionCodeService.page(getPage(), qualityInspectionCode));
}
@ApiOperation("查询 id 信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "主键", required = true, paramType = "path", dataTypeClass = Long.class),
})
@GetMapping("/{id}")
public RestResult<QualityInspectionCode> get(@PathVariable("id") Long id) {
return success(qualityInspectionCodeService.getById(id));
}
@ApiOperation("根据 id 修改信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "主键", required = true, paramType = "path", dataTypeClass = Long.class),
})
@PutMapping("/{id}")
public RestResult<Boolean> edit(@PathVariable("id") Long id, QualityInspectionCode qualityInspectionCode) {
qualityInspectionCode.setId(id);
return success(qualityInspectionCodeService.updateById(qualityInspectionCode));
}
@ApiOperation("添加")
@PostMapping("/")
public RestResult<Boolean> add(QualityInspectionCode qualityInspectionCode) {
qualityInspectionCode.setCreator(getAccount().getUserName());
return success(qualityInspectionCodeService.save(qualityInspectionCode));
}
@ApiOperation("根据 ids 删除")
@ApiImplicitParams({
@ApiImplicitParam(name = "ids", value = "主键列表", required = true, paramType = "query", allowMultiple = true, dataTypeClass = Long.class),
})
@DeleteMapping("/")
public RestResult<Boolean> delete(@RequestParam("ids") List<Long> ids) {
return success(qualityInspectionCodeService.removeByIds(ids));
}
}
......@@ -47,7 +47,7 @@ public interface EntrustSampleMapper extends BatchMapper<EntrustSample> {
@SqlParser(filter = true)
List<ReportSampleVO> selectReportSampleInfos(@Param("sampleIds") Long[] sampleIds);
String selectLastCode(@Param("queryKey") String queryKey);
String selectLastCode(@Param("column") String column, @Param("queryKey") String queryKey);
List<EntrustSampleIndexVO> selectSampleIndex(RowBounds rowBounds, @Param("vo") EntrustSampleIndexVO sampleIndexVO);
......
package com.patzn.cloud.service.lims.hmhj.mapper;
import com.patzn.cloud.commons.mapper.BatchMapper;
import com.patzn.cloud.service.hmhj.entity.QualityInspectionCode;
/**
* <p>
* 用质检编码基础数据 Mapper 接口
* </p>
*
* @author meazty
* @since 2023-04-19
*/
public interface QualityInspectionCodeMapper extends BatchMapper<QualityInspectionCode> {
public Integer selectMaxCode();
}
......@@ -28,11 +28,11 @@ public interface IEntrustSampleService extends IBaseService<EntrustSample> {
Page<EntrustSample> page(Page<EntrustSample> page, EntrustSample entrustSample);
Page<EntrustSample> pageOfReportCheck(Page<EntrustSample> page, EntrustSample entrustSample,Account account);
Page<EntrustSample> pageOfReportCheck(Page<EntrustSample> page, EntrustSample entrustSample, Account account);
Page<EntrustSample> pageOfReportIssue(Page<EntrustSample> page, EntrustSample entrustSample,Account account);
Page<EntrustSample> pageOfReportIssue(Page<EntrustSample> page, EntrustSample entrustSample, Account account);
Page<EntrustSample> pageOfReportSend(Page<EntrustSample> page, EntrustSample entrustSample,Account account);
Page<EntrustSample> pageOfReportSend(Page<EntrustSample> page, EntrustSample entrustSample, Account account);
Page<EntrustSample> pageOfQualityJudge(Page<EntrustSample> page, EntrustSample entrustSample, Account account);
......@@ -62,11 +62,11 @@ public interface IEntrustSampleService extends IBaseService<EntrustSample> {
Page<EntrustSampleVO> pageBySampleLeftHis(Page<EntrustSampleVO> page, EntrustSampleVO sampleVO);
Page<EntrustSampleVO> pageVO(Page<EntrustSampleVO> page, EntrustSampleVO entrustSample,Account account);
Page<EntrustSampleVO> pageVO(Page<EntrustSampleVO> page, EntrustSampleVO entrustSample, Account account);
Page<EntrustSampleVO> pageOfEntrust(Page<EntrustSampleVO> page, EntrustSampleVO entrustSample, Account account);
Page<EntrustSampleVO> pageVOForMake(Page<EntrustSampleVO> page, EntrustSampleVO entrustSample,Account account);
Page<EntrustSampleVO> pageVOForMake(Page<EntrustSampleVO> page, EntrustSampleVO entrustSample, Account account);
boolean submitToAcceptanceResultInput(Long[] ids, Account account);
......@@ -136,8 +136,12 @@ public interface IEntrustSampleService extends IBaseService<EntrustSample> {
String getNewCode(String queryKey, int lens);
String getNewCode(String queryKey, String column, int lens);
String getNewCode(String queryKey, int start, int lens);
String getNewCode(String queryKey, String column, int start, int lens);
EntrustSample getByContractId(Long contractId);
boolean updateAllColumnBatch(List<EntrustSample> sampleList);
......
package com.patzn.cloud.service.lims.hmhj.service;
import com.baomidou.mybatisplus.plugins.Page;
import com.patzn.cloud.commons.controller.Account;
import com.patzn.cloud.commons.service.IBaseService;
import com.patzn.cloud.service.hmhj.entity.QualityInspectionCode;
import java.util.List;
/**
* 用户质检编码基础数据 服务类
*
* @author meazty
* @since 2021-06-20
*/
public interface IQualityInspectionCodeService extends IBaseService<QualityInspectionCode> {
Page<QualityInspectionCode> page(Page<QualityInspectionCode> page, QualityInspectionCode qualityInspectionCode);
boolean removeByIds(List<Long> ids);
QualityInspectionCode getOne(QualityInspectionCode inspectionCode);
String getCode(Account account);
String getCodeAbsentCreate(Account account);
}
......@@ -44,6 +44,7 @@ import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -106,6 +107,9 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
@Resource
private IUserInfoService userInfoService;
@Resource
private RedisTemplate<String, String> redisTemplate;
@Override
public Page<EntrustSample> page(Page<EntrustSample> page, EntrustSample entrustSample) {
Wrapper wrapper = new EntityWrapper<>(entrustSample);
......@@ -1997,18 +2001,40 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
@Override
public String getNewCode(String queryKey, int lens) {
return getNewCode(queryKey, null, lens);
}
@Override
public String getNewCode(String queryKey, String column, int lens) {
column = StringUtils.isBlank(column) ? "code" : column;
String key = String.format("%s_%s_%s", column, queryKey, lens).toUpperCase();
String code = redisTemplate.opsForValue().get(key);
String startKey = "000000000000000000", defKey = queryKey + startKey.substring(0, lens - 1) + 1;
if (StringUtils.isNotBlank(code)) {
String sampleSN = code.substring(code.length() - lens);
return getNewCodeStr(key, queryKey, lens, startKey, code);
}
if (StringUtils.isBlank(queryKey)) {
redisTemplate.opsForValue().set(key, defKey);
return defKey;
}
String lastCode = baseMapper.selectLastCode(queryKey);
String lastCode = baseMapper.selectLastCode(column, queryKey);
if (StringUtils.isBlank(lastCode)) {
redisTemplate.opsForValue().set(key, defKey);
return defKey;
}
String sampleSN = lastCode.substring(lastCode.length() - lens);
return getNewCodeStr(key, queryKey, lens, startKey, lastCode);
}
private String getNewCodeStr(String redisKey, String queryKey, int lens, String startKey, String lastCode) {
try {
String sampleSN = lastCode.substring(lastCode.length() - lens);
Integer nextSN = Integer.parseInt(sampleSN) + 1;
return queryKey + startKey.substring(0, lens - nextSN.toString().length()) + nextSN;
String code = queryKey + startKey.substring(0, lens - nextSN.toString().length()) + nextSN;
redisTemplate.opsForValue().set(redisKey, code);
return code;
} catch (NumberFormatException e) {
logger.error(e.getMessage(), e.getCause());
throw new PatznException("样品编码流水号获取异常");
......@@ -2017,6 +2043,11 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
@Override
public String getNewCode(String queryKey, int start, int lens) {
return getNewCode(queryKey, null, start, lens);
}
@Override
public String getNewCode(String queryKey, String column, int start, int lens) {
String startKey = "000000000000000000";
// 长度默认1
lens = lens == 0 ? 1 : lens;
......@@ -2031,7 +2062,8 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
if (StringUtils.isBlank(queryKey)) {
return defKey;
}
String lastCode = baseMapper.selectLastCode(queryKey);
column = StringUtils.isBlank(column) ? "code" : column;
String lastCode = baseMapper.selectLastCode(column, queryKey);
if (StringUtils.isBlank(lastCode)) {
return defKey;
}
......@@ -2297,6 +2329,7 @@ public class EntrustSampleServiceImpl extends BaseServiceImpl<EntrustSampleMappe
if (StringUtils.isBlank(sample.getCode())) {
return false;
}
sample.setCode(sample.getCode().trim());
return baseMapper.isRepeatSampleCode(sample) > 0;
}
......
......@@ -35,6 +35,7 @@ import com.patzn.poibox.xwpf.XWPFTemplate;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -45,6 +46,7 @@ import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
......@@ -98,6 +100,12 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
@Resource
private IEntrustReportRelSampleService entrustReportRelSampleService;
@Resource
private IQualityInspectionCodeService qualityInspectionCodeService;
@Resource
private RedisTemplate<String, String> redisTemplate;
@Override
public Page<Entrust> page(Page<Entrust> page, Entrust entrust) {
......@@ -194,24 +202,14 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
sample.setFirstCode(StringHandleUtils.toUpper(firstCode));
}
if (StringUtils.isNotBlank(secondCode)) {
sample.setFirstCode(StringHandleUtils.toUpper(secondCode));
sample.setSecondCode(StringHandleUtils.toUpper(secondCode));
}
if (StringUtils.isNotBlank(thirdCode)) {
sample.setFirstCode(StringHandleUtils.toUpper(thirdCode));
sample.setThirdCode(StringHandleUtils.toUpper(thirdCode));
}
}
/**
* 处理槽号空格
*
* @param sample
*/
private void sampleSlotNoHandler(EntrustSample sample) {
String slotNo = null == sample.getSlotNo() ? "" : sample.getSlotNo();
sample.setSlotNo(slotNo.trim());
}
public void initSampleCode(Entrust entrust, EntrustSample sample, Map<String, LmsChemicalCategory> categoryMap) {
public void initSampleCode(Entrust entrust, EntrustSample sample, Map<String, LmsChemicalCategory> categoryMap, Map<String, String> params) {
// 如果合同编号不为空,样品编号不为空,一级编号不为空,则不进行编号生成
if (null != sample.getContractSampleId() && StringUtils.isNotBlank(sample.getCode()) && StringUtils.isNotBlank(sample.getFirstCode())) {
return;
......@@ -233,9 +231,8 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
Account account = LoginHelper.getAccount();
int codeTypeNo = 0;
List<SysOrg> orgList = sysOrgClient.getListByUserId(account.getUserId()).getData();
// 具体是哪一期
String phase = orgList.stream().anyMatch(t -> t.getName().contains("二期")) ? "Z" : "F";
String phase = StringHandleUtils.nvlBlank(params.get("period")).contains("二期") ? "Z" : "F";
// 默认样品初始编号
CodeTypeEnum codeType = null;
switch (parentCategory) {
......@@ -321,6 +318,27 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
}
}
if (Objects.equals(category, "碳素侧原料原辅料") || Objects.equals(category, "铝侧原料原辅料")) {
logger.info("✦✦✦✦ EntrustServiceImpl ✦✦✦✦ initSampleCode ✦✦✦✈ [category]: {}", category);
String abbr = params.get("abbr");
String inspectionCode = qualityInspectionCodeService.getCodeAbsentCreate(account);
String queryKey = abbr + DateUtils.dateTransfer(new Date(), "yyMMdd") + inspectionCode;
logger.info("✦✦✦✦ EntrustServiceImpl ✦✦✦✦ initSampleCode ✦✦✦✈ [abbr, inspectionCode, queryKey]: {},{},{}", abbr, inspectionCode, queryKey);
sampleCode = entrustSampleService.getNewCode(queryKey, "first_code", 3);
logger.info("✦✦✦✦ EntrustServiceImpl ✦✦✦✦ initSampleCode ✦✦✦✈ [sampleCode]: {}", sampleCode);
// 二级加密编码:abbr + 流水号 + 其他随机字符
logger.info("✦✦✦✦ EntrustServiceImpl ✦✦✦✦ initSampleCode ✦✦✦✈ secondCode");
logger.info("✦✦✦✦ EntrustServiceImpl ✦✦✦✦ initSampleCode ✦✦✦✈ [abbr]: {}", abbr);
String sn = sampleCode.substring(sampleCode.length() - 3);
logger.info("✦✦✦✦ EntrustServiceImpl ✦✦✦✦ initSampleCode ✦✦✦✈ [sn]: {}", sn);
String timestamp = (System.currentTimeMillis() + "").substring(2);
logger.info("✦✦✦✦ EntrustServiceImpl ✦✦✦✦ initSampleCode ✦✦✦✈ [timestamp]: {}", timestamp);
String randomStr = RandomUtils.getRandomStr(4);
// 保证二级加密编码不重复
secondCode = abbr + sn + timestamp + randomStr;
logger.info("✦✦✦✦ EntrustServiceImpl ✦✦✦✦ initSampleCode ✦✦✦✈ [secondCode]: {}", secondCode);
}
// 电解质散样样品编号处理
// else if (CodeTypeEnum.ELECT_BULK_SAMPLE_CODE == codeType) {
// // D+@yyMMdd&-&${et.slotNo}
......@@ -353,18 +371,25 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
// 若为三级编号,修改对应类别
if (codeType == CodeTypeEnum.SAMPLE_WWJC_CODE) {
sample.setCodeType(2);
sample.setSecondCode(secondCode.toUpperCase(Locale.ROOT));
sample.setSecondCode(secondCode.toUpperCase());
} else if (codeType == CodeTypeEnum.SAMPLE_YFL_CODE) {
sample.setCodeType(3);
sample.setSecondCode(secondCode.toUpperCase(Locale.ROOT));
sample.setThirdCode(thirdCode.toUpperCase(Locale.ROOT));
sample.setSecondCode(secondCode.toUpperCase());
sample.setThirdCode(thirdCode.toUpperCase());
}
}
}
private String getInspectNo(Account account) {
String inspectNo = userInspectionCodeService.getOne(new UserInspectionCode(account.getUserId(), "ZJ")).getNo();
return Optional.ofNullable(inspectNo).orElse("");
// 从缓存中取质检编号
String key = "INSPECT_NO_" + account.getUserId();
String inspectNo = redisTemplate.opsForValue().get(key);
if (StringUtils.isBlank(inspectNo)) {
inspectNo = userInspectionCodeService.getOne(new UserInspectionCode(account.getUserId(), "ZJ")).getNo();
inspectNo = StringHandleUtils.nvlBlank(inspectNo);
redisTemplate.opsForValue().set(key, inspectNo, 1, TimeUnit.HOURS);
}
return inspectNo;
}
// 验证样品非空字段
......@@ -379,7 +404,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
/**
* 样品编号处理
*/
private void handleSampleCode(Entrust entrust, EntrustSample sample, Map<String, LmsChemicalCategory> categoryMap) {
private void handleSampleCode(Entrust entrust, EntrustSample sample, Map<String, LmsChemicalCategory> categoryMap, Map<String, String> params) {
String
sampleCode = sample.getCode(),
secondCode = sample.getSecondCode(),
......@@ -401,7 +426,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
}
sample.setThirdCode(thirdCode);
} else {
initSampleCode(entrust, sample, categoryMap);
initSampleCode(entrust, sample, categoryMap, params);
if (StringUtils.isNotBlank(sampleCode)) {
sample.setCode(sampleCode);
sample.setFirstCode(sampleCode);
......@@ -446,13 +471,13 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
List<EntrustSampleDTO> sampleDTOList = dto.getSampleDTOList();
RestAssert.fail(CollectionUtils.isEmpty(sampleDTOList), "委托样品为空");
final Long materialId = sampleDTOList.get(0).getMaterialId();
Material material = getMaterial(materialId);
// 赋值 物资ID
if (null == entrust.getMaterialId() && null != materialId) {
if (null == entrust.getMaterialId() && Objects.nonNull(materialId)) {
entrust.setMaterialId(materialId);
}
// 状态路径为空,物料ID不为空,查询样本库
if (StringUtils.isBlank(entrust.getStatusPath()) && Objects.nonNull(entrust.getMaterialId())) {
Material material = materialService.getById(entrust.getMaterialId());
entrust.setStatusPath(material.getEntrustStatusPath());
}
......@@ -470,11 +495,17 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
entrust.setId(IdWorker.getId());
// 保存并提交委托时使用
dto.setId(entrust.getId());
// 获取用户所属期数
String period = userInfoService.getUserPeriod(account);
// ==
List<?> dataList = verifyAndPrepareSampleData(sampleDTOList, isSubmit);
String sampleName = dataList.get(0).toString();
entrust.setSampleName(sampleName);
Map<String, LmsChemicalCategory> categoryMap = (Map<String, LmsChemicalCategory>) dataList.get(1);
Map<String, String> params = new HashMap<>();
params.put("period", period);
params.put("abbr", material.getAbbr());
List<EntrustSample> saveSampleList = new ArrayList<>();
List<EntrustSampleItem> saveEntrustSampleItemList = new ArrayList<>();
......@@ -494,10 +525,9 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
// 若为进场物资,需要考虑是否为采样样品
// 若为采样样品,需要赋值采样样品编号
if (StringUtils.isBlank(sample.getCode()) || Objects.nonNull(sample.getSamplingId())) {
handleSampleCode(entrust, sample, categoryMap);
handleSampleCode(entrust, sample, categoryMap, params);
}
if (StringUtils.isNotBlank(sample.getCode())) {
sample.setCode(sample.getCode().trim().toUpperCase());
retakeSourceCodeHandle(sample);
RestAssert.fail(entrustSampleService.isRepeatSampleCode(sample), String.format("样品编号【%s】重复!", sample.getCode()));
}
......@@ -544,7 +574,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
if (!Objects.equals("原铝重取", sample.getName())) {
return;
}
String code = sample.getCode();
String code = StringHandleUtils.nvlBlank(sample.getCode());
if (StringUtils.isBlank(code)) {
return;
}
......@@ -705,15 +735,25 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
RestAssert.fail(Objects.isNull(entrustId), "委托编号为空");
// ==
List<EntrustSampleDTO> sampleList = dto.getSampleDTOList();
// == 验证 ==> 样品信息
List<?> dataList = verifyAndPrepareSampleData(sampleList, isSubmit);
final Long materialId = sampleList.get(0).getMaterialId();
Material material = getMaterial(materialId);
Entrust entrust = dto.convert(Entrust.class);
// 强制获取数据 样品名称
entrust.setSampleName(dataList.get(0).toString());
// 强制获取数据 分类列表
Map<String, LmsChemicalCategory> categoryMap = (Map<String, LmsChemicalCategory>) dataList.get(1);
// 用户所属期数
String period = userInfoService.getUserPeriod(account);
Map<String, String> params = new HashMap<>();
params.put("period", period);
params.put("abbr", material.getAbbr());
if (updateById(entrust)) {
List<EntrustSample> updateSampleList = new ArrayList<>();
List<EntrustSample> saveSampleList = new ArrayList<>();
......@@ -727,7 +767,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
if (isSubmit) {
// 样品编号为空,或者采样ID不为空
if (StringUtils.isBlank(sample.getCode()) || Objects.nonNull(sample.getSamplingId())) {
handleSampleCode(entrust, sample, categoryMap);
handleSampleCode(entrust, sample, categoryMap, params);
}
if (StringUtils.isNotBlank(sample.getCode())) {
sample.setCode(StringHandleUtils.toUpper(sample.getCode()));
......@@ -1198,6 +1238,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
RestAssert.fail(null == ids || ids.length == 0, "请选择要复制的委托记录");
List<Entrust> entrustList = getBatchIds(Arrays.asList(ids));
RestAssert.fail(CollectionUtils.isEmpty(entrustList), "请选择要复制的委托记录");
Material material = getMaterial(entrustList.get(0).getMaterialId());
// 循环遍历设置委托及其样品信息
List<Long> entrustIdList = new ArrayList<>();
List<EntrustSample> entrustSampleList = new ArrayList<>();
......@@ -1215,6 +1256,11 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
// 保存委托信息
saveEntrust(entrust);
entrustIdList.add(entrust.getId());
// 用户期数
String period = userInfoService.getUserPeriod(account);
Map<String, String> params = new HashMap<>(4);
params.put("period", period);
params.put("abbr", material.getAbbr());
// 单独查询分类信息
List<String> categoryList = sampleList.stream().map(EntrustSample::getCategory).distinct().collect(Collectors.toList());
Map<String, LmsChemicalCategory> categoryMap = lmsChemicalCategoryClient.getTopCategoryMap(categoryList).getData();
......@@ -1229,7 +1275,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
sample.setId(IdWorker.getId());
sample.setCode(null).setFirstCode(null).setSecondCode(null).setThirdCode(null);
//生成样品编号,可能存在为空的情况
initSampleCode(entrust, sample, categoryMap);
initSampleCode(entrust, sample, categoryMap, params);
// 样品编号问题,手填的样品编号不清空
if (StringUtils.isBlank(sample.getCode())) {
sample.setCode(sampleCode);
......@@ -1701,6 +1747,8 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
logger.error("进入提交委托流程......");
RestAssert.fail(null == ids || 0 == ids.length, "请选择要提交的委托!");
List<Entrust> entrustList = getBatchIds(Arrays.asList(ids));
final Long materialId = entrustList.get(0).getMaterialId();
Material material = getMaterial(materialId);
List<Long> specialIds = new ArrayList<>(),
normalIds = new ArrayList<>();
List<Long> sendUserIdList = new ArrayList<>();
......@@ -1718,6 +1766,12 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
categoryList.add(category);
}
});
// 用户所属期数
String period = userInfoService.getUserPeriod(account);
Map<String, String> params = new HashMap<>(4);
params.put("period", period);
params.put("abbr", material.getAbbr());
Map<String, LmsChemicalCategory> categoryMap = lmsChemicalCategoryClient.getTopCategoryMap(categoryList).getData();
List<EntrustSampleItem> itemList = entrustSampleItemService.list(Condition.<EntrustSampleItem>wrapper().in("entrust_sample_id", sampleIds));
RestAssert.fail(CollectionUtils.isEmpty(itemList), "提交的检测项目数据为空!");
......@@ -1731,7 +1785,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
for (EntrustSample sample : sampleList) {
sample.setSlotNo(StringHandleUtils.nvlBlank(sample.getSlotNo()));
if (StringUtils.isBlank(sample.getCode()) || Objects.nonNull(sample.getSamplingId())) {
handleSampleCode(entrust, sample, categoryMap);
handleSampleCode(entrust, sample, categoryMap, params);
}
// 额外处理样品编号空格,大写
fillCodeAfterHandle(sample);
......@@ -1783,13 +1837,21 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
return true;
}
private Material getMaterial(Long materialId) {
Material material = new Material();
if (Objects.nonNull(materialId)) {
material = materialService.getById(materialId);
}
return material;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean saveOrUpdateToSubmit(EntrustDTO entrustDTO, Account account) {
if (null == entrustDTO.getId()) {
saveEntrustDTO(entrustDTO, true, account);
saveEntrustDTO(entrustDTO, false, account);
} else {
editEntrust(entrustDTO, true, account);
editEntrust(entrustDTO, false, account);
}
return submitToNextFlow(new Long[]{entrustDTO.getId()}, account);
}
......@@ -1808,6 +1870,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
String sampleName = sampleDTO.getName(), recheckCode = sampleDTO.getRecheckCode();
RestAssert.fail(StringUtils.isBlank(sampleName), "样品名称不能为空!");
RestAssert.fail(StringUtils.isBlank(recheckCode), "样品复检编号不能为空!");
Material material = getMaterial(sampleDTO.getMaterialId());
List<EntrustSample> oldSampleList = entrustSampleService.list(Condition.create().eq("code", recheckCode));
RestAssert.fail(CollectionUtils.isEmpty(oldSampleList), "复检对应样品不存在!");
Entrust oldEntrust = getById(oldSampleList.get(0).getEntrustId());
......@@ -1822,6 +1885,11 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
.setType(1).setPeriod(oldEntrust.getPeriod()).setPriority(oldEntrust.getPriority()).setEntrustTime(new Date())
.setFlowStatus(EntrustFlowEnum.DRAFT.getName()).setStatusPath(oldEntrust.getStatusPath()).setId(IdWorker.getId());
// 用户期数
String period = userInfoService.getUserPeriod(account);
Map<String, String> params = new HashMap<>(4);
params.put("period", period);
params.put("abbr", material.getAbbr());
// 委托ID
Long entrustId = entrust.getId();
int incNum = 10;
......@@ -1838,7 +1906,7 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust>
.setSampleGrading(null).setLtime(new Date()).setLid(account.getUserId()).setCtime(new Date())
.setJudgeStatus(0).setJudgeTime(null).setJudgeCheckTime(null).setJudgeCheckerId(null).setJudger(null)
.setJudgeProgress(null).setOkJudge(null).setConclusion(null);
initSampleCode(entrust, sample, categoryMap);
initSampleCode(entrust, sample, categoryMap, params);
// 重置三级编码
sample.setThirdCode(getSampleThirdCode(sample));
sample.setOrderBy(incNum).setId(IdWorker.getId());
......
......@@ -32,7 +32,8 @@ public class MaterialServiceImpl extends BaseServiceImpl<MaterialMapper, Materia
String name = material.getName();
String code = material.getCode();
String supplier = material.getSupplier();
material.setCode(null).setName(null).setSupplier(null);
String category = material.getCategory();
material.setCode(null).setName(null).setSupplier(null).setCategory(null);
Wrapper wrapper = new EntityWrapper<>(material);
if (null != materialWrapper) {
wrapper = materialWrapper;
......@@ -46,6 +47,9 @@ public class MaterialServiceImpl extends BaseServiceImpl<MaterialMapper, Materia
if (StringUtils.isNotBlank(supplier)) {
wrapper.like("supplier", supplier);
}
if (StringUtils.isNotBlank(category)) {
wrapper.like("category", category);
}
return this.page(page, wrapper);
}
......
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.baomidou.mybatisplus.toolkit.CollectionUtils;
import com.patzn.cloud.commons.controller.Account;
import com.patzn.cloud.commons.service.impl.BaseServiceImpl;
import com.patzn.cloud.service.hmhj.entity.QualityInspectionCode;
import com.patzn.cloud.service.lims.hmhj.mapper.QualityInspectionCodeMapper;
import com.patzn.cloud.service.lims.hmhj.service.IQualityInspectionCodeService;
import org.apache.commons.lang3.StringUtils;
import org.omg.CORBA.TIMEOUT;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
/**
* 用户质检编码基础数据 服务实现类
*
* @author meazty
* @since 2021-06-20
*/
@Service
public class QualityInspectionCodeServiceImpl extends BaseServiceImpl<QualityInspectionCodeMapper, QualityInspectionCode> implements IQualityInspectionCodeService {
@Resource
private RedisTemplate<String, String> redisTemplate;
private static final String QC_KEY = "QC_CODE_KEY_";
@Override
public Page<QualityInspectionCode> page(Page<QualityInspectionCode> page, QualityInspectionCode qic) {
String username = qic.getUsername(), code = qic.getCode();
qic.setUsername(null).setCode(null);
Wrapper wrapper = new EntityWrapper<>(qic);
if (StringUtils.isNotBlank(username)) {
wrapper.like("username", username);
}
if (StringUtils.isNotBlank(code)) {
wrapper.like("code", code);
}
wrapper.orderBy("ctime");
return this.page(page, wrapper);
}
@Override
public boolean removeByIds(List<Long> ids) {
return baseMapper.deleteBatchIds(ids) > 0;
}
@Override
public QualityInspectionCode getOne(QualityInspectionCode entity) {
QualityInspectionCode data = new QualityInspectionCode();
if (Objects.isNull(entity)) {
return data;
}
try {
QualityInspectionCode inspectionCode = baseMapper.selectOne(entity);
return Optional.ofNullable(inspectionCode).orElse(data);
} catch (Exception e) {
logger.error("获取质检编码异常:", e);
return data;
}
}
@Override
public String getCode(Account account) {
if (Objects.isNull(account) || Objects.isNull(account.getUserId())) {
return null;
}
String key = QC_KEY + account.getUserId();
String code = redisTemplate.opsForValue().get(key);
if (StringUtils.isNotBlank(code)) {
return code;
}
List<Object> objects = baseMapper.selectObjs(
Condition.<QualityInspectionCode>wrapper()
.setSqlSelect("code").eq("user_id", account.getUserId())
.last("limit 1")
);
return CollectionUtils.isNotEmpty(objects) ? objects.get(0).toString() : null;
}
@Transactional(rollbackFor = Exception.class)
public String getNewCode(Account account) {
QualityInspectionCode qic = new QualityInspectionCode();
qic.setUserId(account.getUserId());
qic.setUsername(account.getUserName());
qic.setCreator(account.getUserName());
// 获取库中最大的编号
Integer maxCode = baseMapper.selectMaxCode();
if (Objects.isNull(maxCode)) {
maxCode = 1;
}
Integer newCode = maxCode + 1;
qic.setCode((newCode > 9) ? (String.valueOf(newCode)) : (String.format("0%d", newCode)));
save(qic);
return qic.getCode();
}
@Override
public String getCodeAbsentCreate(Account account) {
String code = getCode(account);
if (StringUtils.isBlank(code)) {
code = getNewCode(account);
}
// 时间1个小时刷新一次
redisTemplate.opsForValue().set(QC_KEY + account.getUserId(), code, 1, TimeUnit.HOURS);
return code;
}
}
......@@ -17,10 +17,12 @@ import com.patzn.cloud.service.lims.hmhj.common.consts.HmConst;
import com.patzn.cloud.service.lims.hmhj.service.IEntrustService;
import com.patzn.cloud.service.lims.hmhj.service.IUserInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;
......@@ -47,6 +49,9 @@ public class UserInfoServiceImpl implements IUserInfoService {
@Resource
private LmsUserGroupClient lmsUserGroupClient;
@Resource
private RedisTemplate<String, String> redisTemplate;
@Override
public List<LmsUserGroup> getGroupList(Long userId) {
if (null == userId) {
......@@ -225,17 +230,25 @@ public class UserInfoServiceImpl implements IUserInfoService {
@Override
public String getUserPeriod(Account account) {
List<SysOrg> orgList = sysOrgClient.getListByUserId(account.getUserId()).getData();
Long userId = account.getUserId();
String key = "USER_PERIOD_" + userId;
String period = redisTemplate.opsForValue().get(key);
if (StringUtils.isNotBlank(period)) {
return period;
}
List<SysOrg> orgList = sysOrgClient.getListByUserId(userId).getData();
if (CollectionUtils.isEmpty(orgList)) {
return null;
return "";
}
for (SysOrg org : orgList) {
String period = getPeriod(org);
if (null != period) {
return period;
for (SysOrg data : orgList) {
String tempPeriod = getPeriod(data);
if (StringUtils.isNotBlank(tempPeriod)) {
period = tempPeriod;
redisTemplate.opsForValue().set(key, period, 1, TimeUnit.HOURS);
break;
}
}
return null;
return period;
}
@Override
......
......@@ -473,7 +473,7 @@
</select>
<select id="selectLastCode" resultType="java.lang.String">
select max(s.code) "max_code" from entrust_sample s where s.deleted = 0 and s.code like concat(#{queryKey},'%')
select max(${column}) "max_code" from entrust_sample s where s.deleted = 0 and ${column} like concat(#{queryKey},'%')
</select>
<!-- 查询样品指标 -->
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.patzn.cloud.service.lims.hmhj.mapper.UserInspectionCodeMapper">
<mapper namespace="com.patzn.cloud.service.lims.hmhj.mapper.QualityInspectionCodeMapper">
<select id="selectMaxCode" resultType="java.lang.Integer">
SELECT MAX(T.code)::int2 FROM quality_inspection_code T WHERE T.deleted = 0
</select>
</mapper>
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