Index: ssts-recyclingapplication/src/test/java/com/forgon/disinfectsystem/recyclingapplication/service/RecyclingApplicationLimitApplyServiceImplLoadRecyclingApplicationTest.java
===================================================================
diff -u
--- ssts-recyclingapplication/src/test/java/com/forgon/disinfectsystem/recyclingapplication/service/RecyclingApplicationLimitApplyServiceImplLoadRecyclingApplicationTest.java (revision 0)
+++ ssts-recyclingapplication/src/test/java/com/forgon/disinfectsystem/recyclingapplication/service/RecyclingApplicationLimitApplyServiceImplLoadRecyclingApplicationTest.java (revision 41651)
@@ -0,0 +1,175 @@
+package com.forgon.disinfectsystem.recyclingapplication.service;
+
+import com.forgon.disinfectsystem.entity.adverseeventrecord.AdverseEventRecord;
+import com.forgon.disinfectsystem.entity.invoicemanager.Invoice;
+import com.forgon.disinfectsystem.entity.recyclingapplication.RecyclingApplication;
+import com.forgon.disinfectsystem.entity.tousseitem.TousseItem;
+import net.sf.json.JSONObject;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.when;
+
+/**
+ * RecyclingApplicationLimitApplyServiceImpl 单元测试类
+ */
+public class RecyclingApplicationLimitApplyServiceImplLoadRecyclingApplicationTest {
+
+ // 注入被测试的服务实现类
+ @InjectMocks
+ private RecyclingApplicationLimitApplyServiceImpl recyclingApplicationLimitApplyService;
+
+ // 模拟依赖的 manager 类
+ @Mock
+ private RecyclingApplicationManager recyclingApplicationManager;
+ private AutoCloseable autoCloseable;
+
+ @Before
+ public void setUp() {
+ // 初始化 Mockito 注解
+ autoCloseable = MockitoAnnotations.openMocks(this);
+ }
+ @After
+ public void tearDown() throws Exception {
+ autoCloseable.close();
+ }
+
+ /**
+ * 测试正常情况下加载回收申请单
+ * 场景:给定有效的部门编码,能够正确返回JSON格式的申请单信息
+ */
+ @Test
+ public void testLoadRecyclingApplication_NormalCase() {
+ // 准备测试数据
+ String departmentCode = "DEPT001";
+ RecyclingApplication recyclingApplication = new RecyclingApplication();
+ recyclingApplication.setId(1L);
+ recyclingApplication.setDepartCoding(departmentCode);
+ recyclingApplication.setApplicationItems(Arrays.asList(new TousseItem("TousseItem1", "TousseType1", 10)));
+ recyclingApplication.setInvoice(Collections.singletonList(new Invoice()));
+ recyclingApplication.setRecyclingApplications(Collections.singletonList(new RecyclingApplication()));
+ recyclingApplication.setParent(new RecyclingApplication());
+ recyclingApplication.setAdverseEventRecords(Collections.singletonList(new AdverseEventRecord()));
+
+ // 模拟 manager 行为
+ when(recyclingApplicationManager.findRecyclingApplicationBySql(anyString()))
+ .thenReturn(recyclingApplication);
+
+ // 执行测试方法
+ String result = recyclingApplicationLimitApplyService.loadRecyclingApplication(departmentCode);
+
+ // 验证结果
+ assertNotNull(result, "返回的JSON字符串不应为null");
+ assertFalse(result.isEmpty(), "返回的JSON字符串不应为空");
+
+ // 验证返回的是有效的JSON对象
+ assertDoesNotThrow(() -> JSONObject.fromObject(result), "应能将结果解析为JSONObject");
+
+ JSONObject jsonObject = JSONObject.fromObject(result);
+ assertTrue(jsonObject.containsKey("id"), "JSON对象应该包含id字段");
+ assertEquals(1L, jsonObject.getLong("id"), "id值应该匹配");
+ assertFalse(jsonObject.containsKey("applicationItems"), "applicationItems字段应该被过滤掉");
+ assertFalse(jsonObject.containsKey("invoice"), "invoice字段应该被过滤掉");
+ assertFalse(jsonObject.containsKey("recyclingApplications"), "recyclingApplications字段应该被过滤掉");
+ assertFalse(jsonObject.containsKey("parent"), "parent字段应该被过滤掉");
+ assertFalse(jsonObject.containsKey("adverseEventRecords"), "adverseEventRecords字段应该被过滤掉");
+ }
+
+ /**
+ * 测试当部门编码为空时的情况
+ * 场景:传入空字符串作为部门编码
+ */
+ @Test
+ public void testLoadRecyclingApplication_EmptyDepartmentCode() {
+ // 准备测试数据
+ String departmentCode = "";
+ RecyclingApplication recyclingApplication = new RecyclingApplication();
+ recyclingApplication.setDepartCoding(departmentCode);
+
+ // 模拟 manager 行为
+ when(recyclingApplicationManager.findRecyclingApplicationBySql(anyString()))
+ .thenReturn(recyclingApplication);
+
+ // 执行测试方法
+ String result = recyclingApplicationLimitApplyService.loadRecyclingApplication(departmentCode);
+
+ // 验证结果
+ assertNotNull(result, "返回的JSON字符串不应为null");
+ assertFalse(result.isEmpty(), "返回的JSON字符串不应为空");
+
+ // 验证返回的是有效的JSON对象
+ assertDoesNotThrow(() -> JSONObject.fromObject(result), "应能将结果解析为JSONObject");
+ }
+
+ /**
+ * 测试当没有找到对应的回收申请单时的情况
+ * 场景:manager 返回 null
+ */
+ @Test
+ public void testLoadRecyclingApplication_NoApplicationFound() {
+ // 准备测试数据
+ String departmentCode = "NONEXISTENT";
+
+ // 模拟 manager 行为,返回null
+ when(recyclingApplicationManager.findRecyclingApplicationBySql(anyString()))
+ .thenReturn(null);
+
+ // 执行测试方法
+ String result = recyclingApplicationLimitApplyService.loadRecyclingApplication(departmentCode);
+
+ // 验证结果
+ assertNotNull(result, "返回的JSON字符串不应为null");
+ assertFalse(result.isEmpty(), "返回的JSON字符串不应为空");
+
+ // 验证返回的是表示null对象的JSON
+ JSONObject jsonObject = JSONObject.fromObject(result);
+ assertTrue(jsonObject.isNullObject(), "应当返回一个null对象的JSON表示");
+ }
+
+ /**
+ * 测试包含复杂嵌套对象的回收申请单序列化
+ * 场景:返回的申请单包含应该被过滤的复杂属性
+ */
+ @Test
+ public void testLoadRecyclingApplication_WithComplexObjects() {
+ // 准备测试数据
+ String departmentCode = "DEPT002";
+ RecyclingApplication mockApplication = new RecyclingApplication();
+ mockApplication.setId(2L);
+ mockApplication.setDepartCoding(departmentCode);
+ // 注意:这里不设置 applicationItems 等复杂属性,因为实际中它们可能通过其他方式添加
+
+ // 模拟 manager 行为
+ when(recyclingApplicationManager.findRecyclingApplicationBySql(anyString()))
+ .thenReturn(mockApplication);
+
+ // 执行测试方法
+ String result = recyclingApplicationLimitApplyService.loadRecyclingApplication(departmentCode);
+
+ // 验证结果
+ assertNotNull(result, "返回的JSON字符串不应为null");
+ assertFalse(result.isEmpty(), "返回的JSON字符串不应为空");
+
+ // 验证返回的是有效的JSON对象
+ assertDoesNotThrow(() -> JSONObject.fromObject(result), "应能将结果解析为JSONObject");
+
+ JSONObject jsonObject = JSONObject.fromObject(result);
+ assertTrue(jsonObject.containsKey("id"), "JSON对象应该包含id字段");
+ assertEquals(2L, jsonObject.getLong("id"), "id值应该匹配");
+ // 验证被过滤的字段不存在于结果中
+ assertFalse(jsonObject.containsKey("applicationItems"), "applicationItems字段应该被过滤掉");
+ assertFalse(jsonObject.containsKey("invoice"), "invoice字段应该被过滤掉");
+ assertFalse(jsonObject.containsKey("recyclingRecord"), "recyclingRecord字段应该被过滤掉");
+ assertFalse(jsonObject.containsKey("handler"), "handler字段应该被过滤掉");
+ assertFalse(jsonObject.containsKey("hibernateLazyInitializer"), "hibernateLazyInitializer字段应该被过滤掉");
+ }
+}
Index: ssts-recyclingapplication/src/main/java/com/forgon/disinfectsystem/recyclingapplication/service/RecyclingApplicationLimitApplyService.java
===================================================================
diff -u
--- ssts-recyclingapplication/src/main/java/com/forgon/disinfectsystem/recyclingapplication/service/RecyclingApplicationLimitApplyService.java (revision 0)
+++ ssts-recyclingapplication/src/main/java/com/forgon/disinfectsystem/recyclingapplication/service/RecyclingApplicationLimitApplyService.java (revision 41651)
@@ -0,0 +1,15 @@
+package com.forgon.disinfectsystem.recyclingapplication.service;
+
+/**
+ * limitApply是config.js中的一个配置项,用来限制同一个科室只有一张申请单,直到供应室回收后才允许再次申请(创建新申请单)。
+ * 只针对临床科室,对于手术室的使用记录转换申请单,不作限制。并且只限制通用申请单
+ * 详情查看 DGZYY-120
+ */
+public interface RecyclingApplicationLimitApplyService {
+ /**
+ * 查询科室的申请单
+ * @param departmentCode 申请科室的科室编码
+ * @return 申请单信息的Json字符串
+ */
+ String loadRecyclingApplication(String departmentCode);
+}
Index: ssts-recyclingapplication/src/main/java/com/forgon/disinfectsystem/recyclingapplication/service/RecyclingApplicationLimitApplyServiceImpl.java
===================================================================
diff -u
--- ssts-recyclingapplication/src/main/java/com/forgon/disinfectsystem/recyclingapplication/service/RecyclingApplicationLimitApplyServiceImpl.java (revision 0)
+++ ssts-recyclingapplication/src/main/java/com/forgon/disinfectsystem/recyclingapplication/service/RecyclingApplicationLimitApplyServiceImpl.java (revision 41651)
@@ -0,0 +1,39 @@
+package com.forgon.disinfectsystem.recyclingapplication.service;
+
+import com.forgon.disinfectsystem.entity.invoicemanager.InvoicePlan;
+import com.forgon.disinfectsystem.entity.recyclingapplication.RecyclingApplication;
+import com.forgon.tools.json.JsonPropertyFilter;
+import net.sf.json.JSONObject;
+import net.sf.json.JsonConfig;
+import net.sf.json.util.CycleDetectionStrategy;
+import net.sf.json.util.PropertyFilter;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service("recyclingApplicationLimitApplyService")
+public class RecyclingApplicationLimitApplyServiceImpl implements RecyclingApplicationLimitApplyService{
+ @Autowired
+ private RecyclingApplicationManager recyclingApplicationManager;
+ @Override
+ public String loadRecyclingApplication(String departmentCode) {
+ String json = "";
+ JsonConfig config = new JsonConfig();
+ PropertyFilter propertyFilter = new JsonPropertyFilter(new String[] {
+ "applicationItems", "invoice",
+ "recyclingRecord", "recyclingApplications", "parent",
+ "recyclingRecords", "adverseEventRecords" });
+ config.setJsonPropertyFilter(propertyFilter);
+ config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
+ //设置hibernate延时加载器句柄,以防申请单的submitTime值为空时调用JSONObject.fromObject报错
+ config.setExcludes(new String[]{"handler","hibernateLazyInitializer"});
+
+ String hqlWhere = String.format("where type='%s' and departCoding='%s' and po.useRecord is null "
+ + "and ((recyclingStatus='%s') or (recyclingStatus is null and deliverStatus<>'%s' and deliverStatus<>'%s' and deliverStatus<>'%s')) "
+ + "order by po.id desc",
+ InvoicePlan.TYPE_COMBO_FORM, departmentCode, InvoicePlan.RECYCLINGSTATUS_AWAITRECYCLE,
+ InvoicePlan.STATUS_END, InvoicePlan.DELIVERSTATUS_PARTDELIVERED, InvoicePlan.DELIVERSTATUS_DELIVERED);
+ RecyclingApplication recyclingApplication = recyclingApplicationManager.findRecyclingApplicationBySql(hqlWhere);
+ json = JSONObject.fromObject(recyclingApplication, config).toString();
+ return json;
+ }
+}
Index: ssts-recyclingapplication/src/main/java/com/forgon/disinfectsystem/recyclingapplication/dwr/table/RecyclingApplicationTableManager.java
===================================================================
diff -u -r39696 -r41651
--- ssts-recyclingapplication/src/main/java/com/forgon/disinfectsystem/recyclingapplication/dwr/table/RecyclingApplicationTableManager.java (.../RecyclingApplicationTableManager.java) (revision 39696)
+++ ssts-recyclingapplication/src/main/java/com/forgon/disinfectsystem/recyclingapplication/dwr/table/RecyclingApplicationTableManager.java (.../RecyclingApplicationTableManager.java) (revision 41651)
@@ -15,6 +15,7 @@
import java.util.Map;
import java.util.Set;
+import com.forgon.disinfectsystem.recyclingapplication.service.RecyclingApplicationLimitApplyService;
import net.sf.json.JSONArray;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
@@ -123,7 +124,13 @@
private OperationManager operationManager;
private SpecialInfectionManager specialInfectionManager;
-
+
+ private RecyclingApplicationLimitApplyService recyclingApplicationLimitApplyService;
+
+ public void setRecyclingApplicationLimitApplyService(RecyclingApplicationLimitApplyService recyclingApplicationLimitApplyService) {
+ this.recyclingApplicationLimitApplyService = recyclingApplicationLimitApplyService;
+ }
+
public void setSpecialInfectionManager(
SpecialInfectionManager specialInfectionManager) {
this.specialInfectionManager = specialInfectionManager;
@@ -641,25 +648,7 @@
* @return
*/
public String getRecyclingApplicationByDepartmentCode(String departmentCode) {
- String json = "";
- JsonConfig config = new JsonConfig();
- PropertyFilter propertyFilter = new JsonPropertyFilter(new String[] {
- "applicationItems", "invoice",
- "recyclingRecord", "recyclingApplications", "parent",
- "recyclingRecords", "adverseEventRecords" });
- config.setJsonPropertyFilter(propertyFilter);
- config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
- //设置hibernate延时加载器句柄,以防申请单的submitTime值为空时调用JSONObject.fromObject报错
- config.setExcludes(new String[]{"handler","hibernateLazyInitializer"});
-
- String hqlWhere = String.format("where type='%s' and departCoding='%s' and po.useRecord is null "
- + "and ((recyclingStatus='%s') or (recyclingStatus is null and deliverStatus<>'%s' and deliverStatus<>'%s' and deliverStatus<>'%s')) "
- + "order by po.id desc",
- InvoicePlan.TYPE_COMBO_FORM, departmentCode, InvoicePlan.RECYCLINGSTATUS_AWAITRECYCLE,
- InvoicePlan.STATUS_END, InvoicePlan.DELIVERSTATUS_PARTDELIVERED, InvoicePlan.DELIVERSTATUS_DELIVERED);
- RecyclingApplication recyclingApplication = recyclingApplicationManager.findRecyclingApplicationBySql(hqlWhere);
- json = JSONObject.fromObject(recyclingApplication, config).toString();
- return json;
+ return recyclingApplicationLimitApplyService.loadRecyclingApplication(departmentCode);
}
public boolean isSaveSterileGoods(String id){
boolean isrecycle = isHasRecyclingRecordByRecyclingAppId(id);