定时任务:增加定时同步原材料退库信息到ERP
master
xs 2 months ago
parent 99b61466fe
commit bf0aea4869

@ -37,6 +37,14 @@ public interface RemoteWmsService {
@PostMapping("/api/synchronizeRawMaterialDeliveryInformationToERP") @PostMapping("/api/synchronizeRawMaterialDeliveryInformationToERP")
public R<AjaxResult> synchronizeRawMaterialDeliveryInformationToERP(@RequestHeader(SecurityConstants.FROM_SOURCE) String source); public R<AjaxResult> synchronizeRawMaterialDeliveryInformationToERP(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/**
* 退ERP
* @param source
* @return
*/
@PostMapping("/api/synchronizeRawReturnInformationToERP")
public R<AjaxResult> synchronizeRawReturnInformationToERP(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
@PostMapping("/rawstock/isExistRawStock") @PostMapping("/rawstock/isExistRawStock")
public R<Boolean> isExistRawStock(@Validated @RequestBody WmsRawStockVo queryRawStockVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); public R<Boolean> isExistRawStock(@Validated @RequestBody WmsRawStockVo queryRawStockVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

@ -37,6 +37,11 @@ public class RemoteWmsFallbackFactory implements FallbackFactory<RemoteWmsServic
return R.fail("定时同步原材料出库给ERP失败:" + throwable.getMessage()); return R.fail("定时同步原材料出库给ERP失败:" + throwable.getMessage());
} }
@Override
public R<AjaxResult> synchronizeRawReturnInformationToERP(String source) {
return R.fail("定时同步原材料退库给ERP失败:" + throwable.getMessage());
}
@Override @Override
public R<AjaxResult> synchronizeProductInstockInformationToERP(Integer days, String inner) { public R<AjaxResult> synchronizeProductInstockInformationToERP(Integer days, String inner) {
return R.fail("定时同步成品入库给ERP失败:" + throwable.getMessage()); return R.fail("定时同步成品入库给ERP失败:" + throwable.getMessage());

@ -63,6 +63,11 @@ public class WmsConfig {
*/ */
private String wcsAgvContinueUrl; private String wcsAgvContinueUrl;
/**
* ERP
*/
private String fStockId;
public String getFifthAssembleStationCode() { public String getFifthAssembleStationCode() {
return fifthAssembleStationCode; return fifthAssembleStationCode;
} }
@ -142,4 +147,12 @@ public class WmsConfig {
public void setWcsAgvContinueUrl(String wcsAgvContinueUrl) { public void setWcsAgvContinueUrl(String wcsAgvContinueUrl) {
this.wcsAgvContinueUrl = wcsAgvContinueUrl; this.wcsAgvContinueUrl = wcsAgvContinueUrl;
} }
public String getfStockId() {
return fStockId;
}
public void setfStockId(String fStockId) {
this.fStockId = fStockId;
}
} }

@ -259,6 +259,17 @@ public class WmsApiController extends BaseController {
return toAjax(wmsErpScheduledTaskService.synchronizeRawMaterialDeliveryInformationToERP()); return toAjax(wmsErpScheduledTaskService.synchronizeRawMaterialDeliveryInformationToERP());
} }
/**
* 退ERP
*
* @return
*/
@PostMapping(("/synchronizeRawReturnInformationToERP"))
public AjaxResult synchronizeRawReturnInformationToERP() {
return toAjax(wmsErpScheduledTaskService.synchronizeRawReturnInformationToERP());
}
/** /**
* ERP * ERP
* *

@ -111,6 +111,10 @@ public class WmsRawReturnDetail extends BaseEntity
private String taskCode; private String taskCode;
private Long purchaseOrderId;
private String unitCode;
public void setRawReturnDetailId(Long rawReturnDetailId) public void setRawReturnDetailId(Long rawReturnDetailId)
{ {
@ -341,6 +345,22 @@ public class WmsRawReturnDetail extends BaseEntity
this.taskCode = taskCode; this.taskCode = taskCode;
} }
public Long getPurchaseOrderId() {
return purchaseOrderId;
}
public void setPurchaseOrderId(Long purchaseOrderId) {
this.purchaseOrderId = purchaseOrderId;
}
public String getUnitCode() {
return unitCode;
}
public void setUnitCode(String unitCode) {
this.unitCode = unitCode;
}
@Override @Override
public String toString() { public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

@ -76,4 +76,14 @@ public interface WmsRawReturnDetailMapper {
* @return 退 * @return 退
*/ */
public List<WmsRawReturnDetail> selectWmsRawReturnDetailJoinMaterialList(WmsRawReturnDetail wmsRawReturnDetail); public List<WmsRawReturnDetail> selectWmsRawReturnDetailJoinMaterialList(WmsRawReturnDetail wmsRawReturnDetail);
/**
* 退
*
* @param wmsRawReturnDetail 退
* @return 退
*/
public List<WmsRawReturnDetail> selectWmsRawReturnDetailERPNotSynchronized(WmsRawReturnDetail wmsRawReturnDetail);
} }

@ -22,6 +22,13 @@ public interface IWmsErpScheduledTaskService {
*/ */
int synchronizeRawMaterialDeliveryInformationToERP(); int synchronizeRawMaterialDeliveryInformationToERP();
/**
* 退ERP
*
* @return
*/
public int synchronizeRawReturnInformationToERP();
/** /**
* ERP * ERP
* @param days days * @param days days

@ -11,14 +11,9 @@ import com.hw.common.core.web.domain.AjaxResult;
import com.hw.jindie.api.RemoteJindieService; import com.hw.jindie.api.RemoteJindieService;
import com.hw.mes.api.RemoteMesService; import com.hw.mes.api.RemoteMesService;
import com.hw.mes.api.domain.MesPurchaseOrder; import com.hw.mes.api.domain.MesPurchaseOrder;
import com.hw.wms.domain.WmsProductInstock; import com.hw.wms.config.WmsConfig;
import com.hw.wms.domain.WmsProductOutstock; import com.hw.wms.domain.*;
import com.hw.wms.domain.WmsRawInstock; import com.hw.wms.mapper.*;
import com.hw.wms.domain.WmsRawOutstock;
import com.hw.wms.mapper.WmsProductInstockMapper;
import com.hw.wms.mapper.WmsProductOutstockMapper;
import com.hw.wms.mapper.WmsRawInstockMapper;
import com.hw.wms.mapper.WmsRawOutstockMapper;
import com.hw.wms.service.IWmsErpScheduledTaskService; import com.hw.wms.service.IWmsErpScheduledTaskService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -55,14 +50,20 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
@Autowired @Autowired
private WmsProductOutstockMapper wmsProductOutstockMapper; private WmsProductOutstockMapper wmsProductOutstockMapper;
@Autowired
private WmsRawReturnDetailMapper wmsRawReturnDetailMapper;
@Autowired @Autowired
private RemoteMesService remoteMesService; private RemoteMesService remoteMesService;
@Autowired @Autowired
private RemoteJindieService remoteJindieService; private RemoteJindieService remoteJindieService;
@Autowired
private WmsConfig wmsConfig;
//仓库编码 //仓库编码
private String FStockId = "CK050"; // private String FStockId = "CK050";
/** /**
* ERP * ERP
@ -110,7 +111,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
data.put("FSrcBillNo", instock.getSrcBillNo()); data.put("FSrcBillNo", instock.getSrcBillNo());
data.put("FUnitID", instock.getUnitCode()); data.put("FUnitID", instock.getUnitCode());
data.put("FRealQty", FRealQty); data.put("FRealQty", FRealQty);
data.put("FStockId", FStockId); data.put("FStockId", wmsConfig.getfStockId());
data.put("FSupplierCode", supplierCode); data.put("FSupplierCode", supplierCode);
data.put("FTondBase", projectNo); data.put("FTondBase", projectNo);
String params = data.toJSONString(); String params = data.toJSONString();
@ -155,6 +156,76 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
return result; return result;
} }
/**
* 退ERP
*
* @return
*/
@Override
// @Transactional
public int synchronizeRawReturnInformationToERP() {
WmsRawReturnDetail wmsRawReturnDetail = new WmsRawReturnDetail();
int result = 0;
List<WmsRawReturnDetail> returnDetailList = wmsRawReturnDetailMapper.selectWmsRawReturnDetailERPNotSynchronized(wmsRawReturnDetail);
Map<Long, List<WmsRawReturnDetail>> purchaseOrderIdMap = returnDetailList.stream().collect(Collectors.groupingBy(WmsRawReturnDetail::getPurchaseOrderId));
for (Long purchaseOrderId : purchaseOrderIdMap.keySet()) {
syncRawReturnInformation(purchaseOrderIdMap, purchaseOrderId, result);
}
return result;
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void syncRawReturnInformation(Map<Long, List<WmsRawReturnDetail>> purchaseOrderIdMap, Long purchaseOrderId, int result) {
R<MesPurchaseOrder> purchaseOrderData = remoteMesService.selectPurchaseOrderJoinSupplierProjectByOrderId(purchaseOrderId, SecurityConstants.INNER);
MesPurchaseOrder mesPurchaseOrder = null;
if (purchaseOrderData != null) {
mesPurchaseOrder = purchaseOrderData.getData();
String supplierCode = mesPurchaseOrder == null ? "" : mesPurchaseOrder.getSupplierCode();
String projectNo = mesPurchaseOrder == null ? "" : mesPurchaseOrder.getProjectNo();
String srcBillNo = mesPurchaseOrder.getSrcBillNo();
List<WmsRawReturnDetail> wmsRawReturnDetaiList = purchaseOrderIdMap.get(purchaseOrderId);
JSONObject data = new JSONObject();
double FRealQty = wmsRawReturnDetaiList.stream().mapToDouble(item -> item.getReturnAmount().subtract(item.getErpAmount()).doubleValue()).sum();
WmsRawReturnDetail rawReturnDetail = wmsRawReturnDetaiList.get(0);
String specificationParameter = StringUtils.isNotEmpty(mesPurchaseOrder.getSpecificationParameter()) ? mesPurchaseOrder.getSpecificationParameter() : rawReturnDetail.getMaterialSpec();
if (StringUtils.isNotEmpty(specificationParameter)) {
for (WmsRawReturnDetail wmsRawReturnDetail : wmsRawReturnDetaiList) {
wmsRawReturnDetail.setErpStatus("1");//同步ERP状态(0:失败,1成功)
wmsRawReturnDetail.setErpAmount(wmsRawReturnDetail.getReturnAmount());
wmsRawReturnDetail.setUpdateDate(DateUtils.getNowDate());
wmsRawReturnDetailMapper.updateWmsRawReturnDetail(wmsRawReturnDetail);
}
data.put("FDate", DateUtils.getTime());
data.put("FMaterialId", rawReturnDetail.getMaterialCode());
data.put("FAuxPropId", specificationParameter);
data.put("FSrcBillNo", srcBillNo);
data.put("FUnitID", rawReturnDetail.getUnitCode());
data.put("FRealQty", FRealQty);
data.put("FStockId", wmsConfig.getfStockId());
data.put("FSupplierCode", supplierCode);
data.put("FTondBase", projectNo);
String params = data.toJSONString();
R<AjaxResult> paramsResult = remoteJindieService.savePurchaseStorage(params, SecurityConstants.INNER);
String paramsResultData = paramsResult.getMsg();
JSONObject jsonObject = JSONObject.parseObject(paramsResultData);
Boolean isSuccess = (Boolean) jsonObject.get("IsSuccess");
if (isSuccess) {
result++;
log.info("synchronizeInventoryInformationToERP同步原材料退库成功:" + paramsResult.toString());
} else {
log.error("synchronizeInventoryInformationToERP同步原材料退库失败:" + paramsResult.toString());
throw new ServiceException("同步原材料入库失败" + paramsResult.toString());
}
}
}
}
@Transactional(propagation = Propagation.REQUIRES_NEW) @Transactional(propagation = Propagation.REQUIRES_NEW)
public int syncOutstockInformation(Map<Long, List<WmsRawOutstock>> materialIdMap, Long materialId, String taskType) { public int syncOutstockInformation(Map<Long, List<WmsRawOutstock>> materialIdMap, Long materialId, String taskType) {
int result = 0; int result = 0;
@ -186,7 +257,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
data.put("FUnitID", outstock.getUnitCode()); data.put("FUnitID", outstock.getUnitCode());
data.put("FQty", FRealQty); data.put("FQty", FRealQty);
data.put("FPrice", outstock.getPrice()); data.put("FPrice", outstock.getPrice());
data.put("FStockId", FStockId); data.put("FStockId", wmsConfig.getfStockId());
String params = data.toJSONString(); String params = data.toJSONString();
R<AjaxResult> paramsResult = remoteJindieService.saveOtherOutStorage(params, SecurityConstants.INNER); R<AjaxResult> paramsResult = remoteJindieService.saveOtherOutStorage(params, SecurityConstants.INNER);
@ -246,7 +317,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
data.put("FUnitID", instock.getUnitCode()); data.put("FUnitID", instock.getUnitCode());
data.put("FQty", FRealQty); data.put("FQty", FRealQty);
data.put("FPrice", instock.getPrice()); data.put("FPrice", instock.getPrice());
data.put("FStockId", FStockId); data.put("FStockId", wmsConfig.getfStockId());
String params = data.toJSONString(); String params = data.toJSONString();
R<AjaxResult> paramsResult = remoteJindieService.saveOtherInStorage(params, SecurityConstants.INNER); R<AjaxResult> paramsResult = remoteJindieService.saveOtherInStorage(params, SecurityConstants.INNER);
String paramsResultData = paramsResult.getMsg(); String paramsResultData = paramsResult.getMsg();
@ -303,7 +374,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
data.put("FUnitID", outstock.getUnitCode()); data.put("FUnitID", outstock.getUnitCode());
data.put("FQty", FRealQty); data.put("FQty", FRealQty);
data.put("FPrice", outstock.getPrice()); data.put("FPrice", outstock.getPrice());
data.put("FStockId", FStockId); data.put("FStockId", wmsConfig.getfStockId());
data.put("FTONDCombo", "一般领料"); data.put("FTONDCombo", "一般领料");
String params = data.toJSONString(); String params = data.toJSONString();
R<AjaxResult> paramsResult = remoteJindieService.saveOtherOutStorage(params, SecurityConstants.INNER); R<AjaxResult> paramsResult = remoteJindieService.saveOtherOutStorage(params, SecurityConstants.INNER);

@ -30,8 +30,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="materialCode" column="material_code" /> <result property="materialCode" column="material_code" />
<result property="materialName" column="material_name" /> <result property="materialName" column="material_name" />
<result property="materialSpec" column="material_spec" /> <result property="materialSpec" column="material_spec" />
<result property="purchaseOrderId" column="purchase_order_id" />
<result property="unitCode" column="unit_code" />
</resultMap> </resultMap>
<sql id="selectWmsRawReturnDetailVo"> <sql id="selectWmsRawReturnDetailVo">
select raw_return_detail_id, raw_return_id, location_code, material_barcode, material_id, instock_batch, material_production_Date, plan_amount, return_amount, execute_status, erp_status, return_person, return_time, return_way, machine_name, quality_status, create_by, create_date, update_by, update_date, stack_amount from wms_raw_return_detail select raw_return_detail_id, raw_return_id, location_code, material_barcode, material_id, instock_batch, material_production_Date, plan_amount, return_amount, execute_status, erp_status, return_person, return_time, return_way, machine_name, quality_status, create_by, create_date, update_by, update_date, stack_amount from wms_raw_return_detail
</sql> </sql>
@ -204,4 +209,31 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="stackAmount != null "> and stack_amount = #{stackAmount}</if> <if test="stackAmount != null "> and stack_amount = #{stackAmount}</if>
</where> </where>
</select> </select>
<select id="selectWmsRawReturnDetailERPNotSynchronized" parameterType="WmsRawReturnDetail" resultMap="WmsRawReturnDetailResult">
select wrrd.raw_return_detail_id,
wrrd.material_id,
mbbi.purchase_order_id,
mbmi.material_spec,
mbmi.material_code,
mbui.unit_code,
wrrd.return_amount,
if(wrrd.erp_amount is null, 0, wrrd.erp_amount) erp_amount,
wrrd.erp_status
from wms_raw_return_detail wrrd
left join mes_base_material_info mbmi on mbmi.material_id = wrrd.material_id
left join mes_base_unit_info mbui on mbui.erp_id = mbmi.material_unit_id
left join mes_base_barcode_info mbbi on wrrd.material_barcode = mbbi.barcode_info
where wrrd.execute_status = 2
and wrrd.return_amount > if(wrrd.erp_amount is null, 0, wrrd.erp_amount)
and mbbi.purchase_order_id is not null and mbbi.purchase_order_id !=0
and mbmi.material_classfication = '1'
and mbmi.material_unit_id is not null and mbmi.material_unit_id !=''
</select>
</mapper> </mapper>

Loading…
Cancel
Save