| 
					
				 | 
			
			
				@@ -1,15 +1,18 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package thyyxxk.webserver.service.zhuyuanyiji; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import lombok.extern.slf4j.Slf4j; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import thyyxxk.webserver.config.exception.ExceptionEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import thyyxxk.webserver.dao.his.zhuyuanyiji.MedicineManagementDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import thyyxxk.webserver.entity.ResultVo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import thyyxxk.webserver.entity.medicaltechnology.AsidePage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import thyyxxk.webserver.entity.medicaltechnology.FetchMedicines; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import thyyxxk.webserver.entity.medicaltechnology.MedicinePage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import thyyxxk.webserver.entity.medicaltechnology.PoisonousAnesthetics; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import thyyxxk.webserver.service.PublicServer; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import thyyxxk.webserver.service.redislike.RedisLikeService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import thyyxxk.webserver.utils.ResultVoUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import thyyxxk.webserver.utils.StringUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import thyyxxk.webserver.utils.TokenUtil; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -22,17 +25,18 @@ import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 public class MedicineManagementService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final MedicineManagementDao dao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final PublicServer publicService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final RedisLikeService redis; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public MedicineManagementService(MedicineManagementDao dao, PublicServer publicService) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public MedicineManagementService(MedicineManagementDao dao, PublicServer publicService, RedisLikeService redis) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         this.dao = dao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         this.publicService = publicService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        this.redis = redis; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public ResultVo<List<MedicinePage>> fetchMedicinePages(FetchMedicines params) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         transformDateToDatetime(params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        buildChildDepartments(params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        List<MedicinePage> list = dao.selectMedicinePages(params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<MedicinePage> list = dao.selectMedicinePages(buildFetchPageNoQw(params)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (list.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -49,18 +53,31 @@ public class MedicineManagementService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return ResultVoUtil.success(list); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public ResultVo<List<MedicinePage>> submitMedicinePages(FetchMedicines newMedicinePage) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (StringUtil.isBlank(newMedicinePage.getChargeCodes())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public ResultVo<List<MedicinePage>> submitMedicinePages(FetchMedicines params) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (StringUtil.isBlank(params.getChargeCodes())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "请勾选需要提交的药品。"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         int pageNo = publicService.getTheDrugListNo(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         dao.deleteExistTargetPageNo(pageNo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        transformDateToDatetime(newMedicinePage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        newMedicinePage.setPageNo(pageNo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        dao.insertNewPageNo(newMedicinePage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        dao.submitMedicinePages(newMedicinePage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        log.info("【操作员:{}】提交药品单:{}", TokenUtil.getTokenUserId(), newMedicinePage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return ResultVoUtil.success(dao.selectMedicinePages(newMedicinePage)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        transformDateToDatetime(params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        params.setPageNo(pageNo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        dao.insertNewPageNo(params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        dao.submitMedicinePages(params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        log.info("【操作员:{}】提交药品单:{}", TokenUtil.getTokenUserId(), params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return ResultVoUtil.success(dao.selectMedicinePages(buildFetchPageNoQw(params))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private QueryWrapper<?> buildFetchPageNoQw(FetchMedicines params) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        QueryWrapper<?> qw = new QueryWrapper<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        qw.ge("charge_date", params.getStart()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .le("charge_date", params.getEnd()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq("isnull(a.page_no,0)", "0") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq("isnull(confirm_flag,'0')", "0") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq("a.group_no", "73") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .apply(" a.charge_code=b.code and isnull(a.serial,'01')=b.serial") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .in("exec_unit", publicService.getChildDeptByUserCode(false)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .groupBy("b.code,b.serial having sum(a.amount)!=0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return qw; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public ResultVo<Map<String, Object>> fetchPoisonousAnesthetics(FetchMedicines params) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -94,6 +111,35 @@ public class MedicineManagementService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return ResultVoUtil.success(map); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public ResultVo<List<AsidePage>> fetchSubmittedPageNos(FetchMedicines params) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        transformDateToDatetime(params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        QueryWrapper<?> qw = new QueryWrapper<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        qw.ge("charge_date", params.getStart()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .le("charge_date", params.getEnd()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .gt("page_no", 0).eq("group_no", "73") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .in("exec_unit", publicService.getChildDeptByUserCode(false)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .groupBy("page_no,exec_unit"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (null != params.getPageNo()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            qw.eq("page_no", params.getPageNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<AsidePage> list = dao.selectSubmittedPageNos(qw); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (list.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        list.forEach(item -> item.setConfirmId(redis.getEmployeeName(item.getConfirmId()))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return ResultVoUtil.success(list); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public ResultVo<List<MedicinePage>> fetchMedicinePageDetail(AsidePage params) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        QueryWrapper<?> qw = new QueryWrapper<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        qw.eq("a.page_no", params.getPageNo()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq("a.group_no", "73") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .eq("a.exec_unit", params.getExecUnit()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .apply("a.charge_code=b.code and isnull(a.serial,'01')=b.serial") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .groupBy("b.code,b.serial having sum(a.amount)!=0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return ResultVoUtil.success(dao.fetchMedicinePageDetail(qw)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private void transformDateToDatetime(FetchMedicines params) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         params.setStart(params.getStart() + " 00:00:00.000"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         params.setEnd(params.getEnd() + " 23:59:59.999"); 
			 |