|
|
@ -1,24 +1,47 @@ |
|
|
|
package com.win.module.wms.service.productputawayRequest; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import cn.hutool.core.exceptions.UtilException; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.google.common.annotations.VisibleForTesting; |
|
|
|
import com.win.framework.datapermission.core.util.DataPermissionUtils; |
|
|
|
import com.win.module.system.api.dict.DictDataApi; |
|
|
|
import com.win.module.system.api.dict.dto.DictDataRespDTO; |
|
|
|
import com.win.module.wms.dal.dataobject.balance.BalanceDO; |
|
|
|
import com.win.module.wms.dal.dataobject.businesstype.BusinesstypeDO; |
|
|
|
import com.win.module.wms.dal.dataobject.itembasic.ItembasicDO; |
|
|
|
import com.win.module.wms.dal.dataobject.requestsetting.RequestsettingDO; |
|
|
|
import com.win.module.wms.dal.mysql.productputawayRequest.ProductputawayRequestDetailMapper; |
|
|
|
import com.win.module.wms.service.requestsetting.RequestsettingService; |
|
|
|
import com.win.module.wms.util.*; |
|
|
|
import com.win.framework.common.pojo.CustomConditions; |
|
|
|
import com.win.framework.common.pojo.PageResult; |
|
|
|
import com.win.module.wms.controller.productputawayRequest.vo.ProductputawayRequestMainCreateReqVO; |
|
|
|
import com.win.module.wms.controller.productputawayRequest.vo.ProductputawayRequestMainExportReqVO; |
|
|
|
import com.win.module.wms.controller.productputawayRequest.vo.ProductputawayRequestMainPageReqVO; |
|
|
|
import com.win.module.wms.controller.productputawayRequest.vo.ProductputawayRequestMainUpdateReqVO; |
|
|
|
import com.win.framework.dict.core.util.DictFrameworkUtils; |
|
|
|
import com.win.module.system.api.serialnumber.SerialNumberApi; |
|
|
|
import com.win.module.system.enums.serialNumber.RuleCodeEnum; |
|
|
|
import com.win.module.wms.controller.productputawayRequest.vo.*; |
|
|
|
import com.win.module.wms.convert.productputawayRequest.ProductputawayRequestMainConvert; |
|
|
|
import com.win.module.wms.dal.dataobject.accountcalendar.AccountcalendarDO; |
|
|
|
import com.win.module.wms.dal.dataobject.productputawayRequest.ProductputawayRequestDetailDO; |
|
|
|
import com.win.module.wms.dal.dataobject.productputawayRequest.ProductputawayRequestMainDO; |
|
|
|
import com.win.module.wms.service.businesstype.*; |
|
|
|
import com.win.module.wms.dal.mysql.productputawayRequest.ProductputawayRequestMainMapper; |
|
|
|
import com.win.module.wms.enums.DictTypeConstants; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport; |
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
|
|
|
|
import com.win.module.wms.convert.productputawayRequest.*; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import com.win.module.wms.service.location.*; |
|
|
|
import static com.win.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
|
|
import static com.win.module.wms.enums.ErrorCodeConstants.PRODUCTPUTAWAY_REQUEST_MAIN_NOT_EXISTS; |
|
|
|
import static com.win.module.wms.enums.ErrorCodeConstants.*; |
|
|
|
import com.win.module.wms.service.recordsetting.*; |
|
|
|
import com.win.module.wms.service.itembasic.*; |
|
|
|
|
|
|
|
/** |
|
|
|
* 制品上架申请主 Service 实现类 |
|
|
@ -31,7 +54,31 @@ public class ProductputawayRequestMainServiceImpl implements ProductputawayReque |
|
|
|
|
|
|
|
@Resource |
|
|
|
private ProductputawayRequestMainMapper productputawayRequestMainMapper; |
|
|
|
@Resource |
|
|
|
private RequestsettingService requestsettingService; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private ProductputawayRequestDetailMapper productputawayRequestDetailMapper; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private ItembasicService itembasicService; |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
private JobUtils jobUtils; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private BusinesstypeService businesstypeService; |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
private LocationService locationService; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private SerialNumberApi serialNumberApi; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private DictDataApi dictDataApi; |
|
|
|
@Override |
|
|
|
public Long createProductputawayRequestMain(ProductputawayRequestMainCreateReqVO createReqVO) { |
|
|
|
// 插入
|
|
|
@ -88,4 +135,193 @@ public class ProductputawayRequestMainServiceImpl implements ProductputawayReque |
|
|
|
public PageResult<ProductputawayRequestMainDO> getProductputawayRequestMainSenior(CustomConditions conditions) { |
|
|
|
return productputawayRequestMainMapper.selectSenior(conditions); |
|
|
|
} |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
|
|
|
|
public List<ProductputawayImportExcelVO> importProductputawayList(List<ProductputawayImportExcelVO> importProductputaways, Integer mode, boolean updatePart) { |
|
|
|
if (CollUtil.isEmpty(importProductputaways)) { |
|
|
|
throw exception(WORKSTATION_IMPORT_LIST_IS_EMPTY); |
|
|
|
} |
|
|
|
List<ProductputawayImportExcelVO> errorList = new ArrayList<>(); |
|
|
|
importProductputaways.forEach(productputaway -> { |
|
|
|
String massage = ""; |
|
|
|
// 校验,判断是否有不符合的原因
|
|
|
|
if(mode != null){ |
|
|
|
try{ |
|
|
|
validateProductputawayExists(null); |
|
|
|
} catch(Exception ex){ |
|
|
|
massage += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
|
|
|
|
if(StrUtil.isNotEmpty(massage)){ |
|
|
|
massage.substring(0,massage.length()-1); |
|
|
|
errorList.add(productputaway); |
|
|
|
} |
|
|
|
// 判断如果不存在,在进行插入
|
|
|
|
if(errorList == null){ |
|
|
|
ProductputawayRequestMainDO existAccountcalendar = productputawayRequestMainMapper.selectByNumber(productputaway.getPackingNumber()); |
|
|
|
if (existAccountcalendar == null&& mode != 3) { |
|
|
|
productputawayRequestMainMapper.insert(ProductputawayRequestMainConvert.INSTANCE.convert(productputaway)); |
|
|
|
} |
|
|
|
else if (existAccountcalendar != null && mode != 2) {// 如果存在,判断是否允许更新
|
|
|
|
ProductputawayRequestMainDO productputawayDo = ProductputawayRequestMainConvert.INSTANCE.convert(productputaway); |
|
|
|
productputawayDo.setId(existAccountcalendar.getId()); |
|
|
|
productputawayRequestMainMapper.updateById(productputawayDo); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
//错误不为空并非部分更新,手工回滚
|
|
|
|
if(!errorList.isEmpty() && !updatePart) { |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
} |
|
|
|
return errorList; |
|
|
|
} |
|
|
|
|
|
|
|
private void validateproductputawayForCreateOrUpdate(Long id,String code,String workshopCode,String productionLineCode,String available) { |
|
|
|
// 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确
|
|
|
|
DataPermissionUtils.executeIgnore(() -> { |
|
|
|
// 校验code唯一
|
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
@VisibleForTesting |
|
|
|
private void validateProductputawayExists(Long id) { |
|
|
|
if (id == null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
ProductputawayRequestMainDO productputaway = productputawayRequestMainMapper.selectById(id); |
|
|
|
if (productputaway == null) { |
|
|
|
throw exception(PRODUCTPUTAWAY_REQUEST_NOT_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String Isuom(String uom1, String uom2) { |
|
|
|
DictDataRespDTO dictDataRespDTO = dictDataApi.selectDictValue(uom1); |
|
|
|
String value = dictDataRespDTO.getLabel(); |
|
|
|
if(uom2.equals(value)){ |
|
|
|
return "ture"; |
|
|
|
}else { |
|
|
|
throw new UtilException("计量单位"+uom2+"错误,应该是"+value); |
|
|
|
} |
|
|
|
} |
|
|
|
public String isqty(BigDecimal qty1, BigDecimal qty2) { |
|
|
|
if(qty1.compareTo(qty2) < 0){ |
|
|
|
return "ture"; |
|
|
|
} else { |
|
|
|
throw new UtilException("上架数量"+qty2+ "不能大于库存数量"+ qty1); |
|
|
|
} |
|
|
|
} |
|
|
|
public List<ProductputawayImportErrorVO> importProductputawayRequestList(List<ProductputawayRequestMainCreateReqVO> datas, Integer mode, boolean updatePart) { |
|
|
|
if (CollUtil.isEmpty(datas)) { |
|
|
|
throw exception(PRODUCTPUTAWAY_REQUEST_NOT_EXISTS); |
|
|
|
} |
|
|
|
List<ProductputawayImportErrorVO> errorList = new ArrayList<>(); |
|
|
|
datas.forEach(createReqVO -> { |
|
|
|
String massage = ""; |
|
|
|
boolean isError = false; |
|
|
|
RequestsettingDO requestsetting = requestsettingService.selectRequestsettingExist("PurchaseReceiptRequest"); |
|
|
|
createReqVO.setAutoCommit(requestsetting.getAutoCommit()); |
|
|
|
createReqVO.setAutoAgree(requestsetting.getAutoAgree()); |
|
|
|
createReqVO.setAutoExecute(requestsetting.getAutoExecute()); |
|
|
|
createReqVO.setDirectCreateRecord(requestsetting.getDirectCreateRecord()); |
|
|
|
|
|
|
|
List<ProductputawayRequestDetailCreateReqVO> subList = createReqVO.getSubList(); |
|
|
|
List<ProductputawayRequestDetailDO> subDOList = ProductputawayRequestDetailConvert.INSTANCE.convertList03(subList); |
|
|
|
// 新增子表数据
|
|
|
|
for (ProductputawayRequestDetailDO detailDO : subDOList) { |
|
|
|
if (mode != null) { |
|
|
|
try { |
|
|
|
validateProductputawayExists(null); |
|
|
|
} catch (Exception ex) { |
|
|
|
massage += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
// 校验,判断是否有不符合的原因,并加入errorList,同主表,只把有错误的子表加入errorList
|
|
|
|
try { |
|
|
|
ItembasicDO item = itembasicService.selectItembasic(detailDO.getItemCode()); |
|
|
|
detailDO.setItemDesc1(item.getDesc1()); |
|
|
|
detailDO.setItemDesc2(item.getDesc2()); |
|
|
|
detailDO.setItemName(item.getName()); |
|
|
|
detailDO.setProjectCode(item.getProject()); |
|
|
|
try{ |
|
|
|
Isuom(item.getUom(),detailDO.getUom()); |
|
|
|
}catch (Exception ex) { |
|
|
|
isError = true; |
|
|
|
massage += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
} catch (Exception ex) { |
|
|
|
isError = true; |
|
|
|
massage += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
try{ |
|
|
|
locationService.selectLocation(detailDO.getFromLocationCode()); |
|
|
|
}catch (Exception ex) { |
|
|
|
isError = true; |
|
|
|
massage += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
try{ |
|
|
|
BusinesstypeDO bus = businesstypeService.selectBusinesstypeExist("ProductPutawayRequest"); |
|
|
|
createReqVO.setBusinessType(bus.getCode()); |
|
|
|
createReqVO.setFromLocationTypes(bus.getOutLocationTypes()); |
|
|
|
createReqVO.setToLocationTypes(bus.getInLocationTypes()); |
|
|
|
createReqVO.setFromAreaCodes(bus.getOutAreaCodes()); |
|
|
|
createReqVO.setToAreaCodes(bus.getInAreaCodes()); |
|
|
|
//TODO TB ---TB1 效验业务类型相关属性
|
|
|
|
try{ |
|
|
|
jobUtils.ifInToLocationType(detailDO.getFromLocationCode(),bus); |
|
|
|
DictDataRespDTO dictDataRespDTO = dictDataApi.selectDictLabel(detailDO.getInventoryStatus()); |
|
|
|
String value = dictDataRespDTO.getValue(); |
|
|
|
String[] businessArray = value.split(","); |
|
|
|
List<String> business = Arrays.asList(businessArray); |
|
|
|
|
|
|
|
List<BalanceDO> balance = jobUtils.selectlocationReturnManagementAccuracy(detailDO.getItemCode(), detailDO.getPackingNumber(), |
|
|
|
detailDO.getBatch(), detailDO.getFromLocationCode(), business); |
|
|
|
|
|
|
|
try{ |
|
|
|
BalanceDO blance1 = balance.get(0); |
|
|
|
isqty(detailDO.getQty(),blance1.getQty()); |
|
|
|
}catch (Exception ex) { |
|
|
|
isError = true; |
|
|
|
massage += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
}catch (Exception ex) { |
|
|
|
isError = true; |
|
|
|
massage += ex.getMessage() + ","; |
|
|
|
|
|
|
|
} |
|
|
|
}catch (Exception ex) { |
|
|
|
isError = true; |
|
|
|
massage += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
if(isError) { |
|
|
|
ProductputawayImportErrorVO importVO = ProductputawayRequestDetailConvert.INSTANCE.convert(createReqVO,detailDO); |
|
|
|
importVO.setImportStatus("失败"); |
|
|
|
importVO.setImportRemark(massage.substring(0, massage.length() - 1)); |
|
|
|
errorList.add(importVO); |
|
|
|
} |
|
|
|
if(!isError) { |
|
|
|
if( mode != 3) { |
|
|
|
createReqVO.setStatus(DictFrameworkUtils.parseDictDataValue(DictTypeConstants.REQUEST_STATUS, "新增")); |
|
|
|
String number = serialNumberApi.generateCode(RuleCodeEnum.PURCHASE_CLAIM_RECORD.getCode()); |
|
|
|
createReqVO.setNumber(number); |
|
|
|
ProductputawayRequestMainDO createObj = ProductputawayRequestMainConvert.INSTANCE.convert(createReqVO); |
|
|
|
productputawayRequestMainMapper.insert(createObj); |
|
|
|
productputawayRequestDetailMapper.insertBatch(subDOList); |
|
|
|
} |
|
|
|
else if(mode != 2){ |
|
|
|
createReqVO.setStatus(DictFrameworkUtils.parseDictDataValue(DictTypeConstants.REQUEST_STATUS, "新增")); |
|
|
|
String number = serialNumberApi.generateCode(RuleCodeEnum.PURCHASE_CLAIM_RECORD.getCode()); |
|
|
|
createReqVO.setNumber(number); |
|
|
|
ProductputawayRequestMainDO createObj = ProductputawayRequestMainConvert.INSTANCE.convert(createReqVO); |
|
|
|
productputawayRequestMainMapper.updateById(createObj); |
|
|
|
productputawayRequestDetailMapper.updateBatch(subDOList); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
return errorList; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|