商品编辑

This commit is contained in:
kuang.yife 2023-02-27 22:59:15 +08:00
parent 52cf089c73
commit 7b0c54024e
11 changed files with 90 additions and 2 deletions

View File

@ -390,8 +390,8 @@ public class GoodsController extends BaseController {
@PostMapping("/app/edit") @PostMapping("/app/edit")
@ResponseBody @ResponseBody
public AjaxResult appEditSave(@RequestBody @Validated Goods goods) { public AjaxResult appEditSave(@RequestBody @Validated Goods goods) {
// goods.setUpdateBy(getLoginName());
// return toAjax(goodsService.updateGoods(goods)); goodsService.edit(goods);
return AjaxResult.success(); return AjaxResult.success();
} }

View File

@ -13,6 +13,8 @@ public interface GoodsAreaMapper {
*/ */
List<GoodsArea> selectByGoodsId(Long goodsId); List<GoodsArea> selectByGoodsId(Long goodsId);
void deleteByGoodsId(Long goodsId);
/** /**
* @param areas 区域集合id * @param areas 区域集合id
* @return 批量insert成功条数 * @return 批量insert成功条数

View File

@ -55,4 +55,6 @@ public interface GoodsStandardMapper {
int updateSaleNum(GoodsStandard goodsStandard); int updateSaleNum(GoodsStandard goodsStandard);
int update(GoodsStandard goodsStandard);
} }

View File

@ -23,4 +23,7 @@ public interface GoodsAreaService {
*/ */
int batchInsert(List<GoodsArea> areas); int batchInsert(List<GoodsArea> areas);
void deleteByGoodsId(Long goodsId);
} }

View File

@ -93,4 +93,6 @@ public interface GoodsService {
*/ */
List<Goods> selectByCategoryIds(Collection<Long> ids); List<Goods> selectByCategoryIds(Collection<Long> ids);
int edit(Goods goods);
} }

View File

@ -41,6 +41,8 @@ public interface GoodsStandardService {
int batchInsert(List<GoodsStandard> goodsStandardList); int batchInsert(List<GoodsStandard> goodsStandardList);
void deleteByGoodsId(Long goodsId);
/** /**
* @param request 校验的商品数量 * @param request 校验的商品数量
* @return 返回结果 * @return 返回结果
@ -54,4 +56,6 @@ public interface GoodsStandardService {
int updateSaleNum(GoodsStandard goodsStandard); int updateSaleNum(GoodsStandard goodsStandard);
int update(GoodsStandard goodsStandard);
} }

View File

@ -33,4 +33,8 @@ public class GoodsAreaServiceImpl implements GoodsAreaService {
return goodsAreaMapper.batchInsert(areas); return goodsAreaMapper.batchInsert(areas);
} }
@Override
public void deleteByGoodsId(Long goodsId) {
goodsAreaMapper.deleteByGoodsId(goodsId);
}
} }

View File

@ -162,6 +162,45 @@ public class GoodsServiceImpl implements GoodsService {
return goodsMapper.selectByCategoryIds(ids); return goodsMapper.selectByCategoryIds(ids);
} }
@Override
@Transactional(rollbackFor = Exception.class)
public int edit(Goods goods) {
// 添加商品主体
int result = goodsMapper.updateGoods(goods);
// 给各组件插入商品主体id
goods.getGoodsAreaList().forEach(goodsArea -> {
goodsArea.setGoodsId(goods.getGoodsId());
});
goods.getGoodsImgsList().forEach(goodsImg -> {
goodsImg.setGoodsId(goods.getGoodsId());
});
goods.getGoodsStandardList().forEach(goodsStandard -> {
goodsStandard.setGoodsId(goods.getGoodsId());
if (goodsStandard.getExtMoney() == null) {
goodsStandard.setExtMoney(BigDecimal.ZERO);
}
});
// 批量删除各组件
goodsAreaService.deleteByGoodsId(goods.getGoodsId());
goodsImgsService.deleteByGoodsId(goods.getGoodsId());
// 批量插入各组件
goodsAreaService.batchInsert(goods.getGoodsAreaList());
goodsImgsService.batchInsert(goods.getGoodsImgsList());
goods.getGoodsStandardList().forEach(goodsStandard -> {
if(goodsStandard.getGoodsStandardId() != null){
goodsStandardService.update(goodsStandard);
}else {
List<GoodsStandard> goodsStandards = new ArrayList<>();
goodsStandards.add(goodsStandard);
goodsStandardService.batchInsert(goodsStandards);
}
});
return result;
}
public int countUserGoodsById(Goods goods) { public int countUserGoodsById(Goods goods) {
//TODO 校验商品是否上架 //TODO 校验商品是否上架

View File

@ -52,6 +52,11 @@ public class GoodsStandardServiceImpl implements GoodsStandardService {
return goodsStandardMapper.batchInsert(goodsStandardList); return goodsStandardMapper.batchInsert(goodsStandardList);
} }
@Override
public void deleteByGoodsId(Long goodsId) {
goodsStandardMapper.deleteByGoodsId(goodsId);
}
@Override @Override
public List<GoodsStandard> checkStore(AppGoodsRequest request) { public List<GoodsStandard> checkStore(AppGoodsRequest request) {
return goodsStandardMapper.checkStore(request); return goodsStandardMapper.checkStore(request);
@ -71,4 +76,9 @@ public class GoodsStandardServiceImpl implements GoodsStandardService {
public int updateSaleNum(GoodsStandard goodsStandard) { public int updateSaleNum(GoodsStandard goodsStandard) {
return goodsStandardMapper.updateSaleNum(goodsStandard); return goodsStandardMapper.updateSaleNum(goodsStandard);
} }
@Override
public int update(GoodsStandard goodsStandard) {
return goodsStandardMapper.update(goodsStandard);
}
} }

View File

@ -24,6 +24,11 @@
</where> </where>
</select> </select>
<delete id="deleteByGoodsId">
delete from goods_area
where goods_id = #{goodsId}
</delete>
<insert id="batchInsert" parameterType="list" > <insert id="batchInsert" parameterType="list" >
INSERT INTO goods_area ( goods_id,country_area_id) INSERT INTO goods_area ( goods_id,country_area_id)
VALUES VALUES

View File

@ -112,4 +112,21 @@
goods_standard_id = #{goodsStandardId} goods_standard_id = #{goodsStandardId}
</update> </update>
<update id="update">
UPDATE goods_standard
<set>
<if test="goodsStandardName != null and goodsStandardName != ''">goods_standard_name = #{goodsStandardName},</if>
<if test="goodsId != null">goods_id = #{goodsId},</if>
<if test="deptGoodsCategoryId != null and deptGoodsCategoryId != ''">dept_goods_category_id = #{deptGoodsCategoryId},</if>
<if test="goodsPrice != null">goods_price = #{goodsPrice},</if>
<if test="extMoney != null">ext_money = #{extMoney},</if>
<if test="discountPrice != null">discount_price = #{discountPrice},</if>
<if test="groupPrice != null">group_price = #{groupPrice},</if>
<if test="goodsUnit != null and goodsUnit != ''">goods_unit = #{goodsUnit},</if>
<if test="status != null">`status` = #{status},</if>
<if test="remark != null">remark = #{remark},</if>
update_time = sysdate()
</set>
WHERE goods_standard_id = #{goodsStandardId}
</update>
</mapper> </mapper>