change - add同步成品出、入库信息到ERP

master
yinq 3 months ago
parent 977d455677
commit 34a4cfd363

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

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

@ -6,15 +6,17 @@ import com.hw.common.core.domain.R;
import com.hw.common.core.web.domain.AjaxResult;
import com.hw.wms.api.factory.RemoteWmsFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
@FeignClient(contextId = "remoteWmsService", value = ServiceNameConstants.WMS_SERVICE, fallbackFactory = RemoteWmsFallbackFactory.class)
public interface RemoteWmsService {
/**
* ERP
* ERP
* @param source
* @return
*/
@ -29,4 +31,22 @@ public interface RemoteWmsService {
@PostMapping("/api/synchronizeRawMaterialDeliveryInformationToERP")
public R<AjaxResult> synchronizeRawMaterialDeliveryInformationToERP(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/**
* ERP
* @param days
* @param source
* @return
*/
@PostMapping("/api/synchronizeProductInstockInformationToERP/{days}")
public R<AjaxResult> synchronizeProductInstockInformationToERP(@PathVariable("days") Integer days, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/**
* ERP
* @param days
* @param source
* @return
*/
@PostMapping("/api/synchronizeProductOutstockInformationToERP/{days}")
public R<AjaxResult> synchronizeProductOutstockInformationToERP(@PathVariable("days") Integer days, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
}

@ -24,13 +24,23 @@ public class RemoteWmsFallbackFactory implements FallbackFactory<RemoteWmsServic
return new RemoteWmsService() {
@Override
public R<AjaxResult> synchronizeInventoryInformationToERP(String source) {
return R.fail("定时同步入库信息给ERP失败:" + throwable.getMessage());
return R.fail("定时同步原材料入库信息给ERP失败:" + throwable.getMessage());
}
@Override
public R<AjaxResult> synchronizeRawMaterialDeliveryInformationToERP(String source) {
return R.fail("定时同步原材料出库给ERP失败:" + throwable.getMessage());
}
@Override
public R<AjaxResult> synchronizeProductInstockInformationToERP(Integer days, String inner) {
return R.fail("定时同步成品入库给ERP失败:" + throwable.getMessage());
}
@Override
public R<AjaxResult> synchronizeProductOutstockInformationToERP(Integer days, String source) {
return R.fail("定时同步成品出库给ERP失败:" + throwable.getMessage());
}
};
}
}

@ -6,6 +6,7 @@ import com.hw.ems.api.RemoteEmsService;
import com.hw.jindie.api.RemoteJindieService;
import com.hw.jindie.api.domain.vo.ErpSyncInfoVo;
import com.hw.wms.api.RemoteWmsService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.hw.common.core.utils.StringUtils;
@ -103,17 +104,27 @@ public class RyTask
public void syncPurchaseOrderFromErp(String maxErpModifyDate){
ErpSyncInfoVo erpSyncInfoVo = new ErpSyncInfoVo();
erpSyncInfoVo.setMaxErpModifyDate(maxErpModifyDate);
System.out.println("++同步ERP中采购订单信息++ErpPurchaseOrder");
System.out.println("++同步ERP中采购订单信息++syncPurchaseOrderFromErp");
remoteJindieService.syncPurchaseOrderFromErp(erpSyncInfoVo,SecurityConstants.INNER);
}
public void syncInventoryInformationToERP(){
System.out.println("++定时同步入库信息给ERP++ErpPurchaseOrder");
System.out.println("++定时同步原材料入库信息给ERP++syncInventoryInformationToERP");
remoteWmsService.synchronizeInventoryInformationToERP(SecurityConstants.INNER);
}
public void syncRawMaterialDeliveryInformationToERP(){
System.out.println("++定时同步入库信息给ERP++ErpPurchaseOrder");
System.out.println("++定时同步原材料入库信息给ERP++syncRawMaterialDeliveryInformationToERP");
remoteWmsService.synchronizeRawMaterialDeliveryInformationToERP(SecurityConstants.INNER);
}
public void synchronizeProductInstockInformationToERP(Integer days){
System.out.println("++定时同步成品入库信息给ERP++synchronizeProductInstockInformationToERP");
remoteWmsService.synchronizeProductInstockInformationToERP(days, SecurityConstants.INNER);
}
public void synchronizeProductOutstockInformationToERP(Integer days){
System.out.println("++定时同步成品出库信息给ERP++synchronizeProductOutstockInformationToERP");
remoteWmsService.synchronizeProductOutstockInformationToERP(days, SecurityConstants.INNER);
}
}

@ -200,4 +200,24 @@ public class WmsApiController extends BaseController {
return toAjax(wmsErpScheduledTaskService.synchronizeRawMaterialDeliveryInformationToERP());
}
/**
* ERP
* @param days days
* @return
*/
@PostMapping(("/synchronizeProductInstockInformationToERP/{days}"))
public AjaxResult synchronizeProductInstockInformationToERP(@PathVariable Integer days) {
return toAjax(wmsErpScheduledTaskService.synchronizeProductInstockInformationToERP(days));
}
/**
* ERP
* @param days days
* @return
*/
@PostMapping(("/synchronizeProductOutstockInformationToERP/{days}"))
public AjaxResult synchronizeProductOutstockInformationToERP(@PathVariable Integer days) {
return toAjax(wmsErpScheduledTaskService.synchronizeProductOutstockInformationToERP(days));
}
}

@ -172,6 +172,46 @@ public class WmsProductInstock extends BaseEntity {
*/
private List<WmsProductInstockDetail> wmsProductInstockDetailList;
private BigDecimal price;
private String specificationParameter;
private String unitCode;
private String materialCode;
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public String getSpecificationParameter() {
return specificationParameter;
}
public void setSpecificationParameter(String specificationParameter) {
this.specificationParameter = specificationParameter;
}
public String getUnitCode() {
return unitCode;
}
public void setUnitCode(String unitCode) {
this.unitCode = unitCode;
}
public String getMaterialCode() {
return materialCode;
}
public void setMaterialCode(String materialCode) {
this.materialCode = materialCode;
}
public void setProductInstockId(Long productInstockId) {
this.productInstockId = productInstockId;
}

@ -153,14 +153,41 @@ public class WmsProductOutstock extends BaseEntity {
private String materialName;
private BigDecimal price;
private String specificationParameter;
private String unitCode;
/**
*
*/
private List<WmsProductOutstockDetail> wmsProductOutstockDetailList;
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public String getSpecificationParameter() {
return specificationParameter;
}
public void setSpecificationParameter(String specificationParameter) {
this.specificationParameter = specificationParameter;
}
public String getUnitCode() {
return unitCode;
}
public void setUnitCode(String unitCode) {
this.unitCode = unitCode;
}
public void setProductOutstockId(Long productOutstockId) {
this.productOutstockId = productOutstockId;
}

@ -84,4 +84,11 @@ public interface WmsProductInstockMapper
* @return
*/
public int deleteWmsProductInstockDetailByProductInstockId(Long productInstockId);
/**
* ERPList
* @param wmsProductInstock
* @return
*/
List<WmsProductInstock> selectWmsProductInstockERPNotSynchronized(WmsProductInstock wmsProductInstock);
}

@ -113,4 +113,10 @@ public interface WmsProductOutstockMapper
*/
public WmsProductOutstock selectOnlyWmsProductOutstockByOutstockId(Long productOutstockId);
/**
* ERPList
* @param wmsProductOutstock
* @return
*/
List<WmsProductOutstock> selectWmsProductOutstockERPNotSynchronized(WmsProductOutstock wmsProductOutstock);
}

@ -21,4 +21,19 @@ public interface IWmsErpScheduledTaskService {
* @return
*/
int synchronizeRawMaterialDeliveryInformationToERP();
/**
* ERP
* @param days days
* @return
*/
int synchronizeProductInstockInformationToERP(Integer days);
/**
* ERP
* @param days days
* @return
*/
int synchronizeProductOutstockInformationToERP(Integer days);
}

@ -6,8 +6,12 @@ import com.hw.common.core.domain.R;
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.WmsProductInstock;
import com.hw.wms.domain.WmsProductOutstock;
import com.hw.wms.domain.WmsRawInstock;
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;
@ -18,8 +22,9 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -39,6 +44,12 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
@Autowired
private WmsRawOutstockMapper wmsRawOutstockMapper;
@Autowired
private WmsProductInstockMapper wmsProductInstockMapper;
@Autowired
private WmsProductOutstockMapper wmsProductOutstockMapper;
@Autowired
private RemoteJindieService remoteJindieService;
@ -96,6 +107,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
/**
* ERP
*
* @return
*/
@Override
@ -131,7 +143,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
if (isSuccess) {
result++;
for (WmsRawOutstock wmsRawOutstock : wmsRawOutstockList) {
if (wmsRawOutstock.getRealOutstockAmount().equals(wmsRawOutstock.getOutstockAmount())){
if (wmsRawOutstock.getRealOutstockAmount().equals(wmsRawOutstock.getOutstockAmount())) {
wmsRawOutstock.setErpStatus("1");//同步ERP状态(0:失败,1成功,2同步中)
} else {
wmsRawOutstock.setErpStatus("2");//同步ERP状态(0:失败,1成功,2同步中)
@ -144,7 +156,134 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
} else {
log.error("synchronizeRawMaterialDeliveryInformationToERP失败:" + paramsResult.toString());
}
}
/**
* ERP
* @param days days
* @return
*/
@Override
public int synchronizeProductInstockInformationToERP(Integer days) {
int result = 0;
WmsProductInstock wmsProductInstock = new WmsProductInstock();
HashMap<String, Object> paramMap = new HashMap<>();
String beginTime= subtractDaysFromCurrentDate(days);
paramMap.put("beginTime", beginTime);
paramMap.put("endTime", DateUtils.getTime());
wmsProductInstock.setParams(paramMap);
List<WmsProductInstock> productInstockList = wmsProductInstockMapper.selectWmsProductInstockERPNotSynchronized(wmsProductInstock);
Map<Long, List<WmsProductInstock>> productIdMap = productInstockList.stream().collect(Collectors.groupingBy(WmsProductInstock::getProductId));
for (Long productId : productIdMap.keySet()) {
syncProductInstockInformation(productIdMap, productId, result);
}
return result;
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
void syncProductInstockInformation(Map<Long, List<WmsProductInstock>> productIdMap, Long productId, int result) {
List<WmsProductInstock> wmsProductInstockList = productIdMap.get(productId);
JSONObject data = new JSONObject();
double FRealQty = wmsProductInstockList.stream().mapToDouble(item -> item.getInstockAmount().subtract(item.getErpAmount()).doubleValue()).sum();
WmsProductInstock instock = wmsProductInstockList.get(0);
data.put("FDate", DateUtils.getTime());
data.put("FMaterialId", instock.getMaterialCode());
data.put("FAuxPropId", instock.getSpecificationParameter());
data.put("FUnitID", instock.getUnitCode());
data.put("FQty", FRealQty);
data.put("FPrice", instock.getPrice());
data.put("FStockId", FStockId);
String params = data.toJSONString();
R<AjaxResult> paramsResult = remoteJindieService.saveOtherInStorage(params, SecurityConstants.INNER);
String paramsResultData = paramsResult.getMsg();
JSONObject jsonObject = JSONObject.parseObject(paramsResultData);
Boolean isSuccess = (Boolean) jsonObject.get("IsSuccess");
if (isSuccess) {
result++;
for (WmsProductInstock wmsProductInstock : wmsProductInstockList) {
wmsProductInstock.setErpStatus("1");//同步ERP状态(0:失败,1成功)
wmsProductInstock.setErpAmount(wmsProductInstock.getInstockAmount());
wmsProductInstock.setUpdateDate(DateUtils.getNowDate());
wmsProductInstockMapper.updateWmsProductInstock(wmsProductInstock);
}
log.info("synchronizeProductInstockInformationToERP成功:" + paramsResult.toString());
} else {
log.error("synchronizeProductInstockInformationToERP失败:" + paramsResult.toString());
}
}
/**
* ERP
* @param days days
* @return
*/
@Override
public int synchronizeProductOutstockInformationToERP(Integer days) {
int result = 0;
WmsProductOutstock wmsProductOutstock = new WmsProductOutstock();
HashMap<String, Object> paramMap = new HashMap<>();
String beginTime= subtractDaysFromCurrentDate(days);
paramMap.put("beginTime", beginTime);
paramMap.put("endTime", DateUtils.getTime());
wmsProductOutstock.setParams(paramMap);
List<WmsProductOutstock> productOutstockList = wmsProductOutstockMapper.selectWmsProductOutstockERPNotSynchronized(wmsProductOutstock);
Map<Long, List<WmsProductOutstock>> productIdMap = productOutstockList.stream().collect(Collectors.groupingBy(WmsProductOutstock::getProductId));
for (Long productId : productIdMap.keySet()) {
syncProductOutstockInformation(productIdMap, productId, result);
}
return result;
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
void syncProductOutstockInformation(Map<Long, List<WmsProductOutstock>> productIdMap, Long productId, int result) {
List<WmsProductOutstock> wmsProductOutstockList = productIdMap.get(productId);
JSONObject data = new JSONObject();
double FRealQty = wmsProductOutstockList.stream().mapToDouble(item -> item.getOutstockQty().subtract(item.getErpAmount()).doubleValue()).sum();
WmsProductOutstock outstock = wmsProductOutstockList.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 (WmsProductOutstock wmsProductOutstock : wmsProductOutstockList) {
wmsProductOutstock.setErpStatus("1");//同步ERP状态(0:失败,1成功)
wmsProductOutstock.setErpAmount(wmsProductOutstock.getOutstockQty());
wmsProductOutstock.setUpdateDate(DateUtils.getNowDate());
wmsProductOutstockMapper.updateWmsProductOutstock(wmsProductOutstock);
}
log.info("synchronizeProductOutstockInformationToERP成功:" + paramsResult.toString());
} else {
log.error("synchronizeProductOutstockInformationToERP失败:" + paramsResult.toString());
}
}
/**
*
*
* @param daysToSubtract 180
* @return
*/
public static String subtractDaysFromCurrentDate(Integer daysToSubtract) {
// 如果 daysToSubtract 为空,则默认为 180 天
daysToSubtract = Optional.ofNullable(daysToSubtract).orElse(180);
// 获取当前日期时间
LocalDateTime currentDateTime = LocalDateTime.now();
// 减去指定的天数
LocalDateTime resultDateTime = currentDateTime.minusDays(daysToSubtract);
// 定义日期时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 格式化结果日期时间
return resultDateTime.format(formatter);
}
}

@ -32,6 +32,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="endTime" column="end_time" />
<result property="erpStatus" column="erp_status" />
<result property="erpAmount" column="erp_amount" />
<result property="unitCode" column="unit_code" />
<result property="price" column="price" />
<result property="specificationParameter" column="specification_parameter" />
<result property="materialCode" column="material_code" />
</resultMap>
<resultMap id="WmsProductInstockWmsProductInstockDetailResult" type="WmsProductInstock" extends="WmsProductInstockResult">
@ -216,4 +220,36 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
( #{item.productInstockDetailId}, #{item.productInstockId}, #{item.locationCode}, #{item.productId}, #{item.productBarcode}, #{item.productBatch}, #{item.executeStatus}, #{item.erpStatus}, #{item.planAmount}, #{item.instockAmount}, #{item.instockBy}, #{item.instockDate}, #{item.instockWay}, #{item.updateBy}, #{item.updateDate})
</foreach>
</insert>
<select id="selectWmsProductInstockERPNotSynchronized" parameterType="WmsProductInstock" resultMap="WmsProductInstockResult">
select wpi.product_instock_id,
wpi.task_code,
wpi.warehouse_id,
wpi.warehouse_floor,
wpi.location_code,
wpi.product_type,
wpi.plan_code,
wpi.instock_type,
wpi.product_id,
wpi.instock_amount,
wpi.execute_status,
wpi.erp_status,
if(wpi.erp_amount is null, 0, wpi.erp_amount) erp_amount,
mbmi.material_code,
mbui.unit_code,
mso.price,
mso.specification_parameter
from wms_product_instock wpi
left join mes_base_material_info mbmi on mbmi.material_id = wpi.product_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 = wpi.plan_code
left join mes_sale_order mso on mso.sale_order_id = mpp.sale_order_id
where wpi.product_type = '3'
and wpi.execute_status = '2'
and (wpi.erp_status is null or wpi.erp_status != '1')
and wpi.instock_type = '1'
<if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
and wpi.apply_date between #{beginTime} and #{endTime}
</if>
</select>
</mapper>

@ -41,6 +41,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="warehouseName" column="warehouse_name" />
<result property="materialCode" column="material_code" />
<result property="materialName" column="material_name" />
<result property="specificationParameter" column="specification_parameter" />
<result property="unitCode" column="unit_code" />
<result property="price" column="price" />
</resultMap>
<resultMap id="WmsProductOutstockWmsProductOutstockDetailResult" type="WmsProductOutstock" extends="WmsProductOutstockResult">
@ -290,4 +293,36 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where a.product_outstock_id = #{productOutstockId}
</select>
<select id="selectWmsProductOutstockERPNotSynchronized" parameterType="WmsProductOutstock" resultMap="WmsProductOutstockResult">
select wpo.product_outstock_id,
wpo.warehouse_id,
wpo.product_type,
wpo.operation_type,
wpo.outstock_type,
wpo.plan_code,
wpo.product_id,
wpo.apply_qty,
wpo.outstock_qty,
wpo.apply_by,
wpo.apply_date,
wpo.erp_status,
if(wpo.erp_amount is null, 0, wpo.erp_amount) erp_amount,
mbmi.material_code,
mbui.unit_code,
mso.price,
mso.specification_parameter
from wms_product_outstock wpo
left join mes_base_material_info mbmi on mbmi.material_id = wpo.product_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 = wpo.plan_code
left join mes_sale_order mso on mso.sale_order_id = mpp.sale_order_id
where wpo.outstock_type = '1'
and wpo.outstock_qty > 0
and wpo.apply_qty >= wpo.outstock_qty
and wpo.outstock_qty > if(wpo.erp_amount is null, 0, wpo.erp_amount)
<if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
and wpi.apply_date between #{beginTime} and #{endTime}
</if>
</select>
</mapper>

Loading…
Cancel
Save