Index: ssts-recyclingapplication/src/main/java/com/forgon/disinfectsystem/recyclingapplication/controller/RecyclingApplicationController.java =================================================================== diff -u --- ssts-recyclingapplication/src/main/java/com/forgon/disinfectsystem/recyclingapplication/controller/RecyclingApplicationController.java (revision 0) +++ ssts-recyclingapplication/src/main/java/com/forgon/disinfectsystem/recyclingapplication/controller/RecyclingApplicationController.java (revision 24373) @@ -0,0 +1,216 @@ +package com.forgon.disinfectsystem.recyclingapplication.controller; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.sf.json.JSON; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; +import net.sf.json.JsonConfig; +import net.sf.json.util.CycleDetectionStrategy; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.time.DateUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +import com.forgon.databaseadapter.service.DateQueryAdapter; +import com.forgon.directory.acegi.tools.AcegiHelper; +import com.forgon.directory.vo.LoginUserData; +import com.forgon.disinfectsystem.basedatamanager.supplier.service.SupplierManager; +import com.forgon.disinfectsystem.basedatamanager.supplyroomconfig.service.SupplyRoomConfigManager; +import com.forgon.disinfectsystem.common.CssdUtils; +import com.forgon.disinfectsystem.entity.basedatamanager.supplier.Supplier; +import com.forgon.disinfectsystem.entity.foreigntousseapplication.ForeignTousseApplication; +import com.forgon.disinfectsystem.entity.invoicemanager.InvoicePlan; +import com.forgon.disinfectsystem.entity.recyclingapplication.RecyclingApplication; +import com.forgon.disinfectsystem.recyclingapplication.service.ReAppTableSqlHandler; +import com.forgon.disinfectsystem.recyclingapplication.service.RecyclingApplicationManager; +import com.forgon.tools.SqlBuilder; +import com.forgon.tools.db.DatabaseUtil; +import com.forgon.tools.hibernate.ObjectDao; +import com.forgon.tools.json.JSONUtil; +import com.forgon.tools.string.StringTools; +import com.forgon.tools.util.SpringUtils; +import com.forgon.tools.util.SqlUtils; + +/** + * 申请单controller类 + * @author shuyongfu + * @since date 2018-09-24 + * + */ +@Controller +@RequestMapping("/disinfectSystem/recyclingApplication/recyclingApplicationController") +public class RecyclingApplicationController { + + @Autowired + private SupplyRoomConfigManager supplyRoomConfigManager; + + @Autowired + private DateQueryAdapter dateQueryAdapter; + + @Autowired + private SupplierManager supplierManager; + + @Autowired + private RecyclingApplicationManager recyclingApplicationManager; + + @Autowired + private ObjectDao objectDao; + + /** + * 默认每页查询数量为20 + */ + static final int DEFAULT_LIMIT = 20; + + static JsonConfig jsonConfig = null; + static{ + jsonConfig = new JsonConfig(); + jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.NOPROP); + } + + /** + * 分页查询申请单 + */ + @RequestMapping(value="/findRecyclingApplicationList") + public void findRecyclingApplicationList(){ + String listType = SpringUtils.getPraramValue("listType", "todoList"); + int limit = SpringUtils.getPraramValue("limit", DEFAULT_LIMIT); + int offset = SpringUtils.getPraramValue("offset", 0); + String sort = SpringUtils.getPraramValue("sort", null); + String order = SpringUtils.getPraramValue("order", null); + String search = SpringUtils.getPraramValue("search", null); + String searchFields = SpringUtils.getPraramValue("searchFields", null); + //查询条件 + StringBuilder sqlBuilder = new StringBuilder(" where 1=1 "); + + //1、当前登录用户的过滤(即:1、处理科室用户能看到已经提交的单 2、自己填的单 3、申请科室用户只能看到本科室申请的单(如果是外来器械包申请单那么还要判断用户是否为外来器械租用商配置的“允许申请人”,注意:如果租用商没配置“允许申请人”则本科室的所有用户都可以看) + LoginUserData loginUserData = AcegiHelper.getLoginUser(); + String currentOrgUnitCode = loginUserData.getCurrentOrgUnitCode(); + String userName = loginUserData.getUserName(); + + //1.1.如果当前登录用户为外来器械供应商的申请人员时(对于外来器械申请单只查询该人员对应的供应商的申请单或无未配置申请人员的供应商的申请单、其它类型申请单业务不变) + String foreignTousseAppFilterSql = ""; + List supplierNameList = supplierManager.getSupplierNameListByTypeAndUserCode(Supplier.SUPPLIER_TYPE_RENTTOUSSE, loginUserData.getUserName()); + if(CollectionUtils.isNotEmpty(supplierNameList)){ +// foreignTousseAppFilterSql = " or (po.type <> '"+ InvoicePlan.TYPE_FOREIGNTOUSSEAPPLIACTION +"' or " +// + "(po.type='"+ InvoicePlan.TYPE_FOREIGNTOUSSEAPPLIACTION +"' and po.id in (select id from "+ ForeignTousseApplication.class.getSimpleName() +" where "+ SqlUtils.getStringFieldInLargeCollectionsPredicate("supplierName", supplierNameList) +")))"; + foreignTousseAppFilterSql = " or (po.departCoding = '" + currentOrgUnitCode +"' and po.type='"+ InvoicePlan.TYPE_FOREIGNTOUSSEAPPLIACTION +"' and po.id in (select id from "+ ForeignTousseApplication.class.getSimpleName() +" where "+ SqlUtils.getStringFieldInLargeCollectionsPredicate("supplierName", supplierNameList) +"))"; + } + + String loginUserSql = String.format(" and ((po.handleDepartCoding = '%s' and po.committedStatus = 1) or po.applicantCode='%s' or (po.departCoding = '%s' and po.type<>'%s') %s) ", + currentOrgUnitCode, userName, currentOrgUnitCode, InvoicePlan.TYPE_FOREIGNTOUSSEAPPLIACTION, foreignTousseAppFilterSql); + sqlBuilder.append(loginUserSql); + + //2、不包含的申请单类型 + List excludeTypelist = new ArrayList(); + //判断是否需要显示“代理灭菌单” + if(!CssdUtils.getSystemSetConfigByNameBool("isShowProxyDisinfection", false)){ + excludeTypelist.add(InvoicePlan.TYPE_PROXYDISINFECTION); + } + excludeTypelist.add(InvoicePlan.TYPE_APPLYING_FOR_RETURN_FORM); + excludeTypelist.add(InvoicePlan.TYPE_QUALITY_MONITOR_RECYCLE_APPLICATION); + if (CssdUtils.getSystemSetConfigByNameBool("hideReservationList", false)) { //手术预约申请单 + excludeTypelist.add(InvoicePlan.TYPE_OPERATION_RESERVATION_APPLICATION); + } + excludeTypelist.add(InvoicePlan.TYPE_EXPENSIVEGOODS_FORM); + String excludeTypeSql = String.format(" and %s ", SqlBuilder.build_IN_Statement("po.type", SqlBuilder.NOT_IN, excludeTypelist)); + sqlBuilder.append(excludeTypeSql); + + //3、未处理完的单和今天处理完的单 + if("todoList".equals(listType)){ + //回收状态:待回收,部分回收(针对哪一些不需要发货的) + String recyclingStatusSql = SqlBuilder.createStatus("recyclingStatus", InvoicePlan.RECYCLINGSTATUS_AWAITRECYCLE, InvoicePlan.RECYCLINGSTATUS_PARTRECYCLE); + recyclingStatusSql = String.format("((deliverStatus='' or deliverStatus is null) and %s)", recyclingStatusSql); + + //发货状态:待发货,部分发货,(空:临床添加外部代理单而供应室未装配时的情况发货状态为空) + String deliverStatusSql = SqlBuilder.createStatus("deliverStatus", InvoicePlan.DELIVERSTATUS_AWAITDELIVER, InvoicePlan.DELIVERSTATUS_PARTDELIVERED); + deliverStatusSql = String.format("(((deliverStatus='' or deliverStatus is null) and type='%s') or %s)", InvoicePlan.TYPE_FOREIGNPROXYDISINFECTION, deliverStatusSql); + + //归还状态:未归还,部分归还,归还待确认 + String returnStatusSql = SqlBuilder.createStatus("returnStatus", InvoicePlan.RETURN_STATUS_UNRETURNED, InvoicePlan.RETURN_STATUS_PARTIALLY_RETURNED, InvoicePlan.RETURN_STATUS_AWAITCONFIRM); + + //提交状态:committedStatus等于0 + String commitSql = " (po.committedStatus = 0) "; + + Date now = new Date(); + //今天处理的单 + String todaySql = "po.lastInvoiceTime >= " + dateQueryAdapter.dateAdapter(DateUtils.truncate(now, Calendar.DAY_OF_MONTH)); + + //判断是否需要显示当前终止的申请单 + boolean isShowEndedGoodsApplication = CssdUtils.getSystemSetConfigByNameBool("isShowEndedGoodsApplication", false); + String todayEndSql="1=0"; + if(isShowEndedGoodsApplication==true){ + //今天终止的单 + todayEndSql="po.applicationTime >="+dateQueryAdapter.dateAdapter(DateUtils.truncate(now, Calendar.DAY_OF_MONTH))+" and po.endStatus="+"'"+InvoicePlan.STATUS_END+"'"; + } + sqlBuilder.append(String.format(" and (%s or %s or %s or %s or %s or %s) ", recyclingStatusSql, deliverStatusSql, returnStatusSql, commitSql, todaySql, todayEndSql)); + } + + Map sqlWhereParamMap = new HashMap(); + //4、其他一些条件的过滤 + ReAppTableSqlHandler reAppTableSqlHandler = ReAppTableSqlHandler.getInstance(dateQueryAdapter); + reAppTableSqlHandler.createFilterSql(sqlWhereParamMap, sqlBuilder); + + //5、根据时间过滤(1、时间不为空 2、如果非供应室用户,满足1或2则需要按时间过滤,否则不需要) + String startTime = SpringUtils.getPraramValue("startTime", null); + String endTime = SpringUtils.getPraramValue("endTime", null); + String timeSearchFmt = SpringUtils.getPraramValue("timeSearchFmt", null); + if ((StringTools.isNotBlank(startTime) && StringTools.isNotBlank(endTime)) || !supplyRoomConfigManager.isSupplyRoomUser(AcegiHelper.getLoginUser())) { + reAppTableSqlHandler.createTimeFilterSql(sqlWhereParamMap, sqlBuilder); + } + JSONObject result = new JSONObject(); + //统计数量 + int count = objectDao.countObjectBySql(InvoicePlan.class.getSimpleName(), sqlBuilder.toString()); + if(count > 0){ + List list = objectDao.findBySql(InvoicePlan.class.getSimpleName(), sqlBuilder.toString(), offset, limit, sort); + result.put(JSONUtil.JSON_KEY_ROWS, JSONArray.fromObject(list,jsonConfig)); + } + result.put(JSONUtil.JSON_KEY_TOTAL, count); + result.put(JSONUtil.JSON_KEY_SUCCESS, true); + SpringUtils.output(result); + } + + /** + * 申请单详情接口 + */ + @RequestMapping(value="/loadRecyclingApplicationById") + public void loadRecyclingApplicationById(){ + JSONObject result = JSONUtil.buildJsonObject(false); + String id = SpringUtils.getPraramValue("id", null); + if(StringUtils.isBlank(id)){ + JSONUtil.addMessage(result, "输入参数id不能为空"); + SpringUtils.output(result); + return; + } + if(!DatabaseUtil.isPoIdValid(id)){ + JSONUtil.addMessage(result, "输入参数id非法,只能是正整数"); + SpringUtils.output(result); + return; + } + RecyclingApplication recyclingApplication = recyclingApplicationManager.get(id); + if(recyclingApplication == null){ + JSONUtil.addMessage(result, "根据输入参数id未找到相应的申请单对象"); + SpringUtils.output(result); + return; + } + JSONUtil.addDataProperty(result, JSONObject.fromObject(recyclingApplication, jsonConfig)); + JSONUtil.addProperty(result, JSONUtil.JSON_KEY_SUCCESS, true); + SpringUtils.output(result); + } + + /** + * 申请单终止接口 + */ + @RequestMapping(value="/terminateMultiInvoicePlans") + public void terminateMultiInvoicePlans(){ + + } +}