浏览代码

多选匹配调整

hulh 8 年之前
父节点
当前提交
34625fe227

+ 1 - 1
src/main/java/com/uas/platform/b2c/prod/commodity/controller/ProductController.java

@@ -248,7 +248,7 @@ public class ProductController {
 	@RequestMapping(value = "/match/selected", method = RequestMethod.POST)
 	public ResultMap matchSelected(@RequestBody List<Long> idList) {
 		Long enuu = SystemSession.getUser().getEnterprise() != null ? SystemSession.getUser().getEnterprise().getUu() : null;
-		logger.info("选中的产品进行匹配" + enuu);
+		logger.info("选中的产品进行匹配,enuu " + enuu);
 		return productService.matchSelected(idList);
 	}
 

+ 15 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/dao/MatchModelDao.java

@@ -0,0 +1,15 @@
+package com.uas.platform.b2c.prod.commodity.dao;
+
+import com.uas.platform.b2c.prod.commodity.model.MatchModel;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.stereotype.Repository;
+
+/**
+ * 匹配结果类操作层
+ * @author hulh
+ */
+@Repository
+public interface MatchModelDao extends JpaRepository<MatchModel, Long>, JpaSpecificationExecutor<MatchModel> {
+
+}

+ 14 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/model/MatchModel.java

@@ -46,6 +46,12 @@ public class MatchModel {
     @Column(name = "ma_product_id")
     private Long productId;
 
+    /**
+     * 匹配后结果
+     */
+    @Column(name = "ma_standard")
+    private Short standard;
+
     public Long getId() {
         return id;
     }
@@ -85,4 +91,12 @@ public class MatchModel {
     public void setProductId(Long productId) {
         this.productId = productId;
     }
+
+    public Short getStandard() {
+        return standard;
+    }
+
+    public void setStandard(Short standard) {
+        this.standard = standard;
+    }
 }

+ 61 - 25
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ProductServiceImpl.java

@@ -160,6 +160,9 @@ public class ProductServiceImpl implements ProductService {
     @Autowired
     private CreateNumberServiceImpl createNumberService;
 
+    @Autowired
+    private MatchModelDao matchModelDao;
+
     private ConcurrentHashMap<String, Field> sortFields = new ConcurrentHashMap<String, Field>();
 
     @Override
@@ -675,33 +678,12 @@ public class ProductServiceImpl implements ProductService {
         return ResultMap.success(map);
     }
 
-    /**
-     * 根据标准上架信息 保存对产品包装,包装数量,生产日期的修改
-     *
-     * @param putOnInfo the Goods
-     * @return the string
-     */
-    @Override
-    public Product updateProduct(ProductStandardPutOnInfo putOnInfo) {
-        if(putOnInfo == null) {
-            throw new IllegalOperatorException("传入的信息信息为空");
-        }
-        if(StringUtils.isEmpty(putOnInfo.getProductid())) {
-            throw new IllegalOperatorException("标准上架信息关联的标准产品信息为空");
-        }
-        Product product = productDao.findOne(putOnInfo.getProductid());
-        if(product == null) {
-            throw new IllegalOperatorException("标准上架信息关联的标准产品信息为空");
-        }
-        product.setAvailableOnSale(putOnInfo.getAvailableOnSale());
-        product.setOnSaleQty(putOnInfo.getOnSaleQty());
-        return product;
-    }
-
     @Override
     public ResultMap matchSelected(List<Long> idList) {
+        Map<String, Object> map = new HashMap<>();
         Enterprise enterprise = SystemSession.getUser().getEnterprise();
         Long enUU = enterprise != null ? enterprise.getUu() : null;
+        Long uu = SystemSession.getUser().getUserUU();
         if (enUU == null) {
             return new ResultMap(CodeType.NO_INFO, "企业或EnUU信息丢失");
         }
@@ -712,11 +694,40 @@ public class ProductServiceImpl implements ProductService {
         ProductStoreStatus status = (ProductStoreStatus) statusResult.getData();
         String batch = createNumberService.getTimeNumber("product$match", 8);
         // 保存要匹配的id数据
+        createMatchModel(idList, batch);
+        int success = 0;
+        int fail = 0;
 
-        return null;
-    }
+        String sql = "/*#mycat:db_type=master*/ call PRODUCT_MATCHES_SELECT_V1(%s, %s, @out); select @out";
+        final String formatSql = String.format(sql, batch, uu);
+        success = jdbcTemplate.execute(new StatementCallback<Integer>() {
+            @Override
+            public Integer doInStatement(Statement statement) throws SQLException, DataAccessException {
+                statement.execute(formatSql);
+                ResultSet rs = statement.getResultSet();
+                if (null != rs) {
+                    rs.next();
+                    return rs.getInt(1);
+                }
+                return 0;
+            }
+        });
+        fail = idList.size() - success;
 
+        status.setStatus(Status.FINISH.value());
+        productStoreStatusDao.save(status);
+        map.put("total", idList.size());
+        map.put("fail", fail);
+        map.put("success", success);
 
+        return ResultMap.success(map);
+    }
+
+    /**
+     * 根据id列表生成匹配信息
+     * @param idList 产品id列表
+     * @param batch 批次号标识
+     */
     private void createMatchModel(List<Long> idList, String batch) {
         Long uu = SystemSession.getUser().getUserUU();
         Long enUU = SystemSession.getUser().getEnterprise() != null ? SystemSession.getUser().getEnterprise().getUu() : null;
@@ -727,8 +738,33 @@ public class ProductServiceImpl implements ProductService {
             matchModel.setProductId(id);
             matchModel.setUseruu(uu);
             matchModel.setEnuu(enUU);
+            matchModel.setStandard(ShortConstant.NO_SHORT);
             resultList.add(matchModel);
         }
+        matchModelDao.save(resultList);
+    }
+
+    /**
+     * 根据标准上架信息 保存对产品包装,包装数量,生产日期的修改
+     *
+     * @param putOnInfo the Goods
+     * @return the string
+     */
+    @Override
+    public Product updateProduct(ProductStandardPutOnInfo putOnInfo) {
+        if(putOnInfo == null) {
+            throw new IllegalOperatorException("传入的信息信息为空");
+        }
+        if(StringUtils.isEmpty(putOnInfo.getProductid())) {
+            throw new IllegalOperatorException("标准上架信息关联的标准产品信息为空");
+        }
+        Product product = productDao.findOne(putOnInfo.getProductid());
+        if(product == null) {
+            throw new IllegalOperatorException("标准上架信息关联的标准产品信息为空");
+        }
+        product.setAvailableOnSale(putOnInfo.getAvailableOnSale());
+        product.setOnSaleQty(putOnInfo.getOnSaleQty());
+        return product;
     }
 
     /**