区域人员数量分析
This commit is contained in:
parent
e2b9281d7b
commit
e63647ef91
@ -7,6 +7,7 @@ import com.gexin.fastjson.JSON;
|
||||
import com.zhgd.jeecg.common.api.vo.Result;
|
||||
import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatData;
|
||||
import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatDev;
|
||||
import com.zhgd.xmgl.modules.safetyhat.entity.vo.WorkerNumByRegionVo;
|
||||
import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatDataService;
|
||||
import com.zhgd.xmgl.modules.worker.entity.WorkerInfo;
|
||||
import com.zhgd.xmgl.util.DateUtils;
|
||||
@ -23,6 +24,7 @@ import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
@ -159,4 +161,13 @@ public class SafetyHatDataController {
|
||||
return Result.success(safetyHatDataService.newestList(paramMap));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "区域人员数量分析", notes = "区域人员数量分析", httpMethod = "POST")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "projectSn", value = "项目sn", paramType = "body", required = true, dataType = "String"),
|
||||
})
|
||||
@PostMapping(value = "/countWorkerNumByRegion")
|
||||
public Result<List<WorkerNumByRegionVo>> countWorkerNumByRegion(@ApiIgnore @RequestBody Map<String, Object> param) {
|
||||
return Result.success(safetyHatDataService.countWorkerNumByRegion(param));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
package com.zhgd.xmgl.modules.safetyhat.entity.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class WorkerNumAndRegionName {
|
||||
private String date;
|
||||
private Integer workerNum;
|
||||
private String regionName;
|
||||
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package com.zhgd.xmgl.modules.safetyhat.entity.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class WorkerNumByRegionVo {
|
||||
private String date;
|
||||
private List<WorkerNumAndRegionName> list;
|
||||
}
|
||||
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatData;
|
||||
import com.zhgd.xmgl.modules.safetyhat.entity.vo.WorkerNumAndRegionName;
|
||||
import com.zhgd.xmgl.modules.worker.entity.WorkerInfo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
@ -12,6 +13,7 @@ import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 智能安全帽-实时数据
|
||||
@ -32,4 +34,5 @@ public interface SafetyHatDataMapper extends BaseMapper<SafetyHatData> {
|
||||
|
||||
int batchInsert(@Param("list") List<SafetyHatData> list);
|
||||
|
||||
List<WorkerNumAndRegionName> countWorkerNumByRegion(@Param("param") Map<String, Object> param);
|
||||
}
|
||||
|
||||
@ -51,4 +51,18 @@
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<select id="countWorkerNumByRegion" resultType="com.zhgd.xmgl.modules.safetyhat.entity.vo.WorkerNumAndRegionName">
|
||||
select
|
||||
qr.region_name,
|
||||
count(*) as workerNum,
|
||||
date_format(shd.upload_time,'%Y-%m-%d') AS date
|
||||
from quality_region qr
|
||||
join safety_hat_fence shf on shf.quality_region_id = qr.id
|
||||
join safety_hat_data_to_fence shdtf on shdtf.safety_hat_fence_id = shf.id
|
||||
join safety_hat_data shd on shd.id=shdtf.safety_hat_data_id
|
||||
where qr.project_sn = #{param.projectSn}
|
||||
and shd.upload_time >= CONCAT(DATE_FORMAT(DATE_SUB(now(), interval 7 day), '%Y-%m-%d'), ' 00:00:00')
|
||||
group by qr.id,date
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@ -4,10 +4,12 @@ import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatData;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatDev;
|
||||
import com.zhgd.xmgl.modules.safetyhat.entity.vo.WorkerNumByRegionVo;
|
||||
import com.zhgd.xmgl.modules.worker.entity.WorkerInfo;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 智能安全帽-实时数据
|
||||
@ -35,4 +37,5 @@ public interface ISafetyHatDataService extends IService<SafetyHatData> {
|
||||
|
||||
int batchInsert(List<SafetyHatData> list);
|
||||
|
||||
List<WorkerNumByRegionVo> countWorkerNumByRegion(Map<String, Object> param);
|
||||
}
|
||||
|
||||
@ -12,22 +12,18 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.zhgd.jeecg.common.execption.OpenAlertException;
|
||||
import com.zhgd.jeecg.common.system.query.QueryGenerator;
|
||||
import com.zhgd.xmgl.modules.project.entity.Project;
|
||||
import com.zhgd.xmgl.modules.project.mapper.ProjectMapper;
|
||||
import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatAlarm;
|
||||
import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatData;
|
||||
import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatDev;
|
||||
import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatFence;
|
||||
import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatAlarmMapper;
|
||||
import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatDataMapper;
|
||||
import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatDevMapper;
|
||||
import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatFenceMapper;
|
||||
import com.zhgd.xmgl.modules.safetyhat.entity.*;
|
||||
import com.zhgd.xmgl.modules.safetyhat.entity.vo.WorkerNumAndRegionName;
|
||||
import com.zhgd.xmgl.modules.safetyhat.entity.vo.WorkerNumByRegionVo;
|
||||
import com.zhgd.xmgl.modules.safetyhat.mapper.*;
|
||||
import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatAlarmService;
|
||||
import com.zhgd.xmgl.modules.safetyhat.service.ISafetyHatDataService;
|
||||
import com.zhgd.xmgl.modules.safetyhat.entity.SafetyHatDataToFence;
|
||||
import com.zhgd.xmgl.modules.safetyhat.mapper.SafetyHatDataToFenceMapper;
|
||||
import com.zhgd.xmgl.util.DateUtils;
|
||||
import com.zhgd.xmgl.util.PageUtil;
|
||||
import com.zhgd.xmgl.util.RefUtil;
|
||||
import com.zhgd.xmgl.util.RegionUtil;
|
||||
@ -39,6 +35,8 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description: 智能安全帽-实时数据
|
||||
@ -274,5 +272,34 @@ public class SafetyHatDataServiceImpl extends ServiceImpl<SafetyHatDataMapper, S
|
||||
return baseMapper.batchInsert(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WorkerNumByRegionVo> countWorkerNumByRegion(Map<String, Object> param) {
|
||||
List<WorkerNumByRegionVo> vos = Lists.newArrayList();
|
||||
List<WorkerNumAndRegionName> dataList = baseMapper.countWorkerNumByRegion(param);
|
||||
Map<String, List<WorkerNumAndRegionName>> dateMap = dataList.stream().collect(Collectors.groupingBy(WorkerNumAndRegionName::getDate));
|
||||
Set<String> regionNameSet = dataList.stream().map(WorkerNumAndRegionName::getRegionName).collect(Collectors.toSet());
|
||||
List<String> dateList = DateUtils.getDateTimeStrList(60, "yyyy-MM-dd");
|
||||
for (String date : dateList) {
|
||||
List<WorkerNumAndRegionName> list = new ArrayList<>();
|
||||
for (String regionName : regionNameSet) {
|
||||
List<WorkerNumAndRegionName> workerNumAndRegionNames = dateMap.get(date);
|
||||
Map<String, WorkerNumAndRegionName> regionNameMap = Optional.ofNullable(workerNumAndRegionNames).orElse(new ArrayList<>()).stream().collect(Collectors.toMap(WorkerNumAndRegionName::getRegionName, Function.identity(), (oldValue, newValue) -> oldValue));
|
||||
WorkerNumAndRegionName workerNumAndRegionName = regionNameMap.get(regionName);
|
||||
if (workerNumAndRegionName == null) {
|
||||
workerNumAndRegionName = new WorkerNumAndRegionName();
|
||||
workerNumAndRegionName.setWorkerNum(0);
|
||||
workerNumAndRegionName.setDate(date);
|
||||
workerNumAndRegionName.setRegionName(regionName);
|
||||
}
|
||||
list.add(workerNumAndRegionName);
|
||||
}
|
||||
WorkerNumByRegionVo oneVo = new WorkerNumByRegionVo();
|
||||
oneVo.setDate(date);
|
||||
oneVo.setList(list);
|
||||
vos.add(oneVo);
|
||||
}
|
||||
return vos;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user