|
@@ -1,14 +1,24 @@
|
|
|
package com.gis.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.gis.common.util.Result;
|
|
|
import com.gis.domain.entity.ReportEntity;
|
|
|
+import com.gis.domain.po.ReportPo;
|
|
|
+import com.gis.domain.vo.ReportVo;
|
|
|
import com.gis.mapper.IBaseMapper;
|
|
|
import com.gis.mapper.ReportMapper;
|
|
|
import com.gis.service.FodderService;
|
|
|
import com.gis.service.ReportService;
|
|
|
import com.gis.service.WorkService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import tk.mybatis.mapper.entity.Condition;
|
|
|
+
|
|
|
+import javax.validation.constraints.NotBlank;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -33,5 +43,135 @@ public class ReportServiceImpl extends IBaseServiceImpl<ReportEntity, Long> impl
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
+ public Result trend(ReportPo po) {
|
|
|
+
|
|
|
+ return Result.success(getTrent(po));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Map> getTrent(ReportPo po){
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+
|
|
|
+
|
|
|
+ String startTime = po.getStartTime();
|
|
|
+ String endTime = po.getEndTime();
|
|
|
+ String timeType = po.getTimeType();
|
|
|
+ String type = po.getPoType();
|
|
|
+ String infoType = po.getInfoType();
|
|
|
+ if (StrUtil.isBlank(infoType)){
|
|
|
+ infoType = "all";
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(startTime) && StrUtil.isNotBlank(endTime)){
|
|
|
+
|
|
|
+ if ("day".equals(timeType)){
|
|
|
+ builder.append("select DATE_FORMAT( day, '%Y-%m-%d' ) as groupKey, total as count, type from tb_report where is_delete=0 ");
|
|
|
+ builder.append(" and day between '").append(startTime).append("' and '").append(endTime).append("'");
|
|
|
+ builder.append(" and type='").append(type).append("'");
|
|
|
+ builder.append(" and info_type='").append(infoType).append("'");
|
|
|
+
|
|
|
+ } else if ("week".equals(timeType)){
|
|
|
+ builder.append(" select groupKey, sum(total) as count,type from (");
|
|
|
+ builder.append(" select DATE_FORMAT(DATE_ADD(day,INTERVAL- (WEEKDAY(day)) day), '%Y-%m-%d' ) as groupKey, total,type from tb_report where is_delete=0 ");
|
|
|
+ builder.append(" and day between '").append(startTime).append("' and '").append(endTime).append("'");
|
|
|
+ builder.append(" and type='").append(type).append("'");
|
|
|
+ builder.append(" and info_type='").append(infoType).append("'");
|
|
|
+ builder.append(" ) as a group by groupKey");
|
|
|
+ } else {
|
|
|
+ builder.append(" select groupKey, sum(total) as count,type from (");
|
|
|
+ builder.append(" select DATE_FORMAT(day, '%Y-%m') as groupKey, total,type from tb_report where is_delete=0");
|
|
|
+ builder.append(" and day between '").append(startTime).append("' and '").append(endTime).append("'");
|
|
|
+ builder.append(" and type='").append(type).append("'");
|
|
|
+ builder.append(" and info_type='").append(infoType).append("'");
|
|
|
+ builder.append(" ) as a group by groupKey");
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if ("day".equals(timeType)){ // 默认最近30天
|
|
|
+ builder.append("select DATE_FORMAT( day, '%Y-%m-%d' ) as groupKey, total as count, type from tb_report where is_delete=0 and DATE(day)>=DATE_SUB(CURDATE(), INTERVAL 30 DAY)");
|
|
|
+ builder.append(" and type='").append(type).append("'");
|
|
|
+ builder.append(" and info_type='").append(infoType).append("'");
|
|
|
+ } else if ("week".equals(timeType)){ // 默认最近半年
|
|
|
+ builder.append(" select groupKey, sum(total) as count,type from (");
|
|
|
+ builder.append(" select DATE_FORMAT(DATE_ADD(day,INTERVAL- (WEEKDAY(day)) day), '%Y-%m-%d' ) as groupKey, total,type from tb_report where is_delete=0 and DATE(day)>=DATE_SUB(CURDATE(), INTERVAL 200 DAY)");
|
|
|
+ builder.append(" and type='").append(type).append("'");
|
|
|
+ builder.append(" and info_type='").append(infoType).append("'");
|
|
|
+ builder.append(" ) as a group by groupKey");
|
|
|
+ } else { // 默认最近6个月
|
|
|
+ builder.append(" select groupKey, sum(total) as count,type from (");
|
|
|
+ builder.append(" select DATE_FORMAT(day, '%Y-%m') as groupKey, total,type from tb_report where is_delete=0");
|
|
|
+ builder.append( " and DATE(day) >= DATE_FORMAT(DATE_SUB( now(), INTERVAL 6 MONTH),'%Y-%m')");
|
|
|
+ builder.append(" and type='").append(type).append("'");
|
|
|
+ builder.append(" and info_type='").append(infoType).append("'");
|
|
|
+ builder.append(" ) as a group by groupKey");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ builder.append(" order by groupKey desc");
|
|
|
+
|
|
|
+ List<Map> res = entityMapper.listMapSql(builder.toString());
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result reportWork() {
|
|
|
+ Map map = workService.countByType(null);
|
|
|
+ HashMap<Object, Object> res = null;
|
|
|
+ if (map.size() != 3){
|
|
|
+
|
|
|
+ Integer mix = convert((Integer)map.get("mix")) ;
|
|
|
+ Integer age = convert((Integer)map.get("4dkk")) ;
|
|
|
+ Integer pano = convert((Integer)map.get("pano")) ;
|
|
|
+
|
|
|
+ map.put("mix", mix);
|
|
|
+ map.put("age", age);
|
|
|
+ map.put("pano", pano);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return Result.success(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result workTrend(ReportPo po) {
|
|
|
+ List<Map> trent = this.getTrent(po);
|
|
|
+ Condition condition = new Condition(ReportEntity.class);
|
|
|
+ condition.and().andEqualTo("infoType", po.getInfoType());
|
|
|
+ condition.and().andEqualTo("type", po.getPoType());
|
|
|
+ List<ReportEntity> all = this.findAll(condition);
|
|
|
+
|
|
|
+ List<ReportVo> res = new ArrayList<>();
|
|
|
+ for (Map map : trent) {
|
|
|
+ for (Object key : map.keySet()) {
|
|
|
+ String groupKey = (String) key;
|
|
|
+ for (ReportEntity entity : all) {
|
|
|
+ String day = entity.getDay().toString();
|
|
|
+ if (groupKey.contains(day)){
|
|
|
+ ReportVo vo = new ReportVo();
|
|
|
+ BeanUtils.copyProperties(entity, vo);
|
|
|
+ vo.setGroupKey(groupKey);
|
|
|
+ res.add(vo);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ return Result.success(res);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Integer convert(Integer num){
|
|
|
+ return num == null ? 0 : num;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private int total(String type){
|
|
|
+ Integer count = entityMapper.countIntSql(StrUtil.format("select sum(total) as count, type from tb_report where is_delete=0 and type='{}'", type));
|
|
|
+ return count == null ? 0 : count;
|
|
|
+ }
|
|
|
}
|