对比新文件 |
| | |
| | | package com.gk.firework.Service.ServiceImpl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.gk.firework.Config.DataSource.MybatisPlusConfig; |
| | | import com.gk.firework.Domain.Exception.BusinessException; |
| | | import com.gk.firework.Domain.ProductLocusInfo; |
| | | import com.gk.firework.Domain.Utils.StringUtils; |
| | | import com.gk.firework.Domain.Vo.DirectionDetail; |
| | | import com.gk.firework.Domain.Vo.FireworkDeal; |
| | | import com.gk.firework.Domain.Vo.ProductLocusVo; |
| | | import com.gk.firework.Domain.Vo.ProductVo; |
| | | import com.gk.firework.Mapper.ProductLocusInfoMapper; |
| | | import com.gk.firework.Service.ProductLocusService; |
| | | import com.gk.firework.Service.ProductService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author : jingjy |
| | | * @date : 2021/3/24 14:34 |
| | | */ |
| | | @Service("ProductLocusService") |
| | | public class ProductLocusServiceImpl extends ServiceImpl<ProductLocusInfoMapper, ProductLocusInfo> implements ProductLocusService { |
| | | @Autowired |
| | | private ProductService productService; |
| | | @Autowired |
| | | private ProductLocusInfoMapper productLocusInfoMapper; |
| | | |
| | | @Override |
| | | public int insertProductLocus(ProductLocusInfo productLocusInfo) { |
| | | int i = 0; |
| | | if (productLocusInfo == null){ |
| | | return i; |
| | | } |
| | | String slice = productService.getSlice(productLocusInfo.getDirectioncode()); |
| | | i = productLocusInfoMapper.insertProductLocus(productLocusInfo, slice); |
| | | return i; |
| | | } |
| | | |
| | | @Override |
| | | public int insertBatch(List<ProductLocusInfo> productLocusInfos) { |
| | | int i = 0; |
| | | if (productLocusInfos == null || productLocusInfos.size() == 0){ |
| | | return i; |
| | | } |
| | | for (ProductLocusInfo productLocusInfo : productLocusInfos){ |
| | | i = insertProductLocus(productLocusInfo); |
| | | } |
| | | return i; |
| | | } |
| | | |
| | | /** |
| | | * @Description: 条码流向查询 |
| | | * @date 2021/4/14 16:01 |
| | | */ |
| | | @Override |
| | | public List<ProductLocusVo> getFlow(String directionCode) { |
| | | |
| | | ArrayList<ProductLocusVo> result = new ArrayList<>(); |
| | | //判空和长度判断 |
| | | if (StringUtils.isBlank(directionCode)) throw new BusinessException("流向码不能为空"); |
| | | if (FireworkDeal.isNotDirectionCode(directionCode)) throw new BusinessException("流向码非法"); |
| | | //根据创建时间倒叙排序 |
| | | DirectionDetail directionDetail = FireworkDeal.dealDirectionCode(directionCode); |
| | | List<ProductVo> productVos = new ArrayList<>(); |
| | | ProductVo productVo = productService.selectVoByDirection(directionCode); |
| | | if (productVo == null) throw new BusinessException("产品不存在"); |
| | | String slice = productService.getSlice(directionCode); |
| | | //22位码 |
| | | if (FireworkDeal.is22Characters(directionCode)){ |
| | | FireworkDeal.getProductVos(directionCode,directionDetail,directionDetail,productVos,productVo); |
| | | if (productVos.size() < 1) throw new BusinessException("产品流向码出现问题"); |
| | | List<String> codes= new ArrayList<>(); |
| | | for (ProductVo product : productVos) { |
| | | codes.add(product.getDirectionCode()); |
| | | } |
| | | //22位查询 |
| | | List<ProductLocusVo> flow_22 = productLocusInfoMapper.selectLists(directionCode, slice); |
| | | if (flow_22.size() < 1) throw new BusinessException("查询结果不存在"); |
| | | result.addAll(flow_22); |
| | | //19位查询 |
| | | List<ProductLocusVo> flow_19 = productLocusInfoMapper.selectFlowByCodes(codes, slice); |
| | | assert flow_19.size() > 0; |
| | | result.addAll(flow_19); |
| | | }else{ |
| | | //19位查询 |
| | | List<ProductLocusVo> flow_19 = productLocusInfoMapper.selectLists(directionCode,slice); |
| | | //19找22位箱 |
| | | Integer boxNumber = productVo.getBoxNumber(); |
| | | String serialNo = directionDetail.getSerialNo(); |
| | | Integer serial = Integer.parseInt(serialNo); |
| | | int left_open_interval = serial - boxNumber; |
| | | int right_close_interval = serial; |
| | | List<String> codes = new ArrayList<>(); |
| | | for (int i = left_open_interval + 1; i <= right_close_interval; i++) { |
| | | int abs = Math.abs(i); |
| | | String itemCode = directionDetail.getItemCode(); |
| | | String dateCode = directionDetail.getDateCode(); |
| | | String serials = String.format("%05d", abs); |
| | | String boxNumberCode = String.format("%03d", boxNumber); |
| | | String code = String.format("%s%s%s%s", itemCode, dateCode, serials, boxNumberCode); |
| | | codes.add(code); |
| | | } |
| | | List<ProductLocusVo> flow_22 = productLocusInfoMapper.selectFlowByCodes(codes,slice); |
| | | assert flow_22.size() > 0; |
| | | result.addAll(flow_22); |
| | | result.addAll(flow_19); |
| | | } |
| | | |
| | | if (result.size() >0 ) |
| | | return result.stream().sorted(Comparator.comparing(ProductLocusVo::getCreateddate).reversed()).collect(Collectors.toList()); |
| | | |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public int saveBatchLocus(List<ProductLocusInfo> productLocuses) { |
| | | if (productLocuses == null || productLocuses.size() == 0) { |
| | | throw new BusinessException("系统入参为空"); |
| | | } |
| | | return productLocusInfoMapper.insertBatch(productLocuses); |
| | | } |
| | | } |