| | |
| | | package com.zy.asrs.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.core.common.R; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.Tag; |
| | | import com.zy.asrs.entity.param.MatSyncParam; |
| | | import com.zy.asrs.service.ApiLogService; |
| | | import com.zy.asrs.service.TagService; |
| | | import com.zy.common.config.CoolExceptionHandler; |
| | | import com.zy.erp.kingdee.enums.KingDeeUtilType; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.zy.asrs.entity.Mat; |
| | | import com.zy.asrs.mapper.MatMapper; |
| | | import com.zy.asrs.service.MatService; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | @Service("matService") |
| | | public class MatServiceImpl extends ServiceImpl<MatMapper, Mat> implements MatService { |
| | | |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | @Autowired |
| | | private TagService tagService; |
| | | @Override |
| | | public Page<Mat> getPage(Page page, String tagId, Object matnr, Object maktx) { |
| | | return page.setRecords(baseMapper.listByPage(page, tagId, matnr, maktx)); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Mat selectLatest() { |
| | | return this.baseMapper.selectLatest(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<Mat> selectByMatnrLink(String matnr) { |
| | | return this.baseMapper.selectByMatnrLink(matnr); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<Mat> selectByMatnrLink10(String matnr) { |
| | | return this.baseMapper.selectByMatnrLink10(matnr); |
| | | } |
| | | |
| | | @Override |
| | | public Mat selectNewUpdateTime() { |
| | | return this.baseMapper.selectNewUpdateTime(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | page.setTotal(16); |
| | | return page; |
| | | }; |
| | | public String getOldMatnr(Long id){ |
| | | return this.baseMapper.getOldMatnr(id); |
| | | } |
| | | private Tag getOrCreateTag(MatSyncParam.MatParam param) { |
| | | Tag tag = tagService.selectOne( |
| | | new EntityWrapper<Tag>() |
| | | .eq("name", param.getGroupName()) |
| | | .eq("uuid", param.getGroupId()) |
| | | ); |
| | | Tag tagAll = tagService.selectOne(new EntityWrapper<Tag>().eq("name", "全部")); |
| | | |
| | | if (tag == null) { |
| | | tag = new Tag(); |
| | | tag.setUuid(param.getGroupId()); |
| | | tag.setName(param.getGroupName()); |
| | | tag.setParentId(tagAll.getId()); |
| | | tag.setParentName("全部"); |
| | | tag.setPath(String.valueOf(tagAll.getId())); |
| | | tag.setPathName("全部"); |
| | | tag.setStatus(1); |
| | | tag.setLevel(2); |
| | | if (!tagService.insert(tag)) { |
| | | throw new CoolException("新建目录失败"); |
| | | } |
| | | } |
| | | return tag; |
| | | } |
| | | |
| | | @Override |
| | | public R sync(MatSyncParam matSyncParam) { |
| | | |
| | | List<String> errors = new ArrayList<>(); |
| | | Date now = new Date(); |
| | | |
| | | for (MatSyncParam.MatParam param : matSyncParam.getMatDetails()) { |
| | | |
| | | try { |
| | | if (param.getOperateType() == 1 || param.getOperateType() == 2) { |
| | | |
| | | Tag tag = getOrCreateTag(param); |
| | | Mat mat = this.selectOne( |
| | | new EntityWrapper<Mat>().eq("matnr", param.getMatNr()) |
| | | ); |
| | | |
| | | if (mat == null) { |
| | | mat = new Mat(); |
| | | mat.setMatnr(param.getMatNr()); |
| | | mat.setStatus(1); |
| | | fillMat(mat, param, tag); |
| | | mat.setCreateTime(now); |
| | | |
| | | if (!this.insert(mat)) { |
| | | errors.add("新增物料失败:" + param.getMatNr()); |
| | | } |
| | | } else { |
| | | if (fillMat(mat, param, tag)) { |
| | | mat.setUpdateTime(now); |
| | | if (!this.updateById(mat)) { |
| | | errors.add("更新物料失败:" + param.getMatNr()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (param.getOperateType() == 3 || param.getOperateType() == 4) { |
| | | Mat mat = this.selectOne( |
| | | new EntityWrapper<Mat>().eq("matnr", param.getMatNr()) |
| | | ); |
| | | if (mat == null) { |
| | | errors.add("物料不存在:" + param.getMatNr()); |
| | | continue; |
| | | } |
| | | mat.setStatus(param.getOperateType() == 3 ? 0 : 1); |
| | | if (!this.updateById(mat)) { |
| | | errors.add("状态更新失败:" + param.getMatNr()); |
| | | } |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | errors.add("处理异常:" + param.getMatNr()); |
| | | } |
| | | } |
| | | |
| | | if (errors.isEmpty()) { |
| | | return R.ok("同步成功"); |
| | | } |
| | | R r = R.error("同步完成,存在失败数据"); |
| | | r.put("errors", errors); |
| | | return r; |
| | | } |
| | | private boolean fillMat(Mat mat, MatSyncParam.MatParam param, Tag tag) { |
| | | boolean changed = false; |
| | | |
| | | if (!Objects.equals(mat.getMaktx(), param.getMakTx())) { |
| | | mat.setMaktx(param.getMakTx()); |
| | | changed = true; |
| | | } |
| | | |
| | | if (!Objects.equals(mat.getMemo(), param.getDescrible())) { |
| | | mat.setMemo(param.getDescrible()); |
| | | changed = true; |
| | | } |
| | | |
| | | if (!Objects.equals(mat.getWeight(), param.getWeight())) { |
| | | mat.setWeight(param.getWeight()); |
| | | changed = true; |
| | | } |
| | | |
| | | if (!Objects.equals(mat.getSpecs(), param.getSpec())) { |
| | | mat.setSpecs(param.getSpec()); |
| | | changed = true; |
| | | } |
| | | |
| | | if (!Objects.equals(mat.getModel(), param.getModel())) { |
| | | mat.setModel(param.getModel()); |
| | | changed = true; |
| | | } |
| | | |
| | | if (!Objects.equals(mat.getColor(), param.getColor())) { |
| | | mat.setColor(param.getColor()); |
| | | changed = true; |
| | | } |
| | | |
| | | if (!Objects.equals(mat.getBrand(), param.getSize())) { |
| | | mat.setBrand(param.getSize()); |
| | | changed = true; |
| | | } |
| | | |
| | | if (!Objects.equals(mat.getUnit(), param.getUnit())) { |
| | | mat.setUnit(param.getUnit()); |
| | | changed = true; |
| | | } |
| | | |
| | | if (!Objects.equals(mat.getUuid(), param.getGroupId())) { |
| | | mat.setUuid(param.getGroupId()); |
| | | changed = true; |
| | | } |
| | | |
| | | Long tagId = tag == null ? null : tag.getId(); |
| | | if (!Objects.equals(mat.getTagId(), tagId)) { |
| | | mat.setTagId(tagId); |
| | | changed = true; |
| | | } |
| | | |
| | | return changed; |
| | | } |
| | | |
| | | public void callApiLogSaveMat(Mat mat, String response, Boolean bool) { |
| | | apiLogService.save("商品档案同步", "mat/sync", "null", "localhost", |
| | | "物料编号:" + mat.getMatnr() + "、物料名称:" + mat.getMaktx() + "、毛重:" + mat.getWeight() |
| | | + "、状态:" + mat.getStatus$(), |
| | | response, bool); |
| | | } |
| | | |
| | | |
| | | } |