Jelajahi Sumber

重构商品单位

tsurumure 1 bulan lalu
induk
melakukan
4c08538fa8

+ 0 - 0
db/b2c_goods_unit.sql → db/__b2c_goods_unit.sql


+ 73 - 0
db/b2c_good_unit.sql

@@ -0,0 +1,73 @@
+/**
+Source Server Version: 8.0.31
+Source Database: backendsys
+Date: 2023/08/18 12:51:10
+*/
+
+DROP TABLE IF EXISTS `b2c_good_unit`;
+CREATE TABLE `b2c_good_unit` (
+   PRIMARY KEY (`id`),
+   `id` BIGINT AUTO_INCREMENT COMMENT 'ID',
+   `unit_category` VARCHAR(255) NOT NULL COMMENT '商品单位分类',
+   `unit_name` VARCHAR(255) NOT NULL COMMENT '商品单位名称',
+   `unit_name_en` VARCHAR(255) NOT NULL COMMENT '商品单位名称',
+   `sort` INT DEFAULT '1' COMMENT '排序'
+) ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='商品单位表';
+
+INSERT INTO b2c_good_unit (id, unit_category, unit_name, unit_name_en, sort) VALUES
+    -- 基础单位
+    (1, 'general', '件', 'piece', 1),
+    (2, 'general', '个', 'unit', 2),
+    (3, 'general', '只', 'each', 3),
+
+    -- 包装类
+    (4, 'packaging', '箱', 'carton', 10),
+    (5, 'packaging', '盒', 'box', 11),
+    (6, 'packaging', '包', 'pack', 12),
+    (7, 'packaging', '袋', 'bag', 13),
+    (8, 'packaging', '罐', 'can', 14),
+    (9, 'packaging', '桶', 'bucket', 15),
+    (10, 'packaging', '筐', 'basket', 16),
+
+    -- 液体/容器
+    (11, 'liquid', '瓶', 'bottle', 20),
+    (12, 'liquid', '杯', 'cup', 21),
+    (13, 'liquid', '升', 'liter', 22),
+    (14, 'liquid', '毫升', 'ml', 23),
+
+    -- 成套商品
+    (15, 'set', '套', 'set', 30),
+    (16, 'set', '对', 'pair', 31),
+    (17, 'set', '打', 'dozen', 32),
+    (18, 'set', '组', 'kit', 33),
+
+    -- 服装/穿戴
+    (19, 'clothing', '条', 'piece', 40),  -- 如裤子
+    (20, 'clothing', '件', 'piece', 41),  -- 如上衣
+    (21, 'clothing', '双', 'pair', 42),  -- 鞋袜
+    (22, 'clothing', '顶', 'piece', 43),  -- 帽子
+
+    -- 电子/设备
+    (23, 'electronics', '台', 'unit', 50),
+    (24, 'electronics', '部', 'unit', 51),  -- 手机等
+    (25, 'electronics', '张', 'card', 52),  -- 如SIM卡
+
+    -- 食品类
+    (26, 'food', '克', 'gram', 60),
+    (27, 'food', '千克', 'kg', 61),
+    (28, 'food', '磅', 'lb', 62),
+    (29, 'food', '盎司', 'oz', 63),
+
+    -- 建材/五金
+    (30, 'construction', '米', 'meter', 70),
+    (31, 'construction', '卷', 'roll', 71),
+    (32, 'construction', '片', 'sheet', 72),
+    (33, 'construction', '块', 'block', 73),
+
+    -- 其他
+    (34, 'other', '本', 'book', 80),
+    (35, 'other', '张', 'sheet', 81),  -- 如纸张
+    (36, 'other', '支', 'stick', 82),  -- 如笔
+    (37, 'other', '辆', 'unit', 83),  -- 车辆
+    (38, 'other', '头', 'head', 84)  -- 牲畜
+;

+ 10 - 10
db/sys_user_role_permission.sql

@@ -157,16 +157,16 @@ INSERT INTO sys_user_role_permission(id, parent_id, permission_name, sort) VALUE
             ('11.2.2', '11.2', '创建商品分类', null),
             ('11.2.3', '11.2', '编辑商品分类', null),
             ('11.2.4', '11.2', '删除商品分类', null),
-        ('11.3', '11', '商品品牌列表', null),
-            ('11.3.1', '11.3', '商品品牌详情', null),
-            ('11.3.2', '11.3', '创建商品品牌', null),
-            ('11.3.3', '11.3', '编辑商品品牌', null),
-            ('11.3.4', '11.3', '删除商品品牌', null),
-        ('11.4', '11', '商品单位列表', null),
-            ('11.4.1', '11.4', '商品单位详情', null),
-            ('11.4.2', '11.4', '创建商品单位', null),
-            ('11.4.3', '11.4', '编辑商品单位', null),
-            ('11.4.4', '11.4', '删除商品单位', null),
+#         ('11.3', '11', '商品品牌列表', null),
+#             ('11.3.1', '11.3', '商品品牌详情', null),
+#             ('11.3.2', '11.3', '创建商品品牌', null),
+#             ('11.3.3', '11.3', '编辑商品品牌', null),
+#             ('11.3.4', '11.3', '删除商品品牌', null),
+#         ('11.4', '11', '商品单位列表', null),
+#             ('11.4.1', '11.4', '商品单位详情', null),
+#             ('11.4.2', '11.4', '创建商品单位', null),
+#             ('11.4.3', '11.4', '编辑商品单位', null),
+#             ('11.4.4', '11.4', '删除商品单位', null),
         ('11.5', '11', '商品规格列表', null),
             ('11.5.1', '11.5', '商品规格详情', null),
             ('11.5.2', '11.5', '创建商品规格', null),

+ 56 - 56
src/main/java/com/backendsys/controller/B2c/B2cGoodUnitController.java

@@ -1,56 +1,56 @@
-package com.backendsys.controller.B2c;
-
-import com.backendsys.aspect.QueryNullCheck;
-import com.backendsys.aspect.QueryNullCheckAspect;
-import com.backendsys.entity.B2c.B2cGoodUnitDTO;
-import com.backendsys.entity.PageDTO;
-import com.backendsys.service.B2c.B2cGoodUnitService;
-import com.backendsys.utils.response.Result;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.*;
-
-/**
- * 商品单位
- */
-@Validated
-@RestController
-public class B2cGoodUnitController {
-
-    @Autowired
-    private B2cGoodUnitService b2cGoodUnitService;
-
-    @PreAuthorize("@sr.hasPermission('11.4')")
-    @GetMapping("/api/b2c/good/getGoodUnit")
-    public Result getGoodUnit(@Validated PageDTO pageDTO, @Validated B2cGoodUnitDTO b2cGoodUnitDTO) {
-        return Result.success(b2cGoodUnitService.queryGoodUnitList(pageDTO.getPage_num(), pageDTO.getPage_size(), b2cGoodUnitDTO));
-    }
-
-    @PreAuthorize("@sr.hasPermission('11.4.1')")
-    @QueryNullCheck(serviceClass = B2cGoodUnitService.class, serviceMethod = "queryGoodUnitDetail", argField = "good_unit_id", message = "商品单位不存在")
-    @GetMapping("/api/b2c/good/getGoodUnitDetail")
-    public Result getGoodUnitDetail(@Validated(B2cGoodUnitDTO.Detail.class) B2cGoodUnitDTO b2cGoodUnitDTO) {
-        return Result.success(QueryNullCheckAspect.getQueryResult());
-    }
-
-    @PreAuthorize("@sr.hasPermission('11.4.2')")
-    @PostMapping("/api/b2c/good/createGoodUnit")
-    public Result createGoodUnit(@Validated(B2cGoodUnitDTO.Create.class) @RequestBody B2cGoodUnitDTO b2cGoodUnitDTO) {
-        return Result.success(b2cGoodUnitService.insertGoodUnit(b2cGoodUnitDTO), "创建成功");
-    }
-
-    @PreAuthorize("@sr.hasPermission('11.4.3')")
-    @QueryNullCheck(serviceClass = B2cGoodUnitService.class, serviceMethod = "queryGoodUnitDetail", argField = "good_unit_id", message = "商品单位不存在")
-    @PutMapping("/api/b2c/good/updateGoodUnit")
-    public Result updateGoodUnit(@Validated(B2cGoodUnitDTO.Update.class) @RequestBody B2cGoodUnitDTO b2cGoodUnitDTO) {
-        return Result.success(b2cGoodUnitService.updateGoodUnit(b2cGoodUnitDTO), "更新成功");
-    }
-
-    @PreAuthorize("@sr.hasPermission('11.4.4')")
-    @QueryNullCheck(serviceClass = B2cGoodUnitService.class, serviceMethod = "queryGoodUnitDetail", argField = "good_unit_id", message = "商品单位不存在")
-    @DeleteMapping("/api/b2c/good/deleteGoodUnit")
-    public Result deleteGoodUnit(@Validated(B2cGoodUnitDTO.Delete.class) @RequestBody B2cGoodUnitDTO b2cGoodUnitDTO) {
-        return Result.success(b2cGoodUnitService.deleteGoodUnit(b2cGoodUnitDTO), "删除成功");
-    }
-}
+//package com.backendsys.controller.B2c;
+//
+//import com.backendsys.aspect.QueryNullCheck;
+//import com.backendsys.aspect.QueryNullCheckAspect;
+//import com.backendsys.entity.B2c.B2cGoodUnitDTO;
+//import com.backendsys.entity.PageDTO;
+//import com.backendsys.service.B2c.B2cGoodUnitService;
+//import com.backendsys.utils.response.Result;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.security.access.prepost.PreAuthorize;
+//import org.springframework.validation.annotation.Validated;
+//import org.springframework.web.bind.annotation.*;
+//
+///**
+// * 商品单位
+// */
+//@Validated
+//@RestController
+//public class B2cGoodUnitController {
+//
+//    @Autowired
+//    private B2cGoodUnitService b2cGoodUnitService;
+//
+//    @PreAuthorize("@sr.hasPermission('11.4')")
+//    @GetMapping("/api/b2c/good/getGoodUnit")
+//    public Result getGoodUnit(@Validated PageDTO pageDTO, @Validated B2cGoodUnitDTO b2cGoodUnitDTO) {
+//        return Result.success(b2cGoodUnitService.queryGoodUnitList(pageDTO.getPage_num(), pageDTO.getPage_size(), b2cGoodUnitDTO));
+//    }
+//
+//    @PreAuthorize("@sr.hasPermission('11.4.1')")
+//    @QueryNullCheck(serviceClass = B2cGoodUnitService.class, serviceMethod = "queryGoodUnitDetail", argField = "good_unit_id", message = "商品单位不存在")
+//    @GetMapping("/api/b2c/good/getGoodUnitDetail")
+//    public Result getGoodUnitDetail(@Validated(B2cGoodUnitDTO.Detail.class) B2cGoodUnitDTO b2cGoodUnitDTO) {
+//        return Result.success(QueryNullCheckAspect.getQueryResult());
+//    }
+//
+//    @PreAuthorize("@sr.hasPermission('11.4.2')")
+//    @PostMapping("/api/b2c/good/createGoodUnit")
+//    public Result createGoodUnit(@Validated(B2cGoodUnitDTO.Create.class) @RequestBody B2cGoodUnitDTO b2cGoodUnitDTO) {
+//        return Result.success(b2cGoodUnitService.insertGoodUnit(b2cGoodUnitDTO), "创建成功");
+//    }
+//
+//    @PreAuthorize("@sr.hasPermission('11.4.3')")
+//    @QueryNullCheck(serviceClass = B2cGoodUnitService.class, serviceMethod = "queryGoodUnitDetail", argField = "good_unit_id", message = "商品单位不存在")
+//    @PutMapping("/api/b2c/good/updateGoodUnit")
+//    public Result updateGoodUnit(@Validated(B2cGoodUnitDTO.Update.class) @RequestBody B2cGoodUnitDTO b2cGoodUnitDTO) {
+//        return Result.success(b2cGoodUnitService.updateGoodUnit(b2cGoodUnitDTO), "更新成功");
+//    }
+//
+//    @PreAuthorize("@sr.hasPermission('11.4.4')")
+//    @QueryNullCheck(serviceClass = B2cGoodUnitService.class, serviceMethod = "queryGoodUnitDetail", argField = "good_unit_id", message = "商品单位不存在")
+//    @DeleteMapping("/api/b2c/good/deleteGoodUnit")
+//    public Result deleteGoodUnit(@Validated(B2cGoodUnitDTO.Delete.class) @RequestBody B2cGoodUnitDTO b2cGoodUnitDTO) {
+//        return Result.success(b2cGoodUnitService.deleteGoodUnit(b2cGoodUnitDTO), "删除成功");
+//    }
+//}

+ 30 - 30
src/main/java/com/backendsys/entity/B2c/B2cGoodUnitDTO.java

@@ -1,30 +1,30 @@
-package com.backendsys.entity.B2c;
-
-import jakarta.validation.constraints.NotBlank;
-import jakarta.validation.constraints.NotNull;
-import jakarta.validation.constraints.Size;
-import lombok.Data;
-import org.hibernate.validator.constraints.Range;
-
-@Data
-public class B2cGoodUnitDTO {
-    public static interface Detail{}
-    public static interface Create{}
-    public static interface Update{}
-    public static interface Delete{}
-
-    /**
-     * b2c_goods_unit
-     */
-    private Long id;
-    @NotNull(message = "商品单位ID不能为空", groups = { B2cGoodUnitDTO.Detail.class, B2cGoodUnitDTO.Update.class, B2cGoodUnitDTO.Delete.class })
-    private Long good_unit_id;
-
-    @Size(max = 50, message = "商品单位名称长度不超过 {max} 个字符", groups = { B2cGoodUnitDTO.Create.class, B2cGoodUnitDTO.Update.class })
-    @NotBlank(message = "商品单位名称不能为空", groups = { B2cGoodUnitDTO.Create.class, B2cGoodUnitDTO.Update.class })
-    private String unit_name;
-
-    @Range(min = 1, max = 9999, message = "排序必须在 {min} 到 {max} 之间")
-    private Integer sort;
-
-}
+//package com.backendsys.entity.B2c;
+//
+//import jakarta.validation.constraints.NotBlank;
+//import jakarta.validation.constraints.NotNull;
+//import jakarta.validation.constraints.Size;
+//import lombok.Data;
+//import org.hibernate.validator.constraints.Range;
+//
+//@Data
+//public class B2cGoodUnitDTO {
+//    public static interface Detail{}
+//    public static interface Create{}
+//    public static interface Update{}
+//    public static interface Delete{}
+//
+//    /**
+//     * b2c_goods_unit
+//     */
+//    private Long id;
+//    @NotNull(message = "商品单位ID不能为空", groups = { B2cGoodUnitDTO.Detail.class, B2cGoodUnitDTO.Update.class, B2cGoodUnitDTO.Delete.class })
+//    private Long good_unit_id;
+//
+//    @Size(max = 50, message = "商品单位名称长度不超过 {max} 个字符", groups = { B2cGoodUnitDTO.Create.class, B2cGoodUnitDTO.Update.class })
+//    @NotBlank(message = "商品单位名称不能为空", groups = { B2cGoodUnitDTO.Create.class, B2cGoodUnitDTO.Update.class })
+//    private String unit_name;
+//
+//    @Range(min = 1, max = 9999, message = "排序必须在 {min} 到 {max} 之间")
+//    private Integer sort;
+//
+//}

+ 16 - 16
src/main/java/com/backendsys/mapper/B2c/B2cGoodUnitMapper.java

@@ -1,16 +1,16 @@
-package com.backendsys.mapper.B2c;
-
-import com.backendsys.entity.B2c.B2cGoodUnitDTO;
-import org.apache.ibatis.annotations.Mapper;
-
-import java.util.List;
-import java.util.Map;
-
-@Mapper
-public interface B2cGoodUnitMapper {
-    List<Map<String, Object>> queryGoodUnitList(B2cGoodUnitDTO b2cGoodUnitDTO);
-    Map<String, Object> queryGoodUnitDetail(Long good_id);
-    long insertGoodUnit(B2cGoodUnitDTO b2cGoodUnitDTO);
-    long deleteGoodUnit(B2cGoodUnitDTO b2cGoodUnitDTO);
-    long updateGoodUnit(B2cGoodUnitDTO b2cGoodUnitDTO);
-}
+//package com.backendsys.mapper.B2c;
+//
+//import com.backendsys.entity.B2c.B2cGoodUnitDTO;
+//import org.apache.ibatis.annotations.Mapper;
+//
+//import java.util.List;
+//import java.util.Map;
+//
+//@Mapper
+//public interface B2cGoodUnitMapper {
+//    List<Map<String, Object>> queryGoodUnitList(B2cGoodUnitDTO b2cGoodUnitDTO);
+//    Map<String, Object> queryGoodUnitDetail(Long good_id);
+//    long insertGoodUnit(B2cGoodUnitDTO b2cGoodUnitDTO);
+//    long deleteGoodUnit(B2cGoodUnitDTO b2cGoodUnitDTO);
+//    long updateGoodUnit(B2cGoodUnitDTO b2cGoodUnitDTO);
+//}

+ 52 - 52
src/main/java/com/backendsys/mapper/B2c/B2cGoodUnitMapper.xml

@@ -1,59 +1,59 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
-<mapper namespace="com.backendsys.mapper.B2c.B2cGoodUnitMapper">
+<!--<?xml version="1.0" encoding="utf-8" ?>-->
+<!--<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >-->
+<!--<mapper namespace="com.backendsys.mapper.B2c.B2cGoodUnitMapper">-->
 
-    <sql id="includeGoodsUnit">
-        id,
-        id good_unit_id,
-        unit_name,
-        sort
-    </sql>
-    <resultMap id="resultMapGoodsUnit" type="java.util.LinkedHashMap">
-        <id property="id" column="id" jdbcType="BIGINT" />
-        <result property="good_unit_id" column="good_unit_id" javaType="java.lang.Long"/>
-        <result property="unit_name" column="unit_name" />
-        <result property="sort" column="sort" javaType="java.lang.Integer" />
-    </resultMap>
+<!--    <sql id="includeGoodsUnit">-->
+<!--        id,-->
+<!--        id good_unit_id,-->
+<!--        unit_name,-->
+<!--        sort-->
+<!--    </sql>-->
+<!--    <resultMap id="resultMapGoodsUnit" type="java.util.LinkedHashMap">-->
+<!--        <id property="id" column="id" jdbcType="BIGINT" />-->
+<!--        <result property="good_unit_id" column="good_unit_id" javaType="java.lang.Long"/>-->
+<!--        <result property="unit_name" column="unit_name" />-->
+<!--        <result property="sort" column="sort" javaType="java.lang.Integer" />-->
+<!--    </resultMap>-->
 
-    <select id="queryGoodUnitList" resultMap="resultMapGoodsUnit">
-        SELECT
-        <include refid="includeGoodsUnit" />
-        FROM b2c_goods_unit
-        <where>
-            <if test="unit_name != null and unit_name != ''">
-                AND unit_name LIKE CONCAT('%', #{unit_name}, '%')
-            </if>
-        </where>
-        ORDER BY sort DESC
-    </select>
+<!--    <select id="queryGoodUnitList" resultMap="resultMapGoodsUnit">-->
+<!--        SELECT-->
+<!--        <include refid="includeGoodsUnit" />-->
+<!--        FROM b2c_goods_unit-->
+<!--        <where>-->
+<!--            <if test="unit_name != null and unit_name != ''">-->
+<!--                AND unit_name LIKE CONCAT('%', #{unit_name}, '%')-->
+<!--            </if>-->
+<!--        </where>-->
+<!--        ORDER BY sort DESC-->
+<!--    </select>-->
 
-    <select id="queryGoodUnitDetail" resultMap="resultMapGoodsUnit">
-        SELECT
-        <include refid="includeGoodsUnit" />
-        FROM b2c_goods_unit
-        WHERE id = #{good_unit_id}
-    </select>
+<!--    <select id="queryGoodUnitDetail" resultMap="resultMapGoodsUnit">-->
+<!--        SELECT-->
+<!--        <include refid="includeGoodsUnit" />-->
+<!--        FROM b2c_goods_unit-->
+<!--        WHERE id = #{good_unit_id}-->
+<!--    </select>-->
 
-    <insert id="insertGoodUnit" parameterType="com.backendsys.entity.B2c.B2cGoodUnitDTO"
-        useGeneratedKeys="true" keyProperty="good_unit_id">
-        INSERT INTO b2c_goods_unit (unit_name
-        <if test="sort != null and sort != ''">, sort</if>
-        )
-        VALUES (#{unit_name}
-        <if test="sort != null and sort != ''">, #{sort}</if>
-        )
-    </insert>
+<!--    <insert id="insertGoodUnit" parameterType="com.backendsys.entity.B2c.B2cGoodUnitDTO"-->
+<!--        useGeneratedKeys="true" keyProperty="good_unit_id">-->
+<!--        INSERT INTO b2c_goods_unit (unit_name-->
+<!--        <if test="sort != null and sort != ''">, sort</if>-->
+<!--        )-->
+<!--        VALUES (#{unit_name}-->
+<!--        <if test="sort != null and sort != ''">, #{sort}</if>-->
+<!--        )-->
+<!--    </insert>-->
 
-    <update id="updateGoodUnit" parameterType="com.backendsys.entity.B2c.B2cGoodUnitDTO"
-        useGeneratedKeys="true" keyProperty="good_unit_id">
-        UPDATE b2c_goods_unit
-        SET unit_name = #{unit_name}
-            <if test="sort != null and sort != ''">, sort = #{sort}</if>
-        WHERE id = #{good_unit_id}
-    </update>
+<!--    <update id="updateGoodUnit" parameterType="com.backendsys.entity.B2c.B2cGoodUnitDTO"-->
+<!--        useGeneratedKeys="true" keyProperty="good_unit_id">-->
+<!--        UPDATE b2c_goods_unit-->
+<!--        SET unit_name = #{unit_name}-->
+<!--            <if test="sort != null and sort != ''">, sort = #{sort}</if>-->
+<!--        WHERE id = #{good_unit_id}-->
+<!--    </update>-->
 
-    <delete id="deleteGoodUnit">
-        DELETE FROM b2c_goods_unit WHERE id = #{good_unit_id}
-    </delete>
+<!--    <delete id="deleteGoodUnit">-->
+<!--        DELETE FROM b2c_goods_unit WHERE id = #{good_unit_id}-->
+<!--    </delete>-->
 
-</mapper>
+<!--</mapper>-->

+ 28 - 0
src/main/java/com/backendsys/modules/b2c/good/controller/GoodUnitController.java

@@ -0,0 +1,28 @@
+package com.backendsys.modules.b2c.good.controller;
+
+import com.backendsys.modules.b2c.good.service.GoodUnitService;
+import com.backendsys.modules.common.config.security.annotations.Anonymous;
+import com.backendsys.modules.common.utils.Result;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Validated
+@RestController
+@Tag(name = "商品单位管理")
+public class GoodUnitController {
+
+    @Autowired
+    private GoodUnitService goodUnitService;
+
+    @Anonymous
+    @Operation(summary = "获取商品单位列表")
+    @GetMapping("/api/b2c/good/getGoodUnitList")
+    public Result getGood(String unit_category) {
+        return Result.success().put("data", goodUnitService.selectGoodUnit(unit_category));
+    }
+
+}

+ 9 - 0
src/main/java/com/backendsys/modules/b2c/good/dao/GoodUnitDao.java

@@ -0,0 +1,9 @@
+package com.backendsys.modules.b2c.good.dao;
+
+import com.backendsys.modules.b2c.good.entity.GoodUnit;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface GoodUnitDao extends BaseMapper<GoodUnit> {
+}

+ 19 - 0
src/main/java/com/backendsys/modules/b2c/good/entity/GoodUnit.java

@@ -0,0 +1,19 @@
+package com.backendsys.modules.b2c.good.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+@Data
+@TableName("b2c_good_unit")
+public class GoodUnit {
+
+    @TableId(type = IdType.AUTO)
+    private Long id;
+    private String unit_category;
+    private String unit_name;
+    private String unit_name_en;
+    private Integer sort;
+
+}

+ 12 - 0
src/main/java/com/backendsys/modules/b2c/good/service/GoodUnitService.java

@@ -0,0 +1,12 @@
+package com.backendsys.modules.b2c.good.service;
+
+import com.backendsys.modules.b2c.good.entity.GoodUnit;
+
+import java.util.List;
+
+public interface GoodUnitService {
+
+    // 获取商品单位
+    List<GoodUnit> selectGoodUnit(String unit_category);
+
+}

+ 41 - 0
src/main/java/com/backendsys/modules/b2c/good/service/impl/GoodUnitServiceImpl.java

@@ -0,0 +1,41 @@
+package com.backendsys.modules.b2c.good.service.impl;
+
+import cn.hutool.core.util.StrUtil;
+import com.backendsys.modules.b2c.good.dao.GoodUnitDao;
+import com.backendsys.modules.b2c.good.entity.GoodUnit;
+import com.backendsys.modules.b2c.good.service.GoodUnitService;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class GoodUnitServiceImpl implements GoodUnitService {
+
+    @Autowired
+    private GoodUnitDao goodUnitDao;
+
+    /**
+     * 获取商品单位
+     *   分类:
+     *   - 基础单位: general
+     *   - 包装类: packaging
+     *   - 液体容器: liquid
+     *   - 成套商品: set
+     *   - 服装穿戴: clothing
+     *   - 电子设备: electronics
+     *   - 食品计量: food
+     *   - 建材五金: construction
+     *   - 其他单位: other
+     */
+    @Override
+    public List<GoodUnit> selectGoodUnit(String unit_category) {
+        LambdaQueryWrapper<GoodUnit> wrapper = new LambdaQueryWrapper<>();
+        if (StrUtil.isNotEmpty(unit_category)) {
+            wrapper.eq(GoodUnit::getUnit_category, unit_category);
+        }
+        return goodUnitDao.selectList(wrapper);
+    }
+
+}

+ 5 - 9
src/main/java/com/backendsys/modules/sdk/tencentcloud/ems/controller/TencentEmsController.java

@@ -1,19 +1,14 @@
 package com.backendsys.modules.sdk.tencentcloud.ems.controller;
 
-import cn.hutool.json.JSONObject;
 import com.backendsys.modules.common.config.security.annotations.Anonymous;
-import com.backendsys.modules.common.config.security.utils.HttpRequestUtil;
 import com.backendsys.modules.common.utils.Result;
-import com.backendsys.modules.sdk.tencentcloud.ems.entity.TencentEmsCallback;
 import com.backendsys.modules.sdk.tencentcloud.ems.entity.TencentEmsCallbackParams;
 import com.backendsys.modules.sdk.tencentcloud.ems.service.TencentEmsService;
 import com.backendsys.modules.sdk.tencentcloud.ems.service.TencentEmsCallbackService;
-import com.tencentcloudapi.common.exception.TencentCloudSDKException;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
-import jakarta.servlet.http.HttpServletRequest;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RestController;
@@ -25,8 +20,9 @@ import java.util.Map;
 @Tag(name = "腾讯云-邮件回调")
 public class TencentEmsController {
 
-    @Autowired
-    private TencentEmsService tencentEmsService;
+//    @Autowired
+//    private TencentEmsService tencentEmsService;
+
     @Autowired
     private TencentEmsCallbackService tencentEmsCallbackService;
 
@@ -45,7 +41,7 @@ public class TencentEmsController {
     @Anonymous
     @Operation(summary = "邮件推送通知事件回调")
     @PostMapping("/api/ems/callback")
-    public Result receiveCallback(@RequestBody TencentEmsCallbackParams tencentEmsCallbackParams) {
+    public Result receiveCallback(@Validated(TencentEmsCallbackParams.Callback.class) @RequestBody TencentEmsCallbackParams tencentEmsCallbackParams) {
         //System.out.println("===============================");
         //System.out.println("邮件推送通知事件回调");
         //System.out.println("body 参数: " + tencentEmsCallbackParams);

+ 5 - 0
src/main/java/com/backendsys/modules/sdk/tencentcloud/ems/entity/TencentEmsCallbackParams.java

@@ -1,10 +1,15 @@
 package com.backendsys.modules.sdk.tencentcloud.ems.entity;
 
+import jakarta.validation.constraints.NotEmpty;
 import lombok.Data;
 
 @Data
 public class TencentEmsCallbackParams {
+
+    public static interface Callback {}
+
     private String event;
+    @NotEmpty(message = "邮件地址不能为空", groups = { Callback.class })
     private String email;
     private String bulkId;
     private Long timestamp;

+ 16 - 35
src/main/java/com/backendsys/modules/sdk/tencentcloud/ems/service/impl/TencentEmsCallbackServiceImpl.java

@@ -17,40 +17,21 @@ public class TencentEmsCallbackServiceImpl implements TencentEmsCallbackService
 
     @Override
     public void receiveCallback(TencentEmsCallbackParams tencentEmsCallbackParams) {
-        String messageId = tencentEmsCallbackParams.getMessageId();
-        try {
-
-            // 判断邮箱地址非空
-            String email = tencentEmsCallbackParams.getEmail();
-            if (!StrUtil.isBlank(email) && Validator.isEmail(email)) {
-
-                // 这里可能需要做更多的条件判断?
-
-                // 构建实体
-                TencentEmsCallback entity = new TencentEmsCallback();
-                entity.setEvent(tencentEmsCallbackParams.getEvent());
-                entity.setEmail(email);
-                entity.setBulk_id(tencentEmsCallbackParams.getBulkId());
-                entity.setTimestamp(tencentEmsCallbackParams.getTimestamp());
-                entity.setReason(tencentEmsCallbackParams.getReason());
-                entity.setBounce_type(tencentEmsCallbackParams.getBounceType());
-                entity.setUsername(tencentEmsCallbackParams.getUsername());
-                entity.setSender(tencentEmsCallbackParams.getFrom());
-                entity.setFrom_domain(tencentEmsCallbackParams.getFromDomain());
-                entity.setTemplate_id(tencentEmsCallbackParams.getTemplateId());
-                entity.setSubject(tencentEmsCallbackParams.getSubject());
-                entity.setMessage_id(messageId);
-                // 保存记录
-                tencentEmsCallbackDao.insert(entity);
-                System.out.println("邮件推送回调成功 From: " + email);
-
-            }
-
-        } catch (DuplicateKeyException e) {
-            // 数据库唯一索引冲突兜底幂等
-            System.out.println("重复插入数据:" + messageId);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+        // 构建实体
+        TencentEmsCallback entity = new TencentEmsCallback();
+        entity.setEvent(tencentEmsCallbackParams.getEvent());
+        entity.setEmail(tencentEmsCallbackParams.getEmail());
+        entity.setBulk_id(tencentEmsCallbackParams.getBulkId());
+        entity.setTimestamp(tencentEmsCallbackParams.getTimestamp());
+        entity.setReason(tencentEmsCallbackParams.getReason());
+        entity.setBounce_type(tencentEmsCallbackParams.getBounceType());
+        entity.setUsername(tencentEmsCallbackParams.getUsername());
+        entity.setSender(tencentEmsCallbackParams.getFrom());
+        entity.setFrom_domain(tencentEmsCallbackParams.getFromDomain());
+        entity.setTemplate_id(tencentEmsCallbackParams.getTemplateId());
+        entity.setSubject(tencentEmsCallbackParams.getSubject());
+        entity.setMessage_id(tencentEmsCallbackParams.getMessageId());
+        // 保存记录
+        tencentEmsCallbackDao.insert(entity);
     }
 }

+ 13 - 13
src/main/java/com/backendsys/service/B2c/B2cGoodUnitService.java

@@ -1,13 +1,13 @@
-package com.backendsys.service.B2c;
-
-import com.backendsys.entity.B2c.B2cGoodUnitDTO;
-
-import java.util.Map;
-
-public interface B2cGoodUnitService {
-    Map<String, Object> queryGoodUnitList(Integer pageNum, Integer pageSize, B2cGoodUnitDTO b2cGoodUnitDTO);
-    Map<String, Object> queryGoodUnitDetail(Long good_id);
-    Map<String, Object> insertGoodUnit(B2cGoodUnitDTO b2cGoodUnitDTO);
-    Map<String, Object> updateGoodUnit(B2cGoodUnitDTO b2cGoodUnitDTO);
-    Map<String, Object> deleteGoodUnit(B2cGoodUnitDTO b2cGoodUnitDTO);
-}
+//package com.backendsys.service.B2c;
+//
+//import com.backendsys.entity.B2c.B2cGoodUnitDTO;
+//
+//import java.util.Map;
+//
+//public interface B2cGoodUnitService {
+//    Map<String, Object> queryGoodUnitList(Integer pageNum, Integer pageSize, B2cGoodUnitDTO b2cGoodUnitDTO);
+//    Map<String, Object> queryGoodUnitDetail(Long good_id);
+//    Map<String, Object> insertGoodUnit(B2cGoodUnitDTO b2cGoodUnitDTO);
+//    Map<String, Object> updateGoodUnit(B2cGoodUnitDTO b2cGoodUnitDTO);
+//    Map<String, Object> deleteGoodUnit(B2cGoodUnitDTO b2cGoodUnitDTO);
+//}

+ 72 - 72
src/main/java/com/backendsys/service/B2c/B2cGoodUnitServiceImpl.java

@@ -1,72 +1,72 @@
-package com.backendsys.service.B2c;
-
-import com.backendsys.entity.B2c.B2cGoodUnitDTO;
-import com.backendsys.mapper.B2c.B2cGoodUnitMapper;
-import com.backendsys.utils.response.PageInfoResult;
-import com.github.pagehelper.PageHelper;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.List;
-import java.util.Map;
-
-@Service
-public class B2cGoodUnitServiceImpl implements B2cGoodUnitService {
-
-    @Autowired
-    private B2cGoodUnitMapper b2cGoodUnitMapper;
-
-    /**
-     * 查询 列表
-     */
-    public Map<String, Object> queryGoodUnitList(Integer pageNum, Integer pageSize, B2cGoodUnitDTO b2cGoodUnitDTO) {
-        // 分页查询
-        if (pageNum != null && pageSize != null) {
-            PageHelper.startPage(pageNum, pageSize);
-            PageHelper.getLocalPage().setPageSizeZero(true);
-        }
-        // 分页输出 (自定义)
-        List<Map<String, Object>> list = b2cGoodUnitMapper.queryGoodUnitList(b2cGoodUnitDTO);
-        PageInfoResult pageInfoResult = new PageInfoResult(list);
-        return pageInfoResult.toMap();
-    }
-
-    /**
-     * 查询 详情
-     */
-    @Override
-    public Map<String, Object> queryGoodUnitDetail(Long good_unit_id) {
-        return b2cGoodUnitMapper.queryGoodUnitDetail(good_unit_id);
-    }
-
-    /**
-     * 创建
-     */
-    @Override
-    @Transactional(rollbackFor = Exception.class)
-    public Map<String, Object> insertGoodUnit(B2cGoodUnitDTO b2cGoodUnitDTO) {
-        b2cGoodUnitMapper.insertGoodUnit(b2cGoodUnitDTO);
-        return Map.of("good_unit_id", b2cGoodUnitDTO.getGood_unit_id());
-    }
-
-    /**
-     * 更新
-     */
-    @Override
-    @Transactional(rollbackFor = Exception.class)
-    public Map<String, Object> updateGoodUnit(B2cGoodUnitDTO b2cGoodUnitDTO) {
-        b2cGoodUnitMapper.updateGoodUnit(b2cGoodUnitDTO);
-        return Map.of("good_unit_id", b2cGoodUnitDTO.getGood_unit_id());
-    }
-
-    /**
-     * 删除
-     */
-    @Override
-    @Transactional(rollbackFor = Exception.class)
-    public Map<String, Object> deleteGoodUnit(B2cGoodUnitDTO b2cGoodUnitDTO) {
-        b2cGoodUnitMapper.deleteGoodUnit(b2cGoodUnitDTO);
-        return Map.of("good_unit_id", b2cGoodUnitDTO.getGood_unit_id());
-    }
-}
+//package com.backendsys.service.B2c;
+//
+//import com.backendsys.entity.B2c.B2cGoodUnitDTO;
+//import com.backendsys.mapper.B2c.B2cGoodUnitMapper;
+//import com.backendsys.utils.response.PageInfoResult;
+//import com.github.pagehelper.PageHelper;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.stereotype.Service;
+//import org.springframework.transaction.annotation.Transactional;
+//
+//import java.util.List;
+//import java.util.Map;
+//
+//@Service
+//public class B2cGoodUnitServiceImpl implements B2cGoodUnitService {
+//
+//    @Autowired
+//    private B2cGoodUnitMapper b2cGoodUnitMapper;
+//
+//    /**
+//     * 查询 列表
+//     */
+//    public Map<String, Object> queryGoodUnitList(Integer pageNum, Integer pageSize, B2cGoodUnitDTO b2cGoodUnitDTO) {
+//        // 分页查询
+//        if (pageNum != null && pageSize != null) {
+//            PageHelper.startPage(pageNum, pageSize);
+//            PageHelper.getLocalPage().setPageSizeZero(true);
+//        }
+//        // 分页输出 (自定义)
+//        List<Map<String, Object>> list = b2cGoodUnitMapper.queryGoodUnitList(b2cGoodUnitDTO);
+//        PageInfoResult pageInfoResult = new PageInfoResult(list);
+//        return pageInfoResult.toMap();
+//    }
+//
+//    /**
+//     * 查询 详情
+//     */
+//    @Override
+//    public Map<String, Object> queryGoodUnitDetail(Long good_unit_id) {
+//        return b2cGoodUnitMapper.queryGoodUnitDetail(good_unit_id);
+//    }
+//
+//    /**
+//     * 创建
+//     */
+//    @Override
+//    @Transactional(rollbackFor = Exception.class)
+//    public Map<String, Object> insertGoodUnit(B2cGoodUnitDTO b2cGoodUnitDTO) {
+//        b2cGoodUnitMapper.insertGoodUnit(b2cGoodUnitDTO);
+//        return Map.of("good_unit_id", b2cGoodUnitDTO.getGood_unit_id());
+//    }
+//
+//    /**
+//     * 更新
+//     */
+//    @Override
+//    @Transactional(rollbackFor = Exception.class)
+//    public Map<String, Object> updateGoodUnit(B2cGoodUnitDTO b2cGoodUnitDTO) {
+//        b2cGoodUnitMapper.updateGoodUnit(b2cGoodUnitDTO);
+//        return Map.of("good_unit_id", b2cGoodUnitDTO.getGood_unit_id());
+//    }
+//
+//    /**
+//     * 删除
+//     */
+//    @Override
+//    @Transactional(rollbackFor = Exception.class)
+//    public Map<String, Object> deleteGoodUnit(B2cGoodUnitDTO b2cGoodUnitDTO) {
+//        b2cGoodUnitMapper.deleteGoodUnit(b2cGoodUnitDTO);
+//        return Map.of("good_unit_id", b2cGoodUnitDTO.getGood_unit_id());
+//    }
+//}