分公司商品类目

This commit is contained in:
HH 2022-05-12 22:37:26 +08:00
parent 22e2abc461
commit 3cb9c512ac
13 changed files with 585 additions and 456 deletions

View File

@ -5,9 +5,8 @@ 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.domain.Ztree;
import com.ghy.common.core.domain.entity.SysDept;
import com.ghy.common.core.page.TableDataInfo;
import com.ghy.common.enums.BusinessType;
import com.ghy.common.utils.ShiroUtils;
import com.ghy.goods.domain.GoodsCategory;
import com.ghy.goods.service.GoodsCategoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
@ -42,8 +41,7 @@ public class GoodsCategoryController extends BaseController {
* 新增部门
*/
@GetMapping("/add/{parentCategoryId}")
public String add(@PathVariable("parentCategoryId") Long parentCategoryId, ModelMap mmap)
{
public String add(@PathVariable("parentCategoryId") Long parentCategoryId, ModelMap mmap) {
mmap.put("goodsCategory", goodsCategoryService.selectById(parentCategoryId));
return PREFIX + "/add";
}
@ -88,9 +86,9 @@ public class GoodsCategoryController extends BaseController {
*/
@RequiresPermissions("goods:category:remove")
@Log(title = "商品类别管理", businessType = BusinessType.DELETE)
@PostMapping("/remove")
@PostMapping("/remove/{ids}")
@ResponseBody
public AjaxResult remove(String ids) {
public AjaxResult remove(@PathVariable("ids") String ids) {
try {
return toAjax(goodsCategoryService.deleteGoodsCategoryByIds(ids));
} catch (Exception e) {
@ -119,36 +117,41 @@ public class GoodsCategoryController extends BaseController {
* 选择部门树
*
* @param categoryId 类目ID
* @param excludeId 排除ID
* @param excludeId 排除ID
*/
@GetMapping(value = { "/selectGoodsCategoryTree/{categoryId}", "/selectGoodsCategoryTree/{categoryId}/{excludeId}" })
@GetMapping(value = {"/selectGoodsCategoryTree/{categoryId}", "/selectGoodsCategoryTree/{categoryId}/{excludeId}"})
public String selectDeptTree(@PathVariable("categoryId") Long categoryId,
@PathVariable(value = "excludeId", required = false) String excludeId, ModelMap mmap)
{
@PathVariable(value = "excludeId", required = false) String excludeId, ModelMap mmap) {
mmap.put("goodsCategory", goodsCategoryService.selectById(categoryId));
mmap.put("excludeId", excludeId);
return PREFIX + "/tree";
}
/**
* 加载部门列表
* 商品类目
*/
@GetMapping("/treeData")
@ResponseBody
public List<Ztree> treeData()
{
public List<Ztree> treeData() {
return goodsCategoryService.selectCategoryTree(new GoodsCategory());
}
@GetMapping("/tree")
@ResponseBody
public List<Ztree> tree() {
Long deptId = ShiroUtils.getSysUser().getDept().getParentId();
return goodsCategoryService.tree(deptId);
}
/**
* 加载部门列表树排除下级
*/
@GetMapping("/treeData/{excludeId}")
@ResponseBody
public List<Ztree> treeDataExcludeChild(@PathVariable(value = "excludeId", required = false) Long excludeId)
{
public List<Ztree> treeDataExcludeChild(@PathVariable(value = "excludeId", required = false) Long excludeId) {
return goodsCategoryService.selectCategoryTree(new GoodsCategory());
}
/**
* 商品类别表
*/

View File

@ -4,10 +4,12 @@ import com.ghy.common.annotation.Log;
import com.ghy.common.core.controller.BaseController;
import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.core.domain.Ztree;
import com.ghy.common.core.text.Convert;
import com.ghy.common.enums.BusinessType;
import com.ghy.common.utils.ShiroUtils;
import com.ghy.goods.domain.DeptGoodsCategory;
import com.ghy.goods.service.DeptGoodsCategoryService;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
@ -33,11 +35,37 @@ public class GoodsDeptCategoryController extends BaseController {
@RequiresPermissions("goods:deptcategory:add")
@GetMapping("/add/{id}")
public String edit(@PathVariable(name = "id") Long id, ModelMap mmap) {
@GetMapping("/add/1")
public String add() {
return PREFIX + "/add";
}
@RequiresPermissions("goods:deptcategory:add")
@PostMapping("/add")
@ResponseBody
public AjaxResult add(String menuIds) {
Long parentId = ShiroUtils.getSysUser().getDept().getParentId();
Long[] categoryIds = Convert.toLongArray(menuIds);
return deptGoodsCategoryService.batchAdd(parentId, categoryIds);
}
@RequiresPermissions("goods:deptcategory:edit")
@GetMapping("/edit/{id}")
public String edit(@PathVariable("id") Long id, ModelMap mmap) {
DeptGoodsCategory deptGoodsCategory = deptGoodsCategoryService.get(id);
mmap.put("deptGoodsCategory", deptGoodsCategory);
return PREFIX + "/edit";
}
@RequiresPermissions("goods:deptcategory:edit")
@PostMapping("/edit")
@ResponseBody
public AjaxResult edit(DeptGoodsCategory category) {
category.setUpdateBy(getLoginName());
deptGoodsCategoryService.edit(category);
return AjaxResult.success();
}
/**
* 商品类别表
*/
@ -45,7 +73,7 @@ public class GoodsDeptCategoryController extends BaseController {
@PostMapping("/list")
@ResponseBody
public List<DeptGoodsCategory> list(DeptGoodsCategory category) {
Long parentId = ShiroUtils.getSysUser().getParentId();
Long parentId = ShiroUtils.getSysUser().getDept().getParentId();
category.setDeptId(parentId);
return deptGoodsCategoryService.list(category);
}
@ -53,9 +81,8 @@ public class GoodsDeptCategoryController extends BaseController {
@GetMapping("/tree")
@ResponseBody
public List<Ztree> goodsDeptCategoryTree() {
Long parentId = ShiroUtils.getSysUser().getParentId();
Long parentId = ShiroUtils.getSysUser().getDept().getParentId();
return deptGoodsCategoryService.tree(parentId);
}
@PostMapping("/app/list")
@ -69,9 +96,9 @@ public class GoodsDeptCategoryController extends BaseController {
*/
@RequiresPermissions("goods:deptcategory:remove")
@Log(title = "子公司商品类别管理", businessType = BusinessType.DELETE)
@PostMapping("/remove")
@PostMapping("/remove/{ids}")
@ResponseBody
public AjaxResult remove(String ids) {
public AjaxResult remove(@PathVariable("ids") String ids) {
try {
return toAjax(deptGoodsCategoryService.delete(ids));
} catch (Exception e) {

View File

@ -1,112 +1,121 @@
<!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('类目列表')" />
<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="goodsCategoryName"/>
</li>
<li>
类目状态:<select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">
<option value="">所有</option>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
</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(1)" shiro:hasPermission="goods:category:add">
<i class="fa fa-plus"></i> 新增
</a>
<a class="btn btn-primary" onclick="$.operate.edit()" shiro:hasPermission="goods:category:edit">
<i class="fa fa-edit"></i> 修改
</a>
<a class="btn btn-info" id="expandAllBtn">
<i class="fa fa-exchange"></i> 展开/折叠
</a>
</div>
<div class="col-sm-12 select-table table-striped">
<table id="bootstrap-tree-table"></table>
</div>
</div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
var addFlag = [[${@permission.hasPermi('goods:category:add')}]];
var editFlag = [[${@permission.hasPermi('goods:category:edit')}]];
var removeFlag = [[${@permission.hasPermi('goods:category:remove')}]];
var datas = [[${@dict.getType('sys_normal_disable')}]];
var prefix = ctx + "goods/category"
<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="goodsCategoryName"/>
</li>
<li>
类目状态:<select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">
<option value="">所有</option>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}"
th:value="${dict.dictValue}"></option>
</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>
$(function() {
var options = {
code: "goodsCategoryId",
parentCode: "parentCategoryId",
uniqueId: "goodsCategoryId",
url: prefix + "/list",
createUrl: prefix + "/add/{id}",
updateUrl: prefix + "/edit/{id}",
removeUrl: prefix + "/remove/{id}",
modalName: "类目",
columns: [{
field: 'selectItem',
radio: true
},
{
field: 'goodsCategoryName',
title: '类目名称',
align: "left"
},
{
field: 'categorySort',
title: '排序',
align: "left"
},
{
field: 'status',
title: '状态',
align: "left",
formatter: function(value, item, index) {
return $.table.selectDictLabel(datas, item.status);
}
},
{
field: 'createTime',
title: '创建时间',
align: "left"
},
{
title: '操作',
align: 'left',
formatter: function(value, row, index) {
if (row.parentId != 0) {
var actions = [];
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.goodsCategoryId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-info btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.goodsCategoryId + '\')"><i class="fa fa-plus"></i>新增</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodsCategoryId + '\')"><i class="fa fa-trash"></i>删除</a>');
return actions.join('');
} else {
return "";
}
}
}]
};
$.treeTable.init(options);
});
</script>
<div class="btn-group-sm" id="toolbar" role="group">
<a class="btn btn-success" onclick="$.operate.add(1)" shiro:hasPermission="goods:category:add">
<i class="fa fa-plus"></i> 新增
</a>
<a class="btn btn-primary" onclick="$.operate.edit()" shiro:hasPermission="goods:category:edit">
<i class="fa fa-edit"></i> 修改
</a>
<a class="btn btn-info" id="expandAllBtn">
<i class="fa fa-exchange"></i> 展开/折叠
</a>
</div>
<div class="col-sm-12 select-table table-striped">
<table id="bootstrap-tree-table"></table>
</div>
</div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
var addFlag = [[${@permission.hasPermi('goods:category:add')}]];
var editFlag = [[${@permission.hasPermi('goods:category:edit')}]];
var removeFlag = [[${@permission.hasPermi('goods:category:remove')}]];
var datas = [[${@dict.getType('sys_normal_disable')}]];
var prefix = ctx + "goods/category"
$(function () {
var options = {
code: "goodsCategoryId",
parentCode: "parentCategoryId",
uniqueId: "goodsCategoryId",
url: prefix + "/list",
createUrl: prefix + "/add/{id}",
updateUrl: prefix + "/edit/{id}",
removeUrl: prefix + "/remove/{id}",
modalName: "类目",
columns: [{
field: 'selectItem',
radio: true
},
{
field: 'goodsCategoryName',
title: '类目名称',
align: "left"
},
{
field: 'categorySort',
title: '排序',
align: "left"
},
{
field: 'status',
title: '状态',
align: "left",
formatter: function (value, item, index) {
return $.table.selectDictLabel(datas, item.status);
}
},
{
field: 'createTime',
title: '创建时间',
align: "left"
},
{
title: '操作',
align: 'left',
formatter: function (value, row, index) {
if (row.parentId !== 0) {
var actions = [];
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.goodsCategoryId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-info btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.goodsCategoryId + '\')"><i class="fa fa-plus"></i>新增</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="remove(\'' + row.goodsCategoryId + '\')"><i class="fa fa-trash"></i>删除</a>');
return actions.join('');
} else {
return "";
}
}
}]
};
$.treeTable.init(options);
});
function remove(id) {
$.modal.confirm("确认要删除吗", function () {
$.operate.post(prefix + '/remove/' + id);
})
}
</script>
</body>
</html>

View File

@ -1,87 +1,86 @@
<!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 :: ztree-css" />
<th:block th:include="include :: header('新增分公司类目')"/>
<th:block th:include="include :: ztree-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-category-add">
<div class="form-group">
<div class="col-sm-8">
<label class="check-box">
<input type="checkbox" value="1">展开/折叠</label>
<label class="check-box">
<input type="checkbox" value="2">全选/全不选</label>
<label class="check-box">
<input type="checkbox" value="3" checked>父子联动</label>
<div id="menuTrees" class="ztree ztree-border"></div>
</div>
</div>
</form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: ztree-js" />
<script type="text/javascript">
$(function() {
var url = ctx + "goods/deptcategory/tree";
var options = {
id: "menuTrees",
url: url,
check: { enable: true },
expandLevel: 0
};
$.tree.init(options);
});
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-category-add">
<div class="form-group">
<div class="col-sm-8">
<label class="check-box">
<input type="checkbox" value="1">展开/折叠</label>
<label class="check-box">
<input type="checkbox" value="2">全选/全不选</label>
<label class="check-box">
<input type="checkbox" value="3" checked>父子联动</label>
<div id="menuTrees" class="ztree ztree-border"></div>
</div>
</div>
</form>
</div>
$('input').on('ifChanged', function(obj){
var type = $(this).val();
var checked = obj.currentTarget.checked;
if (type == 1) {
if (checked) {
$._tree.expandAll(true);
} else {
$._tree.expandAll(false);
}
} else if (type == "2") {
if (checked) {
$._tree.checkAllNodes(true);
} else {
$._tree.checkAllNodes(false);
}
} else if (type == "3") {
if (checked) {
$._tree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };
} else {
$._tree.setting.check.chkboxType = { "Y": "", "N": "" };
}
}
})
<th:block th:include="include :: footer"/>
<th:block th:include="include :: ztree-js"/>
function add() {
var menuIds = $.tree.getCheckedNodes("goodsCategoryId");
$.ajax({
cache : true,
type : "POST",
url : ctx + "system/role/edit",
data : {
"menuIds": menuIds
},
async : false,
error : function(request) {
$.modal.alertError("系统错误");
},
success : function(data) {
$.operate.successCallback(data);
}
});
}
function submitHandler() {
if ($.validate.form()) {
add();
}
}
</script>
<script type="text/javascript">
$(function () {
var url = ctx + "goods/category/tree";
var options = {
id: "menuTrees",
url: url,
check: {enable: true},
expandLevel: 0
};
$.tree.init(options);
});
$('input').on('ifChanged', function (obj) {
var type = $(this).val();
var checked = obj.currentTarget.checked;
if (type === 1) {
if (checked) {
$._tree.expandAll(true);
} else {
$._tree.expandAll(false);
}
} else if (type == "2") {
if (checked) {
$._tree.checkAllNodes(true);
} else {
$._tree.checkAllNodes(false);
}
} else if (type == "3") {
if (checked) {
$._tree.setting.check.chkboxType = {"Y": "ps", "N": "ps"};
} else {
$._tree.setting.check.chkboxType = {"Y": "", "N": ""};
}
}
})
function add() {
var menuIds = $.tree.getCheckedNodes("id");
$.ajax({
cache: true,
type: "POST",
url: ctx + "goods/deptcategory/add?menuIds=" + menuIds,
async: false,
error: function (request) {
$.modal.alertError("系统错误");
},
success: function (data) {
$.operate.successCallback(data);
}
});
}
function submitHandler() {
if ($.validate.form()) {
add();
}
}
</script>
</body>
</html>

View File

@ -32,7 +32,7 @@
</div>
<div class="btn-group-sm" id="toolbar" role="group">
<a class="btn btn-primary" onclick="$.operate.add(1)" shiro:hasPermission="goods:category:edit">
<a class="btn btn-primary" onclick="$.operate.add(1)" shiro:hasPermission="goods:category:add">
<i class="fa fa-edit"></i> 修改
</a>
<a class="btn btn-info" id="expandAllBtn">
@ -46,68 +46,89 @@
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
var addFlag = [[${@permission.hasPermi('goods:category:add')}]];
var editFlag = [[${@permission.hasPermi('goods:category:edit')}]];
var removeFlag = [[${@permission.hasPermi('goods:category:remove')}]];
var datas = [[${@dict.getType('sys_normal_disable')}]];
var prefix = ctx + "goods/deptcategory"
var addFlag = [[${@permission.hasPermi('goods:category:add')}]];
var editFlag = [[${@permission.hasPermi('goods:category:edit')}]];
var removeFlag = [[${@permission.hasPermi('goods:category:remove')}]];
var datas = [[${@dict.getType('sys_normal_disable')}]];
var prefix = ctx + "goods/deptcategory"
$(function() {
var options = {
code: "goodsCategoryId",
parentCode: "parentCategoryId",
uniqueId: "goodsCategoryId",
url: prefix + "/list",
addUrl: prefix + "/add/{id}",
createUrl: prefix + "/add/{id}",
updateUrl: prefix + "/edit/{id}",
removeUrl: prefix + "/remove/{id}",
modalName: "类目",
columns: [{
field: 'selectItem',
radio: true
},
{
field: 'goodsCategoryName',
title: '类目名称',
align: "left"
},
{
field: 'categorySort',
title: '排序',
align: "left"
},
{
field: 'status',
title: '状态',
align: "left",
formatter: function(value, item, index) {
return $.table.selectDictLabel(datas, item.status);
}
},
{
field: 'createTime',
title: '创建时间',
align: "left"
},
{
title: '操作',
align: 'left',
formatter: function(value, row, index) {
if (row.parentId != 0) {
var actions = [];
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.goodsCategoryId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-info btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.goodsCategoryId + '\')"><i class="fa fa-plus"></i>新增</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodsCategoryId + '\')"><i class="fa fa-trash"></i>删除</a>');
return actions.join('');
} else {
return "";
}
}
}]
};
$.treeTable.init(options);
});
$(function () {
var options = {
code: "goodsCategoryId",
parentCode: "parentCategoryId",
uniqueId: "goodsCategoryId",
url: prefix + "/list",
addUrl: prefix + "/add/{id}",
createUrl: prefix + "/add/{id}",
updateUrl: prefix + "/edit/{id}",
removeUrl: prefix + "/remove/{id}",
modalName: "类目",
columns: [{
field: 'selectItem',
radio: true
},
{
field: 'goodsCategoryName',
title: '类目名称',
align: "left"
},
{
field: 'oneRate',
title: '一级分销扣点',
align: "left"
},
{
field: 'twoRate',
title: '二级分销扣点',
align: "left"
},
{
field: 'threeRate',
title: '三级分销扣点',
align: "left"
},
{
field: 'categorySort',
title: '排序',
align: "left"
},
{
field: 'status',
title: '状态',
align: "left",
formatter: function (value, item, index) {
return $.table.selectDictLabel(datas, item.status);
}
},
{
field: 'createTime',
title: '创建时间',
align: "left"
},
{
field: 'remark',
title: '备注',
align: "left"
},
{
title: '操作',
align: 'left',
formatter: function (value, row, index) {
if (row.parentId !== 0) {
var actions = [];
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.deptGoodsCategoryId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
// actions.push('<a class="btn btn-info btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.deptGoodsCategoryId + '\')"><i class="fa fa-plus"></i>新增</a> ');
// actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="remove(\'' + row.deptGoodsCategoryId + '\')"><i class="fa fa-trash"></i>删除</a>');
return actions.join('');
} else {
return "";
}
}
}
]
};
$.treeTable.init(options);
});
</script>
</body>

View File

@ -0,0 +1,98 @@
<!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-deptGoodsCategory-edit" th:object="${deptGoodsCategory}">
<input id="deptGoodsCategoryId" name="deptGoodsCategoryId" type="hidden" th:field="*{deptGoodsCategoryId}"/>
<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="goodsCategoryName" placeholder="请输入商品名称" class="form-control" type="text" maxlength="30"
th:field="*{goodsCategoryName}"
disabled>
</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="oneRate" placeholder="请输入一级分销扣点比例" class="form-control" type="text" maxlength="12"
th:field="*{oneRate}"
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="twoRate" placeholder="请输入二级分销扣点比例" class="form-control" type="text"
th:field="*{twoRate}"
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="threeRate" placeholder="请输入三级分销扣点比例" class="form-control" type="text" maxlength="12"
th:field="*{threeRate}"
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/deptcategory";
$("#form-deptGoodsCategory-edit").validate({
onkeyup: false,
rules: {},
messages: {},
focusCleanup: true
});
function submitHandler() {
if ($.validate.form()) {
var data = $("#form-deptGoodsCategory-edit").serializeArray();
$.operate.saveTab(prefix + "/edit", data);
$.modal.close();
}
}
</script>
</body>
</html>

View File

@ -1,158 +0,0 @@
package com.ghy;
import com.alibaba.fastjson.JSON;
import com.ghy.common.adapay.AdapayService;
import com.ghy.common.adapay.model.DivMember;
import com.ghy.common.adapay.model.PayParam;
import com.ghy.goods.domain.DeptGoodsCategory;
import com.ghy.goods.domain.Goods;
import com.ghy.goods.domain.GoodsCategory;
import com.ghy.goods.mapper.GoodsMapper;
import com.ghy.goods.service.DeptGoodsCategoryService;
import com.ghy.goods.service.GoodsCategoryService;
import com.huifu.adapay.core.exception.BaseAdaPayException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@SpringBootTest
@RunWith(SpringRunner.class)
public class TestApplication {
@Resource
private AdapayService adapayService;
@Resource
private GoodsMapper goodsMapper;
@Resource
private GoodsCategoryService goodsCategoryService;
@Resource
private DeptGoodsCategoryService deptGoodsCategoryService;
@Test
public void testGoodsCategoryService() {
GoodsCategory goodsCategory = new GoodsCategory();
goodsCategory.setGoodsCategoryCode("FRUIT");
goodsCategory.setGoodsCategoryName("水果");
goodsCategory.setLevel(1);
goodsCategory.setType(1);
goodsCategoryService.insertGoodsCategory(goodsCategory);
}
@Test
public void testDeptGoodsCategoryService() {
// DeptGoodsCategory category = new DeptGoodsCategory();
// category.setDeptId(1L);
// category.setGoodsCategoryId(1L);
// category.setCategorySort(1);
// category.setOneRate("0.10");
// category.setTwoRate("0.10");
// category.setThreeRate("0.10");
// deptGoodsCategoryService.add(category);
// category.setGoodsCategoryId(2L);
// category.setCategorySort(2);
// deptGoodsCategoryService.add(category);
// category.setGoodsCategoryId(3L);
// category.setCategorySort(3);
// deptGoodsCategoryService.add(category);
List<DeptGoodsCategory> list = deptGoodsCategoryService.list(null);
list.forEach(System.out::println);
}
@Test
public void addGoods() {
for (int i = 1; i < 11; i++) {
Goods goods = new Goods();
goods.setGoodsCode("GOODS0000" + i);
goods.setGoodsName("神秘商品" + i);
goods.setGoodsPrice(BigDecimal.valueOf(i));
goods.setDiscountsPrice(BigDecimal.valueOf(i));
goods.setGroupPrice(BigDecimal.valueOf(i));
goods.setGoodsSort(i);
goods.setDeptId(1L);
goods.setStatus(0);
goods.setDeptGoodsCategoryId(1L);
goods.setGoodsNumber(i * 100);
System.out.println(goods);
goodsMapper.insertGoods(goods);
}
}
/**
* 转账
*/
@Test
public void balancePay() throws BaseAdaPayException {
String orderNo = "TEST_ORDER_" + System.currentTimeMillis();
System.out.println("orderNo = " + orderNo);
Map<String, Object> map = adapayService.balancePay(orderNo, "0", "HH",
"10.00", "商品标题", "商品描述", null, null);
System.out.println(JSON.toJSONString(map));
}
/**
* 支付宝正扫支付
*/
@Test
public void alipayQr() throws BaseAdaPayException {
DivMember gqz = new DivMember("0", "10.00", false);
DivMember hh = new DivMember("HH", "10.00", true);
String orderNo = "TEST_ORDER_" + System.currentTimeMillis();
System.out.println("orderNo = " + orderNo);
PayParam payParam = new PayParam(orderNo, "20.00", "测试商品", "测试商品描述信息");
Map<String, Object> map = adapayService.alipayQrPay(payParam, reply -> System.out.println(JSON.toJSONString(reply)),
null, null, Arrays.asList(gqz, hh));
System.out.println(JSON.toJSONString(map));
}
/**
* 创建实名用户
*/
@Test
public void createMember() throws BaseAdaPayException {
Map<String, Object> member = adapayService.createMember("LBW", "18788888888", "卢本伟",
"450321199608081017", "广西省桂林市", "velkhana@qq.com", null, null);
System.out.println(JSON.toJSONString(member));
}
/**
* 创建结算账户
*/
@Test
public void createSettleAccount() throws BaseAdaPayException {
Map<String, Object> map = adapayService.createSettleAccount("HH", "6217921009538441", "黄皓", "2",
"450321199608081017", "18777338398", null, null, null);
System.out.println(JSON.toJSONString(map));
}
/**
* 提现
*/
@Test
public void drawCash() throws BaseAdaPayException {
Map<String, Object> map = adapayService.drawCash(reply -> System.out.println(JSON.toJSONString(reply)),
"HH_DRAW_CASH0002", "T1", "198.00", "HH", null, null);
System.out.println(JSON.toJSONString(map));
}
/**
* 退款
*/
@Test
public void refund() throws BaseAdaPayException {
Map<String, Object> map = adapayService.refund(reply -> System.out.println(JSON.toJSONString(reply)),
"002112022051210564510370658738275037184", "REFUND002112022051210564510370658738275037184",
"20.00");
System.out.println(JSON.toJSONString(map));
}
}

View File

@ -1,6 +1,7 @@
package com.ghy.goods.mapper;
import com.ghy.goods.domain.DeptGoodsCategory;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List;
@ -40,12 +41,31 @@ public interface DeptGoodsCategoryMapper {
/**
* 批量删除商品信息
*
* @param goodsCategoryId 需要删除的数据ID
* @param ids 需要删除的数据ID
* @return 结果
*/
int deleteDeptGoodsCategoryByIds(Collection<Long> goodsCategoryId);
int deleteDeptGoodsCategoryByIds(@Param("ids") Collection<Long> ids);
List<DeptGoodsCategory> appList(DeptGoodsCategory deptGoodsCategory);
/**
* 用商品类目ID查一条分公司类目
*
* @param goodsCategoryId 商品类目
*/
DeptGoodsCategory selectOneByGoodsCategoryId(Long goodsCategoryId);
/**
* 用分公司ID查询
*
* @param deptId 分公司ID
*/
List<DeptGoodsCategory> selectByDeptId(Long deptId);
/**
* 删除
*/
int deleteById(Long id);
}

View File

@ -1,5 +1,6 @@
package com.ghy.goods.service;
import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.core.domain.Ztree;
import com.ghy.goods.domain.DeptGoodsCategory;
@ -58,4 +59,20 @@ public interface DeptGoodsCategoryService {
List<DeptGoodsCategory> appList(Long deptId);
int delete(String ids);
/**
* 用商品类目ID查一条分公司类目
*
* @param goodsCategoryId 商品类目
*/
DeptGoodsCategory selectOneByGoodsCategoryId(Long goodsCategoryId);
/**
* 全量保存分公司类目
*
* @param parentId 分公司ID
* @param checked 选中的类目ID
*/
AjaxResult batchAdd(Long parentId, Long[] checked);
}

View File

@ -77,4 +77,11 @@ public interface GoodsCategoryService {
* @return
*/
List<GoodsCategory> selectByIds(Collection<Long> ids);
/**
* 获取所有的商品类目并标记出当前公司拥有的类目
*
* @param deptId 分公司ID
*/
List<Ztree> tree(Long deptId);
}

View File

@ -1,18 +1,21 @@
package com.ghy.goods.service.impl;
import com.ghy.common.constant.UserConstants;
import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.core.domain.Ztree;
import com.ghy.common.core.text.Convert;
import com.ghy.common.utils.StringUtils;
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 lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author clunt
@ -52,7 +55,10 @@ public class DeptGoodsCategoryServiceImpl implements DeptGoodsCategoryService {
@Override
public List<Ztree> tree(Long parentId) {
return null;
DeptGoodsCategory category = new DeptGoodsCategory();
category.setDeptId(parentId);
List<DeptGoodsCategory> list = list(category);
return initZtree(list);
}
@Override
@ -88,6 +94,35 @@ public class DeptGoodsCategoryServiceImpl implements DeptGoodsCategoryService {
return delete(Arrays.asList(array));
}
@Override
public DeptGoodsCategory selectOneByGoodsCategoryId(Long goodsCategoryId) {
return deptGoodsCategoryMapper.selectOneByGoodsCategoryId(goodsCategoryId);
}
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult batchAdd(Long parentId, Long[] checked) {
List<DeptGoodsCategory> oldList = deptGoodsCategoryMapper.selectByDeptId(parentId);
Map<Long, Long> oldMap = oldList.stream().collect(Collectors.toMap(GoodsCategory::getGoodsCategoryId,
DeptGoodsCategory::getDeptGoodsCategoryId));
HashSet<Long> newSet = new HashSet<>(Arrays.asList(checked));
Set<Long> intersection = oldList.stream().map(DeptGoodsCategory::getGoodsCategoryId).collect(Collectors.toSet());
intersection.addAll(Arrays.asList(checked));
for (Long id : intersection) {
if (newSet.contains(id)) {
if (!oldMap.containsKey(id)) {
DeptGoodsCategory category = new DeptGoodsCategory();
category.setDeptId(parentId);
category.setGoodsCategoryId(id);
deptGoodsCategoryMapper.insertDeptGoodsCategory(category);
}
} else if (oldMap.containsKey(id)) {
deptGoodsCategoryMapper.deleteById(oldMap.get(id));
}
}
return AjaxResult.success();
}
private void fillChild(List<DeptGoodsCategory> goodsCategoryList) {
List<DeptGoodsCategory> childList;
for (DeptGoodsCategory deptGoodsCategory : goodsCategoryList) {
@ -97,4 +132,19 @@ public class DeptGoodsCategoryServiceImpl implements DeptGoodsCategoryService {
}
}
}
public List<Ztree> initZtree(List<DeptGoodsCategory> list) {
List<Ztree> ztrees = new ArrayList<>();
for (GoodsCategory goodsCategory : list) {
if (UserConstants.CATEGORY_NORMAL.equals(goodsCategory.getStatus())) {
Ztree ztree = new Ztree();
ztree.setId(goodsCategory.getGoodsCategoryId());
ztree.setpId(goodsCategory.getParentCategoryId());
ztree.setName(goodsCategory.getGoodsCategoryName());
ztree.setTitle(goodsCategory.getGoodsCategoryName());
ztrees.add(ztree);
}
}
return ztrees;
}
}

View File

@ -3,10 +3,10 @@ package com.ghy.goods.service.impl;
import com.ghy.common.constant.UserConstants;
import com.ghy.common.core.domain.Ztree;
import com.ghy.common.core.text.Convert;
import com.ghy.goods.domain.Goods;
import com.ghy.goods.domain.DeptGoodsCategory;
import com.ghy.goods.domain.GoodsCategory;
import com.ghy.goods.mapper.GoodsCategoryMapper;
import com.ghy.goods.mapper.GoodsMapper;
import com.ghy.goods.service.DeptGoodsCategoryService;
import com.ghy.goods.service.GoodsCategoryService;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
@ -15,6 +15,8 @@ import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @author clunt
@ -23,10 +25,10 @@ import java.util.List;
@Service
public class GoodsCategoryServiceImpl implements GoodsCategoryService {
@Resource
private GoodsMapper goodsMapper;
@Resource
GoodsCategoryMapper goodsCategoryMapper;
@Resource
DeptGoodsCategoryService deptGoodsCategoryService;
@Override
public int insertGoodsCategory(GoodsCategory goodsCategory) {
@ -60,8 +62,8 @@ public class GoodsCategoryServiceImpl implements GoodsCategoryService {
public int deleteGoodsCategoryByIds(String ids) {
Long[] idArray = Convert.toLongArray(ids);
for (Long id : idArray) {
Goods goods = goodsMapper.selectOneByGoodsCategoryId(id);
Assert.isNull(goods, "正在被使用的商品类别不能删除");
DeptGoodsCategory category = deptGoodsCategoryService.selectOneByGoodsCategoryId(id);
Assert.isNull(category, "正在被使用的商品类别不能删除");
}
return goodsCategoryMapper.deleteGoodsCategoryByIds(idArray);
}
@ -89,25 +91,24 @@ public class GoodsCategoryServiceImpl implements GoodsCategoryService {
return goodsCategoryMapper.selectByIds(ids);
}
/**
* 对象转类目树
*
* @param goodsCategoryList 类目列表
* @return 树结构列表
*/
public List<Ztree> initZtree(List<GoodsCategory> goodsCategoryList) {
return initZtree(goodsCategoryList, null);
@Override
public List<Ztree> tree(Long deptId) {
List<GoodsCategory> goodsCategoryList = goodsCategoryMapper.selectGoodsCategoryList(null);
DeptGoodsCategory category = new DeptGoodsCategory();
category.setDeptId(deptId);
Set<Long> usedSet = deptGoodsCategoryService.list(category).stream()
.map(DeptGoodsCategory::getGoodsCategoryId).collect(Collectors.toSet());
return initZtree(goodsCategoryList, usedSet);
}
/**
* 对象转部门树
* List转带选中状态(checked)的ZTree
*
* @param goodsCategoryList 类目列表
* @param roleDeptList 该列表无需校验
* @return 树结构列表
* @param goodsCategoryList 商品类目List
* @param checked 选中的集合
* @return
*/
public List<Ztree> initZtree(List<GoodsCategory> goodsCategoryList, List<String> roleDeptList) {
public List<Ztree> initZtree(List<GoodsCategory> goodsCategoryList, Collection<Long> checked) {
List<Ztree> ztrees = new ArrayList<>();
for (GoodsCategory goodsCategory : goodsCategoryList) {
if (UserConstants.CATEGORY_NORMAL.equals(goodsCategory.getStatus())) {
@ -116,7 +117,28 @@ public class GoodsCategoryServiceImpl implements GoodsCategoryService {
ztree.setpId(goodsCategory.getParentCategoryId());
ztree.setName(goodsCategory.getGoodsCategoryName());
ztree.setTitle(goodsCategory.getGoodsCategoryName());
ztrees.add(ztree);
ztree.setChecked(checked.contains(goodsCategory.getGoodsCategoryId()));
}
}
return ztrees;
}
/**
* 对象转部门树
*
* @param goodsCategoryList 类目列表
* @return 树结构列表
*/
public List<Ztree> initZtree(List<GoodsCategory> goodsCategoryList) {
List<Ztree> ztrees = new ArrayList<>();
for (GoodsCategory goodsCategory : goodsCategoryList) {
if (UserConstants.CATEGORY_NORMAL.equals(goodsCategory.getStatus())) {
Ztree ztree = new Ztree();
ztree.setId(goodsCategory.getGoodsCategoryId());
ztree.setpId(goodsCategory.getParentCategoryId());
ztree.setName(goodsCategory.getGoodsCategoryName());
ztree.setTitle(goodsCategory.getGoodsCategoryName());
ztrees.add(ztree);
}
}

View File

@ -52,24 +52,28 @@
<update id="updateDeptGoodsCategory" parameterType="com.ghy.goods.domain.DeptGoodsCategory">
UPDATE dept_goods_category
<set>
<if test="goodsCategoryId != null">goods_category_id = #{goodsCategoryId},</if>
<if test="categorySort != null">category_sort = #{categorySort},</if>
<if test="oneRate != null and oneRate != ''">one_rate = #{oneRate},</if>
<if test="twoRate != null and twoRate != ''">two_rate = #{twoRate},</if>
<if test="threeRate != null and threeRate != ''">three_rate = #{threeRate},</if>
<if test="remark != null and remark != ''">remark = #{remark},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
WHERE dept_goods_category_id = #{goodsCategoryId}
WHERE dept_goods_category_id = #{deptGoodsCategoryId}
</update>
<delete id="deleteDeptGoodsCategoryByIds" parameterType="Long">
DELETE FROM dept_goods_category WHERE dept_goods_category_id IN
<foreach collection="array" item="goodsCategoryId" open="(" separator="," close=")">
<foreach collection="ids" item="goodsCategoryId" open="(" separator="," close=")">
#{goodsCategoryId}
</foreach>
</delete>
<delete id="deleteById">
DELETE FROM dept_goods_category WHERE dept_goods_category_id = #{id}
</delete>
<insert id="insertDeptGoodsCategory" parameterType="com.ghy.goods.domain.DeptGoodsCategory" useGeneratedKeys="true"
keyProperty="goodsCategoryId">
insert into dept_goods_category(
@ -103,13 +107,23 @@
AND gc.goods_category_name LIKE concat('%', #{goodsCategoryName}, '%')
</if>
<if test="status != null and status != ''">
AND gc.status LIKE concat('%', #{status}, '%')
AND gc.status = #{status}
</if>
</where>
</select>
<select id="selectById" parameterType="long" resultMap="DeptGoodsCategoryResult">
<include refid="selectJoin"/>
WHERE dgc.dept_goods_category_id = #{deptGoodsCategoryId}
</select>
<select id="selectOneByGoodsCategoryId" resultMap="DeptGoodsCategoryResult">
<include refid="selectDeptGoodsCategory"/>
WHERE dept_goods_category_id = #{deptGoodsCategoryId}
WHERE goods_category_id = #{goodsCategoryId} LIMIT 1
</select>
<select id="selectByDeptId" resultMap="DeptGoodsCategoryResult">
<include refid="selectDeptGoodsCategory"/>
WHERE dept_id = #{deptId}
</select>
</mapper>