|
|
|
@ -1,7 +1,11 @@
|
|
|
|
|
package com.glxp.api.service.thrsys.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
import com.glxp.api.common.res.BaseResponse;
|
|
|
|
|
import com.glxp.api.constant.Constant;
|
|
|
|
|
import com.glxp.api.constant.ConstantStatus;
|
|
|
|
@ -9,20 +13,34 @@ import com.glxp.api.constant.ConstantType;
|
|
|
|
|
import com.glxp.api.dao.thrsys.ThrInvOrderDetailMapper;
|
|
|
|
|
import com.glxp.api.dao.thrsys.ThrInvOrderMapper;
|
|
|
|
|
import com.glxp.api.entity.basic.BasicSkProjectDetailEntity;
|
|
|
|
|
import com.glxp.api.entity.inout.IoOrderDetailBizEntity;
|
|
|
|
|
import com.glxp.api.entity.inout.IoOrderEntity;
|
|
|
|
|
import com.glxp.api.entity.system.SystemParamConfigEntity;
|
|
|
|
|
import com.glxp.api.entity.thrsys.ThrInvOrder;
|
|
|
|
|
import com.glxp.api.entity.thrsys.ThrInvOrderDetail;
|
|
|
|
|
import com.glxp.api.entity.thrsys.ThrOrderEntity;
|
|
|
|
|
import com.glxp.api.entity.thrsys.ThrSystemDetailEntity;
|
|
|
|
|
import com.glxp.api.http.ErpInvClient;
|
|
|
|
|
import com.glxp.api.req.inv.FilterInvProductRequest;
|
|
|
|
|
import com.glxp.api.req.thrsys.FilterThrInvOrderRequest;
|
|
|
|
|
import com.glxp.api.req.thrsys.GenerateOrderRequest;
|
|
|
|
|
import com.glxp.api.res.PageSimpleResponse;
|
|
|
|
|
import com.glxp.api.res.inv.ThrInvResultResponse;
|
|
|
|
|
import com.glxp.api.service.auth.CustomerService;
|
|
|
|
|
import com.glxp.api.service.basic.impl.BasicDestinyRelService;
|
|
|
|
|
import com.glxp.api.service.inout.IoOrderDetailBizService;
|
|
|
|
|
import com.glxp.api.service.inout.IoOrderService;
|
|
|
|
|
import com.glxp.api.service.system.SystemParamConfigService;
|
|
|
|
|
import com.glxp.api.service.thrsys.ThrInvOrderService;
|
|
|
|
|
import com.glxp.api.util.GennerOrderUtils;
|
|
|
|
|
import com.glxp.api.util.OrderNoTypeBean;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
@ -40,6 +58,17 @@ public class ThrInvOrderServiceImpl implements ThrInvOrderService {
|
|
|
|
|
ThrInvOrderMapper thrInvOrderMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
ThrInvOrderDetailMapper thrInvOrderDetailMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
SystemParamConfigService systemParamConfigService;
|
|
|
|
|
@Resource
|
|
|
|
|
GennerOrderUtils gennerOrderUtils;
|
|
|
|
|
@Resource
|
|
|
|
|
CustomerService customerService;
|
|
|
|
|
@Resource
|
|
|
|
|
IoOrderService ioOrderService;
|
|
|
|
|
@Resource
|
|
|
|
|
IoOrderDetailBizService ioOrderDetailBizService;
|
|
|
|
|
|
|
|
|
|
// 设置要输出的日期格式
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
|
|
|
|
|
|
@ -48,15 +77,15 @@ public class ThrInvOrderServiceImpl implements ThrInvOrderService {
|
|
|
|
|
BaseResponse<PageSimpleResponse<ThrInvResultResponse>> baseResponse = erpInvClient.getInvResult(filterInvProductRequest);
|
|
|
|
|
if (baseResponse.getCode() == 20000) {
|
|
|
|
|
List<ThrInvResultResponse> list = baseResponse.getData().getList();
|
|
|
|
|
if (CollectionUtil.isNotEmpty(list)){
|
|
|
|
|
if (CollectionUtil.isNotEmpty(list)) {
|
|
|
|
|
String billNo = generateBillNo(filterInvProductRequest);//单据号
|
|
|
|
|
//处理 返回实体 转换成 单据 和 单据明细
|
|
|
|
|
List<ThrInvOrderDetail> thrInvOrderDetails = new ArrayList<>();
|
|
|
|
|
handleExternalConvertThrInvOrderDetail(list,thrInvOrderDetails,billNo);
|
|
|
|
|
handleExternalConvertThrInvOrderDetail(list, thrInvOrderDetails, billNo);
|
|
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(thrInvOrderDetails)){
|
|
|
|
|
if (CollectionUtil.isNotEmpty(thrInvOrderDetails)) {
|
|
|
|
|
ThrInvOrder thrInvOrder = new ThrInvOrder();
|
|
|
|
|
handleExternalConvertThrInvOrder(billNo,filterInvProductRequest,thrInvOrder,list.get(0));
|
|
|
|
|
handleExternalConvertThrInvOrder(billNo, filterInvProductRequest, thrInvOrder, list.get(0));
|
|
|
|
|
|
|
|
|
|
//保存数据
|
|
|
|
|
thrInvOrderMapper.insert(thrInvOrder);
|
|
|
|
@ -66,8 +95,98 @@ public class ThrInvOrderServiceImpl implements ThrInvOrderService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void downloadInvOrder(ThrSystemDetailEntity thrSystemDetailEntity) {
|
|
|
|
|
log.info("自动抓取第三方出入库明细生成单据定时任务开始");
|
|
|
|
|
FilterInvProductRequest filterInvProductRequest = new FilterInvProductRequest();
|
|
|
|
|
filterInvProductRequest.setThirdSys(thrSystemDetailEntity.getThirdSysFk());
|
|
|
|
|
filterInvProductRequest.setThirdSysUrlValue(thrSystemDetailEntity.getValue());
|
|
|
|
|
String days = getBeginAndEndDateByDays(1);
|
|
|
|
|
|
|
|
|
|
filterInvProductRequest.setStartDate(stringToDate(days + " 00:00:00"));
|
|
|
|
|
filterInvProductRequest.setEndDate(stringToDate(days + " 23:59:59"));
|
|
|
|
|
handleExternalThrInvOrder(filterInvProductRequest);
|
|
|
|
|
log.info("自动抓取第三方出入库明细生成单据定时任务结束");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<ThrInvOrder> filterThrInvOrder(FilterThrInvOrderRequest filterThrInvOrderRequest) {
|
|
|
|
|
if (filterThrInvOrderRequest == null) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
if (filterThrInvOrderRequest.getPage() != null) {
|
|
|
|
|
int offset = (filterThrInvOrderRequest.getPage() - 1) * filterThrInvOrderRequest.getLimit();
|
|
|
|
|
PageHelper.offsetPage(offset, filterThrInvOrderRequest.getLimit());
|
|
|
|
|
}
|
|
|
|
|
List<ThrInvOrder> data = thrInvOrderMapper.filterThrInvOrder(filterThrInvOrderRequest);
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int delThrInvOrderByBillNo(String billNo) {
|
|
|
|
|
UpdateWrapper<ThrInvOrder> uw = new UpdateWrapper<>();
|
|
|
|
|
uw.eq("billNo", billNo);
|
|
|
|
|
return thrInvOrderMapper.delete(uw);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean generateOrder(GenerateOrderRequest generateOrderRequest) {
|
|
|
|
|
String billNo = generateOrderRequest.getBillNo();
|
|
|
|
|
//通过单号获取单据信息
|
|
|
|
|
QueryWrapper<ThrInvOrder> qw = new QueryWrapper<>();
|
|
|
|
|
qw.eq("billNo",billNo);
|
|
|
|
|
ThrInvOrder thrInvOrder = thrInvOrderMapper.selectOne(qw);
|
|
|
|
|
if (Objects.isNull(thrInvOrder)) return false;
|
|
|
|
|
|
|
|
|
|
//通过单号获取单据明细信息
|
|
|
|
|
QueryWrapper<ThrInvOrderDetail> qwd = new QueryWrapper<>();
|
|
|
|
|
qwd.eq("orderIdFk",billNo);
|
|
|
|
|
List<ThrInvOrderDetail> thrInvOrderDetails = thrInvOrderDetailMapper.selectList(qwd);
|
|
|
|
|
if (CollectionUtil.isNotEmpty(thrInvOrderDetails)) return false;
|
|
|
|
|
|
|
|
|
|
//新单号
|
|
|
|
|
String newBillNo = gennerOrderUtils.createScOrderNo(new OrderNoTypeBean(Constant.SCAN_ORDER, "yyyyMMdd"));
|
|
|
|
|
|
|
|
|
|
IoOrderEntity ioOrderEntity = new IoOrderEntity();
|
|
|
|
|
ioOrderEntity.setBillNo(newBillNo);
|
|
|
|
|
ioOrderEntity.setMainAction(thrInvOrder.getMainAction());
|
|
|
|
|
ioOrderEntity.setFromCorp(generateOrderRequest.getFromCorp());
|
|
|
|
|
ioOrderEntity.setInvCode(thrInvOrder.getInvCode());
|
|
|
|
|
ioOrderEntity.setDeptCode(thrInvOrder.getDeptCode());
|
|
|
|
|
|
|
|
|
|
ioOrderEntity.setFromType(ConstantStatus.FROM_THRORDER);//网页新增
|
|
|
|
|
ioOrderEntity.setStatus(ConstantStatus.ORDER_STATUS_TEMP_SAVE);//草稿
|
|
|
|
|
ioOrderEntity.setDealStatus(ConstantStatus.ORDER_DEAL_DRAFT);//草稿
|
|
|
|
|
ioOrderEntity.setCorpOrderId(billNo);//单据号
|
|
|
|
|
ioOrderEntity.setUpdateTime(new Date());
|
|
|
|
|
ioOrderEntity.setCreateTime(new Date());
|
|
|
|
|
Long userId = customerService.getUserId();
|
|
|
|
|
ioOrderEntity.setCreateUser(userId + "");
|
|
|
|
|
ioOrderEntity.setUpdateUser(userId + "");
|
|
|
|
|
ioOrderEntity.setOrderType(ConstantStatus.ORDER_TYPE_NORMAL);//正常单据处理
|
|
|
|
|
|
|
|
|
|
List<IoOrderDetailBizEntity> newOrderDetailBiz = new ArrayList<>(thrInvOrderDetails.size());
|
|
|
|
|
if (!copyOrderDetailBiz(thrInvOrderDetails,newOrderDetailBiz)){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ioOrderService.insertOrder(ioOrderEntity);
|
|
|
|
|
return ioOrderDetailBizService.batchInsertBizs(newOrderDetailBiz);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean copyOrderDetailBiz(List<ThrInvOrderDetail> thrInvOrderDetails, List<IoOrderDetailBizEntity> newOrderDetailBiz) {
|
|
|
|
|
/**
|
|
|
|
|
* 1、获取产品的集合列表信息
|
|
|
|
|
* 2、遍历封装
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生成单号 SFIO + 6位起始日期 + 6位结束日期 + 6位随机
|
|
|
|
|
*
|
|
|
|
|
* @param filterInvProductRequest
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
@ -75,16 +194,17 @@ public class ThrInvOrderServiceImpl implements ThrInvOrderService {
|
|
|
|
|
String startDate = sdf.format(filterInvProductRequest.getStartDate()).substring(2);
|
|
|
|
|
String endDate = sdf.format(filterInvProductRequest.getEndDate()).substring(2);
|
|
|
|
|
Integer random = new Random().nextInt(900000) + 100000;
|
|
|
|
|
return Constant.TRIPARTITE_INV_ORDER + startDate+endDate + random;
|
|
|
|
|
return Constant.TRIPARTITE_INV_ORDER + startDate + endDate + random;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将三方的出入库明细列表 转换为 系统的出入库单据
|
|
|
|
|
*
|
|
|
|
|
* @param filterInvProductRequest
|
|
|
|
|
* @param thrInvOrder
|
|
|
|
|
* @param thrInvResultResponse
|
|
|
|
|
*/
|
|
|
|
|
private void handleExternalConvertThrInvOrder(String billNo,FilterInvProductRequest filterInvProductRequest,ThrInvOrder thrInvOrder,ThrInvResultResponse thrInvResultResponse) {
|
|
|
|
|
private void handleExternalConvertThrInvOrder(String billNo, FilterInvProductRequest filterInvProductRequest, ThrInvOrder thrInvOrder, ThrInvResultResponse thrInvResultResponse) {
|
|
|
|
|
|
|
|
|
|
Date newDate = new Date();
|
|
|
|
|
thrInvOrder.setBillNo(billNo);//单据号
|
|
|
|
@ -93,6 +213,7 @@ public class ThrInvOrderServiceImpl implements ThrInvOrderService {
|
|
|
|
|
thrInvOrder.setEndDate(filterInvProductRequest.getEndDate());//库存结束时间
|
|
|
|
|
thrInvOrder.setMainAction(thrInvResultResponse.getMainAction());//出入库类型
|
|
|
|
|
thrInvOrder.setBillType(thrInvResultResponse.getMainAction());//第三方单据类型
|
|
|
|
|
thrInvOrder.setThirdSysFk(filterInvProductRequest.getThirdSys());//外部系统
|
|
|
|
|
thrInvOrder.setDeptCode(thrInvResultResponse.getDeptCode());//部门编号
|
|
|
|
|
thrInvOrder.setInvCode(thrInvResultResponse.getInvCode());//仓库代码
|
|
|
|
|
thrInvOrder.setSpaceCode(thrInvResultResponse.getSpaceCode());//货位编码
|
|
|
|
@ -104,36 +225,83 @@ public class ThrInvOrderServiceImpl implements ThrInvOrderService {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将三方的出入库明细列表 转换为 系统的出入库单据明细
|
|
|
|
|
*
|
|
|
|
|
* @param list
|
|
|
|
|
* @param thrInvOrderDetails
|
|
|
|
|
* @param billNo
|
|
|
|
|
*/
|
|
|
|
|
private void handleExternalConvertThrInvOrderDetail(List<ThrInvResultResponse> list, List<ThrInvOrderDetail> thrInvOrderDetails,String billNo) {
|
|
|
|
|
list.forEach( item -> {
|
|
|
|
|
String thrCode = item.getThrCode();
|
|
|
|
|
String mainAction = item.getMainAction();
|
|
|
|
|
Integer count = 0;
|
|
|
|
|
if (ConstantType.TYPE_PUT.equals(mainAction)) {
|
|
|
|
|
count = Integer.valueOf(item.getInCount());
|
|
|
|
|
}else {
|
|
|
|
|
count = Integer.valueOf(item.getOutCount());
|
|
|
|
|
}
|
|
|
|
|
//通过thrCode获取到项目组套
|
|
|
|
|
List<BasicSkProjectDetailEntity> skProjectDetailEntityList= basicDestinyRelService.filterDestinyRelListByPId(thrCode);
|
|
|
|
|
if (CollectionUtil.isNotEmpty(skProjectDetailEntityList) && count > 0 ){
|
|
|
|
|
Integer finalCount = count;
|
|
|
|
|
skProjectDetailEntityList.forEach(sk -> {
|
|
|
|
|
ThrInvOrderDetail thrInvOrderDetail = new ThrInvOrderDetail();
|
|
|
|
|
BeanUtils.copyProperties(item,thrInvOrderDetail);
|
|
|
|
|
thrInvOrderDetail.setOrderIdFk(billNo);
|
|
|
|
|
thrInvOrderDetail.setRelId(sk.getRelId());
|
|
|
|
|
Integer skCount = sk.getCount();
|
|
|
|
|
if (skCount != null && skCount > 0){
|
|
|
|
|
thrInvOrderDetail.setReCount(String.valueOf(skCount * finalCount));
|
|
|
|
|
thrInvOrderDetails.add(thrInvOrderDetail);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
private void handleExternalConvertThrInvOrderDetail(List<ThrInvResultResponse> list, List<ThrInvOrderDetail> thrInvOrderDetails, String billNo) {
|
|
|
|
|
Integer inv_set_enable = Integer.valueOf(systemParamConfigService.selectValueByParamKey("inv_set_enable"));
|
|
|
|
|
if (inv_set_enable == null || inv_set_enable == 0) {
|
|
|
|
|
list.forEach(item -> {
|
|
|
|
|
String mainAction = item.getMainAction();
|
|
|
|
|
Integer count = 0;
|
|
|
|
|
if (ConstantType.TYPE_PUT.equals(mainAction)) {
|
|
|
|
|
count = Integer.valueOf(item.getInCount());
|
|
|
|
|
} else {
|
|
|
|
|
count = Integer.valueOf(item.getOutCount());
|
|
|
|
|
}
|
|
|
|
|
ThrInvOrderDetail thrInvOrderDetail = new ThrInvOrderDetail();
|
|
|
|
|
BeanUtils.copyProperties(item, thrInvOrderDetail);
|
|
|
|
|
thrInvOrderDetail.setOrderIdFk(billNo);
|
|
|
|
|
thrInvOrderDetail.setRelId(Long.parseLong(item.getThrCode()));
|
|
|
|
|
thrInvOrderDetail.setReCount(String.valueOf(count));
|
|
|
|
|
thrInvOrderDetails.add(thrInvOrderDetail);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
list.forEach(item -> {
|
|
|
|
|
String thrCode = item.getThrCode();
|
|
|
|
|
String mainAction = item.getMainAction();
|
|
|
|
|
Integer count = 0;
|
|
|
|
|
if (ConstantType.TYPE_PUT.equals(mainAction)) {
|
|
|
|
|
count = Integer.valueOf(item.getInCount());
|
|
|
|
|
} else {
|
|
|
|
|
count = Integer.valueOf(item.getOutCount());
|
|
|
|
|
}
|
|
|
|
|
//通过thrCode获取到项目组套
|
|
|
|
|
List<BasicSkProjectDetailEntity> skProjectDetailEntityList = basicDestinyRelService.filterDestinyRelListByPId(thrCode);
|
|
|
|
|
if (CollectionUtil.isNotEmpty(skProjectDetailEntityList) && count > 0) {
|
|
|
|
|
Integer finalCount = count;
|
|
|
|
|
skProjectDetailEntityList.forEach(sk -> {
|
|
|
|
|
ThrInvOrderDetail thrInvOrderDetail = new ThrInvOrderDetail();
|
|
|
|
|
BeanUtils.copyProperties(item, thrInvOrderDetail);
|
|
|
|
|
thrInvOrderDetail.setOrderIdFk(billNo);
|
|
|
|
|
thrInvOrderDetail.setRelId(sk.getRelId());
|
|
|
|
|
Integer skCount = sk.getCount();
|
|
|
|
|
if (skCount != null && skCount > 0) {
|
|
|
|
|
thrInvOrderDetail.setReCount(String.valueOf(skCount * finalCount));
|
|
|
|
|
thrInvOrderDetails.add(thrInvOrderDetail);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取距离当前时间日期(n天)的开始时间和结束时间
|
|
|
|
|
*
|
|
|
|
|
* @param n
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static String getBeginAndEndDateByDays(int n) {
|
|
|
|
|
Date date = new Date();//取时间
|
|
|
|
|
Calendar calendar = new GregorianCalendar();
|
|
|
|
|
calendar.setTime(date);
|
|
|
|
|
calendar.add(calendar.DATE, -1);//把日期往前减少一天,若想把日期向后推一天则将负数改为正数
|
|
|
|
|
date = calendar.getTime();
|
|
|
|
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
return formatter.format(date);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Date stringToDate(String time) {
|
|
|
|
|
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
Date date = null;
|
|
|
|
|
try {
|
|
|
|
|
date = dateformat.parse(time);
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return date;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|