Browse Source

网格员巡查统计初始化几重新计算代码

master
jianjun 4 years ago
parent
commit
ab0fe9ddad
  1. 1
      epmet-cloud-generator/src/main/java/io/renren/GeneratorApplication.java
  2. 5
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/extract/form/StaffPatrolStatsFormDTO.java
  3. 61
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/user/result/CustomerGridStaffDTO.java
  4. 122
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/user/result/StaffPatrolRecordResult.java
  5. 2
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/BizDataStatsController.java
  6. 4
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/org/CustomerStaffGridDao.java
  7. 53
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/project/ProjectDao.java
  8. 3
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/user/StatsStaffPatrolRecordDailyDao.java
  9. 3
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/user/UserDao.java
  10. 3
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/extract/biz/BizDataStatsService.java
  11. 196
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/extract/biz/impl/BizDataStatsServiceImpl.java
  12. 4
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/org/CustomerStaffService.java
  13. 4
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/org/impl/CustomerStaffServiceImpl.java
  14. 1
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/project/ProjectService.java
  15. 5
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/project/impl/ProjectServiceImpl.java
  16. 5
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/StatsStaffPatrolService.java
  17. 3
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/UserService.java
  18. 30
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/impl/StatsStaffPatrolServiceImpl.java
  19. 8
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/impl/UserServiceImpl.java
  20. 10
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/CustomerStaffGridDao.xml
  21. 7
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/project/ProjectDao.xml
  22. 11
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/user/StatsStaffPatrolRecordDailyDao.xml
  23. 11
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/user/UserDao.xml

1
epmet-cloud-generator/src/main/java/io/renren/GeneratorApplication.java

@ -2,7 +2,6 @@ package io.renren;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class GeneratorApplication {

5
epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/extract/form/StaffPatrolStatsFormDTO.java

@ -18,5 +18,8 @@ public class StaffPatrolStatsFormDTO implements Serializable {
private String dateId;
private String staffId;
private String gridId;
private String roleType;
/**
* 角色key
*/
private String roleKey;
}

61
epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/user/result/CustomerGridStaffDTO.java

@ -0,0 +1,61 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.dto.user.result;
import lombok.Data;
import java.io.Serializable;
/**
* 政府工作人员表
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2020-04-18
*/
@Data
public class CustomerGridStaffDTO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 客户id
*/
private String customerId;
/**
* 网格id
*/
private String gridId;
/**
* 网格所属组织id
*/
private String agencyId;
/**
* 网格所属的所有组织id
*/
private String gridPids;
/**
* 关联User表的主键Id
*/
private String userId;
}

122
epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/user/result/StaffPatrolRecordResult.java

@ -0,0 +1,122 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.dto.user.result;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 工作人员巡查主记录
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2021-06-07
*/
@Data
public class StaffPatrolRecordResult implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
private String id;
/**
* 客户Id
*/
private String customerId;
/**
* 网格id
*/
private String grid;
/**
* 网格所有上级id
*/
private String gridPids;
/**
* 工作人员用户id
*/
private String staffId;
/**
* 工作人员所属组织id=网格所属的组织id
*/
private String agencyId;
/**
* 巡查开始时间
*/
private Date patrolStartTime;
/**
* 巡查结束时间,前端传入
*/
private Date patrolEndTime;
/**
* 实际结束时间=操作结束巡查的时间
*/
private Date actrualEndTime;
/**
* 本次巡查总耗时单位秒结束巡查时写入
*/
private Integer totalTime;
/**
* 正在巡查中patrolling结束end
*/
private String status;
/**
* 删除标识 0.未删除 1.已删除
*/
private Integer delFlag;
/**
* 乐观锁
*/
private Integer revision;
/**
* 创建人
*/
private String createdBy;
/**
* 创建时间
*/
private Date createdTime;
/**
* 更新人
*/
private String updatedBy;
/**
* 更新时间
*/
private Date updatedTime;
}

2
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/BizDataStatsController.java

@ -29,7 +29,7 @@ public class BizDataStatsController {
**/
@RequestMapping("patrol")
public Result execute(@RequestBody StaffPatrolStatsFormDTO formDTO) {
bizDataStatsService.initStaffPatrolStats(formDTO);
bizDataStatsService.executeStaffPatrolStats(formDTO);
return new Result();
}
}

4
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/org/CustomerStaffGridDao.java

@ -19,7 +19,7 @@ package com.epmet.dao.org;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dto.extract.form.StaffPatrolStatsFormDTO;
import com.epmet.dto.user.result.StatsStaffPatrolRecordDailyDTO;
import com.epmet.dto.user.result.CustomerGridStaffDTO;
import com.epmet.entity.org.CustomerStaffGridEntity;
import org.apache.ibatis.annotations.Mapper;
@ -34,5 +34,5 @@ import java.util.List;
@Mapper
public interface CustomerStaffGridDao extends BaseDao<CustomerStaffGridEntity> {
List<StatsStaffPatrolRecordDailyDTO> selectGridStaffList(StaffPatrolStatsFormDTO formDTO);
List<CustomerGridStaffDTO> selectGridStaffList(StaffPatrolStatsFormDTO formDTO);
}

53
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/project/ProjectDao.java

@ -18,16 +18,12 @@
package com.epmet.dao.project;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dto.CustomerProjectParameterDTO;
import com.epmet.dto.ProjectDTO;
import com.epmet.dto.ProjectSatisfactionStatisticsDTO;
import com.epmet.dto.project.ProjectAgencyDTO;
import com.epmet.dto.project.ProjectCategoryDTO;
import com.epmet.dto.project.ProjectGridDTO;
import com.epmet.dto.project.ProjectPointDTO;
import com.epmet.dto.project.result.ProjectExceedParamsResultDTO;
import com.epmet.dto.screen.ScreenProjectProcessAttachmentDTO;
import com.epmet.entity.evaluationindex.extract.FactOriginProjectMainDailyEntity;
import com.epmet.entity.project.ProjectEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -52,87 +48,92 @@ public interface ProjectDao extends BaseDao<ProjectEntity> {
/**
* 已结案项目统计
* @author zhaoqifeng
* @date 2020/6/18 17:01
*
* @param customerId
* @param date
* @return java.util.List<com.epmet.dto.project.ProjectAgencyDTO>
* @author zhaoqifeng
* @date 2020/6/18 17:01
*/
List<ProjectAgencyDTO> selectAgencyClosedProjectTotal(@Param("customerId") String customerId, @Param("date") String date);
/**
* 已结案项目增量
* @author zhaoqifeng
* @date 2020/6/18 17:01
*
* @param customerId
* @param date
* @return java.util.List<com.epmet.dto.project.ProjectAgencyDTO>
* @author zhaoqifeng
* @date 2020/6/18 17:01
*/
List<ProjectAgencyDTO> selectAgencyClosedProjectInc(@Param("customerId") String customerId, @Param("date") String date);
/**
* 已结案项目统计
* @author zhaoqifeng
* @date 2020/6/18 17:01
*
* @param customerId
* @param date
* @return java.util.List<com.epmet.dto.project.ProjectGridDTO>
* @author zhaoqifeng
* @date 2020/6/18 17:01
*/
List<ProjectGridDTO> selectGridClosedProjectTotal(@Param("customerId") String customerId, @Param("date") String date);
/**
* 已结案项目增量
* @author zhaoqifeng
* @date 2020/6/18 17:01
*
* @param customerId
* @param date
* @return java.util.List<com.epmet.dto.project.ProjectGridDTO>
* @author zhaoqifeng
* @date 2020/6/18 17:01
*/
List<ProjectGridDTO> selectGridClosedProjectInc(@Param("customerId") String customerId, @Param("date") String date);
/**
* 获取项目信息
* @author zhaoqifeng
* @date 2020/9/15 16:13
*
* @param customerId
* @param date
* @return java.util.List<com.epmet.dto.project.ProjectInfoDTO>
* @author zhaoqifeng
* @date 2020/9/15 16:13
*/
List<ProjectDTO> selectProjectInfo(@Param("customerId") String customerId, @Param("date") String date);
/**
* 获取用户可滞留天数
* @author zhaoqifeng
* @date 2020/9/28 10:16
*
* @param customerId
* @return java.lang.String
* @author zhaoqifeng
* @date 2020/9/28 10:16
*/
String selectParameterValueByKey(@Param("customerId") String customerId);
/**
* @Description 查找客户项目超期参数
*
* @param customerId
* @return java.util.List<com.epmet.dto.project.result.ProjectExceedParamsResultDTO>
* @Description 查找客户项目超期参数
* @author wangc
* @date 2021.03.05 17:52
*/
List<ProjectExceedParamsResultDTO> selectProjectExceedParams(@Param("customerId") String customerId);
/**
* @Description 批量查询项目信息
* @param ids
* @return java.util.List<com.epmet.entity.project.ProjectEntity>
* @Description 批量查询项目信息
* @author wangc
* @date 2021.03.08 10:32
*/
List<ProjectEntity> batchSelectProjectInfo(@Param("ids") List<String> ids);
/**
* @Description 查询项目的分类信息
* @param list
* @return java.util.List<com.epmet.dto.project.ProjectCategoryDTO>
* @Description 查询项目的分类信息
* @author wangc
* @date 2021.03.08 23:44
*/
@ -142,20 +143,24 @@ public interface ProjectDao extends BaseDao<ProjectEntity> {
/**
* 获取项目满意度
* @author zhaoqifeng
* @date 2021/5/21 10:06
*
* @param customerId
* @return java.util.List<com.epmet.dto.ProjectSatisfactionStatisticsDTO>
* @author zhaoqifeng
* @date 2021/5/21 10:06
*/
List<ProjectPointDTO> selectProjectSatisfaction(@Param("customerId") String customerId);
/**
* 根据key查找value
* @author zhaoqifeng
* @date 2021/5/21 10:58
*
* @param customerId
* @param parameterKey
* @return java.lang.String
* @author zhaoqifeng
* @date 2021/5/21 10:58
*/
String selectValueByKey(@Param("customerId") String customerId, @Param("parameterKey") String parameterKey);
List<ProjectDTO> selectProjectListByDateId(@Param("customerId") String customerId, @Param("dateId") String dateId, @Param("projectOrigin") String projectOrigin);
}

3
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/user/StatsStaffPatrolRecordDailyDao.java

@ -18,6 +18,7 @@
package com.epmet.dao.user;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dto.extract.form.StaffPatrolStatsFormDTO;
import com.epmet.dto.user.result.StatsStaffPatrolRecordDailyDTO;
import com.epmet.entity.user.StatsStaffPatrolRecordDailyEntity;
import org.apache.ibatis.annotations.Mapper;
@ -35,4 +36,6 @@ import java.util.List;
public interface StatsStaffPatrolRecordDailyDao extends BaseDao<StatsStaffPatrolRecordDailyEntity> {
Integer insertBatch(@Param("list") List<StatsStaffPatrolRecordDailyDTO> insertList);
int delete(StaffPatrolStatsFormDTO formDTO);
}

3
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/user/UserDao.java

@ -6,6 +6,7 @@ import com.epmet.dto.extract.result.UserPartyResultDTO;
import com.epmet.dto.screen.ScreenProjectDataDTO;
import com.epmet.dto.user.result.CommonTotalAndIncCountResultDTO;
import com.epmet.dto.user.result.CustomerStaffDTO;
import com.epmet.dto.user.result.StaffPatrolRecordResult;
import com.epmet.dto.user.result.StatsStaffPatrolRecordDailyDTO;
import com.epmet.entity.evaluationindex.screen.ScreenPartyUserRankDataEntity;
import org.apache.ibatis.annotations.Mapper;
@ -174,5 +175,7 @@ public interface UserDao {
List<CustomerStaffDTO> selectUserByRoleKey(StaffPatrolStatsFormDTO formDTO);
List<StatsStaffPatrolRecordDailyDTO> selectLastStaffPatrolList(StaffPatrolStatsFormDTO formDTO);
List<StaffPatrolRecordResult> selectStaffPatrolListByDateId(@Param("customerId") String customerId, @Param("dateId") String dateId);
}

3
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/extract/biz/BizDataStatsService.java

@ -27,5 +27,6 @@ import com.epmet.dto.extract.form.StaffPatrolStatsFormDTO;
*/
public interface BizDataStatsService {
void initStaffPatrolStats(StaffPatrolStatsFormDTO formDTO);
void executeStaffPatrolStats(StaffPatrolStatsFormDTO formDTO);
}

196
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/extract/biz/impl/BizDataStatsServiceImpl.java

@ -1,15 +1,26 @@
package com.epmet.service.evaluationindex.extract.biz.impl;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.constant.ProjectConstant;
import com.epmet.dto.ProjectDTO;
import com.epmet.dto.extract.form.StaffPatrolStatsFormDTO;
import com.epmet.dto.user.result.CustomerGridStaffDTO;
import com.epmet.dto.user.result.CustomerStaffDTO;
import com.epmet.dto.user.result.StaffPatrolRecordResult;
import com.epmet.dto.user.result.StatsStaffPatrolRecordDailyDTO;
import com.epmet.entity.user.StatsStaffPatrolRecordDailyEntity;
import com.epmet.service.evaluationindex.extract.biz.BizDataStatsService;
import com.epmet.service.org.CustomerStaffService;
import com.epmet.service.project.ProjectService;
import com.epmet.service.user.StatsStaffPatrolService;
import com.epmet.service.user.UserService;
import com.epmet.util.DimIdGenerator;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -34,55 +45,168 @@ public class BizDataStatsServiceImpl implements BizDataStatsService {
@Autowired
private UserService userService;
@Autowired
private ProjectService projectService;
@Autowired
private StatsStaffPatrolService statsStaffPatrolService;
@Override
public void initStaffPatrolStats(StaffPatrolStatsFormDTO formDTO) {
//获取所有的网格员
//1.获取所有网格用户
List<StatsStaffPatrolRecordDailyDTO> allStaffList = customerStaffService.selectStaffGridList(formDTO);
/* if (CollectionUtils.isEmpty(allStaffList)){
log.warn("reloadStaffPatrolStats customerId:{} have any staff,param:{}",formDTO.getCustomerId(), JSON.toJSONString(formDTO));
return
}*/
//获取所有含有网格员角色的用户
List<CustomerStaffDTO> gridMemberList = userService.selectUserListByRoleKey(formDTO);
/*if (CollectionUtils.isEmpty(gridMemberList)){
log.warn("reloadStaffPatrolStats customerId:{} have any gridMembers,param:{}",formDTO.getCustomerId(), JSON.toJSONString(formDTO));
return
}*/
public void executeStaffPatrolStats(StaffPatrolStatsFormDTO formDTO) {
//校正数据
//获取所有网格员
List<CustomerGridStaffDTO> allGridMembers = getAllGridMembers(formDTO);
reloadStaffPatrolStatsData(formDTO, allGridMembers);
//初始化今天的数据
initStaffPatrolTodayData(formDTO, allGridMembers);
}
private void reloadStaffPatrolStatsData(StaffPatrolStatsFormDTO formDTO, List<CustomerGridStaffDTO> allGridMembers) {
//获取昨日的巡查统计记录
String yesterdayStr = getYesterdayString(formDTO);
List<StatsStaffPatrolRecordDailyDTO> yesterdayStatsList = statsStaffPatrolService.selectData(formDTO.getCustomerId(), yesterdayStr);
if (CollectionUtils.isEmpty(yesterdayStatsList)) {
log.warn("reloadStaffPatrolStatsData have any yesterdayStats data,dateId:{}", yesterdayStr);
return;
}
Map<String, StatsStaffPatrolRecordDailyDTO> yesterdayStatsMap = yesterdayStatsList.stream().collect(Collectors.toMap(o -> o.getGridId() + o.getStaffId(), o -> o, (o1, o2) -> o1));
//获取昨日的巡查记录
List<StaffPatrolRecordResult> yesterdayPatrolList = userService.selectStaffPatrolListByDateId(formDTO.getCustomerId(), yesterdayStr);
//获取昨日的立项项目数
List<ProjectDTO> yesterdayProjectList = projectService.selectProjectListByDateId(formDTO.getCustomerId(), yesterdayStr, ProjectConstant.PROJECT_ORIGIN_AGENCY);
//遍历网格员 设置其 巡查次数 巡查时常 上报项目数
Map<String, CustomerGridStaffDTO> gridMemberMap = allGridMembers.stream().collect(Collectors.toMap(o -> o.getGridId() + o.getUserId(), o -> o, (o1, o2) -> o1));
List<StatsStaffPatrolRecordDailyEntity> updateList = new ArrayList<>();
yesterdayPatrolList.forEach(patrolRecord -> {
String key = patrolRecord.getGrid().concat(patrolRecord.getStaffId());
StatsStaffPatrolRecordDailyDTO patrolRecordDailyDTO = yesterdayStatsMap.get(key);
if (patrolRecordDailyDTO != null) {
long total = (patrolRecord.getActrualEndTime().getTime() - patrolRecord.getPatrolStartTime().getTime()) / 1000;
if (patrolRecordDailyDTO.getTotalTime() == null) {
patrolRecordDailyDTO.setTotalTime(NumConstant.ZERO);
}
patrolRecordDailyDTO.setTotalTime(patrolRecordDailyDTO.getTotalTime() + (int) total);
if (patrolRecordDailyDTO.getPatrolTotal() == null) {
patrolRecordDailyDTO.setPatrolTotal(NumConstant.ZERO);
}
patrolRecordDailyDTO.setPatrolTotal(patrolRecordDailyDTO.getPatrolTotal() + NumConstant.ONE);
//如果巡查记录时间小于统计里的最新的时间 则更新
if (patrolRecordDailyDTO.getLatestPatrolTime() == null || patrolRecordDailyDTO.getLatestPatrolTime().getTime() < patrolRecord.getPatrolStartTime().getTime()) {
patrolRecordDailyDTO.setLatestPatrolTime(patrolRecord.getPatrolStartTime());
patrolRecordDailyDTO.setLatestPatrolStatus(patrolRecord.getStatus());
}
}
});
//填充项目数
yesterdayProjectList.forEach(projectDTO -> {
String key = projectDTO.getCreatedBy();
yesterdayPatrolList.forEach(patrol -> {
//项目立项时间 在巡查期间时 总数加1
long projectCreateTime = projectDTO.getCreatedTime().getTime();
if (patrol.getPatrolStartTime().getTime() >= projectCreateTime && patrol.getPatrolStartTime().getTime() >= projectCreateTime) {
String unqPatrolKey = getUnqPatrolKey(patrol.getGrid(), patrol.getStaffId());
StatsStaffPatrolRecordDailyDTO recordDailyDTO = yesterdayStatsMap.get(unqPatrolKey);
if (recordDailyDTO == null) {
log.error("have project data but have any patrolRecordDaily,gridId:{},staffId:{}", patrol.getGrid(), patrol.getStaffId());
return;
}
recordDailyDTO.setReportProjectCount(recordDailyDTO.getReportProjectCount() + 1);
}
});
});
StaffPatrolStatsFormDTO yesterdayParam = ConvertUtils.sourceToTarget(formDTO, StaffPatrolStatsFormDTO.class);
yesterdayParam.setDateId(yesterdayStr);
Integer effectRow = statsStaffPatrolService.delAndInsertBatch(yesterdayParam, yesterdayStatsList);
log.debug("initStaffPatrolStats insert rows:{}", effectRow);
}
/**
* desc: 获取key
*
* @param gridId
* @param staffId
* @return java.lang.String
* @author LiuJanJun
* @date 2021/7/2 8:32 上午
*/
private String getUnqPatrolKey(String gridId, String staffId) {
return gridId.concat(staffId);
}
@Nullable
private String getYesterdayString(StaffPatrolStatsFormDTO formDTO) {
Date dateParam = DateUtils.parse(formDTO.getDateId(), DateUtils.DATE_PATTERN_YYYYMMDD);
Date yesterdayDate = DateUtils.addDateDays(dateParam, -1);
return DateUtils.format(yesterdayDate, DateUtils.DATE_PATTERN_YYYYMMDD);
}
private void initStaffPatrolTodayData(StaffPatrolStatsFormDTO formDTO, List<CustomerGridStaffDTO> allGridMembers) {
List<StatsStaffPatrolRecordDailyDTO> lastStaffPatrolList = userService.selectLastStaffPatrolList(formDTO);
Map<String, StatsStaffPatrolRecordDailyDTO> lastPatrolMap = lastStaffPatrolList.stream().collect(Collectors.toMap(o -> o.getGridId() + o.getStaffId(), o -> o, (o1, o2) -> o1));
//构建数据 插入
List<StatsStaffPatrolRecordDailyDTO> insertList = new ArrayList<>();
DimIdGenerator.DimIdBean dimIdBean = DimIdGenerator.getDimIdBean(new Date());
allStaffList.forEach(gridStaff -> {
gridStaff.setDateId(dimIdBean.getDateId());
gridStaff.setWeekId(dimIdBean.getWeekId());
gridStaff.setQuarterId(dimIdBean.getQuarterId());
gridStaff.setYearId(dimIdBean.getYearId());
gridStaff.setMonthId(dimIdBean.getMonthId());
StatsStaffPatrolRecordDailyDTO recordDailyDTO = lastPatrolMap.get(gridStaff.getGridId().concat(gridStaff.getStaffId()));
gridStaff.setTotalTime(NumConstant.ZERO);
gridStaff.setPatrolTotal(NumConstant.ZERO);
gridStaff.setLatestPatrolStatus("end");
gridStaff.setReportProjectCount(NumConstant.ZERO);
Date date = DateUtils.parse(formDTO.getDateId(), DateUtils.DATE_PATTERN_YYYYMMDD);
DimIdGenerator.DimIdBean dimIdBean = DimIdGenerator.getDimIdBean(date);
allGridMembers.forEach(gridMember -> {
StatsStaffPatrolRecordDailyDTO record = new StatsStaffPatrolRecordDailyDTO();
record.setCustomerId(gridMember.getCustomerId());
record.setGridId(gridMember.getGridId());
record.setAgencyId(gridMember.getAgencyId());
record.setGridPids(gridMember.getGridPids());
record.setStaffId(gridMember.getUserId());
record.setDateId(dimIdBean.getDateId());
record.setWeekId(dimIdBean.getWeekId());
record.setQuarterId(dimIdBean.getQuarterId());
record.setYearId(dimIdBean.getYearId());
record.setMonthId(dimIdBean.getMonthId());
StatsStaffPatrolRecordDailyDTO recordDailyDTO = lastPatrolMap.get(gridMember.getGridId().concat(gridMember.getUserId()));
record.setTotalTime(NumConstant.ZERO);
record.setPatrolTotal(NumConstant.ZERO);
record.setLatestPatrolStatus("end");
record.setReportProjectCount(NumConstant.ZERO);
//最后巡查时间
gridStaff.setLatestPatrolTime(null);
record.setLatestPatrolTime(null);
if (recordDailyDTO != null) {
gridStaff.setLatestPatrolStatus(recordDailyDTO.getLatestPatrolStatus());
gridStaff.setLatestPatrolTime(recordDailyDTO.getLatestPatrolTime());
record.setLatestPatrolStatus(recordDailyDTO.getLatestPatrolStatus());
record.setLatestPatrolTime(recordDailyDTO.getLatestPatrolTime());
}
gridMemberList.forEach(gridMember -> {
if (gridStaff.getStaffId().equals(gridMember.getUserId())) {
insertList.add(gridStaff);
}
});
insertList.add(record);
});
Integer effectRow = statsStaffPatrolService.insertBatch(insertList);
Integer effectRow = statsStaffPatrolService.delAndInsertBatch(formDTO, insertList);
log.debug("initStaffPatrolStats insert rows:{}", effectRow);
}
private List<CustomerGridStaffDTO> getAllGridMembers(StaffPatrolStatsFormDTO formDTO) {
//获取所有的网格员
//1.获取所有网格用户
List<CustomerGridStaffDTO> allStaffList = customerStaffService.selectStaffGridList(formDTO);
if (CollectionUtils.isEmpty(allStaffList)) {
log.warn("reloadStaffPatrolStats customerId:{} have any staff,param:{}", formDTO.getCustomerId(), JSON.toJSONString(formDTO));
return allStaffList;
}
//获取所有含有网格员角色的用户
List<CustomerStaffDTO> gridMemberList = userService.selectUserListByRoleKey(formDTO);
if (CollectionUtils.isEmpty(gridMemberList)) {
log.warn("reloadStaffPatrolStats customerId:{} have any gridMembers,param:{}", formDTO.getCustomerId(), JSON.toJSONString(formDTO));
return allStaffList;
}
List<CustomerGridStaffDTO> insertList = new ArrayList<>();
allStaffList.forEach(gridStaff -> gridMemberList.forEach(gridMember -> {
if (gridStaff.getUserId().equals(gridMember.getUserId())) {
insertList.add(gridStaff);
}
}));
log.debug("getAllGridMembers result:{},param:{}", JSON.toJSONString(insertList), JSON.toJSONString(formDTO));
return insertList;
}
}

4
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/org/CustomerStaffService.java

@ -1,7 +1,7 @@
package com.epmet.service.org;
import com.epmet.dto.extract.form.StaffPatrolStatsFormDTO;
import com.epmet.dto.user.result.StatsStaffPatrolRecordDailyDTO;
import com.epmet.dto.user.result.CustomerGridStaffDTO;
import java.util.List;
@ -18,5 +18,5 @@ public interface CustomerStaffService {
* @author LiuJanJun
* @date 2021/6/29 3:13 下午
*/
List<StatsStaffPatrolRecordDailyDTO> selectStaffGridList(StaffPatrolStatsFormDTO formDTO);
List<CustomerGridStaffDTO> selectStaffGridList(StaffPatrolStatsFormDTO formDTO);
}

4
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/org/impl/CustomerStaffServiceImpl.java

@ -4,7 +4,7 @@ import com.epmet.commons.dynamic.datasource.annotation.DataSource;
import com.epmet.constant.DataSourceConstant;
import com.epmet.dao.org.CustomerStaffGridDao;
import com.epmet.dto.extract.form.StaffPatrolStatsFormDTO;
import com.epmet.dto.user.result.StatsStaffPatrolRecordDailyDTO;
import com.epmet.dto.user.result.CustomerGridStaffDTO;
import com.epmet.service.org.CustomerStaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -33,7 +33,7 @@ public class CustomerStaffServiceImpl implements CustomerStaffService {
* @date 2021/6/29 3:13 下午
*/
@Override
public List<StatsStaffPatrolRecordDailyDTO> selectStaffGridList(StaffPatrolStatsFormDTO formDTO) {
public List<CustomerGridStaffDTO> selectStaffGridList(StaffPatrolStatsFormDTO formDTO) {
return customerStaffGridDao.selectGridStaffList(formDTO);
}
}

1
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/project/ProjectService.java

@ -162,4 +162,5 @@ public interface ProjectService extends BaseService<ProjectEntity> {
*/
List<FactOriginProjectMainDailyEntity> getProjectSatisfaction(String customerId);
List<ProjectDTO> selectProjectListByDateId(String customerId, String yesterdayStr, String projectOriginAgency);
}

5
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/project/impl/ProjectServiceImpl.java

@ -196,5 +196,10 @@ public class ProjectServiceImpl extends BaseServiceImpl<ProjectDao, ProjectEntit
}).collect(Collectors.toList());
}
@Override
public List<ProjectDTO> selectProjectListByDateId(String customerId, String dateId, String projectOrigin) {
return baseDao.selectProjectListByDateId(customerId,dateId,projectOrigin);
}
}

5
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/StatsStaffPatrolService.java

@ -1,5 +1,6 @@
package com.epmet.service.user;
import com.epmet.dto.extract.form.StaffPatrolStatsFormDTO;
import com.epmet.dto.user.result.StatsStaffPatrolRecordDailyDTO;
import java.util.List;
@ -9,5 +10,7 @@ import java.util.List;
*/
public interface StatsStaffPatrolService {
Integer insertBatch(List<StatsStaffPatrolRecordDailyDTO> insertList);
Integer delAndInsertBatch(StaffPatrolStatsFormDTO formDTO, List<StatsStaffPatrolRecordDailyDTO> insertList);
List<StatsStaffPatrolRecordDailyDTO> selectData(String customerId, String yesterdayStr);
}

3
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/UserService.java

@ -7,6 +7,7 @@ import com.epmet.dto.org.result.OrgStaffDTO;
import com.epmet.dto.screen.ScreenProjectDataDTO;
import com.epmet.dto.stats.user.result.UserStatisticalData;
import com.epmet.dto.user.result.CustomerStaffDTO;
import com.epmet.dto.user.result.StaffPatrolRecordResult;
import com.epmet.dto.user.result.StatsStaffPatrolRecordDailyDTO;
import com.epmet.entity.evaluationindex.screen.ScreenPartyUserRankDataEntity;
import com.epmet.util.DimIdGenerator;
@ -109,4 +110,6 @@ public interface UserService {
List<CustomerStaffDTO> selectUserListByRoleKey(StaffPatrolStatsFormDTO formDTO);
List<StatsStaffPatrolRecordDailyDTO> selectLastStaffPatrolList(StaffPatrolStatsFormDTO formDTO);
List<StaffPatrolRecordResult> selectStaffPatrolListByDateId(String customerId, String yesterdayStr);
}

30
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/impl/StatsStaffPatrolServiceImpl.java

@ -1,11 +1,17 @@
package com.epmet.service.user.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.epmet.commons.dynamic.datasource.annotation.DataSource;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.constant.DataSourceConstant;
import com.epmet.dao.user.StatsStaffPatrolRecordDailyDao;
import com.epmet.dto.extract.form.StaffPatrolStatsFormDTO;
import com.epmet.dto.user.result.StatsStaffPatrolRecordDailyDTO;
import com.epmet.entity.user.StatsStaffPatrolRecordDailyEntity;
import com.epmet.service.user.StatsStaffPatrolService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -18,6 +24,7 @@ import java.util.List;
* @date: 2021/6/30 8:33 上午
* @version: 1.0
*/
@Slf4j
@DataSource(DataSourceConstant.EPMET_USER)
@Service
public class StatsStaffPatrolServiceImpl implements StatsStaffPatrolService {
@ -25,7 +32,28 @@ public class StatsStaffPatrolServiceImpl implements StatsStaffPatrolService {
private StatsStaffPatrolRecordDailyDao statsStaffPatrolRecordDailyDao;
@Override
public Integer insertBatch(List<StatsStaffPatrolRecordDailyDTO> insertList) {
public Integer delAndInsertBatch(StaffPatrolStatsFormDTO formDTO, List<StatsStaffPatrolRecordDailyDTO> insertList) {
LambdaQueryWrapper<StatsStaffPatrolRecordDailyEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StatsStaffPatrolRecordDailyEntity::getCustomerId, formDTO.getCustomerId())
.eq(StatsStaffPatrolRecordDailyEntity::getDateId, formDTO.getDateId());
if (StringUtils.isNotBlank(formDTO.getGridId())) {
queryWrapper.eq(StatsStaffPatrolRecordDailyEntity::getGridId, formDTO.getGridId());
}
if (StringUtils.isNotBlank(formDTO.getStaffId())) {
queryWrapper.eq(StatsStaffPatrolRecordDailyEntity::getStaffId, formDTO.getStaffId());
}
int delete = statsStaffPatrolRecordDailyDao.delete(formDTO);
log.debug("delAndInsertBatch delete:{},param:{}", delete, JSON.toJSONString(formDTO));
return statsStaffPatrolRecordDailyDao.insertBatch(insertList);
}
@Override
public List<StatsStaffPatrolRecordDailyDTO> selectData(String customerId, String yesterdayStr) {
LambdaQueryWrapper<StatsStaffPatrolRecordDailyEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StatsStaffPatrolRecordDailyEntity::getCustomerId, customerId)
.eq(StatsStaffPatrolRecordDailyEntity::getDateId, yesterdayStr);
List<StatsStaffPatrolRecordDailyEntity> list = statsStaffPatrolRecordDailyDao.selectList(queryWrapper);
return ConvertUtils.sourceToTarget(list, StatsStaffPatrolRecordDailyDTO.class);
}
}

8
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/impl/UserServiceImpl.java

@ -18,6 +18,7 @@ import com.epmet.dto.stats.user.*;
import com.epmet.dto.stats.user.result.UserStatisticalData;
import com.epmet.dto.user.result.CommonTotalAndIncCountResultDTO;
import com.epmet.dto.user.result.CustomerStaffDTO;
import com.epmet.dto.user.result.StaffPatrolRecordResult;
import com.epmet.dto.user.result.StatsStaffPatrolRecordDailyDTO;
import com.epmet.entity.evaluationindex.screen.ScreenPartyUserRankDataEntity;
import com.epmet.service.user.UserService;
@ -803,7 +804,7 @@ public class UserServiceImpl implements UserService {
@Override
public List<CustomerStaffDTO> selectUserListByRoleKey(StaffPatrolStatsFormDTO formDTO) {
formDTO.setRoleType(RoleKeyConstants.ROLE_KEY_GRID_MEMBER);
formDTO.setRoleKey(RoleKeyConstants.ROLE_KEY_GRID_MEMBER);
return userDao.selectUserByRoleKey(formDTO);
}
@ -812,4 +813,9 @@ public class UserServiceImpl implements UserService {
return userDao.selectLastStaffPatrolList(formDTO);
}
@Override
public List<StaffPatrolRecordResult> selectStaffPatrolListByDateId(String customerId, String yesterdayStr) {
return userDao.selectStaffPatrolListByDateId(customerId,yesterdayStr);
}
}

10
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/org/CustomerStaffGridDao.xml

@ -5,13 +5,13 @@
<select id="selectGridStaffList" resultType="com.epmet.dto.user.result.StatsStaffPatrolRecordDailyDTO">
<!--排除掉pid为空的人-->
<select id="selectGridStaffList" resultType="com.epmet.dto.user.result.CustomerGridStaffDTO">
SELECT * FROM (
SELECT
sg.customer_id,
sg.user_id AS staffId,
sg.grid_id,
grid.grid_name,
sg.user_id,
grid.PID agencyId,
grid.PIDS gridPids
FROM
@ -19,11 +19,13 @@
LEFT JOIN customer_grid grid ON grid.id = sg.grid_id
WHERE
sg.del_flag = '0'
<if test="customerId != null and customerId != ''">
AND sg.customer_id = #{customerId}
</if>
<if test="gridId != null and gridId != ''">
AND sg.GRID_ID = #{gridId}
</if>
) t WHERE t.agencyId IS NOT NULL
</select>
</mapper>

7
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/project/ProjectDao.xml

@ -162,4 +162,11 @@
and CUSTOMER_ID = #{customerId}
and PARAMETER_KEY = #{parameterKey}
</select>
<select id="selectProjectListByDateId" resultType="com.epmet.dto.ProjectDTO">
SELECT * FROM project
WHERE customer_id = #{customerId}
AND ORIGIN = #{projectOrigin}
AND del_flag = '0'
AND DATE_FORMAT( CREATED_TIME, '%Y%m%d' ) = #{dateId}
</select>
</mapper>

11
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/user/StatsStaffPatrolRecordDailyDao.xml

@ -55,4 +55,15 @@
)
</foreach>
</insert>
<delete id="delete">
DELETE FROM stats_staff_patrol_record_daily
WHERE CUSTOMER_ID = #{customerId}
AND DATE_ID = #{dateId}
<if test="gridId != null and gridId != ''">
AND GRID_ID = #{gridId}
</if>
<if test="staffId != null and staffId != ''">
AND STAFF_ID = #{staffId}
</if>
</delete>
</mapper>

11
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/user/UserDao.xml

@ -582,7 +582,7 @@
LEFT JOIN gov_staff_role gsr ON gsr.ID = sr.ROLE_ID
WHERE
s.del_flag = '0'
AND gsr.ROLE_KEY = 'grid_member'
AND gsr.ROLE_KEY = #{roleKey}
</select>
<select id="selectLastStaffPatrolList" resultType="com.epmet.dto.user.result.StatsStaffPatrolRecordDailyDTO">
SELECT
@ -600,4 +600,13 @@
AND a.CUSTOMER_ID = #{customerId}
</select>
<select id="selectStaffPatrolListByDateId" resultType="com.epmet.dto.user.result.StaffPatrolRecordResult">
SELECT
r.*
FROM
staff_patrol_record r
WHERE
r.del_flag = '0' and r.customer_id = #{customerId}
AND DATE_FORMAT( r.ACTRUAL_END_TIME, '%Y%m%d' ) = #{dateId}
</select>
</mapper>

Loading…
Cancel
Save