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;
}
......
......@@ -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