Преглед на файлове

本月加班申请bug修复

chenzhfa преди 3 години
родител
ревизия
3f38d715a2

+ 53 - 17
hrkq/hrkq/src/client/nccloud/hrkq/hrkq/monthottimevo/action/MonthOtTimeVOCheckSaveAction.java

@@ -4,12 +4,18 @@ import java.text.SimpleDateFormat;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.lang3.StringUtils;
+
 import nc.bs.logging.Logger;
+import nc.itf.om.IPostQueryService;
 import nc.vo.hi.psndoc.PsnJobVO;
 import nc.vo.hrkq.monthottime.AggMonthOtTimeVO;
 import nc.vo.hrkq.monthottime.MonthOtTimeBVO;
 import nc.vo.hrkq.monthottime.MonthOtTimeVO;
+import nc.vo.om.post.AggPostVO;
+import nc.vo.om.post.PostVO;
 import nc.vo.pub.BusinessException;
+import nc.vo.pub.lang.UFBoolean;
 import nc.vo.pub.lang.UFDate;
 import nc.vo.pub.lang.UFDateTime;
 import nc.vo.pub.lang.UFDouble;
@@ -110,19 +116,44 @@ public class MonthOtTimeVOCheckSaveAction implements ICommonAction {
 		    		result = "加班日期"+msg2+"不属于节假日加班,请选择正确的加班类型";
 		    	}
 		    }
-		    doBeforeCheck(aggVO);
-		    String dateCheckMsg = CommonUtil.checkSelf(bvos);
-		    if(dateCheckMsg != null) {
-		    	throw new BusinessException("加班时间范围内存在冲突的加班单据");
+		    String pk_post = psnjobVO.getPk_post();
+		    if(StringUtils.isNotBlank(pk_post)) {
+		    	aggVO.setChildrenVO(bvos);
+		    	AggPostVO aggPostVO = ServiceLocator.find(IPostQueryService.class).queryByPk(pk_post);
+		    	if(aggPostVO != null) {
+			    	PostVO postVO = (PostVO) aggPostVO.getParentVO();
+			    	Object glbdef1 = postVO.getAttributeValue("glbdef1");
+			    	if(glbdef1 == null || !UFBoolean.valueOf(glbdef1.toString()).booleanValue()) {
+			    		doBeforeCheck(aggVO);
+			    	}
+		    	}
 		    }
-		    
-		    List<MonthOtTimeBVO> oldBvos = CommonUtil.getMaintainService().queryBVOByPkPsndoc(pk_psndoc);
-		    if(oldBvos != null && oldBvos.size() > 0) {
-			    String dateTwoCheckMsg = CommonUtil.checkTwoList(bvos,oldBvos.toArray(new MonthOtTimeBVO[0]));
-			    if(dateTwoCheckMsg != null) {
-			    	throw new BusinessException("加班时间范围内存在冲突的加班单据");
+		    if("1".equals(otapplytype)) {//按次
+		    	String dateCheckMsg = CommonUtil.checkSelfTimes(bvos);
+			    if(dateCheckMsg != null) {
+			    	throw new BusinessException("加班时间范围内存在冲突的加班单据,冲突时间:"+dateCheckMsg);
+			    }
+			    List<MonthOtTimeBVO> oldBvos = CommonUtil.getMaintainService().queryBVOByPkPsndoc(pk_psndoc);
+			    if(oldBvos != null && oldBvos.size() > 0) {
+			    	String dateTwoCheckMsg = CommonUtil.checkTwoListTimes(bvos,oldBvos.toArray(new MonthOtTimeBVO[0]));
+			    	if(dateTwoCheckMsg != null) {
+			    		throw new BusinessException("加班时间范围内存在冲突的加班单据,冲突时间:"+dateTwoCheckMsg);
+			    	}
+			    }
+		    }else if("2".equals(otapplytype)) {//普通
+			    String dateCheckMsg = CommonUtil.checkSelf(bvos);
+			    if(dateCheckMsg != null) {
+			    	throw new BusinessException("加班时间范围内存在冲突的加班单据,冲突时间:"+dateCheckMsg);
+			    }
+			    List<MonthOtTimeBVO> oldBvos = CommonUtil.getMaintainService().queryBVOByPkPsndoc(pk_psndoc);
+			    if(oldBvos != null && oldBvos.size() > 0) {
+			    	String dateTwoCheckMsg = CommonUtil.checkTwoList(bvos,oldBvos.toArray(new MonthOtTimeBVO[0]));
+			    	if(dateTwoCheckMsg != null) {
+			    		throw new BusinessException("加班时间范围内存在冲突的加班单据,冲突时间:"+dateCheckMsg);
+			    	}
 			    }
 		    }
+		    
 		}catch (BusinessException ex) {
 			Logger.error(ex.getMessage(), ex);
 			ExceptionUtils.wrapException(ex);
@@ -143,13 +174,18 @@ public class MonthOtTimeVOCheckSaveAction implements ICommonAction {
 			  Map<String, UFDouble> map = service.queryMonth(pk_psndoc);
 			  UFDouble totalHours = UFDouble.ZERO_DBL;
 			  MonthOtTimeBVO[] bvos = (MonthOtTimeBVO[]) aggvo.getChildrenVO();
-			  for(MonthOtTimeBVO bvo : bvos) {
-				  UFDate otdate = (UFDate) bvo.getAttributeValue(MonthOtTimeBVO.OTDATE);
-				  String monthday = dateToStr(otdate);
-				  UFDouble hours = map.get(monthday) == null ? UFDouble.ZERO_DBL : map.get(monthday);
-				  totalHours = hours.add(bvo.getOthours());
-				  if(totalHours.toDouble() > 36) {
-					  checkFlag = Boolean.TRUE;
+			  if(map != null && bvos != null && bvos.length > 0) {
+				  for(MonthOtTimeBVO bvo : bvos) {
+					  UFDate otdate = bvo.getAttributeValue(MonthOtTimeBVO.OTDATE) == null ? ((UFDateTime)bvo.getAttributeValue(MonthOtTimeBVO.OVERTIMEBEGINTIME)).getDate() : (UFDate) bvo.getAttributeValue(MonthOtTimeBVO.OTDATE);
+					  if(otdate != null) {
+						  String monthday = dateToStr(otdate);
+						  UFDouble hours = map.get(monthday) == null ? UFDouble.ZERO_DBL : map.get(monthday);
+						  UFDouble othours = bvo.getAttributeValue(MonthOtTimeBVO.OTHOURS) == null ? UFDouble.ZERO_DBL : (UFDouble) bvo.getAttributeValue(MonthOtTimeBVO.OTHOURS);
+						  totalHours = hours.add(othours);
+						  if(totalHours.toDouble() > 36) {
+							  checkFlag = Boolean.TRUE;
+						  }
+					  }
 				  }
 			  }
 			  if(checkFlag) {

+ 33 - 10
hrkq/hrkq/src/client/nccloud/hrkq/hrkq/monthottimevo/action/MonthOtTimeVOCommitAction.java

@@ -5,14 +5,21 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.commons.lang3.StringUtils;
+
 import nc.bs.logging.Logger;
+import nc.itf.om.IPostQueryService;
 import nc.md.persist.framework.IMDPersistenceQueryService;
+import nc.vo.hi.psndoc.PsnJobVO;
 import nc.vo.hrkq.monthottime.AggMonthOtTimeVO;
 import nc.vo.hrkq.monthottime.MonthOtTimeBVO;
 import nc.vo.hrkq.monthottime.MonthOtTimeVO;
+import nc.vo.om.post.AggPostVO;
+import nc.vo.om.post.PostVO;
 import nc.vo.pf.change.PfUtilBaseTools;
 import nc.vo.pf.pub.util.SQLUtil;
 import nc.vo.pub.BusinessException;
+import nc.vo.pub.lang.UFBoolean;
 import nc.vo.pub.lang.UFDate;
 import nc.vo.pub.lang.UFDateTime;
 import nc.vo.pub.lang.UFDouble;
@@ -20,6 +27,7 @@ import nc.vo.pubapp.pattern.model.entity.bill.AbstractBill;
 import nc.vo.uap.pf.PfProcessBatchRetObject;
 import nccloud.framework.core.exception.ExceptionUtils;
 import nccloud.framework.core.json.IJson;
+import nccloud.framework.service.ServiceLocator;
 import nccloud.framework.web.action.itf.ICommonAction;
 import nccloud.framework.web.container.IRequest;
 import nccloud.framework.web.json.JsonFactory;
@@ -32,6 +40,7 @@ import nccloud.itf.hrkq.hrkq.IMonthottimevoMaintain;
 import nccloud.pubitf.riart.pflow.CloudPFlowContext;
 import nccloud.pubitf.riart.pflow.ICloudScriptPFlowService;
 import nccloud.vo.hrkq.hrkq.MonthOtTimeVOConst;
+import nccloud.web.hrkq.common.utils.AttendDataUtil;
 import nccloud.web.workflow.approve.util.NCCFlowUtils;
 
 public class MonthOtTimeVOCommitAction implements ICommonAction{
@@ -46,8 +55,18 @@ public class MonthOtTimeVOCommitAction implements ICommonAction{
 	    	AggMonthOtTimeVO[] operaVOs = this.queryBillsByPks(operaParam);
 	      // ts赋值
 	      CommonUtil.setBillsTs(operaParam.getPkMapTs(), operaVOs);
-	      
-	      doBefore(operaVOs);
+	      PsnJobVO psnjobVO = AttendDataUtil.queryPsnJob(null);
+	      String pk_post = psnjobVO.getPk_post();
+		  if(StringUtils.isNotBlank(pk_post)) {
+			  AggPostVO aggPostVO = ServiceLocator.find(IPostQueryService.class).queryByPk(pk_post);
+			  if(aggPostVO != null) {
+				  PostVO postVO = (PostVO) aggPostVO.getParentVO();
+				  Object glbdef1 = postVO.getAttributeValue("glbdef1");
+				  if(glbdef1 == null || !UFBoolean.valueOf(glbdef1.toString()).booleanValue()) {
+					  doBefore(operaVOs);
+				  }
+			  }
+		  }
 	      
 	      // 对查询结果执行具体业务处理
 	      Object resultVOs = this.commit(operaVOs, operaParam.getUserObj());
@@ -76,14 +95,18 @@ public class MonthOtTimeVOCommitAction implements ICommonAction{
 			  UFDouble totalHours = UFDouble.ZERO_DBL;
 			  MonthOtTimeBVO[] bvos = (MonthOtTimeBVO[]) aggvo.getChildrenVO();
 			  for(MonthOtTimeBVO bvo : bvos) {
-				  UFDate otdate = (UFDate) bvo.getAttributeValue(MonthOtTimeBVO.OTDATE);
-				  String monthday = dateToStr(otdate);
-				  UFDouble hours = map == null || map.size() == 0 || map.get(monthday) == null ? UFDouble.ZERO_DBL : map.get(monthday);
-				  totalHours = hours.add(new UFDouble(bvo.getAttributeValue(MonthOtTimeBVO.OTHOURS).toString()));
-				  if(totalHours.toDouble() > 36) {
-					  checkFlag = Boolean.TRUE;
-				  } else {
-					  map.put(monthday, totalHours);
+				  UFDate otdate = bvo.getAttributeValue(MonthOtTimeBVO.OTDATE) == null ? ((UFDateTime)bvo.getAttributeValue(MonthOtTimeBVO.OVERTIMEBEGINTIME)).getDate() : (UFDate) bvo.getAttributeValue(MonthOtTimeBVO.OTDATE);
+				  if(otdate != null) {
+					  String monthday = dateToStr(otdate);
+					  UFDouble hours = map == null || map.size() == 0 || map.get(monthday) == null ? UFDouble.ZERO_DBL : map.get(monthday);
+	//				  totalHours = hours.add(new UFDouble(bvo.getAttributeValue(MonthOtTimeBVO.OTHOURS).toString()));
+					  UFDouble othours = bvo.getAttributeValue(MonthOtTimeBVO.OTHOURS) == null ? UFDouble.ZERO_DBL : (UFDouble) bvo.getAttributeValue(MonthOtTimeBVO.OTHOURS);
+					  totalHours = hours.add(othours);
+					  if(totalHours.toDouble() > 36) {
+						  checkFlag = Boolean.TRUE;
+					  } else {
+						  map.put(monthday, totalHours);
+					  }
 				  }
 			  }
 		  }

+ 26 - 11
hrkq/hrkq/src/client/nccloud/hrkq/hrkq/monthottimevo/action/MonthOtTimeVOCommonSaveAction.java

@@ -54,6 +54,7 @@ public class MonthOtTimeVOCommonSaveAction implements ICommonAction {
 		try {
 			BillCardOperator billCardOperator = new BillCardOperator();
 			setValue(vo,psnJob,appCode);
+			vo.setAttributeValue(MonthOtTimeVO.WITNESS, bvos[0].getAttributeValue(MonthOtTimeBVO.VBDEF8));
 			AggMonthOtTimeVO aggVO = new AggMonthOtTimeVO();
 			aggVO.setParentVO(vo);
 			for(MonthOtTimeBVO bvo : bvos) {
@@ -309,9 +310,9 @@ public class MonthOtTimeVOCommonSaveAction implements ICommonAction {
 	    }
 		String pk_psndoc = (String) parent.getAttributeValue(MonthOtTimeVO.PK_PSNDOC);
 	    MonthOtTimeBVO[] bvos = (MonthOtTimeBVO[]) vo.getChildrenVO();
+	    //加班类型,1为按次ottimestype,2为普通otdatetype
+	    String otapplytype = (String) parent.getAttributeValue(MonthOtTimeVO.OTAPPLYTYPE);
 	    if(bvos != null && bvos.length > 0) {
-	    	//加班类型,1为按次ottimestype,2为普通otdatetype
-	    	String otapplytype = (String) parent.getAttributeValue(MonthOtTimeVO.OTAPPLYTYPE);
 	    	IMonthottimevoMaintain service = ServiceLocator.find(IMonthottimevoMaintain.class);
 	    	List<Map<String, UFDate>> listMap = service.queryHoliday(pk_psndoc, psnjobVO.getPk_org());
 	    	List<String> defdocList = service.queryDefdoc();//查询节假日类型主键
@@ -382,17 +383,31 @@ public class MonthOtTimeVOCommonSaveAction implements ICommonAction {
 	    	}
 	    }
 	    
-	    String dateCheckMsg = CommonUtil.checkSelf(bvos);
-	    if(dateCheckMsg != null) {
-	    	throw new BusinessException("加班时间范围内存在冲突的加班单据");
-	    }
-	    
-	    List<MonthOtTimeBVO> oldBvos = CommonUtil.getMaintainService().queryBVOByPkPsndoc(pk_psndoc);
-	    if(oldBvos != null && oldBvos.size() > 0) {
-		    String dateTwoCheckMsg = CommonUtil.checkTwoList(bvos,oldBvos.toArray(new MonthOtTimeBVO[0]));
-		    if(dateTwoCheckMsg != null) {
+	    if("1".equals(otapplytype)) {//按次
+        	String dateCheckMsg = CommonUtil.checkSelfTimes(bvos);
+    	    if(dateCheckMsg != null) {
+    	    	throw new BusinessException("加班时间范围内存在冲突的加班单据,冲突时间:"+dateCheckMsg);
+    	    }
+    	    List<MonthOtTimeBVO> oldBvos = CommonUtil.getMaintainService().queryBVOByPkPsndoc(pk_psndoc);
+    	    if(oldBvos != null && oldBvos.size() > 0) {
+    	    	String dateTwoCheckMsg = CommonUtil.checkTwoListTimes(bvos,oldBvos.toArray(new MonthOtTimeBVO[0]));
+    	    	if(dateTwoCheckMsg != null) {
+    	    		throw new BusinessException("加班时间范围内存在冲突的加班单据,冲突时间:"+dateTwoCheckMsg);
+    	    	}
+    	    }
+	    }else if("2".equals(otapplytype)) {//普通
+		    String dateCheckMsg = CommonUtil.checkSelf(bvos);
+		    if(dateCheckMsg != null) {
 		    	throw new BusinessException("加班时间范围内存在冲突的加班单据");
 		    }
+		    
+		    List<MonthOtTimeBVO> oldBvos = CommonUtil.getMaintainService().queryBVOByPkPsndoc(pk_psndoc);
+		    if(oldBvos != null && oldBvos.size() > 0) {
+			    String dateTwoCheckMsg = CommonUtil.checkTwoList(bvos,oldBvos.toArray(new MonthOtTimeBVO[0]));
+			    if(dateTwoCheckMsg != null) {
+			    	throw new BusinessException("加班时间范围内存在冲突的加班单据");
+			    }
+		    }
 	    }
 	}
 	

+ 37 - 13
hrkq/hrkq/src/client/nccloud/hrkq/hrkq/monthottimevo/action/MonthOtTimeVOSaveAction.java

@@ -155,9 +155,9 @@ public class MonthOtTimeVOSaveAction implements ICommonAction {
     }
     
     MonthOtTimeBVO[] bvos = (MonthOtTimeBVO[]) vo.getChildrenVO();
+    //加班类型,1为按次ottimestype,2为普通otdatetype
+    String otapplytype = (String) parent.getAttributeValue(MonthOtTimeVO.OTAPPLYTYPE);
     if(bvos != null && bvos.length > 0) {
-    	//加班类型,1为按次ottimestype,2为普通otdatetype
-    	String otapplytype = (String) parent.getAttributeValue(MonthOtTimeVO.OTAPPLYTYPE);
     	IMonthottimevoMaintain service = ServiceLocator.find(IMonthottimevoMaintain.class);
     	List<Map<String, UFDate>> listMap = service.queryHoliday(pk_psndoc, psnjobVO.getPk_org());
     	List<String> defdocList = service.queryDefdoc();//查询节假日类型主键
@@ -224,19 +224,43 @@ public class MonthOtTimeVOSaveAction implements ICommonAction {
     	}
     	
     }
-    
-    String dateCheckMsg = CommonUtil.checkSelf(bvos);
-    if(dateCheckMsg != null) {
-    	throw new BusinessException("加班时间范围内存在冲突的加班单据");
-    }
-    
-    List<MonthOtTimeBVO> oldBvos = CommonUtil.getMaintainService().queryBVOByPkPsndoc(pk_psndoc);
-    if(oldBvos != null && oldBvos.size() > 0) {
-	    String dateTwoCheckMsg = CommonUtil.checkTwoList(bvos,oldBvos.toArray(new MonthOtTimeBVO[0]));
-	    if(dateTwoCheckMsg != null) {
-	    	throw new BusinessException("加班时间范围内存在冲突的加班单据");
+    if("1".equals(otapplytype)) {//按次
+    	String dateCheckMsg = CommonUtil.checkSelfTimes(bvos);
+	    if(dateCheckMsg != null) {
+	    	throw new BusinessException("加班时间范围内存在冲突的加班单据,冲突时间:"+dateCheckMsg);
+	    }
+	    List<MonthOtTimeBVO> oldBvos = CommonUtil.getMaintainService().queryBVOByPkPsndoc(pk_psndoc);
+	    if(oldBvos != null && oldBvos.size() > 0) {
+	    	String dateTwoCheckMsg = CommonUtil.checkTwoListTimes(bvos,oldBvos.toArray(new MonthOtTimeBVO[0]));
+	    	if(dateTwoCheckMsg != null) {
+	    		throw new BusinessException("加班时间范围内存在冲突的加班单据,冲突时间:"+dateTwoCheckMsg);
+	    	}
+	    }
+    }else if("2".equals(otapplytype)) {//普通
+	    String dateCheckMsg = CommonUtil.checkSelf(bvos);
+	    if(dateCheckMsg != null) {
+	    	throw new BusinessException("加班时间范围内存在冲突的加班单据,冲突时间:"+dateCheckMsg);
+	    }
+	    List<MonthOtTimeBVO> oldBvos = CommonUtil.getMaintainService().queryBVOByPkPsndoc(pk_psndoc);
+	    if(oldBvos != null && oldBvos.size() > 0) {
+	    	String dateTwoCheckMsg = CommonUtil.checkTwoList(bvos,oldBvos.toArray(new MonthOtTimeBVO[0]));
+	    	if(dateTwoCheckMsg != null) {
+	    		throw new BusinessException("加班时间范围内存在冲突的加班单据,冲突时间:"+dateCheckMsg);
+	    	}
 	    }
     }
+//    String dateCheckMsg = CommonUtil.checkSelf(bvos);
+//    if(dateCheckMsg != null) {
+//    	throw new BusinessException("加班时间范围内存在冲突的加班单据");
+//    }
+//    
+//    List<MonthOtTimeBVO> oldBvos = CommonUtil.getMaintainService().queryBVOByPkPsndoc(pk_psndoc);
+//    if(oldBvos != null && oldBvos.size() > 0) {
+//	    String dateTwoCheckMsg = CommonUtil.checkTwoList(bvos,oldBvos.toArray(new MonthOtTimeBVO[0]));
+//	    if(dateTwoCheckMsg != null) {
+//	    	throw new BusinessException("加班时间范围内存在冲突的加班单据");
+//	    }
+//    }
   }
   
   /**

+ 73 - 1
hrkq/hrkq/src/client/nccloud/hrkq/hrkq/monthottimevo/hrkq/util/CommonUtil.java

@@ -3,6 +3,8 @@ package nccloud.hrkq.hrkq.monthottimevo.hrkq.util;
 
 
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 
 import nc.md.persist.framework.IMDPersistenceQueryService;
@@ -194,7 +196,7 @@ public class CommonUtil {
                   continue; // 前台如果是旧数据修改不能再跟自己比较
               }
               
-              if(J_S == null || J_E == null) {
+              if(J_S == null || J_E == null || I_S == null || I_E == null) {
             	  continue;
               }
               
@@ -212,6 +214,68 @@ public class CommonUtil {
       return res;
   }
   
+  /**
+   * 按次
+   * @Param:
+   * @Description: list自身查询有无时间冲突,
+   * 优化1: 如果自身的list过大, j遍历不能从0开始,只需要往后面数据比较大小
+   * @Author: zyf    2019/3/29
+   */
+  public static String checkSelfTimes(MonthOtTimeBVO[] list) {
+      String res = null;
+      if (list.length == 0) {
+          return res;
+      }
+      List<String> keys = new ArrayList();
+      for (int i = 0; i < list.length; i++) {
+    	  Object otdate = list[i].getAttributeValue(MonthOtTimeBVO.OTDATE);
+    	  String ottimestype = (String) list[i].getAttributeValue(MonthOtTimeBVO.OTTIMESTYPE);
+    	  if(otdate != null) {
+	    	  String key = dateToStr((UFDate)otdate) + ottimestype;
+	    	  if(keys.contains(key)) {
+	    		  res = (res == null ? "" : res) + dateToStr((UFDate)otdate) + " ";
+	    		  continue;
+	    	  }
+	    	  keys.add(key);
+    	  }
+      }
+      return res;
+  }
+  
+  /**
+   * 按次
+   * @Param: listNew 前端传的list
+   * @Param: listOld 数据库list,
+   * 优化2*****后端查询数据库可以根据前端的list里面最大时间和最小时间区间作为条件查询出来
+   * @Description: 比较前端传的list跟数据库list有无时间冲突
+   * @Author: zyf    2019/3/29
+   */
+  public static String checkTwoListTimes(MonthOtTimeBVO[] listNew, MonthOtTimeBVO[] listOld) {
+      String res = null;  //没有冲突返回null,有冲突返回冲突的时间段
+      List<String> keys = new ArrayList();
+      for (int i = 0; i < listOld.length; i++) {
+    	  Object otdate = listOld[i].getAttributeValue(MonthOtTimeBVO.OTDATE);
+    	  String ottimestype = (String) listOld[i].getAttributeValue(MonthOtTimeBVO.OTTIMESTYPE);
+    	  if(otdate != null) {
+	    	  String key = dateToStr((UFDate)otdate) + ottimestype;
+	    	  keys.add(dateToStr((UFDate)otdate) + ottimestype);
+    	  }
+      }
+      for (int i = 0; i < listNew.length; i++) {
+    	  Object otdate = listNew[i].getAttributeValue(MonthOtTimeBVO.OTDATE);
+    	  String ottimestype = (String) listNew[i].getAttributeValue(MonthOtTimeBVO.OTTIMESTYPE);
+    	  if(otdate != null) {
+    		  String key = dateToStr((UFDate)otdate) + ottimestype;
+    		  if(keys.contains(key)) {
+    			  res = (res == null ? "" : res) + dateToStr((UFDate)otdate) + " ";
+    			  continue;
+    		  }
+    		  keys.add(key);
+    	  }
+      }
+      return res;
+  }
+  
   public static final String DATE_FORMAT_Y_M_DHM = "yyyy-MM-dd HH:mm:ss";
   public static String dateToStr(UFDateTime date) {
       String strDate = "";
@@ -219,4 +283,12 @@ public class CommonUtil {
       strDate = sdf.format(date.getDate().toDate());
       return strDate;
   }
+  
+  public static final String DATE_FORMAT_Y_M_D = "yyyy-MM-dd";
+  public static String dateToStr(UFDate date) {
+      String strDate = "";
+      SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_Y_M_D);
+      strDate = sdf.format(date.toDate());
+      return strDate;
+  }
 }

+ 438 - 0
hrkq/hrkq/src/private/nccloud/impl/hrkq/diwork/HRKQQuerySerivceImpl.java

@@ -0,0 +1,438 @@
+package nccloud.impl.hrkq.diwork;
+
+import nc.bs.framework.common.NCLocator;
+import nc.bs.logging.Logger;
+import nc.hr.utils.InSQLCreator;
+import nc.hr.utils.ResHelper;
+import nc.hr.utils.StringPiecer;
+import nc.itf.hr.frame.IPersistenceRetrieve;
+import nc.itf.hr.org.IPrimaryOrgQry;
+import nc.itf.org.IOrgConst;
+import nc.itf.uap.IUAPQueryBS;
+import nc.vo.org.DeptVO;
+import nc.vo.org.OrgVO;
+import nc.vo.pub.BusinessException;
+import nc.vo.pub.SuperVO;
+import nccloud.commons.collections.CollectionUtils;
+import nccloud.commons.lang.StringUtils;
+import nccloud.itf.hrkq.IHRKQQueryService;
+import nccloud.pub.hrkq.util.IAttendCommonUtil;
+import nccloud.pub.hrkq.util.StringListProcessor;
+import nccloud.pubitf.baseapp.apprbac.IAppAndOrgPermQueryPubService;
+import nccloud.vo.hrkq.attendance.AttendanceVO;
+import nccloud.vo.hrkq.leave.LeaveVO;
+import nccloud.vo.hrkq.leaveoff.LeaveoffVO;
+import nccloud.vo.hrkq.outside.OutSideVO;
+import nccloud.vo.hrkq.overtime.OverTimeVO;
+import nccloud.vo.hrkq.trip.TripVO;
+import nccloud.vo.hrkq.tripoff.TripoffVO;
+import org.apache.commons.lang3.ArrayUtils;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class HRKQQuerySerivceImpl implements IHRKQQueryService {
+
+    @Override
+    public List<String> queryPsnBillList(String billType, String order, String beginDate, String endDate,
+                                         String pkPsndoc, String pkGroup, String userId, String appCode) throws BusinessException {
+        // 定义查询条件
+        StringBuffer where = new StringBuffer(" where 1=1 ");
+        if (StringUtils.isNotEmpty(beginDate) || StringUtils.isNotEmpty(endDate)) {
+            String dateSql = getDateFilterSql(billType, beginDate, endDate);
+            if (StringUtils.isNotBlank(dateSql)) {
+                where.append(dateSql);
+            }
+        }
+        where.append(" and pk_psndoc ='" + pkPsndoc + "' ");
+        return doQueryBillList(billType, where.toString(), order, pkGroup, userId, appCode);
+    }
+
+    @Override
+    public List<String> queryDeptBillList(String billType, String order, String beginDate, String endDate,
+                                          String pkDept, String psnName, String jobId, String pkGroup, String userId, String appCode, boolean isIncludeSub) throws BusinessException {
+        StringBuffer where = genQuerySql(billType, beginDate, endDate, psnName, pkDept, jobId, isIncludeSub, getPowerDeptMap(userId, pkGroup, appCode));
+        return doQueryBillList(billType, where.toString(), order, pkGroup, userId, appCode);
+    }
+
+    @Override
+    public List<String> queryAdminBillList(String billType, String order, String beginDate, String endDate,
+                                           String pkDept, String tempWhere, String pkGroup, String userId, String appCode) throws BusinessException {
+        StringBuffer where = genQuerySql(billType, beginDate, endDate, null, pkDept, null, false, getPowerDeptMap(userId, pkGroup, appCode));
+        // 权限组织条件
+        String[] powerOrgIds = queryPowerOrgList(userId, pkGroup, appCode);
+        if (ArrayUtils.isEmpty(powerOrgIds)) {
+            return Collections.emptyList();
+        }
+        InSQLCreator inSqlCreator = new InSQLCreator();
+
+        String strInSQL = inSqlCreator.getInSQL(powerOrgIds);
+
+        where.append(" and pk_org in (" + strInSQL + ")");
+
+        if (StringUtils.isNotBlank(tempWhere)) {
+            where.append(" and " + tempWhere);
+        }
+        return doQueryBillList(billType, where.toString(), order, pkGroup, userId, appCode);
+    }
+
+    private StringBuffer genQuerySql(String billType, String beginDate, String endDate, String psnName, String pkDept,
+                                     String jobId, boolean isIncludeSub, Map<String, String> deptMap) {
+        // 在职条件过滤
+        StringBuffer psnSqlIn = new StringBuffer();
+        psnSqlIn.append("SELECT ");
+        psnSqlIn.append("DISTINCT job.pk_psndoc ");
+        psnSqlIn.append("FROM ");
+        psnSqlIn.append("hi_psnjob job INNER JOIN BD_PSNDOC doc ON job.pk_psndoc = doc.pk_psndoc ");
+        psnSqlIn.append("WHERE ");
+        // 主任职
+        psnSqlIn.append("job.ISMAINJOB = 'Y' ");
+        // 生效记录
+        psnSqlIn.append("AND job.lastflag = 'Y' ");
+        // 职务过滤
+        if (StringUtils.isNotBlank(jobId)) {
+            String[] jobArray = jobId.split(",");
+            InSQLCreator creator = new InSQLCreator();
+            try {
+                String jobInSql = creator.getInSQL(jobArray);
+                psnSqlIn.append(" AND job.PK_JOB in (" + jobInSql + ") ");
+            } catch (nc.vo.pub.BusinessException e) {
+                Logger.error(e.getMessage(), e);
+                throw new RuntimeException(ResHelper.getString("6020hrkq", "6020hrkq00023")
+                        /*@res "职务查询异常" */);
+            }
+        }
+
+        // 定义查询条件
+        StringBuffer where = new StringBuffer(" where 1=1 ");
+        if (StringUtils.isNotEmpty(beginDate) || StringUtils.isNotEmpty(endDate)) {
+            String dateSql = getDateFilterSql(billType, beginDate, endDate);
+            if (StringUtils.isNotBlank(dateSql)) {
+                where.append(dateSql);
+            }
+        }
+        // 人员姓名模糊条件
+        if (StringUtils.isNotBlank(psnName)) {
+            // 姓名模糊检索
+            psnSqlIn.append("AND doc.name LIKE '%" + psnName + "%' ");
+        }
+        where.append(" and pk_psndoc in (" + psnSqlIn.toString() + ")");
+        // 部门过滤
+        if (StringUtils.isNotBlank(pkDept)) {
+            if (isIncludeSub) {
+                String strInSql = getChildrenDeptById(pkDept, deptMap);
+                if (StringUtils.isNotEmpty(strInSql)) {
+                    if (strInSql.startsWith("(")) {
+                        where.append(" and pk_dept in " + strInSql);
+                    } else {
+                        where.append(" and pk_dept in (" + strInSql + ")");
+                    }
+                }
+            } else {
+                if (!deptMap.isEmpty() && deptMap.containsKey(pkDept)) {
+                    where.append(" and pk_dept = '" + pkDept + "'");
+                } else {
+                    where.append(" and pk_dept = '#####'");
+                }
+            }
+        } else if (deptMap != null && deptMap.size() > 0) {
+            String[] powerDept = deptMap.keySet().toArray(new String[deptMap.size()]);
+            InSQLCreator creator = new InSQLCreator();
+            try {
+                String inSQL = creator.getInSQL(powerDept);
+                where.append(" AND pk_dept in (" + inSQL + ") ");
+            } catch (nc.vo.pub.BusinessException e) {
+                Logger.error(e.getMessage(), e);
+                throw new RuntimeException(ResHelper.getString("6020hrkq", "6020hrkq00014")
+                        /*@res "查询有权限部门异常" */);
+            }
+        }
+        return where;
+    }
+
+    /**
+     * 根据开始日期结束日期生成sql片段 因为每个单据的日期字段不一样,所以这样处理
+     *
+     * @param billType
+     * @param beginDate
+     * @param endDate
+     * @return
+     */
+    private static String getDateFilterSql(String billType, String beginDate, String endDate) {
+        StringBuffer dateSql = new StringBuffer();
+        String beginDateField = "";
+        String endDateField = "";
+        switch (billType) {
+            case IAttendCommonUtil.BILL_TYPE_LEAVE:
+                beginDateField = LeaveVO.BEGINTIME;
+                endDateField = LeaveVO.ENDTIME;
+                break;
+
+            case IAttendCommonUtil.BILL_TYPE_ATTENDANCE:
+                beginDateField = AttendanceVO.FILL_DATE;
+                break;
+
+            case IAttendCommonUtil.BILL_TYPE_TRIPOFF:
+                beginDateField = TripoffVO.TRIPOFFBEGINTIME;
+                endDateField = TripoffVO.TRIPOFFENDTIME;
+                break;
+
+            case IAttendCommonUtil.BILL_TYPE_LEAVEOFF:
+                beginDateField = LeaveoffVO.LEAVEOFFBEGINTIME;
+                endDateField = LeaveoffVO.LEAVEOFFENDTIME;
+                break;
+
+            case IAttendCommonUtil.BILL_TYPE_OUTSIDE:
+                beginDateField = OutSideVO.SIGNDATE;
+                break;
+
+            case IAttendCommonUtil.BILL_TYPE_OVERTIME:
+                beginDateField = OverTimeVO.OVERTIMEBEGINTIME;
+                endDateField = OverTimeVO.OVERTIMEENDTIME;
+                break;
+            case IAttendCommonUtil.BILL_TYPE_TRIP:
+                beginDateField = TripVO.TRIPBEGINTIME;
+                endDateField = TripVO.TRIPENDTIME;
+                break;
+
+            default:
+                break;
+        }
+        dateSql.append(" and ( ");
+        if (StringUtils.isNotEmpty(beginDateField)) {
+            dateSql.append("( ");
+            if (StringUtils.isNotBlank(beginDate)) {
+                dateSql.append(beginDateField + " >= '" + beginDate + " 00:00:00' ");
+            }
+            if (StringUtils.isNotBlank(endDate)) {
+                dateSql.append(" and " + beginDateField + " <= '" + endDate + " 23:59:59' ");
+            }
+            dateSql.append(") ");
+        }
+        if (StringUtils.isNotEmpty(endDateField)) {
+            dateSql.append("or ( ");
+            if (StringUtils.isNotBlank(beginDate)) {
+                dateSql.append(endDateField + " >= '" + beginDate + " 00:00:00' ");
+            }
+            if (StringUtils.isNotBlank(endDate)) {
+                dateSql.append(" and " + endDateField + " <= '" + endDate + " 23:59:59' ");
+            }
+            dateSql.append(") ");
+        }
+        if (StringUtils.isNotEmpty(beginDateField) && StringUtils.isNotEmpty(endDateField)) {
+            dateSql.append("or (");
+            if (StringUtils.isNotBlank(beginDate)) {
+                dateSql.append(beginDateField + " <= '" + beginDate + " 00:00:00' ");
+            }
+            if (StringUtils.isNotBlank(endDate)) {
+                dateSql.append(" and " + endDateField + " >= '" + endDate + " 23:59:59' ");
+            }
+            dateSql.append(") ");
+        }
+        dateSql.append(")");
+        return dateSql.toString();
+    }
+
+    /**
+     * 查询hr组织
+     *
+     * @return String[]
+     * @throws BusinessException BusinessException
+     */
+    @SuppressWarnings("unchecked")
+    private String[] queryOrgList() throws BusinessException {
+        String sql = "select pk_adminorg from org_adminorg";
+        List<String> orgList = (List<String>) NCLocator.getInstance().lookup(IUAPQueryBS.class).executeQuery(sql,
+                new StringListProcessor());
+        if (CollectionUtils.isEmpty(orgList)) {
+            return null;
+        }
+        String[] pkOrgs = orgList.toArray(new String[0]);
+        // 行政组织
+        OrgVO[] orgVOs = NCLocator.getInstance().lookup(IPrimaryOrgQry.class)
+                .queryPrimaryOrgVOs(IPrimaryOrgQry.CONTROLTYPE_ADMINORG, pkOrgs);
+
+        return StringPiecer.getStrArray(orgVOs, OrgVO.PK_ORG);
+    }
+
+
+    /**
+     * 查询有权限的组织
+     *
+     * @param userId userId
+     * @param pkGroup pkGroup
+     * @param appCode appCode
+     * @return String[]
+     */
+    private String[] queryPowerOrgList(String userId, String pkGroup, String appCode) {
+        try {
+            String[] orgIds = NCLocator.getInstance().lookup(IAppAndOrgPermQueryPubService.class).queryUserPermOrgPksByAppAndWithOrgTypesFilter(userId,appCode,new String[]{IOrgConst.ADMINORGTYPE},pkGroup);
+            if (orgIds == null || orgIds.length == 0) {
+                return null;
+            }
+            InSQLCreator isc = new InSQLCreator();
+            String strInSql = isc.getInSQL(orgIds);
+            String sql = null;
+            if(strInSql.startsWith("(")) {
+                sql = "(select org_adminorg.pk_adminorg from org_adminorg inner join org_admin_enable on org_adminorg.pk_adminorg=org_admin_enable.pk_adminorg where org_adminorg.enablestate = 2 and org_adminorg.islastversion = 'Y' and org_adminorg.dr = 0 and org_adminorg.pk_adminorg in "+ strInSql + ")";
+            } else {
+                sql = "(select org_adminorg.pk_adminorg from org_adminorg inner join org_admin_enable on org_adminorg.pk_adminorg=org_admin_enable.pk_adminorg where org_adminorg.enablestate = 2 and org_adminorg.islastversion = 'Y' and org_adminorg.dr = 0 and org_adminorg.pk_adminorg in ("+ strInSql + "))";
+            }
+            List<String> powerOrgIds = (List<String>) NCLocator.getInstance().lookup(IUAPQueryBS.class).executeQuery(sql,
+                    new StringListProcessor());
+            if(CollectionUtils.isEmpty(powerOrgIds)) {
+                return null;
+            }
+            return powerOrgIds.toArray(new String[0]);
+        } catch (BusinessException e) {
+            Logger.error(e.getMessage(), e);
+        }
+        return null;
+    }
+
+
+    @SuppressWarnings({"unchecked", "deprecation"})
+    private List<String> doQueryBillList(String billType, String where, String order, String pkGroup, String userId, String appCode) throws BusinessException {
+        // 按排序查询所有数据的pk
+        StringBuffer sqlAll = new StringBuffer(" select ");
+        SuperVO superVO = IAttendCommonUtil.beanMap.get(billType);
+        String pkFieldName = superVO.getPKFieldName();
+        String tableName = superVO.getTableName();
+        sqlAll.append(pkFieldName + " ");
+        sqlAll.append(" from ");
+        sqlAll.append(tableName + " ");
+        sqlAll.append(where);
+        if (StringUtils.isNotBlank(pkGroup)) {
+            sqlAll.append(" and pk_group = '" + pkGroup + "'");
+        }
+        if (StringUtils.isNotBlank(order)) {
+            sqlAll.append(" order by " + order);
+        }
+        Logger.error("sqlAll:" + sqlAll);
+        return (List<String>) NCLocator.getInstance().lookup(IUAPQueryBS.class).executeQuery(sqlAll.toString(),
+                new StringListProcessor());
+    }
+
+
+    /**
+     * 获取当前登录人有权限的部门
+     *
+     * @param userId  用户
+     * @param PkGroup 集团
+     * @param appCode appCode
+     * @return 返回sql
+     * @throws BusinessException
+     */
+    private String getPowerDeptCondition(String userId, String PkGroup, String appCode) throws BusinessException {
+        IAppAndOrgPermQueryPubService service = NCLocator.getInstance().lookup(IAppAndOrgPermQueryPubService.class);
+
+        String[] deptIds = service.queryUserPermOrgPksByAppAndWithOrgTypesFilter(userId, appCode, new String[]{IOrgConst.DEPTORGTYPE}, PkGroup);
+        if (deptIds == null || deptIds.length == 0) {
+            return null;
+        }
+        InSQLCreator isc = new InSQLCreator();
+        String strInSql = null;
+        try {
+            strInSql = isc.getInSQL(deptIds);
+        } catch (BusinessException e) {
+            Logger.error(e.getMessage(), e);
+            throw new RuntimeException(ResHelper.getString("6020hrkq", "6020hrkq00014")
+                    /*@res "查询有权限部门异常!" */);
+        }
+        if (strInSql.startsWith("(")) {
+            return "(select org_dept.pk_dept from org_dept inner join org_admin_enable on org_dept.pk_org=org_admin_enable.pk_adminorg where org_dept.hrcanceled<>'Y' and org_dept.pk_dept in " + strInSql + ")";
+        } else {
+            return "(select org_dept.pk_dept from org_dept inner join org_admin_enable on org_dept.pk_org=org_admin_enable.pk_adminorg where org_dept.hrcanceled<>'Y' and org_dept.pk_dept in (" + strInSql + "))";
+        }
+    }
+
+
+    /**
+     * 获取有权限部门map
+     *
+     * @param userId  userId
+     * @param PkGroup pkGroup
+     * @param appCode appCode
+     * @return map
+     * @throws BusinessException BusinessException
+     */
+    private Map<String, String> getPowerDeptMap(String userId, String PkGroup, String appCode) throws BusinessException {
+        IAppAndOrgPermQueryPubService service = NCLocator.getInstance().lookup(IAppAndOrgPermQueryPubService.class);
+
+        String[] deptIds = service.queryUserPermOrgPksByAppAndWithOrgTypesFilter(userId, appCode, new String[]{IOrgConst.DEPTORGTYPE}, PkGroup);
+        if (deptIds == null || deptIds.length == 0) {
+            return null;
+        }
+        InSQLCreator isc = new InSQLCreator();
+        String strInSql = null;
+        try {
+            strInSql = isc.getInSQL(deptIds);
+        } catch (BusinessException e) {
+            Logger.error(e.getMessage(), e);
+            throw new RuntimeException(ResHelper.getString("6020hrkq", "6020hrkq00014")
+                    /*@res "查询有权限部门异常!" */);
+        }
+        String sql;
+        if (strInSql.startsWith("(")) {
+            sql = "(select org_dept.pk_dept from org_dept inner join org_admin_enable on org_dept.pk_org=org_admin_enable.pk_adminorg where org_dept.hrcanceled<>'Y' and org_dept.pk_dept in " + strInSql + ")";
+        } else {
+            sql = "(select org_dept.pk_dept from org_dept inner join org_admin_enable on org_dept.pk_org=org_admin_enable.pk_adminorg where org_dept.hrcanceled<>'Y' and org_dept.pk_dept in (" + strInSql + "))";
+        }
+        List<String> powerDeptIds = (List<String>) NCLocator.getInstance().lookup(IUAPQueryBS.class).executeQuery(sql,
+                new StringListProcessor());
+        Map<String, String> deptMap = new HashMap<>();
+        for (String powerDeptId : powerDeptIds) {
+            if (!deptMap.containsKey(powerDeptId)) {
+                deptMap.put(powerDeptId, "1");
+            }
+        }
+        if (deptMap.isEmpty()) {
+            return null;
+        }
+        return deptMap;
+    }
+
+
+    /**
+     * 查询部门的下级部门
+     *
+     * @param pkDept 部门id
+     * @return string
+     */
+    private String getChildrenDeptById(String pkDept, Map<String, String> deptMap) {
+        IPersistenceRetrieve persistenceRetrieve = NCLocator.getInstance().lookup(IPersistenceRetrieve.class);
+        SuperVO deptVO;
+        String strInSql;
+        try {
+            deptVO = persistenceRetrieve.retrieveByPk(DeptVO.class, pkDept, null);
+            if (deptVO == null) {
+                return null;
+            }
+            // 获取所选部门的innercode
+            String innercode = (String) deptVO.getAttributeValue("innercode");
+            String sql = "select org_dept.pk_dept from org_dept inner join org_admin_enable on org_dept.pk_org=org_admin_enable.pk_adminorg where org_dept.hrcanceled<>'Y' and org_dept.innercode like '" + innercode + "%'";
+            List<String> deptIds = (List<String>) NCLocator.getInstance().lookup(IUAPQueryBS.class).executeQuery(sql,
+                    new StringListProcessor());
+            InSQLCreator isc = new InSQLCreator();
+            if(deptMap.isEmpty()) {
+                strInSql = isc.getInSQL(deptIds.toArray(new String[0]));
+            } else {
+                List<String> ids = new ArrayList<>();
+                for (String deptId : deptIds) {
+                    if (deptMap.containsKey(deptId)) {
+                        ids.add(deptId);
+                    }
+                }
+                strInSql = isc.getInSQL(ids.toArray(new String[0]));
+            }
+        } catch (BusinessException e) {
+            Logger.error(e.getMessage(), e);
+            throw new RuntimeException(ResHelper.getString("6020hrkq", "6020hrkq00039")
+                    /*@res "查询下级部门异常!" */);
+        }
+        return strInSql;
+    }
+}

+ 1 - 1
hrkq/hrkq/src/private/nccloud/impl/hrkq/hrkq/MonthottimevoMaintainImpl.java

@@ -90,7 +90,7 @@ public class MonthottimevoMaintainImpl extends AceAggbusiMonthOtTimeVOPubService
 		public AggMonthOtTimeVO queryByPk(String pk) throws BusinessException {
 			AggMonthOtTimeVO aggvo = MDPersistenceService.lookupPersistenceQueryService().queryBillOfVOByPK(AggMonthOtTimeVO.class, pk, false);
 			if(aggvo != null) {
-				Collection<MonthOtTimeBVO> bbills = MDPersistenceService.lookupPersistenceQueryService().queryBillOfVOByCond(MonthOtTimeBVO.class, "pk_monthottime" + "='" + pk + "'", true,
+				Collection<MonthOtTimeBVO> bbills = MDPersistenceService.lookupPersistenceQueryService().queryBillOfVOByCond(MonthOtTimeBVO.class, "pk_monthottime" + "='" + pk + "' and dr = 0", true,
 		                false);
 				aggvo.setChildrenVO(bbills.toArray(new MonthOtTimeBVO[0]));
 			}