|
@@ -2,6 +2,8 @@ package com.jsh.erp.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.jsh.erp.constants.BusinessConstants;
|
|
|
import com.jsh.erp.constants.ExceptionConstants;
|
|
@@ -10,10 +12,13 @@ import com.jsh.erp.datasource.mappers.DepotHeadMapper;
|
|
|
import com.jsh.erp.datasource.mappers.DepotHeadMapperEx;
|
|
|
import com.jsh.erp.datasource.mappers.DepotItemMapperEx;
|
|
|
import com.jsh.erp.datasource.pda.dto.PDADepotHeadDTO;
|
|
|
+import com.jsh.erp.datasource.pda.dto.PDADepotMaterialDto;
|
|
|
import com.jsh.erp.datasource.pda.vo.PDADepotHeadVO;
|
|
|
import com.jsh.erp.datasource.vo.*;
|
|
|
import com.jsh.erp.exception.BusinessRunTimeException;
|
|
|
import com.jsh.erp.exception.JshException;
|
|
|
+import com.jsh.erp.query.LambdaQueryWrapperX;
|
|
|
+import com.jsh.erp.query.QueryWrapperX;
|
|
|
import com.jsh.erp.service.*;
|
|
|
import com.jsh.erp.util.QRCodeGenerator;
|
|
|
import com.jsh.erp.utils.ExcelUtils;
|
|
@@ -83,6 +88,10 @@ public class DepotHeadServiceImpl extends ServiceImpl<DepotHeadMapper, DepotHead
|
|
|
private LogService logService;
|
|
|
@Resource
|
|
|
private QRCodeGenerator qrCodeGenerator;
|
|
|
+ @Resource
|
|
|
+ private MaterialService materialService;
|
|
|
+ @Resource
|
|
|
+ private MaterialExtendService materialExtendService;
|
|
|
|
|
|
/**
|
|
|
* PDA查询订单
|
|
@@ -392,6 +401,8 @@ public class DepotHeadServiceImpl extends ServiceImpl<DepotHeadMapper, DepotHead
|
|
|
DepotHead depotHead = JSONObject.parseObject(obj.toJSONString(), DepotHead.class);
|
|
|
depotHead.setCreateTime(new Timestamp(System.currentTimeMillis()));
|
|
|
depotHead.setStatus(BusinessConstants.BILLS_STATUS_UN_AUDIT);
|
|
|
+ User user = userService.getCurrentUser();
|
|
|
+ depotHead.setTenantId(user.getId());
|
|
|
int result=0;
|
|
|
try{
|
|
|
result=depotHeadMapper.insert(depotHead);
|
|
@@ -1131,8 +1142,6 @@ public class DepotHeadServiceImpl extends ServiceImpl<DepotHeadMapper, DepotHead
|
|
|
}
|
|
|
}
|
|
|
//生成订单二维码
|
|
|
- //String qrCodeUrl = qrCodeGenerator.generateQRCodeImage(depotHead.getNumber());
|
|
|
- depotHead.setQrcodeUrl(null);
|
|
|
JSONArray rowArr = JSONArray.parseArray(rows);
|
|
|
//商品数量
|
|
|
int operNumber = 0;
|
|
@@ -1838,4 +1847,150 @@ public class DepotHeadServiceImpl extends ServiceImpl<DepotHeadMapper, DepotHead
|
|
|
return depotHeadMapper.getDepotLastByMaterialId(mid);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * pda订单提交
|
|
|
+ *
|
|
|
+ * @param pdaDepotHeadDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
|
|
+ public boolean pdaOrderSubmit(PDADepotHeadDTO pdaDepotHeadDTO) throws Exception {
|
|
|
+ //根据单据号获取单据信息
|
|
|
+ DepotHead depotHead = depotHeadMapper.selectOne(new LambdaQueryWrapperX<DepotHead>().eq(DepotHead::getId, pdaDepotHeadDTO.getId()));
|
|
|
+ //根据单据id获取单据子表信息
|
|
|
+ List<DepotItem> depotItems = depotItemService.getListByHeaderId(depotHead.getId());
|
|
|
+ //设置单据主表信息
|
|
|
+ depotHead.setId(null);
|
|
|
+ String number = sequenceService.buildOnlyNumber();
|
|
|
+ //设置单号
|
|
|
+ if ("采购订单".equals(depotHead.getSubType())){
|
|
|
+ depotHead.setSubType("采购");
|
|
|
+ depotHead.setType("入库");
|
|
|
+ depotHead.setDefaultNumber("CGRK" + number) ;
|
|
|
+ depotHead.setNumber("CGRK" + number);
|
|
|
+ }else if ("销售订单".equals(depotHead.getSubType())){
|
|
|
+ depotHead.setSubType("销售");
|
|
|
+ depotHead.setType("出库");
|
|
|
+ depotHead.setDefaultNumber("XSCK" + number) ;
|
|
|
+ depotHead.setNumber("XSCK" + number);
|
|
|
+ }
|
|
|
+ //校验单号是否重复
|
|
|
+ if(checkIsBillNumberExist(0L, depotHead.getNumber())>0) {
|
|
|
+ throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_BILL_NUMBER_EXIST_CODE,
|
|
|
+ String.format(ExceptionConstants.DEPOT_HEAD_BILL_NUMBER_EXIST_MSG));
|
|
|
+ }
|
|
|
+ //校验是否同时录入关联请购单号和关联订单号
|
|
|
+ if(StringUtil.isNotEmpty(depotHead.getLinkNumber()) && StringUtil.isNotEmpty(depotHead.getLinkApply())) {
|
|
|
+ throw new BusinessRunTimeException(ExceptionConstants.DEPOT_ITEM_EXIST_REPEAT_NO_FAILED_CODE,
|
|
|
+ String.format(ExceptionConstants.DEPOT_ITEM_EXIST_REPEAT_NO_FAILED_MSG));
|
|
|
+ }
|
|
|
+ String subType = depotHead.getSubType();
|
|
|
+ //结算账户校验
|
|
|
+ if("采购".equals(subType) || "采购退货".equals(subType) || "销售".equals(subType) || "销售退货".equals(subType)) {
|
|
|
+ if (StringUtil.isEmpty(depotHead.getAccountIdList()) && depotHead.getAccountId() == null) {
|
|
|
+ throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_ACCOUNT_FAILED_CODE,
|
|
|
+ String.format(ExceptionConstants.DEPOT_HEAD_ACCOUNT_FAILED_MSG));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断用户是否已经登录过,登录过不再处理
|
|
|
+ User userInfo=userService.getCurrentUser();
|
|
|
+ depotHead.setCreator(userInfo==null?null:userInfo.getId());
|
|
|
+ depotHead.setCreateTime(new Timestamp(System.currentTimeMillis()));
|
|
|
+ if(StringUtil.isEmpty(depotHead.getStatus())) {
|
|
|
+ depotHead.setStatus(BusinessConstants.BILLS_STATUS_UN_AUDIT);
|
|
|
+ }
|
|
|
+ depotHead.setPurchaseStatus(BusinessConstants.BILLS_STATUS_UN_AUDIT);
|
|
|
+ depotHead.setPayType(depotHead.getPayType()==null?"现付":depotHead.getPayType());
|
|
|
+ if(StringUtil.isNotEmpty(depotHead.getAccountIdList())){
|
|
|
+ depotHead.setAccountIdList(depotHead.getAccountIdList().replace("[", "").replace("]", "").replaceAll("\"", ""));
|
|
|
+ }
|
|
|
+ if(StringUtil.isNotEmpty(depotHead.getAccountMoneyList())) {
|
|
|
+ //校验多账户的结算金额
|
|
|
+ String accountMoneyList = depotHead.getAccountMoneyList().replace("[", "").replace("]", "").replaceAll("\"", "");
|
|
|
+ BigDecimal sum = StringUtil.getArrSum(accountMoneyList.split(","));
|
|
|
+ BigDecimal manyAccountSum = sum.abs();
|
|
|
+ if(manyAccountSum.compareTo(depotHead.getChangeAmount().abs())!=0) {
|
|
|
+ throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_MANY_ACCOUNT_FAILED_CODE,
|
|
|
+ String.format(ExceptionConstants.DEPOT_HEAD_MANY_ACCOUNT_FAILED_MSG));
|
|
|
+ }
|
|
|
+ depotHead.setAccountMoneyList(accountMoneyList);
|
|
|
+ }
|
|
|
+ //校验附件的数量
|
|
|
+ if(StringUtil.isNotEmpty(depotHead.getFileName())) {
|
|
|
+ String[] fileArr = depotHead.getFileName().split(",");
|
|
|
+ if(fileArr.length>4) {
|
|
|
+ throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_FILE_NUM_LIMIT_CODE,
|
|
|
+ String.format(ExceptionConstants.DEPOT_HEAD_FILE_NUM_LIMIT_MSG, 4));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //商品数量
|
|
|
+ int operNumber = 0;
|
|
|
+ List<PDADepotMaterialDto> list = pdaDepotHeadDTO.getMaterials();
|
|
|
+ Map<String,PDADepotMaterialDto> materialMap = new HashMap<>();
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ operNumber = operNumber + list.get(i).getMaterialNumber().intValue();
|
|
|
+ materialMap.put(list.get(i).getBatchNumber(),list.get(i));
|
|
|
+ }
|
|
|
+ depotHead.setGoodsQuantity(operNumber);
|
|
|
+ //商品总类
|
|
|
+ depotHead.setGoodsTypeCount(list.size());
|
|
|
+ //设置凭证图片、备注
|
|
|
+ depotHead.setVoucherPicture(pdaDepotHeadDTO.getVoucherPicture());
|
|
|
+ depotHead.setRemark(pdaDepotHeadDTO.getRemark());
|
|
|
+ User user = userService.getCurrentUser();
|
|
|
+ depotHead.setTenantId(user.getId());
|
|
|
+ depotHead.setCreateTime(new Timestamp(System.currentTimeMillis()));
|
|
|
+ //添加主表
|
|
|
+ depotHeadMapper.insertSelective(depotHead);
|
|
|
+ //根据单据编号查询单据id
|
|
|
+ long id = depotHeadMapper.selectOne(new QueryWrapperX<DepotHead>().eq("number",depotHead.getNumber())).getId();
|
|
|
+ //设置单据子表信息
|
|
|
+ for (DepotItem depotItem : depotItems) {
|
|
|
+ //获取子表单商品
|
|
|
+ MaterialExtend materialExtend = materialExtendService.getMaterialExtend(depotItem.getMaterialExtendId());
|
|
|
+ //获取子表单批次号
|
|
|
+ String batchNumber = materialExtend.getBatchNumber();
|
|
|
+ //修改原先采购订单实际入库数量
|
|
|
+ depotItemService.update(new UpdateWrapper<DepotItem>().set("actual_quantity_in_storage", materialMap.get(batchNumber).getMaterialNumber()).eq("id", depotItem.getId()));
|
|
|
+ //设置单据主表id
|
|
|
+ depotItem.setHeaderId(id);
|
|
|
+ depotItem.setId(null);
|
|
|
+ //设置实际入库数量
|
|
|
+ depotItem.setActualQuantityInStorage(materialMap.get(batchNumber).getMaterialNumber());
|
|
|
+ //以下进行单位换算
|
|
|
+ Unit unitInfo = materialService.findUnit(depotItem.getMaterialId()); //查询多单位信息
|
|
|
+ if (StringUtil.isExist(depotItem.getActualQuantityInStorage())) {
|
|
|
+ //获取子表单商品单位
|
|
|
+ String unit =depotItem.getMaterialUnit();
|
|
|
+ BigDecimal oNumber = depotItem.getActualQuantityInStorage();
|
|
|
+ //设置基础数量
|
|
|
+ if (StringUtil.isNotEmpty(unitInfo.getName())) {
|
|
|
+ String basicUnit = unitInfo.getBasicUnit(); //基本单位
|
|
|
+ if (unit.equals(basicUnit)) { //如果等于基本单位
|
|
|
+ depotItem.setBasicNumber(oNumber); //数量一致
|
|
|
+ } else if (unit.equals(unitInfo.getOtherUnit())) { //如果等于副单位
|
|
|
+ depotItem.setBasicNumber(oNumber.multiply(unitInfo.getRatio())); //数量乘以比例
|
|
|
+ } else if (unit.equals(unitInfo.getOtherUnitTwo())) { //如果等于副单位2
|
|
|
+ depotItem.setBasicNumber(oNumber.multiply(unitInfo.getRatioTwo())); //数量乘以比例
|
|
|
+ } else if (unit.equals(unitInfo.getOtherUnitThree())) { //如果等于副单位3
|
|
|
+ depotItem.setBasicNumber(oNumber.multiply(unitInfo.getRatioThree())); //数量乘以比例
|
|
|
+ } else {
|
|
|
+ depotItem.setBasicNumber(oNumber); //数量一致
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ depotItem.setBasicNumber(oNumber); //其他情况
|
|
|
+ }
|
|
|
+ }
|
|
|
+ depotItem.setWarehousingUser(user.getId());
|
|
|
+ //添加单据子表
|
|
|
+ depotItemService.insertDepotItemWithObj(depotItem);
|
|
|
+ //修改商品生产日期
|
|
|
+ materialExtendService.update(new UpdateWrapper<MaterialExtend>().set("production_date",materialMap.get(batchNumber).getProductionDate()).eq("id", materialExtend.getId()));
|
|
|
+ }
|
|
|
+ //修改采购订单状态完成
|
|
|
+ this.update(new UpdateWrapper<DepotHead>().set("status", "2").eq("id", pdaDepotHeadDTO.getId()));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
}
|