1.建垛规则添加查重和启用判断

2.修改excel解析工具为easyexcel,提高性能
master
x_z 3 years ago
parent 08d32e6174
commit 860e39eb15

@ -57,4 +57,15 @@ public class ConstantStatus {
public static final int FROM_UDIWMS = 9; public static final int FROM_UDIWMS = 9;
public static final int FROM_COPY = 10; //单据复制 public static final int FROM_COPY = 10; //单据复制
//建垛规则启用状态
/**
*
*/
public static final int STACK_RULES_DISABLE = 0;
/**
*
*/
public static final int STACK_RULES_ENABLE = 1;
} }

@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.glxp.udi.admin.common.enums.ResultEnum; import com.glxp.udi.admin.common.enums.ResultEnum;
import com.glxp.udi.admin.common.res.BaseResponse; import com.glxp.udi.admin.common.res.BaseResponse;
import com.glxp.udi.admin.common.util.ResultVOUtils; import com.glxp.udi.admin.common.util.ResultVOUtils;
import com.glxp.udi.admin.constant.ConstantStatus;
import com.glxp.udi.admin.entity.basic.StackRulesEntity; import com.glxp.udi.admin.entity.basic.StackRulesEntity;
import com.glxp.udi.admin.req.basic.FilterStackRulesRequest; import com.glxp.udi.admin.req.basic.FilterStackRulesRequest;
import com.glxp.udi.admin.req.inout.DeleteRequest; import com.glxp.udi.admin.req.inout.DeleteRequest;
@ -27,7 +28,7 @@ import javax.annotation.Resource;
public class StackRulesController { public class StackRulesController {
@Resource @Resource
private StackRulesService stockRulesService; private StackRulesService stackRulesService;
/** /**
* *
@ -37,7 +38,7 @@ public class StackRulesController {
*/ */
@GetMapping("/udims/stackRules/filter") @GetMapping("/udims/stackRules/filter")
public BaseResponse filterStockRules(FilterStackRulesRequest filterStockRulesRequest) { public BaseResponse filterStockRules(FilterStackRulesRequest filterStockRulesRequest) {
IPage<StackRulesEntity> page = stockRulesService.filter(filterStockRulesRequest); IPage<StackRulesEntity> page = stackRulesService.filter(filterStockRulesRequest);
PageSimpleResponse<StackRulesEntity> pageSimpleResponse = new PageSimpleResponse<>(); PageSimpleResponse<StackRulesEntity> pageSimpleResponse = new PageSimpleResponse<>();
pageSimpleResponse.setList(page.getRecords()); pageSimpleResponse.setList(page.getRecords());
pageSimpleResponse.setTotal(page.getTotal()); pageSimpleResponse.setTotal(page.getTotal());
@ -47,28 +48,51 @@ public class StackRulesController {
/** /**
* *
* *
* @param stockRulesEntity * @param stackRulesEntity
* @return * @return
*/ */
@PostMapping("/udims/stackRules/add") @PostMapping("/udims/stackRules/add")
public BaseResponse addStockRules(@RequestBody StackRulesEntity stockRulesEntity) { public BaseResponse addStockRules(@RequestBody StackRulesEntity stackRulesEntity) {
stockRulesService.addStackRules(stockRulesEntity); //判断此规则是否重复
boolean exists = stackRulesService.exists(stackRulesEntity);
if (exists) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "规则重复");
}
if (stackRulesEntity.getStatus().equals(ConstantStatus.STACK_RULES_ENABLE)) {
//判断当前用户是否已存在启用的规则
Long count = stackRulesService.countEnableRules(stackRulesEntity.getCustomerId());
if (count > 0) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "已有启用规则");
}
}
stackRulesService.addStackRules(stackRulesEntity);
return ResultVOUtils.success(); return ResultVOUtils.success();
} }
/** /**
* *
* *
* @param stockRulesEntity * @param stackRulesEntity
* @return * @return
*/ */
@PostMapping("/udims/stackRules/update") @PostMapping("/udims/stackRules/update")
public BaseResponse updateStockRules(@RequestBody StackRulesEntity stockRulesEntity, BindingResult bindingResult) { public BaseResponse updateStockRules(@RequestBody StackRulesEntity stackRulesEntity, BindingResult bindingResult) {
if (bindingResult.hasErrors()) { if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
} }
//判断此规则是否重复
stockRulesService.updateStackRules(stockRulesEntity); boolean exists = stackRulesService.exists(stackRulesEntity);
if (exists) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "规则重复");
}
if (stackRulesEntity.getStatus().equals(ConstantStatus.STACK_RULES_ENABLE)) {
//判断当前用户是否已存在启用的规则
Long count = stackRulesService.countEnableRules(stackRulesEntity.getCustomerId());
if (count > 0) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "已有启用规则");
}
}
stackRulesService.updateStackRules(stackRulesEntity);
return ResultVOUtils.success("更新成功"); return ResultVOUtils.success("更新成功");
} }
@ -83,7 +107,7 @@ public class StackRulesController {
if (null == deleteRequest || StrUtil.isBlank(deleteRequest.getId())) { if (null == deleteRequest || StrUtil.isBlank(deleteRequest.getId())) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL); return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
} }
stockRulesService.delete(deleteRequest.getId()); stackRulesService.delete(deleteRequest.getId());
return ResultVOUtils.success("删除成功"); return ResultVOUtils.success("删除成功");
} }

@ -53,7 +53,7 @@ public class UdiInfoController {
if (StrUtil.isNotBlank(productInfoFilterRequest.getUdiCode())) { if (StrUtil.isNotBlank(productInfoFilterRequest.getUdiCode())) {
UdiEntity udiEntity = FilterUdiUtils.getUdi(productInfoFilterRequest.getUdiCode()); UdiEntity udiEntity = FilterUdiUtils.getUdi(productInfoFilterRequest.getUdiCode());
if (udiEntity != null) { if (udiEntity != null) {
nameCode = udiEntity.getUdi(); nameCode = udiEntity.getNameCode();
} else { } else {
return ResultVOUtils.error(500, "无效UDI码"); return ResultVOUtils.error(500, "无效UDI码");
} }

@ -59,7 +59,7 @@ public class UdiTraceController {
if (null == udiEntity) { if (null == udiEntity) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "UDI码格式错误"); return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "UDI码格式错误");
} }
UdiInfoEntity udiInfo = udiInfoService.findByNameCode(udiEntity.getUdi(), customerId); UdiInfoEntity udiInfo = udiInfoService.findByNameCode(udiEntity.getNameCode(), customerId);
if (null == udiInfo) { if (null == udiInfo) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "此产品信息在耗材字典中不存在"); return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "此产品信息在耗材字典中不存在");
} }
@ -125,7 +125,7 @@ public class UdiTraceController {
if (udiEntity == null) { if (udiEntity == null) {
return ResultVOUtils.error(500, "UDI码格式错误"); return ResultVOUtils.error(500, "UDI码格式错误");
} }
UdiInfoEntity udiInfoEntity = udiInfoService.findByNameCode(udiEntity.getUdi(), customerId); UdiInfoEntity udiInfoEntity = udiInfoService.findByNameCode(udiEntity.getNameCode(), customerId);
if (null == udiInfoEntity) { if (null == udiInfoEntity) {
//码在耗材字典中不存在 //码在耗材字典中不存在
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "此产品信息在耗材字典中不存在"); return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "此产品信息在耗材字典中不存在");
@ -162,7 +162,7 @@ public class UdiTraceController {
UdiEntity udiEntity = FilterUdiUtils.getUdi(code); UdiEntity udiEntity = FilterUdiUtils.getUdi(code);
List<InvProductDetailEntity> invProductDetailEntities; List<InvProductDetailEntity> invProductDetailEntities;
if (udiEntity.getSerialNo() != null) { //有序列号 if (udiEntity.getSerialNo() != null) { //有序列号
UdiInfoEntity udiInfoEntity = udiInfoService.findByNameCode(udiEntity.getUdi(), warehouseQueryRequest.getCustomerId() + ""); UdiInfoEntity udiInfoEntity = udiInfoService.findByNameCode(udiEntity.getNameCode(), warehouseQueryRequest.getCustomerId() + "");
if (null == udiInfoEntity) { if (null == udiInfoEntity) {
return Collections.emptyList(); return Collections.emptyList();
} }
@ -191,7 +191,7 @@ public class UdiTraceController {
return null; return null;
} }
} else { } else {
UdiInfoEntity udiInfoEntity = udiInfoService.findByNameCode(udiEntity.getUdi(), warehouseQueryRequest.getCustomerId() + ""); UdiInfoEntity udiInfoEntity = udiInfoService.findByNameCode(udiEntity.getNameCode(), warehouseQueryRequest.getCustomerId() + "");
if (udiInfoEntity == null) { if (udiInfoEntity == null) {
return null; return null;
} }

@ -239,11 +239,11 @@ public class WareHouseController {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL); return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
} }
UdiEntity udi = FilterUdiUtils.getUdi(codesReplaceRequest.getCode()); UdiEntity udi = FilterUdiUtils.getUdi(codesReplaceRequest.getCode());
if (null == udi || StrUtil.isBlank(udi.getUdi())) { if (null == udi || StrUtil.isBlank(udi.getNameCode())) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "条码错误"); return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "条码错误");
} }
//判断udi码是否在产品信息中已维护如未维护则返回错误否则库存无法对应 //判断udi码是否在产品信息中已维护如未维护则返回错误否则库存无法对应
UdiInfoEntity udiInfoEntity = udiInfoService.findByNameCode(udi.getUdi(), authAdminService.getCurrentUserCustomerId()); UdiInfoEntity udiInfoEntity = udiInfoService.findByNameCode(udi.getNameCode(), authAdminService.getCurrentUserCustomerId());
if (null == udiInfoEntity) { if (null == udiInfoEntity) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "产品未维护"); return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "产品未维护");
} }
@ -423,7 +423,7 @@ public class WareHouseController {
warehousetempEntity.setBatchNo(udiEntity.getBatchNo()); warehousetempEntity.setBatchNo(udiEntity.getBatchNo());
warehousetempEntity.setProduceDate(udiEntity.getProduceDate()); warehousetempEntity.setProduceDate(udiEntity.getProduceDate());
warehousetempEntity.setLocStorageCode(addOrderRequest.getInvWarehouseCode()); warehousetempEntity.setLocStorageCode(addOrderRequest.getInvWarehouseCode());
warehousetempEntity.setNameCode(udiEntity.getUdi()); warehousetempEntity.setNameCode(udiEntity.getNameCode());
warehousetempEntity.setExpireDate(udiEntity.getExpireDate()); warehousetempEntity.setExpireDate(udiEntity.getExpireDate());
warehousetempEntity.setSerialNo(udiEntity.getSerialNo()); warehousetempEntity.setSerialNo(udiEntity.getSerialNo());
warehousetempEntity.setLocStorageCode(addOrderRequest.getLocStorageCode()); warehousetempEntity.setLocStorageCode(addOrderRequest.getLocStorageCode());
@ -499,7 +499,7 @@ public class WareHouseController {
return drugCodeSelectEntity; return drugCodeSelectEntity;
} }
UdiEntity originUdiEntity = FilterUdiUtils.getUdi(drugCodeSelectEntity.getCode()); UdiEntity originUdiEntity = FilterUdiUtils.getUdi(drugCodeSelectEntity.getCode());
if (!StrUtil.emptyIfNull(originUdiEntity.getUdi()).equals(StrUtil.emptyIfNull(udiEntity.getUdi()))) { if (!StrUtil.emptyIfNull(originUdiEntity.getNameCode()).equals(StrUtil.emptyIfNull(udiEntity.getNameCode()))) {
continue; continue;
} }
if (!StrUtil.emptyIfNull(originUdiEntity.getBatchNo()).toUpperCase(Locale.ROOT).equals(StrUtil.emptyIfNull(udiEntity.getBatchNo()).toUpperCase(Locale.ROOT))) { if (!StrUtil.emptyIfNull(originUdiEntity.getBatchNo()).toUpperCase(Locale.ROOT).equals(StrUtil.emptyIfNull(udiEntity.getBatchNo()).toUpperCase(Locale.ROOT))) {

@ -2,6 +2,7 @@ package com.glxp.udi.admin.controller.product;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.glxp.udi.admin.annotation.AuthRuleAnnotation; import com.glxp.udi.admin.annotation.AuthRuleAnnotation;
@ -176,13 +177,10 @@ public class StackOrderController {
if (StrUtil.isBlank(importStackOrderRequest.getFilePath())) { if (StrUtil.isBlank(importStackOrderRequest.getFilePath())) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "请上传文件!"); return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "请上传文件!");
} }
try { ThreadUtil.execAsync(() -> {
stackOrderService.importStackOrder(importStackOrderRequest.getFilePath()); stackOrderService.importStackOrder(importStackOrderRequest.getFilePath());
return ResultVOUtils.success(); });
} catch (Exception e) { return ResultVOUtils.success("导入成功");
log.error("导入建垛失败", e);
}
return ResultVOUtils.error(500, "建垛失败");
} }

@ -4,6 +4,10 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.glxp.udi.admin.util.serializer.LongJsonDeserializer;
import com.glxp.udi.admin.util.serializer.LongJsonSerializer;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
@ -33,6 +37,8 @@ public class StackRulesEntity {
* ID * ID
*/ */
@TableField(value = "customerId") @TableField(value = "customerId")
@JsonSerialize(using = LongJsonSerializer.class)
@JsonDeserialize(using = LongJsonDeserializer.class)
private Long customerId; private Long customerId;
/** /**

@ -15,9 +15,42 @@ public class StackCode {
@TableId(type = IdType.AUTO) @TableId(type = IdType.AUTO)
private Integer id; private Integer id;
/**
*
*/
private String code; private String code;
/**
*
*/
private String orderIdFk; private String orderIdFk;
/**
*
*/
private String batchNo;
/**
*
*/
private String produceDate;
/**
*
*/
private String expireDate;
/**
*
*/
private String serialNo;
/**
* DI
*/
private String nameCode;
public StackCode() { public StackCode() {
} }

@ -18,15 +18,67 @@ public class StackOrder {
@TableId(type = IdType.AUTO) @TableId(type = IdType.AUTO)
private Integer id; private Integer id;
/**
*
*/
private String orderId; private String orderId;
/**
*
*/
private String name; private String name;
/**
* 0 1
*/
private Integer exportStatus; private Integer exportStatus;
/**
*
*/
private Integer status; private Integer status;
/**
*
*/
@JsonFormat(pattern = "YYYY-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "YYYY-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime; private Date createTime;
/**
*
*/
@JsonFormat(pattern = "YYYY-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "YYYY-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime; private Date updateTime;
/**
* ID
*/
private String customerId; private String customerId;
/**
*
*/
private String batchNo;
/**
*
*/
private String produceDate;
/**
*
*/
private String expireDate;
/**
*
*/
private String serialNo;
/**
* DI
*/
private String nameCode;
} }

@ -1,59 +1,34 @@
package com.glxp.udi.admin.entity.udid; package com.glxp.udi.admin.entity.udid;
/** import lombok.Data;
* @author
* @date 2020/9/22. @Data
*/
public class UdiEntity { public class UdiEntity {
/**
*
*/
private String batchNo; private String batchNo;
/**
*
*/
private String produceDate; private String produceDate;
/**
*
*/
private String expireDate; private String expireDate;
/**
*
*/
private String serialNo; private String serialNo;
private String udi;
public String getBatchNo() {
return batchNo;
}
public void setBatchNo(String batchNo) {
this.batchNo = batchNo;
}
public String getProduceDate() {
return produceDate;
}
public void setProduceDate(String produceDate) {
this.produceDate = produceDate;
}
public String getExpireDate() {
return expireDate;
}
public void setExpireDate(String expireDate) {
this.expireDate = expireDate;
}
public String getSerialNo() {
return serialNo;
}
public void setSerialNo(String serialNo) {
this.serialNo = serialNo;
}
public String getUdi() {
return udi;
}
public void setUdi(String udi) { /**
this.udi = udi; * DI
} */
private String nameCode;
} }

@ -14,6 +14,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
* Service * Service
@ -67,6 +68,34 @@ public class StackRulesService {
stackRulesDao.insert(stackRulesEntity); stackRulesDao.insert(stackRulesEntity);
} }
/**
*
*
* @param stackRules
* @return
*/
public boolean exists(StackRulesEntity stackRules) {
QueryWrapper<StackRulesEntity> wrapper = new QueryWrapper<>();
wrapper.select("id", "name")
.eq("name", stackRules.getName())
.eq("customerId", stackRules.getCustomerId());
List<StackRulesEntity> stackRulesEntities = stackRulesDao.selectList(wrapper);
if (stackRulesEntities.size() > 0) {
if (null != stackRules.getId()) {
//更新,判断此规则是否为当前参数数据
for (StackRulesEntity stackRulesEntity : stackRulesEntities) {
if (!stackRulesEntity.getId().equals(stackRules.getId())) {
return true;
}
}
} else {
//新增,此规则已存在
return true;
}
}
return false;
}
/** /**
* *
* *
@ -99,4 +128,14 @@ public class StackRulesService {
return stackRulesEntity; return stackRulesEntity;
} }
/**
* @param customerId
* @return
*/
public Long countEnableRules(Long customerId) {
QueryWrapper<StackRulesEntity> wrapper = new QueryWrapper<>();
wrapper.eq("status", 1)
.eq("customerId", customerId);
return stackRulesDao.selectCount(wrapper);
}
} }

@ -1,5 +1,6 @@
package com.glxp.udi.admin.service.product; package com.glxp.udi.admin.service.product;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@ -9,8 +10,10 @@ import com.glxp.udi.admin.dao.product.StackCodeDao;
import com.glxp.udi.admin.dao.product.StackOrderDao; import com.glxp.udi.admin.dao.product.StackOrderDao;
import com.glxp.udi.admin.entity.product.StackCode; import com.glxp.udi.admin.entity.product.StackCode;
import com.glxp.udi.admin.entity.product.StackOrder; import com.glxp.udi.admin.entity.product.StackOrder;
import com.glxp.udi.admin.entity.udid.UdiEntity;
import com.glxp.udi.admin.req.product.AddStackCodeRequest; import com.glxp.udi.admin.req.product.AddStackCodeRequest;
import com.glxp.udi.admin.req.product.FilterStackCodeRequest; import com.glxp.udi.admin.req.product.FilterStackCodeRequest;
import com.glxp.udi.admin.util.FilterUdiUtils;
import com.glxp.udi.admin.util.IdUtil; import com.glxp.udi.admin.util.IdUtil;
import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSession;
@ -43,6 +46,8 @@ public class StackCodeService {
if (CollUtil.isNotEmpty(stackCodeEntityList)) { if (CollUtil.isNotEmpty(stackCodeEntityList)) {
StackCodeDao mapper = batchSession.getMapper(StackCodeDao.class); StackCodeDao mapper = batchSession.getMapper(StackCodeDao.class);
stackCodeEntityList.forEach(stackCodeEntity -> { stackCodeEntityList.forEach(stackCodeEntity -> {
UdiEntity udi = FilterUdiUtils.getUdi(stackCodeEntity.getCode());
BeanUtil.copyProperties(udi, stackCodeEntity);
mapper.insert(stackCodeEntity); mapper.insert(stackCodeEntity);
}); });
batchSession.commit(); batchSession.commit();
@ -96,6 +101,8 @@ public class StackCodeService {
} else { } else {
stackCode.setOrderIdFk(addStackCodeRequest.getOrderId()); stackCode.setOrderIdFk(addStackCodeRequest.getOrderId());
} }
UdiEntity udi = FilterUdiUtils.getUdi(stackCode.getCode());
BeanUtil.copyProperties(udi, stackCode);
int id = stackCodeDao.insert(stackCode); int id = stackCodeDao.insert(stackCode);
stackCode.setId(id); stackCode.setId(id);
return stackCode; return stackCode;
@ -104,7 +111,6 @@ public class StackCodeService {
/** /**
* *
* *
* @param orderId
* @param code * @param code
* @return * @return
*/ */

@ -1,10 +1,10 @@
package com.glxp.udi.admin.service.product; package com.glxp.udi.admin.service.product;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
@ -13,10 +13,13 @@ import com.glxp.udi.admin.dao.product.StackCodeDao;
import com.glxp.udi.admin.dao.product.StackOrderDao; import com.glxp.udi.admin.dao.product.StackOrderDao;
import com.glxp.udi.admin.entity.product.StackCode; import com.glxp.udi.admin.entity.product.StackCode;
import com.glxp.udi.admin.entity.product.StackOrder; import com.glxp.udi.admin.entity.product.StackOrder;
import com.glxp.udi.admin.entity.udid.UdiEntity;
import com.glxp.udi.admin.req.product.StackOrderFilterRequest; import com.glxp.udi.admin.req.product.StackOrderFilterRequest;
import com.glxp.udi.admin.req.product.StackUploadRequest; import com.glxp.udi.admin.req.product.StackUploadRequest;
import com.glxp.udi.admin.service.auth.CustomerService; import com.glxp.udi.admin.service.auth.CustomerService;
import com.glxp.udi.admin.util.FilterUdiUtils;
import com.glxp.udi.admin.util.IdUtil; import com.glxp.udi.admin.util.IdUtil;
import com.glxp.udi.admin.vo.StackCodeVo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSession;
@ -26,12 +29,13 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Slf4j @Slf4j
@ -50,6 +54,8 @@ public class StackOrderService {
@Resource @Resource
private CustomerService customerService; private CustomerService customerService;
private ExecutorService executorService = ThreadUtil.newExecutor(8);
public IPage<StackOrder> filterList(StackOrderFilterRequest stackOrderFilterRequest) { public IPage<StackOrder> filterList(StackOrderFilterRequest stackOrderFilterRequest) {
IPage<StackOrder> page = new Page<>(stackOrderFilterRequest.getPage(), stackOrderFilterRequest.getLimit()); IPage<StackOrder> page = new Page<>(stackOrderFilterRequest.getPage(), stackOrderFilterRequest.getLimit());
@ -127,40 +133,74 @@ public class StackOrderService {
* *
* @param filePath * @param filePath
*/ */
public void importStackOrder(String filePath) throws Exception { public void importStackOrder(String filePath) {
long t1 = System.currentTimeMillis(); long t1 = System.currentTimeMillis();
List<Object> objects = EasyExcel.read(filePath).sheet().doReadSync(); List<StackCodeVo> list = EasyExcel.read(filePath).head(StackCodeVo.class).sheet().doReadSync();
long t2 = System.currentTimeMillis();
ExcelReader reader = ExcelUtil.getReader(new File(filePath)); log.info("解析数据用时:{}", t2 - t1);
List<List<Object>> read = reader.read(1); if (CollUtil.isEmpty(list)) {
if (CollUtil.isEmpty(read)) {
log.error("解析垛码excel文件数据为空"); log.error("解析垛码excel文件数据为空");
throw new RuntimeException("垛码excel文件数据为空"); throw new RuntimeException("垛码excel文件数据为空");
} }
List<StackCode> stackCodes = new ArrayList<>(read.size()); //条码集合
for (List<Object> list : read) { List<String> codeList = list.stream().map(StackCodeVo::getCode).collect(Collectors.toList());
//流水号
String serialNum = String.valueOf(list.get(0)); List<StackCode> stackCodes = new ArrayList<>(list.size());
String code = String.valueOf(list.get(1));
if (StrUtil.isBlank(serialNum) || StrUtil.isBlank(code)) { //线程计数器
log.error("数据为空,数据不规范"); CountDownLatch countDownLatch = new CountDownLatch(list.size());
throw new RuntimeException("垛码数据格式错误,解析失败"); for (StackCodeVo vo : list) {
} executorService.submit(() -> {
log.info("添加任务");
if (StrUtil.isBlank(vo.getOrderId()) || StrUtil.isBlank(vo.getCode())) {
log.error("数据为空,数据不规范");
throw new RuntimeException("垛码数据格式错误,解析失败");
}
List<String> codeTemp = new ArrayList<>(codeList.size());
BeanUtil.copyProperties(codeList, codeTemp);
//判断此条码在数据库或者表中是否重复,如果有重复,则直接返回错误数据
codeTemp.remove(vo.getCode()); //先移除自身
if (codeTemp.contains(vo.getCode()) || stackCodeDao.countByCode(vo.getCode()) > 0) {
log.error("条码重复,重复的条码和流水号为:{}{}", vo.getCode(), vo.getOrderId());
throw new RuntimeException("条码重复");
}
//构造码数据
StackCode stackCode = new StackCode(vo.getOrderId(), vo.getCode());
UdiEntity udi = FilterUdiUtils.getUdi(stackCode.getCode());
BeanUtil.copyProperties(udi, stackCode);
stackCodes.add(stackCode);
StackCode stackCode = new StackCode(serialNum, code); log.info("执行结束");
stackCodes.add(stackCode); //线程执行结束,计数器 -1
countDownLatch.countDown();
});
} }
long t2 = System.currentTimeMillis(); //阻塞到线程池任务执行结束
log.info("解析构造数据用时:{}", t2 - t1); try {
countDownLatch.await();
log.info("数据封装任务执行完毕");
} catch (Exception e) {
log.error("解析封装失败失败", e);
throw new RuntimeException("解析封装数据异常");
}
long t3 = System.currentTimeMillis();
log.info("构造数据用时:{}", t3 - t2);
Map<String, List<StackCode>> stacks = stackCodes.stream().collect(Collectors.groupingBy(StackCode::getOrderIdFk)); Map<String, List<StackCode>> stacks = stackCodes.stream().collect(Collectors.groupingBy(StackCode::getOrderIdFk));
//根据每一个流水号,创建单据,生成条码 //根据每一个流水号,创建单据,生成条码
String customerId = String.valueOf(customerService.getCustomerId()); String customerId = String.valueOf(customerService.getCustomerId());
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, TransactionIsolationLevel.READ_COMMITTED);
StackCodeDao mapper = sqlSession.getMapper(StackCodeDao.class); StackCodeDao mapper = sqlSession.getMapper(StackCodeDao.class);
for (String serialNum : stacks.keySet()) { for (String serialNum : stacks.keySet()) {
StackOrder stackOrder = new StackOrder(); StackOrder stackOrder = new StackOrder();
@ -175,13 +215,6 @@ public class StackOrderService {
List<StackCode> saveDataList = new CopyOnWriteArrayList<>(data); List<StackCode> saveDataList = new CopyOnWriteArrayList<>(data);
saveDataList.parallelStream().forEach(stackCode -> { saveDataList.parallelStream().forEach(stackCode -> {
stackCode.setOrderIdFk(stackId); stackCode.setOrderIdFk(stackId);
//检查此码是否已经被添加过
long count = stackCodeDao.countByCode(stackCode.getCode());
if (count > 0) {
log.error("重复条码");
throw new RuntimeException("重复条码");
}
mapper.insert(stackCode); mapper.insert(stackCode);
}); });
@ -190,11 +223,12 @@ public class StackOrderService {
sqlSession.close(); sqlSession.close();
long t3 = System.currentTimeMillis(); long t4 = System.currentTimeMillis();
log.info("插入数据用时:{}", t3 - t2); log.info("插入数据用时:{}", t4 - t3);
log.info("全程用时:{}", t3 - t1); log.info("全程用时:{}", t4 - t1);
//导入成功,删除数据文件 //导入成功,删除数据文件
FileUtil.del(filePath); FileUtil.del(filePath);
} }
} }

@ -63,7 +63,7 @@ public class BasicUpdateProductService {
if (productInfoFilterRequest.getNameCode() != null) { if (productInfoFilterRequest.getNameCode() != null) {
UdiEntity udiEntity = FilterUdiUtils.getUdi(productInfoFilterRequest.getNameCode()); UdiEntity udiEntity = FilterUdiUtils.getUdi(productInfoFilterRequest.getNameCode());
if (udiEntity != null) { if (udiEntity != null) {
nameCode = udiEntity.getUdi(); nameCode = udiEntity.getNameCode();
} else { } else {
nameCode = productInfoFilterRequest.getNameCode(); nameCode = productInfoFilterRequest.getNameCode();
} }

@ -148,7 +148,7 @@ public class FilterUdiUtils {
serialNo = data.substring(18); serialNo = data.substring(18);
} }
udiEntity = new UdiEntity(); udiEntity = new UdiEntity();
udiEntity.setUdi(udi); udiEntity.setNameCode(udi);
udiEntity.setBatchNo(batchNo); udiEntity.setBatchNo(batchNo);
udiEntity.setExpireDate(expireDate); udiEntity.setExpireDate(expireDate);
udiEntity.setProduceDate(produceDate); udiEntity.setProduceDate(produceDate);
@ -188,7 +188,7 @@ public class FilterUdiUtils {
udiEntity.setBatchNo(batchNo); udiEntity.setBatchNo(batchNo);
udiEntity.setExpireDate(expireDate); udiEntity.setExpireDate(expireDate);
udiEntity.setProduceDate(produceDate); udiEntity.setProduceDate(produceDate);
udiEntity.setUdi(nameCode); udiEntity.setNameCode(nameCode);
udiEntity.setSerialNo(serialNo); udiEntity.setSerialNo(serialNo);
return udiEntity; return udiEntity;
@ -218,7 +218,7 @@ public class FilterUdiUtils {
udiEntity.setBatchNo(batchNo); udiEntity.setBatchNo(batchNo);
udiEntity.setExpireDate(expireDate); udiEntity.setExpireDate(expireDate);
udiEntity.setProduceDate(produceDate); udiEntity.setProduceDate(produceDate);
udiEntity.setUdi(udi); udiEntity.setNameCode(udi);
udiEntity.setSerialNo(serialNo); udiEntity.setSerialNo(serialNo);
return udiEntity; return udiEntity;
} }
@ -257,14 +257,14 @@ public class FilterUdiUtils {
data.setProduceDate(udiEntity.getProduceDate()); data.setProduceDate(udiEntity.getProduceDate());
data.setExpireDate(udiEntity.getExpireDate()); data.setExpireDate(udiEntity.getExpireDate());
data.setSerialNo(udiEntity.getSerialNo()); data.setSerialNo(udiEntity.getSerialNo());
data.setUdi(udiEntity.getUdi()); data.setUdi(udiEntity.getNameCode());
} }
return data; return data;
} }
public static String transGlxpStr(String code) { public static String transGlxpStr(String code) {
UdiEntity udiEntity = getUdi(code); UdiEntity udiEntity = getUdi(code);
String udiCode = "#" + udiEntity.getUdi() + "#" + udiEntity.getProduceDate() + "#" + udiEntity.getExpireDate() + String udiCode = "#" + udiEntity.getNameCode() + "#" + udiEntity.getProduceDate() + "#" + udiEntity.getExpireDate() +
"#" + udiEntity.getBatchNo() + "#" + udiEntity.getSerialNo() + "#" + "#"; "#" + udiEntity.getBatchNo() + "#" + udiEntity.getSerialNo() + "#" + "#";
return udiCode; return udiCode;
} }
@ -276,7 +276,7 @@ public class FilterUdiUtils {
} }
public static String transGlxpNoSerStr(UdiEntity warehouseEntity) { public static String transGlxpNoSerStr(UdiEntity warehouseEntity) {
String udiCode = "#" + warehouseEntity.getUdi() + "#" + warehouseEntity.getProduceDate() + "#" + warehouseEntity.getExpireDate() + String udiCode = "#" + warehouseEntity.getNameCode() + "#" + warehouseEntity.getProduceDate() + "#" + warehouseEntity.getExpireDate() +
"#" + warehouseEntity.getBatchNo() + "#" + "#" + "#"; "#" + warehouseEntity.getBatchNo() + "#" + "#" + "#";
return udiCode; return udiCode;
} }

@ -1,5 +1,6 @@
package com.glxp.udi.admin.util; package com.glxp.udi.admin.util;
import cn.hutool.core.util.StrUtil;
import com.glxp.udi.admin.entity.basic.StackRulesEntity; import com.glxp.udi.admin.entity.basic.StackRulesEntity;
import com.glxp.udi.admin.service.basic.StackRulesService; import com.glxp.udi.admin.service.basic.StackRulesService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -24,12 +25,16 @@ public class IdUtil {
*/ */
public synchronized String getStackId(String customerId) { public synchronized String getStackId(String customerId) {
StackRulesEntity stackRulesEntity = stackRulesService.getEnableStockRule(customerId); StackRulesEntity stackRulesEntity = stackRulesService.getEnableStockRule(customerId);
StringBuffer stackId = new StringBuffer(); StringBuilder stackId = new StringBuilder("DH");
//垛号固定标识 //垛号固定标识
stackId.append("DH") if (StrUtil.isNotBlank(stackRulesEntity.getPrefix())) {
.append(stackRulesEntity.getPrefix()) stackId.append(stackRulesEntity.getPrefix());
//拼接起始数 }
.append(stackRulesEntity.getStartNum()); //拼接起始数
if (StrUtil.isBlank(stackRulesEntity.getStartNum())) {
stackId.append(stackRulesEntity.getStartNum());
}
//查找该客户上一个垛号 //查找该客户上一个垛号
String key = "DH" + customerId; String key = "DH" + customerId;
int serialNum = 0; //顺序号 int serialNum = 0; //顺序号

@ -1,5 +1,6 @@
package com.glxp.udi.admin.vo; package com.glxp.udi.admin.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data; import lombok.Data;
/** /**
@ -11,11 +12,13 @@ public class StackCodeVo {
/** /**
* *
*/ */
@ExcelProperty("垛号")
private String orderId; private String orderId;
/** /**
* *
*/ */
@ExcelProperty("条码")
private String code; private String code;
} }

Loading…
Cancel
Save