Jelajahi Sumber

添加场站列表,修改返回对象类型

shilin 5 bulan lalu
induk
melakukan
86221acebe

+ 5 - 0
yudao-module-infra/yudao-module-infra-biz/pom.xml

@@ -35,6 +35,11 @@
             <groupId>cn.iocoder.boot</groupId>
             <artifactId>yudao-spring-boot-starter-biz-tenant</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.alibaba.fastjson2</groupId>
+            <artifactId>fastjson2</artifactId>
+            <version>2.0.50</version>
+        </dependency>
 
         <!-- Web 相关 -->
         <dependency>

+ 6 - 13
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/ProBasicPowerstationController.java

@@ -1,26 +1,18 @@
 package cn.iocoder.yudao.module.infra.controller.admin.db;
 
-import cn.iocoder.yudao.framework.common.pojo.CommonResult;
-import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
-import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigRespVO;
-import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigSaveReqVO;
-import cn.iocoder.yudao.module.infra.dal.dataobject.db.DataSourceConfigDO;
+import cn.iocoder.yudao.module.infra.controller.admin.db.vo.Result;
+import cn.iocoder.yudao.module.infra.controller.admin.db.vo.ResultCode;
 import cn.iocoder.yudao.module.infra.dal.dataobject.db.ProBasicPowerstationDO;
-import cn.iocoder.yudao.module.infra.service.db.DataSourceConfigService;
 import cn.iocoder.yudao.module.infra.service.db.ProBasicPowerstationService;
+import com.alibaba.fastjson2.JSONObject;
 import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import jakarta.annotation.Resource;
-import jakarta.validation.Valid;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 
-import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
-
 @Tag(name = "管理后台 - 场站列表")
 @RestController
 @RequestMapping("/terminal")
@@ -33,8 +25,9 @@ public class ProBasicPowerstationController {
 
     @GetMapping("/getYardStationData")
     @Operation(summary = "获得场站列表")
-    public CommonResult<List<ProBasicPowerstationDO>> getYardStationData() {
+    public JSONObject getYardStationData() {
         List<ProBasicPowerstationDO> list = proBasicPowerstationService.getYardStationData();
-        return success(BeanUtils.toBean(list, ProBasicPowerstationDO.class));
+
+        return Result.successData(ResultCode.SUCCESS, list);
     }
 }

+ 72 - 0
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/vo/Result.java

@@ -0,0 +1,72 @@
+package cn.iocoder.yudao.module.infra.controller.admin.db.vo;
+
+import com.alibaba.fastjson2.JSONObject;
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class Result implements Serializable {
+
+    private Integer code;
+    private String message;
+    private Object data;
+
+    public static JSONObject error(){
+        JSONObject json = new JSONObject();
+        json.put("code", ResultCode.ERROR.getCode());
+        json.put("msg", ResultCode.ERROR.getMessage());
+        return json;
+    }
+
+    public static JSONObject error(ResultCode resultCode){
+        JSONObject json = new JSONObject();
+        json.put("code", resultCode.getCode());
+        json.put("msg", resultCode.getMessage());
+        return json;
+    }
+
+    public static JSONObject error(ResultCode resultCode,String message){
+        JSONObject json = new JSONObject();
+        json.put("code", resultCode.getCode());
+        json.put("msg", resultCode.getMessage()+","+message);
+        return json;
+    }
+
+    public static JSONObject error(int code, String message){
+        JSONObject json = new JSONObject();
+        json.put("code", code);
+        json.put("msg", message);
+        return json;
+    }
+
+    public static JSONObject success(){
+        JSONObject json = new JSONObject();
+        json.put("code", ResultCode.SUCCESS.getCode());
+        json.put("msg", ResultCode.SUCCESS.getMessage());
+        return json;
+    }
+
+    public static JSONObject seccess(int code, String message){
+        JSONObject json = new JSONObject();
+        json.put("code", code);
+        json.put("msg", message);
+        return json;
+    }
+
+    public static JSONObject success(ResultCode resultCode){
+        JSONObject json = new JSONObject();
+        json.put("code", resultCode.getCode());
+        json.put("msg", resultCode.getMessage());
+        return json;
+    }
+
+    public static JSONObject successData(ResultCode code, Object data){
+        JSONObject json = new JSONObject();
+        json.put("code", code.getCode());
+        json.put("msg", code.getMessage());
+        json.put("data", data == null ? new JSONObject():data);
+        return json;
+    }
+
+}

+ 79 - 0
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/db/vo/ResultCode.java

@@ -0,0 +1,79 @@
+package cn.iocoder.yudao.module.infra.controller.admin.db.vo;
+
+public enum ResultCode {
+    /* 成功 */
+    SUCCESS(200, "成功"),
+
+    /* 默认失败 */
+    ERROR(4000, "失败"),
+    ERROR_FILE_NO(4001, "文件未找到"),
+    ERROR_FILE_TYPE(4002, "文件类型不正确"),
+    ERROR_FILE_DATA(4003, "数据为空"),
+    ERROR_DATA_TYPE(4004, "数据格式不正确"),
+    ERROR_CONNECT(4005, "数据库连接异常"),
+    ERROR_DATA(4006, "数据库操作失败"),
+    ERROR_DATA_REPEAT(4007, "数据已存在"),
+    ERROR_MODEL(4008, "同场站不同机型至少启用一个模型"),
+    ERROR_SQL(4009, "sql语法不正确"),
+    ERROR_UNSUPPORTED_SQL(4010, "不支持的sql语句"),
+
+
+    /* 参数错误:1000~1999 */
+    PARAM_NOT_VALID(1001, "参数无效"),
+    PARAM_IS_BLANK(1002, "参数为空"),
+    PARAM_TYPE_ERROR(1003, "参数类型错误"),
+    PARAM_NOT_COMPLETE(1004, "参数缺失"),
+    ERROR_DATA_DIR(1005, "目录创建失败"),
+    ERROR_DATA_FILE(1006, "文件上传失败"),
+
+    /* 用户错误 */
+    USER_NOT_LOGIN(2001, "用户未登录"),
+    USER_ACCOUNT_ERROR(2002, "账号或密码错误"),
+    USER_FAIL_LOGIN(2003, "登录失败"),
+    USER_OUT_LOGIN(2004, "登出成功"),
+    USER_ERROR_TOKEN(2005, "登录已过期,请重新登录"),
+
+    /* 业务错误 */
+    NO_PERMISSION(3001, "没有权限"),
+    ERROR_ENABLE(3002, "模型为启用状态,不允许删除"),
+    ERROR_TASK(3003, "有正在进行的任务,请稍后在试");
+
+    private Integer code;
+    private String message;
+
+    ResultCode(Integer code, String message) {
+        this.code = code;
+        this.message = message;
+    }
+
+    public Integer getCode() {
+        return code;
+    }
+
+    public void setCode(Integer code) {
+        this.code = code;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+
+    /**
+     * 根据code获取message
+     *
+     * @param code
+     * @return
+     */
+    public static String getMessageByCode(Integer code) {
+        for (ResultCode ele : values()) {
+            if (ele.getCode().equals(code)) {
+                return ele.getMessage();
+            }
+        }
+        return null;
+    }
+}