From b79756a488acaecca116d29f8ff394ead6a2b269 Mon Sep 17 00:00:00 2001 From: HH Date: Tue, 10 May 2022 20:54:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E9=A1=B5=E9=9D=A2OK?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/goods/GoodsController.java | 14 +- .../resources/templates/goods/goods/add.html | 218 +++++++++--------- .../resources/templates/goods/goods/edit.html | 134 +++++++++++ .../com/ghy/goods/mapper/GoodsMapper.java | 24 +- .../com/ghy/goods/service/GoodsService.java | 19 +- .../goods/service/impl/GoodsServiceImpl.java | 25 +- .../resources/mapper/goods/GoodsMapper.xml | 8 +- 7 files changed, 292 insertions(+), 150 deletions(-) create mode 100644 ghy-admin/src/main/resources/templates/goods/goods/edit.html diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsController.java b/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsController.java index 897aeb55..37b380f2 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsController.java @@ -1,14 +1,12 @@ package com.ghy.web.controller.goods; import com.ghy.common.annotation.Log; -import com.ghy.common.constant.UserConstants; import com.ghy.common.core.controller.BaseController; import com.ghy.common.core.domain.AjaxResult; import com.ghy.common.core.page.TableDataInfo; import com.ghy.common.enums.BusinessType; import com.ghy.common.utils.ShiroUtils; import com.ghy.common.utils.poi.ExcelUtil; -import com.ghy.goods.domain.DeptGoodsCategory; import com.ghy.goods.domain.Goods; import com.ghy.goods.service.DeptGoodsCategoryService; import com.ghy.goods.service.GoodsService; @@ -87,11 +85,6 @@ public class GoodsController extends BaseController { @PostMapping("/add") @ResponseBody public AjaxResult addSave(@Validated Goods goods) { - if (UserConstants.GOODS_CODE_NOT_UNIQUE.equals(goodsService.checkGoodsNameUnique(goods))) { - return error("新增商品'" + goods.getGoodsName() + "'失败,商品名称已存在"); - } else if (UserConstants.GOODS_CODE_NOT_UNIQUE.equals(goodsService.checkGoodsCodeUnique(goods))) { - return error("新增商品'" + goods.getGoodsName() + "'失败,商品编码已存在"); - } goods.setCreateBy(getLoginName()); goods.setDeptId(getSysUser().getDeptId()); return toAjax(goodsService.insertGoods(goods)); @@ -103,6 +96,8 @@ public class GoodsController extends BaseController { @RequiresPermissions("goods:goods:edit") @GetMapping("/edit/{goodsId}") public String edit(@PathVariable("goodsId") Long goodsId, ModelMap mmap) { + Long parentId = ShiroUtils.getSysUser().getParentId(); + mmap.put("deptGoodsCategories", deptGoodsCategoryService.list(parentId)); mmap.put("goods", goodsService.selectById(goodsId)); return PREFIX + "/edit"; } @@ -115,11 +110,6 @@ public class GoodsController extends BaseController { @PostMapping("/edit") @ResponseBody public AjaxResult editSave(@Validated Goods goods) { - if (UserConstants.GOODS_NAME_NOT_UNIQUE.equals(goodsService.checkGoodsNameUnique(goods))) { - return error("修改商品'" + goods.getGoodsName() + "'失败,商品名称已存在"); - } else if (UserConstants.GOODS_CODE_NOT_UNIQUE.equals(goodsService.checkGoodsCodeUnique(goods))) { - return error("修改商品'" + goods.getGoodsCode() + "'失败,商品编码已存在"); - } goods.setUpdateBy(getLoginName()); return toAjax(goodsService.updateGoods(goods)); } diff --git a/ghy-admin/src/main/resources/templates/goods/goods/add.html b/ghy-admin/src/main/resources/templates/goods/goods/add.html index 47164469..c6d3feb7 100644 --- a/ghy-admin/src/main/resources/templates/goods/goods/add.html +++ b/ghy-admin/src/main/resources/templates/goods/goods/add.html @@ -1,126 +1,124 @@ - + - - + + -
-
-

基本信息

-
-
-
- -
- -
-
-
-
-
- -
- -
+
+ +

基本信息

+
+
+
+ +
+
-
-
-
- -
- -
-
-
-
-
- -
- -
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+
-
-
-
- -
- -
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- -
-
-
-
- -

其他信息

-
-
-
- -
- -
-
-
-
- -
- -
-
-   -
-
- - - + \ No newline at end of file diff --git a/ghy-admin/src/main/resources/templates/goods/goods/edit.html b/ghy-admin/src/main/resources/templates/goods/goods/edit.html new file mode 100644 index 00000000..34b3fcd0 --- /dev/null +++ b/ghy-admin/src/main/resources/templates/goods/goods/edit.html @@ -0,0 +1,134 @@ + + + + + + + + + + +
+
+ +

基本信息

+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+ +

其他信息

+
+
+
+ +
+ +
+
+
+
+
+
+ + + + + + + \ No newline at end of file diff --git a/ghy-goods/src/main/java/com/ghy/goods/mapper/GoodsMapper.java b/ghy-goods/src/main/java/com/ghy/goods/mapper/GoodsMapper.java index e92e96c4..1b45b5d8 100644 --- a/ghy-goods/src/main/java/com/ghy/goods/mapper/GoodsMapper.java +++ b/ghy-goods/src/main/java/com/ghy/goods/mapper/GoodsMapper.java @@ -1,6 +1,7 @@ package com.ghy.goods.mapper; import com.ghy.goods.domain.Goods; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -14,26 +15,26 @@ public interface GoodsMapper { * @param goods 商品属性 * @return 成功条数 */ - public int insertGoods(Goods goods); + int insertGoods(Goods goods); /** * @param goods 商品属性 * @return 成功条数 */ - public int updateGoods(Goods goods); + int updateGoods(Goods goods); /** * @param goods 商品入参 * @return 商品集合 */ - public List selectGoodsList(Goods goods); + List selectGoodsList(Goods goods); /** * @param goodsId 商品id * @return 商品 */ - public Goods selectById(Long goodsId); + Goods selectById(Long goodsId); /** * 批量删除商品信息 @@ -41,19 +42,19 @@ public interface GoodsMapper { * @param goodsId 需要删除的数据ID * @return 结果 */ - public int deleteGoodsByIds(Long[] goodsId); + int deleteGoodsByIds(Long[] goodsId); /** * @param goodsName 商品名称 * @return 商品信息 */ - public Goods checkGoodsNameUnique(String goodsName); + Goods checkGoodsNameUnique(String goodsName); /** * @param goodsCode 商品编码 * @return 商品信息 */ - public Goods checkGoodsCodeUnique(String goodsCode); + Goods checkGoodsCodeUnique(String goodsCode); /** * 用商品类别ID查询一条商品信息 @@ -63,4 +64,13 @@ public interface GoodsMapper { * @return 商品信息 */ Goods selectOneByGoodsCategoryId(Long goodsCategoryId); + + /** + * 设置商品编号 + * + * @param goodsId 商品ID + * @param goodsCode 商品编号 + * @return + */ + int setCode(@Param("goodsId") Long goodsId, @Param("goodsCode") String goodsCode); } diff --git a/ghy-goods/src/main/java/com/ghy/goods/service/GoodsService.java b/ghy-goods/src/main/java/com/ghy/goods/service/GoodsService.java index 39b7426d..10bf5263 100644 --- a/ghy-goods/src/main/java/com/ghy/goods/service/GoodsService.java +++ b/ghy-goods/src/main/java/com/ghy/goods/service/GoodsService.java @@ -5,7 +5,8 @@ import com.ghy.goods.domain.Goods; import java.util.List; /** - * 商品模块接口 + * 商品模块接口 + * * @author clunt */ public interface GoodsService { @@ -14,45 +15,47 @@ public interface GoodsService { * @param goods 商品属性 * @return 成功条数 */ - public int insertGoods(Goods goods); + int insertGoods(Goods goods); /** * @param goods 商品属性 * @return 成功条数 */ - public int updateGoods(Goods goods); + int updateGoods(Goods goods); /** * @param goods 商品入参 * @return 商品集合 */ - public List selectGoodsList(Goods goods); + List selectGoodsList(Goods goods); /** * @param goodsId 商品id * @return 商品 */ - public Goods selectById(Long goodsId); + Goods selectById(Long goodsId); /** * @param ids 商品ids * @return 删除结果 */ - public int deleteGoodsByIds(String ids); + int deleteGoodsByIds(String ids); /** * 校验商品名称是否重复 + * * @param goods 商品属性 * @return 校验结果 1存在 0不存在 */ - public String checkGoodsNameUnique(Goods goods); + String checkGoodsNameUnique(Goods goods); /** * 校验商品编码是否重复 + * * @param goods 商品属性 * @return 校验结果 1存在 0不存在 */ - public String checkGoodsCodeUnique(Goods goods); + String checkGoodsCodeUnique(Goods goods); } diff --git a/ghy-goods/src/main/java/com/ghy/goods/service/impl/GoodsServiceImpl.java b/ghy-goods/src/main/java/com/ghy/goods/service/impl/GoodsServiceImpl.java index 29e82c9e..8d53c7c8 100644 --- a/ghy-goods/src/main/java/com/ghy/goods/service/impl/GoodsServiceImpl.java +++ b/ghy-goods/src/main/java/com/ghy/goods/service/impl/GoodsServiceImpl.java @@ -8,12 +8,15 @@ import com.ghy.goods.domain.Goods; import com.ghy.goods.mapper.GoodsMapper; import com.ghy.goods.service.GoodsService; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.Assert; import javax.annotation.Resource; import java.util.List; /** - * 商品模块实现类 + * 商品模块实现类 + * * @author clunt */ @Service @@ -23,8 +26,12 @@ public class GoodsServiceImpl implements GoodsService { private GoodsMapper goodsMapper; @Override + @Transactional(rollbackFor = Exception.class) public int insertGoods(Goods goods) { - return goodsMapper.insertGoods(goods); + goodsMapper.insertGoods(goods); + Assert.notNull(goods.getGoodsId(), "操作失败"); + String code = String.format("GD%019d", goods.getGoodsId()); + return goodsMapper.setCode(goods.getGoodsId(), code); } @Override @@ -45,11 +52,9 @@ public class GoodsServiceImpl implements GoodsService { @Override public int deleteGoodsByIds(String ids) { Long[] goodsIds = Convert.toLongArray(ids); - for (Long goodsId : goodsIds) - { + for (Long goodsId : goodsIds) { Goods goods = selectById(goodsId); - if (countUserGoodsById(goods) > 0) - { + if (countUserGoodsById(goods) > 0) { throw new ServiceException(String.format("%1$s正在使用,不能删除", goods.getGoodsName())); } } @@ -60,8 +65,7 @@ public class GoodsServiceImpl implements GoodsService { public String checkGoodsNameUnique(Goods goods) { Long goodsId = StringUtils.isNull(goods.getGoodsId()) ? -1L : goods.getGoodsId(); Goods info = goodsMapper.checkGoodsNameUnique(goods.getGoodsName()); - if (StringUtils.isNotNull(info) && info.getGoodsId().longValue() != goodsId.longValue()) - { + if (StringUtils.isNotNull(info) && info.getGoodsId().longValue() != goodsId.longValue()) { return UserConstants.GOODS_NAME_NOT_UNIQUE; } return UserConstants.GOODS_NAME_UNIQUE; @@ -71,15 +75,14 @@ public class GoodsServiceImpl implements GoodsService { public String checkGoodsCodeUnique(Goods goods) { Long goodsId = StringUtils.isNull(goods.getGoodsId()) ? -1L : goods.getGoodsId(); Goods info = goodsMapper.checkGoodsCodeUnique(goods.getGoodsCode()); - if (StringUtils.isNotNull(info) && info.getGoodsId().longValue() != goodsId.longValue()) - { + if (StringUtils.isNotNull(info) && info.getGoodsId().longValue() != goodsId.longValue()) { return UserConstants.GOODS_CODE_NOT_UNIQUE; } return UserConstants.GOODS_CODE_UNIQUE; } - public int countUserGoodsById(Goods goods){ + public int countUserGoodsById(Goods goods) { //TODO 校验商品是否上架 return 0; } diff --git a/ghy-goods/src/main/resources/mapper/goods/GoodsMapper.xml b/ghy-goods/src/main/resources/mapper/goods/GoodsMapper.xml index 65ff4dea..ff0ec65d 100644 --- a/ghy-goods/src/main/resources/mapper/goods/GoodsMapper.xml +++ b/ghy-goods/src/main/resources/mapper/goods/GoodsMapper.xml @@ -33,8 +33,6 @@ UPDATE goods - goods_code = #{goodsCode}, - dept_id = #{deptId}, goods_name = #{goodsName}, goods_price = #{goodsPrice}, discounts_price = #{discountsPrice}, @@ -52,6 +50,12 @@ WHERE goods_id = #{goodsId} + + UPDATE goods + SET goods_code = #{goodsCode}, update_time = sysdate() + WHERE goods_id = #{goodsId} + + insert into goods( goods_code,