From bad6ecb11151056cb0c718fdd3956eaaeb0af2ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E5=B0=8F=E5=A2=A8?= <2291200076@qq.com> Date: Thu, 13 Apr 2023 22:07:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=B1=BB=E7=AE=A1=E7=90=86=E5=A2=9E?= =?UTF-8?q?=E5=88=A0=E6=94=B9=E6=9F=A5=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TODOs.md | 7 + .../epp/PageTable/utils/FieldBuilder.java | 2 +- .../PageTable/utils/FieldMapperBuilder.java | 4 +- .../epp/common/vo/GoodCategoryVO.java | 20 +++ .../epp/shop/controller/GoodController.java | 159 +++++++++++++++++- .../epp/shop/dao/GoodCategoryDao.java | 12 +- .../epp/shop/service/GoodService.java | 37 ++++ .../mybatis/mapper/GoodCategoryDao.xml | 16 -- .../mybatis/mapper/GoodCategoryMapper.xml | 46 +++++ .../epp/user/controller/UserController.java | 2 +- backend/pom.xml | 2 +- frontend/components.d.ts | 7 + frontend/src/api/shop-cate.js | 51 ++++++ frontend/src/components/header.vue | 3 - frontend/src/components/image-upload.vue | 10 +- frontend/src/components/sidebar.vue | 9 +- frontend/src/router/index.ts | 9 + frontend/src/store/permiss.ts | 5 + frontend/src/views/shop-cate-setting.vue | 11 ++ 19 files changed, 376 insertions(+), 36 deletions(-) delete mode 100644 backend/microservice-provider-shop-8003/src/main/resources/mybatis/mapper/GoodCategoryDao.xml create mode 100644 backend/microservice-provider-shop-8003/src/main/resources/mybatis/mapper/GoodCategoryMapper.xml create mode 100644 frontend/src/api/shop-cate.js create mode 100644 frontend/src/views/shop-cate-setting.vue diff --git a/TODOs.md b/TODOs.md index df4b521..7ff7c40 100644 --- a/TODOs.md +++ b/TODOs.md @@ -4,6 +4,13 @@ 小程序扫门禁码之后门禁开门 小程序修改密码 +# IP 配置 + +内网穿透:124.220.172.110 +nacos:106.75.217.14 +数据库:本地 + + # QCloud 主账号ID 100014397291 diff --git a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/PageTable/utils/FieldBuilder.java b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/PageTable/utils/FieldBuilder.java index b29006a..ea24775 100644 --- a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/PageTable/utils/FieldBuilder.java +++ b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/PageTable/utils/FieldBuilder.java @@ -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(); /* 实际字段 */ // 用于筛选、增删改 diff --git a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/PageTable/utils/FieldMapperBuilder.java b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/PageTable/utils/FieldMapperBuilder.java index 7430625..df0858d 100644 --- a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/PageTable/utils/FieldMapperBuilder.java +++ b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/PageTable/utils/FieldMapperBuilder.java @@ -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); diff --git a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/vo/GoodCategoryVO.java b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/vo/GoodCategoryVO.java index 4a617e7..a4aaec7 100644 --- a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/vo/GoodCategoryVO.java +++ b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/vo/GoodCategoryVO.java @@ -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 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; + } } diff --git a/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/controller/GoodController.java b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/controller/GoodController.java index 924bd3f..dd37207 100644 --- a/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/controller/GoodController.java +++ b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/controller/GoodController.java @@ -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 goodCategoryList = goodService.getCateListWithQuery(goodCategoryVO); + PageInfo goodCategoryPageInfo = new PageInfo<>(goodCategoryList); + List list = goodCategoryPageInfo.getList(); + List 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 categoryList = goodService.getCateListWithQuery(goodCategoryVO); + List goodCategoryVOList = GoodCategoryVO.convertFrom(categoryList); + + // 当前时间 + Date now = Calendar.getInstance().getTime(); + SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd_HHmmss"); + String dateTime = format.format(now); + + HashMap map = new HashMap<>(); + map.put("list", goodCategoryVOList); + map.put("sheetName", "商品分类表-" + System.currentTimeMillis()); + map.put("fileName", "商品分类表_导出时间_" + dateTime); + + return Res.success(map); + } } diff --git a/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/dao/GoodCategoryDao.java b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/dao/GoodCategoryDao.java index db5dd88..b15f947 100644 --- a/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/dao/GoodCategoryDao.java +++ b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/dao/GoodCategoryDao.java @@ -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 list(); - GoodCategory getById(Integer id); + GoodCategory getById(Long id); + + + public boolean addCategory(GoodCategory goodCategory); + + public boolean updateCategory(GoodCategory goodCategory); + + public List getCategoryList(GoodCategoryVO goodCategoryVO); + + public boolean deleteCategoryById(Long goodCategoryId); } diff --git a/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/service/GoodService.java b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/service/GoodService.java index 7acae07..4f22c98 100644 --- a/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/service/GoodService.java +++ b/backend/microservice-provider-shop-8003/src/main/java/com/cxyxiaomo/epp/shop/service/GoodService.java @@ -49,11 +49,27 @@ public class GoodService { } + /** + * 获取分类列表(不带查询参数) + * + * @return + */ public List getCateList() { List list = goodCategoryDao.list(); return list; } + /** + * 获取分类列表(带查询参数) + * + * @param goodCategoryVO + * @return + */ + public List getCateListWithQuery(GoodCategoryVO goodCategoryVO) { + List 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); + } } diff --git a/backend/microservice-provider-shop-8003/src/main/resources/mybatis/mapper/GoodCategoryDao.xml b/backend/microservice-provider-shop-8003/src/main/resources/mybatis/mapper/GoodCategoryDao.xml deleted file mode 100644 index 2a655de..0000000 --- a/backend/microservice-provider-shop-8003/src/main/resources/mybatis/mapper/GoodCategoryDao.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - diff --git a/backend/microservice-provider-shop-8003/src/main/resources/mybatis/mapper/GoodCategoryMapper.xml b/backend/microservice-provider-shop-8003/src/main/resources/mybatis/mapper/GoodCategoryMapper.xml new file mode 100644 index 0000000..3b36273 --- /dev/null +++ b/backend/microservice-provider-shop-8003/src/main/resources/mybatis/mapper/GoodCategoryMapper.xml @@ -0,0 +1,46 @@ + + + + + + + + INSERT INTO goods_category ( category_name, `order`) + VALUES (#{categoryName}, #{order}) + + + UPDATE goods_category + + category_name = #{categoryName,jdbcType=VARCHAR}, + `order` = #{order}, + + WHERE id = #{id} + + + + + DELETE + FROM goods_category + WHERE id = #{goodCategoryId} + + diff --git a/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/controller/UserController.java b/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/controller/UserController.java index 23e5441..79f7764 100644 --- a/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/controller/UserController.java +++ b/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/controller/UserController.java @@ -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); diff --git a/backend/pom.xml b/backend/pom.xml index f3e72e4..b96f6f5 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -52,7 +52,7 @@ org.springframework.cloud spring-cloud-starter-gateway - 3.1.4 + 3.1.6 diff --git a/frontend/components.d.ts b/frontend/components.d.ts index 7de2b61..ff12975 100644 --- a/frontend/components.d.ts +++ b/frontend/components.d.ts @@ -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'] diff --git a/frontend/src/api/shop-cate.js b/frontend/src/api/shop-cate.js new file mode 100644 index 0000000..e9b4075 --- /dev/null +++ b/frontend/src/api/shop-cate.js @@ -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, + }); +}; diff --git a/frontend/src/components/header.vue b/frontend/src/components/header.vue index 27d861f..781522a 100644 --- a/frontend/src/components/header.vue +++ b/frontend/src/components/header.vue @@ -31,9 +31,6 @@