浏览代码

增加向互市区添加或删除商品功能

loovi 1 年之前
父节点
当前提交
bd69f7ada3

+ 4 - 4
sp-service/level-one-server/src/main/java/com/pj/tb_goods_type/TbGoodsTypeController.java

@@ -102,9 +102,9 @@ public class TbGoodsTypeController {
 	 * @date
 	 */
 	@RequestMapping("addGoodsToGoodsType")
-	@SaCheckPermission(com.pj.tb_goods_type.TbGoodsType.PERMISSION_CODE_EDIT)
-	public AjaxJson AddGoodsToGoodsType(@RequestParam("goodsTypeId") Long goodsTypeId,@RequestParam("goodsIds") Long [] goodsIds){
-		int  line = tbGoodsTypeService.AddGoodsToGoodsType(goodsTypeId,goodsIds);
+	@SaCheckPermission(TbGoodsType.PERMISSION_CODE_EDIT)
+	public AjaxJson addGoodsToGoodsType(@RequestParam("goodsTypeId") Long goodsTypeId,@RequestParam("goodsIds") Long [] goodsIds){
+		int  line = tbGoodsTypeService.addGoodsToGoodsType(goodsTypeId,goodsIds);
 		return AjaxJson.getByLine(line);
 	}
 
@@ -115,7 +115,7 @@ public class TbGoodsTypeController {
 	 * @date
 	 */
 	@RequestMapping("delGoodsFromGoodsType")
-	@SaCheckPermission(com.pj.tb_goods_type.TbGoodsType.PERMISSION_CODE_EDIT)
+	@SaCheckPermission(TbGoodsType.PERMISSION_CODE_EDIT)
 	public AjaxJson delGoodsFromGoodsType(@RequestParam("goodsTypeId") Long goodsTypeId,@RequestParam("goodsIds") Long [] goodsIds){
 		int  line = tbGoodsTypeService.delGoodsFromGoodsType(goodsTypeId,goodsIds);
 		return AjaxJson.getByLine(line);

+ 1 - 1
sp-service/level-one-server/src/main/java/com/pj/tb_goods_type/TbGoodsTypeMapper.xml

@@ -29,7 +29,7 @@
 	<delete id="delGoodsFromGoodsType">
 		delete from  tb_goods_type_goods_relation
 		<where>
-			<if  test="goodsTypeId!=null and goodsTypeId!=''"> goods_id=#{goodsId}</if>
+			<if  test="goodsId!=null and goodsId!=''"> goods_id=#{goodsId}</if>
 			<if  test="goodsTypeId!=null and goodsTypeId!=''"> and goods_type_id=#{goodsTypeId}</if>
 		</where>
 	</delete>

+ 1 - 1
sp-service/level-one-server/src/main/java/com/pj/tb_goods_type/TbGoodsTypeService.java

@@ -59,7 +59,7 @@ public class TbGoodsTypeService extends ServiceImpl<TbGoodsTypeMapper, TbGoodsTy
 	* @author loovi
 	* @date
 	*/
-	public int AddGoodsToGoodsType(Long goodsTypeId,Long [] goodsIds){
+	public int addGoodsToGoodsType(Long goodsTypeId,Long [] goodsIds){
 		// 获取当前登录用户id
 //		Long loginId = StpUserUtil.getLoginIdAsLong();
 		int line = 0;

+ 24 - 0
sp-service/level-one-server/src/main/java/com/pj/tb_trade_area/TbTradeAreaController.java

@@ -84,7 +84,31 @@ public class TbTradeAreaController {
 	}
 
 
+	/**
+	 *
+	 *给互市区添加商品
+	 * @author loovi
+	 * @date
+	 */
+	@RequestMapping("addGoodsToTradeArea")
+	@SaCheckPermission(TbTradeArea.PERMISSION_CODE_EDIT)
+	public AjaxJson addGoodsToTradeArea(@RequestParam("tradeAreaId") Long tradeAreaId,@RequestParam("goodsIds") Long [] goodsIds){
+		int  line = tbTradeAreaService.addGoodsToTradeArea(tradeAreaId,goodsIds);
+		return AjaxJson.getByLine(line);
+	}
 
+	/**
+	 *
+	 *删除互市区中的商品
+	 * @author loovi
+	 * @date
+	 */
+	@RequestMapping("delGoodsFromTradeArea")
+	@SaCheckPermission(TbTradeArea.PERMISSION_CODE_EDIT)
+	public AjaxJson delGoodsFromTradeArea(@RequestParam("tradeAreaId") Long tradeAreaId,@RequestParam("goodsIds") Long [] goodsIds){
+		int  line = tbTradeAreaService.delGoodsFromTradeArea(tradeAreaId,goodsIds);
+		return AjaxJson.getByLine(line);
+	}
 
 	/**
 	 * 数据导入接口

+ 16 - 0
sp-service/level-one-server/src/main/java/com/pj/tb_trade_area/TbTradeAreaMapper.java

@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Mapper;
 
 import com.pj.utils.so.*;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
 /**
@@ -26,5 +27,20 @@ public interface TbTradeAreaMapper extends BaseMapper <TbTradeArea> {
 	 */
 	List<TbTradeArea> getList(SoMap so);
 
+	/**
+	 *向互市区添加商品
+	 *
+	 * @author loovi
+	 * @date
+	 */
+	int addGoodsToTradeArea(@Param("tradeAreaId") Long tradeAreaId, @Param("goodsId") Long goodsId);
+	/**
+	 *从互市区删除商品
+	 *
+	 * @author loovi
+	 * @date
+	 */
+	int delGoodsFromTradeArea(@Param("tradeAreaId") Long tradeAreaId, @Param("goodsId") Long goodsId);
+
 
 }

+ 42 - 27
sp-service/level-one-server/src/main/java/com/pj/tb_trade_area/TbTradeAreaMapper.xml

@@ -16,38 +16,53 @@
 		select * 
 		from tb_trade_area 
 	</sql>
+	<insert id="addGoodsToTradeArea">
+		insert into tb_goods_trade_area_relation
+		(goods_id,trade_area_id)
+		values(
+		<if  test="goodsId!=null and goodsId!=''"> #{goodsId},</if>
+		<if  test="tradeAreaId!=null and tradeAreaId!=''">  #{tradeAreaId}</if>
+		)
+	</insert>
 
+	<delete id="delGoodsFromTradeArea">
+		delete from  tb_goods_trade_area_relation
+		<where>
+			<if  test="goodsId!=null and goodsId!=''"> goods_id=#{goodsId}</if>
+			<if  test="tradeAreaId!=null and tradeAreaId!=''"> and trade_area_id=#{tradeAreaId}</if>
+		</where>
+	</delete>
 	
 	<!-- 查集合 - 根据条件(参数为空时代表忽略指定条件) [G] -->
 	<select id="getList" resultMap="model">
 		<include refid="select_sql"></include>
-		<where>
-			<if test=' this.has("id") '> and id = #{id} </if>
-			<if test=' this.has("name") '> and name = #{name} </if>
-			<if test=' this.has("addressIds") '> and address_ids = #{addressIds} </if>
-			<if test=' this.has("detailAddress") '> and detail_address = #{detailAddress} </if>
-			<if test=' this.has("address") '> and address = #{address} </if>
-			<if test=' this.has("createBy") '> and create_by = #{createBy} </if>
-			<if test=' this.has("createName") '> and create_name = #{createName} </if>
-			<if test=' this.has("updateBy") '> and update_by = #{updateBy} </if>
-			<if test=' this.has("updateName") '> and update_name = #{updateName} </if>
-			<if test=' this.has("deleteStatus") '> and delete_status = #{deleteStatus} </if>
-		</where>
-		order by
-		<choose>
-			<when test='sortType == 1'> id desc </when>
-			<when test='sortType == 2'> name desc </when>
-			<when test='sortType == 3'> address_ids desc </when>
-			<when test='sortType == 4'> detail_address desc </when>
-			<when test='sortType == 5'> address desc </when>
-			<when test='sortType == 6'> create_time desc </when>
-			<when test='sortType == 7'> create_by desc </when>
-			<when test='sortType == 8'> create_name desc </when>
-			<when test='sortType == 9'> update_by desc </when>
-			<when test='sortType == 10'> update_name desc </when>
-			<when test='sortType == 11'> update_time desc </when>
-			<otherwise> id desc </otherwise>
-		</choose>
+<!--		<where>-->
+<!--			<if test=' this.has("id") '> and id = #{id} </if>-->
+<!--			<if test=' this.has("name") '> and name = #{name} </if>-->
+<!--			<if test=' this.has("addressIds") '> and address_ids = #{addressIds} </if>-->
+<!--			<if test=' this.has("detailAddress") '> and detail_address = #{detailAddress} </if>-->
+<!--			<if test=' this.has("address") '> and address = #{address} </if>-->
+<!--			<if test=' this.has("createBy") '> and create_by = #{createBy} </if>-->
+<!--			<if test=' this.has("createName") '> and create_name = #{createName} </if>-->
+<!--			<if test=' this.has("updateBy") '> and update_by = #{updateBy} </if>-->
+<!--			<if test=' this.has("updateName") '> and update_name = #{updateName} </if>-->
+<!--			<if test=' this.has("deleteStatus") '> and delete_status = #{deleteStatus} </if>-->
+<!--		</where>-->
+<!--		order by-->
+<!--		<choose>-->
+<!--			<when test='sortType == 1'> id desc </when>-->
+<!--			<when test='sortType == 2'> name desc </when>-->
+<!--			<when test='sortType == 3'> address_ids desc </when>-->
+<!--			<when test='sortType == 4'> detail_address desc </when>-->
+<!--			<when test='sortType == 5'> address desc </when>-->
+<!--			<when test='sortType == 6'> create_time desc </when>-->
+<!--			<when test='sortType == 7'> create_by desc </when>-->
+<!--			<when test='sortType == 8'> create_name desc </when>-->
+<!--			<when test='sortType == 9'> update_by desc </when>-->
+<!--			<when test='sortType == 10'> update_name desc </when>-->
+<!--			<when test='sortType == 11'> update_time desc </when>-->
+<!--			<otherwise> id desc </otherwise>-->
+<!--		</choose>-->
 	</select>
 	
 	

+ 67 - 0
sp-service/level-one-server/src/main/java/com/pj/tb_trade_area/TbTradeAreaService.java

@@ -4,9 +4,13 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
+import java.util.Arrays;
 import java.util.List;
+import java.util.Objects;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.pj.tb_goods.TbGoods;
+import com.pj.tb_goods.TbGoodsMapper;
 import com.pj.tb_people.TbPeople;
 import com.pj.utils.so.SoMap;
 import org.apache.commons.lang3.StringUtils;
@@ -35,6 +39,8 @@ public class TbTradeAreaService extends ServiceImpl<TbTradeAreaMapper, TbTradeAr
 	@Autowired
 	TbTradeAreaMapper tbTradeAreaMapper;
 	@Autowired
+	TbGoodsMapper tbGoodsMapper;
+	@Autowired
 	private MethodTradeAreaService methodTradeAreaService;
 
 	/** 增 */
@@ -63,6 +69,67 @@ public class TbTradeAreaService extends ServiceImpl<TbTradeAreaMapper, TbTradeAr
 		return tbTradeAreaMapper.getList(so);	
 	}
 
+	/**
+	 *
+	 *向商品分类添加商品
+	 * @author loovi
+	 * @date
+	 */
+	public int addGoodsToTradeArea(Long tradeAreaId,Long [] goodsIds){
+		// 获取当前登录用户id
+//		Long loginId = StpUserUtil.getLoginIdAsLong();
+		int line = 0;
+		// 获取互市区信息
+		TbTradeArea tbTradeArea = tbTradeAreaMapper.selectById(tradeAreaId);
+		// 如果互市区不存在则抛异常
+		if (Objects.isNull(tbTradeArea)){
+			throw new RuntimeException("该商品类型不存在");
+		}
+		List<Long> list = Arrays.asList(goodsIds);
+		// 添加商品到互市区
+		for (Long goodsId : list) {
+			TbGoods tbGoods = tbGoodsMapper.selectById(goodsId);
+			if(Objects.isNull(tbGoods)){
+				throw new RuntimeException("该商品不存在");
+			}
+			int i =tbTradeAreaMapper.addGoodsToTradeArea(tradeAreaId,goodsId);
+			line = i+1;
+		}
+		return line;
+
+	}
+	/**
+	 *删除商品分类中的商品
+	 *
+	 * @author loovi
+	 * @date
+	 */
+	public int delGoodsFromTradeArea(Long tradeAreaId,Long [] goodsIds){
+
+		// 获取当前登录用户id
+//		Long loginId = StpUserUtil.getLoginIdAsLong();
+		int line = 0;
+		// 获取互市区信息
+		TbTradeArea tbTradeArea = tbTradeAreaMapper.selectById(tradeAreaId);
+		// 如果互市区不存在则抛异常
+		if (Objects.isNull(tbTradeArea)){
+			throw new RuntimeException("该商品类型不存在");
+		}
+		List<Long> list = Arrays.asList(goodsIds);
+		// 从互市区删除商品
+		for (Long goodsId : list) {
+			TbGoods tbGoods = tbGoodsMapper.selectById(goodsId);
+			if(Objects.isNull(tbGoods)){
+				throw new RuntimeException("该商品不存在");
+			}
+			int i =tbTradeAreaMapper.delGoodsFromTradeArea(tradeAreaId,goodsId);
+			line = i+1;
+		}
+		return line;
+	}
+
+
+
 
 	/**
 	 * 导入