|
@@ -0,0 +1,303 @@
|
|
|
|
+package com.mooctest.crowd.domain.repository;
|
|
|
|
+
|
|
|
|
+import com.mooctest.crowd.domain.dao.*;
|
|
|
|
+import com.mooctest.crowd.domain.domainobject.*;
|
|
|
|
+import com.mooctest.crowd.domain.model.*;
|
|
|
|
+import com.mooctest.crowd.domain.util.Converter;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
|
+import org.springframework.data.jpa.domain.Specifications;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+import sun.reflect.generics.tree.VoidDescriptor;
|
|
|
|
+
|
|
|
|
+import javax.persistence.criteria.*;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.util.*;
|
|
|
|
+
|
|
|
|
+@Component
|
|
|
|
+public class BookTestRepo {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private BookTestDao bookTestDao;
|
|
|
|
+ @Autowired
|
|
|
|
+ private BalanceDao balanceDao;
|
|
|
|
+ @Autowired
|
|
|
|
+ private CrowdTestProjectDao crowdTestProjectDao;
|
|
|
|
+ @Autowired
|
|
|
|
+ private CrowdTestTaskDao crowdTestTaskDao;
|
|
|
|
+ @Autowired
|
|
|
|
+ private TaskToUserDao taskToUserDao;
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserDao userDao;
|
|
|
|
+
|
|
|
|
+ public Page<BookTest> findAllBookTestByPage(Pageable pageable, Map<String, String> extraCondition, String keyword) {
|
|
|
|
+ List<Condition> conditionList = new ArrayList<>();
|
|
|
|
+ conditionList.add(new Condition("uid", Condition.EQ, extraCondition.get("userId")));
|
|
|
|
+ conditionList.add(getInCondition(extraCondition, keyword));
|
|
|
|
+ Specifications<BookTestPO> where = Specifications.where(Condition.getSpecification(conditionList));
|
|
|
|
+ Page<BookTest> bookTestPage = bookTestDao.findAll(where, pageable).map(bookTestPO -> Converter.convert(BookTest.class, bookTestPO));
|
|
|
|
+ List<BookTest> content = bookTestPage.getContent();
|
|
|
|
+ if (content.size() > 0) {
|
|
|
|
+ for (BookTest bookTest : content) {
|
|
|
|
+ //查询项目信息
|
|
|
|
+ String cptcode = bookTest.getCptcode();
|
|
|
|
+ if (cptcode == null || cptcode.length() == 0) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ CrowdTestProjectPO project = crowdTestProjectDao.findByCodeAndIsDeleted(cptcode, 0);
|
|
|
|
+ if (project == null || project.getName() == null) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ bookTest.setCptname(project.getName());
|
|
|
|
+
|
|
|
|
+ //查询任务信息
|
|
|
|
+ long uid = bookTest.getUid();
|
|
|
|
+ String cttcode = bookTest.getCttcode();
|
|
|
|
+ if (uid == 0 || cttcode == null || cttcode.length() == 0) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ TaskToUserPO taskToUser = taskToUserDao.findByUserIdAndTaskCode(uid, cttcode);
|
|
|
|
+ if (taskToUser == null) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ bookTest.setAcceptTime(taskToUser.getAcceptTime());
|
|
|
|
+ bookTest.setSubmitTime(taskToUser.getCommitTaskTime());
|
|
|
|
+ CrowdTestTaskPO task = crowdTestTaskDao.findByCodeAndIsDeleted(cttcode, 0);
|
|
|
|
+ if (task == null || task.getName() == null) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ bookTest.setCttname(task.getName());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return bookTestPage;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Page<BookTest> findAllProjectBookTestByPage(Pageable pageable, Map<String, String> extraCondition, String keyword) {
|
|
|
|
+ List<Condition> conditionList = new ArrayList<>();
|
|
|
|
+ conditionList.add(new Condition("rmid", Condition.EQ, extraCondition.get("userId")));
|
|
|
|
+ conditionList.add(getInCondition(extraCondition, keyword));
|
|
|
|
+ Specifications<BookTestPO> where = Specifications.where(Condition.getSpecification(conditionList));
|
|
|
|
+ Page<BookTest> bookTestPage = bookTestDao.findAll(where, pageable).map(bookTestPO -> Converter.convert(BookTest.class, bookTestPO));
|
|
|
|
+ List<BookTest> content = bookTestPage.getContent();
|
|
|
|
+ if (content.size() > 0) {
|
|
|
|
+ for (BookTest bookTest : content) {
|
|
|
|
+ //查询项目信息
|
|
|
|
+ String cptcode = bookTest.getCptcode();
|
|
|
|
+ if (cptcode == null || cptcode.length() == 0) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ CrowdTestProjectPO project = crowdTestProjectDao.findByCodeAndIsDeleted(cptcode, 0);
|
|
|
|
+ if (project == null || project.getName() == null) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ bookTest.setCptname(project.getName());
|
|
|
|
+
|
|
|
|
+ //查询任务信息
|
|
|
|
+ long uid = bookTest.getUid();
|
|
|
|
+ String cttcode = bookTest.getCttcode();
|
|
|
|
+ if (uid == 0 || cttcode == null || cttcode.length() == 0) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ TaskToUserPO taskToUser = taskToUserDao.findByUserIdAndTaskCode(uid, cttcode);
|
|
|
|
+ if (taskToUser == null) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ bookTest.setAcceptTime(taskToUser.getAcceptTime());
|
|
|
|
+ bookTest.setSubmitTime(taskToUser.getCommitTaskTime());
|
|
|
|
+ CrowdTestTaskPO task = crowdTestTaskDao.findByCodeAndIsDeleted(cttcode, 0);
|
|
|
|
+ if (task == null || task.getName() == null) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ bookTest.setCttname(task.getName());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return bookTestPage;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Condition getInCondition(Map<String, String> extraCondition, String keyword) {
|
|
|
|
+ Condition condition = null;
|
|
|
|
+ if (keyword != null && keyword.length() > 0) {
|
|
|
|
+ String key = extraCondition.get("type");
|
|
|
|
+ StringBuilder valueBuilder = new StringBuilder();
|
|
|
|
+ boolean needSpilt = false;
|
|
|
|
+ if (key.equals("cptcode")) {
|
|
|
|
+ List<CrowdTestProjectPO> list = crowdTestProjectDao.findByNameLikeAndIsDeleted("%" + keyword + "%", 0);
|
|
|
|
+ if (list != null && list.size() > 0) {
|
|
|
|
+ for (CrowdTestProjectPO projectPO : list) {
|
|
|
|
+ if (needSpilt) {
|
|
|
|
+ valueBuilder.append(",");
|
|
|
|
+ } else {
|
|
|
|
+ needSpilt = true;
|
|
|
|
+ }
|
|
|
|
+ valueBuilder.append(projectPO.getCode());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else if (key.equals("cttcode")) {
|
|
|
|
+ List<CrowdTestTaskPO> list = crowdTestTaskDao.findByNameLike("%" + keyword + "%");
|
|
|
|
+ if (list != null && list.size() > 0) {
|
|
|
|
+ for (CrowdTestTaskPO taskPO : list) {
|
|
|
|
+ if (needSpilt) {
|
|
|
|
+ valueBuilder.append(",");
|
|
|
|
+ } else {
|
|
|
|
+ needSpilt = true;
|
|
|
|
+ }
|
|
|
|
+ valueBuilder.append(taskPO.getCode());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ condition = new Condition(key, Condition.IN, valueBuilder.toString());
|
|
|
|
+ }
|
|
|
|
+ return condition;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public BookTest findById(int id) {
|
|
|
|
+ BookTestPO bookTestPO = bookTestDao.findById(id);
|
|
|
|
+ BookTest bookTest = Converter.convert(BookTest.class, bookTestPO);
|
|
|
|
+ //查询项目信息
|
|
|
|
+ String cptcode = bookTest.getCptcode();
|
|
|
|
+ if (cptcode != null && cptcode.length() > 0) {
|
|
|
|
+ CrowdTestProjectPO project = crowdTestProjectDao.findByCodeAndIsDeleted(cptcode, 0);
|
|
|
|
+ if (project != null && project.getName() != null) {
|
|
|
|
+ bookTest.setCptname(project.getName());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //查询任务信息
|
|
|
|
+ long uid = bookTest.getUid();
|
|
|
|
+ String cttcode = bookTest.getCttcode();
|
|
|
|
+ if (uid > 0 && cttcode != null && cttcode.length() > 0) {
|
|
|
|
+ TaskToUserPO taskToUser = taskToUserDao.findByUserIdAndTaskCode(uid, cttcode);
|
|
|
|
+ if (taskToUser != null) {
|
|
|
|
+ bookTest.setAcceptTime(taskToUser.getAcceptTime());
|
|
|
|
+ bookTest.setSubmitTime(taskToUser.getCommitTaskTime());
|
|
|
|
+ }
|
|
|
|
+ CrowdTestTaskPO task = crowdTestTaskDao.findByCodeAndIsDeleted(cttcode, 0);
|
|
|
|
+ if (task != null && task.getName() != null) {
|
|
|
|
+ bookTest.setCttname(task.getName());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return bookTest;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Page<Balance> findAllBookTestByPage(Pageable pageable, Map<String, String> extraCondition) {
|
|
|
|
+ Specifications<BalancePO> where = Specifications.where(Condition.getSpecification(new Condition("uid", Condition.EQ, extraCondition.get("userId"))));
|
|
|
|
+ return balanceDao.findAll(where, pageable).map(balancePO -> Converter.convert(Balance.class, balancePO));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Page<Balance> findprojectAllBookTestByPage(Pageable pageable, Map<String, String> extraCondition) {
|
|
|
|
+ Specifications<BalancePO> where = Specifications.where(getProjectBalResource(extraCondition));
|
|
|
|
+ return balanceDao.findAll(where, pageable).map(balancePO -> Converter.convert(Balance.class, balancePO));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Specification<BalancePO> getProjectBalResource(Map<String, String> extraCondition) {
|
|
|
|
+ return new Specification<BalancePO>() {
|
|
|
|
+ @Override
|
|
|
|
+ public Predicate toPredicate(Root<BalancePO> a, CriteriaQuery<?> q, CriteriaBuilder cb) {
|
|
|
|
+ Predicate predicate = cb.conjunction();
|
|
|
|
+ long rmid = Long.parseLong(extraCondition.get("userId"));
|
|
|
|
+ if (rmid != 0) {
|
|
|
|
+ Path<Object> path = a.get("cttcode"); //定义查询的字段
|
|
|
|
+ CriteriaBuilder.In<Object> in = cb.in(path);
|
|
|
|
+ List<BookTestPO> bookTestPOList = bookTestDao.findAllByRmid(rmid);
|
|
|
|
+ if (bookTestPOList != null && bookTestPOList.size() > 0) {
|
|
|
|
+ for (BookTestPO bookTestPO : bookTestPOList) {
|
|
|
|
+ in.value(bookTestPO.getCttcode());
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ in.value("ABCDE");
|
|
|
|
+ }
|
|
|
|
+ predicate.getExpressions().add(
|
|
|
|
+ cb.and(in)
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ return predicate;
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public int updateState(int state, int id) {
|
|
|
|
+ int sum = bookTestDao.updateStateById(state, id);
|
|
|
|
+ if (sum == 1) {
|
|
|
|
+ BookTestPO bookTest = bookTestDao.findById(id);
|
|
|
|
+ if (bookTest != null) {
|
|
|
|
+ //查询任务信息
|
|
|
|
+ long uid = bookTest.getUid();
|
|
|
|
+ String cttcode = bookTest.getCttcode();
|
|
|
|
+ if (uid != 0 && cttcode != null) {
|
|
|
|
+ TaskToUserPO taskToUser = taskToUserDao.findByUserIdAndTaskCode(uid, cttcode);
|
|
|
|
+ //根据id找名字
|
|
|
|
+ UserPO user = userDao.findById(uid).orElse(null);
|
|
|
|
+ //根据code找项目名字
|
|
|
|
+ CrowdTestTaskPO task = crowdTestTaskDao.findByCodeAndIsDeleted(cttcode, 0);
|
|
|
|
+ if (taskToUser != null) {
|
|
|
|
+ BalancePO balance = new BalancePO();
|
|
|
|
+ balance.setUid(bookTest.getUid());
|
|
|
|
+ balance.setUname(user == null ? "-" : user.getName());
|
|
|
|
+ balance.setCttcode(taskToUser.getTaskCode());
|
|
|
|
+ balance.setCttname(task.getName());
|
|
|
|
+ balance.setBalvalue(taskToUser.getQuotedPrice() + "");
|
|
|
|
+ balance.setBaltime(new Date());
|
|
|
|
+ balance.setState(state);
|
|
|
|
+ balanceDao.save(balance);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return sum;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public int examineState(int state, int id) {
|
|
|
|
+ int sum = balanceDao.updateStateById(state, id);
|
|
|
|
+ if (sum == 1) {
|
|
|
|
+ BalancePO balance = balanceDao.findById(id);
|
|
|
|
+ String code = balance.getCttcode();
|
|
|
|
+ long uid = balance.getUid();
|
|
|
|
+ bookTestDao.updateStateByCttcodeAndUid(state, uid,code);
|
|
|
|
+ }
|
|
|
|
+ return sum;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public BookTestSummary findSummaryByUid(String userId) {
|
|
|
|
+ BookTestSummary summary = new BookTestSummary();
|
|
|
|
+ if (userId != null && userId.length() > 0) {
|
|
|
|
+ long uid = Long.parseLong(userId);
|
|
|
|
+ List<BookTestPO> bookTestPOList = bookTestDao.findAllByUid(uid);
|
|
|
|
+ HashMap<String, Integer> stateMap = new HashMap<>();
|
|
|
|
+ if (bookTestPOList != null && bookTestPOList.size() > 0) {
|
|
|
|
+ for (BookTestPO bookTestPO : bookTestPOList) {
|
|
|
|
+ String key = bookTestPO.getUid() + "_" + bookTestPO.getCttcode();
|
|
|
|
+ stateMap.put(key, bookTestPO.getState());
|
|
|
|
+ Integer state = stateMap.get(key);
|
|
|
|
+ if (state != null) {
|
|
|
|
+ BigDecimal totalAmount = bookTestPO.getTotalAmount();
|
|
|
|
+ switch (state) {
|
|
|
|
+ case BookTest.STATE_DEFAULT:
|
|
|
|
+ BigDecimal defaultSum = Optional.ofNullable(summary.getDefaultSum()).orElse(new BigDecimal("0.0"));
|
|
|
|
+ summary.setDefaultSum(defaultSum.add(totalAmount));
|
|
|
|
+ break;
|
|
|
|
+ case BookTest.STATE_COMMIT:
|
|
|
|
+ BigDecimal commitSum = Optional.ofNullable(summary.getCommitSum()).orElse(new BigDecimal("0.0"));
|
|
|
|
+ summary.setCommitSum(commitSum.add(totalAmount));
|
|
|
|
+ break;
|
|
|
|
+ case BookTest.STATE_AUDIT:
|
|
|
|
+ BigDecimal auditSum = Optional.ofNullable(summary.getAuditSum()).orElse(new BigDecimal("0.0"));
|
|
|
|
+ summary.setAuditSum(auditSum.add(totalAmount));
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ summary.setSum(summary.getDefaultSum().add(summary.getCommitSum()).add(summary.getAuditSum()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return summary;
|
|
|
|
+ }
|
|
|
|
+ public BookTestPO saveBookTest(BookTestPO book) {
|
|
|
|
+// int sum = 0;
|
|
|
|
+// BookTestPO bookTest= bookTestDao.save(book);
|
|
|
|
+ BookTestPO bookTest = bookTestDao.save(book);
|
|
|
|
+ return bookTest;
|
|
|
|
+ }
|
|
|
|
+}
|