提交 0ebe743e 作者: xiaowang

新增:商品编辑接口

上级 b5eb8629
......@@ -37,4 +37,11 @@ public class MallGoodsController extends BaseController {
public ResultBody<MallGoodsVO> mallGoodsDetails(@RequestParam Long id) {
return mallGoodsService.mallGoodsDetails(id);
}
@ApiOperation(value = "编辑商城商品")
@PostMapping("editMallGoods")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
public ResultBody editMallGoods(@RequestBody MallGoodsVO mallGoodsVO, HttpServletRequest request) {
return mallGoodsService.editMallGoods(mallGoodsVO, this.getUserLoginInfoFromRedis(request).getUserAccountId());
}
}
......@@ -35,4 +35,10 @@ public interface MallGoodsDao {
List<GoodsSpecDO> getMallGoodsSpec(Long id);
List<GoodsSpecValuesDO> getMallGoodsSpecValues(List<Integer> ids);
void updateMallGoods(@Param("mallGoodsDO") MallGoodsDO mallGoodsDO);
void deleteMallGoodsResources(Long id);
void deleteMallGoodsSpec(Long id);
}
......@@ -26,31 +26,41 @@ public class MallGoodsVO {
@ApiModelProperty(value = "id", example = "1")
@NotNull(message = "id不能为空", groups = {Update.class})
private Long id;
@ApiModelProperty(value = "商品名称", example = "这是商品名称", required = true)
@NotBlank(message = "商品名称不能为空", groups = {Update.class, Create.class})
private String tradeName;
@ApiModelProperty(value = "商品描述", example = "商品描述", required = true)
@NotBlank(message = "商品描述不能为空", groups = {Update.class, Create.class})
private String description;
@ApiModelProperty(value = "商品资源:图片or视频及其他")
@NotEmpty(message = "图片不能为空")
private List<GoodsResourcesVO> resourcesList;
@ApiModelProperty(value = "一级分类id", example = "1", required = true)
@NotNull(message = "一级分类id不能为空", groups = {Update.class, Create.class})
private Integer categoryPrimaryId;
@ApiModelProperty(value = "二级分类id", example = "2", required = true)
@NotNull(message = "二级分类id不能为空", groups = {Update.class, Create.class})
private Integer categorySubId;
@ApiModelProperty(value = "商品状态", example = "1", required = true)
@NotNull(message = "商品状态不能为空", groups = {Update.class, Create.class})
private Integer shelfStatus;
@ApiModelProperty(value = "商品标签")
private String goodsLabel;
@ApiModelProperty(value = "标签是否显示 0否 1是")
private Integer labelShow;
@ApiModelProperty(value = "规格")
@NotEmpty(message = "规格不能为空", groups = {Update.class, Create.class})
private List<GoodsSpecVO> goodsSpecList;
@ApiModelProperty(value = "商品详情 富文本")
private String goodsDetails;
}
......@@ -11,4 +11,6 @@ public interface MallGoodsService {
ResultBody addMallGoods(MallGoodsVO mallGoodsVO, Integer userAccountId);
ResultBody<MallGoodsVO> mallGoodsDetails(Long id);
ResultBody editMallGoods(MallGoodsVO mallGoodsVO, Integer userAccountId);
}
......@@ -50,12 +50,14 @@ public class MallGoodsServiceImpl implements MallGoodsService {
// 将基础信息存储入库
mallGoodsDao.insertMallGoodsBaseInfo(mallGoodsDO);
// 将商品图片等资源存入数据库中
List<MallGoodsResourcesDO> mallGoodsResourcesList = mallGoodsVO.getResourcesList().stream().map(d -> {
MallGoodsResourcesDO mallGoodsResourcesDO = new MallGoodsResourcesDO(d);
mallGoodsResourcesDO.setMallGoodsId(id);
return mallGoodsResourcesDO;
}).collect(Collectors.toList());
mallGoodsDao.batchInsertMallGoodsResources(mallGoodsResourcesList);
insertMallGoodsResources(mallGoodsVO, id);
// 将商品规格存入数据库
insertMallGoodsSpec(mallGoodsVO, id);
return ResultBody.success();
}
@Transactional(rollbackFor = Exception.class)
public void insertMallGoodsSpec(MallGoodsVO mallGoodsVO, long id) {
// 获取输入的规格信息
List<GoodsSpecVO> goodsSpecList = mallGoodsVO.getGoodsSpecList();
for (GoodsSpecVO goodsSpecVO : goodsSpecList) {
......@@ -70,7 +72,16 @@ public class MallGoodsServiceImpl implements MallGoodsService {
// 批量插入规格值的信息
mallGoodsDao.batchInsertSpecValues(goodsSpecValuesList);
}
return ResultBody.success();
}
@Transactional(rollbackFor = Exception.class)
public void insertMallGoodsResources(MallGoodsVO mallGoodsVO, long id) {
List<MallGoodsResourcesDO> mallGoodsResourcesList = mallGoodsVO.getResourcesList().stream().map(d -> {
MallGoodsResourcesDO mallGoodsResourcesDO = new MallGoodsResourcesDO(d);
mallGoodsResourcesDO.setMallGoodsId(id);
return mallGoodsResourcesDO;
}).collect(Collectors.toList());
mallGoodsDao.batchInsertMallGoodsResources(mallGoodsResourcesList);
}
private ResultBody checkInformation(MallGoodsVO mallGoodsVO, Integer userAccountId) {
......@@ -113,4 +124,21 @@ public class MallGoodsServiceImpl implements MallGoodsService {
mallGoodsVO.setGoodsSpecList(goodsSpec);
return ResultBody.success(mallGoodsVO);
}
@Override
public ResultBody editMallGoods(MallGoodsVO mallGoodsVO, Integer userAccountId) {
ResultBody resultError = checkInformation(mallGoodsVO, userAccountId);
if (resultError != null) return resultError;
MallGoodsDO mallGoodsDO = new MallGoodsDO(mallGoodsVO);
// 修改商城商品的基本信息
mallGoodsDao.updateMallGoods(mallGoodsDO);
// 修改商城商品的图片等资源信息,先删除后新增
mallGoodsDao.deleteMallGoodsResources(mallGoodsVO.getId());
this.insertMallGoodsResources(mallGoodsVO, mallGoodsVO.getId());
// 修改商城规格信息,先删除后新增
mallGoodsDao.deleteMallGoodsSpec(mallGoodsVO.getId());
this.insertMallGoodsSpec(mallGoodsVO, mallGoodsVO.getId());
return ResultBody.success();
}
}
......@@ -53,6 +53,28 @@
(#{item.mallGoodsId},#{item.url},#{item.type})
</foreach>
</insert>
<update id="updateMallGoods">
UPDATE mall_goods
SET trade_name = #{mallGoodsDO.tradeName},
description = #{mallGoodsDO.description},
category_primary_id = #{mallGoodsDO.categoryPrimaryId},
category_sub_id = #{mallGoodsDO.categorySubId},
shelf_status = #{mallGoodsDO.shelfStatus},
goods_label = #{mallGoodsDO.goodsLabel},
label_show = #{mallGoodsDO.labelShow},
goods_details = #{mallGoodsDO.goodsDetails}
WHERE id = #{mallGoodsDO.id}
</update>
<delete id="deleteMallGoodsResources">
delete
from mall_goods_resources
where mall_goods_id = #{id}
</delete>
<delete id="deleteMallGoodsSpec">
delete
from goods_spec
where mall_goods_id = #{id}
</delete>
<select id="countMallGoodsByName" resultType="java.lang.Integer">
select count(*)
from mall_goods
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论