商品页面OK
This commit is contained in:
parent
dc94c472cb
commit
b79756a488
|
|
@ -1,14 +1,12 @@
|
||||||
package com.ghy.web.controller.goods;
|
package com.ghy.web.controller.goods;
|
||||||
|
|
||||||
import com.ghy.common.annotation.Log;
|
import com.ghy.common.annotation.Log;
|
||||||
import com.ghy.common.constant.UserConstants;
|
|
||||||
import com.ghy.common.core.controller.BaseController;
|
import com.ghy.common.core.controller.BaseController;
|
||||||
import com.ghy.common.core.domain.AjaxResult;
|
import com.ghy.common.core.domain.AjaxResult;
|
||||||
import com.ghy.common.core.page.TableDataInfo;
|
import com.ghy.common.core.page.TableDataInfo;
|
||||||
import com.ghy.common.enums.BusinessType;
|
import com.ghy.common.enums.BusinessType;
|
||||||
import com.ghy.common.utils.ShiroUtils;
|
import com.ghy.common.utils.ShiroUtils;
|
||||||
import com.ghy.common.utils.poi.ExcelUtil;
|
import com.ghy.common.utils.poi.ExcelUtil;
|
||||||
import com.ghy.goods.domain.DeptGoodsCategory;
|
|
||||||
import com.ghy.goods.domain.Goods;
|
import com.ghy.goods.domain.Goods;
|
||||||
import com.ghy.goods.service.DeptGoodsCategoryService;
|
import com.ghy.goods.service.DeptGoodsCategoryService;
|
||||||
import com.ghy.goods.service.GoodsService;
|
import com.ghy.goods.service.GoodsService;
|
||||||
|
|
@ -87,11 +85,6 @@ public class GoodsController extends BaseController {
|
||||||
@PostMapping("/add")
|
@PostMapping("/add")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public AjaxResult addSave(@Validated Goods goods) {
|
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.setCreateBy(getLoginName());
|
||||||
goods.setDeptId(getSysUser().getDeptId());
|
goods.setDeptId(getSysUser().getDeptId());
|
||||||
return toAjax(goodsService.insertGoods(goods));
|
return toAjax(goodsService.insertGoods(goods));
|
||||||
|
|
@ -103,6 +96,8 @@ public class GoodsController extends BaseController {
|
||||||
@RequiresPermissions("goods:goods:edit")
|
@RequiresPermissions("goods:goods:edit")
|
||||||
@GetMapping("/edit/{goodsId}")
|
@GetMapping("/edit/{goodsId}")
|
||||||
public String edit(@PathVariable("goodsId") Long goodsId, ModelMap mmap) {
|
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));
|
mmap.put("goods", goodsService.selectById(goodsId));
|
||||||
return PREFIX + "/edit";
|
return PREFIX + "/edit";
|
||||||
}
|
}
|
||||||
|
|
@ -115,11 +110,6 @@ public class GoodsController extends BaseController {
|
||||||
@PostMapping("/edit")
|
@PostMapping("/edit")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public AjaxResult editSave(@Validated Goods goods) {
|
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());
|
goods.setUpdateBy(getLoginName());
|
||||||
return toAjax(goodsService.updateGoods(goods));
|
return toAjax(goodsService.updateGoods(goods));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,126 +1,124 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
|
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
|
||||||
<head>
|
<head>
|
||||||
<th:block th:include="include :: header('新增商品')" />
|
<th:block th:include="include :: header('新增商品')"/>
|
||||||
<th:block th:include="include :: select2-css" />
|
<th:block th:include="include :: select2-css"/>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="main-content">
|
<div class="main-content">
|
||||||
<form id="form-goods-add" class="form-horizontal">
|
<form id="form-goods-add" class="form-horizontal">
|
||||||
<h4 class="form-header h4">基本信息</h4>
|
<h4 class="form-header h4">基本信息</h4>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-sm-4 control-label is-required">商品名称:</label>
|
<label class="col-sm-4 control-label is-required">商品名称:</label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<input name="goodsName" placeholder="请输入商品名称" class="form-control" type="text" maxlength="30" required>
|
<input name="goodsName" placeholder="请输入商品名称" class="form-control" type="text" maxlength="30"
|
||||||
</div>
|
required>
|
||||||
</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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="col-sm-6">
|
||||||
<div class="col-sm-6">
|
<div class="form-group">
|
||||||
<div class="form-group">
|
<label class="col-sm-4 control-label is-required">价格:</label>
|
||||||
<label class="col-sm-4 control-label is-required">优惠价:</label>
|
<div class="col-sm-8">
|
||||||
<div class="col-sm-8">
|
<input name="goodsPrice" placeholder="请输入商品价格" class="form-control" type="text" maxlength="12"
|
||||||
<input name="discountsPrice" placeholder="请输入优惠价" class="form-control" type="text" maxlength="12" required>
|
required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-6">
|
</div>
|
||||||
<div class="form-group">
|
<div class="row">
|
||||||
<label class="col-sm-4 control-label is-required">团购价:</label>
|
<div class="col-sm-6">
|
||||||
<div class="col-sm-8">
|
<div class="form-group">
|
||||||
<input name="groupPrice" placeholder="请输入团购价" class="form-control" type="text" maxlength="12" required>
|
<label class="col-sm-4 control-label is-required">优惠价:</label>
|
||||||
</div>
|
<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>
|
||||||
</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>
|
||||||
</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:{
|
|
||||||
|
|
||||||
},
|
<h4 class="form-header h4">其他信息</h4>
|
||||||
messages: {
|
<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>
|
||||||
|
|
||||||
},
|
<th:block th:include="include :: footer"/>
|
||||||
focusCleanup: true
|
<th:block th:include="include :: select2-js"/>
|
||||||
});
|
|
||||||
|
|
||||||
function submitHandler() {
|
|
||||||
if ($.validate.form()) {
|
|
||||||
var data = $("#form-goods-add").serializeArray();
|
|
||||||
$.operate.saveTab(prefix + "/add", data);
|
|
||||||
$.modal.close(index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
</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>
|
</body>
|
||||||
</html>
|
</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;
|
package com.ghy.goods.mapper;
|
||||||
|
|
||||||
import com.ghy.goods.domain.Goods;
|
import com.ghy.goods.domain.Goods;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -14,26 +15,26 @@ public interface GoodsMapper {
|
||||||
* @param goods 商品属性
|
* @param goods 商品属性
|
||||||
* @return 成功条数
|
* @return 成功条数
|
||||||
*/
|
*/
|
||||||
public int insertGoods(Goods goods);
|
int insertGoods(Goods goods);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param goods 商品属性
|
* @param goods 商品属性
|
||||||
* @return 成功条数
|
* @return 成功条数
|
||||||
*/
|
*/
|
||||||
public int updateGoods(Goods goods);
|
int updateGoods(Goods goods);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param goods 商品入参
|
* @param goods 商品入参
|
||||||
* @return 商品集合
|
* @return 商品集合
|
||||||
*/
|
*/
|
||||||
public List<Goods> selectGoodsList(Goods goods);
|
List<Goods> selectGoodsList(Goods goods);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param goodsId 商品id
|
* @param goodsId 商品id
|
||||||
* @return 商品
|
* @return 商品
|
||||||
*/
|
*/
|
||||||
public Goods selectById(Long goodsId);
|
Goods selectById(Long goodsId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量删除商品信息
|
* 批量删除商品信息
|
||||||
|
|
@ -41,19 +42,19 @@ public interface GoodsMapper {
|
||||||
* @param goodsId 需要删除的数据ID
|
* @param goodsId 需要删除的数据ID
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int deleteGoodsByIds(Long[] goodsId);
|
int deleteGoodsByIds(Long[] goodsId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param goodsName 商品名称
|
* @param goodsName 商品名称
|
||||||
* @return 商品信息
|
* @return 商品信息
|
||||||
*/
|
*/
|
||||||
public Goods checkGoodsNameUnique(String goodsName);
|
Goods checkGoodsNameUnique(String goodsName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param goodsCode 商品编码
|
* @param goodsCode 商品编码
|
||||||
* @return 商品信息
|
* @return 商品信息
|
||||||
*/
|
*/
|
||||||
public Goods checkGoodsCodeUnique(String goodsCode);
|
Goods checkGoodsCodeUnique(String goodsCode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用商品类别ID查询一条商品信息
|
* 用商品类别ID查询一条商品信息
|
||||||
|
|
@ -63,4 +64,13 @@ public interface GoodsMapper {
|
||||||
* @return 商品信息
|
* @return 商品信息
|
||||||
*/
|
*/
|
||||||
Goods selectOneByGoodsCategoryId(Long goodsCategoryId);
|
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;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品模块接口
|
* 商品模块接口
|
||||||
|
*
|
||||||
* @author clunt
|
* @author clunt
|
||||||
*/
|
*/
|
||||||
public interface GoodsService {
|
public interface GoodsService {
|
||||||
|
|
@ -14,45 +15,47 @@ public interface GoodsService {
|
||||||
* @param goods 商品属性
|
* @param goods 商品属性
|
||||||
* @return 成功条数
|
* @return 成功条数
|
||||||
*/
|
*/
|
||||||
public int insertGoods(Goods goods);
|
int insertGoods(Goods goods);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param goods 商品属性
|
* @param goods 商品属性
|
||||||
* @return 成功条数
|
* @return 成功条数
|
||||||
*/
|
*/
|
||||||
public int updateGoods(Goods goods);
|
int updateGoods(Goods goods);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param goods 商品入参
|
* @param goods 商品入参
|
||||||
* @return 商品集合
|
* @return 商品集合
|
||||||
*/
|
*/
|
||||||
public List<Goods> selectGoodsList(Goods goods);
|
List<Goods> selectGoodsList(Goods goods);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param goodsId 商品id
|
* @param goodsId 商品id
|
||||||
* @return 商品
|
* @return 商品
|
||||||
*/
|
*/
|
||||||
public Goods selectById(Long goodsId);
|
Goods selectById(Long goodsId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ids 商品ids
|
* @param ids 商品ids
|
||||||
* @return 删除结果
|
* @return 删除结果
|
||||||
*/
|
*/
|
||||||
public int deleteGoodsByIds(String ids);
|
int deleteGoodsByIds(String ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验商品名称是否重复
|
* 校验商品名称是否重复
|
||||||
|
*
|
||||||
* @param goods 商品属性
|
* @param goods 商品属性
|
||||||
* @return 校验结果 1存在 0不存在
|
* @return 校验结果 1存在 0不存在
|
||||||
*/
|
*/
|
||||||
public String checkGoodsNameUnique(Goods goods);
|
String checkGoodsNameUnique(Goods goods);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验商品编码是否重复
|
* 校验商品编码是否重复
|
||||||
|
*
|
||||||
* @param goods 商品属性
|
* @param goods 商品属性
|
||||||
* @return 校验结果 1存在 0不存在
|
* @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.mapper.GoodsMapper;
|
||||||
import com.ghy.goods.service.GoodsService;
|
import com.ghy.goods.service.GoodsService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品模块实现类
|
* 商品模块实现类
|
||||||
|
*
|
||||||
* @author clunt
|
* @author clunt
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
|
@ -23,8 +26,12 @@ public class GoodsServiceImpl implements GoodsService {
|
||||||
private GoodsMapper goodsMapper;
|
private GoodsMapper goodsMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public int insertGoods(Goods goods) {
|
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
|
@Override
|
||||||
|
|
@ -45,11 +52,9 @@ public class GoodsServiceImpl implements GoodsService {
|
||||||
@Override
|
@Override
|
||||||
public int deleteGoodsByIds(String ids) {
|
public int deleteGoodsByIds(String ids) {
|
||||||
Long[] goodsIds = Convert.toLongArray(ids);
|
Long[] goodsIds = Convert.toLongArray(ids);
|
||||||
for (Long goodsId : goodsIds)
|
for (Long goodsId : goodsIds) {
|
||||||
{
|
|
||||||
Goods goods = selectById(goodsId);
|
Goods goods = selectById(goodsId);
|
||||||
if (countUserGoodsById(goods) > 0)
|
if (countUserGoodsById(goods) > 0) {
|
||||||
{
|
|
||||||
throw new ServiceException(String.format("%1$s正在使用,不能删除", goods.getGoodsName()));
|
throw new ServiceException(String.format("%1$s正在使用,不能删除", goods.getGoodsName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -60,8 +65,7 @@ public class GoodsServiceImpl implements GoodsService {
|
||||||
public String checkGoodsNameUnique(Goods goods) {
|
public String checkGoodsNameUnique(Goods goods) {
|
||||||
Long goodsId = StringUtils.isNull(goods.getGoodsId()) ? -1L : goods.getGoodsId();
|
Long goodsId = StringUtils.isNull(goods.getGoodsId()) ? -1L : goods.getGoodsId();
|
||||||
Goods info = goodsMapper.checkGoodsNameUnique(goods.getGoodsName());
|
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_NOT_UNIQUE;
|
||||||
}
|
}
|
||||||
return UserConstants.GOODS_NAME_UNIQUE;
|
return UserConstants.GOODS_NAME_UNIQUE;
|
||||||
|
|
@ -71,15 +75,14 @@ public class GoodsServiceImpl implements GoodsService {
|
||||||
public String checkGoodsCodeUnique(Goods goods) {
|
public String checkGoodsCodeUnique(Goods goods) {
|
||||||
Long goodsId = StringUtils.isNull(goods.getGoodsId()) ? -1L : goods.getGoodsId();
|
Long goodsId = StringUtils.isNull(goods.getGoodsId()) ? -1L : goods.getGoodsId();
|
||||||
Goods info = goodsMapper.checkGoodsCodeUnique(goods.getGoodsCode());
|
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_NOT_UNIQUE;
|
||||||
}
|
}
|
||||||
return UserConstants.GOODS_CODE_UNIQUE;
|
return UserConstants.GOODS_CODE_UNIQUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int countUserGoodsById(Goods goods){
|
public int countUserGoodsById(Goods goods) {
|
||||||
//TODO 校验商品是否上架
|
//TODO 校验商品是否上架
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,6 @@
|
||||||
<update id="updateGoods" parameterType="com.ghy.goods.domain.Goods">
|
<update id="updateGoods" parameterType="com.ghy.goods.domain.Goods">
|
||||||
UPDATE goods
|
UPDATE goods
|
||||||
<set>
|
<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="goodsName != null and goodsName != ''">goods_name = #{goodsName},</if>
|
||||||
<if test="goodsPrice != null and goodsPrice != ''">goods_price = #{goodsPrice},</if>
|
<if test="goodsPrice != null and goodsPrice != ''">goods_price = #{goodsPrice},</if>
|
||||||
<if test="discountsPrice != null and discountsPrice != ''">discounts_price = #{discountsPrice},</if>
|
<if test="discountsPrice != null and discountsPrice != ''">discounts_price = #{discountsPrice},</if>
|
||||||
|
|
@ -52,6 +50,12 @@
|
||||||
WHERE goods_id = #{goodsId}
|
WHERE goods_id = #{goodsId}
|
||||||
</update>
|
</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 id="insertGoods" parameterType="com.ghy.goods.domain.Goods" useGeneratedKeys="true" keyProperty="goodsId">
|
||||||
insert into goods(
|
insert into goods(
|
||||||
<if test="goodsCode != null and goodsCode != ''">goods_code,</if>
|
<if test="goodsCode != null and goodsCode != ''">goods_code,</if>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue