Browse Source

核酸数据

LIVE_YE 3 years ago
parent
commit
0ee53cdb53

+ 0 - 9
boman-web-core/src/main/java/com/boman/web/core/controller/AccountingDataController.java

@@ -92,13 +92,4 @@ public class AccountingDataController extends BaseController {
         taskService.insertAccountingData();
     }
 
-
-    /**
-     * 从第三方库获取核酸数据
-     */
-    @PostMapping("/nucleicAcid/thirdNucleicAcid")
-    public void thirdNucleicAcid()
-    {
-        accountingDataService.thirdNucleicAcid();
-    }
 }

+ 7 - 0
boman-web-core/src/main/java/com/boman/web/core/controller/TaskController.java

@@ -49,6 +49,13 @@ public class TaskController {
         taskService.insertAccountingData();
     }
 
+
+    @GetMapping("/thirdNucleicAcid")
+    private void thirdNucleicAcid() {
+        taskService.thirdNucleicAcid();
+    }
+
+
     @GetMapping("/pphshj")
     private void pphshj() {
         taskService.pphshj();

+ 2 - 2
boman-web-core/src/main/java/com/boman/web/core/mapper/AccountingDataMapper.java

@@ -38,7 +38,7 @@ public interface AccountingDataMapper {
      * @param accountingData
      * @return
      */
-   int insertAccountingData(AccountingData accountingData);
+   int insertAccountingData(AccountingDataVo accountingData);
 
     /**根据id查询
      *
@@ -51,5 +51,5 @@ public interface AccountingDataMapper {
 
     List<AccountingDataVo> getAllData();
 
-    List<AccountingData> thirdNucleicAcid();
+    List<AccountingDataVo> thirdNucleicAcid(@Param("startTime")String startTime,@Param("endTime")String endTime);
 }

+ 74 - 2
boman-web-core/src/main/java/com/boman/web/core/service/TaskService.java

@@ -10,6 +10,7 @@ import com.boman.common.core.utils.DateUtils;
 import com.boman.common.core.utils.StringUtils;
 import com.boman.common.core.utils.number.NumberUtils;
 import com.boman.common.core.utils.obj.ObjectUtils;
+import com.boman.common.datasource.annotation.Master;
 import com.boman.common.redis.service.RedisService;
 import com.boman.common.security.service.TokenService;
 import com.boman.domain.Czrk;
@@ -23,6 +24,7 @@ import com.boman.web.core.domain.AccountingData;
 import com.boman.web.core.domain.BirthRecords;
 import com.boman.web.core.domain.TSampling514;
 import com.boman.web.core.domain.vo.AccountingDataVo;
+import com.boman.web.core.mapper.AccountingDataMapper;
 import com.boman.web.core.mapper.CzrkMapper;
 import com.boman.web.core.mapper.GridInfoMapper;
 import com.boman.web.core.service.accounting.IAccountingDataService;
@@ -33,14 +35,20 @@ import com.boman.web.core.service.czrk.ICzrkJzdzService;
 import com.boman.web.core.service.ip.IpTimesService;
 import com.boman.web.core.utils.HttpClientUtils;
 import org.apache.commons.lang3.BooleanUtils;
+import org.apache.ibatis.session.ExecutorType;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.GetMapping;
 
 import javax.annotation.Resource;
 import java.io.IOException;
 import java.sql.Timestamp;
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
@@ -81,6 +89,9 @@ public class TaskService {
 
     @Resource
     private IAccountingDataService accountingDataService;
+
+    @Resource
+    private SqlSessionFactory sqlSessionFactory;
     private static final String tableName = "attendance_table";
 
     /**
@@ -653,10 +664,10 @@ public class TaskService {
                 String data = HttpClientUtils.doGet(http, paramMap);
 
                 if (StringUtils.isNotBlank(data)) {
-                    List<AccountingData> list = JSONObject.parseArray(data, AccountingData.class);
+                    List<AccountingDataVo> list = JSONObject.parseArray(data, AccountingDataVo.class);
                     if (list != null && list.size() > 0) {
                         //插入数据
-                        accountingDataService.insertAccountingData(list, accountingData);
+                        //accountingDataService.insertAccountingData(list);
                     }
                 }
             } catch (IOException e) {
@@ -665,6 +676,26 @@ public class TaskService {
         }
     }
 
+    //@Scheduled(cron = "0 0/10 * * * ? ")
+    public void thirdNucleicAcid(){
+        String startTime = redisService.getCacheObject("startTime");
+        if(StringUtils.isEmpty(startTime)){
+            startTime = "2022-05-14 00:00:00";
+        }
+        //开始时间往后推10分钟
+        String endTime = DateUtils.plusSeconds(startTime, 10);
+
+        accountingDataService.thirdNucleicAcid(startTime,endTime);
+
+        redisService.setCacheObject("startTime", endTime);
+
+        if(!startTime.equals("2022-05-18 18:00:00")){
+            this.thirdNucleicAcid();
+        }
+
+    }
+
+
     /***
      *  匹配核酸和户籍数据
      */
@@ -749,4 +780,45 @@ public class TaskService {
     public void upStarTime(String starTim) {
         redisService.setCacheObject("startTime", starTim);
     }
+
+
+    /**
+     * 新增
+     *
+     * @param accountingDataList
+     * @return
+     */
+    @Transactional(propagation = Propagation.REQUIRES_NEW)
+    @Master
+    public int insertAccountingData(List<AccountingDataVo> accountingDataList) {
+        SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
+        AccountingDataMapper mapper = sqlSession.getMapper(AccountingDataMapper.class);
+
+        System.out.println("batchInsert 插入开始========");
+        long start = System.currentTimeMillis();
+        Czrk czrk = new Czrk();
+
+        for (AccountingDataVo accountingData : accountingDataList) {
+            String zjhm = accountingData.getZjhm();
+            if (StringUtils.isNotBlank(zjhm)) {
+                czrk.setIdCard(zjhm);
+                czrk.setNucleicAcidTime(accountingData.getCjsj());
+                //去更新常住人口表中数据
+                czrkMapper.updateCzrkByNucleicAcid(czrk);
+            }
+            String mainKey = accountingData.getMainKey();
+            accountingData.setId(mainKey);
+            int result = mapper.selectById(mainKey);
+            if (result == 0) {
+                accountingData.setId(mainKey);
+                mapper.insertAccountingData(accountingData);
+            }
+        }
+
+        sqlSession.flushStatements();
+        long end = System.currentTimeMillis();
+        System.out.println("---------------插入核酸数据耗时" + (end - start) + "---------------");
+        return 0;
+    }
+
 }

+ 18 - 51
boman-web-core/src/main/java/com/boman/web/core/service/accounting/AccountingDataServiceImpl.java

@@ -10,6 +10,8 @@ import com.boman.common.core.exception.BaseException;
 import com.boman.common.core.utils.sql.SqlUtil;
 import com.boman.common.core.web.page.PageDomain;
 import com.boman.common.core.web.page.TableSupport;
+import com.boman.common.datasource.annotation.Master;
+import com.boman.common.datasource.annotation.Slave;
 import com.boman.domain.*;
 import com.alibaba.fastjson.JSON;
 import com.boman.common.core.utils.DateUtils;
@@ -24,6 +26,7 @@ import com.boman.web.core.domain.vo.AccountingDataVo;
 import com.boman.web.core.mapper.AccountingDataMapper;
 import com.boman.web.core.mapper.CzrkMapper;
 import com.boman.web.core.mapper.TSampling514Mapper;
+import com.boman.web.core.service.TaskService;
 import com.boman.web.core.utils.*;
 import com.boman.web.core.utils.AuthUtils;
 import com.boman.web.core.utils.CzrkUtils;
@@ -33,6 +36,8 @@ import org.apache.ibatis.session.ExecutorType;
 import org.apache.ibatis.session.SqlSession;
 import org.apache.ibatis.session.SqlSessionFactory;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.io.IOException;
@@ -66,6 +71,9 @@ public class AccountingDataServiceImpl implements IAccountingDataService {
     @Resource
     private TSampling514Mapper TSampling514Mapper;
 
+    @Resource
+    TaskService taskService;
+
     /**
      * 潜山核酸数据列表页(户籍地址)
      *
@@ -272,54 +280,6 @@ public class AccountingDataServiceImpl implements IAccountingDataService {
         }
     }
 
-    /**
-     * 新增
-     *
-     * @param accountingDataList
-     * @return
-     */
-    @Override
-    public int insertAccountingData(List<AccountingData> accountingDataList, AccountingDataVo accountingDatav) {
-        SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
-        AccountingDataMapper mapper = sqlSession.getMapper(AccountingDataMapper.class);
-
-        System.out.println("batchInsert 插入开始========");
-        long start = System.currentTimeMillis();
-        Czrk czrk = new Czrk();
-
-        Boolean bl = false;
-        if (accountingDatav == null) {
-            bl = true;
-        }
-
-        for (int i = 0; i < accountingDataList.size(); i++) {
-            if (bl) {
-                AccountingData accountingData = accountingDataList.get(i);
-                String zjhm = accountingData.getZjhm();
-                if (StringUtils.isNotBlank(zjhm)) {
-                    czrk.setIdCard(zjhm);
-                    czrk.setNucleicAcidTime(accountingData.getCjsj());
-                    //去更新常住人口表中数据
-                    czrkMapper.updateCzrkByNucleicAcid(czrk);
-                }
-                String mainKey = accountingData.getMainKey();
-                accountingData.setId(mainKey);
-                int result = accountingDataMapper.selectById(mainKey);
-                if (result == 0) {
-                    accountingDataMapper.insertAccountingData(accountingData);
-                }
-            } else {
-                if (accountingDataList.get(i).getZjhm().equals(accountingDatav.getZjhm())) {
-                    bl = true;
-                }
-            }
-
-        }
-        sqlSession.flushStatements();
-        long end = System.currentTimeMillis();
-        System.out.println("---------------插入核酸数据耗时" + (end - start) + "---------------");
-        return 0;
-    }
 
     @Override
     public AccountingDataVo getAccountingDataOne() {
@@ -344,9 +304,16 @@ public class AccountingDataServiceImpl implements IAccountingDataService {
     /**
      * 从第三方库获取核酸数据
      */
+    @Slave
     @Override
-    public void thirdNucleicAcid() {
-        List<AccountingData> accountingDataVos = accountingDataMapper.thirdNucleicAcid();
-        insertAccountingData(accountingDataVos, new AccountingDataVo());
+    public void thirdNucleicAcid(String startTime,String endTime) {
+        System.out.println("batchInsert 查询数据开始========");
+        long start1 = System.currentTimeMillis();
+        List<AccountingDataVo> accountingDataVos = accountingDataMapper.thirdNucleicAcid(startTime,endTime);
+        if(accountingDataVos!=null){
+            taskService.insertAccountingData(accountingDataVos);
+        }
+        long end1 = System.currentTimeMillis();
+        System.out.println("---------------查询数据耗时" + (end1 - start1) + "---------------");
     }
 }

+ 2 - 2
boman-web-core/src/main/java/com/boman/web/core/service/accounting/IAccountingDataService.java

@@ -41,7 +41,7 @@ public interface IAccountingDataService {
      * @param accountingDataVoList
      * @return
      */
-    int insertAccountingData(List<AccountingData> accountingDataVoList,AccountingDataVo accountingData);
+    //int insertAccountingData(List<AccountingDataVo> accountingDataVoList);
 
     AccountingDataVo getAccountingDataOne();
 
@@ -54,5 +54,5 @@ public interface IAccountingDataService {
     /**
      * 从第三方库获取核酸数据
      */
-    void thirdNucleicAcid();
+    void thirdNucleicAcid(String startTime,String endTime);
 }

+ 82 - 41
boman-web-core/src/main/resources/mapper/AccountingDateMapper.xml

@@ -54,21 +54,51 @@
     </resultMap>
 
     <sql id="selectAccountingDataVo">
-        select d.id,d.jcsj, d.lxdh ,d.address, d.batch_number,d.focus_person,d.jcjg,d.from_city,d.jcdd,d.cjdd,d.to_city,d.source,d.zjhm,d.cjsj,d.certificate_no_type,d.xm,d.transit,d.collector_name,d.cjssxq,d.main_key,d.modify_date, d.create_by, d.create_time, d.update_by, d.update_time from accounting_data d
+        select d.id,
+               d.jcsj,
+               d.lxdh,
+               d.address,
+               d.batch_number,
+               d.focus_person,
+               d.jcjg,
+               d.from_city,
+               d.jcdd,
+               d.cjdd,
+               d.to_city,
+               d.source,
+               d.zjhm,
+               d.cjsj,
+               d.certificate_no_type,
+               d.xm,
+               d.transit,
+               d.collector_name,
+               d.cjssxq,
+               d.main_key,
+               d.modify_date,
+               d.create_by,
+               d.create_time,
+               d.update_by,
+               d.update_time
+        from accounting_data d
     </sql>
 
     <select id="selectAccountingDataHjList" parameterType="com.boman.web.core.domain.vo.AccountingDataVo"
             resultMap="AccountingDataResult">
         SELECT
-        r.id,r.user_name as xm,r.id_card as zjhm,r.province,r.city,r.region,r.village_towns,r.village,r.now_in,r.phone_num,d.lxdh,d.jcsj,d.jcdd,d.cjdd,d.cjsj
+        r.id,r.user_name as xm,r.id_card as
+        zjhm,r.province,r.city,r.region,r.village_towns,r.village,r.now_in,r.phone_num,d.lxdh,d.jcsj,d.jcdd,d.cjdd,d.cjsj
         FROM czrk r left join `accounting_data` d on r.id_card = d.zjhm
         <where>
             r.is_del = 'N'
             and r.status = '1'
             <if test="zjhm != null  and zjhm != ''">and r.id_card = #{zjhm}</if>
             <if test="xm != null  and xm != ''">and r.user_name like concat(#{xm}, '%')</if>
-            <if test="params.startTime != null  and params.startTime != '' and params.startTime != 'null'">and DATE_FORMAT(d.cjsj,'%Y-%m-%d %H:%i:%s') &gt;= DATE_FORMAT(#{params.startTime},'%Y-%m-%d %H:%i:%s')</if>
-            <if test="params.endTime != null  and params.endTime != ''  and params.endTime != 'null'">and DATE_FORMAT(d.cjsj,'%Y-%m-%d %H:%i:%s') &lt;= DATE_FORMAT(#{params.endTime},'%Y-%m-%d %H:%i:%s')</if>
+            <if test="params.startTime != null  and params.startTime != '' and params.startTime != 'null'">and
+                DATE_FORMAT(d.cjsj,'%Y-%m-%d %H:%i:%s') &gt;= DATE_FORMAT(#{params.startTime},'%Y-%m-%d %H:%i:%s')
+            </if>
+            <if test="params.endTime != null  and params.endTime != ''  and params.endTime != 'null'">and
+                DATE_FORMAT(d.cjsj,'%Y-%m-%d %H:%i:%s') &lt;= DATE_FORMAT(#{params.endTime},'%Y-%m-%d %H:%i:%s')
+            </if>
             <if test="isNucleicAcid != null  and isNucleicAcid != ''">and r.is_nucleicAcid = #{isNucleicAcid}</if>
             <if test="provinceId != null  and provinceId != ''">and r.province_id = #{provinceId}</if>
             <if test="cityId != null  and cityId != ''">and r.city_id = #{cityId}</if>
@@ -82,7 +112,8 @@
     <select id="selectAccountingDataJzdzList" parameterType="com.boman.web.core.domain.vo.AccountingDataVo"
             resultMap="AccountingDataResult">
         select r.user_name as xm, r.phone_num, r.id_card as zjhm,
-        z.province as provinceXjd , z.city as cityXjd,z.region as regionXjd , z.town as villageTownsXjd, z.village as villageXjd,z.now_in,d.lxdh,d.jcsj,d.jcdd,d.cjdd,d.cjsj
+        z.province as provinceXjd , z.city as cityXjd,z.region as regionXjd , z.town as villageTownsXjd, z.village as
+        villageXjd,z.now_in,d.lxdh,d.jcsj,d.jcdd,d.cjdd,d.cjsj
         from czrk r left join czrk_jzdz z on r.id =z.czrk_id
         left join `accounting_data` d on r.id_card = d.zjhm
         <where>
@@ -90,8 +121,12 @@
             and r.status = '1'
             <if test="zjhm != null  and zjhm != ''">and r.id_card = #{zjhm}</if>
             <if test="xm != null  and xm != ''">and r.user_name like concat(#{xm}, '%')</if>
-            <if test="params.startTime != null  and params.startTime != '' and params.startTime != 'null'">and DATE_FORMAT(d.cjsj,'%Y-%m-%d %H:%i:%s') &gt;= DATE_FORMAT(#{params.startTime},'%Y-%m-%d %H:%i:%s')</if>
-            <if test="params.endTime != null  and params.endTime != '' and params.endTime != 'null'">and DATE_FORMAT(d.cjsj,'%Y-%m-%d %H:%i:%s') &lt;= DATE_FORMAT(#{params.endTime},'%Y-%m-%d %H:%i:%s')</if>
+            <if test="params.startTime != null  and params.startTime != '' and params.startTime != 'null'">and
+                DATE_FORMAT(d.cjsj,'%Y-%m-%d %H:%i:%s') &gt;= DATE_FORMAT(#{params.startTime},'%Y-%m-%d %H:%i:%s')
+            </if>
+            <if test="params.endTime != null  and params.endTime != '' and params.endTime != 'null'">and
+                DATE_FORMAT(d.cjsj,'%Y-%m-%d %H:%i:%s') &lt;= DATE_FORMAT(#{params.endTime},'%Y-%m-%d %H:%i:%s')
+            </if>
             <if test="isNucleicAcid != null  and isNucleicAcid != ''">and r.is_nucleicAcid = #{isNucleicAcid}</if>
             <if test="provinceIdXjd != null and provinceIdXjd != ''">and z.province_id = #{provinceIdXjd}</if>
             <if test="cityIdXjd != null and cityIdXjd != ''">and z.city_id = #{cityIdXjd}</if>
@@ -129,6 +164,7 @@
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="id != null">#{id},</if>
+            <if test="jcsj != null">#{jcsj},</if>
             <if test="lxdh != null">#{lxdh},</if>
             <if test="address != null">#{address},</if>
             <if test="batchNumber != null">#{batchNumber},</if>
@@ -151,47 +187,52 @@
     </insert>
 
     <select id="selectById" parameterType="String" resultType="int">
-        select count(1) from accounting_data where id = #{id}
+        select count(1)
+        from accounting_data
+        where id = #{id}
     </select>
     <select id="getExport" resultMap="AccountingDataResult">
 
     </select>
     <select id="getAccountingDataOne" resultMap="AccountingDataResult">
-        select id,cjsj,lxdh,create_date,modify_date FROM accounting_data order by cjsj desc limit 1;
+        select id, cjsj, lxdh, create_date, modify_date
+        FROM accounting_data
+        order by cjsj desc limit 1;
     </select>
     <select id="getAllData" resultMap="AccountingDataResult">
-        select id,cjsj,lxdh,create_date,zjhm,xm FROM accounting_data
+        select id, cjsj, lxdh, create_date, zjhm, xm
+        FROM accounting_data
     </select>
-    <select id="thirdNucleicAcid" resultType="com.boman.web.core.domain.AccountingData">
-        select
-        a.oid as main_key,
-        a.`name` as xm,
-        a.id_card as zjhm,
-        a.tel as lxdh,
-        a.collect_time as cjsj,
-        c.dis_name_str as cjssxq,
-        b.`name` as cjdd,
-        a.verify_finish_time as jcsj,
-        a.verify_result as jcjg,
-        a.create_date as create_date,
-        a.modify_date as modify_date ,
-        a.source as source ,
-        a.batch_number as batch_number,
-        a.collector_name as collector_name,
-        a.verify_point_name as jcdd,
-        a.certificate_no_type as certificate_no_type ,
-        a.focus_person as focus_person ,
-        a.from_city as from_city,
-        a.to_city as to_city ,
-        a.address as  address,
-        a.transit as transit
-        from t_sampling_dt513 a
-        left join t_collect_verify_point b on a.collect_oid = b.oid
-        left join t_sys_district c on b.district_oid = c.oid
-        where use_flag = 'Y' and type = 'h'
-        and (c.dis_name_str like '%潜山%'
-        or left(a.id_card,6) in ('340824','340882'))
-        and  (`a`.`collect_time` >= '2022-5-14 6:00:00'
-        AND `a`.`collect_time` <= '2022-5-14 6:30:00');
+    <select id="thirdNucleicAcid" resultMap="AccountingDataResult">
+        select a.oid                 as main_key,
+               a.`name`              as xm,
+               a.id_card             as zjhm,
+               a.tel                 as lxdh,
+               a.collect_time        as cjsj,
+               c.dis_name_str        as cjssxq,
+               b.`name`              as cjdd,
+               a.verify_finish_time  as jcsj,
+               a.verify_result       as jcjg,
+               a.create_date         as create_date,
+               a.modify_date         as modify_date,
+               a.source              as source,
+               a.batch_number        as batch_number,
+               a.collector_name      as collector_name,
+               a.verify_point_name   as jcdd,
+               a.certificate_no_type as certificate_no_type,
+               a.focus_person        as focus_person,
+               a.from_city           as from_city,
+               a.to_city             as to_city,
+               a.address             as address,
+               a.transit             as transit
+        from t_sampling_514 a
+                 left join t_collect_verify_point b on a.collect_oid = b.oid
+                 left join t_sys_district c on b.district_oid = c.oid
+        where use_flag = 'Y'
+          and type = 'h'
+          and (c.dis_name_str like '%潜山%'
+            or left (a.id_card,6) in ('340824','340882'))
+          and (`a`.`collect_time` > #{startTime}
+            AND #{endTime} >= `a`.`collect_time`);
     </select>
 </mapper>