商品页面OK
This commit is contained in:
parent
dc94c472cb
commit
b79756a488
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,126 +1,124 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
|
||||
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<th:block th:include="include :: header('新增商品')" />
|
||||
<th:block th:include="include :: select2-css" />
|
||||
<th:block th:include="include :: header('新增商品')"/>
|
||||
<th:block th:include="include :: select2-css"/>
|
||||
</head>
|
||||
<body>
|
||||
<div class="main-content">
|
||||
<form id="form-goods-add" class="form-horizontal">
|
||||
<h4 class="form-header h4">基本信息</h4>
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label is-required">商品名称:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="goodsName" placeholder="请输入商品名称" class="form-control" type="text" maxlength="30" required>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label is-required">价格:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="goodsPrice" placeholder="请输入商品价格" class="form-control" type="text" maxlength="12" required>
|
||||
</div>
|
||||
<div class="main-content">
|
||||
<form id="form-goods-add" class="form-horizontal">
|
||||
<h4 class="form-header h4">基本信息</h4>
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label is-required">商品名称:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="goodsName" placeholder="请输入商品名称" class="form-control" type="text" maxlength="30"
|
||||
required>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label is-required">优惠价:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="discountsPrice" placeholder="请输入优惠价" class="form-control" type="text" maxlength="12" required>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label is-required">团购价:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="groupPrice" placeholder="请输入团购价" class="form-control" type="text" maxlength="12" required>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label is-required">价格:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="goodsPrice" placeholder="请输入商品价格" class="form-control" type="text" maxlength="12"
|
||||
required>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label is-required">优惠价:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="discountsPrice" placeholder="请输入优惠价" class="form-control" type="text"
|
||||
maxlength="12" required>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label is-required">团购价:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="groupPrice" placeholder="请输入团购价" class="form-control" type="text" maxlength="12"
|
||||
required>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label">商品类别:</label>
|
||||
<div class="col-xs-8">
|
||||
<select name="deptGoodsCategoryId" class="form-control m-b">
|
||||
<option th:each="item : ${deptGoodsCategories}" th:text="${item.goodsCategoryName}"
|
||||
th:value="${item.deptGoodsCategoryId}"></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label">状态:</label>
|
||||
<div class="col-sm-8">
|
||||
<select name="status" class="form-control m-b" th:with="type=${@dict.getType('goods_status')}">
|
||||
<option th:each="dict : ${type}" th:text="${dict.dictLabel}"
|
||||
th:value="${dict.dictValue}"></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label is-required">商品库存:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="goodsNumber" placeholder="请输入商品库存" class="form-control" type="text" maxlength="12"
|
||||
required>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label">商品类别:</label>
|
||||
<div class="col-xs-8">
|
||||
<select name="deptGoodsCategoryId" class="form-control m-b" >
|
||||
<option th:each="item : ${deptGoodsCategories}" th:text="${item.goodsCategoryName}" th:value="${item.deptGoodsCategoryId}"></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label">状态:</label>
|
||||
<div class="col-sm-8">
|
||||
<select name="status" class="form-control m-b" th:with="type=${@dict.getType('goods_status')}">
|
||||
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label is-required">商品库存:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="goodsNumber" placeholder="请输入商品库存" class="form-control" type="text" maxlength="12" required>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h4 class="form-header h4">其他信息</h4>
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div class="form-group">
|
||||
<label class="col-xs-2 control-label">备注:</label>
|
||||
<div class="col-xs-10">
|
||||
<textarea name="remark" maxlength="500" class="form-control" rows="3"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-offset-5 col-sm-10">
|
||||
<button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>
|
||||
<button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
|
||||
</div>
|
||||
</div>
|
||||
<th:block th:include="include :: footer" />
|
||||
<th:block th:include="include :: select2-js" />
|
||||
<script>
|
||||
var prefix = ctx + "goods/goods";
|
||||
|
||||
$("#form-goods-add").validate({
|
||||
onkeyup: false,
|
||||
rules:{
|
||||
|
||||
},
|
||||
messages: {
|
||||
<h4 class="form-header h4">其他信息</h4>
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div class="form-group">
|
||||
<label class="col-xs-2 control-label">备注:</label>
|
||||
<div class="col-xs-10">
|
||||
<textarea name="remark" maxlength="500" class="form-control" rows="3"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
},
|
||||
focusCleanup: true
|
||||
});
|
||||
|
||||
function submitHandler() {
|
||||
if ($.validate.form()) {
|
||||
var data = $("#form-goods-add").serializeArray();
|
||||
$.operate.saveTab(prefix + "/add", data);
|
||||
$.modal.close(index);
|
||||
}
|
||||
}
|
||||
<th:block th:include="include :: footer"/>
|
||||
<th:block th:include="include :: select2-js"/>
|
||||
|
||||
</script>
|
||||
<script>
|
||||
var prefix = ctx + "goods/goods";
|
||||
|
||||
$("#form-goods-add").validate({
|
||||
onkeyup: false,
|
||||
rules: {},
|
||||
messages: {},
|
||||
focusCleanup: true
|
||||
});
|
||||
|
||||
function submitHandler() {
|
||||
if ($.validate.form()) {
|
||||
var data = $("#form-goods-add").serializeArray();
|
||||
$.operate.saveTab(prefix + "/add", data);
|
||||
$.modal.close();
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
|
||||
|
||||
<head>
|
||||
<th:block th:include="include :: header('修改商品')"/>
|
||||
<th:block th:include="include :: select2-css"/>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="main-content">
|
||||
<form class="form-horizontal" id="form-goods-edit" th:object="${goods}">
|
||||
<input id="goodsId" name="goodsId" type="hidden" th:field="*{goodsId}"/>
|
||||
<h4 class="form-header h4">基本信息</h4>
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label is-required">商品名称:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="goodsName" placeholder="请输入商品名称" class="form-control" type="text" maxlength="30"
|
||||
th:field="*{goodsName}"
|
||||
required>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label is-required">价格:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="goodsPrice" placeholder="请输入商品价格" class="form-control" type="text" maxlength="12"
|
||||
th:field="*{goodsPrice}"
|
||||
required>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label is-required">优惠价:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="discountsPrice" placeholder="请输入优惠价" class="form-control" type="text"
|
||||
th:field="*{discountsPrice}"
|
||||
maxlength="12" required>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label is-required">团购价:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="groupPrice" placeholder="请输入团购价" class="form-control" type="text" maxlength="12"
|
||||
th:field="*{groupPrice}"
|
||||
required>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label">商品类别:</label>
|
||||
<div class="col-xs-8">
|
||||
<select name="deptGoodsCategoryId" class="form-control m-b">
|
||||
<option th:each="item : ${deptGoodsCategories}" th:text="${item.goodsCategoryName}"
|
||||
th:value="${item.deptGoodsCategoryId}" th:field="*{deptGoodsCategoryId}"></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label">状态:</label>
|
||||
<div class="col-sm-8">
|
||||
<select name="status" class="form-control m-b" th:with="type=${@dict.getType('goods_status')}">
|
||||
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:field="*{status}"
|
||||
th:value="${dict.dictValue}"></option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-4 control-label is-required">商品库存:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="goodsNumber" placeholder="请输入商品库存" class="form-control" type="text" maxlength="12"
|
||||
th:field="*{goodsNumber}"
|
||||
required>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h4 class="form-header h4">其他信息</h4>
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div class="form-group">
|
||||
<label class="col-xs-2 control-label">备注:</label>
|
||||
<div class="col-xs-10">
|
||||
<textarea name="remark" maxlength="500" class="form-control" rows="3"
|
||||
th:field="*{remark}"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<th:block th:include="include :: footer"/>
|
||||
<th:block th:include="include :: select2-js"/>
|
||||
|
||||
<script type="text/javascript">
|
||||
var prefix = ctx + "goods/goods";
|
||||
|
||||
$("#form-goods-edit").validate({
|
||||
onkeyup: false,
|
||||
rules: {},
|
||||
messages: {},
|
||||
focusCleanup: true
|
||||
});
|
||||
|
||||
function submitHandler() {
|
||||
if ($.validate.form()) {
|
||||
var data = $("#form-goods-edit").serializeArray();
|
||||
$.operate.saveTab(prefix + "/edit", data);
|
||||
$.modal.close();
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -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<Goods> selectGoodsList(Goods goods);
|
||||
List<Goods> 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Goods> selectGoodsList(Goods goods);
|
||||
List<Goods> 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);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,8 +33,6 @@
|
|||
<update id="updateGoods" parameterType="com.ghy.goods.domain.Goods">
|
||||
UPDATE goods
|
||||
<set>
|
||||
<if test="goodsCode != null and goodsCode != ''">goods_code = #{goodsCode},</if>
|
||||
<if test="deptId != null and deptId != ''">dept_id = #{deptId},</if>
|
||||
<if test="goodsName != null and goodsName != ''">goods_name = #{goodsName},</if>
|
||||
<if test="goodsPrice != null and goodsPrice != ''">goods_price = #{goodsPrice},</if>
|
||||
<if test="discountsPrice != null and discountsPrice != ''">discounts_price = #{discountsPrice},</if>
|
||||
|
|
@ -52,6 +50,12 @@
|
|||
WHERE goods_id = #{goodsId}
|
||||
</update>
|
||||
|
||||
<update id="setCode">
|
||||
UPDATE goods
|
||||
SET goods_code = #{goodsCode}, update_time = sysdate()
|
||||
WHERE goods_id = #{goodsId}
|
||||
</update>
|
||||
|
||||
<insert id="insertGoods" parameterType="com.ghy.goods.domain.Goods" useGeneratedKeys="true" keyProperty="goodsId">
|
||||
insert into goods(
|
||||
<if test="goodsCode != null and goodsCode != ''">goods_code,</if>
|
||||
|
|
|
|||
Loading…
Reference in New Issue