ソースを参照

feat: 商品进销存

Joburgess 5 年 前
コミット
83869d68c1

+ 10 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/GoodsDao.java

@@ -63,6 +63,16 @@ public interface GoodsDao extends BaseDAO<Integer, Goods> {
     List<Goods> getGoodies(@Param("goodsIds") List<Integer> goodsIds);
 
     /**
+     * @describe 查询附件商品列表中存在指定商品的商品
+     * @author Joburgess
+     * @date 2020.10.12
+     * @param goodsId:
+     * @return java.util.List<com.ym.mec.biz.dal.entity.Goods>
+     */
+    List<Goods> getWithComplementGoodsAndStatus(@Param("goodsId") Integer goodsId,
+                                                @Param("status") Integer status);
+
+    /**
      * @describe 锁定指定商品
      * @author Joburgess
      * @date 2020.10.12

+ 10 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/GoodsService.java

@@ -17,6 +17,16 @@ public interface GoodsService extends BaseService<Integer, Goods> {
     void addGoodsProcurement(Goods goods, Integer operatorId);
 
     /**
+     * @describe 更新商品状态
+     * @author Joburgess
+     * @date 2020.10.12
+     * @param goodsId:
+     * @param status:
+     * @return void
+     */
+    void updateGoodsStatus(Integer goodsId, Integer status);
+
+    /**
      * 通过科目编号查询商品(教材、辅件)列表
      *
      * @param subjectId

+ 34 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsServiceImpl.java

@@ -99,6 +99,40 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 	}
 
 	@Override
+	public void updateGoodsStatus(Integer goodsId, Integer status) {
+		if(Objects.isNull(goodsId)){
+			throw new BizException("请指定商品");
+		}
+		if(Objects.isNull(status)){
+			throw new BizException("请指定状态");
+		}
+		Goods goods = goodsDao.get(goodsId);
+		if(Objects.isNull(goods)){
+			throw new BizException("商品不存在");
+		}
+		if(StringUtils.isBlank(goods.getComplementGoodsIdList())){
+			if(status==0){
+				List<Goods> goodsList = goodsDao.getWithComplementGoodsAndStatus(goodsId, 1);
+				if(!CollectionUtils.isEmpty(goodsList)){
+					String goodsNames = StringUtils.join(goodsList.stream().map(Goods::getName).collect(Collectors.toList()));
+					throw new BizException("{}等商品还在销售中", goodsNames);
+				}
+			}
+		}else{
+			if(status==1){
+				List<Integer> goodsIds = Arrays.stream(goods.getComplementGoodsIdList().split(",")).map(s -> Integer.valueOf(s)).collect(Collectors.toList());
+				List<Goods> goodList = goodsDao.getGoodies(goodsIds);
+				List<String> goodsNames = goodList.stream().filter(g -> YesOrNoEnum.NO.equals(g.getStatus())).map(Goods::getName).collect(Collectors.toList());
+				if(!CollectionUtils.isEmpty(goodsNames)){
+					throw new BizException("{}商品还未上架", StringUtils.join(goodsNames));
+				}
+			}
+		}
+		goods.setStatus(status==0?YesOrNoEnum.NO:YesOrNoEnum.YES);
+		goodsDao.update(goods);
+	}
+
+	@Override
 	public List<Goods> findGoodsBySubId(Integer subjectId,String type) {
 		return goodsDao.findGoodsBySubId(subjectId,type);
 	}

+ 4 - 0
mec-biz/src/main/resources/config/mybatis/GoodsMapper.xml

@@ -319,4 +319,8 @@
     <select id="getOuterRepertoryWarnName" resultType="java.lang.String">
         SELECT GROUP_CONCAT( DISTINCT name_) FROM goods WHERE tax_stock_count_ &lt;= #{outerRepertoryWarnNum} AND stock_warning_ = 0 AND status_ = 1
     </select>
+
+    <select id="getWithComplementGoodsAndStatus" resultMap="Goods">
+        SELECT * FROM goods WHERE status_ = #{status} AND FIND_IN_SET(#{goodsId}, complement_goods_id_list_)
+    </select>
 </mapper>

+ 8 - 0
mec-web/src/main/java/com/ym/mec/web/controller/GoodsController.java

@@ -56,6 +56,14 @@ public class GoodsController extends BaseController {
         return succeed();
     }
 
+    @ApiOperation(value = "修改商品件状态")
+    @PostMapping("/updateGoodsStatus")
+    @PreAuthorize("@pcs.hasPermissions('goods/updateGoodsStatus')")
+    public Object updateGoodsStatus(Integer goodsId, Integer status) {
+        goodsService.updateGoodsStatus(goodsId, status);
+        return succeed();
+    }
+
     @ApiOperation(value = "修改商品(教材、辅件)")
     @PostMapping("/update")
     @PreAuthorize("@pcs.hasPermissions('goods/update')")