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 4c18a3ea55..bb7edb3e2a 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 @@ -871,5 +871,4 @@ public class RedisKeys { public static String getDhToken() { return rootPrefix.concat("dh:token"); } - } diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/user/LoginUserUtil.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/user/LoginUserUtil.java index ce92400ae0..220ac403a8 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/user/LoginUserUtil.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/user/LoginUserUtil.java @@ -2,6 +2,7 @@ package com.epmet.commons.tools.security.user; import com.epmet.commons.tools.constant.AppClientConstant; import com.epmet.commons.tools.utils.EpmetRequestHolder; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/poi/excel/converter/EasyExcelDateConverter.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/poi/excel/converter/EasyExcelDateConverter.java new file mode 100644 index 0000000000..b3c1d207d4 --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/poi/excel/converter/EasyExcelDateConverter.java @@ -0,0 +1,51 @@ +package com.epmet.commons.tools.utils.poi.excel.converter; + +/** + * desc: + * + * @author: LiuJanJun + * @date: 2022/8/26 4:59 下午 + * @version: 1.0 + */ + +import com.alibaba.excel.converters.Converter; +import com.alibaba.excel.enums.CellDataTypeEnum; +import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.WriteCellData; +import com.alibaba.excel.metadata.property.ExcelContentProperty; + +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * @Author: liujianjun + * @Date: 2022/7/19 + * @Description: yyyy-MM-dd easyExcel 日期转换 + */ +public class EasyExcelDateConverter implements Converter { + + private static final String PATTERN_YYYY_MM_DD = "yyyy-MM-dd"; + + @Override + public Class supportJavaTypeKey() { + return Converter.super.supportJavaTypeKey(); + } + + @Override + public CellDataTypeEnum supportExcelTypeKey() { + return Converter.super.supportExcelTypeKey(); + } + + @Override + public WriteCellData convertToExcelData(Date value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { + SimpleDateFormat sdf = new SimpleDateFormat(PATTERN_YYYY_MM_DD); + String dateValue = sdf.format(value); + return new WriteCellData<>(dateValue); + } + + //@Override + //public Date convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception { + // SimpleDateFormat sdf = new SimpleDateFormat(PATTERN_YYYY_MM_DD); + // return sdf.parse(cellData.getStringValue()); + //} +} \ No newline at end of file diff --git a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java index 705b037699..f3dd1c5833 100644 --- a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java +++ b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java @@ -23,6 +23,10 @@ public interface ImportTaskConstants { String BIZ_TYPE_IC_ENTERPRISE="ic_enterprise"; String IC_POINT_NUCLEIC_MONITORING = "ic_point_nucleic_monitoring"; String IC_POINT_VACCINES_INOCULATION = "ic_point_vaccines_inoculation"; + /** + * 工作日志导入 + */ + String BIZ_TYPE_WORK_DIARY_IMPORT = "work_diary_import"; /** * 核酸检测 */ diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/WorkdiaryServiceTypeDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/WorkdiaryServiceTypeDTO.java new file mode 100644 index 0000000000..664465c7ae --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/WorkdiaryServiceTypeDTO.java @@ -0,0 +1,81 @@ +package com.epmet.dto; + +import com.epmet.commons.tools.validator.group.CustomerClientShowGroup; +import com.epmet.dto.result.WorkdiaryServiceRecordDTO; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; +import java.util.Date; + +/** + * 工作日志(服务)-服务类型 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-08-23 + */ +@Data +public class WorkdiaryServiceTypeDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + public interface Save extends CustomerClientShowGroup {} + public interface Update extends CustomerClientShowGroup {} + + /** + * 主键 + */ + @NotBlank(message = "未选中任何数据", groups = { Update.class }) + private String id; + + /** + * 客户id + */ + private String customerId; + + /** + * 服务类型 + */ + private Short serviceType; + + /** + * 服务类型名称 + */ + private String serviceTypeName; + + /** + * 是否启用。0:禁用,1:启用 + */ + private Short enabled; + + /** + * 删除标识 0.未删除 1.已删除 + */ + private Integer delFlag; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建人 + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新人 + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/workdiaryservice/WorkdiaryServiceQueryFormDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/workdiaryservice/WorkdiaryServiceQueryFormDTO.java new file mode 100644 index 0000000000..3d581924a3 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/workdiaryservice/WorkdiaryServiceQueryFormDTO.java @@ -0,0 +1,38 @@ +package com.epmet.dto.form.workdiaryservice; + +import com.epmet.commons.tools.dto.form.PageFormDTO; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +/** + * 工作日志-服务 + */ +@Data +public class WorkdiaryServiceQueryFormDTO extends PageFormDTO { + + private String id; + private Short serviceType; + private String gridId; + private String applicantName; + private String applicantAddress; + private String serviceContent; + private String applicantMobile; + private String principalName; + + //@DateTimeFormat + //@JsonFormat(pattern = "yyyy-MM-dd HH:mm:sss", timezone = "GMT+8") + //private Date serviceTime; + private String remark; + + @DateTimeFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date serviceTimeStart; + + @DateTimeFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date serviceTimeEnd; + +} diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/WorkdiaryServiceRecordDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/WorkdiaryServiceRecordDTO.java new file mode 100755 index 0000000000..8e75f55c34 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/result/WorkdiaryServiceRecordDTO.java @@ -0,0 +1,143 @@ +package com.epmet.dto.result; + +import java.io.Serializable; +import java.util.Date; + +import com.epmet.commons.tools.validator.group.CustomerClientShowGroup; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + + +/** + * 工作日志(服务)-记录 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-08-23 + */ +@Data +public class WorkdiaryServiceRecordDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + public interface Save extends CustomerClientShowGroup {} + public interface Update extends CustomerClientShowGroup {} + + /** + * 主键 + */ + @NotBlank(message = "未选中任何数据", groups = { Update.class }) + private String id; + + /** + * 客户id + */ + private String customerId; + + /** + * 服务类型 + */ + @NotNull(message = "服务类型为必填项", groups = { Save.class }) + private Short serviceType; + private String serviceTypeName; + + /** + * 单位ID + */ + private String agencyId; + + /** + * 网格ID + */ + @NotBlank(message = "网格为必填项", groups = { Save.class }) + private String gridId; + private String gridName; + + /** + * 组织ID path + */ + private String orgIdPath; + + /** + * 申请人ID + */ + @NotBlank(message = "申请人为必填项", groups = { Save.class }) + private String applicantId; + + private String applicantIdCard; + + /** + * 申请人姓名 + */ + private String applicantName; + + /** + * 申请人住址 + */ + @NotBlank(message = "住址为必填项", groups = { Save.class }) + private String applicantAddress; + + /** + * 申请人联系电话 + */ + @NotBlank(message = "联系电话为必填项", groups = { Save.class }) + private String applicantMobile; + + /** + * 服务内容 + */ + @NotBlank(message = "服务内容为必填项", groups = { Save.class }) + private String serviceContent; + + /** + * 服务时间 + */ + @NotNull(message = "服务时间为必填项", groups = { Save.class }) + @DateTimeFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date serviceTime; + + /** + * 负责人姓名 + */ + private String principalName; + + /** + * 备注 + */ + private String remark; + + /** + * 删除标识 0.未删除 1.已删除 + */ + private Integer delFlag; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建人 + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新人 + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/WorkdiaryServiceController.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/WorkdiaryServiceController.java new file mode 100755 index 0000000000..230e3617ee --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/WorkdiaryServiceController.java @@ -0,0 +1,317 @@ +package com.epmet.controller; + +import com.epmet.commons.tools.aop.NoRepeatSubmit; +import com.epmet.commons.tools.constant.ServiceConstant; +import com.epmet.commons.tools.dto.form.PageFormDTO; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; +import com.epmet.commons.tools.exception.ExceptionUtils; +import com.epmet.commons.tools.feign.ResultDataResolver; +import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.utils.EpmetRequestHolder; +import com.epmet.commons.tools.utils.ExcelUtils; +import com.epmet.commons.tools.utils.FileUtils; +import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.AssertUtils; +import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.commons.tools.validator.group.AddGroup; +import com.epmet.commons.tools.validator.group.DefaultGroup; +import com.epmet.commons.tools.validator.group.UpdateGroup; +import com.epmet.constants.ImportTaskConstants; +import com.epmet.dto.WorkdiaryServiceTypeDTO; +import com.epmet.dto.form.workdiaryservice.WorkdiaryServiceQueryFormDTO; +import com.epmet.dto.result.ImportTaskCommonResultDTO; +import com.epmet.dto.result.WorkdiaryServiceRecordDTO; +import com.epmet.entity.WorkdiaryServiceTypeExcel; +import com.epmet.service.WorkdiaryServiceRecordService; +import com.epmet.service.WorkdiaryServiceTypeService; +import com.epmet.utils.ImportTaskUtils; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +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.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.nio.file.Path; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; + + +/** + * 工作日志(服务) + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-08-23 + */ +@Slf4j +@RestController +@RequestMapping("workdiaryService") +public class WorkdiaryServiceController implements ResultDataResolver { + + @Autowired + private WorkdiaryServiceRecordService workdiaryServiceRecordService; + + @Autowired + private WorkdiaryServiceTypeService workdiaryServiceTypeService; + + @Autowired + private ExecutorService executorService; + + /** + * 记录-分页 + * @return + */ + @RequestMapping("/record/page") + public Result> recordPage(@RequestBody WorkdiaryServiceQueryFormDTO query){ + String gridId = query.getGridId(); + Short serviceType = query.getServiceType(); + String applicantName = query.getApplicantName(); + String applicantAddress = query.getApplicantAddress(); + String serviceContent = query.getServiceContent(); + String applicantMobile = query.getApplicantMobile(); + Integer pageNo = query.getPageNo(); + Integer pageSize = query.getPageSize(); + Date startTime = query.getServiceTimeStart(); + Date endTime = query.getServiceTimeEnd(); + + PageData page = workdiaryServiceRecordService.page( + gridId, serviceType, applicantName, applicantAddress, serviceContent, applicantMobile, startTime, endTime, pageNo, pageSize); + return new Result>().ok(page); + } + + /** + * 记录-单条 + * @param id + * @return + */ + @RequestMapping(value = "/record/{id}/detail",method = {RequestMethod.POST,RequestMethod.GET}) + public Result recordGet(@PathVariable("id") String id){ + WorkdiaryServiceRecordDTO data = workdiaryServiceRecordService.get(id); + return new Result().ok(data); + } + + /** + * 记录-保存 + * @return + */ + @NoRepeatSubmit + @PostMapping("/record/save") + public Result recordSave(@RequestBody WorkdiaryServiceRecordDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, WorkdiaryServiceRecordDTO.Save.class); + workdiaryServiceRecordService.save(dto); + return new Result(); + } + + /** + * 记录-更新 + * @param + * @return + */ + @NoRepeatSubmit + @PostMapping("/record/update") + public Result recordUpdate(@RequestBody WorkdiaryServiceRecordDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, WorkdiaryServiceRecordDTO.Update.class); + workdiaryServiceRecordService.update(dto); + return new Result(); + } + + /** + * 记录-删除 + * @return + */ + @PostMapping("/record/delete") + public Result recordDelete(@RequestBody String[] ids){ + //效验数据 + AssertUtils.isArrayEmpty(ids, "id"); + workdiaryServiceRecordService.delete(ids); + return new Result(); + } + + /** + * 记录-导出 + * @return + */ + @PostMapping("/record/export") + public void recordExport(@RequestBody WorkdiaryServiceQueryFormDTO query, HttpServletResponse response) throws Exception { + String gridId = query.getGridId(); + Short serviceType = query.getServiceType(); + String applicantName = query.getApplicantName(); + String applicantAddress = query.getApplicantAddress(); + String serviceContent = query.getServiceContent(); + String applicantMobile = query.getApplicantMobile(); + Date serviceTimeStart = query.getServiceTimeStart(); + Date serviceTimeEnd = query.getServiceTimeEnd(); + + workdiaryServiceRecordService.export(gridId, serviceType, applicantName, applicantAddress, serviceContent, + applicantMobile, serviceTimeStart, serviceTimeEnd, response); + } + + /** + * 下载模板 + * @return + */ + @RequestMapping("/record/downloadTemplate") + public void downloadTemplate(HttpServletResponse response) throws UnsupportedEncodingException { + response.setCharacterEncoding("UTF-8"); + response.addHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, "Content-Disposition"); + response.setHeader(HttpHeaders.CONTENT_TYPE, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("工作日志导入模板", "UTF-8") + ".xlsx"); + + try (InputStream is = this.getClass().getClassLoader().getResourceAsStream("templates/workdiary_service_import.xlsx"); + ServletOutputStream os = response.getOutputStream()) { + IOUtils.copy(is, os); + } catch (IOException e) { + log.error("【工作日志】下载模板-IO错误:{}", ExceptionUtils.getErrorStackTrace(e)); + } + } + + /** + * 记录导入 + * @param file + */ + @PostMapping("/record/import") + public Result recordImport(MultipartFile file) { + + if (file == null) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), null, "请选择文件"); + } + + // 格式校验 + // 只接受如下两种格式后缀 + String originFileName = file.getOriginalFilename(); + String suffix = originFileName.substring(originFileName.lastIndexOf(".")); + if (StringUtils.isBlank(suffix) || (!".xlsx".equals(suffix) && !".xls".equals(suffix))) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), null, "只支持.xls和.xlsx两种格式"); + } + + // 创建保存目录 + Path fileSavePath = null; + try { + Path saveDir = FileUtils.getAndCreateDirUnderEpmetFilesDir("workdiary", "import", EpmetRequestHolder.getLoginUserId()); + fileSavePath = saveDir.resolve(System.currentTimeMillis() + suffix); + } catch (IOException e) { + e.printStackTrace(); + } + + // 将文件保存到本地 + try (FileOutputStream fos = new FileOutputStream(fileSavePath.toString()); + InputStream is = file.getInputStream()) { + IOUtils.copy(is, fos); + } catch (Exception e) { + log.error("【书记日志】上传-保存文件到本地失败:{}", ExceptionUtils.getErrorStackTrace(e)); + throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode()); + } + + // 创建导入记录 + ImportTaskCommonResultDTO itResult = getResultDataOrThrowsException(ImportTaskUtils.createImportTask(originFileName, ImportTaskConstants.BIZ_TYPE_WORK_DIARY_IMPORT), + ServiceConstant.EPMET_COMMON_SERVICE, EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "有导入操作正在进行", "有导入操作正在进行"); + + // 执行异步导入 + Path finalFileSavePath = fileSavePath; + CompletableFuture.runAsync(() -> { + workdiaryServiceRecordService.createImportTaskAndExecuteImport(finalFileSavePath, originFileName, itResult.getTaskId()); + }, executorService); + + return new Result(); + } + + /** + * 服务类型-分页 + * @return + */ + @RequestMapping("/serviceType/page") + public Result> serviceTypePage(@RequestBody PageFormDTO input){ + PageData page = workdiaryServiceTypeService.page(null, input.getPageNo(), input.getPageSize()); + return new Result>().ok(page); + } + + /** + * 列出启用了的类型列表 + * @param input + * @return + */ + @RequestMapping("/serviceType/avaliableList") + public Result> listAvaliableServiceType(@RequestBody PageFormDTO input){ + PageData page = workdiaryServiceTypeService.listAvaliableServiceType(input.getPageNo(), input.getPageSize()); + return new Result>().ok(page); + } + + /** + * 服务类型-单条 + * @return + */ + @RequestMapping(value = "/serviceType/{id}/detail",method = {RequestMethod.POST,RequestMethod.GET}) + public Result serviceTypeGet(@PathVariable("id") String id){ + WorkdiaryServiceTypeDTO data = workdiaryServiceTypeService.get(id); + return new Result().ok(data); + } + + /** + * 服务类型-保存 + * @return + */ + @NoRepeatSubmit + @PostMapping("/serviceType/save") + public Result serviceTypeSave(@RequestBody WorkdiaryServiceTypeDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, WorkdiaryServiceTypeDTO.Save.class); + workdiaryServiceTypeService.save(dto); + return new Result(); + } + + /** + * 服务类型-更新 + * @return + */ + @NoRepeatSubmit + @PostMapping("/serviceType/update") + public Result serviceTypeUpdate(@RequestBody WorkdiaryServiceTypeDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, WorkdiaryServiceTypeDTO.Update.class); + workdiaryServiceTypeService.update(dto); + return new Result(); + } + + /** + * 服务类型-删除 + * @return + */ + @PostMapping("/serviceType/delete") + public Result serviceTypeDelete(@RequestBody String[] ids){ + //效验数据 + AssertUtils.isArrayEmpty(ids, "id"); + int failCount = workdiaryServiceTypeService.delete(ids); + if (failCount == 0) { + return new Result(); + } else { + return new Result().error(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "部分条目已经被使用,未完全删除,失败条目:" + failCount); + } + } + + /** + * 服务类型-导出 + * @return + */ + @GetMapping("/serviceType/export") + public void serviceTypeExport(@RequestParam Map params, HttpServletResponse response) throws Exception { + List list = workdiaryServiceTypeService.list(params); + ExcelUtils.exportExcelToTarget(response, null, list, WorkdiaryServiceTypeExcel.class); + } + + +} diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/WorkdiaryServiceRecordDao.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/WorkdiaryServiceRecordDao.java new file mode 100755 index 0000000000..5f33762fb8 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/WorkdiaryServiceRecordDao.java @@ -0,0 +1,16 @@ +package com.epmet.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.entity.WorkdiaryServiceRecordEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 工作日志(服务)-记录 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-08-23 + */ +@Mapper +public interface WorkdiaryServiceRecordDao extends BaseDao { + +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/WorkdiaryServiceTypeDao.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/WorkdiaryServiceTypeDao.java new file mode 100755 index 0000000000..5997be4147 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/WorkdiaryServiceTypeDao.java @@ -0,0 +1,23 @@ +package com.epmet.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.entity.WorkdiaryServiceTypeEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + * 工作日志(服务)-服务类型 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-08-23 + */ +@Mapper +public interface WorkdiaryServiceTypeDao extends BaseDao { + + /** + * 该客户最大的type是啥 + * @param customerId + * @return + */ + Short getMaxType(@Param("customerId") String customerId); +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/WorkdiaryServiceRecordEntity.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/WorkdiaryServiceRecordEntity.java new file mode 100755 index 0000000000..a72064b8cd --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/WorkdiaryServiceRecordEntity.java @@ -0,0 +1,98 @@ +package com.epmet.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +import java.util.Date; + +/** + * 工作日志(服务)-记录 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-08-23 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("workdiary_service_record") +@NoArgsConstructor +@AllArgsConstructor +public class WorkdiaryServiceRecordEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 客户id + */ + private String customerId; + + /** + * 服务类型 + */ + private Short serviceType; + + /** + * 单位ID + */ + private String agencyId; + + /** + * 网格ID + */ + private String gridId; + + /** + * 组织ID path + */ + private String orgIdPath; + + /** + * 申请人ID + */ + private String applicantId; + + /** + * 证件号 + */ + private String applicantIdCard; + + /** + * 申请人姓名 + */ + private String applicantName; + + /** + * 申请人住址 + */ + private String applicantAddress; + + /** + * 申请人联系电话 + */ + private String applicantMobile; + + /** + * 服务内容 + */ + private String serviceContent; + + /** + * 服务时间 + */ + private Date serviceTime; + + /** + * 负责人姓名 + */ + private String principalName; + + /** + * 备注 + */ + private String remark; + +} diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/WorkdiaryServiceTypeEntity.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/WorkdiaryServiceTypeEntity.java new file mode 100755 index 0000000000..868fb4e001 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/WorkdiaryServiceTypeEntity.java @@ -0,0 +1,44 @@ +package com.epmet.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 工作日志(服务)-服务类型 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-08-23 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("workdiary_service_type") +public class WorkdiaryServiceTypeEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 客户id + */ + private String customerId; + + /** + * 服务类型 + */ + private Short serviceType; + + /** + * 服务类型名称 + */ + private String serviceTypeName; + + /** + * 是否启用。0:禁用,1:启用 + */ + private Short enabled; + +} diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/WorkdiaryServiceTypeExcel.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/WorkdiaryServiceTypeExcel.java new file mode 100755 index 0000000000..a8c3340c73 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/WorkdiaryServiceTypeExcel.java @@ -0,0 +1,51 @@ +package com.epmet.entity; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import lombok.Data; + +import java.util.Date; + +/** + * 工作日志(服务)-服务类型 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-08-23 + */ +@Data +public class WorkdiaryServiceTypeExcel { + + @Excel(name = "主键") + private String id; + + @Excel(name = "客户id") + private String customerId; + + @Excel(name = "服务类型") + private String serviceType; + + @Excel(name = "服务类型名称") + private String serviceName; + + @Excel(name = "是否启用。0:禁用,1:启用") + private Integer enabled; + + @Excel(name = "删除标识 0.未删除 1.已删除") + private Integer delFlag; + + @Excel(name = "乐观锁") + private Integer revision; + + @Excel(name = "创建人") + private String createdBy; + + @Excel(name = "创建时间") + private Date createdTime; + + @Excel(name = "更新人") + private String updatedBy; + + @Excel(name = "更新时间") + private Date updatedTime; + + +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/WorkdiaryServiceRecordExcel.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/WorkdiaryServiceRecordExcel.java new file mode 100755 index 0000000000..13a9afdfdd --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/WorkdiaryServiceRecordExcel.java @@ -0,0 +1,79 @@ +package com.epmet.excel; + +import cn.hutool.core.bean.BeanUtil; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.format.DateTimeFormat; +import com.alibaba.excel.annotation.write.style.ColumnWidth; +import com.epmet.commons.tools.utils.DateUtils; +import com.epmet.commons.tools.utils.poi.excel.converter.EasyExcelDateConverter; +import com.epmet.dto.result.WorkdiaryServiceRecordDTO; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.util.Date; + +/** + * 工作日志(服务)-记录 excel + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-08-23 + */ +@Data +@NoArgsConstructor +public class WorkdiaryServiceRecordExcel { + + @NotBlank(message = "所属网格必填") + @ColumnWidth(25) + @ExcelProperty(value = "所属网格") + private String gridName; + + @NotBlank(message = "服务类型必填") + @ColumnWidth(15) + @ExcelProperty(value = "服务类型") + private String serviceTypeName; + + @NotBlank(message = "申请人必填") + @ColumnWidth(10) + @ExcelProperty(value = "申请人") + private String applicantName; + + @ColumnWidth(10) + @ExcelProperty(value = "证件号") + private String applicantIdCard; + + @ColumnWidth(25) + @ExcelProperty(value = "住址") + private String applicantAddress; + + @NotBlank(message = "服务内容必填") + @ColumnWidth(25) + @ExcelProperty(value = "服务内容") + private String serviceContent; + + @ColumnWidth(15) + @ExcelProperty(value = "联系电话") + private String applicantMobile; + + @ColumnWidth(10) + @ExcelProperty(value = "负责人") + private String principalName; + + @NotNull(message = "服务时间必填") + @ColumnWidth(20) + @ExcelProperty(value = "服务时间") + //@DateTimeFormat("yyyy-MM-dd") + //@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private String serviceTime; + + @ColumnWidth(20) + @ExcelProperty(value = "备注") + private String remark; + + public WorkdiaryServiceRecordExcel(WorkdiaryServiceRecordDTO dto) { + BeanUtil.copyProperties(dto, this); + this.serviceTime = DateUtils.format(dto.getServiceTime()); + } +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/listener/WorkdiaryServiceImportListener.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/listener/WorkdiaryServiceImportListener.java new file mode 100644 index 0000000000..0f98babccc --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/listener/WorkdiaryServiceImportListener.java @@ -0,0 +1,54 @@ +package com.epmet.excel.listener; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import com.epmet.commons.tools.exception.ExceptionUtils; +import com.epmet.excel.WorkdiaryServiceRecordExcel; +import com.epmet.service.WorkdiaryServiceRecordService; +import lombok.extern.slf4j.Slf4j; + +import java.util.ArrayList; +import java.util.List; + +/** + * 工作日志-导入-监听器 + */ +@Slf4j +public class WorkdiaryServiceImportListener extends AnalysisEventListener { + + /** + * 200 一批执行导入 + */ + public static final Integer BATCH_SIZE = 200; + + /** + * 数据列表 + */ + private List datas = new ArrayList<>(); + + private WorkdiaryServiceRecordService workdiaryServiceRecordService; + + public WorkdiaryServiceImportListener(WorkdiaryServiceRecordService workdiaryServiceRecordService) { + this.workdiaryServiceRecordService = workdiaryServiceRecordService; + } + + @Override + public void invoke(WorkdiaryServiceRecordExcel data, AnalysisContext context) { + datas.add(data); + if (datas.size() >= BATCH_SIZE) { + // 达到批量阈值,执行一次导入 + try { + workdiaryServiceRecordService.executeBatchImport(datas); + } catch (Exception e) { + log.error("【工作日志】导入-发生未知错误:{}", ExceptionUtils.getErrorStackTrace(e)); + } finally { + datas.clear(); + } + } + } + + @Override + public void doAfterAllAnalysed(AnalysisContext context) { + workdiaryServiceRecordService.executeBatchImport(datas); + } +} diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/redis/WorkdiaryServiceRecordRedis.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/redis/WorkdiaryServiceRecordRedis.java new file mode 100755 index 0000000000..bb15d79a6a --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/redis/WorkdiaryServiceRecordRedis.java @@ -0,0 +1,30 @@ +package com.epmet.redis; + +import com.epmet.commons.tools.redis.RedisUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * 工作日志(服务)-记录 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-08-23 + */ +@Component +public class WorkdiaryServiceRecordRedis { + @Autowired + private RedisUtils redisUtils; + + public void delete(Object[] ids) { + + } + + public void set(){ + + } + + public String get(String id){ + return null; + } + +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/redis/WorkdiaryServiceTypeRedis.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/redis/WorkdiaryServiceTypeRedis.java new file mode 100755 index 0000000000..bf4dc2ffc1 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/redis/WorkdiaryServiceTypeRedis.java @@ -0,0 +1,30 @@ +package com.epmet.redis; + +import com.epmet.commons.tools.redis.RedisUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * 工作日志(服务)-服务类型 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-08-23 + */ +@Component +public class WorkdiaryServiceTypeRedis { + @Autowired + private RedisUtils redisUtils; + + public void delete(Object[] ids) { + + } + + public void set(){ + + } + + public String get(String id){ + return null; + } + +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/WorkdiaryServiceRecordService.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/WorkdiaryServiceRecordService.java new file mode 100755 index 0000000000..f574f47f17 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/WorkdiaryServiceRecordService.java @@ -0,0 +1,96 @@ +package com.epmet.service; + +import com.epmet.commons.mybatis.service.BaseService; +import com.epmet.commons.tools.page.PageData; +import com.epmet.dto.form.workdiaryservice.WorkdiaryServiceQueryFormDTO; +import com.epmet.dto.result.WorkdiaryServiceRecordDTO; +import com.epmet.entity.WorkdiaryServiceRecordEntity; +import com.epmet.excel.WorkdiaryServiceRecordExcel; + +import javax.servlet.http.HttpServletResponse; +import java.nio.file.Path; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * 工作日志(服务)-记录 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-08-23 + */ +public interface WorkdiaryServiceRecordService extends BaseService { + + /** + * 默认分页 + * + * @param params + * @return PageData + * @author generator + * @date 2022-08-23 + */ + PageData page(Map params); + + PageData page(String gridId, Short serviceType, String applicantName, String applicantAddress, + String serviceContent, String applicantMobile, Date serviceTimeStart, Date serviceTimeEnd, + Integer pageNo, Integer pageSize); + + /** + * 默认查询 + * + * @param params + * @return java.util.List + * @author generator + * @date 2022-08-23 + */ + List list(Map params); + + /** + * 单条查询 + * + * @param id + * @return WorkdiaryServiceRecordDTO + * @author generator + * @date 2022-08-23 + */ + WorkdiaryServiceRecordDTO get(String id); + + /** + * 默认保存 + * + * @param dto + * @return void + * @author generator + * @date 2022-08-23 + */ + void save(WorkdiaryServiceRecordDTO dto); + + /** + * 默认更新 + * + * @param dto + * @return void + * @author generator + * @date 2022-08-23 + */ + void update(WorkdiaryServiceRecordDTO dto); + + /** + * 批量删除 + * + * @param ids + * @return void + * @author generator + * @date 2022-08-23 + */ + void delete(String[] ids); + + void export(String gridId, Short serviceType, String applicantName, String applicantAddress, + String serviceContent, String applicantMobile, Date serviceTimeStart, Date serviceTimeEnd, HttpServletResponse response); + + Integer selectRecordCountOfType(Short serviceType); + + void createImportTaskAndExecuteImport(Path fileSavePath, String originFileName, String taskId); + + void executeBatchImport(List datas); +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/WorkdiaryServiceTypeService.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/WorkdiaryServiceTypeService.java new file mode 100755 index 0000000000..255b1db312 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/WorkdiaryServiceTypeService.java @@ -0,0 +1,81 @@ +package com.epmet.service; + +import com.epmet.commons.mybatis.service.BaseService; +import com.epmet.commons.tools.page.PageData; +import com.epmet.dto.WorkdiaryServiceTypeDTO; +import com.epmet.entity.WorkdiaryServiceTypeEntity; + +import java.util.List; +import java.util.Map; + +/** + * 工作日志(服务)-服务类型 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-08-23 + */ +public interface WorkdiaryServiceTypeService extends BaseService { + + /** + * 默认分页 + * + * @return PageData + * @author generator + * @date 2022-08-23 + */ + PageData page(Short enabled, Integer pageNo, Integer pageSize); + + /** + * 默认查询 + * + * @param params + * @return java.util.List + * @author generator + * @date 2022-08-23 + */ + List list(Map params); + + List list(Short enabled, Integer pageNo, Integer pageSize); + + /** + * 单条查询 + * + * @param id + * @return WorkdiaryServiceTypeDTO + * @author generator + * @date 2022-08-23 + */ + WorkdiaryServiceTypeDTO get(String id); + + /** + * 默认保存 + * + * @param dto + * @return void + * @author generator + * @date 2022-08-23 + */ + void save(WorkdiaryServiceTypeDTO dto); + + /** + * 默认更新 + * + * @param dto + * @return void + * @author generator + * @date 2022-08-23 + */ + void update(WorkdiaryServiceTypeDTO dto); + + /** + * 批量删除 + * + * @param ids + * @return void + * @author generator + * @date 2022-08-23 + */ + int delete(String[] ids); + + PageData listAvaliableServiceType(Integer pageNo, Integer pageSize); +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/WorkdiaryServiceRecordServiceImpl.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/WorkdiaryServiceRecordServiceImpl.java new file mode 100755 index 0000000000..f44d157e22 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/WorkdiaryServiceRecordServiceImpl.java @@ -0,0 +1,551 @@ +package com.epmet.service.impl; + +import cn.afterturn.easypoi.excel.ExcelExportUtil; +import cn.afterturn.easypoi.excel.entity.ExportParams; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; +import com.alibaba.excel.write.metadata.WriteSheet; +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.constant.ServiceConstant; +import com.epmet.commons.tools.dto.result.OptionResultDTO; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; +import com.epmet.commons.tools.exception.ExceptionUtils; +import com.epmet.commons.tools.exception.ValidateException; +import com.epmet.commons.tools.feign.ResultDataResolver; +import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.redis.common.CustomerOrgRedis; +import com.epmet.commons.tools.redis.common.bean.GridInfoCache; +import com.epmet.commons.tools.security.user.LoginUserUtil; +import com.epmet.commons.tools.utils.*; +import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.constants.ImportTaskConstants; +import com.epmet.dao.WorkdiaryServiceRecordDao; +import com.epmet.dao.WorkdiaryServiceTypeDao; +import com.epmet.dto.*; +import com.epmet.dto.form.GridOptionFormDTO; +import com.epmet.dto.form.LoginUserDetailsFormDTO; +import com.epmet.dto.form.resi.IcResiPageNonDynamicFormDTO; +import com.epmet.dto.result.*; +import com.epmet.dto.result.resi.IcResiNonDynamicResultDTO; +import com.epmet.entity.WorkdiaryServiceRecordEntity; +import com.epmet.excel.WorkdiaryServiceRecordExcel; +import com.epmet.excel.listener.WorkdiaryServiceImportListener; +import com.epmet.feign.EpmetUserOpenFeignClient; +import com.epmet.feign.GovOrgOpenFeignClient; +import com.epmet.feign.OssFeignClient; +import com.epmet.redis.WorkdiaryServiceRecordRedis; +import com.epmet.service.WorkdiaryServiceRecordService; +import com.epmet.service.WorkdiaryServiceTypeService; +import com.epmet.utils.ImportTaskUtils; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.lang3.StringUtils; +import org.apache.http.entity.ContentType; +import org.apache.poi.ss.usermodel.Workbook; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.commons.CommonsMultipartFile; + +import javax.servlet.http.HttpServletResponse; +import javax.validation.constraints.NotNull; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * 工作日志(服务)-记录 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-08-23 + */ +@Service +public class WorkdiaryServiceRecordServiceImpl extends BaseServiceImpl implements WorkdiaryServiceRecordService, ResultDataResolver { + + @Autowired + private WorkdiaryServiceRecordRedis workdiaryServiceRecordRedis; + + @Autowired + private WorkdiaryServiceTypeDao workdiaryServiceTypeDao; + + @Autowired + private EpmetUserOpenFeignClient userOpenFeignClient; + + @Autowired + private GovOrgOpenFeignClient govOrgOpenFeignClient; + + @Autowired + private OssFeignClient ossFeignClient; + + private ThreadLocal> importResultDescTl = new ThreadLocal<>(); + + /** + * 导入结果描述 + */ + @Data + @NoArgsConstructor + @AllArgsConstructor + public static class ImportResultDesc { + @ColumnWidth(20) + @ExcelProperty(value = "申请人") + private String applicantName; + + @ColumnWidth(30) + @ExcelProperty(value = "服务内容") + private String serviceContent; + + @ColumnWidth(30) + @ExcelProperty(value = "描述") + private String desc; + } + + @Override + public PageData page(Map params) { + IPage page = baseDao.selectPage( + getPage(params, FieldConstant.CREATED_TIME, false), + getWrapper(params) + ); + return getPageData(page, WorkdiaryServiceRecordDTO.class); + } + + @Override + public PageData page(String gridId, Short serviceType, String applicantName, String applicantAddress, + String serviceContent, String applicantMobile, Date serviceTimeStart, Date serviceTimeEnd, + Integer pageNo, Integer pageSize) { + + LoginUserDetailsResultDTO currentStaff = getResultDataOrThrowsException(userOpenFeignClient.getLoginUserDetails(new LoginUserDetailsFormDTO( + EpmetRequestHolder.getLoginUserApp(), EpmetRequestHolder.getLoginUserClient(), EpmetRequestHolder.getLoginUserId() + )), ServiceConstant.EPMET_USER_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), "查询工作人员信息失败", "查询工作人员信息失败"); + + LambdaQueryWrapper query = new LambdaQueryWrapper<>(); + query.eq(StringUtils.isNotBlank(gridId), WorkdiaryServiceRecordEntity::getGridId, gridId); + query.eq(serviceType != null, WorkdiaryServiceRecordEntity::getServiceType, serviceType); + query.like(StringUtils.isNotBlank(applicantName), WorkdiaryServiceRecordEntity::getApplicantName, applicantName); + query.like(StringUtils.isNotBlank(applicantAddress), WorkdiaryServiceRecordEntity::getApplicantAddress, applicantAddress); + query.like(StringUtils.isNotBlank(serviceContent), WorkdiaryServiceRecordEntity::getServiceContent, serviceContent); + query.like(StringUtils.isNotBlank(applicantMobile), WorkdiaryServiceRecordEntity::getApplicantMobile, applicantMobile); + query.likeRight(WorkdiaryServiceRecordEntity::getOrgIdPath, currentStaff.getOrgIdPath()); + + // 服务时间查询,两端包含,闭区间 + query.ge(serviceTimeStart != null, WorkdiaryServiceRecordEntity::getServiceTime, serviceTimeStart); + query.le(serviceTimeStart != null, WorkdiaryServiceRecordEntity::getServiceTime, serviceTimeEnd); + + // 创建时间倒序 + query.orderByDesc(WorkdiaryServiceRecordEntity::getCreatedTime); + + // 查找类型列表 + List stList = SpringContextUtils.getBean(WorkdiaryServiceTypeService.class).list(null, 1, 100); + Map stMap = stList.stream().collect(Collectors.toMap(WorkdiaryServiceTypeDTO::getServiceType, WorkdiaryServiceTypeDTO::getServiceTypeName)); + + // 查找服务记录 + PageHelper.startPage(pageNo, pageSize); + List list = baseDao.selectList(query) + .stream() + .map(e -> convertEntity2DTO(e, stMap)) + .collect(Collectors.toList()); + return new PageData<>(list, new PageInfo<>(list).getTotal(), pageSize); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, WorkdiaryServiceRecordDTO.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 WorkdiaryServiceRecordDTO get(String id) { + WorkdiaryServiceRecordEntity entity = baseDao.selectById(id); + return convertEntity2DTO(entity, null); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(WorkdiaryServiceRecordDTO dto) { + WorkdiaryServiceRecordEntity entity = ConvertUtils.sourceToTarget(dto, WorkdiaryServiceRecordEntity.class); + + LoginUserDetailsResultDTO currentStaff = getResultDataOrThrowsException(userOpenFeignClient.getLoginUserDetails(new LoginUserDetailsFormDTO( + EpmetRequestHolder.getLoginUserApp(), EpmetRequestHolder.getLoginUserClient(), EpmetRequestHolder.getLoginUserId() + )), ServiceConstant.EPMET_USER_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), "查询工作人员信息失败", "查询工作人员信息失败"); + + String staffOrgIdPath = currentStaff.getOrgIdPath(); + + GridInfoCache gridInfo = CustomerOrgRedis.getGridInfo(dto.getGridId()); + + if (gridInfo == null) { + // 说明网格是其他组织下的 + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "网格未找到", "网格未找到"); + } + + String gridOrgIdPath = gridInfo.getPids().concat(":").concat(gridInfo.getId()); + + if (!gridOrgIdPath.contains(staffOrgIdPath)) { + // 说明网格是其他组织下的 + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "所选网格不在您所属组织下", "所选网格不在您所属组织下"); + } + + entity.setOrgIdPath(gridOrgIdPath); + entity.setAgencyId(gridInfo.getPid()); + + IcResiUserDTO applicant = getResultDataOrThrowsException(userOpenFeignClient.getIcResiUserDTO(dto.getApplicantId()), ServiceConstant.EPMET_USER_SERVER, + EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), null, "未找到申请人信息"); + + entity.setCustomerId(EpmetRequestHolder.getLoginUserCustomerId()); + if (applicant != null) { + entity.setApplicantName(applicant.getName()); + entity.setCustomerId(applicant.getCustomerId()); + } + insert(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(WorkdiaryServiceRecordDTO dto) { + WorkdiaryServiceRecordEntity entity = new WorkdiaryServiceRecordEntity(); + + entity.setId(dto.getId()); + entity.setServiceType(dto.getServiceType()); + entity.setGridId(dto.getGridId()); + entity.setApplicantId(dto.getApplicantId()); + entity.setApplicantAddress(dto.getApplicantAddress()); + entity.setServiceContent(dto.getServiceContent()); + entity.setApplicantMobile(dto.getApplicantMobile()); + entity.setPrincipalName(dto.getPrincipalName()); + entity.setServiceTime(dto.getServiceTime()); + entity.setRemark(dto.getRemark()); + //entity.setApplicantIdCard(dto.getApplicantIdCard()); + + // orgidPath + if (StringUtils.isNotBlank(dto.getGridId())) { + Optional.ofNullable(CustomerOrgRedis.getGridInfo(dto.getGridId())) + .ifPresent(gi -> { + entity.setOrgIdPath(gi.getPids().concat(":").concat(gi.getId())); + entity.setAgencyId(gi.getPid()); + }); + } + + if (StringUtils.isNotBlank(dto.getApplicantId())) { + IcResiUserDTO applicant = getResultDataOrThrowsException(userOpenFeignClient.getIcResiUserDTO(dto.getApplicantId()), ServiceConstant.EPMET_USER_SERVER, + EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), null, "未找到申请人信息"); + + if (applicant != null) { + entity.setApplicantName(applicant.getName()); + entity.setCustomerId(applicant.getCustomerId()); + } + } + + updateById(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(String[] ids) { + // 逻辑删除(@TableLogic 注解) + baseDao.deleteBatchIds(Arrays.asList(ids)); + } + + private WorkdiaryServiceRecordDTO convertEntity2DTO(WorkdiaryServiceRecordEntity entity, Map stMap) { + + if (stMap == null || stMap.size() == 0) { + // 查找类型列表 + List list = SpringContextUtils.getBean(WorkdiaryServiceTypeService.class).list(null, 1, 100); + stMap = list.stream().collect(Collectors.toMap(WorkdiaryServiceTypeDTO::getServiceType, WorkdiaryServiceTypeDTO::getServiceTypeName)); + } + + WorkdiaryServiceRecordDTO d = ConvertUtils.sourceToTarget(entity, WorkdiaryServiceRecordDTO.class); + Optional.ofNullable(CustomerOrgRedis.getGridInfo(entity.getGridId())).ifPresent((gridInfo) -> d.setGridName(gridInfo.getAgencyName() + gridInfo.getGridName())); + d.setServiceTypeName(stMap.get(entity.getServiceType())); + return d; + } + + @Override + public void export(String gridId, Short serviceType, String applicantName, String applicantAddress, + String serviceContent, String applicantMobile, Date serviceTimeStart, Date serviceTimeEnd, HttpServletResponse response) { + + ExcelWriter writer; + try { + writer = EasyExcel.write(ExcelUtils.getOutputStreamForExcel("工作日志导出.xlsx", response)).build(); + } catch (IOException e) { + logger.error("【工作日志-服务】导出-response设置失败:{}", ExceptionUtils.getErrorStackTrace(e)); + throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode()); + } + + WriteSheet sheet = EasyExcel.writerSheet("工作日志") + .head(WorkdiaryServiceRecordExcel.class) + .build(); + + + try { + //一次500条,分批导出 + int pageSize = 500; + for (int pageNo = 1; ; pageNo++) { + PageData page = this.page(gridId, serviceType, applicantName, applicantAddress, serviceContent, + applicantMobile, serviceTimeStart, serviceTimeEnd, pageNo, pageSize); + + List list = page.getList(); + if (CollectionUtils.isEmpty(list)) { + // 空的,导出结束 + break; + } + + List excelObjects = list.stream().map(e -> new WorkdiaryServiceRecordExcel(e)).collect(Collectors.toList()); + writer.write(excelObjects, sheet); + } + } finally { + writer.finish(); + } + } + + @Override + public Integer selectRecordCountOfType(Short serviceType) { + LambdaQueryWrapper query = new LambdaQueryWrapper<>(); + query.eq(WorkdiaryServiceRecordEntity::getCustomerId, EpmetRequestHolder.getLoginUserCustomerId()); + query.eq(WorkdiaryServiceRecordEntity::getServiceType, serviceType); + return baseDao.selectCount(query); + } + + /** + * 创建导入任务并且执行导入 + * @param fileSavePath + */ + @Override + public void createImportTaskAndExecuteImport(Path fileSavePath, String originFileName, String taskId) { + String resultDescFileUtl = null; + // 执行导入操作 + try { + importResultDescTl.set(new ArrayList<>()); + WorkdiaryServiceImportListener listener = new WorkdiaryServiceImportListener(this); + EasyExcel.read(fileSavePath.toFile(), WorkdiaryServiceRecordExcel.class,listener).headRowNumber(1).sheet(0).doRead(); + } catch (Exception e) { + logger.error("【工作日志】-导入-未知错误:{}", ExceptionUtils.getErrorStackTrace(e)); + } finally { + // 清理临时文件 + try { + Files.deleteIfExists(fileSavePath); + } catch (IOException e) { + logger.error("【书记日志】-导入-删除导入临时文件失败,staffId:{}, 文件名称:{}, 错误信息:{}", + EpmetRequestHolder.getLoginUserId(), fileSavePath.toString(), ExceptionUtils.getErrorStackTrace(e)); + } + + // 上传错误描述文件 + try { + resultDescFileUtl = buildAndUploadResultDescFile(importResultDescTl.get()); + } catch (IOException e) { + logger.error("【工作日志】导入-生成和上传错误描述文件失败:{}", ExceptionUtils.getErrorStackTrace(e)); + } + + // 清理错误结果描述缓存 + importResultDescTl.remove(); + } + + + + // 修改导入记录状态为已完成 + ImportTaskUtils.finishImportTask(taskId, ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS, resultDescFileUtl, ""); + } + + /** + * 生成和上传错误描述文件 + * @return + */ + private String buildAndUploadResultDescFile(List descs) throws IOException { + if(CollectionUtils.isEmpty(descs)) { + return null; + } + //Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("导入失败的数据列表","导入失败的数据列表"), + // ImportResultDesc.class, descs); + + String fileName = System.currentTimeMillis() + "_" + EpmetRequestHolder.getLoginUserId() + ".xlsx"; + + FileItem fileItem = new DiskFileItemFactory(DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD, FileUtils.getAndCreateDirUnderEpmetFilesDir("workdiary", "result_desc").toFile()) + .createItem("file", ContentType.APPLICATION_OCTET_STREAM.toString(), false, fileName); + + // 为了自动关闭流 + try (OutputStream os = fileItem.getOutputStream()) { + EasyExcel.write(os, ImportResultDesc.class).sheet("失败列表").doWrite(descs); + } + + UploadImgResultDTO result = getResultDataOrThrowsException(ossFeignClient.uploadImportTaskDescFile(new CommonsMultipartFile(fileItem)), + ServiceConstant.EPMET_OSS_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), "上传结果描述文件失败", "上传结果描述文件失败"); + + if (!fileItem.isInMemory()) { + fileItem.delete(); + } + return result.getUrl(); + } + + /** + * 执行批量插入 + * @param datas + */ + @Override + public void executeBatchImport(List datas) { + if (CollectionUtils.isEmpty(datas)) { + return; + } + + // 当前登录人 + LoginUserDetailsResultDTO currentStaff = getResultDataOrThrowsException(userOpenFeignClient.getLoginUserDetails( + new LoginUserDetailsFormDTO(EpmetRequestHolder.getLoginUserApp(), EpmetRequestHolder.getLoginUserClient(), EpmetRequestHolder.getLoginUserId())), + ServiceConstant.EPMET_USER_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), "【工作日志】-导入-没有找到当前登录人信息", "【工作日志】-导入-没有找到当前登录人信息"); + + // 服务类型字典。key:养老 value:object + List serviceTypes = SpringContextUtils.getBean(WorkdiaryServiceTypeService.class).page(null, 1, 100).getList(); + Map serviceTypeMap = serviceTypes.stream().collect(Collectors.toMap(WorkdiaryServiceTypeDTO::getServiceTypeName, Function.identity())); + + ArrayList diaryRecordList = new ArrayList<>(); + + // 循环校验和填充数据 + for (WorkdiaryServiceRecordExcel row : datas) { + + String gridName = row.getGridName(); + String serviceTypeName = row.getServiceTypeName(); + String applicantName = row.getApplicantName(); + + try { + // 校验必填 + ValidatorUtils.validateEntity(row); + + // 检查服务类型 + WorkdiaryServiceTypeDTO serviceType = serviceTypeMap.get(serviceTypeName); + if (serviceType == null || serviceType.getEnabled().shortValue() == 0) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "所选服务类型不存在或已禁用", "所选服务类型不存在或已禁用"); + } + + // 检查网格 + OptionResultDTO grid = findGrid(currentStaff.getAgencyId(), gridName); + if (grid == null) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "网格不存在,或不在您所属的组织下", "网格不存在,或不在您所属的组织下"); + } + + // 查找居民 + IcResiNonDynamicResultDTO resi = findResi(grid.getValue(), row.getApplicantName(), row.getApplicantMobile()); + + if (StringUtils.isBlank(row.getApplicantMobile())) { + row.setApplicantMobile(resi.getMobile()); + } + + // 没填写住址的,到系统查询 + if (StringUtils.isBlank(row.getApplicantAddress())) { + + HouseAgencyInfoResultDTO house = getResultDataOrThrowsException(govOrgOpenFeignClient.getHouseAgencyInfo(resi.getHomeId()), + ServiceConstant.GOV_ORG_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), "查询房屋失败", "查询房屋失败"); + + if (house == null) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "居民住址未找到", "居民未找到"); + } + + row.setApplicantAddress(house.getFullName()); + } + + // 时间转化 + String serviceTimeStr = row.getServiceTime(); + String spliter = null; + if (serviceTimeStr.contains("/")) { + spliter = "/"; + } else if (serviceTimeStr.contains("-")) { + spliter = "-"; + } else { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "时间格式不正确", "时间格式不正确"); + } + + String[] arr = serviceTimeStr.split(spliter); + + String year = String.format("%04d", Integer.valueOf(arr[0])); + String month = String.format("%02d", Integer.valueOf(arr[1])); + String day = String.format("%02d", Integer.valueOf(arr[2])); + + Date date = DateUtils.parseDate(String.format("%s-%s-%s", year, month, day), DateUtils.DATE_PATTERN); + + // 填充到entity + WorkdiaryServiceRecordEntity record = new WorkdiaryServiceRecordEntity( + EpmetRequestHolder.getLoginUserCustomerId(), + serviceType.getServiceType(), + currentStaff.getAgencyId(), + grid.getValue(), + currentStaff.getOrgIdPath().concat(":").concat(grid.getValue()), + resi.getId(), + row.getApplicantIdCard(), + row.getApplicantName(), + row.getApplicantAddress(), + row.getApplicantMobile(), + row.getServiceContent(), + date, + row.getPrincipalName(), + row.getRemark()); + + diaryRecordList.add(record); + } catch (ValidateException ve) { + importResultDescTl.get().add(new ImportResultDesc(applicantName, row.getServiceContent(), ve.getMsg())); + } catch (EpmetException ee) { + importResultDescTl.get().add(new ImportResultDesc(applicantName, row.getServiceContent(), ee.getMsg())); + } catch (Throwable t) { + logger.error(ExceptionUtils.getThrowableErrorStackTrace(t)); + importResultDescTl.get().add(new ImportResultDesc(applicantName, row.getServiceContent(), "未知错误")); + } + } + + // 批量持久化 + insertBatch(diaryRecordList, 50); + } + + private IcResiNonDynamicResultDTO findResi(String gridId, String applicantName, String mobile) { + PageData page = getResultDataOrThrowsException(userOpenFeignClient.listResiNonDynamic(new IcResiPageNonDynamicFormDTO(gridId, applicantName, mobile, false)), + ServiceConstant.EPMET_USER_SERVER, EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "居民未找到", "居民未找到"); + + List list = page.getList(); + + if (page == null || CollectionUtils.isEmpty(page.getList())) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "居民未找到", "居民未找到"); + } + + return list.get(0); + } + + /** + * 从组织下查找指定的网格名称,得到网格数据 + * @param agencyId + * @param gridName + * @return + */ + private OptionResultDTO findGrid(String agencyId, String gridName) { + List gridOptions = getResultDataOrThrowsException(govOrgOpenFeignClient.getGridOption(new GridOptionFormDTO(agencyId, "saveOrUpdate")), + ServiceConstant.GOV_ORG_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), "【工作日志】-导入-网格查询失败", "【工作日志】-导入-网格查询失败"); + + for (OptionResultDTO grid : gridOptions) { + if (gridName.equals(grid.getLabel())) { + return grid; + } + } + + return null; + } +} diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/WorkdiaryServiceTypeServiceImpl.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/WorkdiaryServiceTypeServiceImpl.java new file mode 100755 index 0000000000..fea0eeaa84 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/WorkdiaryServiceTypeServiceImpl.java @@ -0,0 +1,156 @@ +package com.epmet.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.commons.tools.constant.FieldConstant; +import com.epmet.commons.tools.distributedlock.DistributedLock; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; +import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.redis.RedisUtils; +import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.utils.EpmetRequestHolder; +import com.epmet.commons.tools.utils.SpringContextUtils; +import com.epmet.dao.WorkdiaryServiceTypeDao; +import com.epmet.dto.WorkdiaryServiceTypeDTO; +import com.epmet.entity.WorkdiaryServiceTypeEntity; +import com.epmet.redis.WorkdiaryServiceTypeRedis; +import com.epmet.service.WorkdiaryServiceRecordService; +import com.epmet.service.WorkdiaryServiceTypeService; +import com.github.pagehelper.PageInfo; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.RequestBody; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * 工作日志(服务)-服务类型 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2022-08-23 + */ +@Service +public class WorkdiaryServiceTypeServiceImpl extends BaseServiceImpl implements WorkdiaryServiceTypeService { + + @Autowired + private WorkdiaryServiceTypeRedis workdiaryServiceTypeRedis; + @Autowired + private RedisUtils redisUtils; + @Autowired + private DistributedLock distributedLock; + + @Override + public PageData page(Short enabled, Integer pageNo, Integer pageSize) { + List list = list(enabled, pageNo, pageSize); + return new PageData<>(list, new PageInfo<>(list).getTotal(), pageSize); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, WorkdiaryServiceTypeDTO.class); + } + + @Override + public List list(Short enabled, Integer pageNo, Integer pageSize) { + LambdaQueryWrapper stQuery = new LambdaQueryWrapper<>(); + stQuery.eq(WorkdiaryServiceTypeEntity::getCustomerId, EpmetRequestHolder.getLoginUserCustomerId()); + stQuery.eq(enabled != null, WorkdiaryServiceTypeEntity::getEnabled, enabled); + List ds = baseDao.selectList(stQuery).stream().map((e) -> { + WorkdiaryServiceTypeDTO d = new WorkdiaryServiceTypeDTO(); + d.setId(e.getId()); + d.setServiceType(e.getServiceType()); + d.setServiceTypeName(e.getServiceTypeName()); + d.setEnabled(e.getEnabled()); + return d; + }).collect(Collectors.toList()); + return ds; + } + + @Override + public PageData listAvaliableServiceType(Integer pageNo, Integer pageSize) { + return this.page(Short.valueOf("1"), pageNo, pageSize); + } + + 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 WorkdiaryServiceTypeDTO get(String id) { + WorkdiaryServiceTypeEntity entity = baseDao.selectById(id); + return ConvertUtils.sourceToTarget(entity, WorkdiaryServiceTypeDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(WorkdiaryServiceTypeDTO dto) { + String customerId = EpmetRequestHolder.getLoginUserCustomerId(); + // 预先检查 + LambdaQueryWrapper query = new LambdaQueryWrapper<>(); + query.eq(WorkdiaryServiceTypeEntity::getCustomerId, customerId); + query.eq(WorkdiaryServiceTypeEntity::getServiceTypeName, dto.getServiceTypeName()); + if (baseDao.selectCount(query) > 0) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "已存在该类别", "已存在该类别"); + } + + WorkdiaryServiceTypeEntity entity = ConvertUtils.sourceToTarget(dto, WorkdiaryServiceTypeEntity.class); + entity.setCustomerId(customerId); + entity.setEnabled(Short.valueOf("1")); + synchronized (this) { + Short max = baseDao.getMaxType(customerId); + entity.setServiceType(++max); + insert(entity); + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(WorkdiaryServiceTypeDTO dto) { + WorkdiaryServiceTypeEntity entity = ConvertUtils.sourceToTarget(dto, WorkdiaryServiceTypeEntity.class); + updateById(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public int delete(@RequestBody String[] ids) { + //String.format(""); + //distributedLock.getLock(RedisKeys.getLockByMethodName()); + // todo 此操作与日志记录的新增和修改动作之间需要互斥 + List canDeleteIds = new ArrayList<>(); + int failCount = 0; + for (String id : ids) { + WorkdiaryServiceTypeEntity st = baseDao.selectById(id); + if (st == null) { + continue; + } + WorkdiaryServiceRecordService wsRecordService = SpringContextUtils.getBean(WorkdiaryServiceRecordService.class); + Integer recordCount = wsRecordService.selectRecordCountOfType(st.getServiceType()); + if (recordCount > 0) { + failCount++; + } else { + canDeleteIds.add(id); + } + } + + if (CollectionUtils.isNotEmpty(canDeleteIds)) { + baseDao.deleteBatchIds(canDeleteIds); + } + return failCount; + } + +} \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/db/migration/V0.0.28__workdiary_service.sql b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/db/migration/V0.0.28__workdiary_service.sql new file mode 100644 index 0000000000..c59d94b2a2 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/db/migration/V0.0.28__workdiary_service.sql @@ -0,0 +1,47 @@ +# 服务记录表 +CREATE TABLE `workdiary_service_record` +( + `ID` varchar(64) NOT NULL COMMENT '主键', + `CUSTOMER_ID` varchar(64) NOT NULL COMMENT '客户id', + `SERVICE_TYPE` tinyint(3) NOT NULL COMMENT '服务类型', + `AGENCY_ID` varchar(32) NOT NULL COMMENT '单位ID', + `GRID_ID` varchar(32) NOT NULL COMMENT '网格ID', + `ORG_ID_PATH` varchar(255) NOT NULL COMMENT '组织ID path', + `APPLICANT_ID` varchar(32) NOT NULL COMMENT '申请人ID', + `APPLICANT_ID_CARD` varchar(32) default '' COMMENT '申请人证件号', + `APPLICANT_NAME` varchar(32) NOT NULL COMMENT '申请人姓名', + `APPLICANT_ADDRESS` varchar(32) NOT NULL COMMENT '申请人住址', + `APPLICANT_MOBILE` varchar(20) NOT NULL COMMENT '申请人联系电话', + `SERVICE_CONTENT` varchar(255) NOT NULL COMMENT '服务内容', + `SERVICE_TIME` datetime NOT NULL COMMENT '服务时间', + `PRINCIPAL_NAME` varchar(10) default '' COMMENT '负责人姓名', + `REMARK` varchar(255) default '' COMMENT '备注', + `DEL_FLAG` int(11) 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 ='工作日志(服务)-记录'; + + +# 工作日志-服务分类 +CREATE TABLE `workdiary_service_type` +( + `ID` varchar(64) NOT NULL COMMENT '主键', + `CUSTOMER_ID` varchar(64) NOT NULL COMMENT '客户id', + `SERVICE_TYPE` tinyint(3) NOT NULL COMMENT '服务类型', + `SERVICE_TYPE_NAME` varchar(32) NOT NULL COMMENT '服务类型名称', + `ENABLED` tinyint(1) NOT NULL COMMENT '是否启用。0:禁用,1:启用', + `DEL_FLAG` int(11) 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`), + unique index cust_service_type(CUSTOMER_ID asc , SERVICE_TYPE asc , DEL_FLAG asc) using btree +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 COMMENT ='工作日志(服务)-服务类型' diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/WorkdiaryServiceRecordDao.xml b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/WorkdiaryServiceRecordDao.xml new file mode 100755 index 0000000000..0f92add2d8 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/WorkdiaryServiceRecordDao.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/WorkdiaryServiceTypeDao.xml b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/WorkdiaryServiceTypeDao.xml new file mode 100755 index 0000000000..b62d6f86c6 --- /dev/null +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/WorkdiaryServiceTypeDao.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/templates/workdiary_service_import.xlsx b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/templates/workdiary_service_import.xlsx new file mode 100644 index 0000000000..0938c354cf Binary files /dev/null and b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/templates/workdiary_service_import.xlsx differ diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/GridOptionFormDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/GridOptionFormDTO.java index e6fae52bc9..434af5aed4 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/GridOptionFormDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/GridOptionFormDTO.java @@ -1,6 +1,8 @@ package com.epmet.dto.form; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import javax.validation.constraints.NotBlank; import java.io.Serializable; @@ -11,6 +13,8 @@ import java.io.Serializable; * @Date 2021/11/12 10:54 上午 */ @Data +@NoArgsConstructor +@AllArgsConstructor public class GridOptionFormDTO implements Serializable { /** * 部门Id diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/HouseAgencyInfoResultDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/HouseAgencyInfoResultDTO.java index d5734e2791..eff5a441d8 100644 --- a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/HouseAgencyInfoResultDTO.java +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/HouseAgencyInfoResultDTO.java @@ -21,6 +21,7 @@ public class HouseAgencyInfoResultDTO implements Serializable { private String neighborHoodId; private String buildingId; private String buildingUnitId; + private String fullName; public HouseAgencyInfoResultDTO() { this.agencyId = ""; diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcHouseDao.xml b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcHouseDao.xml index 8b900c90dd..6098775330 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcHouseDao.xml +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcHouseDao.xml @@ -393,6 +393,7 @@ h.BUILDING_UNIT_ID, nh.AGENCY_ID, nh.GRID_ID, + h.FULL_NAME, nh.AGENCY_PIDS AS pids FROM ic_house h INNER JOIN ic_neighbor_hood nh ON (nh.ID = h.NEIGHBOR_HOOD_ID AND nh.DEL_FLAG = '0') diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/resi/IcResiPageNonDynamicFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/resi/IcResiPageNonDynamicFormDTO.java new file mode 100644 index 0000000000..e5453cda85 --- /dev/null +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/resi/IcResiPageNonDynamicFormDTO.java @@ -0,0 +1,25 @@ +package com.epmet.dto.form.resi; + +import com.epmet.commons.tools.dto.form.PageFormDTO; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class IcResiPageNonDynamicFormDTO extends PageFormDTO { + + private String gridId; + + private String name; + + private String mobile; + + /** + * 是否模糊。true:模糊,false:精确 + */ + private Boolean fuzzy = false; + +} diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/resi/IcResiNonDynamicResultDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/resi/IcResiNonDynamicResultDTO.java new file mode 100644 index 0000000000..52da33987e --- /dev/null +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/resi/IcResiNonDynamicResultDTO.java @@ -0,0 +1,23 @@ +package com.epmet.dto.result.resi; + +import lombok.Data; + +/** + * 居民基础信息V2 + */ +@Data +public class IcResiNonDynamicResultDTO { + private String id; + private String name; + private String customerId; + private String agencyId; + private String gridId; + private String villageId; + private String buildId; + private String unitId; + private String homeId; + private String mobile; + private String idCard; + private String gender; + private String idCardType; +} diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java index e37454ed35..47a67e5fbd 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java @@ -3,12 +3,15 @@ package com.epmet.feign; import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.dto.result.OptionDataResultDTO; +import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.*; import com.epmet.dto.form.*; import com.epmet.dto.form.patrol.PatrolQueryFormDTO; +import com.epmet.dto.form.resi.IcResiPageNonDynamicFormDTO; import com.epmet.dto.result.*; +import com.epmet.dto.result.resi.IcResiNonDynamicResultDTO; import com.epmet.feign.fallback.EpmetUserOpenFeignClientFallbackFactory; import com.epmet.resi.partymember.dto.partymember.IcPartyMemberDTO; import org.springframework.cloud.openfeign.FeignClient; @@ -871,4 +874,12 @@ public interface EpmetUserOpenFeignClient { @PostMapping("/epmetuser/customerstaff/customerstaff") Result> customerStaff(@RequestBody GridStaffUploadtFormDTO formDTO); + + /** + * 居民列表,非动态 + * @param input + * @return + */ + @PostMapping("/epmetuser/icresiuser/nonDynamic/listResi") + Result> listResiNonDynamic(@RequestBody IcResiPageNonDynamicFormDTO input); } diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java index 71711e66a8..7c9cc3b2a4 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java @@ -2,13 +2,16 @@ package com.epmet.feign.fallback; import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.dto.result.OptionDataResultDTO; +import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.ModuleUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.dto.*; import com.epmet.dto.form.*; import com.epmet.dto.form.patrol.PatrolQueryFormDTO; +import com.epmet.dto.form.resi.IcResiPageNonDynamicFormDTO; import com.epmet.dto.result.*; +import com.epmet.dto.result.resi.IcResiNonDynamicResultDTO; import com.epmet.feign.EpmetUserOpenFeignClient; import com.epmet.resi.partymember.dto.partymember.IcPartyMemberDTO; import org.springframework.web.bind.annotation.RequestBody; @@ -671,4 +674,8 @@ public class EpmetUserOpenFeignClientFallback implements EpmetUserOpenFeignClien return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "customerStaff", formDTO); } + @Override + public Result> listResiNonDynamic(IcResiPageNonDynamicFormDTO input) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "listResiNonDynamic", input); + } } 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 7ac26844dd..3ef123383f 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 @@ -55,8 +55,10 @@ import com.epmet.constant.SystemMessageType; import com.epmet.constants.ImportTaskConstants; import com.epmet.dto.IcResiUserDTO; import com.epmet.dto.form.*; +import com.epmet.dto.form.resi.IcResiPageNonDynamicFormDTO; import com.epmet.dto.result.*; import com.epmet.dto.result.demand.OptionDTO; +import com.epmet.dto.result.resi.IcResiNonDynamicResultDTO; import com.epmet.enums.IcResiUserTableEnum; import com.epmet.excel.PartyMemberAgeExportExcel; import com.epmet.excel.PartyMemberEducationExportExcel; @@ -1389,4 +1391,23 @@ public class IcResiUserController implements ResultDataResolver { return new Result().ok(icResiUserService.icUserMatchGrid(formDTO)); } + /** + * 居民列表分页查询 非动态 + * @param input + * @return + */ + @PostMapping("/nonDynamic/listResi") + public Result> listResiNonDynamic(@RequestBody IcResiPageNonDynamicFormDTO input) { + + String gridId = input.getGridId(); + String name = input.getName(); + Integer pageNo = input.getPageNo(); + Integer pageSize = input.getPageSize(); + Boolean fuzzy = input.getFuzzy(); + String mobile = input.getMobile(); + + PageData page = icResiUserService.listResiNonDynamic(fuzzy, gridId, name, mobile, pageNo, pageSize); + return new Result>().ok(page); + } + } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserService.java index 37cf258e14..8975e06443 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserService.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserService.java @@ -26,6 +26,7 @@ import com.epmet.dto.IcResiUserDTO; import com.epmet.dto.form.*; import com.epmet.dto.result.*; import com.epmet.dto.result.demand.OptionDTO; +import com.epmet.dto.result.resi.IcResiNonDynamicResultDTO; import com.epmet.entity.IcResiUserEntity; import com.epmet.excel.support.ExportResiUserItemDTO; import com.epmet.resi.partymember.dto.partymember.IcPartyMemberDTO; @@ -505,4 +506,5 @@ public interface IcResiUserService extends BaseService { */ IcUserMatchGridResultDTO icUserMatchGrid(IcUserMatchGridFormDTO formDTO); + PageData listResiNonDynamic(Boolean fuzzy, String gridId, String name, String mobile, Integer pageNo, Integer pageSize); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java index 0f55cab634..2f44c543d5 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java @@ -63,6 +63,7 @@ import com.epmet.dto.form.demand.UserDemandNameQueryFormDTO; import com.epmet.dto.result.*; import com.epmet.dto.result.demand.IcResiDemandDictDTO; import com.epmet.dto.result.demand.OptionDTO; +import com.epmet.dto.result.resi.IcResiNonDynamicResultDTO; import com.epmet.entity.*; import com.epmet.excel.support.ExportResiUserItemDTO; import com.epmet.feign.*; @@ -3333,4 +3334,21 @@ public class IcResiUserServiceImpl extends BaseServiceImpl" + customer); return customer; } + + @Override + public PageData listResiNonDynamic(Boolean fuzzy, String gridId, String name, String mobile, Integer pageNo, Integer pageSize) { + LambdaQueryWrapper query = new LambdaQueryWrapper<>(); + query.eq(IcResiUserEntity::getCustomerId, EpmetRequestHolder.getLoginUserCustomerId()); + query.eq(StringUtils.isNotBlank(gridId), IcResiUserEntity::getGridId, gridId); + // 一个模糊一个精确 + query.eq((!fuzzy && StringUtils.isNotBlank(name)), IcResiUserEntity::getName, name); + query.like((fuzzy && StringUtils.isNotBlank(name)), IcResiUserEntity::getName, name); + + query.eq((!fuzzy && StringUtils.isNotBlank(mobile)), IcResiUserEntity::getMobile, mobile); + query.like((fuzzy && StringUtils.isNotBlank(mobile)), IcResiUserEntity::getMobile, mobile); + + PageHelper.startPage(pageNo, pageSize); + List list = baseDao.selectList(query).stream().map((e) -> ConvertUtils.sourceToTarget(e, IcResiNonDynamicResultDTO.class)).collect(Collectors.toList()); + return new PageData(list, new PageInfo<>(list).getTotal(), pageSize); + } }