+ * 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.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.epmet.opendata.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
+import com.epmet.commons.tools.constant.FieldConstant;
+import com.epmet.commons.tools.page.PageData;
+import com.epmet.commons.tools.utils.ConvertUtils;
+import com.epmet.opendata.dao.ExDeptDao;
+import com.epmet.opendata.dto.ExDeptDTO;
+import com.epmet.opendata.entity.ExDeptEntity;
+import com.epmet.opendata.service.ExDeptService;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * 部门(网格)中间表
+ *
+ * @author generator generator@elink-cn.com
+ * @since v1.0.0 2021-10-19
+ */
+@Service
+public class ExDeptServiceImpl extends BaseServiceImpl implements ExDeptService {
+
+
+ @Override
+ public PageData page(Map params) {
+ IPage page = baseDao.selectPage(
+ getPage(params, FieldConstant.CREATED_TIME, false),
+ getWrapper(params)
+ );
+ return getPageData(page, ExDeptDTO.class);
+ }
+
+ @Override
+ public List list(Map params) {
+ List entityList = baseDao.selectList(getWrapper(params));
+
+ return ConvertUtils.sourceToTarget(entityList, ExDeptDTO.class);
+ }
+
+ private QueryWrapper getWrapper(Map params){
+ String id = (String)params.get(FieldConstant.ID_HUMP);
+
+ QueryWrapper wrapper = new QueryWrapper<>();
+ wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id);
+
+ return wrapper;
+ }
+
+ @Override
+ public ExDeptDTO get(String id) {
+ ExDeptEntity entity = baseDao.selectById(id);
+ return ConvertUtils.sourceToTarget(entity, ExDeptDTO.class);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void save(ExDeptDTO dto) {
+ ExDeptEntity entity = ConvertUtils.sourceToTarget(dto, ExDeptEntity.class);
+ insert(entity);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void update(ExDeptDTO dto) {
+ ExDeptEntity entity = ConvertUtils.sourceToTarget(dto, ExDeptEntity.class);
+ updateById(entity);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void delete(String[] ids) {
+ // 逻辑删除(@TableLogic 注解)
+ baseDao.deleteBatchIds(Arrays.asList(ids));
+ }
+
+ @Override
+ public Map getDeptMap() {
+ LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>();
+ List entityList = baseDao.selectList(wrapper);
+ if (CollectionUtils.isEmpty(entityList)) {
+ return Collections.emptyMap();
+ }
+ return entityList.stream().collect(Collectors.toMap(ExDeptEntity::getGridCode, ExDeptEntity::getDeptId, (key1, key2) -> key2));
+ }
+
+}
\ No newline at end of file
diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/UserPatrolDetailServiceImpl.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/UserPatrolDetailServiceImpl.java
index e5b0956b16..a8e9b220bc 100644
--- a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/UserPatrolDetailServiceImpl.java
+++ b/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 implements UserPatrolDetailService {
+ @Override
+ public int deleteByPatrolId(String patrolId) {
+ LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>();
+ wrapper.eq(UserPatrolDetailEntity::getStaffPatrolRecId, patrolId);
+ return baseDao.delete(wrapper);
+ }
+ @Override
+ public int deleteByCustomerId(String customerId) {
+ LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>();
+ wrapper.eq(UserPatrolDetailEntity::getCustomerId, customerId);
+ return baseDao.delete(wrapper);
+ }
}
diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/UserPatrolRecordServiceImpl.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/UserPatrolRecordServiceImpl.java
index 105b170038..0a5312e602 100644
--- a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/UserPatrolRecordServiceImpl.java
+++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/UserPatrolRecordServiceImpl.java
@@ -21,18 +21,16 @@ 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> record = dataStatisticalOpenFeignClient.getPatrolRecordList(midPatrolFormDTO);
if (record == null || !record.success()) {
@@ -73,7 +70,6 @@ public class UserPatrolRecordServiceImpl extends BaseServiceImpl 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,81 @@ public class UserPatrolRecordServiceImpl extends BaseServiceImpl> 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 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 resultList = null;
+ do {
+ MidPatrolFormDTO param = new MidPatrolFormDTO();
+ param.setCustomerId(customerId);
+ param.setPageNo(pageNo++);
+ param.setPageSize(pageSize);
+ Result> 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 list,boolean isReload){
+ List 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){
+ int i = userPatrolDetailService.deleteByCustomerId(list.get(0).getCustomerId());
+ log.info("insertRecordBatch del patrol effectRow:{}",i);
+ }
+ LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>();
+ wrapper.eq(UserPatrolRecordEntity::getCustomerId, list.get(0).getCustomerId());
+ int delete = baseDao.delete(wrapper);
+ log.info("insertRecordBatch del patrol effectRow:{}",delete);
+ this.insertBatch(insertList, NumConstant.ONE_HUNDRED);
+ List 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> 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 +228,8 @@ public class UserPatrolRecordServiceImpl extends BaseServiceImpl
+
+
+
+
+
+
+
+
+
+
+
UPDATE ex_dept