|
|
@ -1,28 +1,43 @@ |
|
|
|
package com.win.module.wms.service.purchasereceiptRequest; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import cn.hutool.json.JSONArray; |
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
import com.win.framework.common.exception.ServiceException; |
|
|
|
import com.win.framework.common.pojo.CustomConditions; |
|
|
|
import com.win.framework.common.pojo.PageResult; |
|
|
|
import com.win.framework.dict.core.util.DictFrameworkUtils; |
|
|
|
import com.win.framework.common.util.validation.ValidationUtils; |
|
|
|
import com.win.module.system.api.serialnumber.SerialNumberApi; |
|
|
|
import com.win.module.system.enums.serialNumber.RuleCodeEnum; |
|
|
|
import com.win.module.wms.controller.purchasereceiptRequest.vo.*; |
|
|
|
import com.win.module.wms.controller.rule.vo.RuleRespVO; |
|
|
|
import com.win.module.wms.convert.purchasereceiptRequest.PurchasereceiptRequestDetailConvert; |
|
|
|
import com.win.module.wms.convert.purchasereceiptRequest.PurchasereceiptRequestMainConvert; |
|
|
|
import com.win.module.wms.dal.dataobject.purchasereceiptRequest.PurchasereceiptRequestDetailDO; |
|
|
|
import com.win.module.wms.dal.dataobject.purchasereceiptRequest.PurchasereceiptRequestMainDO; |
|
|
|
import com.win.module.wms.dal.dataobject.requestsetting.RequestsettingDO; |
|
|
|
import com.win.module.wms.dal.mysql.purchasereceiptJob.PurchasereceiptJobMainMapper; |
|
|
|
import com.win.module.wms.dal.mysql.purchasereceiptRequest.PurchasereceiptRequestDetailMapper; |
|
|
|
import com.win.module.wms.dal.mysql.purchasereceiptRequest.PurchasereceiptRequestMainMapper; |
|
|
|
import com.win.module.wms.enums.DictTypeConstants; |
|
|
|
import com.win.module.wms.enums.request.RequestStatusEnum; |
|
|
|
import com.win.module.wms.enums.request.RequestStatusState; |
|
|
|
import com.win.module.wms.service.itembasic.ItembasicService; |
|
|
|
import com.win.module.wms.service.requestsetting.RequestsettingService; |
|
|
|
import com.win.module.wms.service.rule.RuleService; |
|
|
|
import com.win.module.wms.service.supplier.SupplierService; |
|
|
|
import com.win.module.wms.service.supplieritem.SupplieritemService; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport; |
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.List; |
|
|
|
import javax.validation.Validator; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import static com.win.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
|
|
import static com.win.module.wms.enums.ErrorCodeConstants.PURCHASECLAIM_REQUEST_IMPORT_LIST_IS_EMPTY; |
|
|
|
import static com.win.module.wms.enums.ErrorCodeConstants.PURCHASERECEIPT_REQUEST_MAIN_NOT_EXISTS; |
|
|
|
import static com.win.module.wms.enums.ErrorCodeConstants.*; |
|
|
|
|
|
|
|
/** |
|
|
|
* 采购收货申请主 Service 实现类 |
|
|
@ -35,43 +50,95 @@ public class PurchasereceiptRequestMainServiceImpl implements PurchasereceiptReq |
|
|
|
|
|
|
|
@Resource |
|
|
|
private PurchasereceiptRequestMainMapper purchasereceiptRequestMainMapper; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private PurchasereceiptRequestDetailMapper purchasereceiptRequestDetailMapper; |
|
|
|
@Resource |
|
|
|
private ItembasicService itembasicService; |
|
|
|
@Resource |
|
|
|
private SupplierService supplierService; |
|
|
|
@Resource |
|
|
|
private SupplieritemService supplieritemService; |
|
|
|
@Resource |
|
|
|
private RuleService ruleService; |
|
|
|
@Resource |
|
|
|
private SerialNumberApi serialNumberApi; |
|
|
|
@Resource |
|
|
|
private Validator validator; |
|
|
|
@Resource |
|
|
|
private RequestsettingService requestsettingService; |
|
|
|
@Resource |
|
|
|
private PurchasereceiptJobMainMapper purchasereceiptJobMainMapper; |
|
|
|
|
|
|
|
@Override |
|
|
|
public Long createPurchasereceiptRequestMain(PurchasereceiptRequestMainCreateReqVO createReqVO) { |
|
|
|
// 插入
|
|
|
|
PurchasereceiptRequestMainDO purchasereceiptRequestMain = PurchasereceiptRequestMainConvert.INSTANCE.convert(createReqVO); |
|
|
|
purchasereceiptRequestMainMapper.insert(purchasereceiptRequestMain); |
|
|
|
PurchasereceiptRequestMainDO mainDo = PurchasereceiptRequestMainConvert.INSTANCE.convert(createReqVO); |
|
|
|
this.validatePurchasereceiptRequestMainCreate(mainDo); |
|
|
|
List<PurchasereceiptRequestDetailDO> subDOList = PurchasereceiptRequestDetailConvert.INSTANCE.convertList03(createReqVO.getSubList()); |
|
|
|
for (PurchasereceiptRequestDetailDO detailDO : subDOList) { |
|
|
|
this.validatePurchasereceiptRequestDetailCreate(detailDO); |
|
|
|
} |
|
|
|
String number = serialNumberApi.generateCode(RuleCodeEnum.PURCHASE_RECEIPT_REQUEST.getCode()); |
|
|
|
mainDo.setNumber(number); |
|
|
|
RequestsettingDO requestsettingDO = requestsettingService.selectRequestsettingExist("PurchaseReceiptRequest"); |
|
|
|
RequestStatusState requestStatusState = new RequestStatusState(); |
|
|
|
requestStatusState.newObject(requestsettingDO); |
|
|
|
mainDo.setStatus(requestStatusState.getState().getCode()); |
|
|
|
mainDo.setAutoCommit(requestsettingDO.getAutoCommit()); |
|
|
|
mainDo.setAutoAgree(requestsettingDO.getAutoAgree()); |
|
|
|
mainDo.setAutoExecute(requestsettingDO.getAutoExecute()); |
|
|
|
//调用自动执行方法
|
|
|
|
if(requestsettingDO.getAutoCommit().equals("TRUE") && requestsettingDO.getAutoAgree().equals("TRUE") && requestsettingDO.getAutoExecute().equals("TREU")) { |
|
|
|
|
|
|
|
} |
|
|
|
purchasereceiptRequestMainMapper.insert(mainDo); |
|
|
|
for (PurchasereceiptRequestDetailDO detailDO : subDOList) { |
|
|
|
detailDO.setMasterId(mainDo.getId()); |
|
|
|
detailDO.setNumber(number); |
|
|
|
} |
|
|
|
purchasereceiptRequestDetailMapper.insertBatch(subDOList); |
|
|
|
// 返回
|
|
|
|
return purchasereceiptRequestMain.getId(); |
|
|
|
return mainDo.getId(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void updatePurchasereceiptRequestMain(PurchasereceiptRequestMainUpdateReqVO updateReqVO) { |
|
|
|
public Integer updatePurchasereceiptRequestMain(PurchasereceiptRequestMainUpdateReqVO updateReqVO) { |
|
|
|
// 校验存在
|
|
|
|
validatePurchasereceiptRequestMainExists(updateReqVO.getId()); |
|
|
|
PurchasereceiptRequestMainDO existPurchasereceiptRequestMainDO = validatePurchasereceiptRequestMainExists(updateReqVO.getId()); |
|
|
|
if(existPurchasereceiptRequestMainDO.getStatus().equals(RequestStatusEnum.NEW.getCode())) { |
|
|
|
throw new ServiceException(PURCHASERECEIPT_REQUEST_STATUS_NOT_NEW); |
|
|
|
} |
|
|
|
// 更新
|
|
|
|
PurchasereceiptRequestMainDO updateObj = PurchasereceiptRequestMainConvert.INSTANCE.convert(updateReqVO); |
|
|
|
purchasereceiptRequestMainMapper.updateById(updateObj); |
|
|
|
return purchasereceiptRequestMainMapper.updateById(updateObj); |
|
|
|
} |
|
|
|
@Override |
|
|
|
public PageResult<PurchasereceiptRequestMainDO> getPurchasereceiptRequestMainSenior(CustomConditions conditions) { |
|
|
|
return purchasereceiptRequestMainMapper.selectSenior(conditions); |
|
|
|
} |
|
|
|
@Override |
|
|
|
public void deletePurchasereceiptRequestMain(Long id) { |
|
|
|
public Integer deletePurchasereceiptRequestMain(Long id) { |
|
|
|
// 校验存在
|
|
|
|
validatePurchasereceiptRequestMainExists(id); |
|
|
|
// 删除
|
|
|
|
purchasereceiptRequestMainMapper.deleteById(id); |
|
|
|
PurchasereceiptRequestMainDO existPurchasereceiptRequestMainDO = validatePurchasereceiptRequestMainExists(id); |
|
|
|
Long count = purchasereceiptJobMainMapper.selectByRequestNumber(existPurchasereceiptRequestMainDO.getNumber()); |
|
|
|
if(count > 0) { |
|
|
|
throw new ServiceException(PURCHASERECEIPT_REQUEST_JOB_EXISTS); |
|
|
|
} |
|
|
|
// 删除子表数据
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
map.put("master_id", id); |
|
|
|
//删除子表
|
|
|
|
purchasereceiptRequestDetailMapper.deleteByMap(map); |
|
|
|
// 删除主表
|
|
|
|
return purchasereceiptRequestMainMapper.deleteById(id); |
|
|
|
} |
|
|
|
|
|
|
|
private void validatePurchasereceiptRequestMainExists(Long id) { |
|
|
|
if (purchasereceiptRequestMainMapper.selectById(id) == null) { |
|
|
|
private PurchasereceiptRequestMainDO validatePurchasereceiptRequestMainExists(Long id) { |
|
|
|
PurchasereceiptRequestMainDO existPurchasereceiptRequestMainDO = purchasereceiptRequestMainMapper.selectById(id); |
|
|
|
if (existPurchasereceiptRequestMainDO == null) { |
|
|
|
throw exception(PURCHASERECEIPT_REQUEST_MAIN_NOT_EXISTS); |
|
|
|
} |
|
|
|
return existPurchasereceiptRequestMainDO; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -101,30 +168,151 @@ public class PurchasereceiptRequestMainServiceImpl implements PurchasereceiptReq |
|
|
|
} |
|
|
|
List<PurchasereceiptRequestMainImportErrorVO> errorList = new ArrayList<>(); |
|
|
|
datas.forEach(createReqVO -> { |
|
|
|
// 校验,判断是否有不符合的原因,并加入errorList,如果主表则所有子表都加入errorList
|
|
|
|
boolean isError = false; |
|
|
|
// try {
|
|
|
|
// if(mode != null){
|
|
|
|
// validatePurchaseclaimRequestMainExists(null);
|
|
|
|
// }
|
|
|
|
// } catch (ServiceException ex) {
|
|
|
|
// isError = true;
|
|
|
|
// importRemark += ex.getMessage() + ",";
|
|
|
|
// }
|
|
|
|
|
|
|
|
createReqVO.setStatus(DictFrameworkUtils.parseDictDataValue(DictTypeConstants.REQUEST_STATUS, "新增")); |
|
|
|
PurchasereceiptRequestMainDO createObj = PurchasereceiptRequestMainConvert.INSTANCE.convert(createReqVO); |
|
|
|
purchasereceiptRequestMainMapper.insert(createObj); |
|
|
|
PurchasereceiptRequestMainDO mainDo = PurchasereceiptRequestMainConvert.INSTANCE.convert(createReqVO); |
|
|
|
String messageMain = this.validatePurchasereceiptRequestMainImport(mainDo); |
|
|
|
List<PurchasereceiptRequestDetailCreateReqVO> subList = createReqVO.getSubList(); |
|
|
|
List<PurchasereceiptRequestDetailDO> subDOList = PurchasereceiptRequestDetailConvert.INSTANCE.convertList03(subList); |
|
|
|
// 新增子表数据
|
|
|
|
// 是否有错误数据
|
|
|
|
boolean flag = true; |
|
|
|
for (PurchasereceiptRequestDetailDO detailDO : subDOList) { |
|
|
|
// 校验,判断是否有不符合的原因,并加入errorList,同主表,只把有错误的子表加入errorList
|
|
|
|
detailDO.setNumber(createReqVO.getNumber()); |
|
|
|
String messageDetail = this.validatePurchasereceiptRequestDetailImport(detailDO); |
|
|
|
if(!messageMain.isEmpty() || messageDetail.isEmpty()) { |
|
|
|
PurchasereceiptRequestMainImportErrorVO importErrorVO = PurchasereceiptRequestMainConvert.INSTANCE.convert(createReqVO, detailDO); |
|
|
|
importErrorVO.setImportStatus("失败"); |
|
|
|
messageMain = messageMain + messageDetail; |
|
|
|
importErrorVO.setImportRemark(messageMain.substring(0, messageMain.length() - 1)); |
|
|
|
errorList.add(importErrorVO); |
|
|
|
flag = false; |
|
|
|
} |
|
|
|
} |
|
|
|
//写入数据
|
|
|
|
if(flag) { |
|
|
|
PurchasereceiptRequestMainDO existPurchasereceiptRequestMainDO = purchasereceiptRequestMainMapper.selectBySupplierCode(mainDo.getSupplierCode()); |
|
|
|
if(existPurchasereceiptRequestMainDO == null && mode != 3) {//新增
|
|
|
|
purchasereceiptRequestMainMapper.insert(mainDo); |
|
|
|
String number = serialNumberApi.generateCode(RuleCodeEnum.PURCHASE_RECEIPT_REQUEST.getCode()); |
|
|
|
mainDo.setNumber(number); |
|
|
|
RequestsettingDO requestsettingDO = requestsettingService.selectRequestsettingExist("PurchaseReceiptRequest"); |
|
|
|
RequestStatusState requestStatusState = new RequestStatusState(); |
|
|
|
requestStatusState.newObject(requestsettingDO); |
|
|
|
mainDo.setStatus(requestStatusState.getState().getCode()); |
|
|
|
mainDo.setAutoCommit(requestsettingDO.getAutoCommit()); |
|
|
|
mainDo.setAutoAgree(requestsettingDO.getAutoAgree()); |
|
|
|
mainDo.setAutoExecute(requestsettingDO.getAutoExecute()); |
|
|
|
for (PurchasereceiptRequestDetailDO detailDO : subDOList) { |
|
|
|
detailDO.setMasterId(mainDo.getId()); |
|
|
|
detailDO.setNumber(number); |
|
|
|
} |
|
|
|
//调用自动执行方法
|
|
|
|
if(requestsettingDO.getAutoCommit().equals("TRUE") && requestsettingDO.getAutoAgree().equals("TRUE") && requestsettingDO.getAutoExecute().equals("TREU")) { |
|
|
|
|
|
|
|
} |
|
|
|
purchasereceiptRequestDetailMapper.insertBatch(subDOList); |
|
|
|
} else if(existPurchasereceiptRequestMainDO != null && existPurchasereceiptRequestMainDO.getStatus().equals(RequestStatusEnum.NEW.getCode()) && mode != 2) {//修改
|
|
|
|
BeanUtils.copyProperties(existPurchasereceiptRequestMainDO, mainDo); |
|
|
|
purchasereceiptRequestMainMapper.updateById(mainDo); |
|
|
|
for (PurchasereceiptRequestDetailDO detailDO : subDOList) { |
|
|
|
detailDO.setMasterId(mainDo.getId()); |
|
|
|
detailDO.setNumber(mainDo.getNumber()); |
|
|
|
purchasereceiptRequestDetailMapper.insertBatch(subDOList); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
purchasereceiptRequestDetailMapper.insertBatch(subDOList); |
|
|
|
}); |
|
|
|
//错误不为空并非部分更新,手工回滚
|
|
|
|
if(!errorList.isEmpty() && !updatePart) { |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
} |
|
|
|
return errorList; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 校验导入,并赋值一些参数,未完全实现 |
|
|
|
* @param mainDo |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private void validatePurchasereceiptRequestMainCreate(PurchasereceiptRequestMainDO mainDo) { |
|
|
|
supplierService.selectSupplier(mainDo.getSupplierCode()); |
|
|
|
RuleRespVO ruleRespVO = ruleService.deliverGoods(null, mainDo.getSupplierCode(), null); |
|
|
|
if(ruleRespVO == null) { |
|
|
|
throw new ServiceException(STDCOSTPRICE_SUPPLIER_CODE_NOT_EXISTS); |
|
|
|
} else { |
|
|
|
JSONArray conditionArray = JSONUtil.parseArray(ruleRespVO.getConfiguration()); |
|
|
|
for (int i = 0; i < conditionArray.size(); i++) { |
|
|
|
JSONObject conditionObject = conditionArray.getJSONObject(i); |
|
|
|
if ("WarehouseCode".equals(conditionObject.get("ParamCode"))) { |
|
|
|
mainDo.setFromWarehouseCode(String.valueOf(conditionObject.get("Value"))); |
|
|
|
} |
|
|
|
if ("DockCode".equals(conditionObject.get("ParamCode"))) { |
|
|
|
mainDo.setToDockCode(String.valueOf(conditionObject.get("Value"))); |
|
|
|
} |
|
|
|
if ("OnTheWayLocationCode".equals(conditionObject.get("ParamCode"))) { |
|
|
|
mainDo.setToWarehouseCode(String.valueOf(conditionObject.get("Value"))); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 校验导入,并赋值一些参数,未完全实现 |
|
|
|
* @param mainDo |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private String validatePurchasereceiptRequestMainImport(PurchasereceiptRequestMainDO mainDo) { |
|
|
|
StringBuilder message = new StringBuilder(); |
|
|
|
try { |
|
|
|
ValidationUtils.validate(validator, mainDo); |
|
|
|
} catch (Exception ex) { |
|
|
|
message.append(ex.getMessage()).append(","); |
|
|
|
} |
|
|
|
try { |
|
|
|
supplierService.selectSupplier(mainDo.getSupplierCode()); |
|
|
|
} catch (Exception ex) { |
|
|
|
message.append(ex.getMessage()).append(","); |
|
|
|
} |
|
|
|
RuleRespVO ruleRespVO = ruleService.deliverGoods(null, mainDo.getSupplierCode(), null); |
|
|
|
if(ruleRespVO == null) { |
|
|
|
message.append(STDCOSTPRICE_SUPPLIER_CODE_NOT_EXISTS.getMsg()); |
|
|
|
} else { |
|
|
|
JSONArray conditionArray = JSONUtil.parseArray(ruleRespVO.getConfiguration()); |
|
|
|
for (int i = 0; i < conditionArray.size(); i++) { |
|
|
|
JSONObject conditionObject = conditionArray.getJSONObject(i); |
|
|
|
if ("WarehouseCode".equals(conditionObject.get("ParamCode"))) { |
|
|
|
mainDo.setFromWarehouseCode(String.valueOf(conditionObject.get("Value"))); |
|
|
|
} |
|
|
|
if ("DockCode".equals(conditionObject.get("ParamCode"))) { |
|
|
|
mainDo.setToDockCode(String.valueOf(conditionObject.get("Value"))); |
|
|
|
} |
|
|
|
if ("OnTheWayLocationCode".equals(conditionObject.get("ParamCode"))) { |
|
|
|
mainDo.setToWarehouseCode(String.valueOf(conditionObject.get("Value"))); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return message.toString(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 校验导入,并赋值一些参数,未完全实现 |
|
|
|
* @param detailDo |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private void validatePurchasereceiptRequestDetailCreate(PurchasereceiptRequestDetailDO detailDo) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 校验导入,并赋值一些参数,未完全实现 |
|
|
|
* @param detailDo |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private String validatePurchasereceiptRequestDetailImport(PurchasereceiptRequestDetailDO detailDo) { |
|
|
|
StringBuilder message = new StringBuilder(); |
|
|
|
try { |
|
|
|
ValidationUtils.validate(validator, detailDo); |
|
|
|
} catch (Exception ex) { |
|
|
|
message.append(ex.getMessage()).append(","); |
|
|
|
} |
|
|
|
return message.toString(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|