Forráskód Böngészése

新增个人网站

zwhui 1 éve
szülő
commit
7ea19c6746

+ 89 - 0
wholesale/src/main/java/com/yhlxj/dao/model/enums/GatewayApiCode.java

@@ -0,0 +1,89 @@
+package com.yhlxj.dao.model.enums;
+
+import lombok.Getter;
+
+/**
+ * @author chan
+ * @className GatewayApiCode
+ * @description 网关响应码枚举
+ * @date 2021/3/22 9:45 下午
+ */
+@Getter
+public enum GatewayApiCode {
+
+    /**
+     * 接口调用成功
+     */
+    SUCCESS(10000, "success"),
+
+
+    /**
+     * API参数错误
+     */
+    ENUM_TYPE_ILLEGAL(10010, "非法枚举值"),
+    DATE_FORMAT_ILLEGAL(10020, "日期格式不对"),
+    START_TIME_FORMAT_ILLEGAL(10021, "起始时间不对"),
+    END_TIME_FORMAT_ILLEGAL(10022, "结束时间不对"),
+    USER_INFO_ILLEGAL(10023, "获取不到用户信息"),
+    WHITE_LIST_PROMOTION_TYPE_ILLEGAL(10124, "获取不到用户信息"),
+
+    /**
+     * 订单相关
+     */
+    THE_ORDER_CANNOT_BE_FOUND(30001,"该订单不存在"),
+    AMOUNT_TOO_SMALL(30021,"Stripe支付金额不能小于0.5$"),
+
+    /**
+     * 系统异常,10-系统异常
+     */
+    ILLEGAL_ENUM_VALUE(100001, "异常枚举类型"),
+    METADATA_SYSTEM_ERROR(100002, "系统错误"),
+
+    /**
+     * 11-mq处理异常
+     */
+    ILLEGAL_DELAY_MQ_TYPE(110001, "延时消息类型不在有效范围之内"),
+    LOOP_DELAY_MQ_ERR_INTERVAL(110002, "循环延时消息的interval不能为0"),
+    LOOP_DELAY_MQ_NOT_SET_STOP_CONDITION(110003, "循环延时消息未设置终止循环的有效数值"),
+
+    /**
+     * API参数错误-14
+     */
+    PARAMETER_MISSING_ERROR(140001, "参数错误"),
+    REPEAT_REQUEST(140002, "重复请求"),
+
+    /**
+     * 车票
+     */
+    GROUP_INDEX_NOT_FIND(40001,"该车位不存在"),
+
+    GROUP_INDEX_ALREADY_BE_USER(40002,"该车位已有人"),
+
+
+    //用户未登录
+    CMS_USER_NO_LOGIN(20000,"用户未登录!"),
+    //用户不存在
+    CMS_USER_NO_FIND(20001,"用户不存在!"),
+    //密码错误
+    CMS_USER_PASSWORD_ERROR(20002,"密码错误!"),
+    //用户无权限
+    CMS_USER_NO_PERMISSION(20003,"您没有此项操作权限"),
+    //用户无角色权限
+    CMS_USER_NO_ROLE(20004,"您没有此项操作角色"),
+    //无登录权限
+    CMS_USER_NO_LOGIN_PERMISSION(20005,"您无法登录,请联系管理员"),
+    //用户登录信息失效
+    CMS_TOKEN_VALID(20006,"登录信息已失效,请重新登录!"),
+    //踢下线
+    CMS_TOKEN_OUT_LINE(20007,"您已被管理员踢下线,请重新登录!"),
+    ;
+
+    private Integer code;
+
+    private String msg;
+
+    GatewayApiCode(Integer _code, String _msg) {
+        this.code = _code;
+        this.msg = _msg;
+    }
+}

+ 112 - 0
wholesale/src/main/java/com/yhlxj/dao/model/enums/GatewayResponse.java

@@ -0,0 +1,112 @@
+package com.yhlxj.dao.model.enums;
+
+
+
+import com.yhlxj.dao.model.dto.Result;
+
+import java.util.Map;
+
+/**
+ * @author chan
+ * @className GatewayResponse
+ * @date 2020/7/29 3:06 下午
+ */
+public enum GatewayResponse {
+
+    /**
+     * 成功
+     */
+    SUCCESS(GatewayApiCode.SUCCESS.getCode(), GatewayApiCode.SUCCESS.getMsg(),Boolean.TRUE),
+
+    /**
+     * 失败
+     */
+    FAIL(GatewayApiCode.METADATA_SYSTEM_ERROR.getCode(), GatewayApiCode.METADATA_SYSTEM_ERROR.getMsg(),Boolean.FALSE);
+
+    GatewayResponse(Integer _code, String _msg, boolean flag) {
+        this.code = _code;
+        this.msg = _msg;
+        this.flag = flag;
+    }
+
+    private Integer code;
+
+    private String msg;
+
+    private boolean flag;
+
+    public Integer getCode() {
+        return code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public boolean getFlag(){
+        return flag;
+    }
+
+    public buildGateWay newBuilder() {
+        return new buildGateWay(this);
+    }
+
+    public class buildGateWay {
+
+        private Integer code;
+
+        private String msg;
+
+        private boolean flag;
+
+        buildGateWay(GatewayResponse response) {
+            this.code = response.getCode();
+            this.msg = response.getMsg();
+            this.flag = response.getFlag();
+        }
+
+        public buildGateWay buildGatewayCode(GatewayApiCode gateWayCode) {
+            this.code = gateWayCode.getCode();
+            this.msg = gateWayCode.getMsg();
+            return this;
+        }
+
+        public buildGateWay setMsg(String _msg) {
+            this.msg = _msg;
+            return this;
+        }
+        public buildGateWay setCode(Integer code) {
+            this.code = code;
+            return this;
+        }
+
+
+        public  <T> Result<T> toResult() {
+            return buildMap();
+        }
+
+
+        public <T extends java.io.Serializable> Result<T> toResult(T model) {
+            return Result.of(this.code,this.msg,this.flag,model);
+        }
+
+        @SuppressWarnings("rawtypes")
+        public <T extends java.util.Collection> Result<T>  toResult(T model) {
+            return Result.of(this.code,this.msg,this.flag,model);
+        }
+
+        @SuppressWarnings("rawtypes")
+        public <T> Result<T> toResult(T model) {
+            return Result.of(this.code,this.msg,this.flag,model);
+        }
+
+        @SuppressWarnings("rawtypes")
+        public <T extends Map> Result<T>  toResult(T model) {
+            return Result.of(this.code,this.msg,this.flag,model);
+        }
+
+        private <T> Result<T> buildMap() {
+            return Result.of(this.code,this.msg,this.flag,null);
+        }
+    }
+}

+ 0 - 1
wholesale/src/main/java/com/yhlxj/service/WebInfoService.java

@@ -31,7 +31,6 @@ public interface WebInfoService {
      * @param webInfo WebInfo对象
      * @return 更新后的WebInfo对象
      */
-    WebInfo updateWebInfo(Long id, WebInfo webInfo);
 
     /**
      * 根据ID获取WebInfo

+ 1 - 35
wholesale/src/main/java/com/yhlxj/service/impl/WebInfoServiceImpl.java

@@ -94,41 +94,7 @@ public class WebInfoServiceImpl implements WebInfoService {
         return webInfo;
     }
     
-    @Override
-    @Transactional
-    public WebInfo updateWebInfo(Long id, WebInfo webInfo) {
-        validateWebInfo(webInfo);
-        
-        // 查询原记录
-        WebInfo existingWebInfo = webInfoMapper.selectById(id);
-        if (existingWebInfo == null) {
-            throw new IllegalArgumentException("要更新的记录不存在");
-        }
-        
-        // 检查前缀唯一性(排除自身)
-        if (!existingWebInfo.getPrefix().equals(webInfo.getPrefix())) {
-            LambdaQueryWrapper<WebInfo> prefixQuery = new LambdaQueryWrapper<>();
-            prefixQuery.eq(WebInfo::getPrefix, webInfo.getPrefix())
-                    .ne(WebInfo::getId, id);
-            if (webInfoMapper.selectCount(prefixQuery) > 0) {
-                throw new IllegalArgumentException("网站前缀已被其他记录使用");
-            }
-        }
-        
-        // 检查账号唯一性(排除自身)
-        if (!existingWebInfo.getAccount().equals(webInfo.getAccount())) {
-            LambdaQueryWrapper<WebInfo> accountQuery = new LambdaQueryWrapper<>();
-            accountQuery.eq(WebInfo::getAccount, webInfo.getAccount())
-                    .ne(WebInfo::getId, id);
-            if (webInfoMapper.selectCount(accountQuery) > 0) {
-                throw new IllegalArgumentException("账号已被其他记录使用");
-            }
-        }
-        
-        webInfo.setId(id);
-        webInfoMapper.updateById(webInfo);
-        return webInfo;
-    }
+
     
     @Override
     public WebInfo getWebInfoById(Long id) {

+ 42 - 4
wholesale/src/main/java/com/yhlxj/web/WholesaleController.java

@@ -2,6 +2,7 @@ package com.yhlxj.web;
 
 import com.yhlxj.dao.model.dto.Result;
 import com.yhlxj.dao.model.entity.WebInfo;
+import com.yhlxj.dao.model.enums.GatewayResponse;
 import com.yhlxj.service.WebInfoService;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -18,12 +19,49 @@ import org.springframework.web.bind.annotation.*;
 public class WholesaleController {
     private final WebInfoService webInfoService;
 
-    @GetMapping("/test")
-    public String test() {
-        log.info("test");
-        return "test";
+
+    /**
+     * 检查前缀是否存在
+     * @param prefix 网站前缀
+     * @return 结果
+     */
+    @GetMapping("/check-prefix")
+    public Result<Boolean> checkPrefixExists(@RequestParam String prefix) {
+        boolean exists = webInfoService.checkPrefixExists(prefix);
+        return GatewayResponse.SUCCESS.newBuilder().toResult(exists);
+    }
+
+    /**
+     * 检查账号是否存在
+     * @param account 账号
+     * @return 结果
+     */
+    @GetMapping("/check-account")
+    public Result<Boolean> checkAccountExists(@RequestParam String account) {
+        boolean exists = webInfoService.checkAccountExists(account);
+        return GatewayResponse.SUCCESS.newBuilder().toResult(exists);
+    }
+
+    /**
+     * 保存WebInfo
+     * @param webInfo WebInfo对象
+     * @return 结果
+     */
+    @PostMapping
+    public Result<WebInfo> saveWebInfo(@RequestBody WebInfo webInfo) {
+        return GatewayResponse.SUCCESS.newBuilder().toResult(webInfoService.saveWebInfo(webInfo));
     }
 
 
+    /**
+     * 根据ID获取WebInfo
+     * @param id ID
+     * @return 结果
+     */
+    @GetMapping("/{id}")
+    public Result<WebInfo> getWebInfoById(@PathVariable Long id) {
+            WebInfo webInfo = webInfoService.getWebInfoById(id);
+            return GatewayResponse.SUCCESS.newBuilder().toResult(webInfo);
+    }
 
 }