Prechádzať zdrojové kódy

'增加分页查询会议室'

o2wwx 5 rokov pred
rodič
commit
2d37231412

+ 147 - 0
o2server/x_meeting_assemble_control/src/main/java/com/x/meeting/assemble/control/jaxrs/meeting/ActionPaging.java

@@ -0,0 +1,147 @@
+package com.x.meeting.assemble.control.jaxrs.meeting;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.TypedQuery;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+
+import org.apache.commons.lang3.StringUtils;
+
+import com.google.gson.JsonElement;
+import com.x.base.core.container.EntityManagerContainer;
+import com.x.base.core.container.factory.EntityManagerContainerFactory;
+import com.x.base.core.entity.JpaObject;
+import com.x.base.core.project.annotation.FieldDescribe;
+import com.x.base.core.project.bean.WrapCopier;
+import com.x.base.core.project.bean.WrapCopierFactory;
+import com.x.base.core.project.http.ActionResult;
+import com.x.base.core.project.http.EffectivePerson;
+import com.x.base.core.project.logger.Logger;
+import com.x.base.core.project.logger.LoggerFactory;
+import com.x.base.core.project.tools.SortTools;
+import com.x.meeting.assemble.control.Business;
+import com.x.meeting.assemble.control.WrapTools;
+import com.x.meeting.assemble.control.wrapout.WrapOutMeeting;
+import com.x.meeting.core.entity.Meeting;
+import com.x.meeting.core.entity.Meeting_;
+
+class ActionPaging extends BaseAction {
+	Logger logger = LoggerFactory.getLogger(ActionPaging.class);
+	
+	ActionResult<List<Wo>> execute(EffectivePerson effectivePerson,Integer page , Integer size, JsonElement jsonElement) throws Exception {
+		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+			ActionResult<List<Wo>> result = new ActionResult<>();
+			Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
+			
+			Business business = new Business(emc);
+			List<String> ids = new ArrayList<>();
+			
+			EntityManager em = emc.get(Meeting.class);
+			CriteriaBuilder cb = em.getCriteriaBuilder();
+			
+			CriteriaQuery<String> cq = cb.createQuery(String.class);
+			Root<Meeting> root = cq.from(Meeting.class);
+			
+			Predicate p = cb.equal(root.get(Meeting_.applicant), effectivePerson.getDistinguishedName());
+			
+			if(!StringUtils.isBlank(wi.getRoom())) {
+				p = cb.and(p, cb.equal(root.get(Meeting_.room), wi.getRoom()));
+			}
+		   
+			if(wi.getStartTime() != null) {
+			   p = cb.and(p, cb.greaterThanOrEqualTo(root.get(Meeting_.startTime), wi.getStartTime()));
+			}
+			
+			if(wi.getCompletedTime()!= null) {
+			   p = cb.and(p, cb.lessThanOrEqualTo(root.get(Meeting_.completedTime), wi.getCompletedTime()));
+			}
+			
+			if(!StringUtils.isBlank(wi.getConfirmStatus())) {
+		    	p = cb.and(p, cb.equal(root.get(Meeting_.confirmStatus), wi.getConfirmStatus()));
+			}
+			
+			cq.select(root.get(Meeting_.id)).where(p);
+			
+			 TypedQuery<String> typedQuery = em.createQuery(cq);
+			    //设置分页
+			 int pageIndex = (page-1)*size;
+			 int pageSize = page*size;
+			 typedQuery.setFirstResult(pageIndex);
+			 typedQuery.setMaxResults(pageSize);
+			    
+			 //logger.info("typedQuery="+  typedQuery.toString()); 
+			 ids =  typedQuery.getResultList();
+			
+			List<Wo> wos = Wo.copier.copy(emc.list(Meeting.class, ids));
+			WrapTools.decorate(business, wos, effectivePerson);
+			WrapTools.setAttachment(business, wos);
+			SortTools.desc(wos, Meeting.startTime_FIELDNAME);
+			result.setData(wos);
+			return result;
+		}
+	}
+
+
+	
+	public static class Wo extends WrapOutMeeting {
+		private static final long serialVersionUID = 4609263020989488356L;
+		public static WrapCopier<Meeting, Wo> copier = WrapCopierFactory.wo(Meeting.class, Wo.class, null,
+				JpaObject.FieldsInvisible);
+	}
+
+    public static class Wi  {
+    	
+		@FieldDescribe("所属楼层.")
+		private String room;
+		
+		@FieldDescribe("开始时间.")
+		private Date startTime;
+		
+		@FieldDescribe("结束时间.")
+		private Date completedTime;
+		
+		@FieldDescribe("会议状态.(wait|processing|completed)")
+		private String confirmStatus;
+		
+
+
+		public String getConfirmStatus() {
+			return confirmStatus;
+		}
+
+		public void setConfirmStatus(String confirmStatus) {
+			this.confirmStatus = confirmStatus;
+		}
+
+		public String getRoom() {
+			return room;
+		}
+
+		public void setRoom(String room) {
+			this.room = room;
+		}
+
+		public Date getStartTime() {
+			return startTime;
+		}
+
+		public void setStartTime(Date startTime) {
+			this.startTime = startTime;
+		}
+
+		public Date getCompletedTime() {
+			return completedTime;
+		}
+
+		public void setCompletedTime(Date completedTime) {
+			this.completedTime = completedTime;
+		}
+			
+	}
+}

+ 161 - 0
o2server/x_meeting_assemble_control/src/main/java/com/x/meeting/assemble/control/jaxrs/meeting/ActionPagingManage.java

@@ -0,0 +1,161 @@
+package com.x.meeting.assemble.control.jaxrs.meeting;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.TypedQuery;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+
+import org.apache.commons.lang3.StringUtils;
+
+import com.google.gson.JsonElement;
+import com.x.base.core.container.EntityManagerContainer;
+import com.x.base.core.container.factory.EntityManagerContainerFactory;
+import com.x.base.core.entity.JpaObject;
+import com.x.base.core.project.annotation.FieldDescribe;
+import com.x.base.core.project.bean.WrapCopier;
+import com.x.base.core.project.bean.WrapCopierFactory;
+import com.x.base.core.project.http.ActionResult;
+import com.x.base.core.project.http.EffectivePerson;
+import com.x.base.core.project.logger.Logger;
+import com.x.base.core.project.logger.LoggerFactory;
+import com.x.base.core.project.tools.SortTools;
+import com.x.meeting.assemble.control.Business;
+import com.x.meeting.assemble.control.WrapTools;
+import com.x.meeting.assemble.control.wrapout.WrapOutMeeting;
+import com.x.meeting.core.entity.Meeting;
+import com.x.meeting.core.entity.Meeting_;
+
+class ActionPagingManage extends BaseAction {
+	Logger logger = LoggerFactory.getLogger(ActionPagingManage.class);
+	
+	ActionResult<List<Wo>> execute(EffectivePerson effectivePerson,Integer page , Integer size, JsonElement jsonElement) throws Exception {
+		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+			ActionResult<List<Wo>> result = new ActionResult<>();
+			Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
+			
+			Business business = new Business(emc);
+			List<String> ids = new ArrayList<>();
+			
+			EntityManager em = emc.get(Meeting.class);
+			CriteriaBuilder cb = em.getCriteriaBuilder();
+			
+			CriteriaQuery<String> cq = cb.createQuery(String.class);
+			Root<Meeting> root = cq.from(Meeting.class);
+			
+			if (StringUtils.isBlank(wi.getDistinguishedName())) {
+				throw new ExceptionDistinguishedNameEmpty();
+			}
+			
+			Predicate p = cb.equal(root.get(Meeting_.applicant), wi.getDistinguishedName());
+			
+			if(!StringUtils.isBlank(wi.getRoom())) {
+				p = cb.and(p, cb.equal(root.get(Meeting_.room), wi.getRoom()));
+			}
+		
+			if(wi.getStartTime()!=null) {
+			   p = cb.and(p, cb.greaterThanOrEqualTo(root.get(Meeting_.startTime), wi.getStartTime()));
+			}
+			
+			if(wi.getCompletedTime()!=null) {
+			   p = cb.and(p, cb.lessThanOrEqualTo(root.get(Meeting_.completedTime), wi.getCompletedTime()));
+			}
+			
+			if(!StringUtils.isBlank(wi.getConfirmStatus())) {
+		    	p = cb.and(p, cb.equal(root.get(Meeting_.confirmStatus), wi.getConfirmStatus()));
+			}
+			
+			cq.select(root.get(Meeting_.id)).where(p);
+			
+			 TypedQuery<String> typedQuery = em.createQuery(cq);
+			    //设置分页
+			 int pageIndex = (page-1)*size;
+			 int pageSize = page*size;
+			 typedQuery.setFirstResult(pageIndex);
+			 typedQuery.setMaxResults(pageSize);
+			    
+			// logger.info("typedQuery="+  typedQuery.toString()); 
+			 ids =  typedQuery.getResultList();
+		
+			List<Wo> wos = Wo.copier.copy(emc.list(Meeting.class, ids));
+			WrapTools.decorate(business, wos, effectivePerson);
+			WrapTools.setAttachment(business, wos);
+			SortTools.desc(wos, Meeting.startTime_FIELDNAME);
+			result.setData(wos);
+			return result;
+		}
+	}
+
+
+	
+	public static class Wo extends WrapOutMeeting {
+		private static final long serialVersionUID = 4609263020989488356L;
+		public static WrapCopier<Meeting, Wo> copier = WrapCopierFactory.wo(Meeting.class, Wo.class, null,
+				JpaObject.FieldsInvisible);
+	}
+
+    public static class Wi  {
+    	
+    	@FieldDescribe("用户的全称")
+    	private String distinguishedName;
+    	
+		@FieldDescribe("所属楼层.")
+		private String room;
+		
+		@FieldDescribe("开始时间.")
+		private Date startTime;
+		
+		@FieldDescribe("结束时间.")
+		private Date completedTime;
+		
+		@FieldDescribe("会议状态.(wait|processing|completed)")
+		private String confirmStatus;
+		
+
+		public String getDistinguishedName() {
+			return distinguishedName;
+		}
+
+		public void setDistinguishedName(String distinguishedName) {
+			this.distinguishedName = distinguishedName;
+		}
+
+		public String getConfirmStatus() {
+			return confirmStatus;
+		}
+
+		public void setConfirmStatus(String confirmStatus) {
+			this.confirmStatus = confirmStatus;
+		}
+
+		public String getRoom() {
+			return room;
+		}
+
+		public void setRoom(String room) {
+			this.room = room;
+		}
+
+		public Date getStartTime() {
+			return startTime;
+		}
+
+		public void setStartTime(Date startTime) {
+			this.startTime = startTime;
+		}
+
+		public Date getCompletedTime() {
+			return completedTime;
+		}
+
+		public void setCompletedTime(Date completedTime) {
+			this.completedTime = completedTime;
+		}
+			
+	}
+}

+ 12 - 0
o2server/x_meeting_assemble_control/src/main/java/com/x/meeting/assemble/control/jaxrs/meeting/ExceptionDistinguishedNameEmpty.java

@@ -0,0 +1,12 @@
+package com.x.meeting.assemble.control.jaxrs.meeting;
+
+import com.x.base.core.project.exception.PromptException;
+
+class ExceptionDistinguishedNameEmpty extends PromptException {
+
+	private static final long serialVersionUID = 4132300948670472899L;
+
+	ExceptionDistinguishedNameEmpty() {
+		super("DistinguishedName is empty.");
+	}
+}

+ 36 - 0
o2server/x_meeting_assemble_control/src/main/java/com/x/meeting/assemble/control/jaxrs/meeting/MeetingAction.java

@@ -320,6 +320,42 @@ public class MeetingAction extends BaseAction {
 		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
 	}
 
+	@JaxrsMethodDescribe(value = "普通用户,分页列示Meeing对象", action = ActionPaging.class)
+	@POST
+	@Path("list/{page}/size/{size}")
+	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
+	@Consumes(MediaType.APPLICATION_JSON)
+	public void listMeetingPaging(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
+			@PathParam("page") Integer page , @PathParam("size") Integer size, JsonElement jsonElement) {
+		ActionResult<List<ActionPaging.Wo>> result = new ActionResult<>();
+		EffectivePerson effectivePerson = this.effectivePerson(request);
+		try {
+			result = new ActionPaging().execute(effectivePerson, page, size, jsonElement);
+		} catch (Exception e) {
+			logger.error(e, effectivePerson, request, null);
+			result.error(e);
+		}
+		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
+	}
+	
+	@JaxrsMethodDescribe(value = "管理员,分页列示Meeing对象", action = ActionPagingManage.class)
+	@POST
+	@Path("list/{page}/size/{size}/manage")
+	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
+	@Consumes(MediaType.APPLICATION_JSON)
+	public void listMeetingPagingManage(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
+			@PathParam("page") Integer page , @PathParam("size") Integer size , JsonElement jsonElement) {
+		ActionResult<List<ActionPagingManage.Wo>> result = new ActionResult<>();
+		EffectivePerson effectivePerson = this.effectivePerson(request);
+		try {
+			result = new ActionPagingManage().execute(effectivePerson, page, size, jsonElement);
+		} catch (Exception e) {
+			logger.error(e, effectivePerson, request, null);
+			result.error(e);
+		}
+		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
+	}
+	
 	@JaxrsMethodDescribe(value = "列示我参与从当前日期开始指定月份范围的会议,或者被邀请,或者是申请人,或者是审核人,管理员可以看到所有.", action = ActionListComingMonth.class)
 	@GET
 	@Path("list/coming/month/{count}")