12
0

2 Commitit 43911282ef ... 999517331d

Tekijä SHA1 Viesti Päivämäärä
  刘云鑫 999517331d Merge remote-tracking branch 'origin/sit-OrderFood' into sit-OrderFood 3 viikkoa sitten
  刘云鑫 e19f14d6ec feat:店铺常用语设置 3 viikkoa sitten

+ 63 - 0
alien-entity/src/main/java/shop/alien/entity/store/CommonExpression.java

@@ -0,0 +1,63 @@
+package shop.alien.entity.store;
+
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * 门店常用语表
+ *
+ * @author system
+ * @since 2026-03-26
+ */
+@Data
+@JsonInclude
+@TableName("common_expressions")
+@ApiModel(value = "CommonExpression对象", description = "门店常用语表")
+public class CommonExpression {
+
+    @ApiModelProperty(value = "主键ID")
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    @ApiModelProperty(value = "门店ID(关联门店表)")
+    @TableField("store_id")
+    private Integer storeId;
+
+    @ApiModelProperty(value = "常用语内容")
+    @TableField("content")
+    private String content;
+
+    @ApiModelProperty(value = "删除标记, 0:未删除, 1:已删除")
+    @TableField("delete_flag")
+    @TableLogic
+    private Integer deleteFlag;
+
+    @ApiModelProperty(value = "创建时间")
+    @TableField(value = "created_time", fill = FieldFill.INSERT)
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date createdTime;
+
+    @ApiModelProperty(value = "创建人ID")
+    @TableField("created_user_id")
+    private Integer createdUserId;
+
+    @ApiModelProperty(value = "修改时间")
+    @TableField(value = "updated_time", fill = FieldFill.INSERT_UPDATE)
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date updatedTime;
+
+    @ApiModelProperty(value = "修改人ID")
+    @TableField("updated_user_id")
+    private Integer updatedUserId;
+}

+ 15 - 0
alien-entity/src/main/java/shop/alien/mapper/CommonExpressionMapper.java

@@ -0,0 +1,15 @@
+package shop.alien.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import shop.alien.entity.store.CommonExpression;
+
+/**
+ * 门店常用语表 Mapper 接口
+ *
+ * @author system
+ * @since 2026-03-26
+ */
+@Mapper
+public interface CommonExpressionMapper extends BaseMapper<CommonExpression> {
+}

+ 130 - 0
alien-store/src/main/java/shop/alien/store/controller/CommonExpressionController.java

@@ -0,0 +1,130 @@
+package shop.alien.store.controller;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiSort;
+import io.swagger.annotations.ApiOperationSupport;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+import shop.alien.entity.result.R;
+import shop.alien.entity.store.CommonExpression;
+import shop.alien.store.service.CommonExpressionService;
+
+import java.util.List;
+
+/**
+ * 门店常用语管理 前端控制器
+ *
+ * @author system
+ * @since 2026-03-26
+ */
+@Slf4j
+@Api(tags = {"门店常用语管理"})
+@ApiSort(16)
+@CrossOrigin
+@RestController
+@RequestMapping("/store/commonExpression")
+@RequiredArgsConstructor
+public class CommonExpressionController {
+
+    private final CommonExpressionService commonExpressionService;
+
+    @ApiOperationSupport(order = 1)
+    @ApiOperation("查询门店常用语列表")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "storeId", value = "门店ID", dataType = "Integer", paramType = "query", required = true)
+    })
+    @GetMapping("/list")
+    public R<List<CommonExpression>> list(@RequestParam Integer storeId) {
+        log.info("CommonExpressionController.list?storeId={}", storeId);
+        if (storeId == null) {
+            return R.fail("门店ID不能为空");
+        }
+        try {
+            return R.data(commonExpressionService.listByStoreId(storeId));
+        } catch (Exception e) {
+            log.error("查询门店常用语列表失败", e);
+            return R.fail("查询失败:" + e.getMessage());
+        }
+    }
+
+    @ApiOperationSupport(order = 2)
+    @ApiOperation("查询门店常用语详情")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", value = "主键ID", dataType = "Integer", paramType = "query", required = true)
+    })
+    @GetMapping("/detail")
+    public R<CommonExpression> detail(@RequestParam Integer id) {
+        log.info("CommonExpressionController.detail?id={}", id);
+        if (id == null) {
+            return R.fail("主键ID不能为空");
+        }
+        try {
+            CommonExpression detail = commonExpressionService.getById(id);
+            if (detail == null) {
+                return R.fail("常用语不存在");
+            }
+            return R.data(detail);
+        } catch (Exception e) {
+            log.error("查询门店常用语详情失败", e);
+            return R.fail("查询失败:" + e.getMessage());
+        }
+    }
+
+    @ApiOperationSupport(order = 3)
+    @ApiOperation("新增门店常用语")
+    @PostMapping("/add")
+    public R<String> add(@RequestBody CommonExpression commonExpression) {
+        log.info("CommonExpressionController.add?commonExpression={}", commonExpression);
+        try {
+            boolean result = commonExpressionService.addCommonExpression(commonExpression);
+            return result ? R.success("新增成功") : R.fail("新增失败");
+        } catch (Exception e) {
+            log.error("新增门店常用语失败", e);
+            return R.fail(e.getMessage());
+        }
+    }
+
+    @ApiOperationSupport(order = 4)
+    @ApiOperation("更新门店常用语")
+    @PostMapping("/update")
+    public R<String> update(@RequestBody CommonExpression commonExpression) {
+        log.info("CommonExpressionController.update?commonExpression={}", commonExpression);
+        try {
+            boolean result = commonExpressionService.updateCommonExpression(commonExpression);
+            return result ? R.success("更新成功") : R.fail("更新失败");
+        } catch (Exception e) {
+            log.error("更新门店常用语失败", e);
+            return R.fail(e.getMessage());
+        }
+    }
+
+    @ApiOperationSupport(order = 5)
+    @ApiOperation("删除门店常用语")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", value = "主键ID", dataType = "Integer", paramType = "query", required = true)
+    })
+    @PostMapping("/delete")
+    public R<String> delete(@RequestParam Integer id) {
+        log.info("CommonExpressionController.delete?id={}", id);
+        if (id == null) {
+            return R.fail("主键ID不能为空");
+        }
+        try {
+            boolean result = commonExpressionService.deleteCommonExpression(id);
+            return result ? R.success("删除成功") : R.fail("删除失败");
+        } catch (Exception e) {
+            log.error("删除门店常用语失败", e);
+            return R.fail(e.getMessage());
+        }
+    }
+}

+ 47 - 0
alien-store/src/main/java/shop/alien/store/service/CommonExpressionService.java

@@ -0,0 +1,47 @@
+package shop.alien.store.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import shop.alien.entity.store.CommonExpression;
+
+import java.util.List;
+
+/**
+ * 门店常用语表 服务类
+ *
+ * @author system
+ * @since 2026-03-26
+ */
+public interface CommonExpressionService extends IService<CommonExpression> {
+
+    /**
+     * 按门店查询常用语
+     *
+     * @param storeId 门店ID
+     * @return 常用语列表
+     */
+    List<CommonExpression> listByStoreId(Integer storeId);
+
+    /**
+     * 新增常用语
+     *
+     * @param commonExpression 常用语
+     * @return 是否成功
+     */
+    boolean addCommonExpression(CommonExpression commonExpression);
+
+    /**
+     * 更新常用语
+     *
+     * @param commonExpression 常用语
+     * @return 是否成功
+     */
+    boolean updateCommonExpression(CommonExpression commonExpression);
+
+    /**
+     * 删除常用语
+     *
+     * @param id 主键ID
+     * @return 是否成功
+     */
+    boolean deleteCommonExpression(Integer id);
+}

+ 117 - 0
alien-store/src/main/java/shop/alien/store/service/impl/CommonExpressionServiceImpl.java

@@ -0,0 +1,117 @@
+package shop.alien.store.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.StringUtils;
+import shop.alien.entity.store.CommonExpression;
+import shop.alien.mapper.CommonExpressionMapper;
+import shop.alien.store.service.CommonExpressionService;
+import shop.alien.util.common.JwtUtil;
+
+import java.util.List;
+
+/**
+ * 门店常用语表 服务实现类
+ *
+ * @author system
+ * @since 2026-03-26
+ */
+@Slf4j
+@Service
+@Transactional
+public class CommonExpressionServiceImpl extends ServiceImpl<CommonExpressionMapper, CommonExpression> implements CommonExpressionService {
+
+    @Override
+    public List<CommonExpression> listByStoreId(Integer storeId) {
+        LambdaQueryWrapper<CommonExpression> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(CommonExpression::getStoreId, storeId)
+                .orderByDesc(CommonExpression::getId);
+        return this.list(wrapper);
+    }
+
+    @Override
+    public boolean addCommonExpression(CommonExpression commonExpression) {
+        if (commonExpression.getStoreId() == null) {
+            throw new RuntimeException("门店ID不能为空");
+        }
+        if (!StringUtils.hasText(commonExpression.getContent())) {
+            throw new RuntimeException("常用语内容不能为空");
+        }
+        String content = commonExpression.getContent().trim();
+        if (existsSameContent(commonExpression.getStoreId(), content, null)) {
+            throw new RuntimeException("此常用语已存在");
+        }
+        commonExpression.setContent(content);
+        commonExpression.setCreatedUserId(getCurrentUserId());
+        return this.save(commonExpression);
+    }
+
+    @Override
+    public boolean updateCommonExpression(CommonExpression commonExpression) {
+        if (commonExpression.getId() == null) {
+            throw new RuntimeException("主键ID不能为空");
+        }
+        if (!StringUtils.hasText(commonExpression.getContent())) {
+            throw new RuntimeException("常用语内容不能为空");
+        }
+        CommonExpression existing = this.getById(commonExpression.getId());
+        if (existing == null) {
+            throw new RuntimeException("常用语不存在");
+        }
+        String content = commonExpression.getContent().trim();
+        if (existsSameContent(existing.getStoreId(), content, commonExpression.getId())) {
+            throw new RuntimeException("此常用语已存在");
+        }
+
+        LambdaUpdateWrapper<CommonExpression> updateWrapper = new LambdaUpdateWrapper<>();
+        updateWrapper.eq(CommonExpression::getId, commonExpression.getId())
+                .set(CommonExpression::getContent, content);
+
+        Integer userId = getCurrentUserId();
+        if (userId != null) {
+            updateWrapper.set(CommonExpression::getUpdatedUserId, userId);
+        }
+        return this.update(updateWrapper);
+    }
+
+    @Override
+    public boolean deleteCommonExpression(Integer id) {
+        CommonExpression existing = this.getById(id);
+        if (existing == null) {
+            throw new RuntimeException("常用语不存在");
+        }
+        return this.removeById(id);
+    }
+
+    private boolean existsSameContent(Integer storeId, String content, Integer excludeId) {
+        LambdaQueryWrapper<CommonExpression> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(CommonExpression::getStoreId, storeId)
+                .eq(CommonExpression::getContent, content);
+        if (excludeId != null) {
+            wrapper.ne(CommonExpression::getId, excludeId);
+        }
+        return this.count(wrapper) > 0;
+    }
+
+    /**
+     * 从JWT获取当前登录用户ID
+     *
+     * @return 用户ID,未获取到返回null
+     */
+    private Integer getCurrentUserId() {
+        try {
+            JSONObject userInfo = JwtUtil.getCurrentUserInfo();
+            if (userInfo != null) {
+                return userInfo.getInteger("userId");
+            }
+        } catch (Exception e) {
+            log.warn("获取当前登录用户ID失败: {}", e.getMessage());
+        }
+        return null;
+    }
+}