|  |  |  | 
|---|
|  |  |  | import com.alibaba.excel.event.AnalysisEventListener; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.zy.asrs.common.domain.entity.MatExcel; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.entity.ManMat; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.entity.ManTag; | 
|---|
|  |  |  | 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.entity.Mat; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.entity.Tag; | 
|---|
|  |  |  | 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())) { | 
|---|
|  |  |  | ManTag priTag = tagService.getOne(new LambdaQueryWrapper<ManTag>().eq(ManTag::getName, excel.getPriClass()).eq(ManTag::getLevel, 2)); | 
|---|
|  |  |  | Tag priTag = tagService.getOne(new LambdaQueryWrapper<Tag>().eq(Tag::getName, excel.getPriClass()).eq(Tag::getLevel, 2)); | 
|---|
|  |  |  | if (priTag == null) { | 
|---|
|  |  |  | ManTag top = tagService.getTop(); | 
|---|
|  |  |  | Tag top = tagService.getTop(hostId); | 
|---|
|  |  |  | NodeUtils nodeUtils = new NodeUtils(); | 
|---|
|  |  |  | nodeUtils.executePath(top.getId()); | 
|---|
|  |  |  | priTag = new ManTag( | 
|---|
|  |  |  | priTag = new Tag( | 
|---|
|  |  |  | null,    // 编号 | 
|---|
|  |  |  | excel.getPriClass(),    // 名称 | 
|---|
|  |  |  | top.getId(),    // 父级 | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 二级分类 | 
|---|
|  |  |  | ManTag secTag = tagService.getOne(new LambdaQueryWrapper<ManTag>().eq(ManTag::getName, excel.getPriClass()).eq(ManTag::getLevel, 3)); | 
|---|
|  |  |  | Tag secTag = tagService.getOne(new LambdaQueryWrapper<Tag>().eq(Tag::getName, excel.getPriClass()).eq(Tag::getLevel, 3)); | 
|---|
|  |  |  | if (secTag == null) { | 
|---|
|  |  |  | NodeUtils nodeUtils = new NodeUtils(); | 
|---|
|  |  |  | nodeUtils.executePath(priTag.getId()); | 
|---|
|  |  |  | secTag = new ManTag( | 
|---|
|  |  |  | secTag = new Tag( | 
|---|
|  |  |  | null,    // 编号 | 
|---|
|  |  |  | excel.getSecClass(),    // 名称 | 
|---|
|  |  |  | priTag.getId(),    // 父级 | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | tagId = secTag.getId(); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | tagId = tagService.getTop().getId(); | 
|---|
|  |  |  | tagId = tagService.getTop(hostId).getId(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 商品 | 
|---|
|  |  |  | ManMat mat = matService.getOne(new LambdaQueryWrapper<ManMat>().eq(ManMat::getMatnr, excel.getMatnr())); | 
|---|
|  |  |  | Mat mat = matService.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getMatnr, excel.getMatnr())); | 
|---|
|  |  |  | if (mat == null) { | 
|---|
|  |  |  | mat = excel; | 
|---|
|  |  |  | mat.setTagId(tagId); | 
|---|