商品编辑
This commit is contained in:
parent
52cf089c73
commit
7b0c54024e
|
|
@ -390,8 +390,8 @@ public class GoodsController extends BaseController {
|
|||
@PostMapping("/app/edit")
|
||||
@ResponseBody
|
||||
public AjaxResult appEditSave(@RequestBody @Validated Goods goods) {
|
||||
// goods.setUpdateBy(getLoginName());
|
||||
// return toAjax(goodsService.updateGoods(goods));
|
||||
|
||||
goodsService.edit(goods);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ public interface GoodsAreaMapper {
|
|||
*/
|
||||
List<GoodsArea> selectByGoodsId(Long goodsId);
|
||||
|
||||
void deleteByGoodsId(Long goodsId);
|
||||
|
||||
/**
|
||||
* @param areas 区域集合id
|
||||
* @return 批量insert成功条数
|
||||
|
|
|
|||
|
|
@ -55,4 +55,6 @@ public interface GoodsStandardMapper {
|
|||
|
||||
int updateSaleNum(GoodsStandard goodsStandard);
|
||||
|
||||
int update(GoodsStandard goodsStandard);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,4 +23,7 @@ public interface GoodsAreaService {
|
|||
*/
|
||||
int batchInsert(List<GoodsArea> areas);
|
||||
|
||||
void deleteByGoodsId(Long goodsId);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,4 +93,6 @@ public interface GoodsService {
|
|||
*/
|
||||
List<Goods> selectByCategoryIds(Collection<Long> ids);
|
||||
|
||||
int edit(Goods goods);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ public interface GoodsStandardService {
|
|||
int batchInsert(List<GoodsStandard> goodsStandardList);
|
||||
|
||||
|
||||
void deleteByGoodsId(Long goodsId);
|
||||
|
||||
/**
|
||||
* @param request 校验的商品数量
|
||||
* @return 返回结果
|
||||
|
|
@ -54,4 +56,6 @@ public interface GoodsStandardService {
|
|||
|
||||
int updateSaleNum(GoodsStandard goodsStandard);
|
||||
|
||||
int update(GoodsStandard goodsStandard);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,4 +33,8 @@ public class GoodsAreaServiceImpl implements GoodsAreaService {
|
|||
return goodsAreaMapper.batchInsert(areas);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByGoodsId(Long goodsId) {
|
||||
goodsAreaMapper.deleteByGoodsId(goodsId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -162,6 +162,45 @@ public class GoodsServiceImpl implements GoodsService {
|
|||
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) {
|
||||
//TODO 校验商品是否上架
|
||||
|
|
|
|||
|
|
@ -52,6 +52,11 @@ public class GoodsStandardServiceImpl implements GoodsStandardService {
|
|||
return goodsStandardMapper.batchInsert(goodsStandardList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByGoodsId(Long goodsId) {
|
||||
goodsStandardMapper.deleteByGoodsId(goodsId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GoodsStandard> checkStore(AppGoodsRequest request) {
|
||||
return goodsStandardMapper.checkStore(request);
|
||||
|
|
@ -71,4 +76,9 @@ public class GoodsStandardServiceImpl implements GoodsStandardService {
|
|||
public int updateSaleNum(GoodsStandard goodsStandard) {
|
||||
return goodsStandardMapper.updateSaleNum(goodsStandard);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(GoodsStandard goodsStandard) {
|
||||
return goodsStandardMapper.update(goodsStandard);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,11 @@
|
|||
</where>
|
||||
</select>
|
||||
|
||||
<delete id="deleteByGoodsId">
|
||||
delete from goods_area
|
||||
where goods_id = #{goodsId}
|
||||
</delete>
|
||||
|
||||
<insert id="batchInsert" parameterType="list" >
|
||||
INSERT INTO goods_area ( goods_id,country_area_id)
|
||||
VALUES
|
||||
|
|
|
|||
|
|
@ -112,4 +112,21 @@
|
|||
goods_standard_id = #{goodsStandardId}
|
||||
</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>
|
||||
|
|
|
|||
Loading…
Reference in New Issue