| | |
| | | import com.zy.asrs.common.domain.entity.MatExcel; |
| | | import com.zy.asrs.common.wms.entity.Mat; |
| | | import com.zy.asrs.common.wms.entity.Tag; |
| | | import com.zy.asrs.common.wms.mapper.ManTagMapper; |
| | | import com.zy.asrs.common.wms.service.ManMatService; |
| | | import com.zy.asrs.common.wms.service.ManTagService; |
| | | import com.zy.asrs.common.wms.mapper.TagMapper; |
| | | import com.zy.asrs.common.wms.service.MatService; |
| | | import com.zy.asrs.common.wms.service.TagService; |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.framework.common.SpringUtils; |
| | | import com.zy.asrs.framework.exception.CoolException; |
| | |
| | | |
| | | private int total = 0; |
| | | private Long userId; |
| | | private Long hostId; |
| | | |
| | | public MatExcelListener() { |
| | | } |
| | | |
| | | public MatExcelListener(Long userId) { |
| | | public MatExcelListener(Long userId, Long hostId) { |
| | | this.userId = userId; |
| | | this.hostId = hostId; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public void invoke(MatExcel excel, AnalysisContext ctx) { |
| | | ManTagService tagService = SpringUtils.getBean(ManTagService.class); |
| | | ManTagMapper tagMapper = SpringUtils.getBean(ManTagMapper.class); |
| | | ManMatService matService = SpringUtils.getBean(ManMatService.class); |
| | | TagService tagService = SpringUtils.getBean(TagService.class); |
| | | TagMapper tagMapper = SpringUtils.getBean(TagMapper.class); |
| | | MatService matService = SpringUtils.getBean(MatService.class); |
| | | Date now = new Date(); |
| | | Long tagId; |
| | | // 分类 |
| | | // 一级分类 |
| | | if (!Cools.isEmpty(excel.getPriClass()) && !Cools.isEmpty(excel.getSecClass())) { |
| | | Tag priTag = tagService.getOne(new LambdaQueryWrapper<Tag>().eq(Tag::getName, excel.getPriClass()).eq(Tag::getLevel, 2)); |
| | | Tag priTag = tagService.getOne(new LambdaQueryWrapper<Tag>().eq(Tag::getName, excel.getPriClass()).eq(Tag::getLevel, 2).eq(Tag::getHostId, hostId)); |
| | | if (priTag == null) { |
| | | Tag top = tagService.getTop(); |
| | | Tag top = tagService.getTop(hostId); |
| | | NodeUtils nodeUtils = new NodeUtils(); |
| | | nodeUtils.executePath(top.getId()); |
| | | priTag = new Tag( |
| | |
| | | null, // 修改人员 |
| | | null // 备注 |
| | | ); |
| | | priTag.setHostId(hostId); |
| | | if (tagMapper.insert(priTag) == 0) { |
| | | throw new CoolException("保存一级分类失败"); |
| | | } |
| | | } |
| | | // 二级分类 |
| | | Tag secTag = tagService.getOne(new LambdaQueryWrapper<Tag>().eq(Tag::getName, excel.getPriClass()).eq(Tag::getLevel, 3)); |
| | | Tag secTag = tagService.getOne(new LambdaQueryWrapper<Tag>().eq(Tag::getName, excel.getSecClass()).eq(Tag::getLevel, 3).eq(Tag::getHostId, hostId)); |
| | | if (secTag == null) { |
| | | NodeUtils nodeUtils = new NodeUtils(); |
| | | nodeUtils.executePath(priTag.getId()); |
| | |
| | | null, // 修改人员 |
| | | null // 备注 |
| | | ); |
| | | secTag.setHostId(hostId); |
| | | if (tagMapper.insert(secTag) == 0) { |
| | | throw new CoolException("保存二级分类失败"); |
| | | } |
| | | } |
| | | tagId = secTag.getId(); |
| | | } else { |
| | | tagId = tagService.getTop().getId(); |
| | | tagId = tagService.getTop(hostId).getId(); |
| | | } |
| | | // 商品 |
| | | Mat mat = matService.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getMatnr, excel.getMatnr())); |
| | | Mat mat = matService.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getMatnr, excel.getMatnr()).eq(Mat::getHostId, hostId)); |
| | | if (mat == null) { |
| | | mat = excel; |
| | | mat.setTagId(tagId); |
| | | mat.setHostId(hostId); |
| | | if (!matService.save(mat)) { |
| | | throw new CoolException("保存商品信息失败,商品编码:" + excel.getMatnr()); |
| | | } |
| | | total++; |
| | | }else { |
| | | matService.removeById(mat.getId()); |
| | | |
| | | mat = excel; |
| | | mat.setTagId(tagId); |
| | | mat.setHostId(hostId); |
| | | if (!matService.save(mat)) { |
| | | throw new CoolException("保存商品信息失败,商品编码:" + excel.getMatnr()); |
| | | } |