2 次代碼提交 ef95fe6b37 ... 8d56d1e95d

作者 SHA1 備註 提交日期
  yuzijian 8d56d1e95d Merge remote-tracking branch 'origin/master' 2 年之前
  yuzijian 9bd064aae1 新增mybatis 2 年之前

+ 16 - 0
pom.xml

@@ -94,6 +94,22 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-thymeleaf</artifactId>
         </dependency>
+        <!--mybatis plus extension,包含了mybatis plus core-->
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-extension</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>
+        </dependency>
+        <dependency>
+            <groupId>org.hibernate</groupId>
+            <artifactId>hibernate-core</artifactId>
+            <version>5.4.8.Final</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 1 - 0
src/main/java/com/syjy/calculate/CalculationApplication.java

@@ -4,6 +4,7 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 
 @SpringBootApplication
+
 public class CalculationApplication {
 
     public static void main(String[] args) {

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

@@ -3,6 +3,7 @@ package com.syjy.calculate.config;
 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.repository.repositoryImpl.CalculationFormulaRepositoryImpl;
 import com.syjy.calculate.service.AccuracyPassRateCalculateService;
 import com.syjy.calculate.util.CreateAndInsertSqlUtil;
@@ -10,10 +11,14 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.Configuration;
 
 @EnableConfigurationProperties(StarterProperties.class)
 @Configuration
+@ComponentScan(basePackages = {"com.syjy.calculate.mapper"})
+
+
 public class StarterAutoConfigure {
 
     @Bean
@@ -58,4 +63,11 @@ public class StarterAutoConfigure {
         return new JarCalculate();
     }
 
+
+/*    @Bean
+    @ConditionalOnMissingBean
+    @ConditionalOnProperty(prefix = "calculate.service", value = "enabled", havingValue = "true")
+    CalculationFormulaMapper calculationFormulaMapper() {
+        return new CalculationFormulaMapper();
+    }*/
 }

+ 75 - 3
src/main/java/com/syjy/calculate/conotroller/JarCalculate.java

@@ -1,15 +1,87 @@
 package com.syjy.calculate.conotroller;
 
+import com.syjy.calculate.entity.CalculationFormula;
+import com.syjy.calculate.mapper.CalculationFormulaMapper;
+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.dao.DataAccessException;
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
 
 @Controller
+@RequestMapping("jarCalculate")
 public class JarCalculate {
-    @PostMapping("/jarCalculate/add")
+    @Resource
+    CalculationFormulaMapper calculationFormulaMapper;
+    @Autowired
+    CalculationFormulaRepository calculationFormulaRepository;
+
+   @GetMapping("test")
     @ResponseBody
     public String test() {
         String aa = "1112";
         return aa;
     }
+ /*   @GetMapping("select")
+    @ResponseBody
+    public ResponseVO select() {
+        List<CalculationFormula> calculationFormulaList = new ArrayList<>();
+        calculationFormulaList =calculationFormulaMapper.findAll();
+        System.out.println("测试"+calculationFormulaList);
+        return ResponseVO.success(calculationFormulaList);
+    }
+
+    @PostMapping("add")
+    @ResponseBody
+    public ResponseVO add(@RequestBody CalculationFormula calculationFormula ) {
+        String type =calculationFormula.getType();
+        Integer order =calculationFormula.getOrder();
+        String formula =calculationFormula.getFormula();
+        String province =calculationFormula.getProvinceEnum();
+        String state =calculationFormula.getState();
+        try {
+
+            calculationFormulaMapper.add(type,order,formula,province,state);
+        } catch (DataAccessException e) {
+            e.printStackTrace();
+            return ResponseVO.fail("添加失败");
+        }
+        return ResponseVO.success("添加成功");
+    }
+
+    @PostMapping("edit")
+    @ResponseBody
+    public ResponseVO edit(@RequestBody CalculationFormula calculationFormula){
+        Integer id =calculationFormula.getId();
+        String type =calculationFormula.getType();
+        Integer order =calculationFormula.getOrder();
+        String formula =calculationFormula.getFormula();
+        String province =calculationFormula.getProvinceEnum();
+        String state =calculationFormula.getState();
+        try {
+            calculationFormulaMapper.edit(id,type,order,formula,province,state);
+        } catch (DataAccessException e) {
+            e.printStackTrace();
+            return ResponseVO.fail("修改失败");
+        }
+        return ResponseVO.success("修改成功");
+    }
+    @PostMapping("delete")
+    @ResponseBody
+    public ResponseVO delete(@RequestBody CalculationFormula calculationFormula){
+        try {
+            calculationFormulaMapper.delete(calculationFormula.getId());
+        } catch (DataAccessException e) {
+            e.printStackTrace();
+            return ResponseVO.fail("删除失败");
+        }
+        return ResponseVO.success("删除成功");
+    }*/
 }

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

@@ -4,6 +4,8 @@ import lombok.Data;
 import lombok.Getter;
 import lombok.Setter;
 
+import javax.persistence.Table;
+
 /**
  * 计算公式
  *

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

@@ -0,0 +1,30 @@
+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;
+
+@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);
+}

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

@@ -0,0 +1,8 @@
+<?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>

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

@@ -1,6 +1,7 @@
 package com.syjy.calculate.repository;
 
 import com.syjy.calculate.entity.CalculationFormula;
+import org.apache.ibatis.annotations.Select;
 import org.springframework.stereotype.Repository;
 
 import java.util.List;
@@ -10,16 +11,15 @@ public interface CalculationFormulaRepository {
 
     /**
      * 创建公式表
-     *
      */
     void createTable();
 
     /**
      * 查询公式数据
      *
-     * @param type     类型
+     * @param type 类型
      * @return 返回记录
      */
-    List<CalculationFormula> findByTypeAndProvince(String type,String provinceEnum);
+    List<CalculationFormula> findByTypeAndProvince(String type, String provinceEnum);
 
 }

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

@@ -103,4 +103,6 @@ public class CalculationFormulaRepositoryImpl implements CalculationFormulaRepos
         }
         return calculationFormulaList;
     }
+
+
 }

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

@@ -169,5 +169,8 @@ public class AccuracyPassRateCalculateService {
         return result;
     }
 
+
+
+
 }
 

+ 4 - 5
src/main/java/com/syjy/calculate/util/CreateAndInsertSqlUtil.java

@@ -19,7 +19,7 @@ import java.util.List;
 
 @Component
 public class CreateAndInsertSqlUtil {
-    private static final String FILE_NAME = "../../../sql/t_calculation_formula.sql";
+    private static final String FILE_NAME = "sql/test.sql";
 
     /**
      * 需要生成的表
@@ -49,10 +49,10 @@ public class CreateAndInsertSqlUtil {
      * @param dbName    数据库名
      */
     @SneakyThrows
-    public void start(String dbSetting, String dbName) {
+    public  void start(String dbSetting, String dbName) {
         Db db = DbUtil.use(DSFactory.get(dbSetting));
-
-        FileWriter sqlFileWriter = FileWriter.create(new File(FILE_NAME));
+            File test =new File(FILE_NAME);
+        FileWriter sqlFileWriter = FileWriter.create(test);
         sqlFileWriter.write("");
         sqlFileWriter.append("USE " + dbName + ";\n");
         sqlFileWriter.append("SET NAMES utf8mb4;\n");
@@ -112,7 +112,6 @@ public class CreateAndInsertSqlUtil {
         }
         sqlFileWriter.append("\n\n\n");
         sqlFileWriter.append("SET FOREIGN_KEY_CHECKS = 1;\n");
-
     }
 
     @Data