|  |  | @ -5,12 +5,15 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.github.pagehelper.PageHelper; |  |  |  | import com.github.pagehelper.PageHelper; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.api.dao.basic.BasicProductsDao; |  |  |  | import com.glxp.api.dao.basic.BasicProductsDao; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.api.entity.basic.BasicProductsEntity; |  |  |  | import com.glxp.api.entity.basic.BasicProductsEntity; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import com.glxp.api.entity.basic.UdiEntity; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.api.exception.JsonException; |  |  |  | import com.glxp.api.exception.JsonException; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.api.req.collect.RelCodeDetailRequest; |  |  |  | import com.glxp.api.req.collect.RelCodeDetailRequest; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.api.res.collect.RelCodeDetailResponse; |  |  |  | import com.glxp.api.res.collect.RelCodeDetailResponse; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import com.glxp.api.util.udi.FilterUdiUtils; | 
			
		
	
		
		
			
				
					
					|  |  |  | import org.springframework.stereotype.Service; |  |  |  | import org.springframework.stereotype.Service; | 
			
		
	
		
		
			
				
					
					|  |  |  | import javax.annotation.Resource; |  |  |  | import javax.annotation.Resource; | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.util.Collections; |  |  |  | import java.util.Collections; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import java.util.Currency; | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.util.List; |  |  |  | import java.util.List; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.api.dao.collect.RelCodeDetailMapper; |  |  |  | import com.glxp.api.dao.collect.RelCodeDetailMapper; | 
			
		
	
	
		
		
			
				
					|  |  | @ -22,37 +25,65 @@ public class RelCodeDetailService extends ServiceImpl<RelCodeDetailMapper, RelCo | 
			
		
	
		
		
			
				
					
					|  |  |  |     private BasicProductsDao basicProductsDao; |  |  |  |     private BasicProductsDao basicProductsDao; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     /** |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |      * 扫码获取子集 |  |  |  |      * 扫码获取关联 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |      * @param relCodeDetailRequest |  |  |  |      * @param relCodeDetailRequest | 
			
		
	
		
		
			
				
					
					|  |  |  |      * @return |  |  |  |      * @return | 
			
		
	
		
		
			
				
					
					|  |  |  |      */ |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public RelCodeDetailResponse scanCode(RelCodeDetailRequest relCodeDetailRequest) { |  |  |  |     public RelCodeDetailResponse scanCode(RelCodeDetailRequest relCodeDetailRequest) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         String curCode = relCodeDetailRequest.getCurCode(); | 
			
		
	
		
		
			
				
					
					|  |  |  |         String parentCode = relCodeDetailRequest.getParentCode(); |  |  |  |         String parentCode = relCodeDetailRequest.getParentCode(); | 
			
		
	
		
		
			
				
					
					|  |  |  |         if(StrUtil.isBlank(parentCode)){ |  |  |  |         if(StrUtil.isBlank(curCode)){ | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             throw new JsonException("父级码不能为空"); |  |  |  |             throw new JsonException("追溯码不能为空"); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         if (curCode.endsWith("\u001D")) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             curCode = curCode.replace("\u001D", ""); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         UdiEntity curCodeUdi = FilterUdiUtils.getUdi(curCode); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         if (curCodeUdi == null){ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             throw new JsonException("无效条码!"); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |         RelCodeDetailResponse relCodeDetailResponse = new RelCodeDetailResponse(); |  |  |  |         RelCodeDetailResponse relCodeDetailResponse = new RelCodeDetailResponse(); | 
			
		
	
		
		
			
				
					
					|  |  |  |         LambdaQueryWrapper<BasicProductsEntity> qw = new LambdaQueryWrapper<BasicProductsEntity>() |  |  |  |         LambdaQueryWrapper<BasicProductsEntity> cw = new LambdaQueryWrapper<BasicProductsEntity>() | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 .eq(BasicProductsEntity::getNameCode, relCodeDetailRequest.getParentCode()) |  |  |  |                 .eq(BasicProductsEntity::getNameCode, curCodeUdi.getUdi()) | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 .last("limit 1"); |  |  |  |                 .last("limit 1"); | 
			
		
	
		
		
			
				
					
					|  |  |  |         BasicProductsEntity parent = basicProductsDao.selectOne(qw); |  |  |  |         BasicProductsEntity cur = basicProductsDao.selectOne(cw); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         if(parent == null){ |  |  |  |         if(cur == null){ | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             throw new JsonException("产品信息不存在"); |  |  |  |             throw new JsonException("产品信息不存在"); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |         Integer packLevel = Integer.valueOf(parent.getPackLevel()); |  |  |  |         if(StrUtil.isNotBlank(parentCode)){ | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         if(packLevel == 1){ |  |  |  |             if (parentCode.endsWith("\u001D")) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             throw new JsonException("产品信息不存在子包装"); |  |  |  |                 parentCode = parentCode.replace("\u001D", ""); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         //todo 可能存在多个子集 如何处理
 |  |  |  |             UdiEntity parentCodeUdi = FilterUdiUtils.getUdi(parentCode); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         LambdaQueryWrapper<BasicProductsEntity> qw2 = new LambdaQueryWrapper<BasicProductsEntity>() |  |  |  |             if (parentCodeUdi == null){ | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 .eq(BasicProductsEntity::getUuid, parent.getUuid()) |  |  |  |                 throw new JsonException("无效父级条码!"); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 .eq(BasicProductsEntity::getPackLevel,packLevel - 1) |  |  |  |             } | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             LambdaQueryWrapper<BasicProductsEntity> pw = new LambdaQueryWrapper<BasicProductsEntity>() | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     .eq(BasicProductsEntity::getNameCode, parentCodeUdi.getUdi()) | 
			
		
	
		
		
			
				
					
					|  |  |  |                     .last("limit 1"); |  |  |  |                     .last("limit 1"); | 
			
		
	
		
		
			
				
					
					|  |  |  |         BasicProductsEntity subset = basicProductsDao.selectOne(qw2); |  |  |  |             BasicProductsEntity parent = basicProductsDao.selectOne(pw); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         relCodeDetailResponse.setCurCode(subset.getNameCode()); |  |  |  |             if(parent == null){ | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         relCodeDetailResponse.setPackLayer(Integer.valueOf(subset.getPackLevel())); |  |  |  |                 throw new JsonException("父级产品信息不存在"); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         relCodeDetailResponse.setParentCode(parent.getNameCode()); |  |  |  |             } | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         relCodeDetailResponse.setFlag(Integer.valueOf(subset.getMajorStatus())); |  |  |  |             if(!StrUtil.equals(parent.getUuid(),cur.getUuid())){ | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 throw new JsonException("当前条码不是同一产品"); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             if(Integer.valueOf(parent.getPackLevel()) - Integer.valueOf(cur.getPackLevel()) != 1){ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 throw new JsonException("当前条码不属于子条码"); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         }else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             parentCode = "0"; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         relCodeDetailResponse.setCurCode(curCode); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         relCodeDetailResponse.setParentCode(parentCode); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         relCodeDetailResponse.setPackLayer(Integer.valueOf(cur.getPackLevel())); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         relCodeDetailResponse.setFlag(Integer.valueOf(cur.getMajorStatus())); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         relCodeDetailResponse.setCpmctymc(cur.getCpmctymc()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         relCodeDetailResponse.setProductCode(cur.getNameCode()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         relCodeDetailResponse.setBhxjsl(cur.getBhxjsl()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         relCodeDetailResponse.setPackageSpec(cur.getBzgg()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         relCodeDetailResponse.setCascadeRatio(cur.getPackRatio()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         relCodeDetailResponse.setPackUnit(cur.getPackUnit()); | 
			
		
	
		
		
			
				
					
					|  |  |  |         return relCodeDetailResponse; |  |  |  |         return relCodeDetailResponse; | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | 
 |