change - 定时同步原材料出库信息给ERP

master
yinq 4 months ago
parent 9e38595fb0
commit fdb75b7a27

@ -47,4 +47,9 @@ public interface RemoteJindieService {
/** 采购入库单保存->提交->审核*/
@PostMapping("/jindie/savePurchaseStorage")
R<AjaxResult> savePurchaseStorage(@RequestBody String params, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/** 其他出库单保存->提交->审核*/
@PostMapping("/jindie/saveOtherOutStorage")
R<AjaxResult> saveOtherOutStorage(@RequestBody String params, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
}

@ -50,6 +50,11 @@ public class RemoteJindieFallbackFactory implements FallbackFactory<RemoteJindie
public R<AjaxResult> savePurchaseStorage(String params, String source) {
return R.fail("采购入库单同步失败:" + throwable.getMessage());
}
@Override
public R<AjaxResult> saveOtherOutStorage(String params, String source) {
return R.fail("其他出库单同步失败:" + throwable.getMessage());
}
};
}
}

@ -21,6 +21,12 @@ public interface RemoteWmsService {
@PostMapping("/api/synchronizeInventoryInformationToERP")
public R<AjaxResult> synchronizeInventoryInformationToERP(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/**
* ERP
* @param source
* @return
*/
@PostMapping("/api/synchronizeRawMaterialDeliveryInformationToERP")
public R<AjaxResult> synchronizeRawMaterialDeliveryInformationToERP(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
}

@ -26,6 +26,11 @@ public class RemoteWmsFallbackFactory implements FallbackFactory<RemoteWmsServic
public R<AjaxResult> synchronizeInventoryInformationToERP(String source) {
return R.fail("定时同步入库信息给ERP失败:" + throwable.getMessage());
}
@Override
public R<AjaxResult> synchronizeRawMaterialDeliveryInformationToERP(String source) {
return R.fail("定时同步原材料出库给ERP失败:" + throwable.getMessage());
}
};
}
}

@ -178,6 +178,18 @@ public class MesSaleOrder extends BaseEntity {
private String tondBase;
/**
*
*/
private String specificationParameter;
public String getSpecificationParameter() {
return specificationParameter;
}
public void setSpecificationParameter(String specificationParameter) {
this.specificationParameter = specificationParameter;
}
public Long getStockId() {
return stockId;

@ -479,8 +479,8 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
JSONObject queryJson = new JSONObject();
String formId = "SAL_SaleOrder";
String fieldKeys = "FID,FBillNo,FApproveDate,FSaleOrderEntry_FEntryID,FSaleOrderEntry_FMaterialModel,FMaterialId,FMaterialId.FNumber,FMaterialName,FDocumentStatus," +
"FQty,FCreateDate,FModifyDate,FMinPlanDeliveryDate,FAuxPropId,FStockId,FOwnerId,FSaleDeptId,FPrice,FStockOrgId,F_TOND_Base";
String fieldKeys = "FID,FBillNo,FApproveDate,FSaleOrderEntry_FEntryID,FMaterialModel,FMaterialId,FMaterialId.FNumber,FMaterialName,FDocumentStatus," +
"FQty,FCreateDate,FModifyDate,FMinPlanDeliveryDate,FAuxPropId,FAUXPROPID.FF100001,FStockId,FOwnerId,FSaleDeptId,FPrice,FStockOrgId,F_TOND_Base";
//
// String filterString = "FNumber='98010102'";
// String filterString = "";
@ -542,6 +542,8 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
String planDeliveryDate = resultObject.getString("FMinPlanDeliveryDate");
//辅助属性
Long auxPropId = resultObject.getLong("FAuxPropId");
//规格参数
String FF100001 = resultObject.getString("FAUXPROPID.FF100001");
//仓库
Long stockId = resultObject.getLong("FStockId");
//货主
@ -568,6 +570,7 @@ public class KingdeeErpSyncServiceImpl implements IKingdeeErpSyncService {
mesSaleOrder.setMaterialName(materialName);
mesSaleOrder.setOrderAmount(orderAmount);
mesSaleOrder.setAuxPropId(auxPropId);
mesSaleOrder.setSpecificationParameter(FF100001);
mesSaleOrder.setStockId(stockId);
mesSaleOrder.setOwnerId(ownerId);
mesSaleOrder.setSaleDeptId(saleDeptId);

@ -41,6 +41,7 @@
<result property="price" column="price"/>
<result property="stockOrgId" column="stock_org_id"/>
<result property="tondBae" column="tond_base"/>
<result property="specificationParameter" column="specification_parameter"/>
</resultMap>
<sql id="selectMesSaleOrderVo">
@ -74,6 +75,7 @@
update_by,
update_time,
aux_prop_id,
specification_parameter,
stock_id,
sale_dept_id,
owner_id,
@ -157,6 +159,7 @@
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="auxPropId != null">aux_prop_id,</if>
<if test="specificationParameter != null">specification_parameter,</if>
<if test="stockId != null">stock_id,</if>
<if test="saleDeptId != null">sale_dept_id,</if>
<if test="ownerId != null">owner_id,</if>
@ -193,6 +196,7 @@
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="auxPropId != null">#{auxPropId},</if>
<if test="specificationParameter != null">#{specificationParameter},</if>
<if test="stockId != null">#{stockId},</if>
<if test="saleDeptId != null">#{saleDeptId},</if>
<if test="ownerId != null">#{ownerId},</if>
@ -233,6 +237,7 @@
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="auxPropId != null">aux_prop_id=#{auxPropId},</if>
<if test="specificationParameter != null">specification_parameter=#{specificationParameter},</if>
<if test="stockId != null">stock_id=#{stockId},</if>
<if test="saleDeptId != null">sale_dept_id=#{saleDeptId},</if>
<if test="ownerId != null">owner_id=#{ownerId},</if>
@ -273,9 +278,9 @@
<insert id="batchMesBaseSaleOrder">
INSERT INTO mes_sale_order (erp_id, fentry_id, saleorder_code, saleorder_linenumber, document_status, material_id, material_code, material_name, matkl, order_amount, complete_amount, release_qty, approve_date, erp_modify_date, plan_delivery_date, stock_id, owner_id, aux_prop_id, sale_dept_id, price, stock_org_id, tond_base, create_time,update_time) VALUES
INSERT INTO mes_sale_order (erp_id, fentry_id, saleorder_code, saleorder_linenumber, document_status, material_id, material_code, material_name, matkl, order_amount, complete_amount, release_qty, approve_date, erp_modify_date, plan_delivery_date, stock_id, owner_id, aux_prop_id, specification_parameter, sale_dept_id, price, stock_org_id, tond_base, create_time,update_time) VALUES
<foreach item="item" index="index" collection="list" separator=",">
(#{item.erpId}, #{item.fentryId}, #{item.saleorderCode}, #{item.saleorderLinenumber}, #{item.documentStatus}, #{item.materialId}, #{item.materialCode}, #{item.materialName}, #{item.matkl}, #{item.orderAmount}, #{item.completeAmount}, #{item.releaseQty}, #{item.approveDate}, #{item.erpModifyDate}, #{item.planDeliveryDate}, #{item.stockId}, #{item.ownerId}, #{item.auxPropId}, #{item.saleDeptId}, #{item.price}, #{item.stockOrgId}, #{item.tondBase}, #{item.createTime}, #{item.updateTime})
(#{item.erpId}, #{item.fentryId}, #{item.saleorderCode}, #{item.saleorderLinenumber}, #{item.documentStatus}, #{item.materialId}, #{item.materialCode}, #{item.materialName}, #{item.matkl}, #{item.orderAmount}, #{item.completeAmount}, #{item.releaseQty}, #{item.approveDate}, #{item.erpModifyDate}, #{item.planDeliveryDate}, #{item.stockId}, #{item.ownerId}, #{item.auxPropId}, #{item.specificationParameter}, #{item.saleDeptId}, #{item.price}, #{item.stockOrgId}, #{item.tondBase}, #{item.createTime}, #{item.updateTime})
</foreach>
</insert>

@ -111,4 +111,9 @@ public class RyTask
System.out.println("++定时同步入库信息给ERP++ErpPurchaseOrder");
remoteWmsService.synchronizeInventoryInformationToERP(SecurityConstants.INNER);
}
public void syncRawMaterialDeliveryInformationToERP(){
System.out.println("++定时同步入库信息给ERP++ErpPurchaseOrder");
remoteWmsService.synchronizeRawMaterialDeliveryInformationToERP(SecurityConstants.INNER);
}
}

@ -191,4 +191,13 @@ public class WmsApiController extends BaseController {
return toAjax(wmsErpScheduledTaskService.synchronizeInventoryInformationToERP());
}
/**
* ERP
* @return
*/
@PostMapping(("/synchronizeRawMaterialDeliveryInformationToERP"))
public AjaxResult synchronizeRawMaterialDeliveryInformationToERP() {
return toAjax(wmsErpScheduledTaskService.synchronizeRawMaterialDeliveryInformationToERP());
}
}

@ -220,6 +220,39 @@ public class WmsRawOutstock extends BaseEntity {
*/
private List<WmsRawOutstockDetail> wmsRawOutstockDetailList;
/** 单价 */
private BigDecimal price;
/** 规格参数 */
private String specificationParameter;
/** 计量单位编号 */
private String unitCode;
public String getUnitCode() {
return unitCode;
}
public void setUnitCode(String unitCode) {
this.unitCode = unitCode;
}
public String getSpecificationParameter() {
return specificationParameter;
}
public void setSpecificationParameter(String specificationParameter) {
this.specificationParameter = specificationParameter;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public void setRawOutstockId(Long rawOutstockId) {
this.rawOutstockId = rawOutstockId;
}

@ -146,4 +146,11 @@ public interface WmsRawOutstockMapper
* @return
*/
public WmsRawOutstock selectNewestWmsRawOutstock(WmsRawOutstock wmsRawOutstock);
/**
* ERPList
* @param rawOutstock
* @return
*/
List<WmsRawOutstock> selectWmsRawOutstockERPNotSynchronized(WmsRawOutstock rawOutstock);
}

@ -16,5 +16,9 @@ public interface IWmsErpScheduledTaskService {
*/
int synchronizeInventoryInformationToERP();
/**
* ERP
* @return
*/
int synchronizeRawMaterialDeliveryInformationToERP();
}

@ -7,7 +7,9 @@ import com.hw.common.core.utils.DateUtils;
import com.hw.common.core.web.domain.AjaxResult;
import com.hw.jindie.api.RemoteJindieService;
import com.hw.wms.domain.WmsRawInstock;
import com.hw.wms.domain.WmsRawOutstock;
import com.hw.wms.mapper.WmsRawInstockMapper;
import com.hw.wms.mapper.WmsRawOutstockMapper;
import com.hw.wms.service.IWmsErpScheduledTaskService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -34,6 +36,9 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
@Autowired
private WmsRawInstockMapper wmsRawInstockMapper;
@Autowired
private WmsRawOutstockMapper wmsRawOutstockMapper;
@Autowired
private RemoteJindieService remoteJindieService;
@ -89,4 +94,57 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
}
}
/**
* ERP
* @return
*/
@Override
public int synchronizeRawMaterialDeliveryInformationToERP() {
WmsRawOutstock rawOutstock = new WmsRawOutstock();
int result = 0;
List<WmsRawOutstock> outStockList = wmsRawOutstockMapper.selectWmsRawOutstockERPNotSynchronized(rawOutstock);
Map<Long, List<WmsRawOutstock>> materialIdMap = outStockList.stream().collect(Collectors.groupingBy(WmsRawOutstock::getMaterialId));
for (Long materialId : materialIdMap.keySet()) {
syncOutstockInformation(materialIdMap, materialId, result);
}
return result;
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
void syncOutstockInformation(Map<Long, List<WmsRawOutstock>> materialIdMap, Long materialId, int result) {
List<WmsRawOutstock> wmsRawOutstockList = materialIdMap.get(materialId);
JSONObject data = new JSONObject();
double FRealQty = wmsRawOutstockList.stream().mapToDouble(item -> item.getRealOutstockAmount().subtract(item.getErpAmount()).doubleValue()).sum();
WmsRawOutstock outstock = wmsRawOutstockList.get(0);
data.put("FDate", DateUtils.getTime());
data.put("FMaterialId", outstock.getMaterialCode());
data.put("FAuxPropId", outstock.getSpecificationParameter());
data.put("FUnitID", outstock.getUnitCode());
data.put("FQty", FRealQty);
data.put("FPrice", outstock.getPrice());
data.put("FStockId", FStockId);
String params = data.toJSONString();
R<AjaxResult> paramsResult = remoteJindieService.saveOtherOutStorage(params, SecurityConstants.INNER);
String paramsResultData = paramsResult.getMsg();
JSONObject jsonObject = JSONObject.parseObject(paramsResultData);
Boolean isSuccess = (Boolean) jsonObject.get("IsSuccess");
if (isSuccess) {
result++;
for (WmsRawOutstock wmsRawOutstock : wmsRawOutstockList) {
if (wmsRawOutstock.getRealOutstockAmount().equals(wmsRawOutstock.getOutstockAmount())){
wmsRawOutstock.setErpStatus("1");//同步ERP状态(0:失败,1成功,2同步中)
} else {
wmsRawOutstock.setErpStatus("2");//同步ERP状态(0:失败,1成功,2同步中)
}
wmsRawOutstock.setErpAmount(wmsRawOutstock.getRealOutstockAmount());
wmsRawOutstock.setUpdateDate(DateUtils.getNowDate());
wmsRawOutstockMapper.updateWmsRawOutstock(wmsRawOutstock);
}
log.info("synchronizeRawMaterialDeliveryInformationToERP成功:" + paramsResult.toString());
} else {
log.error("synchronizeRawMaterialDeliveryInformationToERP失败:" + paramsResult.toString());
}
}
}

@ -45,6 +45,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="planAmount" column="plan_amount" />
<result property="instockBatch" column="instock_batch" />
<result property="rawOutstockDetailId" column="raw_outstock_detail_id" />
<result property="price" column="price" />
<result property="unitCode" column="unit_code" />
<result property="specificationParameter" column="specification_parameter" />
</resultMap>
<resultMap id="WmsRawOutstockWmsRawOutstockDetailResult" type="WmsRawOutstock" extends="WmsRawOutstockResult">
@ -350,4 +353,31 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by wro.raw_outstock_id desc limit 1
</select>
<select id="selectWmsRawOutstockERPNotSynchronized" parameterType="WmsRawOutstock" resultMap="WmsRawOutstockResult">
select wro.raw_outstock_id,
wro.task_code,
wro.warehouse_id,
wbw.warehouse_code,
wro.operation_type,
wro.material_id,
mbmi.material_code,
mbui.unit_code,
wro.outstock_amount,
wro.real_outstock_amount,
if(wro.erp_amount is null, 0, wro.erp_amount) erp_amount,
wro.erp_status,
mso.price,
mso.specification_parameter
from wms_raw_outstock wro
left join wms_base_warehouse wbw on wbw.warehouse_id = wro.warehouse_id
left join mes_base_material_info mbmi on mbmi.material_id = wro.material_id
left join mes_base_unit_info mbui on mbui.erp_id = mbmi.material_unit_id
left join mes_product_plan mpp on mpp.plan_code = wro.plan_code
left join mes_sale_order mso on mso.sale_order_id = mpp.sale_order_id
where wro.real_outstock_amount > 0
and wro.outstock_amount >= wro.real_outstock_amount
and wro.real_outstock_amount > if(wro.erp_amount is null, 0, wro.erp_amount)
and wro.task_type in (1, 3, 9)
</select>
</mapper>

Loading…
Cancel
Save