Kaynağa Gözat

百度地图

xiaochan 2 yıl önce
ebeveyn
işleme
6556cc3d52

+ 1 - 2
src/main/java/thyyxxk/webserver/aop/aspect/SqlStringIsBlakToNullAop.java

@@ -5,6 +5,7 @@ import org.aspectj.lang.JoinPoint;
 import org.aspectj.lang.annotation.Aspect;
 import org.aspectj.lang.annotation.Before;
 import org.aspectj.lang.annotation.Pointcut;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 @Aspect
@@ -12,7 +13,6 @@ import org.springframework.stereotype.Component;
 @Slf4j
 public class SqlStringIsBlakToNullAop {
 
-
     @Pointcut("@annotation(thyyxxk.webserver.aop.interfaces.SqlStringIsBlakToNull)")
     public void pointcut() {
     }
@@ -24,5 +24,4 @@ public class SqlStringIsBlakToNullAop {
         log.info("参数:{}", args);
     }
 
-    //  1431   D430105019925
 }

+ 6 - 2
src/main/java/thyyxxk/webserver/config/StartAutoRequestService.java

@@ -18,7 +18,11 @@ public class StartAutoRequestService implements CommandLineRunner {
 
     @Override
     public void run(String... args) throws Exception {
-//        server.startServer();
-        log.info("软件启动");
+        try {
+            server.startServer();
+        } catch (Exception ignored) {
+        } finally {
+            log.info("软件启动");
+        }
     }
 }

+ 28 - 0
src/main/java/thyyxxk/webserver/controller/reports/PatientDistributionAddressController.java

@@ -0,0 +1,28 @@
+package thyyxxk.webserver.controller.reports;
+
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import thyyxxk.webserver.entity.ResultVo;
+import thyyxxk.webserver.entity.inpatient.patient.Patient;
+import thyyxxk.webserver.service.reports.PatientDistributionAddressServer;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/PatientDistributionAddress")
+public class PatientDistributionAddressController {
+
+    private final PatientDistributionAddressServer server;
+
+    public PatientDistributionAddressController(PatientDistributionAddressServer server) {
+        this.server = server;
+    }
+
+    @GetMapping("/patientAddress")
+    public ResultVo<List<Patient>> patientAddress() {
+        return server.patientAddress();
+    }
+
+
+}

+ 8 - 4
src/main/java/thyyxxk/webserver/dao/his/medicalinsurance/UpIdCollectionDao.java

@@ -61,8 +61,11 @@ public interface UpIdCollectionDao {
             "       psn_idet_type as  sp_psn_type " +
             "from t_si_setlinfo a," +
             " t_si_pat_info b " + "where a.pat_no=b.pat_no and a.times=b.times " +
-            "and a.ledger_sn = b.ledger_sn  " + "and a.pat_no = #{patNo} and a.times = #{times} " + "and a.ledger_sn = #{ledgerSn} " + "and a.revoked = 0 ")
-    SetlinfoUpld setlinfo1(@Param("patNo") String patNo, @Param("times") Integer times, @Param("ledgerSn") Integer ledgerSn);
+            "and a.ledger_sn = b.ledger_sn  " + "and a.pat_no = #{patNo} and a.times = #{times} " +
+            "and a.ledger_sn = #{ledgerSn} " + "and a.revoked = 0 ")
+    SetlinfoUpld setlinfo1(@Param("patNo") String patNo,
+                           @Param("times") Integer times,
+                           @Param("ledgerSn") Integer ledgerSn);
 
 
     @Select("select               (select si_code from zd_country_code where code = country)        as ntly /*国籍*/,\n" +
@@ -80,7 +83,7 @@ public interface UpIdCollectionDao {
             "                      where code = contact_relation)            as patn_rlts /*与患者的关系*/,\n" +
             "                     contact_phone                              as coner_tel /*联系人电话*/,\n" +
             "                     coma_days_before_admiss + '/' + coma_hours_before_admiss + '/' +\n" +
-            "                     coma_minutes_before_admiss                 as pwcry_bfadm_coma_dur/*颅脑损伤患者入院前昏迷时长*/,\n" +
+            "                     coma_minutes_before_admiss                 as pwcry_bfadm_coma_dura/*颅脑损伤患者入院前昏迷时长*/,\n" +
             "                     coma_days_after_admiss + '/' + coma_hours_after_admiss + '/' +\n" +
             "                     coma_minutes_after_admiss                  as pwcry_afadm_coma_dura/*颅脑损伤患者入院后昏迷时长*/,\n" +
             "                     zy_dismiss_way                             as dscg_way /*离院方式*/,\n" +
@@ -510,7 +513,8 @@ public interface UpIdCollectionDao {
     @Select("select rtrim(inpatient_no) inpatient_no,admiss_times,rtrim(dis_diag) dis_diag,case admiss_status when '' then null else admiss_status end admiss_cond " + "from ba_first_page1 " + "where isnull(dis_diag,'') <> '' and inpatient_no = #{patNo} and admiss_times = #{times} ")
     List<YbZyDisDiag> huanZheBingAnShouYeZhenDuanRuYuanBingQing(String patNo, Integer times);
 
-    @Update("<script>" + "<foreach collection='list' item='item' separator=';'>" + "update zy_dis_diag_yb set admiss_cond = #{item.admissCond} where inpatient_no = #{item.inpatientNo} and admiss_times = #{item.admissTimes} and dis_diag_no = #{item.disDiagNo}" + "</foreach>" + "</script>")
+    @Update("<script>" + "<foreach collection='list' item='item' separator=';'>" +
+            "update zy_dis_diag_yb set admiss_cond = #{item.admissCond} where inpatient_no = #{item.inpatientNo} and admiss_times = #{item.admissTimes} and dis_diag_no = #{item.disDiagNo}" + "</foreach>" + "</script>")
     void genXingLaoZhenDuan(@Param("list") List<YbZyDisDiag> ybZyDisDiagList);
 
     @Select("select rtrim(name) from zd_country_code where si_code = #{ntly}")

+ 47 - 0
src/main/java/thyyxxk/webserver/dao/his/reports/PatientDistributionAddressDao.java

@@ -0,0 +1,47 @@
+package thyyxxk.webserver.dao.his.reports;
+
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
+import thyyxxk.webserver.entity.inpatient.patient.Patient;
+
+import java.util.List;
+
+@Mapper
+public interface PatientDistributionAddressDao {
+    // province_code = (select name from t_region where code = province_code),
+    // city_code     = (select name from t_region where code = city_code),
+    // district_code = (select name from t_region where code = district_code),
+    // a_patient_mi 省市区
+
+    @Select("select inpatient_no, " +
+            "       latitude, " +
+            "       longitude,  " +
+            "       addr_transed_flag " +
+            "from a_patient_mi " +
+            "where addr_transed_flag = 0")
+    List<Patient> inpatientAddress();
+
+
+    @Select("select top 5000 inpatient_no," +
+            "                home_street   " +
+            "from a_patient_mi\n" +
+            "where isnull(addr_transed_flag, 3) <> 1\n" +
+            "  and LEFT(inpatient_no, 1) NOT IN ('S', 'T', 'J')\n" +
+            "order by inpatient_no desc")
+    List<Patient> timedTaskPatientData();
+
+
+    @Update("<script>" +
+            "<foreach collection=\"list\" item=\"item\" index=\"index\" open=\"\" close=\"\" separator=\";\">" +
+            "update a_patient_mi " +
+            "set latitude = #{item.latitude,jdbcType=REAL}," +
+            "    longitude = #{item.longitude,jdbcType=REAL}, " +
+            "    addr_transed_flag = #{item.addrTransedFlag,jdbcType=INTEGER}  " +
+            "where inpatient_no = #{item.inpatientNo} " +
+            "</foreach>" +
+            "</script>")
+    void updatePatientAddress(@Param("list") List<Patient> patients);
+
+}

+ 21 - 0
src/main/java/thyyxxk/webserver/entity/inpatient/patient/Patient.java

@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.Data;
 import org.springframework.format.annotation.DateTimeFormat;
 
+import java.math.BigDecimal;
 import java.util.Date;
 
 @Data
@@ -82,6 +83,26 @@ public class Patient {
     private String homeStreet;
     private Integer age;
 
+    /**
+     * 纬度
+     */
+    private BigDecimal latitude;
+
+    /**
+     * 经度
+     */
+    private BigDecimal longitude;
+
+    /**
+     * 转化成功标志
+     */
+    private Integer addrTransedFlag;
+
+    /**
+     * 同区域的人数
+     */
+    private Integer numberOfPeopleInTheSameArea;
+
     /**
      * 是否有出纳
      */

+ 24 - 0
src/main/java/thyyxxk/webserver/entity/reports/BaiduMap.java

@@ -0,0 +1,24 @@
+package thyyxxk.webserver.entity.reports;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class BaiduMap {
+
+    /**
+     * 纬度
+     */
+    private BigDecimal lng;
+
+    /**
+     * 经度
+     */
+    private BigDecimal lat;
+
+    /**
+     * 数量
+     */
+    private Integer count;
+}

+ 126 - 0
src/main/java/thyyxxk/webserver/scheduled/UpdatePatientLatitudeAndLongitude.java

@@ -0,0 +1,126 @@
+package thyyxxk.webserver.scheduled;
+
+import com.alibaba.fastjson.JSON;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.ListUtils;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+import thyyxxk.webserver.dao.his.reports.PatientDistributionAddressDao;
+import thyyxxk.webserver.entity.inpatient.patient.Patient;
+import thyyxxk.webserver.utils.BaiduMapGeocoderUtil;
+import thyyxxk.webserver.utils.ListUtil;
+import thyyxxk.webserver.utils.StringUtil;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+
+@Component
+@Slf4j
+public class UpdatePatientLatitudeAndLongitude {
+
+    @Value("${execute-scheduled}")
+    private Boolean executeScheduled;
+
+    private final PatientDistributionAddressDao dao;
+
+    public UpdatePatientLatitudeAndLongitude(PatientDistributionAddressDao dao) {
+        this.dao = dao;
+    }
+
+    /**
+     * 每天一点执行定时任务
+     * 患者地址转坐标
+     */
+    @Scheduled(cron = "0 0 1 * * ?")
+    public void UpdatePatientLatitudeAndLongitude() {
+        if (!executeScheduled) {
+            return;
+        }
+        List<Patient> list = dao.timedTaskPatientData();
+
+        if (ListUtil.notBlank(list)) {
+            for (Patient patient : list) {
+                if (StringUtil.notBlank(patient.getHomeStreet())) {
+                    String[] address = BaiduMapGeocoderUtil.getlocation(patient.getHomeStreet());
+                    if (address == null) {
+                        patient.setAddrTransedFlag(1);
+                        patient.setLatitude(null);
+                        patient.setLongitude(null);
+                    } else {
+                        patient.setAddrTransedFlag(0);
+                        patient.setLongitude(new BigDecimal(address[0]));
+                        patient.setLatitude(new BigDecimal(address[1]));
+                    }
+                    log.info("住院号:{},地址:{},经度:{},纬度:{}", patient.getInpatientNo(),
+                            patient.getHomeStreet(),
+                            patient.getLongitude(), patient.getLatitude());
+                }
+            }
+
+            List<List<Patient>> performAnUpdate = ListUtils.partition(list, 50);
+
+            for (List<Patient> patients : performAnUpdate) {
+                dao.updatePatientAddress(patients);
+            }
+
+        }
+    }
+
+    public void test() throws IOException {
+        String fileName = "D:\\world\\server\\web-server\\serverlog\\temp.txt";
+        Path path = Paths.get(fileName);
+        List<String> allLines = Files.readAllLines(path, StandardCharsets.UTF_8);
+
+        List<Patient> updated = new ArrayList<>();
+
+        Integer 数量 = 0;
+
+        for (String allLine : allLines) {
+            Patient patient = new Patient();
+
+            Integer 位置 = allLine.indexOf("住院号:");
+
+            if (位置 > -1) {
+                String str = allLine.substring(位置);
+                String[] list = str.split(",");
+
+                for (int i = 0; i < list.length; i++) {
+                    String 信息 = list[i].split(":")[1];
+                    if ("null".equals(信息)) {
+                        信息 = null;
+                    }
+                    switch (i) {
+                        case 0:
+                            patient.setInpatientNo(信息);
+                            break;
+                        case 2:
+                            patient.setLongitude(信息 == null ? null : new BigDecimal(信息));
+                            break;
+                        case 3:
+                            patient.setLatitude(信息 == null ? null : new BigDecimal(信息));
+                            break;
+                        default:
+                            break;
+                    }
+                }
+                log.info("转化信息:{}", JSON.toJSONString(patient));
+                updated.add(patient);
+            }
+        }
+
+        List<List<Patient>> performAnUpdate = ListUtils.partition(updated, 50);
+        for (List<Patient> patients : performAnUpdate) {
+            dao.updatePatientAddress(patients);
+        }
+
+    }
+
+}
+

+ 58 - 0
src/main/java/thyyxxk/webserver/service/reports/PatientDistributionAddressServer.java

@@ -0,0 +1,58 @@
+package thyyxxk.webserver.service.reports;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+import thyyxxk.webserver.config.exception.ExceptionEnum;
+import thyyxxk.webserver.dao.his.reports.PatientDistributionAddressDao;
+import thyyxxk.webserver.entity.ResultVo;
+import thyyxxk.webserver.entity.inpatient.patient.Patient;
+import thyyxxk.webserver.utils.ListUtil;
+import thyyxxk.webserver.utils.ResultVoUtil;
+
+import java.util.List;
+
+@Service
+@Slf4j
+public class PatientDistributionAddressServer {
+
+    private final PatientDistributionAddressDao dao;
+
+    public PatientDistributionAddressServer(PatientDistributionAddressDao dao) {
+        this.dao = dao;
+    }
+
+    public ResultVo<List<Patient>> patientAddress() {
+
+        List<Patient> list = dao.inpatientAddress();
+
+        if (ListUtil.isBlank(list)) {
+            return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
+        }
+        return ResultVoUtil.success(list);
+
+
+//        Map<String, BaiduMap> latitudeAndLongitude = new HashMap<>();
+//
+//        for (Patient patient : list) {
+//            BaiduMap baiduMap = new BaiduMap();
+//            String lat = patient.getLatitude().toPlainString();
+//            String lng = patient.getLongitude().toPlainString();
+//            baiduMap.setLat(patient.getLatitude());
+//            baiduMap.setLng(patient.getLongitude());
+//
+//            String key = lat + "_" + lng;
+//
+//            if (latitudeAndLongitude.containsKey(key)) {
+//                BaiduMap temp = latitudeAndLongitude.get(key);
+//                temp.setCount(temp.getCount() + 1);
+//            } else {
+//                baiduMap.setCount(1);
+//                latitudeAndLongitude.put(key, baiduMap);
+//            }
+//        }
+//
+//        return ResultVoUtil.success(latitudeAndLongitude);
+    }
+
+
+}

+ 16 - 7
src/main/java/thyyxxk/webserver/utils/BaiduMapGeocoderUtil.java

@@ -1,6 +1,7 @@
 package thyyxxk.webserver.utils;
 
 import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
 import org.dom4j.Document;
 import org.dom4j.Element;
 import org.dom4j.io.SAXReader;
@@ -14,6 +15,7 @@ import java.net.URL;
 import java.net.URLConnection;
 import java.nio.charset.StandardCharsets;
 
+@Slf4j
 public class BaiduMapGeocoderUtil {
 
     /**
@@ -21,20 +23,20 @@ public class BaiduMapGeocoderUtil {
      */
     public final static String BAIDU_MAP_AK = "10rlflGd5szufZSPSrn59FYYxBkl2voy";
 
-    public static JSONObject getAddressInfoByLngAndLat(String rawAddress){
+    public static JSONObject getAddressInfoByLngAndLat(String rawAddress) {
         String[] points = getlocation(rawAddress);
         if (null == points) {
             return null;
         }
         JSONObject obj;
-        String location=points[1]+","+points[0];
-        String url ="http://api.map.baidu.com/reverse_geocoding/v3/?ak="+BAIDU_MAP_AK+"&output=json&coordtype=wgs84ll&location="+location;
+        String location = points[1] + "," + points[0];
+        String url = "http://api.map.baidu.com/reverse_geocoding/v3/?ak=" + BAIDU_MAP_AK + "&output=json&coordtype=wgs84ll&location=" + location;
         try {
             String json = loadJSON(url);
             obj = JSONObject.parseObject(json);
-            String success="0";
+            String success = "0";
             String status = String.valueOf(obj.get("status"));
-            if(success.equals(status)){
+            if (success.equals(status)) {
                 JSONObject result = obj.getJSONObject("result");
                 return result.getJSONObject("addressComponent");
             }
@@ -55,7 +57,8 @@ public class BaiduMapGeocoderUtil {
                 json.append(inputLine);
             }
             in.close();
-        } catch (IOException ignored) {}
+        } catch (IOException ignored) {
+        }
         return json.toString();
     }
 
@@ -93,7 +96,7 @@ public class BaiduMapGeocoderUtil {
             ins.close();
             conn.disconnect();
         } catch (Exception e) {
-            System.out.println("报错:" + rawAddress);
+            log.info("地址转化报错信息:{}", rawAddress);
             e.printStackTrace();
             return null;
         } finally {
@@ -110,5 +113,11 @@ public class BaiduMapGeocoderUtil {
         }
         return result;
     }
+
+    public static String getlocationString(String rawAddress) {
+        return StringUtil.stringArrayToCharacter(getlocation(rawAddress));
+    }
+
+
 }
 

+ 19 - 1
src/main/java/thyyxxk/webserver/utils/StringUtil.java

@@ -115,6 +115,7 @@ public class StringUtil {
 
     /**
      * 驼峰转下划线
+     *
      * @param str 数据
      * @return 返回数据
      */
@@ -123,7 +124,7 @@ public class StringUtil {
         Matcher matcher = Pattern.compile(regex).matcher(str);
         while (matcher.find()) {
             String target = matcher.group();
-            str = str.replaceAll(target, "_"+target.toLowerCase());
+            str = str.replaceAll(target, "_" + target.toLowerCase());
         }
         return str;
     }
@@ -185,5 +186,22 @@ public class StringUtil {
         v2Modulo = Math.sqrt(v2Modulo);
         return vProduct / (v1Modulo * v2Modulo);
     }
+
+    public static String stringArrayToCharacter(String[] lytype) {
+        if (lytype == null) {
+            return null;
+        }
+        StringBuilder sb = new StringBuilder();
+        if (lytype.length > 0) {
+            for (int i = 0; i < lytype.length; i++) {
+                if (i < lytype.length - 1) {
+                    sb.append(lytype[i]).append(",");
+                } else {
+                    sb.append(lytype[i]);
+                }
+            }
+        }
+        return sb.toString();
+    }
 }