|
@ -1,3 +1,20 @@ |
|
|
|
|
|
/** |
|
|
|
|
|
* 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.opendata.service.impl; |
|
|
package com.epmet.opendata.service.impl; |
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSON; |
|
@ -6,12 +23,7 @@ import com.epmet.commons.tools.constant.NumConstant; |
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
import com.epmet.commons.tools.redis.common.CustomerOrgRedis; |
|
|
|
|
|
import com.epmet.commons.tools.redis.common.bean.GridInfoCache; |
|
|
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.utils.StrUtil; |
|
|
|
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
import com.epmet.commons.tools.validator.group.AddGroup; |
|
|
import com.epmet.commons.tools.validator.group.AddGroup; |
|
|
import com.epmet.dto.form.patrol.PatrolQueryFormDTO; |
|
|
import com.epmet.dto.form.patrol.PatrolQueryFormDTO; |
|
@ -20,18 +32,15 @@ import com.epmet.feign.EpmetUserOpenFeignClient; |
|
|
import com.epmet.opendata.dao.BaseGridDailyworkDao; |
|
|
import com.epmet.opendata.dao.BaseGridDailyworkDao; |
|
|
import com.epmet.opendata.dto.ExDeptDTO; |
|
|
import com.epmet.opendata.dto.ExDeptDTO; |
|
|
import com.epmet.opendata.dto.ExUserDTO; |
|
|
import com.epmet.opendata.dto.ExUserDTO; |
|
|
import com.epmet.opendata.dto.form.HistoryDataSyncFormDTO; |
|
|
|
|
|
import com.epmet.opendata.dto.form.UpsertPatrolRecordForm; |
|
|
import com.epmet.opendata.dto.form.UpsertPatrolRecordForm; |
|
|
import com.epmet.opendata.entity.BaseGridDailyworkEntity; |
|
|
import com.epmet.opendata.entity.BaseGridDailyworkEntity; |
|
|
import com.epmet.opendata.entity.GridstaffWorkInfoPingyinEntity; |
|
|
import com.epmet.opendata.service.BaseGridDailyworkService; |
|
|
import com.epmet.opendata.service.*; |
|
|
import com.epmet.opendata.service.ExDeptService; |
|
|
|
|
|
import com.epmet.opendata.service.ExUserService; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.apache.commons.collections4.ListUtils; |
|
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
import org.jetbrains.annotations.NotNull; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
@ -55,12 +64,6 @@ public class BaseGridDailyworkServiceImpl extends BaseServiceImpl<BaseGridDailyw |
|
|
private ExDeptService exDeptService; |
|
|
private ExDeptService exDeptService; |
|
|
@Autowired |
|
|
@Autowired |
|
|
private ExUserService exUserService; |
|
|
private ExUserService exUserService; |
|
|
@Autowired |
|
|
|
|
|
private GridstaffWorkInfoPingyinService pingYinService; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private GridstaffInfoPingyinService gridstaffInfoPingyinService; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private GridInfoPingyinService gridInfoPingyinService; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public Boolean insertBaseGridWorkRecord(UpsertPatrolRecordForm patrolRecordForm) { |
|
|
public Boolean insertBaseGridWorkRecord(UpsertPatrolRecordForm patrolRecordForm) { |
|
@ -114,7 +117,6 @@ public class BaseGridDailyworkServiceImpl extends BaseServiceImpl<BaseGridDailyw |
|
|
|
|
|
|
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private Boolean insertRecordBatch(List<PatrolRoutineWorkResult> list, Map<String, ExDeptDTO> deptMap, Map<String, ExUserDTO> userMap){ |
|
|
private Boolean insertRecordBatch(List<PatrolRoutineWorkResult> list, Map<String, ExDeptDTO> deptMap, Map<String, ExUserDTO> userMap){ |
|
|
List<BaseGridDailyworkEntity> insertList = new ArrayList<>(); |
|
|
List<BaseGridDailyworkEntity> insertList = new ArrayList<>(); |
|
|
list.forEach(o-> insertList.add(buildEntity(o, deptMap, userMap))); |
|
|
list.forEach(o-> insertList.add(buildEntity(o, deptMap, userMap))); |
|
@ -128,6 +130,7 @@ public class BaseGridDailyworkServiceImpl extends BaseServiceImpl<BaseGridDailyw |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private BaseGridDailyworkEntity buildEntity(PatrolRoutineWorkResult record, Map<String, ExDeptDTO> deptMap, Map<String, ExUserDTO> userMap) { |
|
|
private BaseGridDailyworkEntity buildEntity(PatrolRoutineWorkResult record, Map<String, ExDeptDTO> deptMap, Map<String, ExUserDTO> userMap) { |
|
|
BaseGridDailyworkEntity entity = new BaseGridDailyworkEntity(); |
|
|
BaseGridDailyworkEntity entity = new BaseGridDailyworkEntity(); |
|
|
entity.setCustomerId(record.getCustomerId()); |
|
|
entity.setCustomerId(record.getCustomerId()); |
|
@ -175,132 +178,9 @@ public class BaseGridDailyworkServiceImpl extends BaseServiceImpl<BaseGridDailyw |
|
|
private PatrolQueryFormDTO buildParam(UpsertPatrolRecordForm patrolRecordForm) { |
|
|
private PatrolQueryFormDTO buildParam(UpsertPatrolRecordForm patrolRecordForm) { |
|
|
PatrolQueryFormDTO midPatrolFormDTO = new PatrolQueryFormDTO(); |
|
|
PatrolQueryFormDTO midPatrolFormDTO = new PatrolQueryFormDTO(); |
|
|
midPatrolFormDTO.setCustomerId(patrolRecordForm.getCustomerId()); |
|
|
midPatrolFormDTO.setCustomerId(patrolRecordForm.getCustomerId()); |
|
|
midPatrolFormDTO.setId(StringUtils.isBlank(patrolRecordForm.getId()) ? "" : patrolRecordForm.getId()); |
|
|
midPatrolFormDTO.setId(patrolRecordForm.getId()); |
|
|
midPatrolFormDTO.setPageNo(patrolRecordForm.getPageNo()); |
|
|
midPatrolFormDTO.setPageNo(patrolRecordForm.getPageNo()); |
|
|
midPatrolFormDTO.setPageSize(NumConstant.ONE_THOUSAND); |
|
|
midPatrolFormDTO.setPageSize(patrolRecordForm.getPageSize()); |
|
|
return midPatrolFormDTO; |
|
|
return midPatrolFormDTO; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private GridstaffWorkInfoPingyinEntity buildNewEntity(PatrolRoutineWorkResult record) { |
|
|
|
|
|
GridstaffWorkInfoPingyinEntity entity = ConvertUtils.sourceToTarget(record, GridstaffWorkInfoPingyinEntity.class); |
|
|
|
|
|
entity.setQxBm("370124"); |
|
|
|
|
|
entity.setQxMc("平阴县"); |
|
|
|
|
|
entity.setHappenTime(DateUtils.parseDate(record.getHappenTime().concat(" 00:00:00"),DateUtils.DATE_PATTERN)); |
|
|
|
|
|
entity.setWorkResult(NumConstant.ONE == record.getIsNormal()? "Y":"N"); |
|
|
|
|
|
entity.setWorkType(record.getWorkTypeSecondCode()); |
|
|
|
|
|
entity.setRecoredInsertTime(record.getCreatedTime()); |
|
|
|
|
|
entity.setUpdateTime(record.getUpdatedTime()); |
|
|
|
|
|
entity.setId(null); |
|
|
|
|
|
entity.setIsDel(NumConstant.ZERO_STR); |
|
|
|
|
|
return entity; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public Boolean insertBaseGridWorkRecordV2(UpsertPatrolRecordForm patrolRecordForm) { |
|
|
|
|
|
log.info("insertBaseGridWorkRecordV2 param:{}", JSON.toJSONString(patrolRecordForm)); |
|
|
|
|
|
ValidatorUtils.validateEntity(patrolRecordForm, AddGroup.class); |
|
|
|
|
|
// 构建传参
|
|
|
|
|
|
PatrolQueryFormDTO midPatrolFormDTO = buildParam(patrolRecordForm); |
|
|
|
|
|
if (StringUtils.isBlank(patrolRecordForm.getId())){ |
|
|
|
|
|
Integer row; |
|
|
|
|
|
do { |
|
|
|
|
|
row = pingYinService.delAllGridStaffWorkInfoPY(); |
|
|
|
|
|
}while (row == NumConstant.ONE_THOUSAND); |
|
|
|
|
|
} |
|
|
|
|
|
List<PatrolRoutineWorkResult> data; |
|
|
|
|
|
do { |
|
|
|
|
|
Result<List<PatrolRoutineWorkResult>> record = epmetUserOpenFeignClient.getPatrolRoutineWorkListV2(midPatrolFormDTO); |
|
|
|
|
|
midPatrolFormDTO.setPageNo(midPatrolFormDTO.getPageNo() + 1); |
|
|
|
|
|
if (record == null || !record.success()) { |
|
|
|
|
|
log.error("获取例行工作记录V2失败,param:{}", JSON.toJSONString(midPatrolFormDTO)); |
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode()); |
|
|
|
|
|
} |
|
|
|
|
|
data = record.getData(); |
|
|
|
|
|
if (CollectionUtils.isEmpty(data)) { |
|
|
|
|
|
//数据已被删除了
|
|
|
|
|
|
//暂时设置error 用于排错
|
|
|
|
|
|
log.error("获取例行工作记录返回为空,param:{}", JSON.toJSONString(midPatrolFormDTO)); |
|
|
|
|
|
int effectRow = baseDao.deleteById(patrolRecordForm.getId()); |
|
|
|
|
|
log.warn("del effectRow:{}", effectRow); |
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode()); |
|
|
|
|
|
} |
|
|
|
|
|
data.forEach(d -> { |
|
|
|
|
|
GridInfoCache gridInfo = CustomerOrgRedis.getGridInfo(d.getGridId()); |
|
|
|
|
|
if (null == gridInfo){ |
|
|
|
|
|
log.warn("未查询到网格信息:"+ d.getGridId()); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
String s = StrUtil.filterEmoji(d.getWorkContent()); |
|
|
|
|
|
d.setWorkContent(s); |
|
|
|
|
|
d.setGridCode(gridInfo.getCode()); |
|
|
|
|
|
d.setGridName(gridInfo.getGridName()); |
|
|
|
|
|
}); |
|
|
|
|
|
insertNewRecordBatch(data); |
|
|
|
|
|
|
|
|
|
|
|
}while (data.size() == NumConstant.ONE_THOUSAND); |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Desc: 历史数据处理 |
|
|
|
|
|
* @param formDTO |
|
|
|
|
|
* @author zxc |
|
|
|
|
|
* @date 2022/7/22 13:24 |
|
|
|
|
|
*/ |
|
|
|
|
|
@Override |
|
|
|
|
|
public void historyDataSync(HistoryDataSyncFormDTO formDTO) { |
|
|
|
|
|
Integer pageSize = NumConstant.ONE_THOUSAND; |
|
|
|
|
|
Integer pageNo = NumConstant.ONE; |
|
|
|
|
|
List<BaseGridDailyworkEntity> baseGridDailyWork; |
|
|
|
|
|
do { |
|
|
|
|
|
baseGridDailyWork = baseDao.getBaseGridDailyWork(formDTO.getCustomerId(),(pageNo - NumConstant.ONE) * pageSize); |
|
|
|
|
|
List<GridstaffWorkInfoPingyinEntity> newEntities = ConvertUtils.sourceToTarget(baseGridDailyWork, GridstaffWorkInfoPingyinEntity.class); |
|
|
|
|
|
newEntities.forEach(n -> { |
|
|
|
|
|
GridInfoCache gridInfo = CustomerOrgRedis.getGridInfo(n.getGridId()); |
|
|
|
|
|
if (null == gridInfo){ |
|
|
|
|
|
throw new EpmetException("未查询到网格信息:"+ n.getGridId()); |
|
|
|
|
|
} |
|
|
|
|
|
n.setGridCode(gridInfo.getCode()); |
|
|
|
|
|
n.setHappenTime(DateUtils.parseDate(n.getHappenTimeString(),DateUtils.DATE_PATTERN)); |
|
|
|
|
|
n.setIsDel(NumConstant.ZERO_STR); |
|
|
|
|
|
}); |
|
|
|
|
|
insertGridStaffWorkInfoPY(newEntities); |
|
|
|
|
|
pageNo++; |
|
|
|
|
|
}while (baseGridDailyWork.size() == NumConstant.ONE_THOUSAND); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Desc: 数据存入 |
|
|
|
|
|
* @param newEntities |
|
|
|
|
|
* @author zxc |
|
|
|
|
|
* @date 2022/7/22 14:17 |
|
|
|
|
|
*/ |
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
|
public void insertGridStaffWorkInfoPY(List<GridstaffWorkInfoPingyinEntity> newEntities){ |
|
|
|
|
|
if (!CollectionUtils.isEmpty(newEntities)){ |
|
|
|
|
|
List<List<GridstaffWorkInfoPingyinEntity>> partition = ListUtils.partition(newEntities, NumConstant.ONE_HUNDRED); |
|
|
|
|
|
partition.forEach(p -> { |
|
|
|
|
|
pingYinService.insertBatch(p); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Boolean insertNewRecordBatch(List<PatrolRoutineWorkResult> list){ |
|
|
|
|
|
List<GridstaffWorkInfoPingyinEntity> insertList = new ArrayList<>(); |
|
|
|
|
|
list.forEach(o-> { |
|
|
|
|
|
if (StringUtils.isBlank(o.getGridCode())){ |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
insertList.add(buildNewEntity(o)); |
|
|
|
|
|
}); |
|
|
|
|
|
//insert
|
|
|
|
|
|
if (CollectionUtils.isEmpty(insertList)){ |
|
|
|
|
|
log.error("新构建要插入的数据为空,param:{}", JSON.toJSONString(list)); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
insertGridStaffWorkInfoPY(insertList); |
|
|
|
|
|
// pingYinService.saveOrUpdateBatch(insertList, NumConstant.ONE_HUNDRED);
|
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|