Pārlūkot izejas kodu

实体类修改对应表,sql字段修改

yuzijian 2 gadi atpakaļ
vecāks
revīzija
f9c692170b

+ 10 - 0
pom.xml

@@ -101,6 +101,16 @@
             <version>3.3.1</version>
         </dependency>
         <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-annotation</artifactId>
+            <version>3.3.1</version>
+        </dependency>
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-boot-starter</artifactId>
+            <version>3.3.1</version>
+        </dependency>
+        <dependency>
             <groupId>org.mybatis.spring.boot</groupId>
             <artifactId>mybatis-spring-boot-starter</artifactId>
             <version>2.1.1</version>

+ 10 - 0
src/main/java/com/syjy/calculate/config/StarterAutoConfigure.java

@@ -4,6 +4,7 @@ import com.syjy.calculate.conotroller.JarCalculate;
 import com.syjy.calculate.conotroller.Test;
 import com.syjy.calculate.listener.ApplicationListenerImpl;
 import com.syjy.calculate.mapper.CalculationFormulaMapper;
+import com.syjy.calculate.mapper.CalculationFormulaServiceImpl;
 import com.syjy.calculate.repository.repositoryImpl.CalculationFormulaRepositoryImpl;
 import com.syjy.calculate.service.AccuracyPassRateCalculateService;
 import com.syjy.calculate.util.CreateAndInsertSqlUtil;
@@ -70,4 +71,13 @@ public class StarterAutoConfigure {
     CalculationFormulaMapper calculationFormulaMapper() {
         return new CalculationFormulaMapper();
     }*/
+@Bean
+@ConditionalOnMissingBean
+@ConditionalOnProperty(prefix = "calculate.service", value = "enabled", havingValue = "true")
+CalculationFormulaServiceImpl clculationFormulaServiceImpl() {
+    return new CalculationFormulaServiceImpl();
+}
+
+
+
 }

+ 18 - 8
src/main/java/com/syjy/calculate/conotroller/JarCalculate.java

@@ -1,13 +1,17 @@
 package com.syjy.calculate.conotroller;
 
-import com.syjy.calculate.entity.CalculationFormula;
+
+import com.syjy.calculate.entity.tCalculationFormula;
 import com.syjy.calculate.mapper.CalculationFormulaMapper;
+import com.syjy.calculate.mapper.CalculationFormulaService;
 import com.syjy.calculate.repository.CalculationFormulaRepository;
 import com.syjy.calculate.service.AccuracyPassRateCalculateService;
 import com.syjy.calculate.vo.ResponseVO;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.dao.DataAccessException;
 import org.springframework.jdbc.core.BeanPropertyRowMapper;
+import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.*;
 
@@ -19,25 +23,31 @@ import java.util.List;
 @RequestMapping("jarCalculate")
 public class JarCalculate {
     @Resource
-    CalculationFormulaMapper calculationFormulaMapper;
+    public JdbcTemplate jdbcTemplate;
     @Autowired
     CalculationFormulaRepository calculationFormulaRepository;
-
+    @Autowired
+   CalculationFormulaService calculationFormulaService;
    @GetMapping("test")
     @ResponseBody
     public String test() {
         String aa = "1112";
         return aa;
     }
- /*   @GetMapping("select")
+  @GetMapping("select")
     @ResponseBody
     public ResponseVO select() {
-        List<CalculationFormula> calculationFormulaList = new ArrayList<>();
-        calculationFormulaList =calculationFormulaMapper.findAll();
-        System.out.println("测试"+calculationFormulaList);
+      String sql = "SELECT * from t_calculation_formula";
+
+      List<tCalculationFormula> calculationFormulaList = new ArrayList<>();
+      try {
+          calculationFormulaList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(tCalculationFormula.class));
+      } catch (DataAccessException e) {
+          e.printStackTrace();
+      }
         return ResponseVO.success(calculationFormulaList);
     }
-
+/*
     @PostMapping("add")
     @ResponseBody
     public ResponseVO add(@RequestBody CalculationFormula calculationFormula ) {

+ 0 - 61
src/main/java/com/syjy/calculate/entity/CalculationFormula.java

@@ -1,61 +0,0 @@
-package com.syjy.calculate.entity;
-
-import lombok.Data;
-import lombok.Getter;
-import lombok.Setter;
-
-import javax.persistence.Table;
-
-/**
- * 计算公式
- *
- * @author zcl
- * @version 1.0
- * @since 2022/8/02 10:16
- */
-@Data
-public class CalculationFormula {
-
-    /**
-     * 公式编号(运维标识,主键)
-     */
-    @Getter
-    @Setter
-    private Integer id;
-
-    /**
-     * 公式类型
-     */
-    @Getter
-    @Setter
-    private String type;
-
-    /**
-     * 公式执行顺序
-     */
-    @Getter
-    @Setter
-    private Integer order;
-
-    /**
-     * 公式内容
-     */
-    @Getter
-    @Setter
-    private String formula;
-
-    /**
-     * 上报省调
-     */
-    @Getter
-    @Setter
-    private String provinceEnum;
-
-    /**
-     * 状态
-     */
-    @Getter
-    @Setter
-    private String state;
-
-}

+ 74 - 0
src/main/java/com/syjy/calculate/entity/tCalculationFormula.java

@@ -0,0 +1,74 @@
+package com.syjy.calculate.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import javax.persistence.Table;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 计算公式
+ *
+ * @author zcl
+ * @version 1.0
+ * @since 2022/8/02 10:16
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class tCalculationFormula implements Serializable  {
+
+    /**
+     * 公式编号(运维标识,主键)
+     */
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    /**
+     * 公式类型
+     */
+
+    private String type;
+
+    /**
+     * 公式执行顺序
+     */
+
+    private Integer order2;
+
+    /**
+     * 公式内容
+     */
+
+    private String formula;
+
+    /**
+     * 上报省调
+     */
+
+    private String provinceEnum;
+
+    /**
+     * 状态
+     */
+
+    private String state;
+    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
+    @DateTimeFormat(pattern = "yyyy-MM-dd")
+    private Date createTime;
+
+    private String creator;
+
+    private String lastModifier;
+    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
+    @DateTimeFormat(pattern = "yyyy-MM-dd")
+    private Date lastModifyTime;
+}

+ 3 - 23
src/main/java/com/syjy/calculate/mapper/CalculationFormulaMapper.java

@@ -1,30 +1,10 @@
 package com.syjy.calculate.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.syjy.calculate.entity.CalculationFormula;
-import org.apache.ibatis.annotations.*;
-import org.springframework.context.annotation.ComponentScan;
-import org.springframework.stereotype.Service;
 
-import java.util.List;
+import com.syjy.calculate.entity.tCalculationFormula;
+import org.apache.ibatis.annotations.Mapper;
 
 @Mapper
-public interface CalculationFormulaMapper extends BaseMapper<CalculationFormula> {
-    @Select("SELECT * from t_calculation_formula")
-    List<CalculationFormula> findAll();
-
-    @Select("INSERT INTO t_calculation_formula(type,`order`,formula,province_enum,state) VALUES(#{type},#{order},#{formula},#{province},#{state})")
-    void add(String type, Integer order, String formula, String province, String state);
-
-    @Update("UPDATE t_calculation_formula\n" +
-            "SET type = #{type}\n," +
-            " `order` = #{order}\n," +
-            " `formula` = #{formula}\n," +
-            " `province_enum` = #{province}\n," +
-            " `state` = #{state}\n" +
-            "WHERE id = #{id};\n")
-    void edit(Integer id, String type, Integer order, String formula, String province, String state);
-
-    @Delete("DELETE FROM t_calculation_formula WHERE id = #{id}")
-    void delete(Integer id);
+public interface CalculationFormulaMapper  extends BaseMapper<tCalculationFormula> {
 }

+ 0 - 8
src/main/java/com/syjy/calculate/mapper/CalculationFormulaMapper.xml

@@ -1,8 +0,0 @@
-<?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.syjy.calculate.mapper.CalculationFormulaMapper">
-
-
-
-</mapper>

+ 35 - 0
src/main/java/com/syjy/calculate/mapper/CalculationFormulaService.java

@@ -0,0 +1,35 @@
+package com.syjy.calculate.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.syjy.calculate.entity.tCalculationFormula;
+import org.apache.ibatis.annotations.*;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.stereotype.Repository;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/*@Repository
+public interface CalculationFormulaMapper{
+    @Select("SELECT * from t_calculation_formula")
+    List<CalculationFormula> findAll();
+
+    @Select("INSERT INTO t_calculation_formula(type,`order`,formula,province_enum,state) VALUES(#{type},#{order},#{formula},#{province},#{state})")
+    void add(String type, Integer order, String formula, String province, String state);
+
+    @Update("UPDATE t_calculation_formula\n" +
+            "SET type = #{type}\n," +
+            " `order` = #{order}\n," +
+            " `formula` = #{formula}\n," +
+            " `province_enum` = #{province}\n," +
+            " `state` = #{state}\n" +
+            "WHERE id = #{id};\n")
+    void edit(Integer id, String type, Integer order, String formula, String province, String state);
+
+    @Delete("DELETE FROM t_calculation_formula WHERE id = #{id}")
+    void delete(Integer id);
+}*/
+public interface CalculationFormulaService extends IService<tCalculationFormula> {
+
+}

+ 12 - 0
src/main/java/com/syjy/calculate/mapper/CalculationFormulaServiceImpl.java

@@ -0,0 +1,12 @@
+package com.syjy.calculate.mapper;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.syjy.calculate.entity.tCalculationFormula;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CalculationFormulaServiceImpl extends ServiceImpl <CalculationFormulaMapper, tCalculationFormula> implements CalculationFormulaService {
+
+}

+ 2 - 2
src/main/java/com/syjy/calculate/repository/CalculationFormulaRepository.java

@@ -1,6 +1,6 @@
 package com.syjy.calculate.repository;
 
-import com.syjy.calculate.entity.CalculationFormula;
+import com.syjy.calculate.entity.tCalculationFormula;
 import org.apache.ibatis.annotations.Select;
 import org.springframework.stereotype.Repository;
 
@@ -20,6 +20,6 @@ public interface CalculationFormulaRepository {
      * @param type 类型
      * @return 返回记录
      */
-    List<CalculationFormula> findByTypeAndProvince(String type, String provinceEnum);
+    List<tCalculationFormula> findByTypeAndProvince(String type, String provinceEnum);
 
 }

+ 4 - 4
src/main/java/com/syjy/calculate/repository/repositoryImpl/CalculationFormulaRepositoryImpl.java

@@ -1,7 +1,7 @@
 package com.syjy.calculate.repository.repositoryImpl;
 
 import com.syjy.calculate.config.StarterProperties;
-import com.syjy.calculate.entity.CalculationFormula;
+import com.syjy.calculate.entity.tCalculationFormula;
 import com.syjy.calculate.repository.CalculationFormulaRepository;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -89,15 +89,15 @@ public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepos
      * @return
      */
     @Override
-    public List<CalculationFormula> findByTypeAndProvince(String type, String provinceEnum) {
+    public List<tCalculationFormula> findByTypeAndProvince(String type, String provinceEnum) {
         // 模糊查询参数
         provinceEnum = "%" + provinceEnum + ";%";
         // 查询sql
         String sql = "SELECT * from t_calculation_formula where TYPE = ? and PROVINCE_ENUM like ?  ";
         // 根据类型和省调查询公式
-        List<CalculationFormula> calculationFormulaList = new ArrayList<>();
+        List<tCalculationFormula> calculationFormulaList = new ArrayList<>();
         try {
-            calculationFormulaList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(CalculationFormula.class), type, provinceEnum);
+            calculationFormulaList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(tCalculationFormula.class), type, provinceEnum);
         } catch (DataAccessException e) {
             e.printStackTrace();
         }

+ 7 - 7
src/main/java/com/syjy/calculate/service/AccuracyPassRateCalculateService.java

@@ -3,7 +3,7 @@ package com.syjy.calculate.service;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.googlecode.aviator.AviatorEvaluator;
-import com.syjy.calculate.entity.CalculationFormula;
+import com.syjy.calculate.entity.tCalculationFormula;
 import com.syjy.calculate.repository.CalculationFormulaRepository;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -43,7 +43,7 @@ public class AccuracyPassRateCalculateService {
         JSONObject jsonResult = new JSONObject();
         jsonResult.put("result", false);
         // 获取公式
-        List<CalculationFormula> calculationFormulaList = getCalculationFormulaData(type, provinceEnum);
+        List<tCalculationFormula> calculationFormulaList = getCalculationFormulaData(type, provinceEnum);
         if (calculationFormulaList == null || calculationFormulaList.size() == 0) {
             jsonResult.put("msg", "计算失败,未匹配到公式");
             return jsonResult;
@@ -55,7 +55,7 @@ public class AccuracyPassRateCalculateService {
         // 公式
         String formula;
         // 循环公式,依次执行公式
-        for (CalculationFormula calculationFormula : calculationFormulaList) {
+        for (tCalculationFormula calculationFormula : calculationFormulaList) {
             BigDecimal formulaResult = ZERO;
             // 获取公式
             formula = calculationFormula.getFormula();
@@ -116,8 +116,8 @@ public class AccuracyPassRateCalculateService {
                 }
             }
             // 记录本次公式的计算结果
-            resultMap.put("result" + calculationFormula.getOrder(), formulaResult);
-            log.info("result" + calculationFormula.getOrder() + ":" + formulaResult);
+            resultMap.put("result" + calculationFormula.getOrder2(), formulaResult);
+            log.info("result" + calculationFormula.getOrder2() + ":" + formulaResult);
         }
         // 获取最后一个公式计算的结果
         String lastResult = String.valueOf(resultMap.get("result" + calculationFormulaList.size()));
@@ -144,8 +144,8 @@ public class AccuracyPassRateCalculateService {
      * @param provinceEnum 省调(在数据库中省调存储必须带分号,例如:E12;)
      * @return
      */
-    public List<CalculationFormula> getCalculationFormulaData(String type, String provinceEnum) {
-        List<CalculationFormula> calculationFormulaList = new ArrayList<>();
+    public List<tCalculationFormula> getCalculationFormulaData(String type, String provinceEnum) {
+        List<tCalculationFormula> calculationFormulaList = new ArrayList<>();
         // 根据类型从数据库中查出公式列表
         calculationFormulaList = calculationFormulaRepository.findByTypeAndProvince(type, provinceEnum);
         return calculationFormulaList;

+ 1 - 1
src/main/resources/sql/t_calculation_formula.sql

@@ -24,7 +24,7 @@ DROP TABLE IF EXISTS `t_calculation_formula`;
 CREATE TABLE `t_calculation_formula`  (
   `ID` int(0) NOT NULL AUTO_INCREMENT,
   `TYPE` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '公式类型',
-  `ORDER` int(0) NULL DEFAULT NULL COMMENT '公式执行顺讯',
+  `ORDER2` int(0) NULL DEFAULT NULL COMMENT '公式执行顺讯',
   `FORMULA` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '公式内容',
   `PROVINCE_ENUM` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '省调',
   `STATE` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '状态: 0 失效    1 有效',