浏览代码

字典增删改查

vincent 3 年之前
父节点
当前提交
07044e547f

+ 5 - 6
server/src/main/java/edp/DavinciServerApplication.java

@@ -48,11 +48,11 @@ public class DavinciServerApplication {
     @Value("${server.port}")
     private int serverPort;
 
-    @NacosValue(value = "${person.name}", autoRefreshed = true)
-    private String name;
+    @Value("${server.address}")
+    private String serverAddress;
 
-    @Value("${nacos.discovery.server-addr}")
-    private String serverAddr;
+//    @NacosValue(value = "${person.name}", autoRefreshed = true)
+//    private String name;
 
     @Value("${spring.application.name}")
     private String applicationName;
@@ -60,9 +60,8 @@ public class DavinciServerApplication {
     @PostConstruct
     public void registerInstance() throws NacosException
     {
-        System.out.println(name);
         if(CollectionUtils.isEmpty(namingService.getAllInstances(applicationName))){
-            namingService.registerInstance(applicationName,serverAddr,serverPort);
+            namingService.registerInstance(applicationName,serverAddress,serverPort);
         }
     }
 

+ 4 - 4
server/src/main/java/edp/davinci/controller/DictController.java

@@ -13,6 +13,7 @@ import io.swagger.annotations.ApiResponse;
 import io.swagger.annotations.ApiResponses;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.validation.BindingResult;
@@ -45,7 +46,7 @@ public class DictController extends BaseController
             HttpServletRequest request)
     {
         List<DictType> dictTypes = dictService.getDictType();
-        return ResponseEntity.ok(dictTypes);
+        return ResponseEntity.status(HttpStatus.OK).body(dictTypes);
     }
 
     /**
@@ -61,7 +62,7 @@ public class DictController extends BaseController
                                     HttpServletRequest request)
     {
         List<DictData> dictDataList = dictService.getDictData(dictType);
-        return ResponseEntity.ok(dictDataList);
+        return ResponseEntity.status(HttpStatus.OK).body(dictDataList);
     }
 
     /**
@@ -80,7 +81,7 @@ public class DictController extends BaseController
 
         DictType record = dictService.createDictType(dictType);
 
-        return ResponseEntity.ok(record);
+        return ResponseEntity.status(HttpStatus.OK).body(record);
     }
 
     /**
@@ -191,7 +192,6 @@ public class DictController extends BaseController
      * 删除dicttype
      *
      * @param id
-     * @param user
      * @param request
      * @return
      */

+ 11 - 8
server/src/main/java/edp/davinci/dao/DictDataMapper.java

@@ -34,22 +34,25 @@ public interface DictDataMapper
 
     int insert(DictData dictData);
 
-    @Delete({"delete from `dict_data` where id = #{id}"})
+    @Delete({"delete from `dict_data` where dict_code = #{id}"})
     int deleteById(@Param("id") Long id);
 
-    @Select({"select * from `dict_data` where id = #{id}"})
+    @Select({"select * from `dict_data` where dict_code = #{id}"})
     DictData getById(@Param("id") Long id);
 
     @Update({
             "update `dict_data`",
-            "set `name` = #{name,jdbcType=VARCHAR},",
-            "`description` = #{description,jdbcType=VARCHAR},",
-            "`type` = #{type,jdbcType=VARCHAR},",
-            "`project_id` = #{projectId,jdbcType=BIGINT},",
-            "`config` = #{config,jdbcType=LONGVARCHAR},",
+            "set `dict_sort` = #{dictSort,jdbcType=BIGINT},",
+            "`dict_label` = #{dictLabel,jdbcType=VARCHAR},",
+            "`dict_value` = #{dictValue,jdbcType=VARCHAR},",
+            "`dict_type` = #{dictType,jdbcType=VARCHAR},",
+            "`css_class` = #{cssClass,jdbcType=VARCHAR},",
+            "`list_class` = #{listClass,jdbcType=VARCHAR},",
+            "`is_default` = #{isDefault,jdbcType=VARCHAR},",
+            "`status` = #{status,jdbcType=BIGINT},",
             "`update_by` = #{updateBy,jdbcType=BIGINT},",
             "`update_time` = #{updateTime,jdbcType=TIMESTAMP}",
-            "where id = #{id,jdbcType=BIGINT}"
+            "where dict_code = #{dictCode,jdbcType=BIGINT}"
     })
     int update(DictData dictData);
 

+ 4 - 4
server/src/main/java/edp/davinci/dao/DictTypeMapper.java

@@ -34,21 +34,21 @@ public interface DictTypeMapper
 
     int insert(DictType dictType);
 
-    @Delete({"delete from `dict_type` where id = #{id}"})
+    @Delete({"delete from `dict_type` where dict_id = #{id}"})
     int deleteById(@Param("id") Long id);
 
-    @Select({"select * from `dict_type` where id = #{id}"})
+    @Select({"select * from `dict_type` where dict_id = #{id}"})
     DictType getById(@Param("id") Long id);
 
     @Update({
             "update `dict_type`",
             "set `dict_name` = #{dictName,jdbcType=VARCHAR},",
             "`dict_type` = #{dictType,jdbcType=VARCHAR},",
-            "`status` = #{type,jdbcType=BIGINT},",
+            "`status` = #{status,jdbcType=BIGINT},",
             "`remark` = #{remark,jdbcType=VARCHAR},",
             "`update_by` = #{updateBy,jdbcType=BIGINT},",
             "`update_time` = #{updateTime,jdbcType=TIMESTAMP}",
-            "where id = #{id,jdbcType=BIGINT}"
+            "where dict_id = #{dictId,jdbcType=BIGINT}"
     })
     int update(DictType dictType);
 

+ 1 - 1
server/src/main/java/edp/davinci/model/DictData.java

@@ -31,7 +31,7 @@ public class DictData extends RecordInfo<DictData>
     private String isDefault;
 
     //0=正常,1=停用
-    private String status;
+    private Integer status;
 
     // 备注
     private String remark;

+ 1 - 2
server/src/main/java/edp/davinci/model/DictType.java

@@ -10,7 +10,6 @@ import lombok.extern.slf4j.Slf4j;
  */
 @Slf4j
 @Data
-@EqualsAndHashCode(callSuper = true)
 public class DictType extends RecordInfo<DictType>
 {
     private Long dictId;
@@ -22,7 +21,7 @@ public class DictType extends RecordInfo<DictType>
     private String dictType;
 
     // 字典状态 0=正常,1=停用
-    private String status;
+    private Integer status;
 
     // 备注
     private String remark;

+ 1 - 1
server/src/main/java/edp/davinci/service/impl/DictServiceImpl.java

@@ -69,8 +69,8 @@ public class DictServiceImpl implements DictService
     @Override
     public boolean deleteDictType(Long id)
     {
-        int count = dictTypeMapper.deleteById(id);
         DictType dictType = dictTypeMapper.getById(id);
+        int count = dictTypeMapper.deleteById(id);
 
         List<DictData> dictDataList = dictDataMapper.getDictDataList(dictType.getDictType());
         for (DictData dictData : dictDataList)

+ 4 - 3
server/src/main/resources/application.yml

@@ -18,8 +18,9 @@ davinci:
   version: 0.3-rc
 
 DAVINCI3_HOME: /Users/vincent/workspace/taihu/data-analysis
+
 file:
-  userfiles-path: ${DAVINCI3_HOME:}/userfiles/
+  userfiles-path: ${DAVINCI3_HOME}/userfiles/
   web_resources: ${DAVINCI3_HOME}/davinci-ui/
   base-path: ${DAVINCI3_HOME}/lib/
 spring:
@@ -62,9 +63,9 @@ logging:
 ## nacos 配置
 nacos:
   discovery:
-    server-addr: 127.0.1.1:8848
+    server-addr: ${NACOS_DISCOVERY_SERVER_ADDR:127.0.0.1:8848}
   config:
-    server-addr: 127.0.0.1:8848
+    server-addr: ${NACOS_CONFIG_SERVER_ADDR:127.0.0.1:8848}
 
 springfox:
   documentation:

+ 0 - 12
server/src/main/resources/bootstrap.properties

@@ -1,12 +0,0 @@
-#nacos config
-nacos.config.server-addr           =${NACOS_CONFIG_SERVER_ADDR:127.0.0.1:8848}
-# Nacos Console add configuration:
-# Data ID:maxkey.properties
-# Group:DEFAULT_GROUP
-# configuration:useLocalCache=true
-spring.application.name                         =taihu-analysis
-# Suffix for the configuration. Supports properties,yaml,yml,default is properties
-#spring.cloud.nacos.config.file-extension        =properties
-nacos.config.file-extension=yaml
-#nacos enabled
-nacos.config.enabled               =${NACOS_CONFIG_ENABLED:true}

+ 21 - 17
server/src/main/resources/mybatis/mapper/DictDataMapper.xml

@@ -21,29 +21,33 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
 <mapper namespace="edp.davinci.dao.DictDataMapper">
     <insert id="insert" parameterType="edp.davinci.model.DictData">
-        <selectKey resultType="java.lang.Long" order="AFTER" keyProperty="id">
-            SELECT LAST_INSERT_ID() AS id
+        <selectKey resultType="java.lang.Long" order="AFTER" keyProperty="dictCode">
+            SELECT LAST_INSERT_ID() AS dict_code
         </selectKey>
-        insert into source
+        insert into dict_data
         <trim prefix="(" suffix=")" suffixOverrides=",">
-            `name`,
-            <if test="description != null">
-                description,
-            </if>
-            `type`,
-            `project_id`,
-            `config`,
+            `dict_sort`,
+            `dict_label`,
+            `dict_value`,
+            `dict_type`,
+            `css_class`,
+            `list_class`,
+            `is_default`,
+            `remark`,
+            `status`,
             `create_by`,
             `create_time`
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
-            #{name,jdbcType=VARCHAR},
-            <if test="description != null">
-                #{description,jdbcType=VARCHAR},
-            </if>
-            #{type,jdbcType=VARCHAR},
-            #{projectId,jdbcType=BIGINT},
-            #{config,jdbcType=LONGVARCHAR},
+            #{dictSort,jdbcType=BIGINT},
+            #{dictLabel,jdbcType=VARCHAR},
+            #{dictValue,jdbcType=VARCHAR},
+            #{dictType,jdbcType=VARCHAR},
+            #{cssClass,jdbcType=VARCHAR},
+            #{listClass,jdbcType=VARCHAR},
+            #{isDefault,jdbcType=VARCHAR},
+            #{remark,jdbcType=VARCHAR},
+            #{status,jdbcType=BIGINT},
             #{createBy,jdbcType=BIGINT},
             #{createTime,jdbcType=TIMESTAMP}
         </trim>

+ 7 - 16
server/src/main/resources/mybatis/mapper/DictTypeMapper.xml

@@ -20,33 +20,24 @@
 
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
 <mapper namespace="edp.davinci.dao.DictTypeMapper">
-    <insert id="insert" parameterType="edp.davinci.model.DictData">
-        <selectKey resultType="java.lang.Long" order="AFTER" keyProperty="dictCode">
-            SELECT LAST_INSERT_ID() AS dict_code
+    <insert id="insert" parameterType="edp.davinci.model.DictType">
+        <selectKey resultType="java.lang.Long" order="AFTER" keyProperty="dictId">
+            SELECT LAST_INSERT_ID() AS dict_id
         </selectKey>
-        insert into source
+        insert into dict_type
         <trim prefix="(" suffix=")" suffixOverrides=",">
-            `dict_sort`,
-            `dict_label`,
-            `dict_value`,
+            `dict_name`,
             `dict_type`,
-            `cssClass`,
-            `listClass`,
-            `isDefault`,
             `remark`,
             `status`,
             `create_by`,
             `create_time`
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
-            #{dictSort,jdbcType=BIGINT},
-            #{dictLable,jdbcType=VARCHAR},
-            #{dictValue,jdbcType=VARCHAR},
+            #{dictName,jdbcType=VARCHAR},
             #{dictType,jdbcType=VARCHAR},
-            #{cssClass,jdbcType=VARCHAR},
-            #{listClass,jdbcType=VARCHAR},
-            #{isDefault,jdbcType=VARCHAR},
             #{remark,jdbcType=VARCHAR},
+            #{status,jdbcType=BIGINT},
             #{createBy,jdbcType=BIGINT},
             #{createTime,jdbcType=TIMESTAMP}
         </trim>