diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java index 04db67cfed..05e5c200a4 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java @@ -10,6 +10,8 @@ package com.epmet.commons.tools.redis; import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.constant.StrConstant; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.utils.DateUtils; import org.apache.commons.lang3.StringUtils; @@ -763,4 +765,16 @@ public class RedisKeys { public static String getNextAreaCodeKey(String areaCode) { return rootPrefix.concat("areaCode:parentCode:").concat(areaCode); } + + /** + * desc:获取分布式锁key + * @param methodName + * @return + */ + public static String getLockByMethodName(String methodName) { + if (StringUtils.isBlank(methodName)){ + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"参数错误"); + } + return rootPrefix.concat("lock:").concat(methodName); + } } diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/bean/AgencyInfoCache.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/bean/AgencyInfoCache.java index 1a842d3987..c9e908d7da 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/bean/AgencyInfoCache.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/common/bean/AgencyInfoCache.java @@ -145,4 +145,26 @@ public class AgencyInfoCache implements Serializable { * 中心位置纬度 */ private String latitude; + + /** + * 组织编码 + */ + private String code; + + /** + * 负责人姓名 + */ + private String contacts; + + /** + * 联系电话 + */ + private String mobile; + + + //内部接口使用 + /** + * open:当前客户新增组织需要选择areaCode;closed: 无需选择区域编码 + */ + private String areaCodeSwitch; } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/redis/CustomerAgencyRedis.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/redis/CustomerAgencyRedis.java index fb65a508d5..a4be0f2703 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/redis/CustomerAgencyRedis.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/redis/CustomerAgencyRedis.java @@ -20,7 +20,7 @@ package com.epmet.redis; import cn.hutool.core.bean.BeanUtil; import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.redis.RedisUtils; -import com.epmet.dto.CustomerAgencyDTO; +import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; @@ -44,19 +44,19 @@ public class CustomerAgencyRedis { redisUtils.delete(key); } - public void set(String agencyId, CustomerAgencyDTO value){ + public void set(String agencyId, AgencyInfoCache value){ String key = RedisKeys.getAgencyByIdKey(agencyId); Map map = BeanUtil.beanToMap(value, false, true); redisUtils.hMSet(key, map); } - public CustomerAgencyDTO get(String agencyId){ + public AgencyInfoCache get(String agencyId){ String key = RedisKeys.getAgencyByIdKey(agencyId); Map resultMap = redisUtils.hGetAll(key); if (CollectionUtils.isEmpty(resultMap)) { return null; } - return BeanUtil.mapToBean(resultMap, CustomerAgencyDTO.class, true); + return BeanUtil.mapToBean(resultMap, AgencyInfoCache.class, true); } } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java index 7a81bd7fd0..c07985347c 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/AgencyServiceImpl.java @@ -20,6 +20,7 @@ package com.epmet.service.impl; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.epmet.commons.tools.constant.Constant; import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; @@ -490,16 +491,53 @@ public class AgencyServiceImpl implements AgencyService { @Override public CustomerAgencyDTO getAgencyById(String agencyId) { - CustomerAgencyDTO cachedAgency = customerAgencyRedis.get(agencyId); - if (cachedAgency == null) { - cachedAgency = new CustomerAgencyDTO(); + AgencyInfoCache agencyInfoCache = customerAgencyRedis.get(agencyId); + if (agencyInfoCache == null) { + agencyInfoCache = new AgencyInfoCache(); CustomerAgencyEntity agencyEntity = customerAgencyDao.selectById(agencyId); if (agencyEntity != null) { - BeanUtils.copyProperties(agencyEntity, cachedAgency); + //设置行政地区编码全路径 + if (StringUtils.isNotBlank(agencyEntity.getAreaCode()) && StringUtils.isNotBlank(agencyEntity.getParentAreaCode())) { + agencyInfoCache.setAreaCodePath(queryAreaCodePath(agencyEntity)); + } + BeanUtils.copyProperties(agencyEntity, agencyInfoCache); } - customerAgencyRedis.set(agencyId, cachedAgency); + customerAgencyRedis.set(agencyId, agencyInfoCache); + } + CustomerAgencyDTO customerAgencyDTO=ConvertUtils.sourceToTarget(agencyInfoCache,CustomerAgencyDTO.class); + return customerAgencyDTO; + } + + private List queryAreaCodePath(CustomerAgencyEntity customerAgencyEntity) { + List areaCodePath = new ArrayList<>(); + switch (customerAgencyEntity.getLevel()) { + case Constant.COMMUNITY: + areaCodePath.add(customerAgencyEntity.getAreaCode().substring(NumConstant.ZERO, NumConstant.TWO)); + areaCodePath.add(customerAgencyEntity.getAreaCode().substring(NumConstant.ZERO, NumConstant.FOUR)); + areaCodePath.add(customerAgencyEntity.getAreaCode().substring(NumConstant.ZERO, NumConstant.SIX)); + areaCodePath.add(customerAgencyEntity.getParentAreaCode()); + areaCodePath.add(customerAgencyEntity.getAreaCode()); + break; + case Constant.STREET: + areaCodePath.add(customerAgencyEntity.getAreaCode().substring(NumConstant.ZERO, NumConstant.TWO)); + areaCodePath.add(customerAgencyEntity.getAreaCode().substring(NumConstant.ZERO, NumConstant.FOUR)); + areaCodePath.add(customerAgencyEntity.getParentAreaCode()); + areaCodePath.add(customerAgencyEntity.getAreaCode()); + break; + case Constant.DISTRICT: + areaCodePath.add(customerAgencyEntity.getAreaCode().substring(NumConstant.ZERO, NumConstant.TWO)); + areaCodePath.add(customerAgencyEntity.getParentAreaCode()); + areaCodePath.add(customerAgencyEntity.getAreaCode()); + break; + case Constant.CITY: + areaCodePath.add(customerAgencyEntity.getParentAreaCode()); + areaCodePath.add(customerAgencyEntity.getAreaCode()); + break; + case Constant.PROVINCE: + areaCodePath.add(customerAgencyEntity.getAreaCode()); + break; } - return cachedAgency; + return areaCodePath; } @Override diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/excel/house_export.xlsx b/epmet-module/gov-org/gov-org-server/src/main/resources/excel/house_export.xlsx index 9460a651da..815e222273 100644 Binary files a/epmet-module/gov-org/gov-org-server/src/main/resources/excel/house_export.xlsx and b/epmet-module/gov-org/gov-org-server/src/main/resources/excel/house_export.xlsx differ diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/excel/house_template.xlsx b/epmet-module/gov-org/gov-org-server/src/main/resources/excel/house_template.xlsx index 027f37bcad..0f58eff1d8 100644 Binary files a/epmet-module/gov-org/gov-org-server/src/main/resources/excel/house_template.xlsx and b/epmet-module/gov-org/gov-org-server/src/main/resources/excel/house_template.xlsx differ diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/OpenDataApplication.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/OpenDataApplication.java index 532877cf4b..c786abb9ba 100644 --- a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/OpenDataApplication.java +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/OpenDataApplication.java @@ -5,7 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.openfeign.EnableFeignClients; -import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableScheduling; /** * @Description OpenData服务启动类 @@ -14,6 +14,7 @@ import org.springframework.context.annotation.ComponentScan; * @author wxz * @date 2021.10.13 15:16:05 */ +@EnableScheduling @SpringBootApplication @EnableDiscoveryClient @EnableFeignClients diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/dao/GriderOnlineNumDao.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/dao/GriderOnlineNumDao.java new file mode 100644 index 0000000000..9f4080c054 --- /dev/null +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/dao/GriderOnlineNumDao.java @@ -0,0 +1,33 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * 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.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.opendata.entity.GriderOnlineNumEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 在线网格员人数 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2021-10-14 + */ +@Mapper +public interface GriderOnlineNumDao extends BaseDao { + +} diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/entity/GriderOnlineNumEntity.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/entity/GriderOnlineNumEntity.java new file mode 100644 index 0000000000..ca707865cf --- /dev/null +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/entity/GriderOnlineNumEntity.java @@ -0,0 +1,61 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * 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.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 用户巡查主记录 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2021-10-14 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("grider_online_num") +public class GriderOnlineNumEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 客户Id + */ + private String customerId; + + private String qxGridId; + + /** + * 推送时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date pushTime; + + /** + * 在线数 + */ + private Integer onlineNum; + + + +} diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/GriderOnlineNumService.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/GriderOnlineNumService.java new file mode 100644 index 0000000000..55112c1d8d --- /dev/null +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/GriderOnlineNumService.java @@ -0,0 +1,38 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * 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; + +import com.epmet.commons.mybatis.service.BaseService; +import com.epmet.opendata.entity.GriderOnlineNumEntity; + +/** + * 用户巡查主记录 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2021-10-14 + */ +public interface GriderOnlineNumService extends BaseService { + + /** + * desc:插入巡查中的网格员数据 + * @return boolean + */ + Boolean insertData(String agencyId); + + +} diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/GriderOnlineNumServiceImpl.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/GriderOnlineNumServiceImpl.java new file mode 100644 index 0000000000..b024c1436e --- /dev/null +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/GriderOnlineNumServiceImpl.java @@ -0,0 +1,69 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * 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.alibaba.fastjson.JSON; +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.dto.form.PatrolCountFormDTO; +import com.epmet.dto.result.PatrolCountResultDTO; +import com.epmet.feign.EpmetUserOpenFeignClient; +import com.epmet.opendata.dao.GriderOnlineNumDao; +import com.epmet.opendata.entity.GriderOnlineNumEntity; +import com.epmet.opendata.service.GriderOnlineNumService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; + + +/** + * 用户巡查主记录 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2021-10-14 + */ +@Slf4j +@Service +public class GriderOnlineNumServiceImpl extends BaseServiceImpl implements GriderOnlineNumService { +@Autowired +private EpmetUserOpenFeignClient epmetUserOpenFeignClient; + @Override + public Boolean insertData(String agencyId) { + PatrolCountFormDTO param = new PatrolCountFormDTO(); + param.setAgencyId(agencyId); + Result patrolCountResult = epmetUserOpenFeignClient.patrolCount(param); + + log.debug("insertData patrolCountResult return:{}", JSON.toJSONString(patrolCountResult)); + if (patrolCountResult == null || !patrolCountResult.success()) { + log.warn("insertData patrolCount fail,return null"); + return false; + } + PatrolCountResultDTO data = patrolCountResult.getData(); + int count = data.getPatrollingCount() == null ? NumConstant.ZERO : data.getPatrollingCount(); + GriderOnlineNumEntity entity = new GriderOnlineNumEntity(); + entity.setCustomerId(StrConstant.PY_CUSTOMER); + entity.setPushTime(new Date()); + entity.setOnlineNum(count); + baseDao.insert(entity); + return true; + } +} diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/task/ExtractBizDataToOpenData.java b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/task/ExtractBizDataToOpenData.java new file mode 100644 index 0000000000..ebcd5aa27d --- /dev/null +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/task/ExtractBizDataToOpenData.java @@ -0,0 +1,71 @@ +package com.epmet.opendata.task; + +import com.epmet.commons.tools.constant.NumConstant; +import com.epmet.commons.tools.constant.StrConstant; +import com.epmet.commons.tools.distributedlock.DistributedLock; +import com.epmet.commons.tools.redis.RedisKeys; +import com.epmet.commons.tools.utils.DateUtils; +import com.epmet.opendata.service.GriderOnlineNumService; +import lombok.extern.slf4j.Slf4j; +import org.redisson.api.RLock; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.util.Date; + +/** + * desc: + * + * @author: LiuJanJun + * @date: 2022/4/12 4:21 下午 + * @version: 1.0 + */ +@Slf4j +@Component +public class ExtractBizDataToOpenData { + + @Autowired + private DistributedLock distributedLock; + + @Autowired + private GriderOnlineNumService griderOnlineNumService; + + @Scheduled(cron = "0 30 */2 * * *") + //@Scheduled(cron = "0/15 * * * * *") + public void extractGridMemberPatrollingCount() { + String currentTime = DateUtils.format(new Date(), DateUtils.DATE_TIME_PATTERN); + log.info("extractGridMemberPatrollingCount start,date:{}", currentTime); + RLock rLock = null; + try { + rLock = distributedLock.tryLock(RedisKeys.getLockByMethodName("extractGridMemberPatrollingCount")); + if (rLock == null || !rLock.isLocked()) { + log.warn("tryLock method extractGridMemberPatrollingCount fail"); + return; + } + boolean patrolCountResult; + int retryTime = NumConstant.THREE; + do { + //StrConstant.PY_ROOT_AGENCY + patrolCountResult = griderOnlineNumService.insertData(StrConstant.PY_ROOT_AGENCY); + if (!patrolCountResult) { + break; + } + //如果 重试次数为1了 就让歇个 5分钟 + if (retryTime == 1) { + Thread.sleep(NumConstant.FIVE * NumConstant.SIXTY * NumConstant.ONE_THOUSAND); + } + } while (retryTime-- > 0); + if (!patrolCountResult) { + log.error("插入网格员在线人数失败,请检查原因,时间:{}", currentTime); + } + + } catch (Exception e) { + log.warn("tryLock method extractGridMemberPatrollingCount fail"); + } finally { + distributedLock.unLock(rLock); + } + log.info("extractGridMemberPatrollingCount end"); + } + +} diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/resources/db/migration/V0.0.1__add_grider_online_num.sql b/epmet-module/open-data-worker/open-data-worker-server/src/main/resources/db/migration/V0.0.1__add_grider_online_num.sql new file mode 100644 index 0000000000..d4fd9ca93f --- /dev/null +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/resources/db/migration/V0.0.1__add_grider_online_num.sql @@ -0,0 +1,13 @@ +CREATE TABLE `grider_online_num` ( + `ID` varchar(64) NOT NULL COMMENT '主键', + `CUSTOMER_ID` varchar(64) NOT NULL COMMENT '客户Id', + `ONLINE_NUM` int(11) NOT NULL COMMENT '在线人数', + `PUSH_TIME` datetime NOT NULL COMMENT '推送时间', + `DEL_FLAG` bigint(1) NOT NULL DEFAULT '0' COMMENT '删除标识 0.未删除 1.已删除', + `REVISION` int(11) NOT NULL COMMENT '乐观锁', + `CREATED_BY` varchar(64) NOT NULL COMMENT '创建人', + `CREATED_TIME` datetime NOT NULL COMMENT '创建时间', + `UPDATED_BY` varchar(64) NOT NULL COMMENT '更新人', + `UPDATED_TIME` datetime NOT NULL COMMENT '更新时间', + PRIMARY KEY (`ID`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='网格员在线人数'; diff --git a/epmet-module/open-data-worker/open-data-worker-server/src/main/resources/mapper/GriderOnlineNumDao.xml b/epmet-module/open-data-worker/open-data-worker-server/src/main/resources/mapper/GriderOnlineNumDao.xml new file mode 100644 index 0000000000..27c636d525 --- /dev/null +++ b/epmet-module/open-data-worker/open-data-worker-server/src/main/resources/mapper/GriderOnlineNumDao.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java index 4d2444d767..f5a54cdc8c 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java @@ -76,6 +76,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; @@ -140,7 +141,7 @@ public class IcResiUserController implements ResultDataResolver { * 模板枚举 */ public enum IcUserTemplateEnums { - IC_RESI_IMPORT_TEMPLATE("excel/ic_resi_info_import_cid_for_easy_excel.xls", "居民信息导入模板.xls"), + IC_RESI_IMPORT_TEMPLATE("excel/ic_resi_import_template.xls", "居民信息导入模板.xls"), IC_RESI_EXPORT_TEMPLATE("excel/ic_resi_info_cid_for_easy_excel.xlsx", "居民信息导出模板.xlsx"); private String pathInApp; @@ -162,18 +163,13 @@ public class IcResiUserController implements ResultDataResolver { { // 初始化上传目录 - String home = System.getProperty("user.home"); - Path importDir = Paths.get(home, "epmet_files", "ic_user_import"); - if (Files.notExists(importDir)) { - try { - Files.createDirectories(importDir); - } catch (IOException e) { - log.error("创建数字赋能平台上传目录失败"); - } + try { + IC_RESI_UPLOAD_DIR = com.epmet.commons.tools.utils.FileUtils.getAndCreateDirUnderEpmetFilesDir("ic_user_import"); + } catch (IOException e) { + log.error("初始化居民信息上传目录失败:{}", ExceptionUtils.getErrorStackTrace(e)); } - IC_RESI_UPLOAD_DIR = importDir; - Path exportDir = Paths.get(home, "epmet_files", "ic_user_export"); + Path exportDir = Paths.get(System.getProperty("user.home"), "epmet_files", "ic_user_export"); if (Files.notExists(exportDir)) { try { Files.createDirectories(exportDir); @@ -474,10 +470,10 @@ public class IcResiUserController implements ResultDataResolver { // 三.异步执行导入 executorService.execute(() -> { - + boolean isAllSuccess = false; try { List formItemList = icResiUserService.listFormItems(customerId,IcFormCodeEnum.RESI_BASE_INFO.getCode()); - icResiUserImportService.importIcResiInfoFromExcel(importTaskId, formItemList, importTempFileSavePath.toString(), response, IC_RESI_UPLOAD_DIR); + isAllSuccess = icResiUserImportService.importIcResiInfoFromExcel(importTaskId, formItemList, importTempFileSavePath.toString(), response, IC_RESI_UPLOAD_DIR); } catch (Throwable e) { String errorMsg = ExceptionUtils.getThrowableErrorStackTrace(e); log.error("【导入居民信息失败】导入失败:{}", errorMsg); @@ -493,8 +489,13 @@ public class IcResiUserController implements ResultDataResolver { icResiUserImportService.finishImportTask(importTaskId, operatorId, ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL, resultDesc, null); } finally { try { + // 都导入成功了没问题,才删除 if (importTempFileSavePath != null){ - Files.delete(importTempFileSavePath); + if (isAllSuccess) { + Files.delete(importTempFileSavePath); + } else { + log.error("【导入居民信息】未完全成功,上传文件:{}", importTempFileSavePath); + } } } catch (IOException e) { log.error("【导入居民信息失败】清理上传的文件失败:{}", ExceptionUtils.getErrorStackTrace(e)); @@ -606,28 +607,30 @@ public class IcResiUserController implements ResultDataResolver { /** * 下载ic居民信息导入excel模板 - * @param loginUserInfo * @return */ @PostMapping("import/download-template") - public ResponseEntity downloadIcResiDownloadTemplate(@LoginUser TokenDto loginUserInfo) { - String customerId = loginUserInfo.getCustomerId(); - + public void downloadIcResiDownloadTemplate(HttpServletResponse response) { + InputStream is = null; + ServletOutputStream os = null; try { - File icResiImportTemplateFile = getIcResiTemplateFile(customerId, IcUserTemplateEnums.IC_RESI_IMPORT_TEMPLATE); + os = response.getOutputStream(); + + is = this.getClass().getClassLoader().getResourceAsStream(IcUserTemplateEnums.IC_RESI_IMPORT_TEMPLATE.getPathInApp()); - HttpHeaders headers = new HttpHeaders(); - headers.add("Access-Control-Expose-Headers", "Content-Disposition"); - headers.add("content-Type", "application/vnd.ms-excel"); - headers.add("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(IcUserTemplateEnums.IC_RESI_IMPORT_TEMPLATE.getTemplateName(), "UTF-8")); + response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); + response.setHeader("content-Type", "application/vnd.ms-excel"); + response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(IcUserTemplateEnums.IC_RESI_IMPORT_TEMPLATE.getTemplateName(), "UTF-8")); - return new ResponseEntity<>(FileUtil.readBytes(icResiImportTemplateFile), headers, HttpStatus.OK); + IOUtils.copy(is, os); } catch (Exception e) { String errorStackTrace = ExceptionUtils.getErrorStackTrace(e); - log.error("下载IC居民信息导入模板失败:{}", errorStackTrace); throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "下载IC居民信息导入模板失败"); + } finally { + org.apache.poi.util.IOUtils.closeQuietly(is); + org.apache.poi.util.IOUtils.closeQuietly(os); } } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/PartyMemberAgeExportExcel.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/PartyMemberAgeExportExcel.java index c8a6e6f8d0..6e0a65afc3 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/PartyMemberAgeExportExcel.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/PartyMemberAgeExportExcel.java @@ -1,6 +1,10 @@ package com.epmet.excel; import cn.afterturn.easypoi.excel.annotation.Excel; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; +import com.alibaba.excel.annotation.write.style.HeadStyle; +import com.alibaba.excel.enums.poi.FillPatternTypeEnum; import lombok.Data; /** @@ -9,13 +13,19 @@ import lombok.Data; * @Date 2022/4/13 10:46 */ @Data +@HeadStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 44) public class PartyMemberAgeExportExcel { - @Excel(name = "序号", width = 10) + @ColumnWidth(8) + @ExcelProperty(value = "序号",order = 1) private Integer index; - @Excel(name = "姓名", width = 20) + @ColumnWidth(15) + @ExcelProperty(value = "姓名",order = 2) private String name; - @Excel(name = "年龄", width = 10) + @ColumnWidth(8) + @ExcelProperty(value = "年龄",order = 3) private String age; + @ColumnWidth(20) + @ExcelProperty(value = "手机号码",order = 4) @Excel(name = "手机号码", width = 30) private String mobile; } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/PartyMemberEducationExportExcel.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/PartyMemberEducationExportExcel.java index 1ec5f8033d..1a6955ede2 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/PartyMemberEducationExportExcel.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/excel/PartyMemberEducationExportExcel.java @@ -1,6 +1,10 @@ package com.epmet.excel; import cn.afterturn.easypoi.excel.annotation.Excel; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; +import com.alibaba.excel.annotation.write.style.HeadStyle; +import com.alibaba.excel.enums.poi.FillPatternTypeEnum; import lombok.Data; /** @@ -9,13 +13,19 @@ import lombok.Data; * @Date 2022/4/13 10:46 */ @Data +@HeadStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 44) public class PartyMemberEducationExportExcel { - @Excel(name = "序号", width = 10) + @ColumnWidth(8) + @ExcelProperty(value = "序号",order = 1) private Integer index; - @Excel(name = "姓名", width = 20) + @ColumnWidth(15) + @ExcelProperty(value = "姓名",order = 2) private String name; - @Excel(name = "学历", width = 10) + @ColumnWidth(11) + @ExcelProperty(value = "学历",order = 3) private String education; + @ColumnWidth(20) + @ExcelProperty(value = "手机号码",order = 4) @Excel(name = "手机号码", width = 30) private String mobile; } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserImportService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserImportService.java index 05fb431c32..f3451f3e13 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserImportService.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserImportService.java @@ -13,7 +13,7 @@ import java.util.List; */ public interface IcResiUserImportService { - void importIcResiInfoFromExcel(String importTaskId, List formItemList, String excelPathName, HttpServletResponse response, Path importTempPath); + boolean importIcResiInfoFromExcel(String importTaskId, List formItemList, String excelPathName, HttpServletResponse response, Path importTempPath); /** * 创建导入任务 diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserImportServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserImportServiceImpl.java index 44a6ee7a63..722fb93cd2 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserImportServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserImportServiceImpl.java @@ -13,7 +13,6 @@ import com.epmet.bean.ResiImportChangedData; import com.epmet.commons.tools.constant.AppClientConstant; import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.constant.StrConstant; -import com.epmet.commons.tools.constant.ThreadLocalConstant; import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; import com.epmet.commons.tools.dto.result.OptionResultDTO; import com.epmet.commons.tools.exception.EpmetErrorCode; @@ -24,7 +23,6 @@ import com.epmet.commons.tools.feign.ResultDataResolver; import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.redis.RedisUtils; import com.epmet.commons.tools.redis.common.CustomerStaffRedis; -import com.epmet.commons.tools.security.user.LoginUserUtil; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.EpmetRequestHolder; import com.epmet.commons.tools.utils.Result; @@ -211,9 +209,11 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res * @param formItemList item列表 * @param excelPathName excel缓存路径 * @param response 响应对象 + * @return */ @Override - public void importIcResiInfoFromExcel(String importTaskId, List formItemList, String excelPathName, HttpServletResponse response, Path importTempPath) { + public boolean importIcResiInfoFromExcel(String importTaskId, List formItemList, String excelPathName, HttpServletResponse response, Path importTempPath) { + boolean isAllSuccess = false; String app = EpmetRequestHolder.getHeader(AppClientConstant.APP); String client = EpmetRequestHolder.getHeader(AppClientConstant.CLIENT); @@ -276,6 +276,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res } finishImportTask(importTaskId, loginUserId, ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL,null, resultDescFilePath); } else { + isAllSuccess = true; finishImportTask(importTaskId, loginUserId, ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS,null, null); } @@ -298,6 +299,8 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res resiCategoryColumnNameAndLabel.remove(); itemIdAndOptionsCache.invalidateAll(); } + + return isAllSuccess; } /** @@ -536,10 +539,18 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res private void specifiedCheck(LinkedHashMap columnAndValues) { String idCard = columnAndValues.get("ID_CARD"); String mobile = columnAndValues.get("MOBILE"); + String name = columnAndValues.get("NAME"); List errors = new ArrayList<>(); - if (StringUtils.isNotBlank(idCard) && idCard.length() > 18) { + if (StringUtils.isBlank(idCard)) { + log.debug("【居民信息导入】specifiedCheck身份证号为空的:{},{}", mobile, name); + + String errorMsg = "身份证号不能为空"; + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), errorMsg, errorMsg); + } + + if (idCard.length() > 18) { // 身份证号超长了哦,不可以的 errors.add("身份证号过长"); } @@ -570,9 +581,6 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res LinkedHashMap columnAndValues = new LinkedHashMap<>(); - String loginUserApp = EpmetRequestHolder.getHeader(AppClientConstant.APP); - String loginUserClient = EpmetRequestHolder.getHeader(AppClientConstant.CLIENT); - String loginUserId = EpmetRequestHolder.getHeader(AppClientConstant.USER_ID.toLowerCase()); String loginUserCustomerId = EpmetRequestHolder.getHeader(AppClientConstant.CUSTOMER_ID.toLowerCase()); // 遍历每一行,将行内容转化为 diff --git a/epmet-user/epmet-user-server/src/main/resources/db/migration/V0.0.40__member_huji.sql b/epmet-user/epmet-user-server/src/main/resources/db/migration/V0.0.40__member_huji.sql index 03a2a4bc23..b3f04f8c3c 100644 --- a/epmet-user/epmet-user-server/src/main/resources/db/migration/V0.0.40__member_huji.sql +++ b/epmet-user/epmet-user-server/src/main/resources/db/migration/V0.0.40__member_huji.sql @@ -1,2 +1,6 @@ alter table ic_resi_member add COLUMN DOMICILE_PLACE VARCHAR(128) comment '户籍所在地' AFTER YMJZ; alter table ic_resi_member add COLUMN WORK_PLACE VARCHAR(128) comment '单位或学校' AFTER DOMICILE_PLACE; + +-- 居民信息表添加租户列 +alter table ic_resi_user add column IS_TENANT char(1) comment '是否租户【是:1 否:0】' after IS_SPECIAL; +update ic_resi_user set ic_resi_user.IS_TENANT='0' where ic_resi_user.IS_TENANT is null or ic_resi_user.IS_TENANT=''; \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/resources/excel/ic_resi_info_import_cid_for_easy_excel.xls b/epmet-user/epmet-user-server/src/main/resources/excel/ic_resi_import_template.xls similarity index 100% rename from epmet-user/epmet-user-server/src/main/resources/excel/ic_resi_info_import_cid_for_easy_excel.xls rename to epmet-user/epmet-user-server/src/main/resources/excel/ic_resi_import_template.xls