Просмотр исходного кода

考勤,修复申诉审批权限问题。

luojing 5 лет назад
Родитель
Сommit
eb64760e67

+ 65 - 0
o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/Business.java

@@ -2,7 +2,12 @@ package com.x.attendance.assemble.control;
 
 import com.x.attendance.assemble.control.factory.*;
 import com.x.base.core.container.EntityManagerContainer;
+import com.x.base.core.project.http.EffectivePerson;
 import com.x.organization.core.express.Organization;
+import org.apache.commons.lang3.StringUtils;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.List;
 
 public class Business {
 
@@ -204,4 +209,64 @@ public class Business {
 		}
 		return attendanceSelfHolidayFactory;
 	}
+
+	/**
+	 * TODO 判断用户是否管理员权限 1、person.isManager() 2、xadmin 3、CRMManager
+	 *
+	 * @param request
+	 * @return
+	 * @throws Exception
+	 */
+	public boolean isManager(HttpServletRequest request, EffectivePerson person) throws Exception {
+		// 如果用户的身份是平台的超级管理员,那么就是超级管理员权限
+		if (person.isManager()) {
+			return true;
+		}
+		if ("xadmin".equalsIgnoreCase(person.getDistinguishedName())) {
+			return true;
+		}
+		if (isHasPlatformRole(person.getDistinguishedName(), ThisApplication.ROLE_AttendanceManager)) {
+			return true;
+		}
+		return false;
+	}
+
+	/**
+	 * TODO 判断用户是否管理员权限 1、person.isManager() 2、xadmin 3、CRMManager
+	 * @return
+	 * @throws Exception
+	 */
+
+	public boolean isManager(EffectivePerson person) throws Exception {
+		// 如果用户的身份是平台的超级管理员,那么就是超级管理员权限
+		if (person.isManager()) {
+			return true;
+		}
+		if ("xadmin".equalsIgnoreCase(person.getDistinguishedName())) {
+			return true;
+		}
+		if (isHasPlatformRole(person.getDistinguishedName(), ThisApplication.ROLE_AttendanceManager)) {
+			return true;
+		}
+		return false;
+	}
+
+	public boolean isHasPlatformRole(String personName, String roleName) throws Exception {
+		if (StringUtils.isEmpty(personName)) {
+			throw new Exception("personName is null!");
+		}
+		if (StringUtils.isEmpty(roleName)) {
+			throw new Exception("roleName is null!");
+		}
+		List<String> roleList = null;
+		roleList = organization().role().listWithPerson(personName);
+		if (roleList != null && !roleList.isEmpty()) {
+			if (roleList.stream().filter(r -> roleName.equalsIgnoreCase(r)).count() > 0) {
+				return true;
+			}
+		} else {
+			return false;
+		}
+		return false;
+	}
 }

+ 2 - 1
o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/ThisApplication.java

@@ -36,6 +36,7 @@ public class ThisApplication {
 
 	public static final QueuePersonAttendanceDetailAnalyse detailAnalyseQueue = new QueuePersonAttendanceDetailAnalyse();
 	public static final QueueAttendanceDetailStatistic detailStatisticQueue = new QueueAttendanceDetailStatistic();
+	public static final String ROLE_AttendanceManager = "AttendanceManager@AttendanceManagerSystemRole@R";
 
 	public static void init() throws Exception {
 		try {
@@ -58,7 +59,7 @@ public class ThisApplication {
 				context.schedule(QywxAttendanceSyncScheduleTask.class, "0 0 1 * * ?");
 			}
 			context.schedule(AttendanceStatisticTask.class, "0 0 0/4 * * ?");
-			context.schedule(MobileRecordAnalyseTask.class, "0 0 * * * ?");
+			//context.schedule(MobileRecordAnalyseTask.class, "0 0 * * * ?");
 			// 每天凌晨1点,计算前一天所有的未签退和未分析的打卡数据
 			context.schedule(DetailLastDayRecordAnalyseTask.class, "0 0 1 * * ?");
 

+ 212 - 2
o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/factory/AttendanceAppealInfoFactory.java

@@ -10,6 +10,7 @@ import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 
+import com.x.attendance.assemble.control.service.UserManagerService;
 import org.apache.commons.lang3.StringUtils;
 
 import com.x.attendance.assemble.control.AbstractFactory;
@@ -311,8 +312,124 @@ public class AttendanceAppealInfoFactory extends AbstractFactory {
 			query.setParameter(i + 1, vs.get(i));
 		}
 		return query.setMaxResults(count).getResultList();
-	}	
-	
+	}
+
+	/**
+	 * 查询下一页的信息数据--只查询当前人有权限审批的
+	 * @param id
+	 * @param count
+	 * @param sequence
+	 * @param wrapIn
+	 * @return
+	 * @throws Exception
+	 */
+	@SuppressWarnings("unchecked")
+	public List<AttendanceAppealInfo> listIdsNextWithFilterWithCurrentProcessor( String id, Integer count, Object sequence, WrapInFilterAppeal wrapIn ,Boolean isManager) throws Exception {
+		//先获取上一页最后一条的sequence值,如果有值的话,以此sequence值作为依据取后续的count条数据
+		EntityManager em = this.entityManagerContainer().get( AttendanceAppealInfo.class );
+		String order = wrapIn.getOrder();//排序方式
+		List<Object> vs = new ArrayList<>();
+		StringBuffer sql_stringBuffer = new StringBuffer();
+		UserManagerService userManagerService = new UserManagerService();
+		if( order == null || order.isEmpty() ){
+			order = "DESC";
+		}
+
+		Integer index = 1;
+		sql_stringBuffer.append( "SELECT o FROM "+AttendanceAppealInfo.class.getCanonicalName()+" o where 1=1" );
+
+		if ((null != sequence) ) {
+			sql_stringBuffer.append(" and o.sequence " + (StringUtils.equalsIgnoreCase(order, "DESC") ? "<" : ">") + (" ?" + (index)));
+			vs.add(sequence);
+			index++;
+		}
+		if ((null != wrapIn.getDetailId()) && (!wrapIn.getDetailId().isEmpty())) {
+			sql_stringBuffer.append(" and o.detailId = ?" + (index));
+			vs.add( wrapIn.getDetailId() );
+			index++;
+		}
+		if ((null != wrapIn.getEmpName()) && (!wrapIn.getEmpName().isEmpty())) {
+			sql_stringBuffer.append(" and o.empName = ?" + (index));
+			vs.add( wrapIn.getEmpName() );
+			index++;
+		}
+		if ((null != wrapIn.getUnitName()) && (!wrapIn.getUnitName().isEmpty())) {
+			sql_stringBuffer.append(" and o.unitName = ?" + (index));
+			vs.add( wrapIn.getUnitName() );
+			index++;
+		}
+		if ((null != wrapIn.getTopUnitName()) && (!wrapIn.getTopUnitName().isEmpty())) {
+			sql_stringBuffer.append(" and o.topUnitName = ?" + (index));
+			vs.add( wrapIn.getTopUnitName() );
+			index++;
+		}
+		if ((null != wrapIn.getYearString() ) && (!wrapIn.getYearString().isEmpty())) {
+			sql_stringBuffer.append(" and o.yearString = ?" + (index));
+			vs.add( wrapIn.getYearString() );
+			index++;
+		}
+		if ((null != wrapIn.getMonthString()) && (!wrapIn.getMonthString().isEmpty())) {
+			sql_stringBuffer.append(" and o.monthString = ?" + (index));
+			vs.add( wrapIn.getMonthString() );
+			index++;
+		}
+		if (wrapIn.getStatus()!=999) {
+			sql_stringBuffer.append(" and o.status = ?" + (index));
+			vs.add( wrapIn.getStatus() );
+			index++;
+		}
+		if ((null != wrapIn.getAppealReason()) && (!wrapIn.getAppealReason().isEmpty())) {
+			sql_stringBuffer.append(" and o.appealReason = ?" + (index));
+			vs.add( wrapIn.getAppealReason() );
+			index++;
+		}
+		if(!isManager){
+			if ((null != wrapIn.getProcessPerson1()) && (!wrapIn.getProcessPerson1().isEmpty())) {
+				sql_stringBuffer.append(" and o.currentProcessor = ?" + (index));
+				vs.add( wrapIn.getProcessPerson1() );
+				index++;
+			}
+		}
+
+//		if ((null != wrapIn.getProcessPerson2()) && (!wrapIn.getProcessPerson2().isEmpty())) {
+//			sql_stringBuffer.append(" and o.processPerson2 = ?" + (index));
+//			vs.add( wrapIn.getProcessPerson2() );
+//			index++;
+//		}
+
+		//添加OR条件
+		if (wrapIn.getOrAtrribute() != null && wrapIn.getOrAtrribute().size() > 0) {
+			sql_stringBuffer.append(" and (");
+			NameValueCountPair nameValueCountPair = null;
+			for (int p = 0; p < wrapIn.getOrAtrribute().size(); p++) {
+				nameValueCountPair = wrapIn.getOrAtrribute().get(p);
+				if (p == 0) {
+					sql_stringBuffer.append(" o." + nameValueCountPair.getName() + " = ?" + (index));
+
+				} else {
+					sql_stringBuffer.append(" or o." + nameValueCountPair.getName() + " = ?" + (index));
+				}
+				vs.add(nameValueCountPair.getValue());
+				index++;
+			}
+			sql_stringBuffer.append(" )");
+		}
+
+		if( StringUtils.isNotEmpty( wrapIn.getKey() )){
+			sql_stringBuffer.append(" order by o."+wrapIn.getKey()+" " + order );
+		}else{
+			sql_stringBuffer.append(" order by o.sequence " + order );
+		}
+
+		Query query = em.createQuery( sql_stringBuffer.toString(), AttendanceAppealInfo.class );
+		//为查询设置所有的参数值
+		for (int i = 0; i < vs.size(); i++) {
+			query.setParameter(i + 1, vs.get(i));
+		}
+		System.out.println("listIdsNextWithFilterWithCurrentProcessor="+query);
+		return query.setMaxResults(count).getResultList();
+	}
+
 	/**
 	 * 查询上一页的文档信息数据
 	 * @param id
@@ -514,4 +631,97 @@ public class AttendanceAppealInfoFactory extends AbstractFactory {
 		}		
 		return (Long) query.getSingleResult();
 	}
+
+	/**
+	 * 查询符合的文档信息总数
+	 * @param wrapIn
+	 * @return
+	 * @throws Exception
+	 */
+	public long getCountWithFilterWithCurrentProcessor( WrapInFilterAppeal wrapIn ,boolean isManager) throws Exception {
+		//先获取上一页最后一条的sequence值,如果有值的话,以此sequence值作为依据取后续的count条数据
+		EntityManager em = this.entityManagerContainer().get( AttendanceAppealInfo.class );
+		List<Object> vs = new ArrayList<>();
+		StringBuffer sql_stringBuffer = new StringBuffer();
+		Integer index = 1;
+
+		sql_stringBuffer.append( "SELECT count(o.id) FROM "+AttendanceAppealInfo.class.getCanonicalName()+" o where 1=1" );
+
+		if ((null != wrapIn.getDetailId()) && (!wrapIn.getDetailId().isEmpty())) {
+			sql_stringBuffer.append(" and o.detailId = ?" + (index));
+			vs.add( wrapIn.getDetailId() );
+			index++;
+		}
+		if ((null != wrapIn.getEmpName()) && (!wrapIn.getEmpName().isEmpty())) {
+			sql_stringBuffer.append(" and o.empName = ?" + (index));
+			vs.add( wrapIn.getEmpName() );
+			index++;
+		}
+		if ((null != wrapIn.getUnitName()) && (!wrapIn.getUnitName().isEmpty())) {
+			sql_stringBuffer.append(" and o.unitName = ?" + (index));
+			vs.add( wrapIn.getUnitName() );
+			index++;
+		}
+		if ((null != wrapIn.getTopUnitName()) && (!wrapIn.getTopUnitName().isEmpty())) {
+			sql_stringBuffer.append(" and o.topUnitName = ?" + (index));
+			vs.add( wrapIn.getTopUnitName() );
+			index++;
+		}
+		if ((null != wrapIn.getYearString() ) && (!wrapIn.getYearString().isEmpty())) {
+			sql_stringBuffer.append(" and o.yearString = ?" + (index));
+			vs.add( wrapIn.getYearString() );
+			index++;
+		}
+		if ((null != wrapIn.getMonthString()) && (!wrapIn.getMonthString().isEmpty())) {
+			sql_stringBuffer.append(" and o.monthString = ?" + (index));
+			vs.add( wrapIn.getMonthString() );
+			index++;
+		}
+		if (wrapIn.getStatus()!=999) {
+			sql_stringBuffer.append(" and o.status = ?" + (index));
+			vs.add( wrapIn.getStatus() );
+			index++;
+		}
+		if ((null != wrapIn.getAppealReason()) && (!wrapIn.getAppealReason().isEmpty())) {
+			sql_stringBuffer.append(" and o.appealReason = ?" + (index));
+			vs.add( wrapIn.getAppealReason() );
+			index++;
+		}
+		if(!isManager){
+			if ((null != wrapIn.getProcessPerson1()) && (!wrapIn.getProcessPerson1().isEmpty())) {
+				sql_stringBuffer.append(" and o.currentProcessor = ?" + (index));
+				vs.add( wrapIn.getProcessPerson1() );
+				index++;
+			}
+		}
+//		if ((null != wrapIn.getProcessPerson2()) && (!wrapIn.getProcessPerson2().isEmpty())) {
+//			sql_stringBuffer.append(" and o.processPerson2 = ?" + (index));
+//			vs.add( wrapIn.getProcessPerson2() );
+//			index++;
+//		}
+		//添加OR
+		if (wrapIn.getOrAtrribute() != null && wrapIn.getOrAtrribute().size() > 0) {
+			sql_stringBuffer.append(" and (");
+			NameValueCountPair nameValueCountPair = null;
+			for (int p = 0; p < wrapIn.getOrAtrribute().size(); p++) {
+				nameValueCountPair = wrapIn.getOrAtrribute().get(p);
+				if (p == 0) {
+					sql_stringBuffer.append(" o." + nameValueCountPair.getName() + " = ?" + (index));
+
+				} else {
+					sql_stringBuffer.append(" or o." + nameValueCountPair.getName() + " = ?" + (index));
+				}
+				vs.add(nameValueCountPair.getValue());
+				index++;
+			}
+			sql_stringBuffer.append(" )");
+		}
+
+		Query query = em.createQuery( sql_stringBuffer.toString(), AttendanceAppealInfo.class );
+		//为查询设置所有的参数值
+		for (int i = 0; i < vs.size(); i++) {
+			query.setParameter(i + 1, vs.get(i));
+		}
+		return (Long) query.getSingleResult();
+	}
 }

+ 7 - 4
o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attendanceappealinfo/ActionListNextWithFilter.java

@@ -37,6 +37,7 @@ public class ActionListNextWithFilter extends BaseAction {
 		List<AttendanceAppealInfo> detailList = null;
 		WrapInFilterAppeal wrapIn = null;
 		Boolean check = true;
+		Boolean isManager = false;
 
 		try {
 			wrapIn = this.convertToWrapIn(jsonElement, WrapInFilterAppeal.class);
@@ -60,11 +61,13 @@ public class ActionListNextWithFilter extends BaseAction {
 						sequence = PropertyUtils.getProperty(emc.find(id, AttendanceAppealInfo.class),  JpaObject.sequence_FIELDNAME);
 					}
 				}
-				// 从数据库中查询符合条件的一页数据对象
-				detailList = business.getAttendanceAppealInfoFactory().listIdsNextWithFilter(id, count, sequence,
-						wrapIn);
+
+				isManager = business.isManager(effectivePerson);
+				// 从数据库中查询符合条件的一页数据对象(根据当前审批人查询)
+				detailList = business.getAttendanceAppealInfoFactory().listIdsNextWithFilterWithCurrentProcessor(id, count, sequence,
+						wrapIn,isManager);
 				// 从数据库中查询符合条件的对象总数
-				total = business.getAttendanceAppealInfoFactory().getCountWithFilter(wrapIn);
+				total = business.getAttendanceAppealInfoFactory().getCountWithFilterWithCurrentProcessor(wrapIn,isManager);
 				// 将所有查询出来的有状态的对象转换为可以输出的过滤过属性的对象
 				wraps = Wo.copier.copy(detailList);