From 540692c2c84beb3c7d56b46749349fb187027adb Mon Sep 17 00:00:00 2001 From: wangxianzhang Date: Tue, 12 Apr 2022 12:50:17 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=E5=B1=85?= =?UTF-8?q?=E6=B0=91=E4=BF=A1=E6=81=AF=E5=AF=BC=E5=85=A5=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=20=E4=BF=AE=E6=94=B9=EF=BC=9A=E5=B1=85?= =?UTF-8?q?=E6=B0=91=E4=BF=A1=E6=81=AF=E5=AF=BC=E5=85=A5=EF=BC=8C=E5=A6=82?= =?UTF-8?q?=E6=9E=9C=E6=9C=AA=E5=85=A8=E6=88=90=E5=8A=9F=EF=BC=8C=E9=82=A3?= =?UTF-8?q?=E4=B9=88=E4=BF=9D=E7=95=99=E4=B8=B4=E6=97=B6=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E7=9A=84=E9=82=A3=E4=B8=AAexcel=E6=96=87=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E4=BE=9B=E6=8E=92=E6=9F=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/IcResiUserController.java | 53 +++++++++--------- .../service/IcResiUserImportService.java | 2 +- .../impl/IcResiUserImportServiceImpl.java | 9 ++- ..._excel.xls => ic_resi_import_template.xls} | Bin 4 files changed, 35 insertions(+), 29 deletions(-) rename epmet-user/epmet-user-server/src/main/resources/excel/{ic_resi_info_import_cid_for_easy_excel.xls => ic_resi_import_template.xls} (100%) 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 0bfc2fa442..f054e77608 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 @@ -72,6 +72,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; @@ -135,7 +136,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; @@ -157,18 +158,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); @@ -469,10 +465,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); @@ -488,8 +484,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)); @@ -585,28 +586,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/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..f17c6ad2d4 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; } /** 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 From 83226ebd048f9eb8cd0e604ad3dd3215b632ad88 Mon Sep 17 00:00:00 2001 From: wangxianzhang Date: Tue, 12 Apr 2022 15:46:31 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=B1=85=E6=B0=91=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=EF=BC=9Aidcard=E4=B8=BA=E7=A9=BA=EF=BC=8C=E5=AF=BC=E8=87=B4sel?= =?UTF-8?q?ectOne=20return=20many?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/IcResiUserImportServiceImpl.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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 f17c6ad2d4..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 @@ -539,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("身份证号过长"); } @@ -573,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()); // 遍历每一行,将行内容转化为 From 5e0ae7d48361fbf3063f4898e8a21d4f4fdb9843 Mon Sep 17 00:00:00 2001 From: jianjun Date: Tue, 12 Apr 2022 18:30:45 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E7=BD=91=E6=A0=BC=E5=91=98=E5=B7=A1?= =?UTF-8?q?=E6=9F=A5=E5=9C=A8=E7=BA=BF=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/commons/tools/redis/RedisKeys.java | 14 ++++ .../java/com/epmet/OpenDataApplication.java | 3 +- .../opendata/dao/GriderOnlineNumDao.java | 33 +++++++++ .../entity/GriderOnlineNumEntity.java | 61 ++++++++++++++++ .../service/GriderOnlineNumService.java | 38 ++++++++++ .../impl/GriderOnlineNumServiceImpl.java | 69 ++++++++++++++++++ .../task/ExtractBizDataToOpenData.java | 71 +++++++++++++++++++ .../V0.0.1__add_grider_online_num.sql | 13 ++++ .../resources/mapper/GriderOnlineNumDao.xml | 6 ++ 9 files changed, 307 insertions(+), 1 deletion(-) create mode 100644 epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/dao/GriderOnlineNumDao.java create mode 100644 epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/entity/GriderOnlineNumEntity.java create mode 100644 epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/GriderOnlineNumService.java create mode 100644 epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/service/impl/GriderOnlineNumServiceImpl.java create mode 100644 epmet-module/open-data-worker/open-data-worker-server/src/main/java/com/epmet/opendata/task/ExtractBizDataToOpenData.java create mode 100644 epmet-module/open-data-worker/open-data-worker-server/src/main/resources/db/migration/V0.0.1__add_grider_online_num.sql create mode 100644 epmet-module/open-data-worker/open-data-worker-server/src/main/resources/mapper/GriderOnlineNumDao.xml 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-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 @@ + + + + + +