1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
   | 
 
  @Service public class PmsProductServiceImpl implements PmsProductService {     private static final Logger LOGGER = LoggerFactory.getLogger(PmsProductServiceImpl.class);     @Resource     private PmsProductMapper productMapper;     @Resource     private PmsMemberPriceDao memberPriceDao;     @Resource     private PmsMemberPriceMapper memberPriceMapper;     @Resource     private PmsProductLadderDao productLadderDao;     @Resource     private PmsProductLadderMapper productLadderMapper;     @Resource     private PmsProductFullReductionDao productFullReductionDao;     @Resource     private PmsProductFullReductionMapper productFullReductionMapper;     @Resource     private PmsSkuStockDao skuStockDao;     @Resource     private PmsSkuStockMapper skuStockMapper;     @Resource     private PmsProductAttributeValueDao productAttributeValueDao;     @Resource     private PmsProductAttributeValueMapper productAttributeValueMapper;     @Resource     private CmsSubjectProductRelationDao subjectProductRelationDao;     @Resource     private CmsSubjectProductRelationMapper subjectProductRelationMapper;     @Resource     private CmsPrefrenceAreaProductRelationDao prefrenceAreaProductRelationDao;     @Resource     private CmsPrefrenceAreaProductRelationMapper prefrenceAreaProductRelationMapper;     @Resource     private PmsProductDao productDao;     @Resource     private PmsProductVertifyRecordDao productVertifyRecordDao;
      @Override     public int create(PmsProductParam productParam)     {         int count;                  PmsProduct product = productParam;         product.setId(null);         productMapper.insertSelective(product);                  Long productId = product.getId();                  relateAndInsertList(memberPriceDao, productParam.getMemberPriceList(), productId);                  relateAndInsertList(productLadderDao, productParam.getProductLadderList(), productId);                  relateAndInsertList(productFullReductionDao, productParam.getProductFullReductionList(), productId);
                   handleSkuStockCode(productParam.getSkuStockList(), productId);
                   relateAndInsertList(skuStockDao, productParam.getSkuStockList(), productId);                  relateAndInsertList(productAttributeValueDao, productParam.getProductAttributeValueList(), productId);                  relateAndInsertList(subjectProductRelationDao, productParam.getSubjectProductRelationList(), productId);                  relateAndInsertList(prefrenceAreaProductRelationDao, productParam.getPrefrenceAreaProductRelationList(), productId);                  count = 1;         return count;     }
      private void handleSkuStockCode(List<PmsSkuStock> skuStockList, Long productId)     {         if(CollectionUtils.isEmpty(skuStockList)) return;         for(int i = 0; i < skuStockList.size(); i++){             PmsSkuStock skuStock = skuStockList.get(i);             if(StrUtil.isEmpty(skuStock.getSkuCode())){                 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");                 StringBuilder sb = new StringBuilder();                                  sb.append(sdf.format(new Date()));                                  sb.append(String.format("%04d", productId));                                  sb.append(String.format("%03d", i + 1));                 skuStock.setSkuCode(sb.toString());             }         }     }
      @Override     public PmsProductResult getUpdateInfo(Long id)     {         return productDao.getUpdateInfo(id);     }
      @Override     public int update(Long id, PmsProductParam productParam)     {         int count;                  PmsProduct product = productParam;         product.setId(id);         productMapper.updateByPrimaryKeySelective(product);                  PmsMemberPriceExample pmsMemberPriceExample = new PmsMemberPriceExample();         pmsMemberPriceExample.createCriteria().andProductIdEqualTo(id);         memberPriceMapper.deleteByExample(pmsMemberPriceExample);         relateAndInsertList(memberPriceDao, productParam.getMemberPriceList(), id);                  PmsProductLadderExample ladderExample = new PmsProductLadderExample();         ladderExample.createCriteria().andProductIdEqualTo(id);         productLadderMapper.deleteByExample(ladderExample);         relateAndInsertList(productLadderDao, productParam.getProductLadderList(), id);                  PmsProductFullReductionExample fullReductionExample = new PmsProductFullReductionExample();         fullReductionExample.createCriteria().andProductIdEqualTo(id);         productFullReductionMapper.deleteByExample(fullReductionExample);         relateAndInsertList(productFullReductionDao, productParam.getProductFullReductionList(), id);                  handleUpdateSkuStockList(id, productParam);                  PmsProductAttributeValueExample productAttributeValueExample = new PmsProductAttributeValueExample();         productAttributeValueExample.createCriteria().andProductIdEqualTo(id);         productAttributeValueMapper.deleteByExample(productAttributeValueExample);         relateAndInsertList(productAttributeValueDao, productParam.getProductAttributeValueList(), id);                  CmsSubjectProductRelationExample subjectProductRelationExample = new CmsSubjectProductRelationExample();         subjectProductRelationExample.createCriteria().andProductIdEqualTo(id);         subjectProductRelationMapper.deleteByExample(subjectProductRelationExample);         relateAndInsertList(subjectProductRelationDao, productParam.getSubjectProductRelationList(), id);                  CmsPrefrenceAreaProductRelationExample prefrenceAreaExample = new CmsPrefrenceAreaProductRelationExample();         prefrenceAreaExample.createCriteria().andProductIdEqualTo(id);         prefrenceAreaProductRelationMapper.deleteByExample(prefrenceAreaExample);         relateAndInsertList(prefrenceAreaProductRelationDao, productParam.getPrefrenceAreaProductRelationList(), id);         count = 1;         return count;     }
      private void handleUpdateSkuStockList(Long id, PmsProductParam productParam)     {                  List<PmsSkuStock> currSkuList = productParam.getSkuStockList();                  if(CollUtil.isEmpty(currSkuList)){             PmsSkuStockExample skuStockExample = new PmsSkuStockExample();             skuStockExample.createCriteria().andProductIdEqualTo(id);             skuStockMapper.deleteByExample(skuStockExample);             return;         }                  PmsSkuStockExample skuStockExample = new PmsSkuStockExample();         skuStockExample.createCriteria().andProductIdEqualTo(id);         List<PmsSkuStock> oriStuList = skuStockMapper.selectByExample(skuStockExample);                  List<PmsSkuStock> insertSkuList =                 currSkuList.stream()                            .filter(item -> item.getId() == null)                            .collect(Collectors.toList());                  List<PmsSkuStock> updateSkuList =                 currSkuList.stream()                            .filter(item -> item.getId() != null)                            .collect(Collectors.toList());         List<Long> updateSkuIds = updateSkuList.stream()                                                .map(PmsSkuStock::getId)                                                .collect(Collectors.toList());                           List<PmsSkuStock> removeSkuList =                 oriStuList.stream()                           .filter(item -> !updateSkuIds.contains(item.getId()))                           .collect(Collectors.toList());                  handleSkuStockCode(insertSkuList, id);         handleSkuStockCode(updateSkuList, id);                  if(CollUtil.isNotEmpty(insertSkuList)){             relateAndInsertList(skuStockDao, insertSkuList, id);         }                  if(CollUtil.isNotEmpty(removeSkuList)){             List<Long> removeSkuIds = removeSkuList.stream().map(PmsSkuStock::getId).collect(Collectors.toList());             PmsSkuStockExample removeExample = new PmsSkuStockExample();             removeExample.createCriteria().andIdIn(removeSkuIds);             skuStockMapper.deleteByExample(removeExample);         }                  if(CollUtil.isNotEmpty(updateSkuList)){             for(PmsSkuStock pmsSkuStock : updateSkuList){                 skuStockMapper.updateByPrimaryKeySelective(pmsSkuStock);             }         }     }
      @Override     public List<PmsProduct> list(PmsProductQueryParam productQueryParam, Integer pageSize, Integer pageNum)     {         PageHelper.startPage(pageNum, pageSize);         PmsProductExample productExample = new PmsProductExample();         PmsProductExample.Criteria criteria = productExample.createCriteria();                  criteria.andDeleteStatusEqualTo(0);                  if(productQueryParam.getPublishStatus() != null){             criteria.andPublishStatusEqualTo(productQueryParam.getPublishStatus());         }         if(productQueryParam.getVerifyStatus() != null){             criteria.andVerifyStatusEqualTo(productQueryParam.getVerifyStatus());         }         if(!StrUtil.isEmpty(productQueryParam.getKeyword())){             criteria.andNameLike("%" + productQueryParam.getKeyword() + "%");         }         if(!StrUtil.isEmpty(productQueryParam.getProductSn())){             criteria.andProductSnEqualTo(productQueryParam.getProductSn());         }         if(productQueryParam.getBrandId() != null){             criteria.andBrandIdEqualTo(productQueryParam.getBrandId());         }         if(productQueryParam.getProductCategoryId() != null){             criteria.andProductCategoryIdEqualTo(productQueryParam.getProductCategoryId());         }         return productMapper.selectByExample(productExample);     }
      @Override     public int updateVerifyStatus(List<Long> ids, Integer verifyStatus, String detail)     {         PmsProduct product = new PmsProduct();         product.setVerifyStatus(verifyStatus);         PmsProductExample example = new PmsProductExample();         example.createCriteria().andIdIn(ids);         List<PmsProductVertifyRecord> list = new ArrayList<>();         int count = productMapper.updateByExampleSelective(product, example);                           Authentication authentication = SecurityContextHolder.getContext().getAuthentication();         String username = authentication.getName();         UmsAdmin details = (UmsAdmin) authentication.getDetails();         LOGGER.info("PmsProductServiceImpl username = {}, details = {}", username, details);         for(Long id : ids){             PmsProductVertifyRecord record = new PmsProductVertifyRecord();             record.setProductId(id);             record.setCreateTime(new Date());             record.setDetail(detail);             record.setStatus(verifyStatus);                                       record.setVertifyMan("test");             list.add(record);         }         productVertifyRecordDao.insertList(list);         return count;     }
      @Override     public int updatePublishStatus(List<Long> ids, Integer publishStatus)     {         PmsProduct record = new PmsProduct();         record.setPublishStatus(publishStatus);         PmsProductExample example = new PmsProductExample();         example.createCriteria().andIdIn(ids);         return productMapper.updateByExampleSelective(record, example);     }
      @Override     public int updateRecommendStatus(List<Long> ids, Integer recommendStatus)     {         PmsProduct record = new PmsProduct();         record.setRecommandStatus(recommendStatus);         PmsProductExample example = new PmsProductExample();         example.createCriteria().andIdIn(ids);         return productMapper.updateByExampleSelective(record, example);     }
      @Override     public int updateNewStatus(List<Long> ids, Integer newStatus)     {         PmsProduct record = new PmsProduct();         record.setNewStatus(newStatus);         PmsProductExample example = new PmsProductExample();         example.createCriteria().andIdIn(ids);         return productMapper.updateByExampleSelective(record, example);     }
      @Override     public int updateDeleteStatus(List<Long> ids, Integer deleteStatus)     {         PmsProduct record = new PmsProduct();         record.setDeleteStatus(deleteStatus);         PmsProductExample example = new PmsProductExample();         example.createCriteria().andIdIn(ids);         return productMapper.updateByExampleSelective(record, example);     }
      @Override     public List<PmsProduct> list(String keyword)     {         PmsProductExample productExample = new PmsProductExample();         PmsProductExample.Criteria criteria = productExample.createCriteria();         criteria.andDeleteStatusEqualTo(0);         if(!StrUtil.isEmpty(keyword)){             criteria.andNameLike("%" + keyword + "%");             productExample.or().andDeleteStatusEqualTo(0).andProductSnLike("%" + keyword + "%");         }         return productMapper.selectByExample(productExample);     }
      
 
 
 
 
      private void relateAndInsertList(Object dao, List dataList, Long productId)     {         try{             if(CollectionUtils.isEmpty(dataList)) return;                          for(Object item : dataList){                 Method setId = item.getClass().getMethod("setId", Long.class);                 setId.invoke(item, (Long) null);                 Method setProductId = item.getClass().getMethod("setProductId", Long.class);                 setProductId.invoke(item, productId);             }                          Method insertList = dao.getClass().getMethod("insertList", List.class);             insertList.invoke(dao, dataList);         } catch(Exception e){             LOGGER.warn("创建产品出错:{}", e.getMessage());             throw new RuntimeException(e.getMessage());         }     } }
 
  |