Преглед на файлове

数据拉取定时任务、逻辑补充

zhouyy преди 1 месец
родител
ревизия
fabc11bb9c

+ 6 - 0
fhKeeper/formulahousekeeper/management-platform/pom.xml

@@ -15,6 +15,12 @@
 
     <dependencies>
 
+        <dependency>
+            <groupId>com.microsoft.sqlserver</groupId>
+            <artifactId>mssql-jdbc</artifactId>
+            <version>10.2.1.jre8</version>
+        </dependency>
+
         <dependency>
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-compress</artifactId>

+ 6 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/entity/ErpOrderInfo.java

@@ -48,4 +48,10 @@ public class ErpOrderInfo extends Model<ErpOrderInfo> {
 
     @TableField(exist = false)
     private String trueProjectId;
+
+    @TableField("dept_id")
+    private String deptId;
+
+    @TableField("dept_name")
+    private String deptName;
 }

+ 12 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/entity/vo/TisTimeVO.java

@@ -0,0 +1,12 @@
+package com.management.platform.entity.vo;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class TisTimeVO {
+    private String orderId;
+    private Integer line;
+    private BigDecimal workTime;
+}

+ 3 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/mapper/ReportMapper.java

@@ -3,6 +3,7 @@ package com.management.platform.mapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.management.platform.entity.Report;
 import com.management.platform.entity.bo.BonusDataBO;
+import com.management.platform.entity.vo.TisTimeVO;
 import com.management.platform.entity.vo.UserProjectBonusTimeVO;
 import com.management.platform.entity.vo.UserRestTimeVO;
 import org.apache.ibatis.annotations.Param;
@@ -254,4 +255,6 @@ public interface ReportMapper extends BaseMapper<Report> {
     List<UserProjectBonusTimeVO> getUserProjectsByBonusBO(BonusDataBO bonusDataBO);
 
     List<UserRestTimeVO> getCompanyUserOverTimeHours(@Param("companyId") Integer companyId,@Param("userId") String userId);
+
+    List<TisTimeVO> getTisTimeByDate(@Param("companyId") Integer companyId,@Param("date") String dateStr);
 }

+ 58 - 4
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/task/DataCollectTask.java

@@ -2,7 +2,10 @@ package com.management.platform.task;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.management.platform.entity.*;
+import com.management.platform.entity.vo.TisTimeVO;
 import com.management.platform.mapper.*;
+import com.zaxxer.hikari.HikariConfig;
+import com.zaxxer.hikari.HikariDataSource;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.core.ParameterizedTypeReference;
 import org.springframework.http.*;
@@ -14,10 +17,12 @@ import org.springframework.util.CollectionUtils;
 import org.springframework.web.client.RestTemplate;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.text.SimpleDateFormat;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @EnableScheduling
@@ -49,6 +54,55 @@ public class DataCollectTask {
     @Resource
     private BustripProjectMapper bustripProjectMapper;
 
+    @Resource
+    private ReportMapper reportMapper;
+
+
+    private static HikariDataSource sqlServerDataSource;
+
+    static {
+        HikariConfig sqlServerConfig = new HikariConfig();
+        sqlServerConfig.setJdbcUrl("jdbc:sqlserver://172.168.10.84:1433;databaseName=UFDATA_001_2023;encrypt=true;trustServerCertificate=true");
+        sqlServerConfig.setUsername("zhangyuhua");
+        sqlServerConfig.setPassword("ZC12zyh18");
+        sqlServerConfig.setMaximumPoolSize(5);
+        sqlServerDataSource = new HikariDataSource(sqlServerConfig);
+    }
+
+
+    public void caDayTisTask(){
+        SimpleDateFormat sdfYmd = new SimpleDateFormat("yyyy-MM-dd");
+        Date date = new Date();
+        String dateStr = sdfYmd.format(date);
+        List<TisTimeVO> timeVOList =  reportMapper.getTisTimeByDate(specialCompanyId,dateStr);
+        for (TisTimeVO tisTimeVO : timeVOList) {
+            String sqlQuery = "select top 1 iRealCOID from ca_batchmap where cMOCode = ? and iMOSubSN = ? ";
+            try (Connection connection = sqlServerDataSource.getConnection()) {
+                PreparedStatement queryStmt = connection.prepareStatement(sqlQuery);
+                queryStmt.setString(1,tisTimeVO.getOrderId());
+                queryStmt.setInt(2,tisTimeVO.getLine());
+                ResultSet queryRs = queryStmt.executeQuery();
+                if (queryRs.next()) {
+                    String iRealCOID = queryRs.getString("iRealCOID");
+                    String sqlInsert = "insert into CA_DayTiS(cPPID,iRealWkt,dDate) values(?,?,?)";
+                    PreparedStatement insertStmt = connection.prepareStatement(sqlInsert);
+                    insertStmt.setString(1,iRealCOID);
+                    insertStmt.setBigDecimal(2,tisTimeVO.getWorkTime());
+                    insertStmt.setString(3,dateStr);
+                    int i = insertStmt.executeUpdate();
+                    if(i>0){
+                        System.out.println("执行成功");
+                    }else{
+                        System.out.println(iRealCOID+"执行失败");
+                    }
+                }
+            } catch (SQLException e) {
+                System.err.println("数据库操作错误: " + e.getMessage());
+            }
+        }
+    }
+
+
 
     @Scheduled(cron = "0 0 1 * * ?")
     @Async

+ 2 - 2
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/ErpOrderInfoMapper.xml

@@ -4,10 +4,10 @@
 <mapper namespace="com.management.platform.mapper.ErpOrderInfoMapper">
 
     <insert id="batchInsert">
-        insert into erp_order_info(order_id, project_id, project_name, line, status,rels_date)
+        insert into erp_order_info(order_id, project_id, project_name, line, status,rels_date,dept_id,dept_name)
         VALUES
             <foreach collection="resList" separator="," item="res">
-                (#{res.orderId},#{res.projectId},#{res.projectName},#{res.line},#{res.status},#{res.relsDate})
+                (#{res.orderId},#{res.projectId},#{res.projectName},#{res.line},#{res.status},#{res.relsDate},#{res.deptId},#{res.deptName})
             </foreach>
     </insert>
     <select id="getExistIds" resultType="java.lang.String">

+ 6 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/ReportMapper.xml

@@ -1533,6 +1533,12 @@
         group by report.creator_id
         ) tmp2 on tmp1.id = tmp2.userId
     </select>
+    <select id="getTisTimeByDate" resultType="com.management.platform.entity.vo.TisTimeVO">
+        select extra_field4 as orderId,extra_field5 as line,sum(working_time) as workTime
+        from report
+        where company_id = #{companyId} and create_date = #{date}
+        group by extra_field4,extra_field5
+    </select>
 
     <update id="batchUpdateReportStageToNull">
         update report set stage=null where id in