1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

分类管理增删改查完成

This commit is contained in:
程序员小墨 2023-04-13 22:07:05 +08:00
parent 7dcf15fd79
commit bad6ecb111
19 changed files with 376 additions and 36 deletions

View File

@ -4,6 +4,13 @@
小程序扫门禁码之后门禁开门
小程序修改密码
# IP 配置
内网穿透124.220.172.110
nacos106.75.217.14
数据库:本地
# QCloud
主账号ID 100014397291

View File

@ -43,7 +43,7 @@ public class FieldBuilder {
FieldType fieldType, SearchType searchType, AddType addType, EditType editType,
String searchPlaceholder, String addPlaceholder, String editPlaceholder,
FieldRuleListBuilder fieldRuleListBuilder, String mockDataPattern) {
JSONObject jsonObject = new JSONObject(2);
JSONObject jsonObject = new JSONObject();
/* 实际字段 */
// 用于筛选增删改

View File

@ -19,7 +19,7 @@ public class FieldMapperBuilder {
// if (mapper == null || mapper.size() == 0) {
// return this;
// }
// JSONObject jsonObject = new JSONObject(2);
// JSONObject jsonObject = new JSONObject(3);
// jsonObject.put("key", prop);
// jsonObject.put("value", label);
// jsonObject.put("mapper", mapper);
@ -28,7 +28,7 @@ public class FieldMapperBuilder {
// }
public FieldMapperBuilder add(String prop, String label, HashMap mapper) {
JSONObject jsonObject = new JSONObject(2);
JSONObject jsonObject = new JSONObject(3);
jsonObject.put("key", prop);
jsonObject.put("value", label);
jsonObject.put("mapper", mapper);

View File

@ -8,6 +8,7 @@ import org.springframework.beans.BeanUtils;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
// 数据库关系映射
@ -38,4 +39,23 @@ public class GoodCategoryVO implements Serializable {
List<GoodCategoryVO> goodCategoryVOList = goodCategoryList.stream().map(GoodCategoryVO::convertFrom).collect(Collectors.toList());
return goodCategoryVOList;
}
public static GoodCategory convertTo(GoodCategoryVO goodCategoryVO) {
if (goodCategoryVO == null) {
return null;
}
GoodCategory goodCategory = new GoodCategory();
BeanUtils.copyProperties(goodCategoryVO, goodCategory);
try {
if (!Objects.isNull(goodCategoryVO.getId())) {
Long goodCategoryId = Long.valueOf(goodCategoryVO.getId());
goodCategory.setId(goodCategoryId);
} else {
goodCategory.setId(null);
}
} catch (Exception e) {
goodCategory.setId(null);
}
return goodCategory;
}
}

View File

@ -216,7 +216,7 @@ public class GoodController {
.build();
// 拼装返回结果
JSONObject map = new JSONObject(2);
JSONObject map = new JSONObject(6);
map.put("total", goodPageInfo.getTotal());
map.put("list", voList);
map.put("columns", columns);
@ -244,12 +244,12 @@ public class GoodController {
if (good.getId() == null || good.getId() < 1) {
// 新增商品
if (existGood != null) {
return Res.error("商品已存在,操作失败");
return Res.error("商品已存在,操作失败");
}
// if (password == null || "".equals(password)) {
// return Res.error("密码不能为空");
// }
if (good.getGoodsName() == null || "".equals(good.getGoodsName())) {
return Res.error("商品名称不能为空");
}
good.setId(null);
goodService.addGood(good);
} else {
@ -275,7 +275,7 @@ public class GoodController {
if (id == null || id <= 0) {
return Res.error("商品不存在,删除失败");
}
// 先查询商品是否存在
// 先查询商品是否存在
Good existGood = goodService.getGoodById(id);
if (existGood == null) {
return Res.error("商品不存在,删除失败");
@ -308,6 +308,13 @@ public class GoodController {
return Res.success(map);
}
/**
* 上传商品图片到腾讯云COS桶
* 获取上传临时密钥及生成文件名
*
* @param ext
* @return
*/
@GetMapping("/manage/imageUpload/getTmpCosCredential")
@ResponseBody
public Res getTmpCosCredential(@RequestParam(required = true) String ext) {
@ -319,4 +326,144 @@ public class GoodController {
// 返回结果
return Res.success(credential);
}
/**
* 获取商品分类
*
* @return
*/
@GetMapping("/manage/getCategoryList")
@ResponseBody
public Res getCategoryList(PageQuery pageQuery, GoodCategoryVO goodCategoryVO) {
// 查询分页数据
PageHelper.startPage(pageQuery.getPageIndex(), pageQuery.getPageSize());
List<GoodCategory> goodCategoryList = goodService.getCateListWithQuery(goodCategoryVO);
PageInfo<GoodCategory> goodCategoryPageInfo = new PageInfo<>(goodCategoryList);
List<GoodCategory> list = goodCategoryPageInfo.getList();
List<GoodCategoryVO> voList = GoodCategoryVO.convertFrom(list);
// id列 字段名区分大小写以VO中的变量名为准
// 新增修改弹窗时使用该列作为主键列进行操作
String idFieldName = "id";
// 当前管理页面
String pageName = "分类管理";
// 指定前端表格显示列
JSONArray columns = FieldBuilder.create()
.add("categoryName", "categoryName", "商品分类", "",
FieldType.TEXT, SearchType.INPUT, AddType.INPUT, EditType.INPUT,
FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
"商品分类", FieldBuilder.EDIT_PLACEHOLDER_SAME_AS_ADD_PLACEHOLDER,
FieldRuleListBuilder.create()
.add(FieldRuleBuilder.create("商品分类").required())
.add(FieldRuleBuilder.create("商品分类").minMax(2, 4)),
"DPD @cword(2, 4)"
)
.add("order", "order", "排序", "",
FieldType.TEXT, SearchType.CAN_NOT_SEARCH, AddType.INPUT, EditType.INPUT,
FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
"排序", FieldBuilder.EDIT_PLACEHOLDER_SAME_AS_ADD_PLACEHOLDER,
FieldRuleListBuilder.create(),
"DTD /^\\d+?$/"
)
.build();
// 指定需要翻译的字段
JSONArray fieldMapper = FieldMapperBuilder.create()
.build();
// 拼装返回结果
JSONObject map = new JSONObject(6);
map.put("total", goodCategoryPageInfo.getTotal());
map.put("list", voList);
map.put("columns", columns);
map.put("fieldMapper", fieldMapper);
map.put("idFieldName", idFieldName);
map.put("pageName", pageName);
// 返回结果
return Res.success(map);
}
/**
* 新增 / 编辑分类
*
* @return
*/
@PostMapping("/manage/editCategory")
@ResponseBody
public Res editCategory(@ModelAttribute GoodCategoryVO goodCategoryVO) {
GoodCategory goodCategory = GoodCategoryVO.convertTo(goodCategoryVO);
// 先查询分类是否存在
GoodCategory existGoodCategory = goodService.getGoodCategoryById(goodCategory.getId());
if (goodCategory.getId() == null || goodCategory.getId() < 1) {
// 新增分类
if (existGoodCategory != null) {
return Res.error("分类已存在,操作失败");
}
if (goodCategory.getCategoryName() == null || "".equals(goodCategory.getCategoryName())) {
return Res.error("分类名称不能为空");
}
goodCategory.setId(null);
goodService.addGoodCategory(goodCategory);
} else {
// 修改分类
if (existGoodCategory == null) {
return Res.error("分类不存在,操作失败");
}
goodService.updateGoodCategory(goodCategory);
}
return Res.success(true);
}
/**
* 删除分类
*
* @param id
* @return
*/
@PostMapping("/manage/deleteCategory")
@ResponseBody
public Res deleteCategory(Long id) {
if (id == null || id <= 0) {
return Res.error("分类不存在,删除失败");
}
// 先查询分类是否存在
GoodCategory existGoodCategory = goodService.getGoodCategoryById(id);
if (existGoodCategory == null) {
return Res.error("分类不存在,删除失败");
}
boolean b = goodService.deleteGoodCategory(existGoodCategory.getId());
return Res.success(b);
}
/**
* 导出分类列表
*
* @return
*/
@GetMapping("/manage/exportCategoryList")
@ResponseBody
public Res exportCategoryList(GoodCategoryVO goodCategoryVO) {
List<GoodCategory> categoryList = goodService.getCateListWithQuery(goodCategoryVO);
List<GoodCategoryVO> goodCategoryVOList = GoodCategoryVO.convertFrom(categoryList);
// 当前时间
Date now = Calendar.getInstance().getTime();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd_HHmmss");
String dateTime = format.format(now);
HashMap<String, Object> map = new HashMap<>();
map.put("list", goodCategoryVOList);
map.put("sheetName", "商品分类表-" + System.currentTimeMillis());
map.put("fileName", "商品分类表_导出时间_" + dateTime);
return Res.success(map);
}
}

View File

@ -1,6 +1,7 @@
package com.cxyxiaomo.epp.shop.dao;
import com.cxyxiaomo.epp.common.pojo.GoodCategory;
import com.cxyxiaomo.epp.common.vo.GoodCategoryVO;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
@ -12,5 +13,14 @@ public interface GoodCategoryDao {
List<GoodCategory> list();
GoodCategory getById(Integer id);
GoodCategory getById(Long id);
public boolean addCategory(GoodCategory goodCategory);
public boolean updateCategory(GoodCategory goodCategory);
public List<GoodCategory> getCategoryList(GoodCategoryVO goodCategoryVO);
public boolean deleteCategoryById(Long goodCategoryId);
}

View File

@ -49,11 +49,27 @@ public class GoodService {
}
/**
* 获取分类列表不带查询参数
*
* @return
*/
public List<GoodCategory> getCateList() {
List<GoodCategory> list = goodCategoryDao.list();
return list;
}
/**
* 获取分类列表带查询参数
*
* @param goodCategoryVO
* @return
*/
public List<GoodCategory> getCateListWithQuery(GoodCategoryVO goodCategoryVO) {
List<GoodCategory> list = goodCategoryDao.getCategoryList(goodCategoryVO);
return list;
}
public Good getGoodById(Long id) {
if (id == null) {
@ -79,4 +95,25 @@ public class GoodService {
public boolean deleteGood(Long goodId) {
return goodDao.deleteGoodById(goodId);
}
public boolean addGoodCategory(GoodCategory goodCategory) {
goodCategory.setId(null);
return goodCategoryDao.addCategory(goodCategory);
}
public boolean updateGoodCategory(GoodCategory goodCategory) {
return goodCategoryDao.updateCategory(goodCategory);
}
public boolean deleteGoodCategory(Long goodCategoryId) {
return goodCategoryDao.deleteCategoryById(goodCategoryId);
}
public GoodCategory getGoodCategoryById(Long id) {
if (id == null) {
return null;
}
return goodCategoryDao.getById(id);
}
}

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cxyxiaomo.epp.shop.dao.GoodCategoryDao">
<select id="list" resultType="com.cxyxiaomo.epp.common.pojo.GoodCategory">
SELECT * FROM goods_category
WHERE 1 = 1
order by `order` asc
</select>
<select id="getById" parameterType="java.lang.Integer" resultType="com.cxyxiaomo.epp.common.pojo.GoodCategory">
SELECT * FROM goods_category
WHERE id = #{id}
order by `order` asc
</select>
</mapper>

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cxyxiaomo.epp.shop.dao.GoodCategoryDao">
<select id="list" resultType="com.cxyxiaomo.epp.common.pojo.GoodCategory">
SELECT * FROM goods_category
WHERE 1 = 1
order by `order` asc
</select>
<select id="getById" parameterType="java.lang.Long" resultType="com.cxyxiaomo.epp.common.pojo.GoodCategory">
SELECT * FROM goods_category
WHERE id = #{id}
</select>
<insert id="addCategory" parameterType="com.cxyxiaomo.epp.common.pojo.GoodCategory">
INSERT INTO goods_category ( category_name, `order`)
VALUES (#{categoryName}, #{order})
</insert>
<update id="updateCategory" parameterType="com.cxyxiaomo.epp.common.pojo.GoodCategory">
UPDATE goods_category
<set>
<if test="categoryName != null and categoryName != ''">category_name = #{categoryName,jdbcType=VARCHAR},</if>
<if test="order != null">`order` = #{order},</if>
</set>
WHERE id = #{id}
</update>
<select id="getCategoryList" resultType="com.cxyxiaomo.epp.common.pojo.GoodCategory">
select *
from goods_category
where 1 = 1
<if test="id != null">
AND id = #{id}
</if>
<if test="categoryName != null &amp;&amp; categoryName != ''">
AND category_name LIKE concat('%',#{categoryName,jdbcType=VARCHAR},'%')
</if>
order by `order` asc
</select>
<delete id="deleteCategoryById">
DELETE
FROM goods_category
WHERE id = #{goodCategoryId}
</delete>
</mapper>

View File

@ -186,7 +186,7 @@ public class UserController {
.build();
// 拼装返回结果
JSONObject map = new JSONObject(2);
JSONObject map = new JSONObject(6);
map.put("total", userPageInfo.getTotal());
map.put("list", voList);
map.put("columns", columns);

View File

@ -52,7 +52,7 @@
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
<version>3.1.4</version>
<version>3.1.6</version>
</dependency>
<!-- Spring Cloud Starter Load Balancer -->
<dependency>

View File

@ -12,6 +12,9 @@ declare module '@vue/runtime-core' {
ElAlert: typeof import('element-plus/es')['ElAlert']
ElAvatar: typeof import('element-plus/es')['ElAvatar']
ElButton: typeof import('element-plus/es')['ElButton']
ElCard: typeof import('element-plus/es')['ElCard']
ElCheckbox: typeof import('element-plus/es')['ElCheckbox']
ElCol: typeof import('element-plus/es')['ElCol']
ElDialog: typeof import('element-plus/es')['ElDialog']
ElDropdown: typeof import('element-plus/es')['ElDropdown']
ElDropdownItem: typeof import('element-plus/es')['ElDropdownItem']
@ -26,14 +29,18 @@ declare module '@vue/runtime-core' {
ElMenuItem: typeof import('element-plus/es')['ElMenuItem']
ElOption: typeof import('element-plus/es')['ElOption']
ElPagination: typeof import('element-plus/es')['ElPagination']
ElProgress: typeof import('element-plus/es')['ElProgress']
ElRadio: typeof import('element-plus/es')['ElRadio']
ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup']
ElRow: typeof import('element-plus/es')['ElRow']
ElSelect: typeof import('element-plus/es')['ElSelect']
ElSubMenu: typeof import('element-plus/es')['ElSubMenu']
ElTable: typeof import('element-plus/es')['ElTable']
ElTableColumn: typeof import('element-plus/es')['ElTableColumn']
ElTooltip: typeof import('element-plus/es')['ElTooltip']
ElUpload: typeof import('element-plus/es')['ElUpload']
Header: typeof import('./src/components/header.vue')['default']
ImageUpload: typeof import('./src/components/image-upload.vue')['default']
ManageList: typeof import('./src/components/manage-list.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']

View File

@ -0,0 +1,51 @@
import send_request from '../utils/send_request';
/**
* 获取商品列表
* @returns
*/
export function getCateList(params) {
return send_request({
url: '/shop/good/manage/getCategoryList',
method: 'GET',
params: params,
});
};
/**
* 添加/修改商品信息
* @returns
*/
export function editCate(params) {
return send_request({
url: '/shop/good/manage/editCategory',
method: 'POST',
useQS: true,
params: params,
});
};
/**
* 删除商品
* @returns
*/
export function deleteCate(params) {
return send_request({
url: '/shop/good/manage/deleteCategory',
method: 'POST',
useQS: true,
params: params,
});
};
/**
* 导出商品列表
* @returns
*/
export function exportCateList(params) {
return send_request({
url: '/shop/good/manage/exportCategoryList',
method: 'GET',
params: params,
});
};

View File

@ -31,9 +31,6 @@
</span>
<template #dropdown>
<el-dropdown-menu>
<a href="https://github.com/lin-xin/vue-manage-system" target="_blank">
<el-dropdown-item>项目仓库</el-dropdown-item>
</a>
<el-dropdown-item command="user">个人中心</el-dropdown-item>
<el-dropdown-item divided command="loginout">退出登录</el-dropdown-item>
</el-dropdown-menu>

View File

@ -28,14 +28,18 @@ const emit = defineEmits(['change'])
const handleHttpRequest = async (data: UploadRequestOptions) => {
console.log('httpRequest', data)
await cos.upload(data.file)
let result = await cos.upload(data.file)
console.log("result", result)
return result
}
const handleSuccess: UploadProps['onSuccess'] = (
response,
response, // response handleHttpRequest
uploadFile
) => {
let url = URL.createObjectURL(uploadFile.raw!)
console.log("response", response)
// let url = URL.createObjectURL(uploadFile.raw!)
let url = "//" + response.Location
emit('change', url)
}

View File

@ -73,9 +73,14 @@ const items = [
{
icon: 'OfficeBuilding',
index: '/shop',
title: '商品管理',
title: '生活物资',
permiss: 'shop',
subs: [
{
index: '/shop-cate-setting',
title: '分类管理',
permiss: 'shop-cate-setting',
},
{
index: '/shop-good-setting',
title: '商品管理',
@ -86,7 +91,7 @@ const items = [
{
icon: 'Avatar',
index: '/privilege',
title: '用户管理',
title: '系统管理',
permiss: 'privilege',
subs: [
{

View File

@ -31,6 +31,15 @@ const routes: RouteRecordRaw[] = [
},
component: () => import('../views/shop-good-setting.vue'),
},
{
path: '/shop-cate-setting',
name: 'shop-cate-setting',
meta: {
title: '分类管理',
permiss: 'shop-good-setting',
},
component: () => import('../views/shop-cate-setting.vue'),
},
{
path: '/privilege-user-setting',
name: 'privilege-user-setting',

View File

@ -9,6 +9,7 @@ interface ObjectList {
export const usePermissStore = defineStore('permiss', {
state: () => {
return {
// 系统管理员
"1": [
"default",
@ -16,10 +17,13 @@ export const usePermissStore = defineStore('permiss', {
"shop",
"shop-good-setting",
"shop-cate-setting",
"privilege",
"privilege-user-setting",
],
// 社区管理员
"2": [
"default",
@ -27,6 +31,7 @@ export const usePermissStore = defineStore('permiss', {
"shop",
"shop-good-setting",
"shop-cate-setting",
"privilege",
"privilege-user-setting",

View File

@ -0,0 +1,11 @@
<template>
<div class="container">
<manageList :list-func="shopCateApi.getCateList" :add-func="shopCateApi.editCate" :edit-func="shopCateApi.editCate"
:delete-func="shopCateApi.deleteCate" :export-func="shopCateApi.exportCateList" edit-permiss="shop-cate-setting" />
</div>
</template>
<script setup lang="ts">
import manageList from '../components/manage-list.vue';
import * as shopCateApi from '../api/shop-cate';
</script>