|
|
@ -1,7 +1,11 @@
|
|
|
|
package com.glxp.udi.admin.service.product;
|
|
|
|
package com.glxp.udi.admin.service.product;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
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.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;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
@ -11,7 +15,9 @@ 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.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.util.IdUtil;
|
|
|
|
import com.glxp.udi.admin.util.IdUtil;
|
|
|
|
|
|
|
|
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;
|
|
|
|
import org.apache.ibatis.session.SqlSessionFactory;
|
|
|
|
import org.apache.ibatis.session.SqlSessionFactory;
|
|
|
@ -20,9 +26,15 @@ 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.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.concurrent.CopyOnWriteArrayList;
|
|
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public class StackOrderService {
|
|
|
|
public class StackOrderService {
|
|
|
@ -35,6 +47,8 @@ public class StackOrderService {
|
|
|
|
private StackCodeDao stackCodeDao;
|
|
|
|
private StackCodeDao stackCodeDao;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private SqlSessionFactory sqlSessionFactory;
|
|
|
|
private SqlSessionFactory sqlSessionFactory;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private CustomerService customerService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IPage<StackOrder> filterList(StackOrderFilterRequest stackOrderFilterRequest) {
|
|
|
|
public IPage<StackOrder> filterList(StackOrderFilterRequest stackOrderFilterRequest) {
|
|
|
@ -107,4 +121,80 @@ public class StackOrderService {
|
|
|
|
Long codeNum = stackCodeDao.countByOrderId(orderId);
|
|
|
|
Long codeNum = stackCodeDao.countByOrderId(orderId);
|
|
|
|
return codeNum;
|
|
|
|
return codeNum;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 读取excel文件,建垛
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param filePath
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public void importStackOrder(String filePath) throws Exception {
|
|
|
|
|
|
|
|
long t1 = System.currentTimeMillis();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Object> objects = EasyExcel.read(filePath).sheet().doReadSync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ExcelReader reader = ExcelUtil.getReader(new File(filePath));
|
|
|
|
|
|
|
|
List<List<Object>> read = reader.read(1);
|
|
|
|
|
|
|
|
if (CollUtil.isEmpty(read)) {
|
|
|
|
|
|
|
|
log.error("解析垛码excel文件数据为空");
|
|
|
|
|
|
|
|
throw new RuntimeException("垛码excel文件数据为空");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<StackCode> stackCodes = new ArrayList<>(read.size());
|
|
|
|
|
|
|
|
for (List<Object> list : read) {
|
|
|
|
|
|
|
|
//流水号
|
|
|
|
|
|
|
|
String serialNum = String.valueOf(list.get(0));
|
|
|
|
|
|
|
|
String code = String.valueOf(list.get(1));
|
|
|
|
|
|
|
|
if (StrUtil.isBlank(serialNum) || StrUtil.isBlank(code)) {
|
|
|
|
|
|
|
|
log.error("数据为空,数据不规范");
|
|
|
|
|
|
|
|
throw new RuntimeException("垛码数据格式错误,解析失败");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StackCode stackCode = new StackCode(serialNum, code);
|
|
|
|
|
|
|
|
stackCodes.add(stackCode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long t2 = System.currentTimeMillis();
|
|
|
|
|
|
|
|
log.info("解析构造数据用时:{}", t2 - t1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, List<StackCode>> stacks = stackCodes.stream().collect(Collectors.groupingBy(StackCode::getOrderIdFk));
|
|
|
|
|
|
|
|
//根据每一个流水号,创建单据,生成条码
|
|
|
|
|
|
|
|
String customerId = String.valueOf(customerService.getCustomerId());
|
|
|
|
|
|
|
|
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
|
|
|
|
|
|
|
StackCodeDao mapper = sqlSession.getMapper(StackCodeDao.class);
|
|
|
|
|
|
|
|
for (String serialNum : stacks.keySet()) {
|
|
|
|
|
|
|
|
StackOrder stackOrder = new StackOrder();
|
|
|
|
|
|
|
|
String stackId = idUtil.getStackId(customerId);
|
|
|
|
|
|
|
|
stackOrder.setOrderId(stackId);
|
|
|
|
|
|
|
|
stackOrder.setCreateTime(new Date());
|
|
|
|
|
|
|
|
stackOrder.setExportStatus(0);
|
|
|
|
|
|
|
|
stackOrder.setCustomerId(customerId);
|
|
|
|
|
|
|
|
//插入垛数据
|
|
|
|
|
|
|
|
stackOrderDao.insert(stackOrder);
|
|
|
|
|
|
|
|
List<StackCode> data = stacks.get(serialNum);
|
|
|
|
|
|
|
|
List<StackCode> saveDataList = new CopyOnWriteArrayList<>(data);
|
|
|
|
|
|
|
|
saveDataList.parallelStream().forEach(stackCode -> {
|
|
|
|
|
|
|
|
stackCode.setOrderIdFk(stackId);
|
|
|
|
|
|
|
|
//检查此码是否已经被添加过
|
|
|
|
|
|
|
|
long count = stackCodeDao.countByCode(stackCode.getCode());
|
|
|
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
|
|
|
log.error("重复条码");
|
|
|
|
|
|
|
|
throw new RuntimeException("重复条码");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapper.insert(stackCode);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sqlSession.commit();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sqlSession.close();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long t3 = System.currentTimeMillis();
|
|
|
|
|
|
|
|
log.info("插入数据用时:{}", t3 - t2);
|
|
|
|
|
|
|
|
log.info("全程用时:{}", t3 - t1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//导入成功,删除数据文件
|
|
|
|
|
|
|
|
FileUtil.del(filePath);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|