物料同步
This commit is contained in:
parent
cf814c36d9
commit
d53c7ae117
|
@ -20,5 +20,9 @@ import java.util.List;
|
|||
public interface IZjMaterielSynchronizationEventDao extends IBaseDao<ZjMaterielSynchronizationEventEntity, String> {
|
||||
|
||||
List<InventoryEntity> queryInventoryEntity(ZjMaterielSynchronizationEventDto entity);
|
||||
|
||||
Integer queryMaxLsh(ZjMaterielSynchronizationEventEntity entity);
|
||||
|
||||
Integer updatewlbm(ZjMaterielSynchronizationEventEntity entity);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,5 +26,17 @@ public class ZjMaterielSynchronizationEventDaoImpl extends MybatisGenericDao<ZjM
|
|||
public List<InventoryEntity> queryInventoryEntity(ZjMaterielSynchronizationEventDto entity) {
|
||||
return (List<InventoryEntity>) super.selectList(getSqlIdPrifx() + "queryInventoryEntity",entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@DS("#entity.dataSourceCode")
|
||||
public Integer queryMaxLsh(ZjMaterielSynchronizationEventEntity entity) {
|
||||
return super.getCount(getSqlIdPrifx() + "queryMaxLsh",entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@DS("#entity.dataSourceCode")
|
||||
public Integer updatewlbm(ZjMaterielSynchronizationEventEntity entity) {
|
||||
return super.update(getSqlIdPrifx() + "updatewlbm",entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,5 +29,23 @@
|
|||
</if>
|
||||
</trim>
|
||||
</select>
|
||||
|
||||
<select id="queryMaxLsh" resultType="java.lang.Integer"
|
||||
parameterType = "com.hzya.frame.plugin.zjmaterielsynchronizationevent.entity.ZjMaterielSynchronizationEventDto">
|
||||
SELECT max(cInvCode) from Inventory
|
||||
<trim prefix="where" prefixOverrides="and">
|
||||
<if test="field0043code != null and field0043code != ''"> and cInvCCode = #{field0043code} and cInvCode like concat(#{field0043code},'%') </if>
|
||||
</trim>
|
||||
</select>
|
||||
|
||||
|
||||
<update id="entity_update" parameterType="com.hzya.frame.plugin.zjmaterielsynchronizationevent.entity.ZjMaterielSynchronizationEventEntity">
|
||||
update formson_0275 set
|
||||
<trim suffix="" suffixOverrides=",">
|
||||
<if test="field0005 != null and field0005 !='' ">field0005 =#{field0005},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
||||
|
|
|
@ -8,12 +8,18 @@ import com.hzya.frame.plugin.zjmaterielsynchronizationevent.entity.ZjMaterielSyn
|
|||
import com.hzya.frame.plugin.zjmaterielsynchronizationevent.service.IZjMaterielSynchronizationEventService;
|
||||
import com.hzya.frame.u8.base.inventory.dao.IInventoryDao;
|
||||
import com.hzya.frame.u8.base.inventory.entity.InventoryEntity;
|
||||
import com.hzya.frame.u8.base.inventory.service.IInventoryService;
|
||||
import com.hzya.frame.u8.base.inventory.service.impl.InventoryService;
|
||||
import com.hzya.frame.web.entity.BaseResult;
|
||||
import com.hzya.frame.web.entity.JsonResultEntity;
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -41,6 +47,8 @@ public class ZjMaterielSynchronizationEventServiceImpl extends BaseService<ZjMat
|
|||
|
||||
@Autowired
|
||||
private IInventoryDao inventoryDao;
|
||||
@Autowired
|
||||
private IInventoryService iInventoryService;
|
||||
private String zjoa = "zjoa";
|
||||
private String zju8 = "zju8";
|
||||
|
||||
|
@ -52,6 +60,7 @@ public class ZjMaterielSynchronizationEventServiceImpl extends BaseService<ZjMat
|
|||
* @Date 11:39 上午 2025/3/17
|
||||
**/
|
||||
@Override
|
||||
@Transactional
|
||||
public JsonResultEntity materielSynchronization(JSONObject requestJson) {
|
||||
JSONObject reqJson = new JSONObject();
|
||||
JSONObject jsonStr = requestJson.getJSONObject("jsonStr");
|
||||
|
@ -71,7 +80,8 @@ public class ZjMaterielSynchronizationEventServiceImpl extends BaseService<ZjMat
|
|||
if(list == null || list.size() == 0){
|
||||
return BaseResult.getFailureMessageEntity("onBeforeStart流程监听事件,未获取到明细数据");
|
||||
}
|
||||
return checkData(list,false);
|
||||
List<InventoryEntity> inventoryEntities = null;
|
||||
return checkData(list,false,inventoryEntities);
|
||||
case "onProcessFinished"://流程结束事件,同步物料到U8C
|
||||
String id = getFormmain_id(businessDataStr);
|
||||
if(id == null || "".equals(id)){
|
||||
|
@ -84,7 +94,8 @@ public class ZjMaterielSynchronizationEventServiceImpl extends BaseService<ZjMat
|
|||
if(list1 == null || list1.size() == 0){
|
||||
return BaseResult.getFailureMessageEntity("onProcessFinished流程监听事件,未获取到明细数据");
|
||||
}
|
||||
JsonResultEntity jsonResultEntity = checkData(list1,true);
|
||||
List<InventoryEntity> inventoryEntities1 = null;
|
||||
JsonResultEntity jsonResultEntity = checkData(list1,true,inventoryEntities1);
|
||||
if(jsonResultEntity == null){
|
||||
return BaseResult.getFailureMessageEntity("onProcessFinished流程监听事件,校验发生系统错误");
|
||||
}
|
||||
|
@ -92,10 +103,14 @@ public class ZjMaterielSynchronizationEventServiceImpl extends BaseService<ZjMat
|
|||
return jsonResultEntity;
|
||||
}
|
||||
//组装数据,保存数据
|
||||
saveMaterielToU8(list1);
|
||||
try {
|
||||
saveMaterielToU8(list1,inventoryEntities1);
|
||||
//回写U8生成的编码
|
||||
updateOaCode(list1);
|
||||
return null;
|
||||
}catch (Exception e){
|
||||
throw new RuntimeException("保存u8数据错误:"+e.getMessage());
|
||||
}
|
||||
return BaseResult.getSuccessMessageEntity("保存u8成功");
|
||||
case "onStart"://流程发起 oa数据重新排序
|
||||
return BaseResult.getSuccessMessageEntity("排序暂不处理");
|
||||
default:
|
||||
|
@ -111,6 +126,15 @@ public class ZjMaterielSynchronizationEventServiceImpl extends BaseService<ZjMat
|
|||
* @return void
|
||||
**/
|
||||
private void updateOaCode(List<ZjMaterielSynchronizationEventEntity> list) {
|
||||
if(list != null && list.size() > 0){
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ZjMaterielSynchronizationEventEntity entity = list.get(i);
|
||||
if("新增".equals(entity.getField0018code()) || "增加替代".equals(entity.getField0018code()) || "升级".equals(entity.getField0018code())){
|
||||
entity.setDataSourceCode(zjoa);
|
||||
zjMaterielSynchronizationEventDao.updatewlbm(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -120,24 +144,137 @@ public class ZjMaterielSynchronizationEventServiceImpl extends BaseService<ZjMat
|
|||
* @param list
|
||||
* @return void
|
||||
**/
|
||||
private void saveMaterielToU8(List<ZjMaterielSynchronizationEventEntity> list) {
|
||||
private void saveMaterielToU8(List<ZjMaterielSynchronizationEventEntity> list,List<InventoryEntity> inventoryEntities) throws Exception {
|
||||
Map<String,Integer> lsh = new HashMap<>();//当前流水号
|
||||
List<InventoryEntity> savedata = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ZjMaterielSynchronizationEventEntity entity = list.get(i);
|
||||
//获取最大流水号
|
||||
Integer maxnum = 0;
|
||||
if(lsh.get(entity.getField0043code()) != null){
|
||||
maxnum = lsh.get(entity.getField0043code());
|
||||
}else {
|
||||
entity.setDataSourceCode(zju8);
|
||||
maxnum = zjMaterielSynchronizationEventDao.queryMaxLsh(entity);
|
||||
}
|
||||
StringBuffer wlcode = new StringBuffer();
|
||||
//设置编码
|
||||
if("新增".equals(entity.getField0018code()) || "增加替代".equals(entity.getField0018code()) || "升级".equals(entity.getField0018code())){
|
||||
if(entity.getField0043code().equals("12400")
|
||||
|| entity.getField0043code().equals("12500")
|
||||
|| entity.getField0043code().equals("12418")
|
||||
|| entity.getField0043code().equals("12001")
|
||||
|| entity.getField0043code().equals("12003")
|
||||
|| entity.getField0043code().equals("12005")){
|
||||
//货品分类(12400-贴片电阻, 12500-贴片电容, 12418-贴片检测电阻, 12001-单面板, 12003-双面板, 12005-多层板)
|
||||
//封装分类(贴片 0 , 其他 0 )
|
||||
//当前分类最大流水号
|
||||
//品牌(单据内填写品牌 01,未填写 00)
|
||||
//是否委外
|
||||
//是:勾选存货属性的委外,计划页面的委外属性
|
||||
//否:取消勾选勾选存货属性的”委外”,计划页面的委外属性设置成“采购”
|
||||
// 整体逻辑 12400物料分类 0贴片 002流水号 01品牌号
|
||||
//例:12400 0 002 01
|
||||
//货品分类以这几个开头的。封装分类是贴片,依然填0
|
||||
String formattedNum = String.format("%03d", ++maxnum);
|
||||
lsh.put(entity.getField0043code(),maxnum);
|
||||
wlcode.append(entity.getField0043code()).append("0").append(formattedNum);
|
||||
if(entity.getField0008code() != null && !"".equals(entity.getField0008code())){
|
||||
wlcode.append("01");
|
||||
}else {
|
||||
wlcode.append("00");
|
||||
}
|
||||
}else if(entity.getField0043code().startsWith("1") || entity.getField0043code().startsWith("4") || entity.getField0043code().startsWith("5")){
|
||||
//货品分类(区分是否是原材料通过分类首位1,4,5)
|
||||
//封装分类(贴片 9 , 其他 0 )
|
||||
//当前分类最大流水号
|
||||
//品牌(单据内填写品牌 01,未填写 00)
|
||||
//是否委外
|
||||
//是:勾选存货属性的委外,计划页面的委外属性
|
||||
//否:取消勾选勾选存货属性的”委外”,计划页面的委外属性设置成“采购”
|
||||
// 整体逻辑 12100物料分类 0非贴片 002流水号 01品牌号
|
||||
String formattedNum = String.format("%03d", ++maxnum);
|
||||
lsh.put(entity.getField0043code(),maxnum);
|
||||
wlcode.append(entity.getField0043code());
|
||||
if(entity.getField0017code() != null && "贴片".equals(entity.getField0017code())){
|
||||
wlcode.append("9");
|
||||
}else {
|
||||
wlcode.append("0");
|
||||
}
|
||||
wlcode.append(formattedNum);
|
||||
if(entity.getField0008code() != null && !"".equals(entity.getField0008code())){
|
||||
wlcode.append("01");
|
||||
}else {
|
||||
wlcode.append("00");
|
||||
}
|
||||
}else if(entity.getField0043code().startsWith("6") || entity.getField0043code().startsWith("7") || entity.getField0043code().startsWith("8") || entity.getField0043code().startsWith("8")){
|
||||
//货品分类(区分是否是”产品”通过分类首位6,7,8,9)
|
||||
//当前分类最大流水号(编码第6-9是顺序号)
|
||||
//最后2位默认11
|
||||
//整体逻辑 62100物料分类 0001流水 11默认
|
||||
//例:62100 0001 11
|
||||
String formattedNum = String.format("%04d", ++maxnum);
|
||||
lsh.put(entity.getField0043code(),maxnum);
|
||||
wlcode.append(entity.getField0043code());
|
||||
wlcode.append(formattedNum);
|
||||
wlcode.append("11");
|
||||
|
||||
}else if(entity.getField0043code().startsWith("A")){
|
||||
//货品分类(区分是”软件”通过分类首位A)
|
||||
//当前分类最大流水号(编码第6-10是顺序号)
|
||||
//最后1位默认1
|
||||
//整体逻辑 A0110物料分类 00001流水 1默认
|
||||
//例:A0110 00001 1
|
||||
String formattedNum = String.format("%05d", ++maxnum);
|
||||
lsh.put(entity.getField0043code(),maxnum);
|
||||
wlcode.append(entity.getField0043code());
|
||||
wlcode.append(formattedNum);
|
||||
wlcode.append("1");
|
||||
}
|
||||
}else if("修改".equals(entity.getField0018code())){
|
||||
wlcode.append(entity.getField0005());
|
||||
}
|
||||
//设置其他字段
|
||||
//物料编码
|
||||
InventoryEntity inventoryEntity = new InventoryEntity();
|
||||
//设置全部字段属性
|
||||
for (int i1 = 0; i1 < inventoryEntities.size(); i1++) {
|
||||
if(inventoryEntities.get(i1).getcInvCode().equals(entity.getField0043code())){
|
||||
BeanUtils.copyProperties(inventoryEntities.get(i1), inventoryEntity);
|
||||
}
|
||||
}
|
||||
entity.setField0005(wlcode.toString());
|
||||
//定制化字段
|
||||
inventoryEntity.setAcc_name("UFDATA_998_2014");
|
||||
inventoryEntity.setCacc_id("998");
|
||||
if("新增".equals(entity.getField0018code())){
|
||||
|
||||
}else if("增加替代".equals(entity.getField0018code())){
|
||||
|
||||
}else if("升级".equals(entity.getField0018code())){
|
||||
|
||||
inventoryEntity.setcInvCode(wlcode.toString());//物料编码
|
||||
inventoryEntity.setcInvCCode(entity.getField0043code());//物料中类
|
||||
inventoryEntity.setcInvAddCode(entity.getField0045());// 货品代码
|
||||
inventoryEntity.setcInvName(entity.getField0006());// 货品名称
|
||||
inventoryEntity.setcInvStd(entity.getField0007());// 货品规格
|
||||
//inventoryEntity.setcInvCCode(entity.getField0008code());// todo 品牌
|
||||
//inventoryEntity.setcInvCCode(entity.getField0034code());// todo 客户名
|
||||
//inventoryEntity.setcInvCCode(entity.getField0017code());// todo 工艺属性
|
||||
inventoryEntity.setcDefWareHouse(entity.getField0040code());// 仓库名称
|
||||
//inventoryEntity.setcInvCCode(entity.getField0012code());// todo 优选等级
|
||||
inventoryEntity.setbSrvItem(entity.getField0039());// 开发号
|
||||
//inventoryEntity.setcInvCCode(entity.getField0042code());// todo 物料属性
|
||||
inventoryEntity.setbProxyForeign(entity.getField0022code());// 是否委外
|
||||
//inventoryEntity.setcInvCCode(entity.getField0022code());// todo 计划属性字段不确定
|
||||
//inventoryEntity.setcInvCCode(entity.getField0033code());// todo 产品阶段
|
||||
//inventoryEntity.setcInvCCode(entity.getField0032code());// todo 负责人
|
||||
savedata.add(inventoryEntity);
|
||||
if("新增".equals(entity.getField0018code()) || "增加替代".equals(entity.getField0018code()) || "升级".equals(entity.getField0018code())){
|
||||
iInventoryService.saveInventory(inventoryEntity);
|
||||
}else if("修改".equals(entity.getField0018code())){
|
||||
|
||||
iInventoryService.updateInventory(inventoryEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @Author lvleigang
|
||||
|
@ -167,7 +304,7 @@ public class ZjMaterielSynchronizationEventServiceImpl extends BaseService<ZjMat
|
|||
* @param flag 该项是否校验
|
||||
* @return com.hzya.frame.web.entity.JsonResultEntity
|
||||
**/
|
||||
private JsonResultEntity checkData(List<ZjMaterielSynchronizationEventEntity> list, boolean flag) {
|
||||
private JsonResultEntity checkData(List<ZjMaterielSynchronizationEventEntity> list, boolean flag,List<InventoryEntity> inventoryEntities) {
|
||||
// 定义正则表达式,匹配全角符号
|
||||
String regex = "[\uFF00-\uFFEF]";
|
||||
// 编译正则表达式
|
||||
|
@ -272,7 +409,7 @@ public class ZjMaterielSynchronizationEventServiceImpl extends BaseService<ZjMat
|
|||
ZjMaterielSynchronizationEventDto querywl = new ZjMaterielSynchronizationEventDto();
|
||||
querywl.setDataSourceCode(zju8);
|
||||
querywl.setZjMaterielSynchronizationEventEntities(list);
|
||||
List<InventoryEntity> inventoryEntities = zjMaterielSynchronizationEventDao.queryInventoryEntity(querywl);
|
||||
inventoryEntities = zjMaterielSynchronizationEventDao.queryInventoryEntity(querywl);
|
||||
if(inventoryEntities == null || inventoryEntities.size() == 0){
|
||||
return BaseResult.getFailureMessageEntity("物料分类在U8中不存在");
|
||||
}
|
||||
|
@ -309,8 +446,10 @@ public class ZjMaterielSynchronizationEventServiceImpl extends BaseService<ZjMat
|
|||
queryCz.setcInvCode(entity.getField0005());
|
||||
List<InventoryEntity> queryCzList = inventoryDao.query(queryCz);
|
||||
if(queryCzList == null || queryCzList.size() == 0 ){
|
||||
return BaseResult.getFailureMessageEntity("序号为"+entity.getField0004()+"明细行修改的物料编码在U8中不存在");
|
||||
//return BaseResult.getFailureMessageEntity("序号为"+entity.getField0004()+"明细行修改的物料编码在U8中不存在");
|
||||
return BaseResult.getFailureMessageEntity(entity.getField0005()+"已存在U8中不存在,请检查货品编号");
|
||||
}
|
||||
|
||||
}else {//新增/增加替代/升级
|
||||
xzCount++;
|
||||
if(entity.getField0043code().startsWith("a")
|
||||
|
|
Loading…
Reference in New Issue