package com.zy.third.erp.task;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.core.common.Cools;
|
import com.core.exception.CoolException;
|
import com.zy.asrs.entity.Mat;
|
import com.zy.asrs.entity.Tag;
|
import com.zy.asrs.mapper.MatMapper;
|
import com.zy.asrs.mapper.TagMapper;
|
import com.zy.asrs.service.MatService;
|
import com.zy.asrs.service.TagService;
|
import com.zy.common.utils.NodeUtils;
|
import com.zy.third.erp.entity.ItemTB;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.util.Date;
|
|
|
@Slf4j
|
@Component
|
public class ERPItemService {
|
|
@Autowired
|
private MatService matService;
|
|
@Autowired
|
private TagService tagService;
|
|
@Autowired
|
private TagMapper tagMapper;
|
|
@Autowired
|
private MatMapper matMapper;
|
|
/**
|
* 将物料中间表数据同步到立库物料基础数据,如果没有则插入,如果有则更新
|
*
|
* @param itemTB,物料实体类
|
*/
|
protected void addToMainDatabase(ItemTB itemTB) {
|
Date now = new Date();
|
Mat mat = matService.selectByMatnr(itemTB.getItemId());
|
if (mat == null) {
|
mat = new Mat();
|
Tag priTag = null;
|
if (!Cools.isEmpty(itemTB.getItemKind())) {
|
priTag = tagService.selectByName(itemTB.getItemKind(), 2);
|
if (priTag == null) {
|
Tag top = tagService.getTop();
|
NodeUtils nodeUtils = new NodeUtils();
|
nodeUtils.executePath(top.getId());
|
priTag = new Tag(
|
null, // 编号
|
itemTB.getItemKind(), // 名称
|
top.getId(), // 父级
|
top.getName(), // 父级名称
|
nodeUtils.path.toString(), // 关联路径
|
nodeUtils.pathName.toString(), // 关联路径名
|
0, // 类型
|
null, // 负责人
|
null, // 图片
|
null, // 简要描述
|
null, // 数量
|
2, // 等级
|
null, // 排序
|
1, // 状态
|
now, // 添加时间
|
null, // 添加人员
|
now, // 修改时间
|
null, // 修改人员
|
null // 备注
|
);
|
if (tagMapper.insert(priTag) == 0) {
|
throw new CoolException("服务器内部错误,请联系管理员");
|
}
|
}
|
}
|
priTag = tagService.selectByName(itemTB.getItemKind(), 2);
|
mat = sync(mat, itemTB);
|
|
mat.setTagId(priTag.getId());
|
mat.setStatus(1);
|
mat.setCreateTime(now);
|
mat.setUpdateTime(now);
|
if (!matService.insert(mat)) {
|
throw new CoolException("服务器内部错误,请联系管理员");
|
} else {
|
log.info("同步新物料[商品编号:{}]", mat.getMatnr());
|
}
|
} else {
|
mat = sync(mat, itemTB);
|
if (!matService.update(mat, new EntityWrapper<Mat>().eq("matnr", itemTB.getItemId()))) {
|
throw new CoolException("更新已存在商品信息失败,请联系管理员");
|
}
|
}
|
}
|
|
private Mat sync(Mat mat, ItemTB itemTB) {
|
mat.setModel(itemTB.getItemCode());
|
mat.setMatnr(itemTB.getItemId());
|
mat.setMaktx(itemTB.getItemName());
|
mat.setSpecs(itemTB.getItemSpc());
|
mat.setUnit(itemTB.getItemUnit());
|
mat.setMemo(itemTB.getRemark());
|
mat.setCreateTime(itemTB.getMakeDate());
|
mat.setTemp1(itemTB.getTemp1());
|
mat.setTemp2(itemTB.getTemp2());
|
mat.setTemp3(itemTB.getTemp3());
|
return mat;
|
}
|
|
/**
|
* 删除ASRS物料通知档数据
|
*
|
* @param itemTB,物料实体类
|
*/
|
protected void deleteFromMainDatabase(ItemTB itemTB) {
|
EntityWrapper<Mat> matCodeEntityWrapper = new EntityWrapper<>();
|
matCodeEntityWrapper.eq("matnr", itemTB.getItemCode());
|
matMapper.delete(matCodeEntityWrapper);
|
}
|
|
|
}
|