Browse Source

代码调整

dev_shibei_match
jianjun 4 years ago
parent
commit
b046aa7a69
  1. 5
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/dto/form/PageFormDTO.java
  2. 5
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/user/result/MidPatrolRecordResult.java
  3. 42
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/user/UserDao.xml
  4. 4
      epmet-module/open-data-worker/open-data-worker-client/src/main/java/com/epmet/opendata/dto/form/UpsertPatrolRecordForm.java
  5. 12
      epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/controller/InitDataController.java
  6. 3
      epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/UserPatrolDetailService.java
  7. 8
      epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/UserPatrolRecordService.java
  8. 13
      epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/UserPatrolDetailServiceImpl.java
  9. 87
      epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/UserPatrolRecordServiceImpl.java

5
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/dto/form/PageFormDTO.java

@ -30,11 +30,6 @@ public class PageFormDTO {
*/
private Integer offset;
/**
* 是否分页 默认分页
*/
private boolean isPage = true;
public Integer getOffset() {
return (pageNo-1)*pageSize;
}

5
epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/user/result/MidPatrolRecordResult.java

@ -129,4 +129,9 @@ public class MidPatrolRecordResult implements Serializable {
*/
private String longitude;
/**
* 经纬度组合成的路线 经度,维度;
*/
private String route;
}

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

@ -1006,20 +1006,38 @@
</select>
<select id="getPatrolRecordList" resultType="com.epmet.dto.user.result.MidPatrolRecordResult">
SELECT
id, customer_id, grid, grid_pids, staff_id, agency_id, patrol_start_time, patrol_end_time,
actrual_end_time, total_time, status, del_flag, revision, created_by, created_time, updated_by, updated_time
FROM staff_patrol_record
m.id,
m.customer_id,
m.grid,
m.grid_pids,
m.staff_id,
m.agency_id,
m.patrol_start_time,
m.patrol_end_time,
m.actrual_end_time,
m.total_time,
m.STATUS,
m.del_flag,
m.revision,
m.created_by,
m.created_time,
m.updated_by,
m.updated_time,
GROUP_CONCAT(d.LATITUDE,',',d.LONGITUDE ORDER BY d.CREATED_TIME ASC SEPARATOR ';') AS route
FROM
staff_patrol_record m
LEFT JOIN staff_patrol_detail d ON m.ID = d.STAFF_PATROL_REC_ID
WHERE
1=1
1 =1
<if test="patrolId != null and patrolId != ''">
AND ID = #{patrolId}
</if>
and CUSTOMER_ID = #{customerId}
AND DEL_FLAG = '0'
order by created_time
<if test="isPage != null and isPage">
LIMIT #{offset},#{pageSize}
</if>
and m.CUSTOMER_ID = #{customerId}
AND m.DEL_FLAG = '0'
GROUP BY m.ID
order by m.created_time
LIMIT #{offset},#{pageSize}
</select>
<select id="getPatrolDetailList" resultType="com.epmet.dto.user.result.MidPatrolDetailResult">
select
@ -1033,9 +1051,7 @@
and CUSTOMER_ID = #{customerId}
AND DEL_FLAG = '0'
order by created_time
<if test="isPage != null and isPage">
LIMIT #{offset},#{pageSize}
</if>
LIMIT #{offset},#{pageSize}
</select>
</mapper>

4
epmet-module/open-data-worker/open-data-worker-client/src/main/java/com/epmet/opendata/dto/form/UpsertPatrolRecordForm.java

@ -1,5 +1,6 @@
package com.epmet.opendata.dto.form;
import com.epmet.commons.tools.dto.form.PageFormDTO;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
@ -9,7 +10,7 @@ import javax.validation.constraints.NotEmpty;
* @author liujianjun
*/
@Data
public class UpsertPatrolRecordForm {
public class UpsertPatrolRecordForm extends PageFormDTO {
/**
* 客户Id
*/
@ -19,7 +20,6 @@ public class UpsertPatrolRecordForm {
/**
* 巡查记录id
*/
@NotEmpty(message = "patrolId不能为空")
private String patrolId;
/**

12
epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/controller/InitDataController.java

@ -18,10 +18,14 @@
package com.epmet.opendata.controller;
import com.epmet.commons.tools.utils.Result;
import com.epmet.constant.SystemMessageType;
import com.epmet.opendata.dto.form.UpsertPatrolRecordForm;
import com.epmet.opendata.service.UserPatrolRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
@ -42,9 +46,7 @@ public class InitDataController {
* @Description 网格员信息中间库同步
**/
@PostMapping("patrol/{customerId}")
public Result<Boolean> getStaffBaseInfo(@PathVariable String customerId) {
UpsertPatrolRecordForm formDTO = new UpsertPatrolRecordForm();
formDTO.setCustomerId(customerId);
return new Result().ok(userPatrolRecordService.insertPatrolRecord(formDTO));
public Result<Boolean> reloadPatrolData(@PathVariable String customerId) {
return new Result().ok(userPatrolRecordService.reloadPatrolData(customerId));
}
}

3
epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/UserPatrolDetailService.java

@ -29,4 +29,7 @@ import com.epmet.opendata.entity.UserPatrolDetailEntity;
public interface UserPatrolDetailService extends BaseService<UserPatrolDetailEntity> {
int deleteByPatrolId(String patrolId);
int deleteByCustomerId(String customerId);
}

8
epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/UserPatrolRecordService.java

@ -42,4 +42,12 @@ public interface UserPatrolRecordService extends BaseService<UserPatrolRecordEnt
* @return
*/
Boolean updatePatrolRecord(UpsertPatrolRecordForm patrolRecordForm);
/**
* desc重新加载数据
* @param customerId
* @return
*/
Boolean reloadPatrolData(String customerId);
}

13
epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/UserPatrolDetailServiceImpl.java

@ -17,6 +17,7 @@
package com.epmet.opendata.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.opendata.dao.UserPatrolDetailDao;
import com.epmet.opendata.entity.UserPatrolDetailEntity;
@ -33,5 +34,17 @@ import org.springframework.stereotype.Service;
public class UserPatrolDetailServiceImpl extends BaseServiceImpl<UserPatrolDetailDao, UserPatrolDetailEntity> implements UserPatrolDetailService {
@Override
public int deleteByPatrolId(String patrolId) {
LambdaQueryWrapper<UserPatrolDetailEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(UserPatrolDetailEntity::getStaffPatrolRecId, patrolId);
return baseDao.delete(wrapper);
}
@Override
public int deleteByCustomerId(String customerId) {
LambdaQueryWrapper<UserPatrolDetailEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(UserPatrolDetailEntity::getCustomerId, customerId);
return baseDao.delete(wrapper);
}
}

87
epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/UserPatrolRecordServiceImpl.java

@ -18,21 +18,19 @@
package com.epmet.opendata.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.dto.user.param.MidPatrolFormDTO;
import com.epmet.dto.user.result.MidPatrolDetailResult;
import com.epmet.dto.user.result.MidPatrolRecordResult;
import com.epmet.feign.DataStatisticalOpenFeignClient;
import com.epmet.opendata.dao.UserPatrolDetailDao;
import com.epmet.opendata.dao.UserPatrolRecordDao;
import com.epmet.opendata.dto.form.UpsertPatrolRecordForm;
import com.epmet.opendata.entity.UserPatrolDetailEntity;
import com.epmet.opendata.entity.UserPatrolRecordEntity;
import com.epmet.opendata.service.UserPatrolDetailService;
import com.epmet.opendata.service.UserPatrolRecordService;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
@ -57,13 +55,12 @@ public class UserPatrolRecordServiceImpl extends BaseServiceImpl<UserPatrolRecor
@Autowired
private DataStatisticalOpenFeignClient dataStatisticalOpenFeignClient;
@Autowired
private UserPatrolDetailDao userPatrolDetailDao;
private UserPatrolDetailService userPatrolDetailService;
@Override
public Boolean insertPatrolRecord(UpsertPatrolRecordForm patrolRecordForm) {
log.info("upsertPatrolRecord param:{}", JSON.toJSONString(patrolRecordForm));
ValidatorUtils.validateEntity(patrolRecordForm);
boolean delFlag = false;
MidPatrolFormDTO midPatrolFormDTO = buildParam(patrolRecordForm);
Result<List<MidPatrolRecordResult>> record = dataStatisticalOpenFeignClient.getPatrolRecordList(midPatrolFormDTO);
if (record == null || !record.success()) {
@ -73,7 +70,6 @@ public class UserPatrolRecordServiceImpl extends BaseServiceImpl<UserPatrolRecor
List<MidPatrolRecordResult> data = record.getData();
if (CollectionUtils.isEmpty(data)) {
//数据已被删除了
delFlag = true;
//暂时设置error 用于排错
log.error("获取巡查记录返回为空,param:{}", JSON.toJSONString(midPatrolFormDTO));
int effectRow = baseDao.deleteById(patrolRecordForm.getPatrolId());
@ -117,37 +113,82 @@ public class UserPatrolRecordServiceImpl extends BaseServiceImpl<UserPatrolRecor
if (effectRow == NumConstant.ZERO) {
baseDao.insert(recordEntity);
}
midPatrolFormDTO.setPage(false);
//todo 过滤掉巡查结束时间之后的轨迹
Result<List<MidPatrolDetailResult>> detailResult = dataStatisticalOpenFeignClient.getPatrolDetailList(midPatrolFormDTO);
if (detailResult == null || !detailResult.success()) {
log.error("获取巡查记录明细失败,param:{}", JSON.toJSONString(midPatrolFormDTO));
return;
}
UserPatrolDetailEntity detailEntity = buildDetailEntity(o, detailResult);
UserPatrolDetailEntity detailEntity = buildDetailEntity(o);
//先删除再新增
LambdaQueryWrapper<UserPatrolDetailEntity> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(UserPatrolDetailEntity::getStaffPatrolRecId, recordEntity.getId());
userPatrolDetailDao.delete(wrapper);
int insert = userPatrolDetailDao.insert(detailEntity);
userPatrolDetailService.deleteByPatrolId(recordEntity.getId());
boolean insert = userPatrolDetailService.insert(detailEntity);
});
return true;
}
@Override
public Boolean reloadPatrolData(String customerId) {
int pageNo = 1;
int pageSize = 1000;
List<MidPatrolRecordResult> resultList = null;
do {
MidPatrolFormDTO param = new MidPatrolFormDTO();
param.setCustomerId(customerId);
param.setPageNo(pageNo++);
param.setPageSize(pageSize);
Result<List<MidPatrolRecordResult>> record = dataStatisticalOpenFeignClient.getPatrolRecordList(param);
if (record == null || !record.success()) {
log.error("获取巡查记录失败,param:{}", JSON.toJSONString(param));
return false;
}
resultList = record.getData();
if (CollectionUtils.isEmpty(resultList)){
log.warn("不存在巡查记录,param:{}", JSON.toJSONString(param));
return false;
}
insertRecordBatch(resultList,true);
}while (!CollectionUtils.isEmpty(resultList) && resultList.size()> pageSize );
return null;
}
private Boolean insertRecordBatch(List<MidPatrolRecordResult> list,boolean isReload){
List<UserPatrolRecordEntity> insertList = new ArrayList<>();
list.forEach(o-> insertList.add(buildEntity(o)));
//insert
if (CollectionUtils.isEmpty(insertList)){
log.error("构建要插入的数据为空,param:{}", JSON.toJSONString(list));
return false;
}
if (isReload){
userPatrolDetailService.deleteByCustomerId(list.get(0).getCustomerId());
}
this.insertBatch(insertList, NumConstant.ONE_HUNDRED);
List<UserPatrolDetailEntity> insertDetailList = new ArrayList<>();
list.forEach(o-> {
insertDetailList.add(buildDetailEntity(o));
if (!isReload){
//先删除再新增
userPatrolDetailService.deleteByPatrolId(o.getId());
}
});
if (CollectionUtils.isEmpty(insertList)){
log.warn("构建要插入的数据为空,param:{}", JSON.toJSONString(list));
}
userPatrolDetailService.insertBatch(insertDetailList, NumConstant.ONE_HUNDRED);
return true;
}
@NotNull
private UserPatrolDetailEntity buildDetailEntity(MidPatrolRecordResult recordResult, Result<List<MidPatrolDetailResult>> detailResult) {
private UserPatrolDetailEntity buildDetailEntity(MidPatrolRecordResult recordResult) {
UserPatrolDetailEntity detailEntity = new UserPatrolDetailEntity();
detailEntity.setCustomerId(recordResult.getCustomerId());
detailEntity.setStaffPatrolRecId(recordResult.getId());
StringBuilder sb = new StringBuilder();
detailResult.getData().forEach(o -> {
sb.append(o.getLongitude())
.append(StrConstant.COMMA)
.append(o.getLatitude())
.append(StrConstant.SEMICOLON);
});
detailEntity.setRoute(sb.toString());
detailEntity.setRoute(recordResult.getRoute());
detailEntity.setId(recordResult.getId());
detailEntity.setRevision(recordResult.getRevision());
detailEntity.setCreatedBy(recordResult.getCreatedBy());
@ -188,8 +229,8 @@ public class UserPatrolRecordServiceImpl extends BaseServiceImpl<UserPatrolRecor
MidPatrolFormDTO midPatrolFormDTO = new MidPatrolFormDTO();
midPatrolFormDTO.setCustomerId(patrolRecordForm.getCustomerId());
midPatrolFormDTO.setPatrolId(patrolRecordForm.getPatrolId());
midPatrolFormDTO.setPageNo(1);
midPatrolFormDTO.setPageSize(1);
midPatrolFormDTO.setPageNo(patrolRecordForm.getPageNo());
midPatrolFormDTO.setPageSize(patrolRecordForm.getPageSize());
return midPatrolFormDTO;
}
}

Loading…
Cancel
Save