Browse Source

巡查-001、各人员巡查记录列表查询

dev_shibei_match
sunyuchao 4 years ago
parent
commit
b7c4ba41b4
  1. 11
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/DateUtils.java
  2. 14
      epmet-module/data-aggregator/data-aggregator-client/src/main/java/com/epmet/dataaggre/dto/epmetuser/form/StaffListFormDTO.java
  3. 12
      epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/controller/EpmetUserController.java
  4. 10
      epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/dao/epmetuser/StaffPatrolRecordDao.java
  5. 8
      epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/dao/govorg/CustomerGridDao.java
  6. 41
      epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/epmetuser/impl/EpmetUserServiceImpl.java
  7. 8
      epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/GovOrgService.java
  8. 11
      epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java
  9. 45
      epmet-module/data-aggregator/data-aggregator-server/src/main/resources/mapper/epmetuser/StaffPatrolRecordDao.xml
  10. 22
      epmet-module/data-aggregator/data-aggregator-server/src/main/resources/mapper/govorg/CustomerGridDao.xml

11
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/DateUtils.java

@ -818,4 +818,15 @@ public class DateUtils {
return date;
}
/**
* @Author sun
* @Description 获取当前日期几个自然月之前的日期yyyy-MM-dd HH:mm:ss
**/
public static String getBeforeMonthDate(int beforMonth){
Calendar c = Calendar.getInstance();
c.add(Calendar.MONTH, - beforMonth);
Date date = c.getTime();
return DateUtils.format(date,DateUtils.DATE_TIME_PATTERN);
}
}

14
epmet-module/data-aggregator/data-aggregator-client/src/main/java/com/epmet/dataaggre/dto/epmetuser/form/StaffListFormDTO.java

@ -5,7 +5,10 @@ import lombok.Data;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* @Description 巡查-各人员巡查记录列表查询-接口入参
@ -18,7 +21,7 @@ public class StaffListFormDTO implements Serializable {
/**
* 近1一个月传1 近3个月传3自然月分
*/
@NotBlank(message = "最近时间不能为空", groups = StaffListFormDTO.Staff.class)
@NotNull(message = "最近时间不能为空", groups = StaffListFormDTO.Staff.class)
private Integer time;
/**
* 排序字段巡查总次数patrolTotal最近开始巡查时间latestPatrolledTime
@ -28,7 +31,7 @@ public class StaffListFormDTO implements Serializable {
/**
* 网格id集合为空则查询当前组织下所有网格数据
*/
private Integer gridIds;
private List<String> gridIds;
/**
* 工作人员姓名可空
*/
@ -42,7 +45,10 @@ public class StaffListFormDTO implements Serializable {
* 每页多少条
* */
private Integer pageSize = 20;
public interface Staff extends CustomerClientShowGroup {
}
//token中用户Id
private String userId;
//起止巡查开始时间
private String patrolStartTime;
public interface Staff extends CustomerClientShowGroup {}
}

12
epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/controller/EpmetUserController.java

@ -1,5 +1,8 @@
package com.epmet.dataaggre.controller;
import com.epmet.commons.tools.annotation.LoginUser;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.dataaggre.dto.datastats.form.SubAgencyFormDTO;
@ -34,8 +37,15 @@ public class EpmetUserController {
* @author sun
*/
@PostMapping("stafflist")
public Result<List<StaffListResultDTO>> staffList(@RequestBody StaffListFormDTO formDTO) {
public Result<List<StaffListResultDTO>> staffList(@LoginUser TokenDto tokenDto, @RequestBody StaffListFormDTO formDTO) {
ValidatorUtils.validateEntity(formDTO, StaffListFormDTO.Staff.class);
if (!"patrolTotal".equals(formDTO.getSortCode()) && !"latestPatrolledTime".equals(formDTO.getSortCode())) {
throw new RenException("参数错误,排序条件值错误");
}
if (formDTO.getTime() != 1 && formDTO.getTime() != 3) {
throw new RenException("参数错误,最近时间值不正确");
}
formDTO.setUserId(tokenDto.getUserId());
return new Result<List<StaffListResultDTO>>().ok(epmetUserService.staffList(formDTO));
}

10
epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/dao/epmetuser/StaffPatrolRecordDao.java

@ -19,9 +19,13 @@ package com.epmet.dataaggre.dao.epmetuser;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dataaggre.dto.epmetuser.form.StaffListFormDTO;
import com.epmet.dataaggre.dto.epmetuser.result.StaffListResultDTO;
import com.epmet.dataaggre.entity.epmetuser.StaffPatrolRecordEntity;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 工作人员巡查主记录
*
@ -31,4 +35,10 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface StaffPatrolRecordDao extends BaseDao<StaffPatrolRecordEntity> {
/**
* @Description 按条件查询巡查业务数据
* @author sun
*/
List<StaffListResultDTO> selectPatrolList(StaffListFormDTO formDTO);
}

8
epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/dao/govorg/CustomerGridDao.java

@ -18,6 +18,7 @@
package com.epmet.dataaggre.dao.govorg;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dataaggre.dto.govorg.CustomerGridDTO;
import com.epmet.dataaggre.dto.govorg.result.GridInfoResultDTO;
import com.epmet.dataaggre.dto.govorg.result.GridsInfoListResultDTO;
import com.epmet.dataaggre.entity.govorg.CustomerGridEntity;
@ -54,4 +55,11 @@ public interface CustomerGridDao extends BaseDao<CustomerGridEntity> {
* @Description 根据组织Id查询当前组织下所有网格列表
**/
List<GridInfoResultDTO> selectGridListByAgencyId(@Param("agencyId") String agencyId);
/**
* @param staffId
* @Author sun
* @Description 查询工作人员所属组织下网格列表
**/
List<CustomerGridDTO> gridListByStaffId(@Param("staffId") String staffId);
}

41
epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/epmetuser/impl/EpmetUserServiceImpl.java

@ -1,17 +1,25 @@
package com.epmet.dataaggre.service.epmetuser.impl;
import com.epmet.commons.dynamic.datasource.annotation.DataSource;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.dataaggre.constant.DataSourceConstant;
import com.epmet.dataaggre.dao.epmetuser.StaffPatrolRecordDao;
import com.epmet.dataaggre.dao.epmetuser.UserBaseInfoDao;
import com.epmet.dataaggre.dto.epmetuser.form.StaffListFormDTO;
import com.epmet.dataaggre.dto.epmetuser.result.StaffListResultDTO;
import com.epmet.dataaggre.dto.epmetuser.result.UserInfosResultDTO;
import com.epmet.dataaggre.dto.govorg.CustomerGridDTO;
import com.epmet.dataaggre.service.epmetuser.EpmetUserService;
import com.epmet.dataaggre.service.govorg.GovOrgService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Author zxc
@ -24,6 +32,10 @@ public class EpmetUserServiceImpl implements EpmetUserService {
@Autowired
private UserBaseInfoDao userBaseInfoDao;
@Autowired
private GovOrgService govOrgService;
@Autowired
private StaffPatrolRecordDao staffPatrolRecordDao;
/**
* @Description 根据UserIds查询
@ -54,7 +66,32 @@ public class EpmetUserServiceImpl implements EpmetUserService {
*/
@Override
public List<StaffListResultDTO> staffList(StaffListFormDTO formDTO) {
return null;
List<StaffListResultDTO> resultList = new ArrayList<>();
//1.设置分页参数
int num = (formDTO.getPageNo() - NumConstant.ONE) * formDTO.getPageSize();
formDTO.setPageNo(num);
//2.查询当前人员所属组织下网格列表数据,供后续使用
List<CustomerGridDTO> list = govOrgService.gridListByStaffId(formDTO.getUserId());
if (list.size() < NumConstant.ONE) {
return resultList;
}
//网格集合为空则查询当前人员所属组织下网格列表
if (CollectionUtils.isEmpty(formDTO.getGridIds())) {
formDTO.setGridIds(list.stream().map(CustomerGridDTO::getId).collect(Collectors.toList()));
}
//3.按条件查询巡查业务数据
formDTO.setPatrolStartTime(DateUtils.getBeforeMonthDate(formDTO.getTime()));
resultList = staffPatrolRecordDao.selectPatrolList(formDTO);
if (resultList.size() < NumConstant.ONE) {
return new ArrayList<>();
}
//4.封装数据并返回
resultList.forEach(re -> list.stream().filter(l -> re.getGridId().equals(l.getId())).forEach(s -> re.setGridName(s.getGridName())));
return resultList;
}
}

8
epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/GovOrgService.java

@ -1,5 +1,6 @@
package com.epmet.dataaggre.service.govorg;
import com.epmet.dataaggre.dto.govorg.CustomerGridDTO;
import com.epmet.dataaggre.dto.govorg.form.NextAreaCodeFormDTO;
import com.epmet.dataaggre.dto.govorg.result.AgencyGridResultDTO;
import com.epmet.dataaggre.dto.govorg.result.GridInfoResultDTO;
@ -48,4 +49,11 @@ public interface GovOrgService {
List<NextAreaCodeResultDTO> queryNextLevelAreaCodeList(NextAreaCodeFormDTO formDTO);
List<OrgInfoCommonDTO> queryNextOrgInfoDTO(String customerId, String orgId);
/**
* @param staffId
* @Author sun
* @Description 查询工作人员所属组织下网格列表
**/
List<CustomerGridDTO> gridListByStaffId(String staffId);
}

11
epmet-module/data-aggregator/data-aggregator-server/src/main/java/com/epmet/dataaggre/service/govorg/impl/GovOrgServiceImpl.java

@ -9,6 +9,7 @@ import com.epmet.dataaggre.constant.DataSourceConstant;
import com.epmet.dataaggre.dao.govorg.CustomerAgencyDao;
import com.epmet.dataaggre.dao.govorg.CustomerGridDao;
import com.epmet.dataaggre.dao.govorg.CustomerStaffAgencyDao;
import com.epmet.dataaggre.dto.govorg.CustomerGridDTO;
import com.epmet.dataaggre.dto.govorg.CustomerStaffAgencyDTO;
import com.epmet.dataaggre.dto.govorg.form.NextAreaCodeFormDTO;
import com.epmet.dataaggre.dto.govorg.result.AgencyGridResultDTO;
@ -225,5 +226,15 @@ public class GovOrgServiceImpl implements GovOrgService {
System.out.println(JSON.toJSONString(allList, true));
}
/**
* @param staffId
* @Author sun
* @Description 查询工作人员所属组织下网格列表
**/
@Override
public List<CustomerGridDTO> gridListByStaffId(String staffId) {
List<CustomerGridDTO> resultList = customerGridDao.gridListByStaffId(staffId);
return resultList;
}
}

45
epmet-module/data-aggregator/data-aggregator-server/src/main/resources/mapper/epmetuser/StaffPatrolRecordDao.xml

@ -3,5 +3,50 @@
<mapper namespace="com.epmet.dataaggre.dao.epmetuser.StaffPatrolRecordDao">
<select id="selectPatrolList" resultType="com.epmet.dataaggre.dto.epmetuser.result.StaffListResultDTO">
SELECT
spr.grid AS "gridId",
spr.staff_id AS "staffId",
MAX(spr.patrol_start_time) AS "patrolStartTime",
COUNT(spr.staff_id) AS "patrolTotal",
(
select
`status`
from
staff_patrol_record
where
grid = spr.grid
and staff_id = spr.staff_id
order by
patrol_start_time desc
limit 1
) AS "status",
cs.real_name AS "staffName",
cs.gender AS "gender"
FROM
staff_patrol_record spr
LEFT JOIN customer_staff cs ON spr.staff_id = cs.user_id
WHERE
spr.del_flag = '0'
<if test='patrolStartTime != "" and patrolStartTime != null'>
AND spr.patrol_start_time <![CDATA[ >= ]]> #{patrolStartTime}
</if>
<if test='staffName != "" and staffName != null'>
AND cs.real_name LIKE CONCAT('%',#{staffName},'%')
</if>
<foreach collection="gridIds" item="gridId" open="AND( " separator=" OR " close=")">
spr.GRID = #{gridId}
</foreach>
GROUP BY
spr.grid, spr.staff_id
<if test='sortCode != "" and sortCode != null and sortCode == "patrolTotal" '>
ORDER BY COUNT(spr.staff_id) DESC
</if>
<if test='sortCode != "" and sortCode != null and sortCode == "latestPatrolledTime" '>
ORDER BY MAX(spr.patrol_start_time) DESC
</if>
LIMIT
#{pageNo}, #{pageSize}
</select>
</mapper>

22
epmet-module/data-aggregator/data-aggregator-server/src/main/resources/mapper/govorg/CustomerGridDao.xml

@ -52,4 +52,26 @@
AND pid = #{agencyId}
</select>
<select id="gridListByStaffId" resultType="com.epmet.dataaggre.dto.govorg.CustomerGridDTO">
SELECT
cg.id AS 'id',
IF (
ca.organization_name = '',
cg.grid_name,
CONCAT(ca.organization_name,'-',cg.grid_name)
) AS 'gridName'
FROM
customer_grid cg
INNER JOIN customer_agency ca ON cg.pid = ca.id
WHERE
cg.del_flag = '0'
AND ca.del_flag = '0'
AND cg.pid = (
select agency_id
from customer_staff_agency
where del_flag = '0'
AND user_id = #{staffId}
)
</select>
</mapper>

Loading…
Cancel
Save