|
@@ -1,7 +1,172 @@
|
|
|
package cn.com.qmth.examcloud.core.reports.service.impl;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
+
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.data.domain.Sort.Direction;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.api.commons.exchange.PageInfo;
|
|
|
+import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
+import cn.com.qmth.examcloud.core.reports.base.bean.AddProjectReq;
|
|
|
+import cn.com.qmth.examcloud.core.reports.base.bean.ProjectBean;
|
|
|
+import cn.com.qmth.examcloud.core.reports.base.bean.QueryProjectPageReq;
|
|
|
+import cn.com.qmth.examcloud.core.reports.base.bean.UpdateProjectReq;
|
|
|
+import cn.com.qmth.examcloud.core.reports.base.enums.AnalyseType;
|
|
|
+import cn.com.qmth.examcloud.core.reports.base.enums.DataOrigin;
|
|
|
+import cn.com.qmth.examcloud.core.reports.base.enums.ReportStatus;
|
|
|
+import cn.com.qmth.examcloud.core.reports.dao.ProjectRepo;
|
|
|
+import cn.com.qmth.examcloud.core.reports.dao.entity.ProjectEntity;
|
|
|
import cn.com.qmth.examcloud.core.reports.service.ProjectService;
|
|
|
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
|
|
|
+@Service
|
|
|
public class ProjectServiceImpl implements ProjectService {
|
|
|
+ @Autowired
|
|
|
+ private ProjectRepo projectRepo;
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public Long addProject(AddProjectReq req,Long rootOrgId) {
|
|
|
+ ProjectEntity pe=new ProjectEntity();
|
|
|
+ BeanUtils.copyProperties(req, pe);
|
|
|
+ pe.setRootOrgId(rootOrgId);
|
|
|
+ pe.setEnable(true);
|
|
|
+ pe.setReportStatus(ReportStatus.NONE);
|
|
|
+ pe.setExamIds(StringUtils.join(req.getExamIds().toArray(), ","));
|
|
|
+ projectRepo.save(pe);
|
|
|
+ return pe.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void updateProject(UpdateProjectReq req,Long rootOrgId) {
|
|
|
+ ProjectEntity pe = GlobalHelper.getEntity(projectRepo, req.getId(), ProjectEntity.class);
|
|
|
+ if(pe==null) {
|
|
|
+ throw new StatusException("1000001", "项目不存在");
|
|
|
+ }
|
|
|
+ if(!rootOrgId.equals(pe.getRootOrgId())) {
|
|
|
+ throw new StatusException("1000002", "RootOrgId不一致");
|
|
|
+ }
|
|
|
+ pe.setName(req.getName());
|
|
|
+ pe.setRemarks(req.getRemarks());
|
|
|
+ projectRepo.save(pe);
|
|
|
+ }
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void updateEnable(String ids, Boolean enable,Long rootOrgId) {
|
|
|
+ List<Long> idList = Arrays.asList(ids.split(",")).stream().map(str -> Long.parseLong(str))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ projectRepo.updateEnable(idList, rootOrgId, enable);
|
|
|
+ }
|
|
|
+ private String toSqlSearchPattern(String column) {
|
|
|
+ if (StringUtils.isBlank(column)) {
|
|
|
+ return "%";
|
|
|
+ } else {
|
|
|
+ column = column.trim().replaceAll("\\s", "%");
|
|
|
+ column = "%" + column + "%";
|
|
|
+ return column;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public PageInfo<ProjectBean> queryPage(QueryProjectPageReq req, Integer pageNo, Integer pageSize,Long rootOrgId) {
|
|
|
+ Long id=req.getId();
|
|
|
+ String name=req.getName();
|
|
|
+ AnalyseType analyseType=req.getAnalyseType();
|
|
|
+ DataOrigin dataOrigin=req.getDataOrigin();
|
|
|
+ Specification<ProjectEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ predicates.add(cb.equal(root.get("rootOrgId"), rootOrgId));
|
|
|
+
|
|
|
+ if (null != id) {
|
|
|
+ predicates.add(cb.equal(root.get("id"), id));
|
|
|
+ }
|
|
|
+ if (null != analyseType) {
|
|
|
+ predicates.add(cb.equal(root.get("analyseType"), analyseType));
|
|
|
+ }
|
|
|
+ if (null != dataOrigin) {
|
|
|
+ predicates.add(cb.equal(root.get("dataOrigin"), dataOrigin));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(name)) {
|
|
|
+ predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
|
|
|
+ }
|
|
|
+
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ PageRequest pageRequest = PageRequest.of(pageNo-1, pageSize,
|
|
|
+ new Sort(Direction.DESC, "id"));
|
|
|
+
|
|
|
+ Page<ProjectEntity> projects = projectRepo.findAll(specification, pageRequest);
|
|
|
+
|
|
|
+ List<ProjectBean> ret = Lists.newArrayList();
|
|
|
+
|
|
|
+ for (ProjectEntity cur : projects) {
|
|
|
+ ProjectBean bean = new ProjectBean();
|
|
|
+ BeanUtils.copyProperties(cur, bean);
|
|
|
+ bean.setAnalyseTypeName(getAnalyseTypeName(bean.getAnalyseType()));
|
|
|
+ bean.setDataOriginName(getDataOriginName(bean.getDataOrigin()));
|
|
|
+ bean.setReportStatusName(getReportStatusName(bean.getReportStatus()));
|
|
|
+ if(StringUtils.isNotBlank(cur.getExamIds())) {
|
|
|
+ List<Long> temList = Arrays.asList(cur.getExamIds().split(",")).stream().map(str -> Long.parseLong(str))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ bean.setExamIds(temList);
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(cur.getPartitionDetails())) {
|
|
|
+ List<Double> temList = Arrays.asList(cur.getPartitionDetails().split(",")).stream().map(str -> Double.parseDouble(str))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ bean.setPartitionDetails(temList);
|
|
|
+ }
|
|
|
+ ret.add(bean);
|
|
|
+ }
|
|
|
+ return new PageInfo<ProjectBean>(projects, ret);
|
|
|
+ }
|
|
|
+ private String getAnalyseTypeName(AnalyseType e) {
|
|
|
+ if(e.equals(AnalyseType.SINGLE)) {
|
|
|
+ return "单项分析";
|
|
|
+ }
|
|
|
+ if(e.equals(AnalyseType.TREND)) {
|
|
|
+ return "趋势分析";
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ private String getDataOriginName(DataOrigin e) {
|
|
|
+ if(e.equals(DataOrigin.SYNC)) {
|
|
|
+ return "同步";
|
|
|
+ }
|
|
|
+ if(e.equals(DataOrigin.IMPORT)) {
|
|
|
+ return "导入";
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ private String getReportStatusName(ReportStatus e) {
|
|
|
+ if(e.equals(ReportStatus.NONE)) {
|
|
|
+ return "未计算";
|
|
|
+ }
|
|
|
+ if(e.equals(ReportStatus.COMPUTING)) {
|
|
|
+ return "计算中";
|
|
|
+ }
|
|
|
+ if(e.equals(ReportStatus.SUCCESS)) {
|
|
|
+ return "计算成功";
|
|
|
+ }
|
|
|
+ if(e.equals(ReportStatus.FAIL)) {
|
|
|
+ return "计算失败";
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
|
|
|
}
|