sunzq 4 years ago
parent
commit
6baf10b9b3

+ 10 - 0
pom.xml

@@ -207,6 +207,16 @@
             <artifactId>springfox-swagger-ui</artifactId>
             <version>2.7.0</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpcore</artifactId>
+            <version>4.4.10</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>4.5.6</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 4 - 0
src/main/java/com/miyzh/config/SheduledConfig.java

@@ -1,6 +1,8 @@
 package com.miyzh.config;
 
 import com.miyzh.service.BaseService;
+import lombok.extern.log4j.Log4j;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.scheduling.annotation.EnableScheduling;
@@ -14,6 +16,7 @@ import org.springframework.scheduling.annotation.Scheduled;
 
 @Configuration
 @EnableScheduling
+@Slf4j
 public class SheduledConfig {
 
     @Autowired
@@ -21,6 +24,7 @@ public class SheduledConfig {
 
     @Scheduled(cron = "0 0 0 * * ?")
     private void runservice() {
+        log.info("开始定时任务");
         baseService.runService();
     }
 }

+ 1 - 1
src/main/java/com/miyzh/controller/StoreController.java

@@ -30,7 +30,7 @@ public class StoreController {
     @PostMapping("medicineChiStore")
     public void medicineChiStore(){
         try {
-            baseService.medicineStore();
+            baseService.medicineChiStore();
         } catch (Exception e) {
             e.printStackTrace();
         }

+ 10 - 8
src/main/java/com/miyzh/dao/MedicineReturnDao.java

@@ -3,34 +3,36 @@ package com.miyzh.dao;
 import com.miyzh.entity.MedicineReturnTemp;
 import com.miyzh.entity.dto.MedicineReturnDto;
 import org.apache.ibatis.annotations.Mapper;
+import org.springframework.beans.factory.annotation.Value;
 
 import java.util.List;
 
 @Mapper
 public interface MedicineReturnDao {
 
+
     // 西药销售出库记录
-    List<MedicineReturnTemp> listMedicineOutbound(String clinicId);
+    List<MedicineReturnTemp> listMedicineOutbound(String clinicId, String startDate, String endDate, String dateType, Integer count);
 
     // 中药销售出库记录
-    List<MedicineReturnTemp> listChinaMedicineOutbound(String clinicId);
+    List<MedicineReturnTemp> listChinaMedicineOutbound(String clinicId, String startDate, String endDate, String dateType, Integer count);
 
     // 西药损耗/领用出库记录
-    List<MedicineReturnTemp> listMedicineOutTreasury(String clinicId);
+    List<MedicineReturnTemp> listMedicineOutTreasury(String clinicId, String startDate, String endDate, String dateType, Integer count);
 
     // 中药损耗/领用出库记录
-    List<MedicineReturnTemp> listChinaMedicineOutTreasury(String clinicId);
+    List<MedicineReturnTemp> listChinaMedicineOutTreasury(String clinicId, String startDate, String endDate, String dateType, Integer count);
 
     // 西药采购退货出库记录
-    List<MedicineReturnTemp> listMedicineBack(String clinicId);
+    List<MedicineReturnTemp> listMedicineBack(String clinicId, String startDate, String endDate, String dateType, Integer count);
 
     // 中药采购退货出库记录
-    List<MedicineReturnTemp> listChinaMedicineBack(String clinicId);
+    List<MedicineReturnTemp> listChinaMedicineBack(String clinicId, String startDate, String endDate, String dateType, Integer count);
 
     // 西药盘点盘亏出库记录
-    List<MedicineReturnTemp> listMedicineInventory(String clinicId);
+    List<MedicineReturnTemp> listMedicineInventory(String clinicId, String startDate, String endDate, String dateType, Integer count);
 
     // 中药盘点盘亏出库记录
-    List<MedicineReturnTemp> listChinaMedicineInventory(String clinicId);
+    List<MedicineReturnTemp> listChinaMedicineInventory(String clinicId, String startDate, String endDate, String dateType, Integer count);
 
 }

+ 6 - 6
src/main/java/com/miyzh/dao/MedicineStorageDao.java

@@ -11,21 +11,21 @@ import java.util.List;
 public interface MedicineStorageDao {
 
     // 西药采购入库记录
-    List<MedicineStorageTemp> listMedicinePurchase(String clinicId);
+    List<MedicineStorageTemp> listMedicinePurchase(String clinicId, String startDate, String endDate, String dateType, Integer count);
 
     // 中药采购入库记录
-    List<MedicineStorageTemp> listChinaMedicinePurchase(String clinicId);
+    List<MedicineStorageTemp> listChinaMedicinePurchase(String clinicId, String startDate, String endDate, String dateType, Integer count);
 
     // 西药销售退回入库记录
-    List<MedicineStorageTemp> listMedicineOutbound(String clinicId);
+    List<MedicineStorageTemp> listMedicineOutbound(String clinicId, String startDate, String endDate, String dateType, Integer count);
 
     // 中药销售退回入库记录
-    List<MedicineStorageTemp> listChinaMedicineOutbound(String clinicId);
+    List<MedicineStorageTemp> listChinaMedicineOutbound(String clinicId, String startDate, String endDate, String dateType, Integer count);
 
     // 西药盘点盘盈入库记录
-    List<MedicineStorageTemp> listMedicineInventory(String clinicId);
+    List<MedicineStorageTemp> listMedicineInventory(String clinicId, String startDate, String endDate, String dateType, Integer count);
 
     // 中药盘点盘盈入库记录
-    List<MedicineStorageTemp> listChinaMedicineInventory(String clinicId);
+    List<MedicineStorageTemp> listChinaMedicineInventory(String clinicId, String startDate, String endDate, String dateType, Integer count);
 
 }

+ 2 - 2
src/main/java/com/miyzh/dao/MedicineStoreDao.java

@@ -9,7 +9,7 @@ import java.util.List;
 @Mapper
 public interface MedicineStoreDao {
 
-    List<MedicineStore> listMedicineStore(@Param("clinicId") String clinicId);
+    List<MedicineStore> listMedicineStore(String clinicId, String startDate, String endDate, String dateType, Integer count);
 
-    List<MedicineStore> listChinaMedicineStore(@Param("clinicId") String clinicId);
+    List<MedicineStore> listChinaMedicineStore(String clinicId, String startDate, String endDate, String dateType, Integer count);
 }

+ 6 - 6
src/main/java/com/miyzh/dao/OrderDetailDao.java

@@ -9,22 +9,22 @@ import java.util.List;
 public interface OrderDetailDao {
 
     // 西药销售明细记录(自费门诊)
-    List<OrderDetailTemp> listClcMedOrder(String clinicId);
+    List<OrderDetailTemp> listClcMedOrder(String clinicId, String startDate, String endDate, String dateType, Integer count);
 
     // 西药销售明细记录(医保门诊)
-    List<OrderDetailTemp> listInsClcMedOrder(String clinicId);
+    List<OrderDetailTemp> listInsClcMedOrder(String clinicId, String startDate, String endDate, String dateType, Integer count);
 
     // 中药销售明细记录(自费门诊)
-    List<OrderDetailTemp> listClcChinaMedOrder(String clinicId);
+    List<OrderDetailTemp> listClcChinaMedOrder(String clinicId, String startDate, String endDate, String dateType, Integer count);
 
     // 中药销售明细记录(医保门诊)
-    List<OrderDetailTemp> listInsClcChinaMedOrder(String clinicId);
+    List<OrderDetailTemp> listInsClcChinaMedOrder(String clinicId, String startDate, String endDate, String dateType, Integer count);
 
     // 西药药销售明细记录(住院)
-    List<OrderDetailTemp> listHosMedOrder(String clinicId);
+    List<OrderDetailTemp> listHosMedOrder(String clinicId, String startDate, String endDate, String dateType, Integer count);
 
     // 中药销售明细记录(住院)
-    List<OrderDetailTemp> listHosChinaMedOrder(String clinicId);
+    List<OrderDetailTemp> listHosChinaMedOrder(String clinicId, String startDate, String endDate, String dateType, Integer count);
 
 
 

+ 1 - 1
src/main/java/com/miyzh/entity/dto/MedicineStoreDto.java

@@ -10,7 +10,7 @@ public class MedicineStoreDto {
 
     private String storeCode; //医药机构编码
 
-    private String srpNo; //机构采购记录编码
+    private String erpNo; //机构采购记录编码
 
     private String  checkTime; //盘点时间
 

+ 1 - 1
src/main/java/com/miyzh/service/BaseService.java

@@ -62,7 +62,7 @@ public class BaseService {
         try{
             long startTime = System.currentTimeMillis();
             List<Clinic> clinicList = clinicService.listClinic();
-            // 库存同步
+//             库存同步
             medicineStoreService.uploadMedicine(clinicList);
             medicineStoreService.uploadChinaMedicine(clinicList);
 

+ 106 - 25
src/main/java/com/miyzh/service/MedicineReturnService.java

@@ -9,11 +9,11 @@ import com.miyzh.entity.*;
 import com.miyzh.entity.dto.MedicineReturnDto;
 import com.miyzh.utils.RestTemplateUtil;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
 
 import java.util.List;
 import java.util.Map;
@@ -29,10 +29,20 @@ public class MedicineReturnService {
 
     @Autowired
     private MedicineReturnDao medicineReturnDao;
+
+
     @Value ("${postApi.returnUrl}")
     private String url;
     @Value("${postApi.pageSize}")
     private int pageSize;
+    @Value("${update.startDate}")
+    public String startDate;
+    @Value("${update.endDate}")
+    public String endDate;
+    @Value("${update.dateType}")
+    public String dateType;
+    @Value("${update.count}")
+    public Integer count;
 
     private class StockoutType {
         private static final String SELL = "1"; //销售
@@ -42,6 +52,7 @@ public class MedicineReturnService {
         private static final String ALLOT = "5"; // 调拨
     }
 
+
     private static final String MED_OUT = "1"; //西药销售出库记录
     private static final String CHI_MED_OUT = "2"; //中药销售出库记录
     private static final String MED_OUTTREASURY = "3"; //西药损耗/领用出库记录
@@ -59,43 +70,51 @@ public class MedicineReturnService {
             switch (flag) {
                 case MED_OUT:
                     page = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                        medicineReturnDao.listMedicineOutbound(clinic.getClinicId());
+                        medicineReturnDao.listMedicineOutbound(clinic.getClinicId(), startDate, endDate, dateType, count);
                     });
+                    System.out.println(clinic.getStoreCode() + "======西药销售出库记录======total=" + page.getTotal());
                     break;
                 case CHI_MED_OUT:
                     page = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                        medicineReturnDao.listChinaMedicineOutbound(clinic.getClinicId());
+                        medicineReturnDao.listChinaMedicineOutbound(clinic.getClinicId(), startDate, endDate, dateType, count);
                     });
+                    System.out.println(clinic.getStoreCode() + "======中药销售出库记录======total=" + page.getTotal());
                     break;
                 case MED_OUTTREASURY:
                     page = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                        medicineReturnDao.listMedicineOutTreasury(clinic.getClinicId());
+                        medicineReturnDao.listMedicineOutTreasury(clinic.getClinicId(), startDate, endDate, dateType, count);
                     });
+                    System.out.println(clinic.getStoreCode() + "======西药损耗/领用出库记录======total=" + page.getTotal());
                     break;
                 case CHI_MED_OUTTREASURY:
                     page = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                        medicineReturnDao.listChinaMedicineOutTreasury(clinic.getClinicId());
+                        medicineReturnDao.listChinaMedicineOutTreasury(clinic.getClinicId(), startDate, endDate, dateType, count);
                     });
+                    System.out.println(clinic.getStoreCode() + "======中药损耗/领用出库记录======total=" + page.getTotal());
                     break;
                 case MED_BACK:
                     page = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                        medicineReturnDao.listMedicineBack(clinic.getClinicId());
+                        medicineReturnDao.listMedicineBack(clinic.getClinicId(), startDate, endDate, dateType, count);
                     });
+                    System.out.println(clinic.getStoreCode() + "======西药采购退货出库记录======total=" + page.getTotal());
                     break;
                 case CHI_MED_BACK:
                     page = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                        medicineReturnDao.listChinaMedicineBack(clinic.getClinicId());
+                        medicineReturnDao.listChinaMedicineBack(clinic.getClinicId(), startDate, endDate, dateType, count);
                     });
+                    System.out.println(clinic.getStoreCode() + "======中药采购退货出库记录======total=" + page.getTotal());
                     break;
                 case MED_INV:
                     page = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                        medicineReturnDao.listMedicineInventory(clinic.getClinicId());
+                        medicineReturnDao.listMedicineInventory(clinic.getClinicId(), startDate, endDate, dateType, count);
                     });
+                    System.out.println(clinic.getStoreCode() + "======西药盘点盘亏出库记录======total=" + page.getTotal());
                     break;
                 case CHI_MED_INV:
                     page = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                        medicineReturnDao.listChinaMedicineInventory(clinic.getClinicId());
+                        medicineReturnDao.listChinaMedicineInventory(clinic.getClinicId(), startDate, endDate, dateType, count);
                     });
+                    System.out.println(clinic.getStoreCode() + "======中药盘点盘亏出库记录======total=" + page.getTotal());
                     break;
             }
             if (page.getTotal() == 0) {
@@ -137,8 +156,19 @@ public class MedicineReturnService {
                         .stream()
                         .map(MedicineReturnTemp::temp2MedRet)
                         .collect(Collectors.toList());
-                medicineReturnDto.setMedicineInfos(list);
-                this.upload(medicineReturnDto);
+                // 西药部分 耗材西药分别上传 中药不需要处理
+                if(flag.equals(MED_OUT) || flag.equals(MED_OUTTREASURY) || flag.equals(MED_BACK) || flag.equals(MED_INV)){
+                    Map<String, List<MedicineReturn>> medMap = list.stream().collect(Collectors.groupingBy(MedicineReturn::getItemType));
+                    for(Map.Entry<String, List<MedicineReturn>> m : medMap.entrySet()) {
+                        if(m.getValue().size() > 0) {
+                            medicineReturnDto.setMedicineInfos(m.getValue());
+                            this.upload(medicineReturnDto, flag);
+                        }
+                    }
+                }  else {
+                    medicineReturnDto.setMedicineInfos(list);
+                    this.upload(medicineReturnDto, flag);
+                }
             }
             if (page.getPages() > 1) {
                 PageInfo<MedicineReturnTemp> page1 = new PageInfo<>();
@@ -146,43 +176,51 @@ public class MedicineReturnService {
                     switch (flag) {
                         case MED_OUT:
                             page1 = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                                medicineReturnDao.listMedicineOutbound(clinic.getClinicId());
+                                medicineReturnDao.listMedicineOutbound(clinic.getClinicId(), startDate, endDate, dateType, count);
                             });
+                            System.out.println(clinic.getStoreCode() + "======西药销售出库记录分页" + i + "======total=" + page.getTotal());
                             break;
                         case CHI_MED_OUT:
                             page1 = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                                medicineReturnDao.listChinaMedicineOutbound(clinic.getClinicId());
+                                medicineReturnDao.listChinaMedicineOutbound(clinic.getClinicId(), startDate, endDate, dateType, count);
                             });
+                            System.out.println(clinic.getStoreCode() + "======中药销售出库记录分页" + i + "======total=" + page.getTotal());
                             break;
                         case MED_OUTTREASURY:
                             page1 = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                                medicineReturnDao.listMedicineOutTreasury(clinic.getClinicId());
+                                medicineReturnDao.listMedicineOutTreasury(clinic.getClinicId(), startDate, endDate, dateType, count);
                             });
+                            System.out.println(clinic.getStoreCode() + "======西药损耗/领用出库记录分页" + i + "======total=" + page.getTotal());
                             break;
                         case CHI_MED_OUTTREASURY:
                             page1 = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                                medicineReturnDao.listChinaMedicineOutTreasury(clinic.getClinicId());
+                                medicineReturnDao.listChinaMedicineOutTreasury(clinic.getClinicId(), startDate, endDate, dateType, count);
                             });
+                            System.out.println(clinic.getStoreCode() + "======中药损耗/领用出库记录分页" + i + "======total=" + page.getTotal());
                             break;
                         case MED_BACK:
                             page1 = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                                medicineReturnDao.listMedicineBack(clinic.getClinicId());
+                                medicineReturnDao.listMedicineBack(clinic.getClinicId(), startDate, endDate, dateType, count);
                             });
+                            System.out.println(clinic.getStoreCode() + "======西药采购退货出库记录分页" + i + "======total=" + page.getTotal());
                             break;
                         case CHI_MED_BACK:
                             page1 = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                                medicineReturnDao.listChinaMedicineBack(clinic.getClinicId());
+                                medicineReturnDao.listChinaMedicineBack(clinic.getClinicId(), startDate, endDate, dateType, count);
                             });
+                            System.out.println(clinic.getStoreCode() + "======中药采购退货出库记录分页" + i + "======total=" + page.getTotal());
                             break;
                         case MED_INV:
                             page1 = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                                medicineReturnDao.listMedicineInventory(clinic.getClinicId());
+                                medicineReturnDao.listMedicineInventory(clinic.getClinicId(), startDate, endDate, dateType, count);
                             });
+                            System.out.println(clinic.getStoreCode() + "======西药盘点盘亏出库记录分页" + i + "======total=" + page.getTotal());
                             break;
                         case CHI_MED_INV:
                             page1 = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                                medicineReturnDao.listChinaMedicineInventory(clinic.getClinicId());
+                                medicineReturnDao.listChinaMedicineInventory(clinic.getClinicId(), startDate, endDate, dateType, count);
                             });
+                            System.out.println(clinic.getStoreCode() + "======中药盘点盘亏出库记录分页" + i + "======total=" + page.getTotal());
                             break;
                     }
                     Map<String, List<MedicineReturnTemp>> map1 =  page1.getList()
@@ -219,20 +257,63 @@ public class MedicineReturnService {
                                 .stream()
                                 .map(MedicineReturnTemp::temp2MedRet)
                                 .collect(Collectors.toList());
-                        medicineReturnDto.setMedicineInfos(list);
-                        this.upload(medicineReturnDto);
+
+                        if(flag.equals(MED_OUT) || flag.equals(MED_OUTTREASURY) || flag.equals(MED_BACK) || flag.equals(MED_INV)){
+                            Map<String, List<MedicineReturn>> medMap = list.stream().collect(Collectors.groupingBy(MedicineReturn::getItemType));
+                            for(Map.Entry<String, List<MedicineReturn>> m : medMap.entrySet()) {
+                                System.out.println(medicineReturnDto.getStoreCode() + "======" + ("1".equals(m.getKey())?"药品":"耗材"));
+                                if(m.getValue().size() > 0) {
+                                    medicineReturnDto.setMedicineInfos(m.getValue());
+                                    this.upload(medicineReturnDto, flag);
+                                }
+                            }
+                        } else {
+                            medicineReturnDto.setMedicineInfos(list);
+                            this.upload(medicineReturnDto, flag);
+                        }
                     }
                 }
             }
         };
         long syncTime = System.currentTimeMillis();
-        log.info("执行用时--{}", startTime - syncTime);
+        log.info("出库执行用时--{}", startTime - syncTime);
     };
 
-    public void upload (Object o) throws JsonProcessingException {
+    public void upload (MedicineReturnDto medicineReturnDto, String flag) throws JsonProcessingException {
+        String flagStr = "";
+        switch (flag) {
+            case MED_OUT:
+                flagStr = "西药销售出库";
+                break;
+            case CHI_MED_OUT:
+                flagStr = "中药销售出库";
+                break;
+            case MED_OUTTREASURY:
+                flagStr = "西药损耗/领用出库";
+                break;
+            case CHI_MED_OUTTREASURY:
+                flagStr = "中药损耗/领用出库";
+                break;
+            case MED_BACK:
+                flagStr = "西药采购退货出库";
+                break;
+            case CHI_MED_BACK:
+                flagStr = "中药采购退货出库";
+            case MED_INV:
+                flagStr = "西药盘点盘亏出库";
+                break;
+            case CHI_MED_INV:
+                flagStr = "中药盘点盘亏出库";
+                break;
+        }
         ObjectMapper objectMapper = new ObjectMapper();
-        String params = objectMapper.writeValueAsString(o);
-        System.out.println(objectMapper.writeValueAsString(RestTemplateUtil.postHttp(url, params)));
+        String params = objectMapper.writeValueAsString(medicineReturnDto);
+        BaseResult baseResult = RestTemplateUtil.postHttp(url, params);
+        if (null != baseResult && baseResult.isSuccess()) {
+            System.out.println(flagStr + "======" + medicineReturnDto.getStoreCode() + "======" + baseResult.getMessage());
+        } else {
+            log.error(flagStr + "------" + medicineReturnDto.getStoreCode() + "------" + baseResult.getMessage());
+        }
     }
 
 }

+ 91 - 24
src/main/java/com/miyzh/service/MedicineStorageService.java

@@ -5,10 +5,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.miyzh.dao.MedicineStorageDao;
-import com.miyzh.entity.Clinic;
-import com.miyzh.entity.MedicineStorage;
-import com.miyzh.entity.MedicineStorageTemp;
+import com.miyzh.entity.*;
 import com.miyzh.entity.dto.MedicineStorageDto;
+import com.miyzh.entity.dto.MedicineStoreDto;
 import com.miyzh.utils.RestTemplateUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
@@ -35,6 +34,14 @@ public class MedicineStorageService {
     private String url;
     @Value("${postApi.pageSize}")
     private int pageSize;
+    @Value("${update.startDate}")
+    public String startDate;
+    @Value("${update.endDate}")
+    public String endDate;
+    @Value("${update.dateType}")
+    public String dateType;
+    @Value("${update.count}")
+    public Integer count;
 
     private class StorageType {
         private static final String PUR = "1"; //采购入库
@@ -57,33 +64,39 @@ public class MedicineStorageService {
             switch (flag) {
                 case MED_PUR:
                     page = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                        medicineStorageDao.listMedicinePurchase(clinic.getClinicId());
+                        medicineStorageDao.listMedicinePurchase(clinic.getClinicId(), startDate, endDate, dateType, count);
                     });
+                    System.out.println(clinic.getStoreCode() + "======查询西药采购入库列表======total=" + page.getTotal());
                     break;
                 case CHI_MED_PUR:
                     page = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                        medicineStorageDao.listChinaMedicinePurchase(clinic.getClinicId());
+                        medicineStorageDao.listChinaMedicinePurchase(clinic.getClinicId(), startDate, endDate, dateType, count);
                     });
+                    System.out.println(clinic.getStoreCode() + "======查询中药采购入库列表======total=" + page.getTotal());
                     break;
                 case MED_MED_INBOUND:
                     page = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                        medicineStorageDao.listMedicineOutbound(clinic.getClinicId());
+                        medicineStorageDao.listMedicineOutbound(clinic.getClinicId(), startDate, endDate, dateType, count);
                     });
+                    System.out.println(clinic.getStoreCode() + "======查询西药销售退回入库列表======total=" + page.getTotal());
                     break;
                 case CHI_MED_INBOUND:
                     page = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                        medicineStorageDao.listChinaMedicineOutbound(clinic.getClinicId());
+                        medicineStorageDao.listChinaMedicineOutbound(clinic.getClinicId(), startDate, endDate, dateType, count);
                     });
+                    System.out.println(clinic.getStoreCode() + "======中药销售退回入库列表======total=" + page.getTotal());
                     break;
                 case MED_INV:
                     page = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                        medicineStorageDao.listMedicineInventory(clinic.getClinicId());
+                        medicineStorageDao.listMedicineInventory(clinic.getClinicId(), startDate, endDate, dateType, count);
                     });
+                    System.out.println(clinic.getStoreCode() + "======西药盘盈入库列表======total=" + page.getTotal());
                     break;
                 case CHI_MED_INV:
                     page = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                        medicineStorageDao.listChinaMedicineInventory(clinic.getClinicId());
+                        medicineStorageDao.listChinaMedicineInventory(clinic.getClinicId(), startDate, endDate, dateType, count);
                     });
+                    System.out.println(clinic.getStoreCode() + "======中药盘盈入库列表======total=" + page.getTotal());
                     break;
             }
             if (page.getTotal() == 0) {
@@ -119,8 +132,20 @@ public class MedicineStorageService {
                         .stream()
                         .map(MedicineStorageTemp::temp2MedSto)
                         .collect(Collectors.toList());
-                medicineStorageDto.setMedicineInfos(list);
-                this.upload(medicineStorageDto);
+
+                // 西药部分 耗材西药分别上传 中药不需要处理
+                if(flag.equals(MED_PUR) || flag.equals(MED_MED_INBOUND) || flag.equals(MED_INV)){
+                    Map<String, List<MedicineStorage>> medMap = list.stream().collect(Collectors.groupingBy(MedicineStorage::getItemType));
+                    for(Map.Entry<String, List<MedicineStorage>> m : medMap.entrySet()) {
+                        if(m.getValue().size() > 0) {
+                            medicineStorageDto.setMedicineInfos(m.getValue());
+                            this.upload(medicineStorageDto, flag);
+                        }
+                    }
+                }  else {
+                    medicineStorageDto.setMedicineInfos(list);
+                    this.upload(medicineStorageDto, flag);
+                }
             }
             if (page.getPages() > 1) {
                 PageInfo<MedicineStorageTemp> page1 = new PageInfo<>();
@@ -128,33 +153,39 @@ public class MedicineStorageService {
                     switch (flag) {
                         case MED_PUR:
                             page1 = PageHelper.startPage(i, pageSize).doSelectPageInfo(() -> {
-                                medicineStorageDao.listMedicinePurchase(clinic.getClinicId());
+                                medicineStorageDao.listMedicinePurchase(clinic.getClinicId(), startDate, endDate, dateType, count);
                             });
+                            System.out.println(clinic.getStoreCode() + "======查询西药采购入库分页" + i + "======total=" + page.getTotal());
                             break;
                         case CHI_MED_PUR:
                             page1 = PageHelper.startPage(i, pageSize).doSelectPageInfo(() -> {
-                                medicineStorageDao.listChinaMedicinePurchase(clinic.getClinicId());
+                                medicineStorageDao.listChinaMedicinePurchase(clinic.getClinicId(), startDate, endDate, dateType, count);
                             });
+                            System.out.println(clinic.getStoreCode() + "======查询中药采购入库分页" + i + "======total=" + page.getTotal() );
                             break;
                         case MED_MED_INBOUND:
                             page1 = PageHelper.startPage(i, pageSize).doSelectPageInfo(() -> {
-                                medicineStorageDao.listMedicineOutbound(clinic.getClinicId());
+                                medicineStorageDao.listMedicineOutbound(clinic.getClinicId(), startDate, endDate, dateType, count);
                             });
+                            System.out.println(clinic.getStoreCode() + "======查询西药销售退回入库分页" + i + "======total=" + page.getTotal());
                             break;
                         case CHI_MED_INBOUND:
                             page1 = PageHelper.startPage(i, pageSize).doSelectPageInfo(() -> {
-                                medicineStorageDao.listChinaMedicineOutbound(clinic.getClinicId());
+                                medicineStorageDao.listChinaMedicineOutbound(clinic.getClinicId(), startDate, endDate, dateType, count);
                             });
+                            System.out.println(clinic.getStoreCode() + "======查询中药销售退回入库分页" + i + "======total=" + page.getTotal());
                             break;
                         case MED_INV:
                             page1 = PageHelper.startPage(i, pageSize).doSelectPageInfo(() -> {
-                                medicineStorageDao.listMedicineInventory(clinic.getClinicId());
+                                medicineStorageDao.listMedicineInventory(clinic.getClinicId(), startDate, endDate, dateType, count);
                             });
+                            System.out.println(clinic.getStoreCode() + "======查询西药盘盈入库分页" + i + "======total=" + page.getTotal());
                             break;
                         case CHI_MED_INV:
                             page1 = PageHelper.startPage(i, pageSize).doSelectPageInfo(() -> {
-                                medicineStorageDao.listChinaMedicineInventory(clinic.getClinicId());
+                                medicineStorageDao.listChinaMedicineInventory(clinic.getClinicId(), startDate, endDate, dateType, count);
                             });
+                            System.out.println(clinic.getStoreCode() + "======查询中药销售退回入库上传分页" + i + "======total=" + page.getTotal());
                             break;
                     }
                     Map<String, List<MedicineStorageTemp>> map1 =  page1.getList()
@@ -187,20 +218,56 @@ public class MedicineStorageService {
                                 .stream()
                                 .map(MedicineStorageTemp::temp2MedSto)
                                 .collect(Collectors.toList());
-                        medicineStorageDto.setMedicineInfos(list);
-                        this.upload(medicineStorageDto);
+                        if(flag.equals(MED_PUR) || flag.equals(MED_MED_INBOUND) || flag.equals(MED_INV)){
+                            Map<String, List<MedicineStorage>> medMap = list.stream().collect(Collectors.groupingBy(MedicineStorage::getItemType));
+                            for(Map.Entry<String, List<MedicineStorage>> m : medMap.entrySet()) {
+                                System.out.println(medicineStorageDto.getStoreCode() + "======" + ("1".equals(m.getKey())?"药品":"耗材"));
+                                if(m.getValue().size() > 0) {
+                                    medicineStorageDto.setMedicineInfos(m.getValue());
+                                    this.upload(medicineStorageDto, flag);
+                                }
+                            }
+                        }  else {
+                            medicineStorageDto.setMedicineInfos(list);
+                            this.upload(medicineStorageDto, flag);
+                        }
                     }
                 }
             }
         };
         long syncTime = System.currentTimeMillis();
-        log.info("1方法执行用时--{}", startTime - syncTime);
+        log.info("入库上传用时--{}", startTime - syncTime);
     };
 
-    public void upload (Object o) throws JsonProcessingException {
+    public void upload (MedicineStorageDto storageDtoInfo, String flag) throws InterruptedException, JsonProcessingException {
+        String flagStr = "";
+        switch (flag) {
+            case MED_PUR:
+                flagStr = "西药采购入库";
+                break;
+            case CHI_MED_PUR:
+                flagStr = "中药采购入库";
+                break;
+            case MED_MED_INBOUND:
+                flagStr = "西药销售退回入库";
+                break;
+            case CHI_MED_INBOUND:
+                flagStr = "中药销售退回";
+                break;
+            case MED_INV:
+                flagStr = "西药盘盈入库";
+                break;
+            case CHI_MED_INV:
+                flagStr = "中药盘盈入库";
+                break;
+        }
         ObjectMapper objectMapper = new ObjectMapper();
-        String params = objectMapper.writeValueAsString(o);
-        System.out.println(objectMapper.writeValueAsString(RestTemplateUtil.postHttp(url, params)));
+        String params = objectMapper.writeValueAsString(storageDtoInfo);
+        BaseResult baseResult = RestTemplateUtil.postHttp(url, params);
+        if (null != baseResult && baseResult.isSuccess()) {
+            System.out.println(flagStr + "======" + storageDtoInfo.getStoreCode() + "======" + baseResult.getMessage());
+        } else {
+            log.error(flagStr + "------" + storageDtoInfo.getStoreCode() + "------" + baseResult.getMessage());
+        }
     }
-
 }

+ 44 - 19
src/main/java/com/miyzh/service/MedicineStoreService.java

@@ -1,6 +1,5 @@
 package com.miyzh.service;
 
-import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
@@ -20,6 +19,8 @@ import org.springframework.stereotype.Service;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * 库存信息同步
@@ -37,6 +38,14 @@ public class MedicineStoreService {
     private String url;
     @Value("${postApi.pageSize}")
     private int pageSize;
+    @Value("${update.startDate}")
+    public String startDate;
+    @Value("${update.endDate}")
+    public String endDate;
+    @Value("${update.dateType}")
+    public String dateType;
+    @Value("${update.count}")
+    public Integer count;
 
     @Async
     public void uploadMedicine(List<Clinic> clinicList) throws Exception {
@@ -48,20 +57,34 @@ public class MedicineStoreService {
             System.out.println(clinic.getStoreCode());
             storeInfo.setStoreCode(clinic.getStoreCode());
             PageInfo<MedicineStore> page = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                medicineStoreDao.listMedicineStore(clinic.getClinicId());
+                medicineStoreDao.listMedicineStore(clinic.getClinicId(), startDate, endDate, dateType, count);
             });
+            System.out.println(clinic.getStoreCode() + "======西药库存记录======total=" + page.getTotal());
             if (page.getTotal() == 0) {
                 continue;
             }
-            storeInfo.setMedicineInfos(page.getList());
-            this.upload(storeInfo);
+            Map<String, List<MedicineStore>> map = page.getList().stream().collect(Collectors.groupingBy(MedicineStore::getItemType));
+            for(Map.Entry<String, List<MedicineStore>> m : map.entrySet()) {
+                if(m.getValue().size() > 0) {
+                    System.out.println(storeInfo.getStoreCode() + "======" + ("1".equals(m.getKey())?"药品":"耗材"));
+                    storeInfo.setMedicineInfos(m.getValue());
+                    this.upload(storeInfo, "西药库存同步");
+                }
+            }
             if (page.getPages() > 1) {
                 for(int i = 2; i <= page.getPages(); i++) {
                     PageHelper.startPage(i, pageSize).doSelectPageInfo(() -> {
-                        medicineStoreDao.listMedicineStore(clinic.getClinicId());
+                        medicineStoreDao.listMedicineStore(clinic.getClinicId(), startDate, endDate, dateType, count);
                     });
-                    storeInfo.setMedicineInfos(page.getList());
-                    this.upload(storeInfo);
+                    System.out.println(clinic.getStoreCode() + "======西药库存记录分页======" + i + "total=" + page.getTotal());
+                    Map<String, List<MedicineStore>> map1 = page.getList().stream().collect(Collectors.groupingBy(MedicineStore::getItemType));
+                    for(Map.Entry<String, List<MedicineStore>> m : map1.entrySet()) {
+                        if(m.getValue().size() > 0) {
+                            System.out.println(storeInfo.getStoreCode() + "======" + ("1".equals(m.getKey())?"药品":"耗材"));
+                            storeInfo.setMedicineInfos(m.getValue());
+                            this.upload(storeInfo, "西药库存分页同步");
+                        }
+                    }
                 }
             }
         };
@@ -76,22 +99,25 @@ public class MedicineStoreService {
         storeInfo.setCheckMan("");
         storeInfo.setCheckTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss")));
         for(Clinic clinic : clinicList) {
+            System.out.println(clinic.getStoreCode());
             storeInfo.setStoreCode(clinic.getStoreCode());
             PageInfo<MedicineStore> page = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                medicineStoreDao.listChinaMedicineStore(clinic.getClinicId());
+                medicineStoreDao.listChinaMedicineStore(clinic.getClinicId(), startDate, endDate, dateType, count);
             });
+            System.out.println(clinic.getStoreCode() + "======中药库存记录======total=" + page.getTotal());
             if (page.getTotal() == 0) {
                 continue;
             }
             storeInfo.setMedicineInfos(page.getList());
-            this.upload(storeInfo);
+            this.upload(storeInfo, "中药库存同步");
             if (page.getPages() > 1) {
                 for(int i = 2; i <= page.getPages(); i++) {
                     PageHelper.startPage(i, pageSize).doSelectPageInfo(() -> {
-                        medicineStoreDao.listChinaMedicineStore(clinic.getClinicId());
+                        medicineStoreDao.listChinaMedicineStore(clinic.getClinicId(), startDate, endDate, dateType, count);
                     });
+                    System.out.println(clinic.getStoreCode() + "======中药库存记录分页======" + i + "total=" + page.getTotal());
                     storeInfo.setMedicineInfos(page.getList());
-                    this.upload(storeInfo);
+                    this.upload(storeInfo, "中药库存分页同步");
                 }
             }
         };
@@ -99,16 +125,15 @@ public class MedicineStoreService {
         log.info("中药库存同步方法执行用时--{}", startTime - syncTime);
     };
 
-    public void upload (MedicineStoreDto storeInfo) throws Exception {
+    public void upload (MedicineStoreDto storeInfo, String flag) throws Exception {
         ObjectMapper objectMapper = new ObjectMapper();
         String params = objectMapper.writeValueAsString(storeInfo);
-        System.out.println(objectMapper.writeValueAsString(RestTemplateUtil.postHttp(url, params)));
-//        BaseResult baseResult = RestTemplateUtil.postHttp(url, params);
-//        if (null != baseResult && baseResult.isSuccess()) {
-//            log.info(storeInfo.getStoreCode() + baseResult.getMessage());
-//        } else {
-//            log.error(storeInfo.getStoreCode() + baseResult.getMessage());
-//        }
+        BaseResult baseResult = RestTemplateUtil.postHttp(url, params);
+        if (null != baseResult && baseResult.isSuccess()) {
+            System.out.println(flag + "======" + storeInfo.getStoreCode() + "======" + baseResult.getMessage());
+        } else {
+            log.error(flag + "------" + storeInfo.getStoreCode() + "------" + baseResult.getMessage());
+        }
 
 
     }

+ 96 - 27
src/main/java/com/miyzh/service/OrderDetailService.java

@@ -7,6 +7,7 @@ import com.github.pagehelper.PageInfo;
 import com.miyzh.dao.ClinicDao;
 import com.miyzh.dao.OrderDetailDao;
 import com.miyzh.entity.*;
+import com.miyzh.entity.dto.MedicineReturnDto;
 import com.miyzh.entity.dto.OrderDetailDto;
 import com.miyzh.utils.RestTemplateUtil;
 import com.mysql.cj.util.StringUtils;
@@ -30,13 +31,19 @@ import java.util.stream.Collectors;
 public class OrderDetailService {
 
     @Autowired
-    private ClinicDao clinicDao;
-    @Autowired
     private OrderDetailDao orderDetailDao;
     @Value ("${postApi.orderUrl}")
     private String url;
     @Value("${postApi.pageSize}")
     private int pageSize;
+    @Value("${update.startDate}")
+    public String startDate;
+    @Value("${update.endDate}")
+    public String endDate;
+    @Value("${update.dateType}")
+    public String dateType;
+    @Value("${update.count}")
+    public Integer count;
 
     private static final String CLI_MED = "1"; // 西药销售明细(自费门诊)
     private static final String CLI_CHI_MED = "2"; // 中药销售明细(自费门诊)
@@ -53,44 +60,51 @@ public class OrderDetailService {
             switch (flag) {
                 case CLI_MED:
                     page = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                        orderDetailDao.listClcMedOrder(clinic.getClinicId());
+                        orderDetailDao.listClcMedOrder(clinic.getClinicId(), startDate, endDate, dateType, count);
                     });
+                    System.out.println(clinic.getStoreCode() + "======查询西药销售明细(自费门诊)======total=" + page.getTotal());
                     break;
                 case CLI_CHI_MED:
                     page = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                        orderDetailDao.listClcChinaMedOrder(clinic.getClinicId());
+                        orderDetailDao.listClcChinaMedOrder(clinic.getClinicId(), startDate, endDate, dateType, count);
                     });
+                    System.out.println(clinic.getStoreCode() + "======查询中药销售明细(自费门诊)======total=" + page.getTotal());
                     break;
                 case INS_CLC_MED:
                     page = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                        orderDetailDao.listInsClcMedOrder(clinic.getClinicId());
+                        orderDetailDao.listInsClcMedOrder(clinic.getClinicId(), startDate, endDate, dateType, count);
                     });
+                    System.out.println(clinic.getStoreCode() + "======查询西药销售明细(医保门诊)======total=" + page.getTotal());
                     break;
                 case INS_CLC_CHI_MED:
                     page = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                        orderDetailDao.listInsClcChinaMedOrder(clinic.getClinicId());
+                        orderDetailDao.listInsClcChinaMedOrder(clinic.getClinicId(), startDate, endDate, dateType, count);
                     });
+                    System.out.println(clinic.getStoreCode() + "======查询中药销售明细(医保门诊)======total=" + page.getTotal());
                     break;
                 case HOS_MED:
                     page = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                        orderDetailDao.listHosMedOrder(clinic.getClinicId());
+                        orderDetailDao.listHosMedOrder(clinic.getClinicId(), startDate, endDate, dateType, count);
                     });
+                    System.out.println(clinic.getStoreCode() + "======查询西药销售明细(住院)======total=" + page.getTotal());
                     break;
                 case HOS_CHI_MED:
                     page = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                        orderDetailDao.listHosChinaMedOrder(clinic.getClinicId());
+                        orderDetailDao.listHosChinaMedOrder(clinic.getClinicId(), startDate, endDate, dateType, count);
                     });
+                    System.out.println(clinic.getStoreCode() + "======查询中药销售明细(住院)======total=" + page.getTotal());
                     break;
             }
             if (page.getTotal() == 0) {
                 continue;
             }
             Map<String, List<OrderDetailTemp>> map = new HashMap<>();
-            if (HOS_MED.equals(flag) || HOS_CHI_MED.equals(flag)) {
-                map =  page.getList().stream().collect(Collectors.groupingBy(OrderDetailTemp::getVisitCode));
-            } else {
-                map =  page.getList().stream().collect(Collectors.groupingBy(OrderDetailTemp::getStoreOrderNo));
-            }
+//            if (HOS_MED.equals(flag) || HOS_CHI_MED.equals(flag)) {
+//                map =  page.getList().stream().collect(Collectors.groupingBy(OrderDetailTemp::getVisitCode));
+//            } else {
+//                map =  page.getList().stream().collect(Collectors.groupingBy(OrderDetailTemp::getStoreOrderNo));
+//            }
+            map =  page.getList().stream().collect(Collectors.groupingBy(OrderDetailTemp::getStoreOrderNo));
 
             for(Map.Entry<String, List<OrderDetailTemp>> msMap:map.entrySet()){
                 OrderDetailDto orderDetailDto = new OrderDetailDto();
@@ -118,8 +132,18 @@ public class OrderDetailService {
                         .stream()
                         .map(OrderDetailTemp::temp2OrderDetail)
                         .collect(Collectors.toList());
-                orderDetailDto.setMedicineInfos(list);
-                this.upload(orderDetailDto);
+                if(flag.equals(CLI_MED) || flag.equals(INS_CLC_MED) || flag.equals(HOS_MED)){
+                    Map<String, List<OrderDetail>> medMap = list.stream().collect(Collectors.groupingBy(OrderDetail::getItemType));
+                    for(Map.Entry<String, List<OrderDetail>> m : medMap.entrySet()) {
+                        if(m.getValue().size() > 0) {
+                            orderDetailDto.setMedicineInfos(m.getValue());
+                            this.upload(orderDetailDto, flag);
+                        }
+                    }
+                }  else {
+                    orderDetailDto.setMedicineInfos(list);
+                    this.upload(orderDetailDto, flag);
+                }
             }
             if (page.getPages() > 1) {
                 PageInfo<OrderDetailTemp> page1 = new PageInfo<>();
@@ -127,33 +151,39 @@ public class OrderDetailService {
                     switch (flag) {
                         case CLI_MED:
                             page1 = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                                orderDetailDao.listClcMedOrder(clinic.getClinicId());
+                                orderDetailDao.listClcMedOrder(clinic.getClinicId(), startDate, endDate, dateType, count);
                             });
+                            System.out.println(clinic.getStoreCode() + "======查询西药销售明细(自费门诊)分页" + i + "======total=" + page.getTotal());
                             break;
                         case CLI_CHI_MED:
                             page1 = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                                orderDetailDao.listClcChinaMedOrder(clinic.getClinicId());
+                                orderDetailDao.listClcChinaMedOrder(clinic.getClinicId(), startDate, endDate, dateType, count);
                             });
+                            System.out.println(clinic.getStoreCode() + "======查询中药销售明细(自费门诊)分页" + i + "======total=" + page.getTotal());
                             break;
                         case INS_CLC_MED:
                             page1 = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                                orderDetailDao.listInsClcMedOrder(clinic.getClinicId());
+                                orderDetailDao.listInsClcMedOrder(clinic.getClinicId(), startDate, endDate, dateType, count);
                             });
+                            System.out.println(clinic.getStoreCode() + "======查询西药销售明细(医保门诊)分页" + i + "======total=" + page.getTotal());
                             break;
                         case INS_CLC_CHI_MED:
                             page1 = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                                orderDetailDao.listInsClcChinaMedOrder(clinic.getClinicId());
+                                orderDetailDao.listInsClcChinaMedOrder(clinic.getClinicId(), startDate, endDate, dateType, count);
                             });
+                            System.out.println(clinic.getStoreCode() + "======查询中药销售明细(医保门诊)分页" + i + "======total=" + page.getTotal());
                             break;
                         case HOS_MED:
                             page1 = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                                orderDetailDao.listHosMedOrder(clinic.getClinicId());
+                                orderDetailDao.listHosMedOrder(clinic.getClinicId(), startDate, endDate, dateType, count);
                             });
+                            System.out.println(clinic.getStoreCode() + "======查询西药销售明细(住院)分页" + i + "======total=" + page.getTotal());
                             break;
                         case HOS_CHI_MED:
                             page1 = PageHelper.startPage(1, pageSize).doSelectPageInfo(() -> {
-                                orderDetailDao.listHosChinaMedOrder(clinic.getClinicId());
+                                orderDetailDao.listHosChinaMedOrder(clinic.getClinicId(), startDate, endDate, dateType, count);
                             });
+                            System.out.println(clinic.getStoreCode() + "======查询中药销售明细(住院)分页" + i + "======total=" + page.getTotal());
                             break;
                     }
                     Map<String, List<OrderDetailTemp>> map1 = new HashMap<>();
@@ -192,20 +222,59 @@ public class OrderDetailService {
                                 .stream()
                                 .map(OrderDetailTemp::temp2OrderDetail)
                                 .collect(Collectors.toList());
-                        orderDetailDto.setMedicineInfos(list);
-                        this.upload(orderDetailDto);
+                        // 西药部分 耗材西药分别上传 中药不需要处理
+                        if(flag.equals(CLI_MED) || flag.equals(INS_CLC_MED) || flag.equals(HOS_MED)){
+                            Map<String, List<OrderDetail>> medMap = list.stream().collect(Collectors.groupingBy(OrderDetail::getItemType));
+                            for(Map.Entry<String, List<OrderDetail>> m : medMap.entrySet()) {
+                                if(m.getValue().size() > 0) {
+                                    System.out.println(orderDetailDto.getStoreCode() + "======" + ("1".equals(m.getKey())?"药品":"耗材"));
+                                    orderDetailDto.setMedicineInfos(m.getValue());
+                                    this.upload(orderDetailDto, flag);
+                                }
+                            }
+                        }  else {
+                            orderDetailDto.setMedicineInfos(list);
+                            this.upload(orderDetailDto, flag);
+                        }
                     }
                 }
             }
         };
         long syncTime = System.currentTimeMillis();
-        log.info("执行用时--{}", startTime - syncTime);
+        log.info("订单上传执行用时--{}", startTime - syncTime);
     };
 
-    public void upload (Object o) throws JsonProcessingException {
+    public void upload (OrderDetailDto orderDetailDto, String flag) throws JsonProcessingException {
+        String flagStr = "";
+        switch (flag) {
+            case CLI_MED:
+                flagStr = "西药销售明细(自费门诊)";
+                break;
+            case CLI_CHI_MED:
+                flagStr = "中药销售明细(自费门诊)";
+                break;
+            case INS_CLC_MED:
+                flagStr = "西药销售明细(医保门诊)";
+                break;
+            case INS_CLC_CHI_MED:
+                flagStr = "中药销售明细(医保门诊)";
+                break;
+            case HOS_MED:
+                flagStr = "西药销售明细(住院)";
+                break;
+            case HOS_CHI_MED:
+                flagStr = "中药销售明细(住院)";
+                break;
+        }
+
         ObjectMapper objectMapper = new ObjectMapper();
-        String params = objectMapper.writeValueAsString(o);
-        System.out.println(objectMapper.writeValueAsString(RestTemplateUtil.postHttp(url, params)));
+        String params = objectMapper.writeValueAsString(orderDetailDto);
+        BaseResult baseResult = RestTemplateUtil.postHttp(url, params);
+        if (null != baseResult && baseResult.isSuccess()) {
+            System.out.println(flagStr + "======" + orderDetailDto.getStoreCode() + "======" + baseResult.getMessage());
+        } else {
+            log.error(flagStr + "------" + orderDetailDto.getStoreCode() + "------" + baseResult.getMessage());
+        }
     }
 
 }

+ 58 - 11
src/main/java/com/miyzh/utils/RestTemplateUtil.java

@@ -3,29 +3,41 @@ package com.miyzh.utils;
 import com.alibaba.fastjson.JSONObject;
 import com.miyzh.entity.BaseResult;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.Header;
+import org.apache.http.client.HttpClient;
+import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy;
+import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.message.BasicHeader;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.MediaType;
 import org.springframework.http.client.ClientHttpResponse;
+import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
 import org.springframework.http.client.SimpleClientHttpRequestFactory;
 import org.springframework.http.converter.StringHttpMessageConverter;
-import org.springframework.util.MultiValueMap;
 import org.springframework.web.client.ResponseErrorHandler;
 import org.springframework.web.client.RestClientException;
 import org.springframework.web.client.RestTemplate;
+
 import javax.servlet.http.HttpServletResponse;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
-import java.util.Map;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
 
 @Slf4j
 public class RestTemplateUtil {
 
+
     // 默认时间五秒,不重试。
-    private final static int CONNEC_TIMEOUT = 5000;
-    private final static int READ_TIMEOUT   = 5000;
+    private final static int CONNEC_TIMEOUT = 10000;
+    private final static int READ_TIMEOUT   = 10000;
     private final static int RETRY_COUNT    = 1;
 
 
@@ -47,13 +59,15 @@ public class RestTemplateUtil {
     }
 
     private static RestTemplate simpeClient(String url, int connecTimeout, int readTimeout) {
-        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
-        requestFactory.setConnectTimeout(connecTimeout);
-        requestFactory.setReadTimeout(readTimeout);
-        RestTemplate restTemplate = new RestTemplate(requestFactory);
-        restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8)); // 设置编码集
+//        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
+//        requestFactory.setConnectTimeout(connecTimeout);
+//        requestFactory.setReadTimeout(readTimeout);
+//        RestTemplate restTemplate = new RestTemplate(requestFactory);
+//        restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8)); // 设置编码集
 //        restTemplate.setErrorHandler(new DefaultResponseErrorHandler()); //error处理
-        return restTemplate;
+//        return restTemplate;
+        HttpComponentsClientHttpRequestFactory httpRequestFactory = httpComponentsClientHttpRequestFactory(5);
+        return new RestTemplate(httpRequestFactory);
     }
 
     private static class DefaultResponseErrorHandler implements ResponseErrorHandler {
@@ -84,4 +98,37 @@ public class RestTemplateUtil {
             }
         }
     }
+    private static HttpComponentsClientHttpRequestFactory httpComponentsClientHttpRequestFactory(int maxTotal) {
+        //Httpclient连接池,长连接保持时间
+        PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(1, TimeUnit.HOURS);
+        //设置总连接数
+        connectionManager.setMaxTotal(maxTotal);
+        //设置同路由的并发数
+        connectionManager.setDefaultMaxPerRoute(maxTotal);
+        //设置header
+        List<Header> headers = new ArrayList<Header>();
+        headers.add(new BasicHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.04"));
+        headers.add(new BasicHeader("Accept-Encoding", "gzip, deflate"));
+        headers.add(new BasicHeader("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3"));
+        headers.add(new BasicHeader("Connection", "keep-alive"));
+        //创建HttpClient
+        HttpClient httpClient = HttpClientBuilder.create()
+                .setConnectionManager(connectionManager)
+                .setDefaultHeaders(headers)
+                .setRetryHandler(new DefaultHttpRequestRetryHandler(3, true)) //设置重试次数
+                .setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy()) //设置保持长连接
+                .build();
+        //创建HttpComponentsClientHttpRequestFactory实例
+        HttpComponentsClientHttpRequestFactory requestFactory =
+                new HttpComponentsClientHttpRequestFactory(httpClient);
+        //设置客户端和服务端建立连接的超时时间
+        requestFactory.setConnectTimeout(10000);
+        //设置客户端从服务端读取数据的超时时间
+        requestFactory.setReadTimeout(5000);
+        //设置从连接池获取连接的超时时间,不宜过长
+        requestFactory.setConnectionRequestTimeout(2000);
+        //缓冲请求数据,默认为true。通过POST或者PUT大量发送数据时,建议将此更改为false,以免耗尽内存
+        requestFactory.setBufferRequestBody(false);
+        return requestFactory;
+    }
 }

+ 15 - 5
src/main/resources/application-szq.yml

@@ -71,16 +71,26 @@ mybatis:
   mapperLocations: classpath:/mapper/*.xml
   configLocation: classpath:mybatis/mybatis-config.xml
 
+logging:
+  config: classpath:logback-spring.xml
 
 server:
   port: 18099
 
 postApi:
-  pageSize: 2000
-  storeUrl: http://15.72.176.14/mhis-pisp/api/pis/inventory-balance/upload
-  sorageUrl: http://15.72.176.14/mhis-pisp/api/pis/storagein-records/upload
-  returnUrl: http://15.72.176.14/mhis-pisp/api/pis/storageout-records/upload
-  orderUrl: http://15.72.176.14/mhis-pisp/api/pis/order-details/upload
+  pageSize: 1000
+  storeUrl: http://120.221.72.9:8081/mhis-pisp/api/pis/inventory-balance/upload
+  sorageUrl: http://120.221.72.9:8081/mhis-pisp/api/pis/storagein-records/upload
+  returnUrl: http://120.221.72.9:8081/mhis-pisp/api/pis/storageout-records/upload
+  orderUrl: http://120.221.72.9:8081/mhis-pisp/api/pis/order-details/upload
+
+update:
+  # 查询时间类型 d(天)/m(月)/y(年)/s(区间)
+  dateType: s
+  count: 1
+  # 只有时间类型为s时生效
+  startDate: 20170101
+  endDate: 20201001
 
 
 

+ 3 - 1
src/main/resources/logback-spring.xml

@@ -198,10 +198,12 @@
     <!--&lt;!&ndash; 添加附加的appender,最多只能添加一个 &ndash;&gt;-->
     <!--<appender-ref ref="TRACE"/>-->
     <!--</appender>-->
+    <!--myibatis log configure-->
+    <logger name="com.miyzh.dao" level="INFO"/>
 
 
     <!-- root级别   DEBUG -->
-    <root level="DEBUG">
+    <root level="INFO">
         <!-- 控制台输出 -->
         <appender-ref ref="CONSOLE"/>
         <!-- 文件输出 -->

+ 0 - 1
src/main/resources/mapper/ClinicMapper.xml

@@ -8,7 +8,6 @@
     </resultMap>
 
     <select id="listClinic" resultMap="BaseResultMap">
-
         select
         cci.clinic_id, cci.ins_code
         from clc_clinic_ins cci

+ 171 - 1
src/main/resources/mapper/MedicineReturnMapper.xml

@@ -58,6 +58,28 @@
             WHERE
                 cso.clinic_id = #{clinicId}
                 AND cso.change_type IN ( 1, 2 )
+                and cso.create_id is not null
+                <choose>
+                    <when test='dateType == "d" and count != null'>
+                        and cso.create_time between date_sub(curdate(), interval #{count} day) and now()
+                    </when>
+                    <when test='dateType == "m" and count != null'>
+                        and cso.create_time between date_sub(curdate(), interval #{count} month) and now()
+                    </when>
+                    <when test='dateType == "y" and count != null'>
+                        and cso.create_time between date_sub(curdate(), interval #{count} year) and now()
+                    </when>
+                </choose>
+                <if test='dateType == "s" and startDate != "" and startDate != null'>
+                    <![CDATA[
+                        and cso.create_time >= str_to_date(#{startDate},'%Y%m%d')
+                    ]]>
+                </if>
+                <if test='dateType == "s" and endDate != "" and endDate != null'>
+                    <![CDATA[
+                        and cso.create_time <= str_to_date(#{endDate},'%Y%m%d')
+                    ]]>
+                </if>
                 GROUP BY cso.medicine_id
     </select>
 
@@ -105,6 +127,28 @@
             WHERE
                 ccso.clinic_id = #{clinicId}
                 AND ccso.change_type IN ( 1, 2 )
+                and ccso.create_id is not null
+                <choose>
+                    <when test='dateType == "d" and count != null'>
+                        and ccso.create_time between date_sub(curdate(), interval #{count} day) and now()
+                    </when>
+                    <when test='dateType == "m" and count != null'>
+                        and ccso.create_time between date_sub(curdate(), interval #{count} month) and now()
+                    </when>
+                    <when test='dateType == "y" and count != null'>
+                        and ccso.create_time between date_sub(curdate(), interval #{count} year) and now()
+                    </when>
+                </choose>
+                <if test='dateType == "s" and startDate != "" and startDate != null'>
+                    <![CDATA[
+                                and ccso.create_time >= str_to_date(#{startDate},'%Y%m%d')
+                            ]]>
+                </if>
+                <if test='dateType == "s" and endDate != "" and endDate != null'>
+                    <![CDATA[
+                                and ccso.create_time <= str_to_date(#{endDate},'%Y%m%d')
+                            ]]>
+                </if>
                 GROUP BY ccso.medicine_id
     </select>
 
@@ -158,6 +202,27 @@
             AND cm.clinic_id = idm.clinic_id
             AND cod.clinic_id = #{clinicId}
             AND cod.biz_type = 1
+            <choose>
+                <when test='dateType == "d" and count != null'>
+                    and co.create_time between date_sub(curdate(), interval #{count} day) and now()
+                </when>
+                <when test='dateType == "m" and count != null'>
+                    and co.create_time between date_sub(curdate(), interval #{count} month) and now()
+                </when>
+                <when test='dateType == "y" and count != null'>
+                    and co.create_time between date_sub(curdate(), interval #{count} year) and now()
+                </when>
+            </choose>
+            <if test='dateType == "s" and startDate != "" and startDate != null'>
+                <![CDATA[
+                            and co.create_time >= str_to_date(#{startDate},'%Y%m%d')
+                        ]]>
+            </if>
+            <if test='dateType == "s" and endDate != "" and endDate != null'>
+                <![CDATA[
+                            and co.create_time <= str_to_date(#{endDate},'%Y%m%d')
+                        ]]>
+            </if>
             GROUP BY cod.medicine_id
          ORDER BY
             co.create_time,
@@ -214,6 +279,27 @@
                 AND ccm.clinic_id = idm.clinic_id
                 AND cod.clinic_id = #{clinicId}
                 AND cod.biz_type = 2
+                <choose>
+                    <when test='dateType == "d" and count != null'>
+                        and co.create_time between date_sub(curdate(), interval #{count} day) and now()
+                    </when>
+                    <when test='dateType == "m" and count != null'>
+                        and co.create_time between date_sub(curdate(), interval #{count} month) and now()
+                    </when>
+                    <when test='dateType == "y" and count != null'>
+                        and co.create_time between date_sub(curdate(), interval #{count} year) and now()
+                    </when>
+                </choose>
+                <if test='dateType == "s" and startDate != "" and startDate != null'>
+                    <![CDATA[
+                                and co.create_time >= str_to_date(#{startDate},'%Y%m%d')
+                            ]]>
+                </if>
+                <if test='dateType == "s" and endDate != "" and endDate != null'>
+                    <![CDATA[
+                                and co.create_time <= str_to_date(#{endDate},'%Y%m%d')
+                            ]]>
+                </if>
                 GROUP BY cod.medicine_id
              ORDER BY
                 co.create_time,
@@ -269,6 +355,27 @@
                 AND cpbd.stock_purchase_number = csd.stock_purchase_number
                 AND cpbd.clinic_id = #{clinicId}
                 AND cpb.biz_type in (1, 2, 3)
+                <choose>
+                    <when test='dateType == "d" and count != null'>
+                        and cpb.create_time between date_sub(curdate(), interval #{count} day) and now()
+                    </when>
+                    <when test='dateType == "m" and count != null'>
+                        and cpb.create_time between date_sub(curdate(), interval #{count} month) and now()
+                    </when>
+                    <when test='dateType == "y" and count != null'>
+                        and cpb.create_time between date_sub(curdate(), interval #{count} year) and now()
+                    </when>
+                </choose>
+                <if test='dateType == "s" and startDate != "" and startDate != null'>
+                    <![CDATA[
+                                and cpb.create_time >= str_to_date(#{startDate},'%Y%m%d')
+                            ]]>
+                </if>
+                <if test='dateType == "s" and endDate != "" and endDate != null'>
+                    <![CDATA[
+                                and cpb.create_time <= str_to_date(#{endDate},'%Y%m%d')
+                            ]]>
+                </if>
                 GROUP BY cpbd.medicine_id
             ORDER BY
                 cpb.create_time,
@@ -327,6 +434,27 @@
             AND cpbd.stock_purchase_number = ccsp.stock_purchase_number
             AND cpbd.clinic_id = #{clinicId}
             AND cpb.biz_type = 4
+            <choose>
+                <when test='dateType == "d" and count != null'>
+                    and cpb.create_time between date_sub(curdate(), interval #{count} day) and now()
+                </when>
+                <when test='dateType == "m" and count != null'>
+                    and cpb.create_time between date_sub(curdate(), interval #{count} month) and now()
+                </when>
+                <when test='dateType == "y" and count != null'>
+                    and cpb.create_time between date_sub(curdate(), interval #{count} year) and now()
+                </when>
+            </choose>
+            <if test='dateType == "s" and startDate != "" and startDate != null'>
+                <![CDATA[
+                            and cpb.create_time >= str_to_date(#{startDate},'%Y%m%d')
+                        ]]>
+            </if>
+            <if test='dateType == "s" and endDate != "" and endDate != null'>
+                <![CDATA[
+                            and cpb.create_time <= str_to_date(#{endDate},'%Y%m%d')
+                        ]]>
+            </if>
             GROUP BY cpbd.medicine_id
         ORDER BY
             cpb.create_time,
@@ -380,7 +508,28 @@
                 AND cm.clinic_id = idm.clinic_id
                 AND cid.inventory_type = 2
                 AND cid.clinic_id = #{clinicId}
-                AND <![CDATA[cid.biz_type != 4]]>
+                AND cid.biz_type != 4
+                <choose>
+                    <when test='dateType == "d" and count != null'>
+                        and ci.create_time between date_sub(curdate(), interval #{count} day) and now()
+                    </when>
+                    <when test='dateType == "m" and count != null'>
+                        and ci.create_time between date_sub(curdate(), interval #{count} month) and now()
+                    </when>
+                    <when test='dateType == "y" and count != null'>
+                        and ci.create_time between date_sub(curdate(), interval #{count} year) and now()
+                    </when>
+                </choose>
+                <if test='dateType == "s" and startDate != "" and startDate != null'>
+                    <![CDATA[
+                                and ci.create_time >= str_to_date(#{startDate},'%Y%m%d')
+                            ]]>
+                </if>
+                <if test='dateType == "s" and endDate != "" and endDate != null'>
+                    <![CDATA[
+                                and ci.create_time <= str_to_date(#{endDate},'%Y%m%d')
+                            ]]>
+                </if>
                 GROUP BY cid.medicine_id
             ORDER BY
                 ci.create_time,
@@ -438,6 +587,27 @@
                 AND cid.inventory_type = 2
                 AND cid.clinic_id = #{clinicId}
                 AND cid.biz_type = 4
+                <choose>
+                    <when test='dateType == "d" and count != null'>
+                        and ci.create_time between date_sub(curdate(), interval #{count} day) and now()
+                    </when>
+                    <when test='dateType == "m" and count != null'>
+                        and ci.create_time between date_sub(curdate(), interval #{count} month) and now()
+                    </when>
+                    <when test='dateType == "y" and count != null'>
+                        and ci.create_time between date_sub(curdate(), interval #{count} year) and now()
+                    </when>
+                </choose>
+                <if test='dateType == "s" and startDate != "" and startDate != null'>
+                    <![CDATA[
+                                and ci.create_time >= str_to_date(#{startDate},'%Y%m%d')
+                            ]]>
+                </if>
+                <if test='dateType == "s" and endDate != "" and endDate != null'>
+                    <![CDATA[
+                                and ci.create_time <= str_to_date(#{endDate},'%Y%m%d')
+                            ]]>
+                </if>
                 GROUP BY cid.medicine_id
             ORDER BY
                 ci.create_time,

+ 129 - 1
src/main/resources/mapper/MedicineStorageMapper.xml

@@ -13,6 +13,8 @@
         <result column="storage_time" jdbcType="VARCHAR" property="storageTime" />
     </resultMap>
 
+<!--    AND <![CDATA[ to_days(a.create_time) <= to_days(date_sub(curdate(),interval 1 day))]]>-->
+
     <!--西药采购入库记录-->
     <select id="listMedicinePurchase" resultMap="BaseResultMap" parameterType="java.lang.String">
         SELECT DISTINCT
@@ -63,6 +65,27 @@
             and cp.purchase_no is not null
             AND idm.medicine_id = cm.medicine_id
             AND idm.clinic_id = cm.clinic_id
+            <choose>
+                <when test='dateType == "d" and count != null'>
+                    and csi.create_time between date_sub(curdate(), interval #{count} day) and now()
+                </when>
+                <when test='dateType == "m" and count != null'>
+                    and csi.create_time between date_sub(curdate(), interval #{count} month) and now()
+                </when>
+                <when test='dateType == "y" and count != null'>
+                    and csi.create_time between date_sub(curdate(), interval #{count} year) and now()
+                </when>
+            </choose>
+            <if test='dateType == "s" and startDate != "" and startDate != null'>
+                <![CDATA[
+                            and csi.create_time >= str_to_date(#{startDate},'%Y%m%d')
+                        ]]>
+            </if>
+            <if test='dateType == "s" and endDate != "" and endDate != null'>
+                <![CDATA[
+                            and csi.create_time <= str_to_date(#{endDate},'%Y%m%d')
+                        ]]>
+            </if>
         GROUP BY
             cp.id,
             csi.medicine_id
@@ -124,6 +147,27 @@
                 AND ccssf.clinic_id = #{clinicId}
                 AND cs.warehouse_code = '1'
                 AND cp.purchase_no IS NOT NULL
+                <choose>
+                    <when test='dateType == "d" and count != null'>
+                        and ccssf.create_time between date_sub(curdate(), interval #{count} day) and now()
+                    </when>
+                    <when test='dateType == "m" and count != null'>
+                        and ccssf.create_time between date_sub(curdate(), interval #{count} month) and now()
+                    </when>
+                    <when test='dateType == "y" and count != null'>
+                        and ccssf.create_time between date_sub(curdate(), interval #{count} year) and now()
+                    </when>
+                </choose>
+                <if test='dateType == "s" and startDate != "" and startDate != null'>
+                    <![CDATA[
+                                and ccssf.create_time >= str_to_date(#{startDate},'%Y%m%d')
+                            ]]>
+                </if>
+                <if test='dateType == "s" and endDate != "" and endDate != null'>
+                    <![CDATA[
+                                and ccssf.create_time <= str_to_date(#{endDate},'%Y%m%d')
+                            ]]>
+                </if>
             GROUP BY
                 cp.id,
                 ccssf.medicine_id
@@ -177,6 +221,27 @@
         WHERE
             cm.clinic_id = #{clinicId}
             AND cso.change_type IN ( '03', '04' )
+            <choose>
+                <when test='dateType == "d" and count != null'>
+                    and cso.create_time between date_sub(curdate(), interval #{count} day) and now()
+                </when>
+                <when test='dateType == "m" and count != null'>
+                    and cso.create_time between date_sub(curdate(), interval #{count} month) and now()
+                </when>
+                <when test='dateType == "y" and count != null'>
+                    and cso.create_time between date_sub(curdate(), interval #{count} year) and now()
+                </when>
+            </choose>
+            <if test='dateType == "s" and startDate != "" and startDate != null'>
+                <![CDATA[
+                            and cso.create_time >= str_to_date(#{startDate},'%Y%m%d')
+                        ]]>
+            </if>
+            <if test='dateType == "s" and endDate != "" and endDate != null'>
+                <![CDATA[
+                            and cso.create_time <= str_to_date(#{endDate},'%Y%m%d')
+                        ]]>
+            </if>
         GROUP BY
             cso.medicine_id
         ORDER BY
@@ -228,6 +293,27 @@
         WHERE
             ccm.clinic_id = #{clinicId}
             AND cso.change_type IN ( '03', '04' )
+            <choose>
+                <when test='dateType == "d" and count != null'>
+                    and cso.create_time between date_sub(curdate(), interval #{count} day) and now()
+                </when>
+                <when test='dateType == "m" and count != null'>
+                    and cso.create_time between date_sub(curdate(), interval #{count} month) and now()
+                </when>
+                <when test='dateType == "y" and count != null'>
+                    and cso.create_time between date_sub(curdate(), interval #{count} year) and now()
+                </when>
+            </choose>
+            <if test='dateType == "s" and startDate != "" and startDate != null'>
+                <![CDATA[
+                            and cso.create_time >= str_to_date(#{startDate},'%Y%m%d')
+                        ]]>
+            </if>
+            <if test='dateType == "s" and endDate != "" and endDate != null'>
+                <![CDATA[
+                            and cso.create_time <= str_to_date(#{endDate},'%Y%m%d')
+                        ]]>
+            </if>
         GROUP BY
             cso.medicine_id
         ORDER BY
@@ -280,7 +366,28 @@
                 AND cm.clinic_id = idm.clinic_id
                 AND cid.inventory_type = 1
                 AND cid.clinic_id = #{clinicId}
-                AND <![CDATA[cid.biz_type != 4]]>
+                AND cid.biz_type != '4'
+                <choose>
+                    <when test='dateType == "d" and count != null'>
+                        and ci.create_time between date_sub(curdate(), interval #{count} day) and now()
+                    </when>
+                    <when test='dateType == "m" and count != null'>
+                        and ci.create_time between date_sub(curdate(), interval #{count} month) and now()
+                    </when>
+                    <when test='dateType == "y" and count != null'>
+                        and ci.create_time between date_sub(curdate(), interval #{count} year) and now()
+                    </when>
+                </choose>
+                <if test='dateType == "s" and startDate != "" and startDate != null'>
+                    <![CDATA[
+                                and ci.create_time >= str_to_date(#{startDate},'%Y%m%d')
+                            ]]>
+                </if>
+                <if test='dateType == "s" and endDate != "" and endDate != null'>
+                    <![CDATA[
+                                and ci.create_time <= str_to_date(#{endDate},'%Y%m%d')
+                            ]]>
+                </if>
                 GROUP BY cid.medicine_id
             ORDER BY
                 ci.create_time,
@@ -337,6 +444,27 @@
                 AND cid.inventory_type = 1
                 AND cid.clinic_id = #{clinicId}
                 AND cid.biz_type = 4
+                <choose>
+                    <when test='dateType == "d" and count != null'>
+                        and ci.create_time between date_sub(curdate(), interval #{count} day) and now()
+                    </when>
+                    <when test='dateType == "m" and count != null'>
+                        and ci.create_time between date_sub(curdate(), interval #{count} month) and now()
+                    </when>
+                    <when test='dateType == "y" and count != null'>
+                        and ci.create_time between date_sub(curdate(), interval #{count} year) and now()
+                    </when>
+                </choose>
+                <if test='dateType == "s" and startDate != "" and startDate != null'>
+                    <![CDATA[
+                                and ci.create_time >= str_to_date(#{startDate},'%Y%m%d')
+                            ]]>
+                </if>
+                <if test='dateType == "s" and endDate != "" and endDate != null'>
+                    <![CDATA[
+                                and ci.create_time <= str_to_date(#{endDate},'%Y%m%d')
+                            ]]>
+                </if>
                 GROUP BY cid.medicine_id
             ORDER BY
                 ci.create_time,

+ 3 - 3
src/main/resources/mapper/MedicineStoreMapper.xml

@@ -49,7 +49,7 @@
             csd.clinic_id = idm.clinic_id and csd.medicine_id=idm.medicine_id
         where
             csd.clinic_id = #{clinicId}
-            and <![CDATA[csd.timestamp_number != 'default' ]]>
+            and csd.timestamp_number != 'default'
         GROUP BY
             csd.medicine_id
     </select>
@@ -64,7 +64,7 @@
                 ) AS store_medicine_code,
         ccm.medicine_name as store_medicine_name,
         ccm.medicine_name as store_medicine_trade_name,
-        if(ifnull(idm.formulation, '')='','99999999',idm.formulation) as dosage_id
+        if(ifnull(idm.formulation, '')='','99999999',idm.formulation) as dosage_id,
         if(ifnull(ccm.medicine_rate_last,'')='','999999999',ccm.medicine_rate_last) as dosage_name,
         if(ifnull(ccm.medicine_specifications,'')='','999999999',ccm.medicine_specifications) as specification,
         if(ifnull(ccm.medicine_manufacturer_name,'')='','999999999',ccm.medicine_manufacturer_name) as manufacturer,
@@ -98,7 +98,7 @@
             ccsp.clinic_id = idm.clinic_id and ccsp.medicine_id=idm.medicine_id
         where
             ccsp.clinic_id = #{clinicId}
-            and <![CDATA[ccsp.timestamp_number != 'default' ]]>
+            and ccsp.timestamp_number != 'default'
         GROUP BY
             ccsp.medicine_id
     </select>

+ 158 - 47
src/main/resources/mapper/OrderDetailMapper.xml

@@ -52,7 +52,7 @@
     <select id="listClcMedOrder" resultMap="BaseResultMap" parameterType="java.lang.String">
         SELECT
             cpi.prescription_id AS store_order_no,
-            '99999999' AS mis_no,
+            if(ifnull(ics.settle_transaction_id,'')='','999999999',ics.settle_transaction_id) as mis_no,
             cpi.states AS settledstatus,
             ROUND(cpi.price,2) AS total_amt,
             0 AS insurance_amt,
@@ -63,7 +63,7 @@
             '0000000000000' AS credential_num,
             IF( cm.medicine_category = '04', '2', '1') AS item_type,
             cso.medicine_name AS store_medicine_name,
-            cso.med_ins_backup_id AS store_medicine_code,
+            IF( length( cso.med_ins_backup_id ) > 0, cm.med_ins_backup_id, cm.medicine_id ) AS store_medicine_code,
             '' AS plat_item_code,
             '' AS plat_item_name,
             if(ifnull(idm.standard_menu_code,'')='','999999999',idm.standard_menu_code) as item_code,
@@ -112,6 +112,11 @@
         ON
             cso.stock_detail_id = csd.id
             and cso.clinic_id = csd.clinic_id
+        left join
+            ins_clinic_settlement as ics
+        on
+            ics.clinic_id = csd.clinic_id
+            and cpi.prescription_id = ics.prescription_id
         WHERE
             cso.clinic_id = #{clinicId}
         AND
@@ -119,6 +124,27 @@
         AND
             cso.change_type in (1, 2)
         and cso.source_type = 1
+        <choose>
+            <when test='dateType == "d" and count != null'>
+                and cso.create_time between date_sub(curdate(), interval #{count} day) and now()
+            </when>
+            <when test='dateType == "m" and count != null'>
+                and cso.create_time between date_sub(curdate(), interval #{count} month) and now()
+            </when>
+            <when test='dateType == "y" and count != null'>
+                and cso.create_time between date_sub(curdate(), interval #{count} year) and now()
+            </when>
+        </choose>
+        <if test='dateType == "s" and startDate != "" and startDate != null'>
+            <![CDATA[
+                        and cso.create_time >= str_to_date(#{startDate},'%Y%m%d')
+                    ]]>
+        </if>
+        <if test='dateType == "s" and endDate != "" and endDate != null'>
+            <![CDATA[
+                        and cso.create_time <= str_to_date(#{endDate},'%Y%m%d')
+                    ]]>
+        </if>
         GROUP BY
             cso.id
     </select>
@@ -126,7 +152,7 @@
     <select id="listClcChinaMedOrder" resultMap="BaseResultMap" parameterType="java.lang.String">
         SELECT
             cpi.prescription_id AS store_order_no,
-            '99999999' AS mis_no,
+            if(ifnull(ics.settle_transaction_id,'')='','999999999',ics.settle_transaction_id) as mis_no,
             cpi.states AS settledstatus,
             ROUND(cpi.price,2) AS total_amt,
             0 AS insurance_amt,
@@ -138,7 +164,7 @@
         IF
             ( ccm.medicine_category = '04', 2, 1 ) AS item_type,
             ccso.medicine_name AS store_medicine_name,
-            ccso.med_ins_backup_id AS store_medicine_code,
+            IF( length( ccso.med_ins_backup_id ) > 0, ccm.med_ins_backup_id, ccm.medicine_id ) AS store_medicine_code,
             '' AS plat_item_code,
             '' AS plat_item_name,
             if(ifnull(idm.standard_menu_code,'')='','999999999',idm.standard_menu_code) as item_code,
@@ -187,6 +213,11 @@
         ON
             ccso.stock_detail_id = ccsp.id
             and ccso.clinic_id = ccsp.clinic_id
+        left join
+            ins_clinic_settlement as ics
+        on
+            ics.clinic_id = ccso.clinic_id
+            and cpi.prescription_id = ics.prescription_id
         WHERE
             ccso.clinic_id = #{clinicId}
         AND
@@ -194,6 +225,27 @@
         AND
             ccso.change_type in (1, 2)
         and ccso.source_type = 1
+        <choose>
+            <when test='dateType == "d" and count != null'>
+                and ccso.create_time between date_sub(curdate(), interval #{count} day) and now()
+            </when>
+            <when test='dateType == "m" and count != null'>
+                and ccso.create_time between date_sub(curdate(), interval #{count} month) and now()
+            </when>
+            <when test='dateType == "y" and count != null'>
+                and ccso.create_time between date_sub(curdate(), interval #{count} year) and now()
+            </when>
+        </choose>
+        <if test='dateType == "s" and startDate != "" and startDate != null'>
+            <![CDATA[
+                        and ccso.create_time >= str_to_date(#{startDate},'%Y%m%d')
+                    ]]>
+        </if>
+        <if test='dateType == "s" and endDate != "" and endDate != null'>
+            <![CDATA[
+                        and ccso.create_time <= str_to_date(#{endDate},'%Y%m%d')
+                    ]]>
+        </if>
         GROUP BY
             ccso.id
     </select>
@@ -201,10 +253,10 @@
     <select id="listInsClcMedOrder" resultMap="BaseResultMap" parameterType="java.lang.String">
         SELECT
             cpi.prescription_id AS store_order_no,
-            '99999999' AS mis_no,
+            if(ifnull(ics.settle_transaction_id,'')='','999999999',ics.settle_transaction_id) as mis_no,
             cpi.states AS settledstatus,
              ROUND(cpi.price,2) AS total_amt,
-            ifnull( ROUND(ids.ordinate_total_score,2), '0.00' ) AS insurance_amt,
+            ifnull( ROUND(ics.insurance_pay,2), '0.00' ) AS insurance_amt,
             cso.doctor_name AS operater,
             SUBSTR( cso.create_time, 1, 10 ) AS sale_date,
             cso.create_time AS sale_time,
@@ -212,7 +264,7 @@
             '0000000000000' AS credential_num,
             IF( cm.medicine_category = '04', 2, 1 ) AS item_type,
             cso.medicine_name AS store_medicine_name,
-            cso.med_ins_backup_id AS store_medicine_code,
+            IF( length( cso.med_ins_backup_id ) > 0, cm.med_ins_backup_id, cm.medicine_id ) AS store_medicine_code,
             '' AS plat_item_code,
             '' AS plat_item_name,
             if(ifnull(idm.standard_menu_code,'')='','999999999',idm.standard_menu_code) as item_code,
@@ -252,13 +304,32 @@
             left join ins_clinic_settlement ics
             on ics.prescription_id = cso.prescription_id
             and ics.clinic_id = cso.clinic_id
-            LEFT JOIN ins_d_settlement ids ON ids.settlement_id = ics.id
-            AND ids.clinic_id = cso.clinic_id
         WHERE
             cso.clinic_id = #{clinicId}
             AND cpi.prescription_type = 0
             AND cso.change_type IN ( 1, 2 )
             AND cso.source_type IN ( 2, 3 )
+        <choose>
+            <when test='dateType == "d" and count != null'>
+                and cso.create_time between date_sub(curdate(), interval #{count} day) and now()
+            </when>
+            <when test='dateType == "m" and count != null'>
+                and cso.create_time between date_sub(curdate(), interval #{count} month) and now()
+            </when>
+            <when test='dateType == "y" and count != null'>
+                and cso.create_time between date_sub(curdate(), interval #{count} year) and now()
+            </when>
+        </choose>
+        <if test='dateType == "s" and startDate != "" and startDate != null'>
+            <![CDATA[
+                        and cso.create_time >= str_to_date(#{startDate},'%Y%m%d')
+                    ]]>
+        </if>
+        <if test='dateType == "s" and endDate != "" and endDate != null'>
+            <![CDATA[
+                        and cso.create_time <= str_to_date(#{endDate},'%Y%m%d')
+                    ]]>
+        </if>
         GROUP BY
             cso.id
     </select>
@@ -266,10 +337,10 @@
     <select id="listInsClcChinaMedOrder" resultMap="BaseResultMap" parameterType="java.lang.String">
         SELECT
             cpi.prescription_id AS store_order_no,
-            '99999999' AS mis_no,
+            if(ifnull(ics.settle_transaction_id,'')='','999999999',ics.settle_transaction_id) as mis_no,
             cpi.states AS settledstatus,
             ROUND(cpi.price,2) AS total_amt,
-            ifnull( ROUND(ids.ordinate_total_score,2), '0.00' ) AS insurance_amt,
+            ifnull( ROUND(ics.insurance_pay,2), '0.00' ) AS insurance_amt,
             cso.doctor_name AS operater,
             SUBSTR( cso.create_time, 1, 10 ) AS sale_date,
             cso.create_time AS sale_time,
@@ -277,7 +348,7 @@
             '0000000000000' AS credential_num,
             IF( ccm.medicine_category = '04', 2, 1 ) AS item_type,
             cso.medicine_name AS store_medicine_name,
-            cso.med_ins_backup_id AS store_medicine_code,
+            IF( length( cso.med_ins_backup_id ) > 0, ccm.med_ins_backup_id, ccm.medicine_id ) AS store_medicine_code,
             '' AS plat_item_code,
             '' AS plat_item_name,
             if(ifnull(idm.standard_menu_code,'')='','999999999',idm.standard_menu_code) as item_code,
@@ -321,14 +392,32 @@
             LEFT JOIN ins_clinic_settlement ics
             ON ics.prescription_id = cso.prescription_id
             AND ics.clinic_id = cso.clinic_id
-            LEFT JOIN ins_d_settlement ids
-            ON ids.settlement_id = ics.id
-            AND ids.clinic_id = cso.clinic_id
         WHERE
             cso.clinic_id = #{clinicId}
             AND cpi.prescription_type = 1
             AND cso.change_type IN ( 1, 2 )
             AND cso.source_type in (2, 3)
+        <choose>
+            <when test='dateType == "d" and count != null'>
+                and cso.create_time between date_sub(curdate(), interval #{count} day) and now()
+            </when>
+            <when test='dateType == "m" and count != null'>
+                and cso.create_time between date_sub(curdate(), interval #{count} month) and now()
+            </when>
+            <when test='dateType == "y" and count != null'>
+                and cso.create_time between date_sub(curdate(), interval #{count} year) and now()
+            </when>
+        </choose>
+        <if test='dateType == "s" and startDate != "" and startDate != null'>
+            <![CDATA[
+                        and cso.create_time >= str_to_date(#{startDate},'%Y%m%d')
+                    ]]>
+        </if>
+        <if test='dateType == "s" and endDate != "" and endDate != null'>
+            <![CDATA[
+                        and cso.create_time <= str_to_date(#{endDate},'%Y%m%d')
+                    ]]>
+        </if>
         GROUP BY
             cso.id
     </select>
@@ -336,10 +425,10 @@
     <select id="listHosMedOrder" resultMap="BaseResultMap" parameterType="java.lang.String">
         SELECT
             cpi.prescription_id AS store_order_no,
-            '99999999' AS mis_no,
+            if(ifnull(ics.settle_transaction_id,'')='','999999999',ics.settle_transaction_id) as mis_no,
             cpi.states AS settledstatus,
             ROUND(cpi.price,2) AS total_amt,
-            ifnull( ROUND(ids.ordinate_total_score,2), '0.00' ) AS insurance_amt,
+            ifnull( ROUND(ics.insurance_pay,2), '0.00' ) AS insurance_amt,
             cso.doctor_name AS operater,
             SUBSTR( cso.create_time, 1, 10 ) AS sale_date,
             cso.create_time AS sale_time,
@@ -348,7 +437,7 @@
         IF
             ( cm.medicine_category = '04', 2, 1 ) AS item_type,
             cso.medicine_name AS store_medicine_name,
-            cso.med_ins_backup_id AS store_medicine_code,
+            IF( length( cso.med_ins_backup_id ) > 0, cm.med_ins_backup_id, cm.medicine_id ) AS store_medicine_code,
             '' AS plat_item_code,
             '' AS plat_item_name,
             if(ifnull(idm.standard_menu_code,'')='','999999999',idm.standard_menu_code) as item_code,
@@ -390,24 +479,35 @@
             ON cso.stock_detail_id = csd.id
             AND cso.clinic_id = csd.clinic_id
             AND cso.medicine_id = csd.medicine_id
-            LEFT JOIN (
-            SELECT
-                t.clinic_id,
-                t.total_score,
-                t.ordinate_total_score,
-                t.settlement_id,
-                t.visit_code
-            FROM
-                ins_d_settlement t
-            WHERE
-                t.settlement_id IN ( SELECT settlement_id FROM ins_d_settlement GROUP BY settlement_id HAVING count( settlement_id ) = 1 )
-            ) ids ON ids.visit_code = cpi.visit_code
-            AND ids.clinic_id = cso.clinic_id
+            LEFT JOIN ins_clinic_settlement ics
+            ON ics.prescription_id = cso.prescription_id
+            AND ics.clinic_id = cso.clinic_id
         WHERE
             cso.clinic_id = #{clinicId}
            AND cpi.prescription_type = 0
             AND cso.change_type IN ( 1, 2 )
             AND cso.source_type = 4
+        <choose>
+            <when test='dateType == "d" and count != null'>
+                and cso.create_time between date_sub(curdate(), interval #{count} day) and now()
+            </when>
+            <when test='dateType == "m" and count != null'>
+                and cso.create_time between date_sub(curdate(), interval #{count} month) and now()
+            </when>
+            <when test='dateType == "y" and count != null'>
+                and cso.create_time between date_sub(curdate(), interval #{count} year) and now()
+            </when>
+        </choose>
+        <if test='dateType == "s" and startDate != "" and startDate != null'>
+            <![CDATA[
+                        and cso.create_time >= str_to_date(#{startDate},'%Y%m%d')
+                    ]]>
+        </if>
+        <if test='dateType == "s" and endDate != "" and endDate != null'>
+            <![CDATA[
+                        and cso.create_time <= str_to_date(#{endDate},'%Y%m%d')
+                    ]]>
+        </if>
         GROUP BY
             cso.id
     </select>
@@ -415,10 +515,10 @@
     <select id="listHosChinaMedOrder" resultMap="BaseResultMap" parameterType="java.lang.String">
         SELECT
             cpi.prescription_id AS store_order_no,
-            '99999999' AS mis_no,
+            if(ifnull(ics.settle_transaction_id,'')='','999999999',ics.settle_transaction_id) as mis_no,
             cpi.states AS settledstatus,
             ROUND(cpi.price,2) AS total_amt,
-            ifnull( ROUND(ids.ordinate_total_score,2), '0.00' ) AS insurance_amt,
+            ifnull( ROUND(ics.ordinate_total_score,2), '0.00' ) AS insurance_amt,
             cso.doctor_name AS operater,
             SUBSTR( cso.create_time, 1, 10 ) AS sale_date,
             cso.create_time AS sale_time,
@@ -427,7 +527,7 @@
         IF
             ( ccm.medicine_category = '04', 2, 1 ) AS item_type,
             cso.medicine_name AS store_medicine_name,
-            cso.med_ins_backup_id AS store_medicine_code,
+            IF( length( cso.med_ins_backup_id ) > 0, ccm.med_ins_backup_id, ccm.medicine_id ) AS store_medicine_code,
             '' AS plat_item_code,
             '' AS plat_item_name,
             if(ifnull(idm.standard_menu_code,'')='','999999999',idm.standard_menu_code) as item_code,
@@ -468,24 +568,35 @@
             LEFT JOIN clc_china_stock_profit csd
             ON cso.stock_detail_id = csd.id
             AND cso.clinic_id = csd.clinic_id
-            LEFT JOIN (
-            SELECT
-                t.clinic_id,
-                t.total_score,
-                t.ordinate_total_score,
-                t.settlement_id,
-                t.visit_code
-            FROM
-                ins_d_settlement t
-            WHERE
-                t.settlement_id IN ( SELECT settlement_id FROM ins_d_settlement GROUP BY settlement_id HAVING count( settlement_id ) = 1 )
-            ) ids ON ids.visit_code = cpi.visit_code
-            AND ids.clinic_id = cso.clinic_id
+            LEFT JOIN ins_clinic_settlement ics
+            ON ics.prescription_id = cso.prescription_id
+            AND ics.clinic_id = cso.clinic_id
         WHERE
             cso.clinic_id = #{clinicId}
             AND cpi.prescription_type = 1
             AND cso.change_type IN ( 1, 2 )
             AND cso.source_type = 4
+        <choose>
+            <when test='dateType == "d" and count != null'>
+                and cso.create_time between date_sub(curdate(), interval #{count} day) and now()
+            </when>
+            <when test='dateType == "m" and count != null'>
+                and cso.create_time between date_sub(curdate(), interval #{count} month) and now()
+            </when>
+            <when test='dateType == "y" and count != null'>
+                and cso.create_time between date_sub(curdate(), interval #{count} year) and now()
+            </when>
+        </choose>
+        <if test='dateType == "s" and startDate != "" and startDate != null'>
+            <![CDATA[
+                        and cso.create_time >= str_to_date(#{startDate},'%Y%m%d')
+                    ]]>
+        </if>
+        <if test='dateType == "s" and endDate != "" and endDate != null'>
+            <![CDATA[
+                        and cso.create_time <= str_to_date(#{endDate},'%Y%m%d')
+                    ]]>
+        </if>
         GROUP BY
             cso.id
     </select>

+ 2 - 1
src/main/resources/mybatis/mybatis-config.xml

@@ -24,6 +24,7 @@
         <!-- 数据库超过25000秒仍未响应则超时 -->
         <setting name="defaultStatementTimeout" value="25000" />
         <!-- 打印查询语句,如果将它注释,你的sql就可以打印进日志;如果将它放开,你的sql就打印到了控制台 -->
-        <!-- <setting name="logImpl" value="STDOUT_LOGGING" /> -->
+<!--        <setting name="logImpl" value="SLF4J" />-->
+         <setting name="logImpl" value="STDOUT_LOGGING" />
     </settings>
 </configuration>