Pārlūkot izejas kodu

退宿单代码提交

Heyuan 3 nedēļas atpakaļ
vecāks
revīzija
4248c3c04a

+ 188 - 73
src/com/kingdee/eas/custom/dormitorysystem/application/app/CheckoutApplicationControllerBean.java

@@ -5,13 +5,17 @@ import com.kingdee.bos.Context;
 import com.kingdee.bos.dao.IObjectPK;
 import com.kingdee.bos.dao.IObjectPK;
 import com.kingdee.bos.dao.IObjectValue;
 import com.kingdee.bos.dao.IObjectValue;
 import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
 import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
-import com.kingdee.bos.metadata.entity.SelectorItemCollection;
+import com.kingdee.bos.metadata.entity.*;
+import com.kingdee.bos.metadata.query.util.CompareType;
+import com.kingdee.bos.util.BOSUuid;
 import com.kingdee.eas.basedata.person.IPerson;
 import com.kingdee.eas.basedata.person.IPerson;
 import com.kingdee.eas.basedata.person.PersonFactory;
 import com.kingdee.eas.basedata.person.PersonFactory;
 import com.kingdee.eas.basedata.person.PersonInfo;
 import com.kingdee.eas.basedata.person.PersonInfo;
 import com.kingdee.eas.common.EASBizException;
 import com.kingdee.eas.common.EASBizException;
 import com.kingdee.eas.custom.dormitorysystem.application.*;
 import com.kingdee.eas.custom.dormitorysystem.application.*;
+import com.kingdee.eas.custom.dormitorysystem.dormitory.DormitoryInfo;
 import com.kingdee.eas.custom.dormitorysystem.occupants.IOccupants;
 import com.kingdee.eas.custom.dormitorysystem.occupants.IOccupants;
+import com.kingdee.eas.custom.dormitorysystem.occupants.OccupantsCollection;
 import com.kingdee.eas.custom.dormitorysystem.occupants.OccupantsFactory;
 import com.kingdee.eas.custom.dormitorysystem.occupants.OccupantsFactory;
 import com.kingdee.eas.custom.dormitorysystem.occupants.OccupantsInfo;
 import com.kingdee.eas.custom.dormitorysystem.occupants.OccupantsInfo;
 import com.kingdee.eas.custom.dormitorysystem.otherbasicdata.PersonDormitoryTypeInfo;
 import com.kingdee.eas.custom.dormitorysystem.otherbasicdata.PersonDormitoryTypeInfo;
@@ -32,11 +36,59 @@ import com.kingdee.shr.base.syssetting.MSFServiceFacadeFactory;
 import com.kingdee.util.StringUtils;
 import com.kingdee.util.StringUtils;
 import org.apache.log4j.Logger;
 import org.apache.log4j.Logger;
 
 
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.*;
 
 
 public class CheckoutApplicationControllerBean extends AbstractCheckoutApplicationControllerBean {
 public class CheckoutApplicationControllerBean extends AbstractCheckoutApplicationControllerBean {
     private static Logger logger = Logger.getLogger(CheckoutApplicationControllerBean.class);
     private static Logger logger = Logger.getLogger(CheckoutApplicationControllerBean.class);
 
 
+
+    @Override
+    protected IObjectPK _save(Context ctx, IObjectValue model) throws BOSException, EASBizException {
+        //退宿单
+        CheckoutApplicationInfo info = (CheckoutApplicationInfo) model;
+        //退宿单分录
+        CheckoutApplicationEntryCollection entrys = info.getEntrys();
+        Set<String> occupantsIds = new HashSet<>();
+        ICheckoutApplicationEntry iCheckoutApplicationEntry = CheckoutApplicationEntryFactory.getLocalInstance(ctx);
+        for (int i = 0; i < entrys.size(); i++) {
+            CheckoutApplicationEntryInfo checkoutApplicationEntryInfo = entrys.get(i);
+            BOSUuid id = checkoutApplicationEntryInfo.getId();
+            //入住人员信息
+            OccupantsInfo occupants = checkoutApplicationEntryInfo.getOccupants();
+            if (occupants == null) {
+                throw new BOSException("入住人员信息不能为空!");
+            }
+            String occupantsId = occupants.getId().toString();
+            if (occupantsIds.contains(occupantsId)) {
+                throw new BOSException("本单据中存在对相同入住信息做退宿情况,请检查单据信息!");
+            }
+            occupantsIds.add(occupantsId);
+            //校验是否存在对相同入住信息对退宿的退宿单分录
+            FilterInfo filterInfo = new FilterInfo();
+            FilterItemCollection filterItems = filterInfo.getFilterItems();
+            filterItems.add(new FilterItemInfo("occupants", occupantsId));
+            if (id != null) {
+                filterItems.add(new FilterItemInfo("id", id, CompareType.NOTEQUALS));
+            }
+            SelectorItemCollection sic = new SelectorItemCollection();
+            sic.add("person.name");
+            sic.add("occupants.number");
+            sic.add("parent.number");
+            EntityViewInfo viewInfo = EntityViewInfo.getInstance(filterInfo, sic, null);
+            CheckoutApplicationEntryCollection checkoutApplicationEntryCol = iCheckoutApplicationEntry.getCheckoutApplicationEntryCollection(viewInfo);
+            for (int j = 0; j < checkoutApplicationEntryCol.size(); j++) {
+                CheckoutApplicationEntryInfo checkoutApplicationEntry = checkoutApplicationEntryCol.get(j);
+                String personName = checkoutApplicationEntry.getPerson().getName();
+                String occupantsNumber = checkoutApplicationEntry.getOccupants().getNumber();
+                String number = checkoutApplicationEntry.getParent().getNumber();
+                throw new BOSException(personName + "的入住信息[" + occupantsNumber + "]已经在退宿单[" + number + "],请勿重复提交退宿单!");
+            }
+        }
+        return super._save(ctx, model);
+    }
+
+
     /**
     /**
      * 删除
      * 删除
      *
      *
@@ -86,43 +138,7 @@ public class CheckoutApplicationControllerBean extends AbstractCheckoutApplicati
         if (HRBillStateEnum.AUDITED.equals(billState)) {
         if (HRBillStateEnum.AUDITED.equals(billState)) {
             throw new BaseItemException(BaseItemException.CUSTOM_EXCEPTION, new Object[]{"单据已经审批通过,请勿重复操作!"});
             throw new BaseItemException(BaseItemException.CUSTOM_EXCEPTION, new Object[]{"单据已经审批通过,请勿重复操作!"});
         }
         }
-//        Map<String, String> params = new HashMap<String, String>();
-//        params.put("billIds", billId);
-//        Map result = null;
-//        try {
-//            IMSFServiceFacade imsfServiceFacade = MSFServiceFacadeFactory.getLocalInstance(ctx);
-//            result = (Map) imsfServiceFacade.processService("validateRoomAvailableByBillIdsService", params);
-//        } catch (Exception e) {
-//            logger.error(e);
-//            throw new BaseItemException(BaseItemException.CUSTOM_EXCEPTION, new Object[]{"调用接口validateRoomAvailableByBillIdsService报错: " + e.getMessage()});
-//        }
-//        Integer code = (Integer) result.get("code");
-//        if (500 == code) {
-//            List<String> errorMsgList = (List<String>) result.get("errorMsg");
-//            StringBuilder errorMsgBuilder = new StringBuilder();
-//            for (String errorMsg : errorMsgList) {
-//                errorMsgBuilder.append(errorMsg).append("\n");
-//            }
-//            throw new BaseItemException(BaseItemException.CUSTOM_EXCEPTION, new Object[]{errorMsgBuilder.toString()});
-//        }
-//        //校验入住申请单是否重复提交、校验入住信息时间交叉
-//        Map result2 = null;
-//        try {
-//            IMSFServiceFacade imsfServiceFacade = MSFServiceFacadeFactory.getLocalInstance(ctx);
-//            result2 = (Map) imsfServiceFacade.processService("checkDuplicateCheckInByBillIdService", params);
-//        } catch (Exception e) {
-//            logger.error(e);
-//            throw new BaseItemException(BaseItemException.CUSTOM_EXCEPTION, new Object[]{"调用接口checkDuplicateCheckInByBillIdService报错: " + e.getMessage()});
-//        }
-//        Integer code2 = (Integer) result2.get("code");
-//        if (500 == code2) {
-//            List<String> errorMsgList = (List<String>) result2.get("errorMsg");
-//            StringBuilder errorMsgBuilder = new StringBuilder();
-//            for (String errorMsg : errorMsgList) {
-//                errorMsgBuilder.append(errorMsg).append("\n");
-//            }
-//            throw new BaseItemException(BaseItemException.CUSTOM_EXCEPTION, new Object[]{errorMsgBuilder.toString()});
-//        }
+        IRoomChangeApplicationEntry iRoomChangeApplicationEntry = RoomChangeApplicationEntryFactory.getLocalInstance(ctx);
         IOccupants iOccupants = OccupantsFactory.getLocalInstance(ctx);
         IOccupants iOccupants = OccupantsFactory.getLocalInstance(ctx);
         CoreBaseCollection updateCols = new CoreBaseCollection();
         CoreBaseCollection updateCols = new CoreBaseCollection();
         CheckoutApplicationEntryCollection entrys = info.getEntrys();
         CheckoutApplicationEntryCollection entrys = info.getEntrys();
@@ -130,28 +146,24 @@ public class CheckoutApplicationControllerBean extends AbstractCheckoutApplicati
             CheckoutApplicationEntryInfo entryInfo = entrys.get(i);
             CheckoutApplicationEntryInfo entryInfo = entrys.get(i);
             Date checkoutDate = entryInfo.getCheckoutDate();
             Date checkoutDate = entryInfo.getCheckoutDate();
             OccupantsInfo occupants = entryInfo.getOccupants();
             OccupantsInfo occupants = entryInfo.getOccupants();
+            if (occupants == null) {
+                throw new BaseItemException(BaseItemException.CUSTOM_EXCEPTION, new Object[]{"入住信息为空!"});
+            }
+            String personName = entryInfo.getPerson().getName();
+            //校验入住信息是否被换宿
+            RoomChangeApplicationEntryCollection roomChangeApplicationEntryCollection =
+                    iRoomChangeApplicationEntry.getRoomChangeApplicationEntryCollection("select parent.number where oldOccupants = '" + occupants.getId() + "'");
+            if (roomChangeApplicationEntryCollection.size() > 0) {
+                RoomChangeApplicationEntryInfo roomChangeApplicationEntryInfo = roomChangeApplicationEntryCollection.get(0);
+                String number = roomChangeApplicationEntryInfo.getParent().getNumber();
+                throw new BaseItemException(BaseItemException.CUSTOM_EXCEPTION, new Object[]{"员工 " + personName + "已有换宿单[ " + number + " ],不能提交生效!\n"});
+            }
             occupants.setCheckOutDate(checkoutDate);
             occupants.setCheckOutDate(checkoutDate);
-//            PersonInfo personInfo = entryInfo.getPerson();
-//            String personId = personInfo.getId().toString();
-//            //校验员工用工关系状态
-//            IPerson iPerson = PersonFactory.getLocalInstance(ctx);
-//            //SelectorItemCollection sic = new SelectorItemCollection();
-//            //sic.add("");
-//            personInfo = iPerson.getPersonInfo(new ObjectUuidPK(personId));
-//            boolean isInCount = personInfo.getEmployeeType().isIsInCount();
-//            if (!isInCount) {
-//                //员工用工关系状态
-//                //
-//            }
-            //生成入住人员信息
-            //校验时间是否存在交叉
             updateCols.add(occupants);
             updateCols.add(occupants);
         }
         }
         //批量更新入住信息
         //批量更新入住信息
         iOccupants.updateBatchData(updateCols);
         iOccupants.updateBatchData(updateCols);
-        //更新
-        //update(ctx, new ObjectUuidPK(billId), info);
-        //提交
+        //提交生效
         IObjectPK iObjectPK = super._submitEffect(ctx, info);
         IObjectPK iObjectPK = super._submitEffect(ctx, info);
         return iObjectPK;
         return iObjectPK;
     }
     }
@@ -192,47 +204,150 @@ public class CheckoutApplicationControllerBean extends AbstractCheckoutApplicati
         sic.add("entrys.*");
         sic.add("entrys.*");
         sic.add("entrys.person.*");
         sic.add("entrys.person.*");
         sic.add("entrys.occupants.*");
         sic.add("entrys.occupants.*");
+        sic.add("entrys.currentRoom.*");
         CheckoutApplicationInfo info = getCheckoutApplicationInfo(ctx, new ObjectUuidPK(billId), sic);
         CheckoutApplicationInfo info = getCheckoutApplicationInfo(ctx, new ObjectUuidPK(billId), sic);
         HRBillStateEnum billState = info.getBillState();
         HRBillStateEnum billState = info.getBillState();
         if (!HRBillStateEnum.AUDITED.equals(billState)) {
         if (!HRBillStateEnum.AUDITED.equals(billState)) {
             throw new AffairBizException(HRBaseException.BILLSTATECANUNCHECK);
             throw new AffairBizException(HRBaseException.BILLSTATECANUNCHECK);
         }
         }
         IOccupants iOccupants = OccupantsFactory.getLocalInstance(ctx);
         IOccupants iOccupants = OccupantsFactory.getLocalInstance(ctx);
-        IRoomChangeApplicationEntry iRoomChangeApplicationEntry = RoomChangeApplicationEntryFactory.getLocalInstance(ctx);
-        ICheckoutApplicationEntry iCheckoutApplicationEntry = CheckoutApplicationEntryFactory.getLocalInstance(ctx);
+//        IRoomChangeApplicationEntry iRoomChangeApplicationEntry = RoomChangeApplicationEntryFactory.getLocalInstance(ctx);
+//        ICheckoutApplicationEntry iCheckoutApplicationEntry = CheckoutApplicationEntryFactory.getLocalInstance(ctx);
         CheckoutApplicationEntryCollection entrys = info.getEntrys();
         CheckoutApplicationEntryCollection entrys = info.getEntrys();
-        StringBuilder errorMsg = new StringBuilder();
+        //StringBuilder errorMsg = new StringBuilder();
         CoreBaseCollection updateCols = new CoreBaseCollection();
         CoreBaseCollection updateCols = new CoreBaseCollection();
         for (int i = 0; i < entrys.size(); i++) {
         for (int i = 0; i < entrys.size(); i++) {
+            //退宿单分录
             CheckoutApplicationEntryInfo entryInfo = entrys.get(i);
             CheckoutApplicationEntryInfo entryInfo = entrys.get(i);
-            //PersonInfo person = entryInfo.getPerson();
+            PersonInfo person = entryInfo.getPerson();
+            String personId = person.getId().toString();
+            //入住日期
+            Date checkInDate = entryInfo.getCheckInDate();
+            if (checkInDate == null) {
+                throw new BaseItemException(BaseItemException.CUSTOM_EXCEPTION, new Object[]{"入住日期为空!"});
+            }
+            //原退宿日期
+            Date oldCheckoutDate = entryInfo.getOldCheckoutDate();
+            if (oldCheckoutDate == null) {
+                throw new BaseItemException(BaseItemException.CUSTOM_EXCEPTION, new Object[]{"原退宿日期为空!"});
+            }
             OccupantsInfo occupants = entryInfo.getOccupants();
             OccupantsInfo occupants = entryInfo.getOccupants();
+            if (occupants == null) {
+                throw new BaseItemException(BaseItemException.CUSTOM_EXCEPTION, new Object[]{"入住信息为空!"});
+            }
             String occupantsId = occupants.getId().toString();
             String occupantsId = occupants.getId().toString();
-            //检查是否有退宿流程
-//            RoomChangeApplicationEntryCollection roomChangeApplicationEntryCollection = iRoomChangeApplicationEntry.getRoomChangeApplicationEntryCollection("select parent.number where oldOccupants = '" + occupantsId + "'");
+            //现住房间
+            DormitoryInfo currentRoom = entryInfo.getCurrentRoom();
+            if (currentRoom == null) {
+                throw new BaseItemException(BaseItemException.CUSTOM_EXCEPTION, new Object[]{"现住房间为空!"});
+            }
+            String roomName = currentRoom.getName();
+            String displayName = currentRoom.getDisplayName();
+            String roomId = currentRoom.getId().toString();
+            //1.校验房间在原入住期间内有没有被其他人入住
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            Map<String, List> paramAll = new HashMap<String, List>();
+            Map<String, String> params = new HashMap<String, String>();
+            List list = new ArrayList();
+            list.add(params);
+            params.put("checkInDate", sdf.format(checkInDate));
+            params.put("checkoutDate", sdf.format(oldCheckoutDate));
+            params.put("personId", personId);
+            params.put("roomId", roomId);
+            paramAll.put("validateData", list);
+            Map result = null;
+            try {
+                IMSFServiceFacade imsfServiceFacade = MSFServiceFacadeFactory.getLocalInstance(ctx);
+                result = (Map) imsfServiceFacade.processService("validateRoomAvailableService", paramAll);
+            } catch (Exception e) {
+                logger.error(e);
+                throw new BaseItemException(BaseItemException.CUSTOM_EXCEPTION, new Object[]{"调用接口validateRoomAvailableService报错: " + e.getMessage()});
+            }
+            Integer code = (Integer) result.get("code");
+            if (500 == code) {
+                throw new BaseItemException(BaseItemException.CUSTOM_EXCEPTION, new Object[]{(String) result.get("errorMsg").toString()});
+            }
+//            verifyOccupants(ctx, roomId, occupantsId, displayName, checkInDate, oldCheckoutDate);
+//            //2.校验房间在原入住期间内有没有审批中的入住单、换宿单中
+//            //检查是否有换宿流程
+//            FilterInfo rcFilterInfo = new FilterInfo();
+//            FilterItemCollection rcFilterItems = rcFilterInfo.getFilterItems();
+//            //单据状态等于已提交、审批中或审批通过
+//            rcFilterItems.add(new FilterItemInfo("parent.billState", "1,2,3", CompareType.INCLUDE));
+//            //申请入住日期在入住日期和退宿日期之间
+//            rcFilterItems.add(new FilterItemInfo("checkInDate", checkInDate, CompareType.LESS_EQUALS));
+//            rcFilterItems.add(new FilterItemInfo("checkoutDate", checkInDate, CompareType.GREATER_EQUALS));
+//            //入住日期在申请入住日期和申请退宿日期之间
+//            rcFilterItems.add(new FilterItemInfo("checkInDate", checkInDate, CompareType.GREATER_EQUALS));
+//            rcFilterItems.add(new FilterItemInfo("checkInDate", oldCheckoutDate, CompareType.LESS_EQUALS));
+//            //调整房间
+//            rcFilterItems.add(new FilterItemInfo("adjustRoom", currentRoom.getId()));
+//            rcFilterInfo.setMaskString("#0 and ((#1 and #2) or (#3 and #4)) and #5 and #6");
+//            rcFilterInfo.setMaskString("#0 and ((#1 and #2) or (#3 and #4)) and #5");
+//            SelectorItemCollection rcSic = new SelectorItemCollection();
+//            rcSic.add("person.name");
+//            EntityViewInfo rcViewInfo = EntityViewInfo.getInstance(rcFilterInfo, rcSic, null);
+//            RoomChangeApplicationEntryCollection roomChangeApplicationEntryCollection =
+//                    iRoomChangeApplicationEntry.getRoomChangeApplicationEntryCollection(rcViewInfo);
 //            if (roomChangeApplicationEntryCollection.size() > 0) {
 //            if (roomChangeApplicationEntryCollection.size() > 0) {
 //                RoomChangeApplicationEntryInfo roomChangeApplicationEntryInfo = roomChangeApplicationEntryCollection.get(0);
 //                RoomChangeApplicationEntryInfo roomChangeApplicationEntryInfo = roomChangeApplicationEntryCollection.get(0);
 //                String number = roomChangeApplicationEntryInfo.getParent().getNumber();
 //                String number = roomChangeApplicationEntryInfo.getParent().getNumber();
-//                errorMsg.append("员工 " + person.getName() + "已有换宿单[ " + number + " ],不能反审核!\n");
-//            }
-            //检查是否有换宿流程
-//            CheckoutApplicationEntryCollection checkoutApplicationEntryCollection = iCheckoutApplicationEntry.getCheckoutApplicationEntryCollection("select parent.number where occupants = '" + occupantsId + "'");
-//            if (checkoutApplicationEntryCollection.size() > 0) {
-//                CheckoutApplicationEntryInfo checkoutApplicationEntryInfo = checkoutApplicationEntryCollection.get(0);
-//                String number = checkoutApplicationEntryInfo.getParent().getNumber();
-//                errorMsg.append("员工 " + person.getName() + "已有退宿单[ " + number + " ],不能反审核!\n");
+//                //errorMsg.append("员工 " + person.getName() + "已有换宿单[ " + number + " ],不能反审核!\n");
 //            }
 //            }
             //没有水电明细的可以反审批
             //没有水电明细的可以反审批
-            occupants.setCheckOutDate(entryInfo.getOldCheckoutDate());
+            occupants.setCheckOutDate(oldCheckoutDate);
             updateCols.add(occupants);
             updateCols.add(occupants);
         }
         }
-        if (errorMsg.length() > 0) {
-            throw new BaseItemException(BaseItemException.CUSTOM_EXCEPTION, new Object[]{errorMsg.toString()});
-        }
         super._untiCheckBizBill(ctx, billId);
         super._untiCheckBizBill(ctx, billId);
         if (updateCols.size() > 0) {
         if (updateCols.size() > 0) {
             //批量更新入住信息
             //批量更新入住信息
             iOccupants.updateBatchData(updateCols);
             iOccupants.updateBatchData(updateCols);
         }
         }
     }
     }
+
+    /**
+     * 校验房间在原入住期间内有没有被其他人入住
+     *
+     * @param ctx
+     * @param roomId
+     * @param occupantsId
+     * @param displayName
+     * @param checkInDate
+     * @param oldCheckoutDate
+     * @throws BOSException
+     * @throws BaseItemException
+     */
+    private void verifyOccupants(
+            Context ctx,
+            String roomId,
+            String occupantsId,
+            String displayName,
+            Date checkInDate,
+            Date oldCheckoutDate
+    ) throws BOSException, BaseItemException {
+        IOccupants iOccupants = OccupantsFactory.getLocalInstance(ctx);
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        FilterInfo filterInfo = new FilterInfo();
+        FilterItemCollection filterItems = filterInfo.getFilterItems();
+        filterItems.add(new FilterItemInfo("Dormitory", roomId));
+        //申请入住日期在入住日期和退宿日期之间
+        filterItems.add(new FilterItemInfo("CheckInDate", checkInDate, CompareType.LESS_EQUALS));
+        filterItems.add(new FilterItemInfo("CheckOutDate", checkInDate, CompareType.GREATER_EQUALS));
+        //入住日期在申请入住日期和申请退宿日期之间
+        filterItems.add(new FilterItemInfo("CheckInDate", checkInDate, CompareType.GREATER_EQUALS));
+        filterItems.add(new FilterItemInfo("CheckInDate", oldCheckoutDate, CompareType.LESS_EQUALS));
+        filterItems.add(new FilterItemInfo("id", occupantsId, CompareType.NOTEQUALS));
+        filterInfo.setMaskString("#0 and ((#1 and #2) or (#3 and #4)) and #5");
+        SelectorItemCollection occupantsSic = new SelectorItemCollection();
+        occupantsSic.add("person.name");
+        EntityViewInfo viewInfo = EntityViewInfo.getInstance(filterInfo, occupantsSic, null);
+        OccupantsCollection occupantsCollection = iOccupants.getOccupantsCollection(viewInfo);
+        for (int j = 0; j < occupantsCollection.size(); j++) {
+            OccupantsInfo occupantsInfo = occupantsCollection.get(j);
+            String personName = occupantsInfo.getPerson().getName();
+            throw new BaseItemException(BaseItemException.CUSTOM_EXCEPTION, new Object[]{
+                    "入住信息中员工[" + personName + "]在" + sdf.format(checkInDate) + " ~ " + sdf.format(oldCheckoutDate) + "期间已入住房间[" + displayName + "],无法反审批该退宿单"});
+
+        }
+    }
 }
 }

+ 86 - 0
websrc/com/kingdee/eas/custom/dormitorysystem/application/handler/CheckInApplicationEditHandler.java

@@ -1,7 +1,26 @@
 package com.kingdee.eas.custom.dormitorysystem.application.handler;
 package com.kingdee.eas.custom.dormitorysystem.application.handler;
 
 
+import com.kingdee.bos.Context;
+import com.kingdee.bos.util.BOSUuid;
+import com.kingdee.eas.basedata.org.HROrgUnitInfo;
+import com.kingdee.eas.custom.dormitorysystem.application.CheckInApplicationEntryInfo;
+import com.kingdee.eas.custom.dormitorysystem.application.CheckInApplicationInfo;
+import com.kingdee.eas.framework.CoreBaseInfo;
+import com.kingdee.eas.hr.base.HRBillBaseInfo;
+import com.kingdee.shr.base.syssetting.IMSFServiceFacade;
+import com.kingdee.shr.base.syssetting.MSFServiceFacadeFactory;
+import com.kingdee.shr.base.syssetting.context.SHRContext;
+import com.kingdee.shr.base.syssetting.exception.SHRWebException;
+import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
+import com.kingdee.util.DateTimeUtils;
 import org.apache.log4j.Logger;
 import org.apache.log4j.Logger;
 
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 /**
 /**
  * @Description 入住申请单表单Handler
  * @Description 入住申请单表单Handler
  * @Date 2025/4/24 13:48
  * @Date 2025/4/24 13:48
@@ -9,6 +28,73 @@ import org.apache.log4j.Logger;
  */
  */
 public class CheckInApplicationEditHandler extends DormitoryApplicationEditHandler {
 public class CheckInApplicationEditHandler extends DormitoryApplicationEditHandler {
     private static Logger logger = Logger.getLogger(CheckInApplicationSelfEditHandler.class);
     private static Logger logger = Logger.getLogger(CheckInApplicationSelfEditHandler.class);
+    private Context ctx = SHRContext.getInstance().getContext();
+
+
+    @Override
+    protected void beforeSubmit(
+            HttpServletRequest request,
+            HttpServletResponse response,
+            CoreBaseInfo model
+    ) throws SHRWebException {
+        HRBillBaseInfo hrBillBaseInfo = (HRBillBaseInfo) model;
+        String billIds = hrBillBaseInfo.getId().toString();
+        Map result = null;
+        Map<String, String> params = new HashMap<String, String>();
+        params.put("billIds", billIds);
+        try {
+            //校验房间是否可入住
+            IMSFServiceFacade imsfServiceFacade = MSFServiceFacadeFactory.getLocalInstance(ctx);
+            result = (Map) imsfServiceFacade.processService("validateRoomAvailableByBillIdsService", params);
+        } catch (Exception e) {
+            logger.error(e);
+            throw new ShrWebBizException("调用接口validateRoomAvailableByBillIdsService报错: " + e.getMessage());
+        }
+        Integer code = (Integer) result.get("code");
+        if (500 == code) {
+            List<String> errorMsgList = (List<String>) result.get("errorMsg");
+            StringBuilder errorMsgBuilder = new StringBuilder();
+            for (String errorMsg : errorMsgList) {
+                errorMsgBuilder.append(errorMsg).append("\n");
+            }
+            throw new ShrWebBizException(errorMsgBuilder.toString());
+        }
+        //设置单据状态为未审批
+        model.setInt("billState", 1);
+        super.beforeSubmit(request, response, model);
+    }
 
 
 
 
+    /**
+     * 创建对象后置方法
+     *
+     * @param request
+     * @param response
+     * @param coreBaseInfo
+     * @throws SHRWebException
+     */
+    protected void afterCreateNewModel(
+            HttpServletRequest request,
+            HttpServletResponse response,
+            CoreBaseInfo coreBaseInfo
+    ) throws SHRWebException {
+        try {
+            Context ctx = SHRContext.getInstance().getContext();
+            CheckInApplicationInfo checkInApplicationInfo = (CheckInApplicationInfo) coreBaseInfo;
+            HROrgUnitInfo hrOrgUnitInfo = new HROrgUnitInfo();
+            hrOrgUnitInfo.setId(BOSUuid.read("00000000-0000-0000-0000-000000000000CCE7AED4"));
+            checkInApplicationInfo.setHrOrgUnit(hrOrgUnitInfo);
+            checkInApplicationInfo.setManagementNotes("本人愿意遵守以下条款:" +
+                    "\n1、自觉遵守公司《宿舍管理制度》和员工宿舍区有关管理办法,不私自调换宿舍和床位。" +
+                    "\n2、自觉维护宿舍公共区域的卫生,爱护公物,损坏公物自觉赔偿。 3、自觉遵守消防安全,节约用电用水。" +
+                    "\n3、自觉遵守消防安全,节约用电用水。");
+            //分录
+            CheckInApplicationEntryInfo entryInfo = new CheckInApplicationEntryInfo();
+            entryInfo.setCheckoutDate(DateTimeUtils.parseDate("2199-12-31", "yyyy-MM-dd"));
+            checkInApplicationInfo.getEntrys().add(entryInfo);
+        } catch (Exception e) {
+            logger.error(e);
+            throw new ShrWebBizException(e);
+        }
+    }
 }
 }

+ 42 - 14
websrc/com/kingdee/eas/custom/dormitorysystem/application/handler/CheckInApplicationListHandler.java

@@ -1,11 +1,23 @@
 package com.kingdee.eas.custom.dormitorysystem.application.handler;
 package com.kingdee.eas.custom.dormitorysystem.application.handler;
 
 
 import com.kingdee.bos.BOSException;
 import com.kingdee.bos.BOSException;
+import com.kingdee.bos.Context;
+import com.kingdee.eas.framework.CoreBaseInfo;
+import com.kingdee.eas.hr.base.HRBillBaseInfo;
+import com.kingdee.shr.base.syssetting.BaseItemException;
+import com.kingdee.shr.base.syssetting.IMSFServiceFacade;
+import com.kingdee.shr.base.syssetting.MSFServiceFacadeFactory;
+import com.kingdee.shr.base.syssetting.context.SHRContext;
 import com.kingdee.shr.base.syssetting.exception.SHRWebException;
 import com.kingdee.shr.base.syssetting.exception.SHRWebException;
+import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
+import org.apache.log4j.Logger;
 import org.springframework.ui.ModelMap;
 import org.springframework.ui.ModelMap;
 
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 
 /**
 /**
  * @Description 入住申请单列表Handler
  * @Description 入住申请单列表Handler
@@ -13,21 +25,37 @@ import javax.servlet.http.HttpServletResponse;
  * @Created by Heyuan
  * @Created by Heyuan
  */
  */
 public class CheckInApplicationListHandler extends DormitoryApplicationListHandler {
 public class CheckInApplicationListHandler extends DormitoryApplicationListHandler {
-    /**
-     * 提交生效
-     *
-     * @param request
-     * @param response
-     * @param modelMap
-     * @throws SHRWebException
-     * @throws BOSException
-     */
-    public void submitEffectAction(
+    private static Logger logger = Logger.getLogger(CheckInApplicationListHandler.class);
+    private Context ctx = SHRContext.getInstance().getContext();
+
+    @Override
+    protected void beforeSubmit(
             HttpServletRequest request,
             HttpServletRequest request,
             HttpServletResponse response,
             HttpServletResponse response,
-            ModelMap modelMap
-    ) throws SHRWebException, BOSException {
-        this.handleEnableWithTips(request, "submitEffect");
-        //JSONUtils.writeJson(response, res);
+            CoreBaseInfo model
+    ) throws SHRWebException {
+        super.beforeSubmit(request, response, model);
+        HRBillBaseInfo hrBillBaseInfo = (HRBillBaseInfo) model;
+        String billIds = hrBillBaseInfo.getId().toString();
+        Map result = null;
+        Map<String, String> params = new HashMap<String, String>();
+        params.put("billIds", billIds);
+        //校验入住申请单是否重复提交、校验入住信息时间交叉
+        try {
+            IMSFServiceFacade imsfServiceFacade = MSFServiceFacadeFactory.getLocalInstance(ctx);
+            result = (Map) imsfServiceFacade.processService("checkDuplicateCheckInByBillIdService", params);
+        } catch (Exception e) {
+            logger.error(e);
+            throw new ShrWebBizException("调用接口checkDuplicateCheckInByBillIdService报错: " + e.getMessage());
+        }
+        Integer code = (Integer) result.get("code");
+        if (500 == code) {
+            List<String> errorMsgList = (List<String>) result.get("errorMsg");
+            StringBuilder errorMsgBuilder = new StringBuilder();
+            for (String errorMsg : errorMsgList) {
+                errorMsgBuilder.append(errorMsg).append("\n");
+            }
+            throw new ShrWebBizException(errorMsgBuilder.toString());
+        }
     }
     }
 }
 }

+ 4 - 1
websrc/com/kingdee/eas/custom/dormitorysystem/application/handler/CheckInApplicationSelfEditHandler.java

@@ -27,6 +27,9 @@ import javax.servlet.http.HttpServletResponse;
 public class CheckInApplicationSelfEditHandler extends DormitoryApplicationEditHandler {
 public class CheckInApplicationSelfEditHandler extends DormitoryApplicationEditHandler {
     private static Logger logger = Logger.getLogger(CheckInApplicationSelfEditHandler.class);
     private static Logger logger = Logger.getLogger(CheckInApplicationSelfEditHandler.class);
 
 
+
+
+
     /**
     /**
      * ´´½¨¶ÔÏóºóÖ÷½·¨
      * ´´½¨¶ÔÏóºóÖ÷½·¨
      *
      *
@@ -57,7 +60,7 @@ public class CheckInApplicationSelfEditHandler extends DormitoryApplicationEditH
             PersonPositionInfo pp = PersonPositionFactory.getLocalInstance(ctx).getPersonPositionInfo("select personDep.*,primaryPosition.* where person = '" + person.getId() + "'");
             PersonPositionInfo pp = PersonPositionFactory.getLocalInstance(ctx).getPersonPositionInfo("select personDep.*,primaryPosition.* where person = '" + person.getId() + "'");
             entryInfo.setAdminOrg(pp.getPersonDep());
             entryInfo.setAdminOrg(pp.getPersonDep());
             entryInfo.setPosition(pp.getPrimaryPosition());
             entryInfo.setPosition(pp.getPrimaryPosition());
-            //entryInfo.setCheckoutDate(DateTimeUtils.parseDate("2199-12-31", "yyyy-MM-dd"));
+            entryInfo.setCheckoutDate(DateTimeUtils.parseDate("2199-12-31", "yyyy-MM-dd"));
             checkInApplicationInfo.getEntrys().add(entryInfo);
             checkInApplicationInfo.getEntrys().add(entryInfo);
         } catch (Exception e) {
         } catch (Exception e) {
             logger.error(e);
             logger.error(e);

+ 83 - 8
websrc/com/kingdee/eas/custom/dormitorysystem/application/handler/CheckoutApplicationEditHandler.java

@@ -1,20 +1,32 @@
 package com.kingdee.eas.custom.dormitorysystem.application.handler;
 package com.kingdee.eas.custom.dormitorysystem.application.handler;
 
 
+import com.kingdee.bos.BOSException;
 import com.kingdee.bos.Context;
 import com.kingdee.bos.Context;
+import com.kingdee.bos.metadata.entity.*;
+import com.kingdee.bos.metadata.query.util.CompareType;
 import com.kingdee.bos.util.BOSUuid;
 import com.kingdee.bos.util.BOSUuid;
 import com.kingdee.eas.basedata.org.HROrgUnitInfo;
 import com.kingdee.eas.basedata.org.HROrgUnitInfo;
-import com.kingdee.eas.custom.dormitorysystem.application.CheckInApplicationEntryInfo;
-import com.kingdee.eas.custom.dormitorysystem.application.CheckoutApplicationEntryInfo;
-import com.kingdee.eas.custom.dormitorysystem.application.CheckoutApplicationInfo;
+import com.kingdee.eas.custom.dormitorysystem.application.*;
+import com.kingdee.eas.custom.dormitorysystem.occupants.IOccupants;
+import com.kingdee.eas.custom.dormitorysystem.occupants.OccupantsCollection;
+import com.kingdee.eas.custom.dormitorysystem.occupants.OccupantsFactory;
+import com.kingdee.eas.custom.dormitorysystem.occupants.OccupantsInfo;
 import com.kingdee.eas.framework.CoreBaseInfo;
 import com.kingdee.eas.framework.CoreBaseInfo;
+import com.kingdee.eas.hr.ats.AtsUtil;
+import com.kingdee.eas.hr.base.HRBillBaseInfo;
+import com.kingdee.shr.base.syssetting.BaseItemException;
 import com.kingdee.shr.base.syssetting.context.SHRContext;
 import com.kingdee.shr.base.syssetting.context.SHRContext;
 import com.kingdee.shr.base.syssetting.exception.SHRWebException;
 import com.kingdee.shr.base.syssetting.exception.SHRWebException;
 import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
 import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
-import com.kingdee.util.DateTimeUtils;
+import com.kingdee.shr.base.syssetting.web.json.JSONUtils;
 import org.apache.log4j.Logger;
 import org.apache.log4j.Logger;
+import org.springframework.ui.ModelMap;
 
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
 
 
 /**
 /**
  * @Description 退宿申请单表单Handler
  * @Description 退宿申请单表单Handler
@@ -23,6 +35,7 @@ import javax.servlet.http.HttpServletResponse;
  */
  */
 public class CheckoutApplicationEditHandler extends DormitoryApplicationEditHandler {
 public class CheckoutApplicationEditHandler extends DormitoryApplicationEditHandler {
     private static Logger logger = Logger.getLogger(CheckoutApplicationEditHandler.class);
     private static Logger logger = Logger.getLogger(CheckoutApplicationEditHandler.class);
+    private Context ctx = SHRContext.getInstance().getContext();
 
 
     /**
     /**
      * 创建对象后置方法
      * 创建对象后置方法
@@ -47,13 +60,75 @@ public class CheckoutApplicationEditHandler extends DormitoryApplicationEditHand
 //                    "\n1、自觉遵守公司《宿舍管理制度》和员工宿舍区有关管理办法,不私自调换宿舍和床位。" +
 //                    "\n1、自觉遵守公司《宿舍管理制度》和员工宿舍区有关管理办法,不私自调换宿舍和床位。" +
 //                    "\n2、自觉维护宿舍公共区域的卫生,爱护公物,损坏公物自觉赔偿。 3、自觉遵守消防安全,节约用电用水。" +
 //                    "\n2、自觉维护宿舍公共区域的卫生,爱护公物,损坏公物自觉赔偿。 3、自觉遵守消防安全,节约用电用水。" +
 //                    "\n3、自觉遵守消防安全,节约用电用水。");
 //                    "\n3、自觉遵守消防安全,节约用电用水。");
-            //分录
-            CheckoutApplicationEntryInfo entryInfo = new CheckoutApplicationEntryInfo();
-            entryInfo.setCheckoutDate(DateTimeUtils.parseDate("2199-12-31", "yyyy-MM-dd"));
-            checkoutApplicationInfo.getEntrys().add(entryInfo);
         } catch (Exception e) {
         } catch (Exception e) {
             logger.error(e);
             logger.error(e);
             throw new ShrWebBizException(e);
             throw new ShrWebBizException(e);
         }
         }
     }
     }
+
+    /**
+     * 获取可选入住人员信息
+     *
+     * @param request
+     * @param response
+     * @param modelMap
+     * @throws SHRWebException
+     */
+    public void getOptionalOccupantsAction(
+            HttpServletRequest request,
+            HttpServletResponse response,
+            ModelMap modelMap
+    ) throws SHRWebException {
+        try {
+            Context ctx = SHRContext.getInstance().getContext();
+            IOccupants iOccupants = OccupantsFactory.getLocalInstance(ctx);
+            FilterInfo filterInfo = new FilterInfo();
+            FilterItemCollection filterItems = filterInfo.getFilterItems();
+            Date date = new Date();
+            filterItems.add(new FilterItemInfo("CheckInDate", date, CompareType.LESS_EQUALS));
+            filterItems.add(new FilterItemInfo("CheckOutDate", date, CompareType.GREATER));
+            EntityViewInfo viewInfo = EntityViewInfo.getInstance(filterInfo, null, null);
+            OccupantsCollection occupantsCollection = iOccupants.getOccupantsCollection(viewInfo);
+            Set<String> occupantsIds = new HashSet<String>();
+            for (int i = 0; i < occupantsCollection.size(); i++) {
+                OccupantsInfo occupantsInfo = occupantsCollection.get(i);
+                String occupantsId = occupantsInfo.getId().toString();
+                occupantsIds.add(occupantsId);
+            }
+            JSONUtils.SUCCESS(AtsUtil.convertSetToString(occupantsIds));
+        } catch (BOSException e) {
+            logger.error(e);
+            throw new ShrWebBizException(e);
+        }
+    }
+
+    @Override
+    protected void beforeSubmit(
+            HttpServletRequest request,
+            HttpServletResponse response,
+            CoreBaseInfo model
+    ) throws SHRWebException {
+        super.beforeSubmit(request, response, model);
+        try {
+            IRoomChangeApplicationEntry  iRoomChangeApplicationEntry = RoomChangeApplicationEntryFactory.getLocalInstance(ctx);
+            CheckoutApplicationInfo checkoutApplicationInfo = (CheckoutApplicationInfo) model;
+            CheckoutApplicationEntryCollection entrys = checkoutApplicationInfo.getEntrys();
+            for (int i = 0; i < entrys.size(); i++) {
+                CheckoutApplicationEntryInfo checkoutApplicationEntryInfo = entrys.get(i);
+                OccupantsInfo occupants = checkoutApplicationEntryInfo.getOccupants();
+                String personName = checkoutApplicationEntryInfo.getPerson().getName();
+                //校验入住信息是否被换宿
+                RoomChangeApplicationEntryCollection roomChangeApplicationEntryCollection =
+                        iRoomChangeApplicationEntry.getRoomChangeApplicationEntryCollection("select parent.number where oldOccupants = '" + occupants.getId() + "'");
+                if (roomChangeApplicationEntryCollection.size() > 0) {
+                    RoomChangeApplicationEntryInfo roomChangeApplicationEntryInfo = roomChangeApplicationEntryCollection.get(0);
+                    String number = roomChangeApplicationEntryInfo.getParent().getNumber();
+                    throw new ShrWebBizException("员工 " + personName + "已有换宿单[ " + number + " ],不能提交生效!");
+                }
+            }
+        } catch (BOSException e) {
+            logger.error(e);
+            throw new ShrWebBizException(e);
+        }
+    }
 }
 }

+ 32 - 22
websrc/com/kingdee/eas/custom/dormitorysystem/application/handler/CheckoutApplicationListHandler.java

@@ -1,10 +1,14 @@
 package com.kingdee.eas.custom.dormitorysystem.application.handler;
 package com.kingdee.eas.custom.dormitorysystem.application.handler;
 
 
+import com.kingdee.bos.BOSException;
 import com.kingdee.bos.Context;
 import com.kingdee.bos.Context;
+import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
+import com.kingdee.bos.metadata.entity.SelectorItemCollection;
+import com.kingdee.eas.common.EASBizException;
+import com.kingdee.eas.custom.dormitorysystem.application.*;
+import com.kingdee.eas.custom.dormitorysystem.occupants.OccupantsInfo;
 import com.kingdee.eas.framework.CoreBaseInfo;
 import com.kingdee.eas.framework.CoreBaseInfo;
 import com.kingdee.eas.hr.base.HRBillBaseInfo;
 import com.kingdee.eas.hr.base.HRBillBaseInfo;
-import com.kingdee.shr.base.syssetting.IMSFServiceFacade;
-import com.kingdee.shr.base.syssetting.MSFServiceFacadeFactory;
 import com.kingdee.shr.base.syssetting.context.SHRContext;
 import com.kingdee.shr.base.syssetting.context.SHRContext;
 import com.kingdee.shr.base.syssetting.exception.SHRWebException;
 import com.kingdee.shr.base.syssetting.exception.SHRWebException;
 import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
 import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
@@ -13,7 +17,6 @@ import org.apache.log4j.Logger;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
 import java.util.HashMap;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.Map;
 
 
 /**
 /**
@@ -32,27 +35,34 @@ public class CheckoutApplicationListHandler extends DormitoryApplicationListHand
             CoreBaseInfo model
             CoreBaseInfo model
     ) throws SHRWebException {
     ) throws SHRWebException {
         super.beforeSubmit(request, response, model);
         super.beforeSubmit(request, response, model);
-        HRBillBaseInfo hrBillBaseInfo = (HRBillBaseInfo) model;
-        String billIds = hrBillBaseInfo.getId().toString();
-        Map result = null;
-        Map<String, String> params = new HashMap<String, String>();
-        params.put("billIds", billIds);
-        //校验入住申请单是否重复提交、校验入住信息时间交叉
         try {
         try {
-            IMSFServiceFacade imsfServiceFacade = MSFServiceFacadeFactory.getLocalInstance(ctx);
-            result = (Map) imsfServiceFacade.processService("checkDuplicateCheckInByBillIdService", params);
-        } catch (Exception e) {
-            logger.error(e);
-            throw new ShrWebBizException("调用接口checkDuplicateCheckInByBillIdService报错: " + e.getMessage());
-        }
-        Integer code = (Integer) result.get("code");
-        if (500 == code) {
-            List<String> errorMsgList = (List<String>) result.get("errorMsg");
-            StringBuilder errorMsgBuilder = new StringBuilder();
-            for (String errorMsg : errorMsgList) {
-                errorMsgBuilder.append(errorMsg).append("\n");
+            IRoomChangeApplicationEntry iRoomChangeApplicationEntry = RoomChangeApplicationEntryFactory.getLocalInstance(ctx);
+            CheckoutApplicationInfo checkoutApplicationInfo = (CheckoutApplicationInfo) model;
+            ICheckoutApplication iCheckoutApplication = CheckoutApplicationFactory.getLocalInstance(ctx);
+            SelectorItemCollection sic = new SelectorItemCollection();
+            sic.add("entrys.person.name");
+            sic.add("entrys.occupants.id");
+            checkoutApplicationInfo = iCheckoutApplication.getCheckoutApplicationInfo(new ObjectUuidPK(checkoutApplicationInfo.getId()), sic);
+            CheckoutApplicationEntryCollection entrys = checkoutApplicationInfo.getEntrys();
+            for (int i = 0; i < entrys.size(); i++) {
+                CheckoutApplicationEntryInfo checkoutApplicationEntryInfo = entrys.get(i);
+                OccupantsInfo occupants = checkoutApplicationEntryInfo.getOccupants();
+                String personName = checkoutApplicationEntryInfo.getPerson().getName();
+                //校验入住信息是否被换宿
+                RoomChangeApplicationEntryCollection roomChangeApplicationEntryCollection =
+                        iRoomChangeApplicationEntry.getRoomChangeApplicationEntryCollection("select parent.number where oldOccupants = '" + occupants.getId() + "'");
+                if (roomChangeApplicationEntryCollection.size() > 0) {
+                    RoomChangeApplicationEntryInfo roomChangeApplicationEntryInfo = roomChangeApplicationEntryCollection.get(0);
+                    String number = roomChangeApplicationEntryInfo.getParent().getNumber();
+                    throw new ShrWebBizException("员工 " + personName + "已有换宿单[ " + number + " ],不能提交生效!");
+                }
             }
             }
-            throw new ShrWebBizException(errorMsgBuilder.toString());
+        } catch (BOSException e) {
+            logger.error(e);
+            throw new ShrWebBizException(e);
+        } catch (EASBizException e) {
+            logger.error(e);
+            throw new ShrWebBizException(e);
         }
         }
     }
     }
 }
 }

+ 8 - 6
websrc/com/kingdee/eas/custom/dormitorysystem/application/handler/CheckoutApplicationSelfEditHandler.java

@@ -6,8 +6,6 @@ import com.kingdee.bos.metadata.query.util.CompareType;
 import com.kingdee.bos.util.BOSUuid;
 import com.kingdee.bos.util.BOSUuid;
 import com.kingdee.eas.basedata.org.HROrgUnitInfo;
 import com.kingdee.eas.basedata.org.HROrgUnitInfo;
 import com.kingdee.eas.basedata.person.PersonInfo;
 import com.kingdee.eas.basedata.person.PersonInfo;
-import com.kingdee.eas.custom.dormitorysystem.application.CheckInApplicationEntryInfo;
-import com.kingdee.eas.custom.dormitorysystem.application.CheckInApplicationInfo;
 import com.kingdee.eas.custom.dormitorysystem.application.CheckoutApplicationEntryInfo;
 import com.kingdee.eas.custom.dormitorysystem.application.CheckoutApplicationEntryInfo;
 import com.kingdee.eas.custom.dormitorysystem.application.CheckoutApplicationInfo;
 import com.kingdee.eas.custom.dormitorysystem.application.CheckoutApplicationInfo;
 import com.kingdee.eas.custom.dormitorysystem.occupants.IOccupants;
 import com.kingdee.eas.custom.dormitorysystem.occupants.IOccupants;
@@ -15,13 +13,11 @@ import com.kingdee.eas.custom.dormitorysystem.occupants.OccupantsCollection;
 import com.kingdee.eas.custom.dormitorysystem.occupants.OccupantsFactory;
 import com.kingdee.eas.custom.dormitorysystem.occupants.OccupantsFactory;
 import com.kingdee.eas.custom.dormitorysystem.occupants.OccupantsInfo;
 import com.kingdee.eas.custom.dormitorysystem.occupants.OccupantsInfo;
 import com.kingdee.eas.framework.CoreBaseInfo;
 import com.kingdee.eas.framework.CoreBaseInfo;
-import com.kingdee.eas.hr.emp.PersonPositionFactory;
 import com.kingdee.eas.hr.emp.PersonPositionInfo;
 import com.kingdee.eas.hr.emp.PersonPositionInfo;
 import com.kingdee.eas.util.app.ContextUtil;
 import com.kingdee.eas.util.app.ContextUtil;
 import com.kingdee.shr.base.syssetting.context.SHRContext;
 import com.kingdee.shr.base.syssetting.context.SHRContext;
 import com.kingdee.shr.base.syssetting.exception.SHRWebException;
 import com.kingdee.shr.base.syssetting.exception.SHRWebException;
 import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
 import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
-import com.kingdee.util.DateTimeUtils;
 import org.apache.log4j.Logger;
 import org.apache.log4j.Logger;
 
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
@@ -33,7 +29,7 @@ import java.util.Date;
  * @Date 2025/4/24 13:48
  * @Date 2025/4/24 13:48
  * @Created by Heyuan
  * @Created by Heyuan
  */
  */
-public class CheckoutApplicationSelfEditHandler extends DormitoryApplicationEditHandler {
+public class CheckoutApplicationSelfEditHandler extends CheckoutApplicationEditHandler {
     private static Logger logger = Logger.getLogger(CheckoutApplicationSelfEditHandler.class);
     private static Logger logger = Logger.getLogger(CheckoutApplicationSelfEditHandler.class);
 
 
 
 
@@ -64,7 +60,13 @@ public class CheckoutApplicationSelfEditHandler extends DormitoryApplicationEdit
             filterItems.add(new FilterItemInfo("CheckInDate", date, CompareType.LESS_EQUALS));
             filterItems.add(new FilterItemInfo("CheckInDate", date, CompareType.LESS_EQUALS));
             filterItems.add(new FilterItemInfo("CheckOutDate", date, CompareType.GREATER));
             filterItems.add(new FilterItemInfo("CheckOutDate", date, CompareType.GREATER));
             SelectorItemCollection sic = new SelectorItemCollection();
             SelectorItemCollection sic = new SelectorItemCollection();
-            //sic.add("personPosition¡£pe")
+            sic.add("personPosition.person.name");
+            sic.add("id");
+            sic.add("CheckInDate");
+            sic.add("CheckOutDate");
+            sic.add("personPosition.personDep.*");
+            sic.add("personPosition.primaryPosition.*");
+            sic.add("Dormitory.*");
             EntityViewInfo viewInfo = EntityViewInfo.getInstance(filterInfo, sic, null);
             EntityViewInfo viewInfo = EntityViewInfo.getInstance(filterInfo, sic, null);
             occupantsCollection = iOccupants.getOccupantsCollection(viewInfo);
             occupantsCollection = iOccupants.getOccupantsCollection(viewInfo);
         } catch (Exception e) {
         } catch (Exception e) {

+ 126 - 0
websrc/com/kingdee/eas/custom/dormitorysystem/application/service/CheckoutApplicationImportService.java

@@ -0,0 +1,126 @@
+package com.kingdee.eas.custom.dormitorysystem.application.service;
+
+import com.kingdee.bos.BOSException;
+import com.kingdee.bos.Context;
+import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
+import com.kingdee.bos.metadata.entity.FilterInfo;
+import com.kingdee.bos.metadata.entity.FilterItemCollection;
+import com.kingdee.bos.metadata.entity.FilterItemInfo;
+import com.kingdee.bos.metadata.entity.SelectorItemCollection;
+import com.kingdee.bos.metadata.query.SelectorInfo;
+import com.kingdee.bos.metadata.query.util.CompareType;
+import com.kingdee.bos.util.BOSUuid;
+import com.kingdee.eas.basedata.org.HROrgUnitInfo;
+import com.kingdee.eas.basedata.person.PersonInfo;
+import com.kingdee.eas.common.EASBizException;
+import com.kingdee.eas.custom.dormitorysystem.application.*;
+import com.kingdee.eas.custom.dormitorysystem.dormitory.DormitoryFactory;
+import com.kingdee.eas.custom.dormitorysystem.dormitory.DormitoryInfo;
+import com.kingdee.eas.custom.dormitorysystem.dormitory.IDormitory;
+import com.kingdee.eas.custom.dormitorysystem.enumerationset.DormitoryClassification;
+import com.kingdee.eas.custom.dormitorysystem.occupants.IOccupants;
+import com.kingdee.eas.custom.dormitorysystem.occupants.OccupantsFactory;
+import com.kingdee.eas.custom.dormitorysystem.occupants.OccupantsInfo;
+import com.kingdee.eas.framework.CoreBaseInfo;
+import com.kingdee.eas.hr.base.HRBillStateEnum;
+import com.kingdee.eas.hr.emp.PersonPositionFactory;
+import com.kingdee.eas.hr.emp.PersonPositionInfo;
+import com.kingdee.shr.base.syssetting.app.io.fileImport.BaseColumnInfo;
+import com.kingdee.shr.base.syssetting.app.io.fileImport.BaseImportService;
+import com.kingdee.shr.base.syssetting.app.io.fileImport.ImportException;
+import com.kingdee.shr.ml.util.SHRServerResource;
+import com.kingdee.util.DateTimeUtils;
+import org.apache.log4j.Logger;
+
+import java.util.Date;
+
+/**
+ * @Description 入住申请单导入实现类
+ * @Date 2025/4/24 13:48
+ * @Created by Heyuan
+ */
+public class CheckoutApplicationImportService extends BaseImportService {
+    Logger logger = Logger.getLogger(this.getClass());
+
+    @Override
+    protected FilterInfo getDefaultFilterByEntityInfo(String entityName, BaseColumnInfo columnInfo) {
+        FilterInfo defaultFilterByEntityInfo = super.getDefaultFilterByEntityInfo(entityName, columnInfo);
+        if ("com.kingdee.eas.custom.dormitorysystem.occupants.app.Occupants".equals(entityName)) {
+            Date date = new Date();
+            //房间
+            FilterInfo filter = new FilterInfo();
+            FilterItemCollection filterItems = filter.getFilterItems();
+            filterItems.add(new FilterItemInfo("CheckInDate", date, CompareType.LESS_EQUALS));
+            filterItems.add(new FilterItemInfo("CheckOutDate", date, CompareType.GREATER));
+            return filter;
+        }
+        return defaultFilterByEntityInfo;
+    }
+
+    protected void verifyRowBiz(CoreBaseInfo coreBaseInfo) throws ImportException {
+        try {
+            Context ctx = this.getContext();
+            CheckoutApplicationEntryInfo entryInfo = (CheckoutApplicationEntryInfo) coreBaseInfo;
+            Date checkoutDate = entryInfo.getCheckoutDate();
+            OccupantsInfo occupants = entryInfo.getOccupants();
+            String occupantsId = occupants.getId().toString();
+            IOccupants iOccupants = OccupantsFactory.getLocalInstance(ctx);
+            occupants = iOccupants.getOccupantsInfo(new ObjectUuidPK(occupantsId));
+            Date checkInDate = occupants.getCheckInDate();
+            Date oldCheckOutDate = occupants.getCheckOutDate();
+            if (!checkoutDate.after(checkInDate)) {
+                throw new ImportException("退宿日期不能小于等于入住日期!");
+            } else if (checkoutDate.compareTo(oldCheckOutDate) == 0) {
+                throw new ImportException("退宿日期不能等于原退宿日期!");
+            }
+        } catch (BOSException e) {
+            logger.error(e);
+            throw new ImportException(e);
+        } catch (EASBizException e) {
+            logger.error(e);
+            throw new ImportException(e);
+        }
+    }
+
+    protected void submitData(CoreBaseInfo coreBaseInfo) throws ImportException {
+        Context ctx = this.getContext();
+        try {
+            CheckoutApplicationInfo checkoutApplicationInfo = new CheckoutApplicationInfo();
+            checkoutApplicationInfo.setBillState(HRBillStateEnum.SAVED);
+            HROrgUnitInfo hrOrgUnitInfo = new HROrgUnitInfo();
+            hrOrgUnitInfo.setId(BOSUuid.read("00000000-0000-0000-0000-000000000000CCE7AED4"));
+            checkoutApplicationInfo.setHrOrgUnit(hrOrgUnitInfo);
+            //分录
+            CheckoutApplicationEntryInfo entryInfo = (CheckoutApplicationEntryInfo) coreBaseInfo;
+            OccupantsInfo occupants = entryInfo.getOccupants();
+            String occupantsId = occupants.getId().toString();
+            SelectorItemCollection sic = new SelectorItemCollection();
+            sic.add("person.id");
+            sic.add("CheckOutDate");
+            sic.add("CheckInDate");
+            sic.add("Dormitory.id");
+            sic.add("personPosition.personDep.id");
+            sic.add("personPosition.primaryPosition.id");
+            IOccupants iOccupants = OccupantsFactory.getLocalInstance(ctx);
+            occupants = iOccupants.getOccupantsInfo(new ObjectUuidPK(occupantsId),sic);
+            entryInfo.setPerson(occupants.getPerson());
+            entryInfo.setAdminOrg(occupants.getPersonPosition().getPersonDep());
+            entryInfo.setPosition(occupants.getPersonPosition().getPrimaryPosition());
+            //原退宿日期
+            entryInfo.setOldCheckoutDate(occupants.getCheckOutDate());
+            entryInfo.setCurrentRoom(occupants.getDormitory());
+            entryInfo.setCheckInDate(occupants.getCheckInDate());
+            checkoutApplicationInfo.getEntrys().add(entryInfo);
+            CheckoutApplicationFactory.getLocalInstance(ctx).save(checkoutApplicationInfo);
+        } catch (EASBizException e) {
+            ImportException importException = new ImportException(e.getMessage(ctx.getLocale()), e);
+            throw importException;
+        } catch (BOSException e) {
+            ImportException importException = new ImportException(SHRServerResource.getString("com.kingdee.shr.base.syssetting.CommonserviceResource", "save_fails_bos", ctx), e);
+            throw importException;
+        } catch (Exception e) {
+            ImportException importException = new ImportException(SHRServerResource.getString("com.kingdee.shr.base.syssetting.CommonserviceResource", "save_submit_fails", ctx), e);
+            throw importException;
+        }
+    }
+}

+ 73 - 8
websrc/com/kingdee/eas/custom/dormitorysystem/application/service/ValidateRoomAvailableByBillIdsService.java

@@ -11,10 +11,7 @@ import com.kingdee.bos.util.BOSUuid;
 import com.kingdee.eas.basedata.person.Genders;
 import com.kingdee.eas.basedata.person.Genders;
 import com.kingdee.eas.basedata.person.PersonInfo;
 import com.kingdee.eas.basedata.person.PersonInfo;
 import com.kingdee.eas.common.EASBizException;
 import com.kingdee.eas.common.EASBizException;
-import com.kingdee.eas.custom.dormitorysystem.application.CheckInApplicationEntryCollection;
-import com.kingdee.eas.custom.dormitorysystem.application.CheckInApplicationEntryFactory;
-import com.kingdee.eas.custom.dormitorysystem.application.CheckInApplicationEntryInfo;
-import com.kingdee.eas.custom.dormitorysystem.application.ICheckInApplicationEntry;
+import com.kingdee.eas.custom.dormitorysystem.application.*;
 import com.kingdee.eas.custom.dormitorysystem.dormitory.DormitoryFactory;
 import com.kingdee.eas.custom.dormitorysystem.dormitory.DormitoryFactory;
 import com.kingdee.eas.custom.dormitorysystem.dormitory.DormitoryInfo;
 import com.kingdee.eas.custom.dormitorysystem.dormitory.DormitoryInfo;
 import com.kingdee.eas.custom.dormitorysystem.dormitory.IDormitory;
 import com.kingdee.eas.custom.dormitorysystem.dormitory.IDormitory;
@@ -131,7 +128,9 @@ public class ValidateRoomAvailableByBillIdsService implements IHRMsfService {
                     dormCheckInCount += getCheckInInfoByOccupants(ctx, checkInDate, checkoutDate, roomId, personType);
                     dormCheckInCount += getCheckInInfoByOccupants(ctx, checkInDate, checkoutDate, roomId, personType);
                     //3.根据入住日期和退宿日期算出入住申请单状态为申请中的已住人数
                     //3.根据入住日期和退宿日期算出入住申请单状态为申请中的已住人数
                     dormCheckInCount += getCheckInInfoByCheckInApplication(ctx, checkInDate, checkoutDate, roomId, personType);
                     dormCheckInCount += getCheckInInfoByCheckInApplication(ctx, checkInDate, checkoutDate, roomId, personType);
-                    //4.根据当前参数缓存算出已住人数
+                    //4.根据入住日期和退宿日期算出换宿申请单状态为申请中的已住人数
+                    dormCheckInCount += getRoomChangeInfoByRoomChangeApplication(ctx, checkInDate, checkoutDate, roomId, personType);
+                    //5.根据当前参数缓存算出已住人数
                     if (roomListMap.containsKey(roomId)) {
                     if (roomListMap.containsKey(roomId)) {
                         List<Map<String, Date>> roomMapList = roomListMap.get(roomId);
                         List<Map<String, Date>> roomMapList = roomListMap.get(roomId);
                         for (int k = 0; k < roomMapList.size(); k++) {
                         for (int k = 0; k < roomMapList.size(); k++) {
@@ -146,7 +145,7 @@ public class ValidateRoomAvailableByBillIdsService implements IHRMsfService {
                             }
                             }
                         }
                         }
                     }
                     }
-                    //5.算出房间剩余可住人数: 可住人数 - 已住人数
+                    //6.算出房间剩余可住人数: 可住人数 - 已住人数
                     if (occupancyCapacity - dormCheckInCount < 0) {
                     if (occupancyCapacity - dormCheckInCount < 0) {
                         String dormitoryName = dormitory.getName();
                         String dormitoryName = dormitory.getName();
                         throw new BOSException("当前入住人数" + dormCheckInCount + ",已超过房间[" + dormitoryName + "]可住人数" + occupancyCapacity + ",不能入住!");
                         throw new BOSException("当前入住人数" + dormCheckInCount + ",已超过房间[" + dormitoryName + "]可住人数" + occupancyCapacity + ",不能入住!");
@@ -162,7 +161,7 @@ public class ValidateRoomAvailableByBillIdsService implements IHRMsfService {
                         list.add(roomMap);
                         list.add(roomMap);
                     }
                     }
                 } catch (Exception e) {
                 } catch (Exception e) {
-                    logger.error("单据编号为" + baseInfoNumber + "校验未通过: " + e.getMessage());
+                    logger.error("单据编号为" + baseInfoNumber + "校验未通过: " + e.getMessage(), e);
                     errorMsgList.add("单据编号为" + baseInfoNumber + "校验未通过: " + e.getMessage());
                     errorMsgList.add("单据编号为" + baseInfoNumber + "校验未通过: " + e.getMessage());
                     //errorMsg.append("单据编号为").append(baseInfoNumber).append("校验未通过: ").append(e.getMessage()).append(System.lineSeparator());
                     //errorMsg.append("单据编号为").append(baseInfoNumber).append("校验未通过: ").append(e.getMessage()).append(System.lineSeparator());
                 }
                 }
@@ -178,6 +177,69 @@ public class ValidateRoomAvailableByBillIdsService implements IHRMsfService {
         return result;
         return result;
     }
     }
 
 
+    /**
+     * 根据入住日期和退宿日期算出换宿申请单状态为申请中的已住人数
+     *
+     * @param ctx
+     * @param checkInDate  入住日期
+     * @param checkoutDate 退宿日期
+     * @param roomId       房间id
+     * @param personType   人员类型
+     * @return
+     * @throws BOSException
+     */
+    private int getRoomChangeInfoByRoomChangeApplication(
+            Context ctx,
+            Date checkInDate,
+            Date checkoutDate,
+            String roomId,
+            PersonDormitoryTypeInfo personType
+    ) throws BOSException {
+        IRoomChangeApplicationEntry iRoomChangeApplicationEntry = RoomChangeApplicationEntryFactory.getLocalInstance(ctx);
+        FilterInfo filterInfo = new FilterInfo();
+        FilterItemCollection filterItems = filterInfo.getFilterItems();
+        //房间
+        filterItems.add(new FilterItemInfo("adjustRoom", roomId));
+        //申请入住日期在入住日期和退宿日期之间
+        filterItems.add(new FilterItemInfo("checkInDate", checkInDate, CompareType.LESS_EQUALS));
+        filterItems.add(new FilterItemInfo("checkoutDate", checkInDate, CompareType.GREATER_EQUALS));
+        //入住日期在申请入住日期和申请退宿日期之间
+        filterItems.add(new FilterItemInfo("checkInDate", checkInDate, CompareType.GREATER_EQUALS));
+        filterItems.add(new FilterItemInfo("checkInDate", checkoutDate, CompareType.LESS_EQUALS));
+        //单据状态等于审批中
+        filterItems.add(new FilterItemInfo("parent.billState", "1,2,3", CompareType.INCLUDE));
+        filterInfo.setMaskString("#0 and ((#1 and #2) or (#3 and #4)) and #5");
+        SelectorItemCollection sic = new SelectorItemCollection();
+        sic.add("checkInRoom.id");
+        sic.add("person.personType.id");
+        sic.add("person.personType.name");
+        EntityViewInfo viewInfo = EntityViewInfo.getInstance(filterInfo, sic, null);
+        RoomChangeApplicationEntryCollection roomChangeApplicationEntryCol = iRoomChangeApplicationEntry.getRoomChangeApplicationEntryCollection(viewInfo);
+        String personTypeId = personType.getId().toString();
+        String personTypeName = personType.getName();
+        //已住人数
+        int dormCheckInCount = 0;
+        for (int i = 0; i < roomChangeApplicationEntryCol.size(); i++) {
+            RoomChangeApplicationEntryInfo roomChangeApplicationEntryInfo = roomChangeApplicationEntryCol.get(i);
+            //房间
+            PersonInfo person = roomChangeApplicationEntryInfo.getPerson();
+            String personName = person.getName();
+            //人员类型
+            PersonDormitoryTypeInfo personDormitoryType = (PersonDormitoryTypeInfo) person.get("personType");
+            if (personDormitoryType == null) {
+                throw new BOSException("员工[" + personName + "]的人员类别为空,请及时维护!");
+            }
+            String personDormitoryTypeId = personDormitoryType.getId().toString();
+            String personDormitoryTypeName = personDormitoryType.getName();
+            if (!personTypeId.equals(personDormitoryTypeId)) {
+                throw new BOSException("人员类别[" + personTypeName + "]与宿舍类型[" + personDormitoryTypeName + "]不符,不能入住!");
+            }
+            //累计已住人数
+            dormCheckInCount++;
+        }
+        return dormCheckInCount;
+    }
+
     /**
     /**
      * 根据入住日期和退宿日期算出入住申请单状态为申请中的已住人数
      * 根据入住日期和退宿日期算出入住申请单状态为申请中的已住人数
      *
      *
@@ -208,7 +270,7 @@ public class ValidateRoomAvailableByBillIdsService implements IHRMsfService {
         filterItems.add(new FilterItemInfo("checkInDate", checkInDate, CompareType.GREATER_EQUALS));
         filterItems.add(new FilterItemInfo("checkInDate", checkInDate, CompareType.GREATER_EQUALS));
         filterItems.add(new FilterItemInfo("checkInDate", checkoutDate, CompareType.LESS_EQUALS));
         filterItems.add(new FilterItemInfo("checkInDate", checkoutDate, CompareType.LESS_EQUALS));
         //单据状态等于审批中
         //单据状态等于审批中
-        filterItems.add(new FilterItemInfo("parent.billState", "3"));
+        filterItems.add(new FilterItemInfo("parent.billState", "1,2,3", CompareType.INCLUDE));
         filterInfo.setMaskString("#0 and ((#1 and #2) or (#3 and #4)) and #5");
         filterInfo.setMaskString("#0 and ((#1 and #2) or (#3 and #4)) and #5");
         SelectorItemCollection sic = new SelectorItemCollection();
         SelectorItemCollection sic = new SelectorItemCollection();
         sic.add("checkInRoom.id");
         sic.add("checkInRoom.id");
@@ -312,6 +374,9 @@ public class ValidateRoomAvailableByBillIdsService implements IHRMsfService {
             DormitoryInfo dormitory
             DormitoryInfo dormitory
     ) throws BOSException, EASBizException {
     ) throws BOSException, EASBizException {
         Genders gender = personInfo.getGender();
         Genders gender = personInfo.getGender();
+        if (gender == null) {
+            throw new BOSException("员工性别为空!");
+        }
         String personInfoName = personInfo.getName();
         String personInfoName = personInfo.getName();
         IDormitory iDormitory = DormitoryFactory.getLocalInstance(ctx);
         IDormitory iDormitory = DormitoryFactory.getLocalInstance(ctx);
         //查询房间信息
         //查询房间信息

+ 74 - 8
websrc/com/kingdee/eas/custom/dormitorysystem/application/service/ValidateRoomAvailableService.java

@@ -1,5 +1,6 @@
 package com.kingdee.eas.custom.dormitorysystem.application.service;
 package com.kingdee.eas.custom.dormitorysystem.application.service;
 
 
+import com.kingdee.eas.custom.dormitorysystem.application.*;
 import com.kingdee.eas.custom.dormitorysystem.enumerationset.DormitoryClassification;
 import com.kingdee.eas.custom.dormitorysystem.enumerationset.DormitoryClassification;
 import com.kingdee.eas.custom.dormitorysystem.otherbasicdata.DormitoryTypeInfo;
 import com.kingdee.eas.custom.dormitorysystem.otherbasicdata.DormitoryTypeInfo;
 import com.kingdee.shr.base.syssetting.BasicItemStateEnum;
 import com.kingdee.shr.base.syssetting.BasicItemStateEnum;
@@ -16,10 +17,6 @@ import com.kingdee.eas.basedata.person.IPerson;
 import com.kingdee.eas.basedata.person.PersonFactory;
 import com.kingdee.eas.basedata.person.PersonFactory;
 import com.kingdee.eas.basedata.person.PersonInfo;
 import com.kingdee.eas.basedata.person.PersonInfo;
 import com.kingdee.eas.common.EASBizException;
 import com.kingdee.eas.common.EASBizException;
-import com.kingdee.eas.custom.dormitorysystem.application.CheckInApplicationEntryCollection;
-import com.kingdee.eas.custom.dormitorysystem.application.CheckInApplicationEntryFactory;
-import com.kingdee.eas.custom.dormitorysystem.application.CheckInApplicationEntryInfo;
-import com.kingdee.eas.custom.dormitorysystem.application.ICheckInApplicationEntry;
 import com.kingdee.eas.custom.dormitorysystem.dormitory.DormitoryFactory;
 import com.kingdee.eas.custom.dormitorysystem.dormitory.DormitoryFactory;
 import com.kingdee.eas.custom.dormitorysystem.dormitory.DormitoryInfo;
 import com.kingdee.eas.custom.dormitorysystem.dormitory.DormitoryInfo;
 import com.kingdee.eas.custom.dormitorysystem.dormitory.IDormitory;
 import com.kingdee.eas.custom.dormitorysystem.dormitory.IDormitory;
@@ -110,8 +107,10 @@ public class ValidateRoomAvailableService implements IHRMsfService {
                 //2.根据入住日期和退宿日期算出入住信息房间已住人数
                 //2.根据入住日期和退宿日期算出入住信息房间已住人数
                 dormCheckInCount += getCheckInInfoByOccupants(ctx, checkInDate, checkoutDate, roomId, personType);
                 dormCheckInCount += getCheckInInfoByOccupants(ctx, checkInDate, checkoutDate, roomId, personType);
                 //3.根据入住日期和退宿日期算出入住申请单状态为申请中的已住人数
                 //3.根据入住日期和退宿日期算出入住申请单状态为申请中的已住人数
-                dormCheckInCount += getCheckInInfoByCheckInApplication(ctx, checkInDate, checkoutDate, roomId, personType);
-                //4.根据当前参数缓存算出已住人数
+                dormCheckInCount += getCheckInInfoByCheckInApplication(ctx, checkInDate, checkoutDate, roomId,  personType);
+                //4.根据入住日期和退宿日期算出换宿申请单状态为申请中的已住人数
+                dormCheckInCount += getRoomChangeInfoByRoomChangeApplication(ctx, checkInDate, checkoutDate, roomId,  personType);
+                //5.根据当前参数缓存算出已住人数
                 if (roomListMap.containsKey(roomId)) {
                 if (roomListMap.containsKey(roomId)) {
                     List<Map<String, Date>> roomMapList = roomListMap.get(roomId);
                     List<Map<String, Date>> roomMapList = roomListMap.get(roomId);
                     for (int j = 0; j < roomMapList.size(); j++) {
                     for (int j = 0; j < roomMapList.size(); j++) {
@@ -126,7 +125,7 @@ public class ValidateRoomAvailableService implements IHRMsfService {
                         }
                         }
                     }
                     }
                 }
                 }
-                //5.算出房间剩余可住人数: 可住人数 - 已住人数
+                //6.算出房间剩余可住人数: 可住人数 - 已住人数
                 if (occupancyCapacity - dormCheckInCount < 0) {
                 if (occupancyCapacity - dormCheckInCount < 0) {
                     String dormitoryName = dormitoryInfo.getName();
                     String dormitoryName = dormitoryInfo.getName();
                     throw new BOSException("当前入住人数" + dormCheckInCount + ",已超过房间[" + dormitoryName + "]可住人数" + occupancyCapacity + ",不能入住!");
                     throw new BOSException("当前入住人数" + dormCheckInCount + ",已超过房间[" + dormitoryName + "]可住人数" + occupancyCapacity + ",不能入住!");
@@ -156,6 +155,70 @@ public class ValidateRoomAvailableService implements IHRMsfService {
         return result;
         return result;
     }
     }
 
 
+
+    /**
+     * 根据入住日期和退宿日期算出换宿申请单状态为申请中的已住人数
+     *
+     * @param ctx
+     * @param checkInDate  入住日期
+     * @param checkoutDate 退宿日期
+     * @param roomId       房间id
+     * @param personType   人员类型
+     * @return
+     * @throws BOSException
+     */
+    private int getRoomChangeInfoByRoomChangeApplication(
+            Context ctx,
+            Date checkInDate,
+            Date checkoutDate,
+            String roomId,
+            PersonDormitoryTypeInfo personType
+    ) throws BOSException {
+        IRoomChangeApplicationEntry iRoomChangeApplicationEntry = RoomChangeApplicationEntryFactory.getLocalInstance(ctx);
+        FilterInfo filterInfo = new FilterInfo();
+        FilterItemCollection filterItems = filterInfo.getFilterItems();
+        //房间
+        filterItems.add(new FilterItemInfo("adjustRoom", roomId));
+        //申请入住日期在入住日期和退宿日期之间
+        filterItems.add(new FilterItemInfo("checkInDate", checkInDate, CompareType.LESS_EQUALS));
+        filterItems.add(new FilterItemInfo("checkoutDate", checkInDate, CompareType.GREATER_EQUALS));
+        //入住日期在申请入住日期和申请退宿日期之间
+        filterItems.add(new FilterItemInfo("checkInDate", checkInDate, CompareType.GREATER_EQUALS));
+        filterItems.add(new FilterItemInfo("checkInDate", checkoutDate, CompareType.LESS_EQUALS));
+        //单据状态等于审批中
+        filterItems.add(new FilterItemInfo("parent.billState", "1,2,3", CompareType.INCLUDE));
+        filterInfo.setMaskString("#0 and ((#1 and #2) or (#3 and #4)) and #5");
+        SelectorItemCollection sic = new SelectorItemCollection();
+        sic.add("checkInRoom.id");
+        sic.add("person.personType.id");
+        sic.add("person.personType.name");
+        EntityViewInfo viewInfo = EntityViewInfo.getInstance(filterInfo, sic, null);
+        RoomChangeApplicationEntryCollection roomChangeApplicationEntryCol = iRoomChangeApplicationEntry.getRoomChangeApplicationEntryCollection(viewInfo);
+        String personTypeId = personType.getId().toString();
+        String personTypeName = personType.getName();
+        //已住人数
+        int dormCheckInCount = 0;
+        for (int i = 0; i < roomChangeApplicationEntryCol.size(); i++) {
+            RoomChangeApplicationEntryInfo roomChangeApplicationEntryInfo = roomChangeApplicationEntryCol.get(i);
+            //房间
+            PersonInfo person = roomChangeApplicationEntryInfo.getPerson();
+            String personName = person.getName();
+            //人员类型
+            PersonDormitoryTypeInfo personDormitoryType = (PersonDormitoryTypeInfo) person.get("personType");
+            if (personDormitoryType == null) {
+                throw new BOSException("员工[" + personName + "]的人员类别为空,请及时维护!");
+            }
+            String personDormitoryTypeId = personDormitoryType.getId().toString();
+            String personDormitoryTypeName = personDormitoryType.getName();
+            if (!personTypeId.equals(personDormitoryTypeId)) {
+                throw new BOSException("人员类别[" + personTypeName + "]与宿舍类型[" + personDormitoryTypeName + "]不符,不能入住!");
+            }
+            //累计已住人数
+            dormCheckInCount++;
+        }
+        return dormCheckInCount;
+    }
+
     /**
     /**
      * 根据入住日期和退宿日期算出入住申请单状态为申请中的已住人数
      * 根据入住日期和退宿日期算出入住申请单状态为申请中的已住人数
      *
      *
@@ -186,7 +249,7 @@ public class ValidateRoomAvailableService implements IHRMsfService {
         filterItems.add(new FilterItemInfo("checkInDate", checkInDate, CompareType.GREATER_EQUALS));
         filterItems.add(new FilterItemInfo("checkInDate", checkInDate, CompareType.GREATER_EQUALS));
         filterItems.add(new FilterItemInfo("checkInDate", checkoutDate, CompareType.LESS_EQUALS));
         filterItems.add(new FilterItemInfo("checkInDate", checkoutDate, CompareType.LESS_EQUALS));
         //单据状态等于审批中
         //单据状态等于审批中
-        filterItems.add(new FilterItemInfo("parent.billState", "3"));
+        filterItems.add(new FilterItemInfo("parent.billState", "1,2,3", CompareType.INCLUDE));
         filterInfo.setMaskString("#0 and ((#1 and #2) or (#3 and #4)) and #5");
         filterInfo.setMaskString("#0 and ((#1 and #2) or (#3 and #4)) and #5");
         SelectorItemCollection sic = new SelectorItemCollection();
         SelectorItemCollection sic = new SelectorItemCollection();
         sic.add("checkInRoom.id");
         sic.add("checkInRoom.id");
@@ -290,6 +353,9 @@ public class ValidateRoomAvailableService implements IHRMsfService {
             String roomIds
             String roomIds
     ) throws BOSException, EASBizException {
     ) throws BOSException, EASBizException {
         Genders gender = personInfo.getGender();
         Genders gender = personInfo.getGender();
+        if (gender == null) {
+            throw new BOSException("员工性别为空!");
+        }
         String personInfoName = personInfo.getName();
         String personInfoName = personInfo.getName();
         IDormitory iDormitory = DormitoryFactory.getLocalInstance(ctx);
         IDormitory iDormitory = DormitoryFactory.getLocalInstance(ctx);
         //查询房间信息
         //查询房间信息