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