|
|
@@ -4,10 +4,7 @@ import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
import javax.persistence.EntityManager;
|
|
|
-import javax.persistence.criteria.CriteriaBuilder;
|
|
|
-import javax.persistence.criteria.CriteriaQuery;
|
|
|
-import javax.persistence.criteria.Predicate;
|
|
|
-import javax.persistence.criteria.Root;
|
|
|
+import javax.persistence.criteria.*;
|
|
|
|
|
|
import com.x.base.core.container.EntityManagerContainer;
|
|
|
import com.x.base.core.container.factory.EntityManagerContainerFactory;
|
|
|
@@ -21,6 +18,8 @@ import com.x.processplatform.core.entity.content.Work;
|
|
|
import com.x.processplatform.core.entity.content.Work_;
|
|
|
import com.x.processplatform.core.entity.element.Application;
|
|
|
import com.x.processplatform.core.entity.element.Process;
|
|
|
+import org.apache.commons.lang3.BooleanUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
class ActionManageListCountWithProcess extends BaseAction {
|
|
|
|
|
|
@@ -28,28 +27,28 @@ class ActionManageListCountWithProcess extends BaseAction {
|
|
|
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
|
|
|
ActionResult<List<Wo>> result = new ActionResult<>();
|
|
|
Business business = new Business(emc);
|
|
|
- List<Wo> wos = new ArrayList<>();
|
|
|
Application application = business.application().pick(applicationFlag);
|
|
|
if (null == application) {
|
|
|
throw new ExceptionApplicationNotExist(applicationFlag);
|
|
|
}
|
|
|
EntityManager em = business.entityManagerContainer().get(Work.class);
|
|
|
CriteriaBuilder cb = em.getCriteriaBuilder();
|
|
|
- CriteriaQuery<String> cq = cb.createQuery(String.class);
|
|
|
+ CriteriaQuery<Wo> cq = cb.createQuery(Wo.class);
|
|
|
Root<Work> root = cq.from(Work.class);
|
|
|
- Predicate p = cb.equal(root.get(Work_.application), application.getId());
|
|
|
- cq.select(root.get(Work_.process)).where(p).distinct(true);
|
|
|
- List<String> list = em.createQuery(cq).getResultList();
|
|
|
- for (String str : list) {
|
|
|
- Wo wo = new Wo();
|
|
|
- Process process = business.process().pick(str);
|
|
|
- if (null != process) {
|
|
|
- if (business.canManageApplicationOrProcess(effectivePerson, application, process)) {
|
|
|
- wo.setValue(process.getId());
|
|
|
- wo.setName(process.getName());
|
|
|
- wo.setCount(this.countWithProcess(business, process));
|
|
|
- wos.add(wo);
|
|
|
+ Predicate p = cb.equal(root.get(Work_.application), application.getId());
|
|
|
+ Path<String> value = root.get(Work_.process);
|
|
|
+ cq.multiselect(value, cb.count(root).as(Long.class)).where(p).groupBy(value);
|
|
|
+ List<Wo> list = em.createQuery(cq).getResultList();
|
|
|
+ List<Wo> wos = new ArrayList<>();
|
|
|
+ for (Wo wo : list) {
|
|
|
+ Process process = business.process().pick(wo.getValue());
|
|
|
+ if (process != null && business.canManageApplicationOrProcess(effectivePerson, application, process)){
|
|
|
+ String name = process.getName();
|
|
|
+ if (process.getEditionNumber() != null) {
|
|
|
+ name = name + "V" + process.getEditionNumber();
|
|
|
}
|
|
|
+ wo.setName(name);
|
|
|
+ wos.add(wo);
|
|
|
}
|
|
|
}
|
|
|
SortTools.asc(wos, "name");
|
|
|
@@ -60,15 +59,20 @@ class ActionManageListCountWithProcess extends BaseAction {
|
|
|
|
|
|
public static class Wo extends GsonPropertyObject {
|
|
|
|
|
|
- @FieldDescribe("流程名称")
|
|
|
+ @FieldDescribe("流程标识")
|
|
|
private String value;
|
|
|
|
|
|
- @FieldDescribe("流程标识")
|
|
|
+ @FieldDescribe("流程名称")
|
|
|
private String name;
|
|
|
|
|
|
@FieldDescribe("数量")
|
|
|
private Long count;
|
|
|
|
|
|
+ public Wo(String value, Long count){
|
|
|
+ this.value = value;
|
|
|
+ this.count = count;
|
|
|
+ }
|
|
|
+
|
|
|
public String getValue() {
|
|
|
return value;
|
|
|
}
|
|
|
@@ -94,35 +98,5 @@ class ActionManageListCountWithProcess extends BaseAction {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- //
|
|
|
- // private String getProcessName(Business business, String id) throws
|
|
|
- // Exception {
|
|
|
- // Process o = business.process().pick(id);
|
|
|
- // if (null != o) {
|
|
|
- // return o.getName();
|
|
|
- // }
|
|
|
- // EntityManagerContainer emc = business.entityManagerContainer();
|
|
|
- // EntityManager em = emc.get(Work.class);
|
|
|
- // CriteriaBuilder cb = em.getCriteriaBuilder();
|
|
|
- // CriteriaQuery<String> cq = cb.createQuery(String.class);
|
|
|
- // Root<Work> root = cq.from(Work.class);
|
|
|
- // Predicate p = cb.equal(root.get(Work_.process), id);
|
|
|
- // cq.select(root.get(Work_.processName)).where(p);
|
|
|
- // List<String> list = em.createQuery(cq).setMaxResults(1).getResultList();
|
|
|
- // if (!list.isEmpty()) {
|
|
|
- // return list.get(0);
|
|
|
- // }
|
|
|
- // return null;
|
|
|
- // }
|
|
|
-
|
|
|
- private Long countWithProcess(Business business, Process process) throws Exception {
|
|
|
- EntityManager em = business.entityManagerContainer().get(Work.class);
|
|
|
- CriteriaBuilder cb = em.getCriteriaBuilder();
|
|
|
- CriteriaQuery<Long> cq = cb.createQuery(Long.class);
|
|
|
- Root<Work> root = cq.from(Work.class);
|
|
|
- Predicate p = cb.equal(root.get(Work_.process), process.getId());
|
|
|
- cq.select(cb.count(root)).where(p);
|
|
|
- return em.createQuery(cq).getSingleResult();
|
|
|
- }
|
|
|
|
|
|
}
|