商品列表、新增、删除

This commit is contained in:
HH 2022-05-10 19:22:45 +08:00
parent 7a2c3683bd
commit 79d0296406
15 changed files with 504 additions and 115 deletions

View File

@ -6,39 +6,42 @@ 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;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@Controller
@RequestMapping("/goods/goods")
public class GoodsController extends BaseController {
private String prefix = "goods/goods";
private static final String PREFIX = "goods/goods";
@Autowired
@Resource
private GoodsService goodsService;
@Resource
private DeptGoodsCategoryService deptGoodsCategoryService;
@RequiresPermissions("goods:goods:view")
@GetMapping()
public String goods()
{
return prefix + "/goods";
public String goods() {
return PREFIX + "/goods";
}
@RequiresPermissions("goods:goods:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(Goods goods)
{
public TableDataInfo list(Goods goods) {
startPage();
List<Goods> list = goodsService.selectGoodsList(goods);
return getDataTable(list);
@ -48,8 +51,7 @@ public class GoodsController extends BaseController {
@RequiresPermissions("goods:goods:export")
@PostMapping("/export")
@ResponseBody
public AjaxResult export(Goods goods)
{
public AjaxResult export(Goods goods) {
List<Goods> list = goodsService.selectGoodsList(goods);
ExcelUtil<Goods> util = new ExcelUtil<Goods>(Goods.class);
return util.exportExcel(list, "商品数据");
@ -57,16 +59,12 @@ public class GoodsController extends BaseController {
@RequiresPermissions("goods:goods:remove")
@Log(title = "商品管理", businessType = BusinessType.DELETE)
@PostMapping("/remove")
@PostMapping("/remove/{ids}")
@ResponseBody
public AjaxResult remove(String ids)
{
try
{
public AjaxResult remove(@PathVariable String ids) {
try {
return toAjax(goodsService.deleteGoodsByIds(ids));
}
catch (Exception e)
{
} catch (Exception e) {
return error(e.getMessage());
}
}
@ -75,9 +73,10 @@ public class GoodsController extends BaseController {
* 新增商品
*/
@GetMapping("/add")
public String add()
{
return prefix + "/add";
public String add(ModelMap mmap) {
Long parentId = ShiroUtils.getSysUser().getParentId();
mmap.put("deptGoodsCategories", deptGoodsCategoryService.list(parentId));
return PREFIX + "/add";
}
/**
@ -87,17 +86,14 @@ public class GoodsController extends BaseController {
@Log(title = "商品管理", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(@Validated Goods goods)
{
if (UserConstants.GOODS_CODE_NOT_UNIQUE.equals(goodsService.checkGoodsNameUnique(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)))
{
} 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));
}
@ -106,10 +102,9 @@ public class GoodsController extends BaseController {
*/
@RequiresPermissions("goods:goods:edit")
@GetMapping("/edit/{goodsId}")
public String edit(@PathVariable("goodsId") Long goodsId, ModelMap mmap)
{
public String edit(@PathVariable("goodsId") Long goodsId, ModelMap mmap) {
mmap.put("goods", goodsService.selectById(goodsId));
return prefix + "/edit";
return PREFIX + "/edit";
}
/**
@ -119,14 +114,10 @@ public class GoodsController extends BaseController {
@Log(title = "商品管理", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(@Validated Goods goods)
{
if (UserConstants.GOODS_NAME_NOT_UNIQUE.equals(goodsService.checkGoodsNameUnique(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)))
{
} else if (UserConstants.GOODS_CODE_NOT_UNIQUE.equals(goodsService.checkGoodsCodeUnique(goods))) {
return error("修改商品'" + goods.getGoodsCode() + "'失败,商品编码已存在");
}
goods.setUpdateBy(getLoginName());
@ -138,8 +129,7 @@ public class GoodsController extends BaseController {
*/
@PostMapping("/checkGoodsNameUnique")
@ResponseBody
public String checkGoodsNameUnique(Goods goods)
{
public String checkGoodsNameUnique(Goods goods) {
return goodsService.checkGoodsNameUnique(goods);
}
@ -148,8 +138,7 @@ public class GoodsController extends BaseController {
*/
@PostMapping("/checkGoodsCodeUnique")
@ResponseBody
public String checkGoodsCodeUnique(Goods goods)
{
public String checkGoodsCodeUnique(Goods goods) {
return goodsService.checkGoodsCodeUnique(goods);
}

View File

@ -0,0 +1,126 @@
<!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 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>
</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>
<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>&nbsp;
<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: {
},
focusCleanup: true
});
function submitHandler() {
if ($.validate.form()) {
var data = $("#form-goods-add").serializeArray();
$.operate.saveTab(prefix + "/add", data);
$.modal.close(index);
}
}
</script>
</body>
</html>

View File

@ -0,0 +1,124 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
<th:block th:include="include :: header('商品列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
<div class="row">
<div class="col-sm-12 search-collapse">
<form id="dept-form">
<div class="select-list">
<ul>
<li>
商品名称:<input type="text" name="goodsName"/>
</li>
<li>
类目状态:<select name="status" th:with="type=${@dict.getType('goods_status')}">
<option value="">所有</option>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" />
</select>
</li>
<li>
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i
class="fa fa-search"></i>&nbsp;搜索</a>
<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
class="fa fa-refresh"></i>&nbsp;重置</a>
</li>
</ul>
</div>
</form>
</div>
<div class="btn-group-sm" id="toolbar" role="group">
<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="goods:goods:add">
<i class="fa fa-plus"></i> 新增
</a>
<!-- <a class="btn btn-primary" onclick="$.operate.edit()" shiro:hasPermission="goods:goods:edit">-->
<!-- <i class="fa fa-edit"></i> 修改-->
<!-- </a>-->
</div>
<div class="col-sm-12 select-table table-striped">
<table id="bootstrap-table"></table>
</div>
</div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
var addFlag = [[${@permission.hasPermi('goods:goods:add')}]];
var editFlag = [[${@permission.hasPermi('goods:goods:edit')}]];
var removeFlag = [[${@permission.hasPermi('goods:goods:remove')}]];
var datas = [[${@dict.getType('sys_normal_disable')}]];
var prefix = ctx + "goods/goods"
$(function () {
var options = {
url: prefix + "/list",
createUrl: prefix + "/add/{id}",
updateUrl: prefix + "/edit/{id}",
removeUrl: prefix + "/remove/{id}",
modalName: "商品",
columns: [
{
checkbox: true
}, {
field: 'goodsCode',
title: '商品编码',
align: "left"
}, {
field: 'goodsName',
title: '商品名称',
align: "left"
}, {
field: 'goodsPrice',
title: '价格',
align: "left"
}, {
field: 'discountsPrice',
title: '优惠价',
align: "left"
}, {
field: 'groupPrice',
title: '团购价',
align: "left"
}, {
field: 'goodsSort',
title: '排序',
align: "left"
}, {
field: 'status',
title: '状态',
align: "left",
formatter: function (value, item, index) {
return $.table.selectDictLabel(datas, item.status);
}
}, {
field: 'goodsImgUrl',
title: '图片',
align: "left"
}, {
field: 'goodsNumber',
title: '商品库存',
align: "left"
}, {
field: 'createTime',
title: '创建时间',
align: "left"
}, {
title: '操作',
align: 'left',
formatter: function (value, row, index) {
var actions = [];
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.goodsId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodsId + '\')"><i class="fa fa-trash"></i>删除</a>');
return actions.join('');
}
}]
};
$.table.init(options);
});
</script>
</body>
</html>

View File

@ -19,6 +19,12 @@ public class DeptGoodsCategory extends BaseEntity {
@Excel(name = "类别id", cellType = Excel.ColumnType.NUMERIC)
private Long goodsCategoryId;
@Excel(name = "类别编码", cellType = Excel.ColumnType.STRING)
private String goodsCategoryCode;
@Excel(name = "类别名称", cellType = Excel.ColumnType.STRING)
private String goodsCategoryName;
@Excel(name = "类别类型. 1.服务类 2.商品类", cellType = Excel.ColumnType.STRING)
private Integer type;
@Excel(name = "排序", cellType = Excel.ColumnType.STRING)
private Integer categorySort;
@ -31,4 +37,5 @@ public class DeptGoodsCategory extends BaseEntity {
@Excel(name = "三级分销扣点比例", cellType = Excel.ColumnType.STRING)
private String threeRate;
}

View File

@ -7,9 +7,9 @@ import lombok.Data;
import java.math.BigDecimal;
/**
* 商品
* 商品
*
* @author clunt
* @author clunt
*/
@Data
public class Goods extends BaseEntity {
@ -30,23 +30,21 @@ public class Goods extends BaseEntity {
@Excel(name = "价格")
private BigDecimal goodsPrice;
@Excel(name = "优惠价")
private BigDecimal discountsPrice;
@Excel(name = "团购价")
private BigDecimal groupPrice;
/** 岗位排序 */
/**
* 岗位排序
*/
@Excel(name = "商品排序", cellType = Excel.ColumnType.NUMERIC)
private String goodsSort;
/** 状态0上架 1下架 2删除 */
@Excel(name = "状态", readConverterExp = "0=上架,1=下架,2删除")
private String status;
private Integer goodsSort;
@Excel(name = "类别id")
private Long goodsCategoryId;
private Long deptGoodsCategoryId;
@Excel(name = "商品图片", cellType = Excel.ColumnType.IMAGE)
private String goodsImgUrl;
@ -57,4 +55,9 @@ public class Goods extends BaseEntity {
@Excel(name = "商品库存,-1则表示无限制", cellType = Excel.ColumnType.NUMERIC)
private Integer goodsNumber;
/**
* 状态0上架 1下架 2删除
*/
@Excel(name = "状态", readConverterExp = "0=上架,1=下架,2删除")
private Integer status;
}

View File

@ -6,7 +6,7 @@ import com.ghy.common.core.domain.BaseEntity;
import lombok.Data;
/**
* 商品类别表
* 商品类别表
*
* @author clunt
*/
@ -34,7 +34,7 @@ public class GoodsCategory extends BaseEntity {
private Integer level;
@Excel(name = "类别类型. 1.服务类 2.商品类", cellType = Excel.ColumnType.STRING)
private String type;
private Integer type;
@Excel(name = "状态")
private Integer status;

View File

@ -2,6 +2,7 @@ package com.ghy.goods.mapper;
import com.ghy.goods.domain.DeptGoodsCategory;
import java.util.Collection;
import java.util.List;
/**
@ -42,6 +43,6 @@ public interface DeptGoodsCategoryMapper {
* @param goodsCategoryId 需要删除的数据ID
* @return 结果
*/
int deleteDeptGoodsCategoryByIds(Long[] goodsCategoryId);
int deleteDeptGoodsCategoryByIds(Collection<Long> goodsCategoryId);
}

View File

@ -2,6 +2,7 @@ package com.ghy.goods.mapper;
import com.ghy.goods.domain.GoodsCategory;
import java.util.Collection;
import java.util.List;
/**
@ -55,4 +56,12 @@ public interface GoodsCategoryMapper {
* @return 商品信息
*/
GoodsCategory selectByGoodsCategoryCode(String goodsCategoryCode);
/**
* 通过ID批量查询商品类别
*
* @param ids 商品类别ID
* @return
*/
List<GoodsCategory> selectByIds(Collection<Long> ids);
}

View File

@ -1,11 +1,50 @@
package com.ghy.goods.service;
import com.ghy.goods.domain.DeptGoodsCategory;
import java.util.Collection;
import java.util.List;
/**
* 分公司使用类目
*
* @author clunt
*/
public interface DeptGoodsCategoryService {
// 选择使用指定的公司类别
/**
* 用deptId查询出该公司的所有类目
*
* @param deptId 公司ID
*/
List<DeptGoodsCategory> list(Long deptId);
/**
* 新增一条分公司类目
*
* @param deptGoodsCategory 分公司类目
*/
int add(DeptGoodsCategory deptGoodsCategory);
/**
* 编辑分公司类目
*
* @param deptGoodsCategory 分公司类目
*/
int edit(DeptGoodsCategory deptGoodsCategory);
/**
* 批量删除
*
* @param ids 分公司类目ID
*/
int delete(Collection<Long> ids);
/**
* 用ID获取一条DeptGoodsCategory
*
* @param id 分公司类目ID
* @return 分公司类目
*/
DeptGoodsCategory get(long id);
}

View File

@ -4,7 +4,9 @@ import com.ghy.common.core.domain.Ztree;
import com.ghy.common.core.domain.entity.SysDept;
import com.ghy.goods.domain.GoodsCategory;
import java.util.Collection;
import java.util.List;
import java.util.Set;
/**
* @author clunt
@ -38,7 +40,7 @@ public interface GoodsCategoryService {
* @param goodsCategory 类目信息
* @return 所有类目信息
*/
public List<Ztree> selectCategoryTree(GoodsCategory goodsCategory);
List<Ztree> selectCategoryTree(GoodsCategory goodsCategory);
/**
* @param goodsCategoryId 商品类别id
@ -67,4 +69,12 @@ public interface GoodsCategoryService {
* @return 校验结果 true重复 false不重复
*/
boolean checkGoodsCategoryCodeUnique(GoodsCategory goodsCategory);
/**
* 通过ID批量查询商品类别
*
* @param ids 商品类别ID
* @return
*/
List<GoodsCategory> selectByIds(Collection<Long> ids);
}

View File

@ -1,9 +1,17 @@
package com.ghy.goods.service.impl;
import com.ghy.goods.domain.DeptGoodsCategory;
import com.ghy.goods.domain.GoodsCategory;
import com.ghy.goods.mapper.DeptGoodsCategoryMapper;
import com.ghy.goods.service.DeptGoodsCategoryService;
import com.ghy.goods.service.GoodsCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author clunt
* 分公司使用类目
@ -12,6 +20,49 @@ import org.springframework.stereotype.Service;
@Service
public class DeptGoodsCategoryServiceImpl implements DeptGoodsCategoryService {
@Resource
GoodsCategoryService goodsCategoryService;
@Resource
DeptGoodsCategoryMapper deptGoodsCategoryMapper;
@Override
public List<DeptGoodsCategory> list(Long deptId) {
DeptGoodsCategory query = new DeptGoodsCategory();
query.setDeptId(deptId);
List<DeptGoodsCategory> result = deptGoodsCategoryMapper.selectDeptGoodsCategoryList(query);
if (result.isEmpty())
return result;
Set<Long> goodsCategoryIdSet = result.stream().map(DeptGoodsCategory::getGoodsCategoryId).filter(Objects::nonNull).collect(Collectors.toSet());
List<GoodsCategory> goodsCategoryList = goodsCategoryService.selectByIds(goodsCategoryIdSet);
Map<Long, GoodsCategory> goodsCategoryMap = goodsCategoryList.stream().collect(Collectors.toMap(GoodsCategory::getGoodsCategoryId, x -> x));
result.forEach(x -> {
GoodsCategory goodsCategory = goodsCategoryMap.get(x.getGoodsCategoryId());
if (goodsCategory != null) {
x.setGoodsCategoryName(goodsCategory.getGoodsCategoryName());
x.setGoodsCategoryCode(goodsCategory.getGoodsCategoryCode());
x.setType(goodsCategory.getType());
}
});
return result;
}
@Override
public int add(DeptGoodsCategory deptGoodsCategory) {
return deptGoodsCategoryMapper.insertDeptGoodsCategory(deptGoodsCategory);
}
@Override
public int edit(DeptGoodsCategory deptGoodsCategory) {
return deptGoodsCategoryMapper.updateDeptGoodsCategory(deptGoodsCategory);
}
@Override
public int delete(Collection<Long> ids) {
return deptGoodsCategoryMapper.deleteDeptGoodsCategoryByIds(ids);
}
@Override
public DeptGoodsCategory get(long id) {
return deptGoodsCategoryMapper.selectById(id);
}
}

View File

@ -2,9 +2,7 @@ package com.ghy.goods.service.impl;
import com.ghy.common.constant.UserConstants;
import com.ghy.common.core.domain.Ztree;
import com.ghy.common.core.domain.entity.SysDept;
import com.ghy.common.core.text.Convert;
import com.ghy.common.utils.StringUtils;
import com.ghy.goods.domain.Goods;
import com.ghy.goods.domain.GoodsCategory;
import com.ghy.goods.mapper.GoodsCategoryMapper;
@ -15,6 +13,7 @@ import org.springframework.util.Assert;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
@ -68,7 +67,7 @@ public class GoodsCategoryServiceImpl implements GoodsCategoryService {
@Override
public boolean checkGoodsCategoryNameUnique(GoodsCategory goodsCategory) {
GoodsCategory category = goodsCategoryMapper.selectByGoodsCategoryName(goodsCategory.getGoodsCategoryName());
if (category == null){
if (category == null) {
return false;
}
return category.getGoodsCategoryId().equals(goodsCategory.getGoodsCategoryId());
@ -77,20 +76,24 @@ public class GoodsCategoryServiceImpl implements GoodsCategoryService {
@Override
public boolean checkGoodsCategoryCodeUnique(GoodsCategory goodsCategory) {
GoodsCategory category = goodsCategoryMapper.selectByGoodsCategoryCode(goodsCategory.getGoodsCategoryCode());
if (category == null){
if (category == null) {
return false;
}
return category.getGoodsCategoryId().equals(goodsCategory.getGoodsCategoryId());
}
@Override
public List<GoodsCategory> selectByIds(Collection<Long> ids) {
return goodsCategoryMapper.selectByIds(ids);
}
/**
* 对象转类目树
*
* @param goodsCategoryList 类目列表
* @return 树结构列表
*/
public List<Ztree> initZtree(List<GoodsCategory> goodsCategoryList)
{
public List<Ztree> initZtree(List<GoodsCategory> goodsCategoryList) {
return initZtree(goodsCategoryList, null);
}
@ -98,17 +101,14 @@ public class GoodsCategoryServiceImpl implements GoodsCategoryService {
* 对象转部门树
*
* @param goodsCategoryList 类目列表
* @param roleDeptList 该列表无需校验
* @param roleDeptList 该列表无需校验
* @return 树结构列表
*/
public List<Ztree> initZtree(List<GoodsCategory> goodsCategoryList, List<String> roleDeptList)
{
public List<Ztree> initZtree(List<GoodsCategory> goodsCategoryList, List<String> roleDeptList) {
List<Ztree> ztrees = new ArrayList<Ztree>();
for (GoodsCategory goodsCategory : goodsCategoryList)
{
if (UserConstants.CATEGORY_NORMAL.equals(goodsCategory.getStatus()))
{
for (GoodsCategory goodsCategory : goodsCategoryList) {
if (UserConstants.CATEGORY_NORMAL.equals(goodsCategory.getStatus())) {
Ztree ztree = new Ztree();
ztree.setId(goodsCategory.getGoodsCategoryId());
ztree.setpId(goodsCategory.getParentCategoryId());

View File

@ -19,7 +19,7 @@
</resultMap>
<sql id="selectDeptGoodsCategory">
SELECT dept_goods_category_id, dept_id, dept_goods_category_id, category_sort,
SELECT dept_goods_category_id, dept_id, goods_category_id, category_sort,
one_rate, two_rate, three_rate, create_by, create_time, remark
FROM dept_goods_category
</sql>
@ -49,7 +49,7 @@
<insert id="insertDeptGoodsCategory" parameterType="com.ghy.goods.domain.DeptGoodsCategory" useGeneratedKeys="true"
keyProperty="goodsCategoryId">
insert into dept_goods_category(
<if test="deptId != null and goodsCategoryCode != ''">dept_id,</if>
<if test="deptId != null and deptId != ''">dept_id,</if>
<if test="goodsCategoryId != null">goods_category_id,</if>
<if test="categorySort != null">category_sort,</if>
<if test="oneRate != null and oneRate != ''">one_rate,</if>

View File

@ -93,4 +93,12 @@
<include refid="selectGoodsCategory"/>
WHERE goods_category_code = #{goodsCategoryCode} LIMIT 1
</select>
<select id="selectByIds" parameterType="Long" resultMap="GoodsCategoryResult">
<include refid="selectGoodsCategory"/>
WHERE goods_category_id IN
<foreach collection="collection" item="goodsCategoryId" open="(" separator="," close=")">
#{goodsCategoryId}
</foreach>
</select>
</mapper>

View File

@ -9,10 +9,10 @@
<result property="deptId" column="dept_id" />
<result property="goodsName" column="goods_name" />
<result property="goodsPrice" column="goods_price" />
<result property="discountsPrice" column="discounts_price" />
<result property="discountsPrice" column="discounts_price" />
<result property="groupPrice" column="group_price" />
<result property="goodsSort" column="goods_sort"/>
<result property="goodsCategoryId" column="goods_category_id"/>
<result property="deptGoodsCategoryId" column="dept_goods_category_id"/>
<result property="goodsImgUrl" column="goods_img_url"/>
<result property="goodsVideoUrl" column="goods_video_url"/>
<result property="goodsNumber" column="goods_number"/>
@ -25,11 +25,69 @@
</resultMap>
<sql id="selectGoods">
select goods_id, goods_code, dept_id, goods_name, goods_price, discounts_price, group_price, goods_sort, goods_category_id,
goods_img_url, goods_number, status, create_by, create_time, remark
from goods
SELECT goods_id, goods_code, dept_id, goods_name, goods_price, discounts_price, group_price, goods_sort,
dept_goods_category_id, goods_img_url, goods_video_url, goods_number, status, create_by, create_time, remark
FROM goods
</sql>
<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>
<if test="groupPrice != null and groupPrice != ''">group_price = #{groupPrice},</if>
<if test="goodsSort != null and goodsSort != ''">goods_sort = #{goodsSort},</if>
<if test="deptGoodsCategoryId != null and deptGoodsCategoryId != ''">dept_goods_category_id = #{deptGoodsCategoryId},</if>
<if test="goodsImgUrl != null and goodsImgUrl != ''">goods_img_url = #{goodsImgUrl},</if>
<if test="goodsVideoUrl != null and goodsVideoUrl != ''">goods_video_url = #{goodsVideoUrl},</if>
<if test="goodsNumber != null and goodsNumber != ''">goods_number = #{goodsNumber},</if>
<if test="status != null and status != ''">`status` = #{status},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
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>
<if test="deptId != null and deptId != ''">dept_id,</if>
<if test="goodsName != null and goodsName != ''">goods_name,</if>
<if test="goodsPrice != null and goodsPrice != ''">goods_price,</if>
<if test="discountsPrice != null and discountsPrice != ''">discounts_price,</if>
<if test="groupPrice != null and groupPrice != ''">group_price,</if>
<if test="goodsSort != null and goodsSort != ''">goods_sort,</if>
<if test="deptGoodsCategoryId != null and deptGoodsCategoryId != 0">dept_goods_category_id,</if>
<if test="goodsImgUrl != null and goodsImgUrl != ''">goods_img_url,</if>
<if test="goodsVideoUrl != null and goodsVideoUrl != ''">goods_video_url,</if>
<if test="goodsNumber != null and goodsNumber != ''">goods_number,</if>
<if test="status != null and status != ''">status,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)values(
<if test="goodsCode != null and goodsCode != ''">#{goodsCode},</if>
<if test="deptId != null and deptId != ''">#{deptId},</if>
<if test="goodsName != null and goodsName != ''">#{goodsName},</if>
<if test="goodsPrice != null and goodsPrice != ''">#{goodsPrice},</if>
<if test="discountsPrice != null and discountsPrice != ''">#{discountsPrice},</if>
<if test="groupPrice != null and groupPrice != ''">#{groupPrice},</if>
<if test="goodsSort != null and goodsSort != ''">#{goodsSort},</if>
<if test="deptGoodsCategoryId != null and deptGoodsCategoryId != 0">#{deptGoodsCategoryId},</if>
<if test="goodsImgUrl != null and goodsImgUrl != ''">#{goodsImgUrl},</if>
<if test="goodsVideoUrl != null and goodsVideoUrl != ''">#{goodsVideoUrl},</if>
<if test="goodsNumber != null and goodsNumber != ''">#{goodsNumber},</if>
<if test="status != null and status != ''">#{status},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>
<select id="selectGoodsList" parameterType="com.ghy.goods.domain.Goods" resultMap="GoodsResult">
<include refid="selectGoods" />
<where>
@ -38,7 +96,7 @@
</if>
</where>
</select>
<select id="selectById" parameterType="long" resultMap="GoodsResult">
<include refid="selectGoods"/>
<where>
@ -55,42 +113,6 @@
</foreach>
</delete>
<update id="updateGoods" parameterType="com.ghy.goods.domain.Goods">
update goods
<set>
<if test="goodsCode != null and goodsCode != ''">goods_code = #{goodsCode},</if>
<if test="goodsName != null and goodsName != ''">goods_name = #{goodsName},</if>
<if test="goodsSort != null and goodsSort != ''">goods_sort = #{goodsSort},</if>
<if test="status != null and status != ''">status = #{status},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
where goods_id = #{goodsId}
</update>
<insert id="insertGoods" parameterType="com.ghy.goods.domain.Goods" useGeneratedKeys="true" keyProperty="goodsId">
insert into goods(
<if test="goodsId != null and goodsId != 0">goods_id,</if>
<if test="goodsCode != null and goodsCode != ''">goods_code,</if>
<if test="goodsName != null and goodsName != ''">goods_name,</if>
<if test="goodsSort != null and goodsSort != ''">goods_sort,</if>
<if test="status != null and status != ''">status,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)values(
<if test="goodsId != null and goodsId != 0">#{goodsId},</if>
<if test="goodsCode != null and goodsCode != ''">#{goodsCode},</if>
<if test="goodsName != null and goodsName != ''">#{goodsName},</if>
<if test="goodsSort != null and goodsSort != ''">#{goodsSort},</if>
<if test="status != null and status != ''">#{status},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>
<select id="checkGoodsNameUnique" parameterType="String" resultMap="GoodsResult">
<include refid="selectGoods"/>
where goods_name=#{goodsName} limit 1
@ -103,7 +125,7 @@
<select id="selectOneByGoodsCategoryId" parameterType="String" resultMap="GoodsResult">
<include refid="selectGoods"/>
WHERE goods_category_id = #{goodsCategoryId} LIMIT 1
WHERE dept_goods_category_id = #{deptGoodsCategoryId} LIMIT 1
</select>
</mapper>