35 changed files with 2162 additions and 1 deletions
@ -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<Date> { |
|||
|
|||
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());
|
|||
//}
|
|||
} |
@ -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; |
|||
|
|||
} |
@ -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; |
|||
|
|||
} |
@ -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; |
|||
|
|||
} |
@ -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<PageData<WorkdiaryServiceRecordDTO>> 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<WorkdiaryServiceRecordDTO> page = workdiaryServiceRecordService.page( |
|||
gridId, serviceType, applicantName, applicantAddress, serviceContent, applicantMobile, startTime, endTime, pageNo, pageSize); |
|||
return new Result<PageData<WorkdiaryServiceRecordDTO>>().ok(page); |
|||
} |
|||
|
|||
/** |
|||
* 记录-单条 |
|||
* @param id |
|||
* @return |
|||
*/ |
|||
@RequestMapping(value = "/record/{id}/detail",method = {RequestMethod.POST,RequestMethod.GET}) |
|||
public Result<WorkdiaryServiceRecordDTO> recordGet(@PathVariable("id") String id){ |
|||
WorkdiaryServiceRecordDTO data = workdiaryServiceRecordService.get(id); |
|||
return new Result<WorkdiaryServiceRecordDTO>().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<PageData<WorkdiaryServiceTypeDTO>> serviceTypePage(@RequestBody PageFormDTO input){ |
|||
PageData<WorkdiaryServiceTypeDTO> page = workdiaryServiceTypeService.page(null, input.getPageNo(), input.getPageSize()); |
|||
return new Result<PageData<WorkdiaryServiceTypeDTO>>().ok(page); |
|||
} |
|||
|
|||
/** |
|||
* 列出启用了的类型列表 |
|||
* @param input |
|||
* @return |
|||
*/ |
|||
@RequestMapping("/serviceType/avaliableList") |
|||
public Result<PageData<WorkdiaryServiceTypeDTO>> listAvaliableServiceType(@RequestBody PageFormDTO input){ |
|||
PageData<WorkdiaryServiceTypeDTO> page = workdiaryServiceTypeService.listAvaliableServiceType(input.getPageNo(), input.getPageSize()); |
|||
return new Result<PageData<WorkdiaryServiceTypeDTO>>().ok(page); |
|||
} |
|||
|
|||
/** |
|||
* 服务类型-单条 |
|||
* @return |
|||
*/ |
|||
@RequestMapping(value = "/serviceType/{id}/detail",method = {RequestMethod.POST,RequestMethod.GET}) |
|||
public Result<WorkdiaryServiceTypeDTO> serviceTypeGet(@PathVariable("id") String id){ |
|||
WorkdiaryServiceTypeDTO data = workdiaryServiceTypeService.get(id); |
|||
return new Result<WorkdiaryServiceTypeDTO>().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<String, Object> params, HttpServletResponse response) throws Exception { |
|||
List<WorkdiaryServiceTypeDTO> list = workdiaryServiceTypeService.list(params); |
|||
ExcelUtils.exportExcelToTarget(response, null, list, WorkdiaryServiceTypeExcel.class); |
|||
} |
|||
|
|||
|
|||
} |
@ -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<WorkdiaryServiceRecordEntity> { |
|||
|
|||
} |
@ -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<WorkdiaryServiceTypeEntity> { |
|||
|
|||
/** |
|||
* 该客户最大的type是啥 |
|||
* @param customerId |
|||
* @return |
|||
*/ |
|||
Short getMaxType(@Param("customerId") String customerId); |
|||
} |
@ -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; |
|||
|
|||
} |
@ -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; |
|||
|
|||
} |
@ -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; |
|||
|
|||
|
|||
} |
@ -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()); |
|||
} |
|||
} |
@ -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<WorkdiaryServiceRecordExcel> { |
|||
|
|||
/** |
|||
* 200 一批执行导入 |
|||
*/ |
|||
public static final Integer BATCH_SIZE = 200; |
|||
|
|||
/** |
|||
* 数据列表 |
|||
*/ |
|||
private List<WorkdiaryServiceRecordExcel> 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); |
|||
} |
|||
} |
@ -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; |
|||
} |
|||
|
|||
} |
@ -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; |
|||
} |
|||
|
|||
} |
@ -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<WorkdiaryServiceRecordEntity> { |
|||
|
|||
/** |
|||
* 默认分页 |
|||
* |
|||
* @param params |
|||
* @return PageData<WorkdiaryServiceRecordDTO> |
|||
* @author generator |
|||
* @date 2022-08-23 |
|||
*/ |
|||
PageData<WorkdiaryServiceRecordDTO> page(Map<String, Object> params); |
|||
|
|||
PageData<WorkdiaryServiceRecordDTO> 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<WorkdiaryServiceRecordDTO> |
|||
* @author generator |
|||
* @date 2022-08-23 |
|||
*/ |
|||
List<WorkdiaryServiceRecordDTO> list(Map<String, Object> 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<WorkdiaryServiceRecordExcel> datas); |
|||
} |
@ -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<WorkdiaryServiceTypeEntity> { |
|||
|
|||
/** |
|||
* 默认分页 |
|||
* |
|||
* @return PageData<WorkdiaryServiceTypeDTO> |
|||
* @author generator |
|||
* @date 2022-08-23 |
|||
*/ |
|||
PageData<WorkdiaryServiceTypeDTO> page(Short enabled, Integer pageNo, Integer pageSize); |
|||
|
|||
/** |
|||
* 默认查询 |
|||
* |
|||
* @param params |
|||
* @return java.util.List<WorkdiaryServiceTypeDTO> |
|||
* @author generator |
|||
* @date 2022-08-23 |
|||
*/ |
|||
List<WorkdiaryServiceTypeDTO> list(Map<String, Object> params); |
|||
|
|||
List<WorkdiaryServiceTypeDTO> 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<WorkdiaryServiceTypeDTO> listAvaliableServiceType(Integer pageNo, Integer pageSize); |
|||
} |
@ -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<WorkdiaryServiceRecordDao, WorkdiaryServiceRecordEntity> 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<List<ImportResultDesc>> 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<WorkdiaryServiceRecordDTO> page(Map<String, Object> params) { |
|||
IPage<WorkdiaryServiceRecordEntity> page = baseDao.selectPage( |
|||
getPage(params, FieldConstant.CREATED_TIME, false), |
|||
getWrapper(params) |
|||
); |
|||
return getPageData(page, WorkdiaryServiceRecordDTO.class); |
|||
} |
|||
|
|||
@Override |
|||
public PageData<WorkdiaryServiceRecordDTO> 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<WorkdiaryServiceRecordEntity> 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<WorkdiaryServiceTypeDTO> stList = SpringContextUtils.getBean(WorkdiaryServiceTypeService.class).list(null, 1, 100); |
|||
Map<Short, String> stMap = stList.stream().collect(Collectors.toMap(WorkdiaryServiceTypeDTO::getServiceType, WorkdiaryServiceTypeDTO::getServiceTypeName)); |
|||
|
|||
// 查找服务记录
|
|||
PageHelper.startPage(pageNo, pageSize); |
|||
List<WorkdiaryServiceRecordDTO> 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<WorkdiaryServiceRecordDTO> list(Map<String, Object> params) { |
|||
List<WorkdiaryServiceRecordEntity> entityList = baseDao.selectList(getWrapper(params)); |
|||
|
|||
return ConvertUtils.sourceToTarget(entityList, WorkdiaryServiceRecordDTO.class); |
|||
} |
|||
|
|||
private QueryWrapper<WorkdiaryServiceRecordEntity> getWrapper(Map<String, Object> params){ |
|||
String id = (String)params.get(FieldConstant.ID_HUMP); |
|||
|
|||
QueryWrapper<WorkdiaryServiceRecordEntity> 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<Short, String> stMap) { |
|||
|
|||
if (stMap == null || stMap.size() == 0) { |
|||
// 查找类型列表
|
|||
List<WorkdiaryServiceTypeDTO> 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<WorkdiaryServiceRecordDTO> page = this.page(gridId, serviceType, applicantName, applicantAddress, serviceContent, |
|||
applicantMobile, serviceTimeStart, serviceTimeEnd, pageNo, pageSize); |
|||
|
|||
List<WorkdiaryServiceRecordDTO> list = page.getList(); |
|||
if (CollectionUtils.isEmpty(list)) { |
|||
// 空的,导出结束
|
|||
break; |
|||
} |
|||
|
|||
List<WorkdiaryServiceRecordExcel> 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<WorkdiaryServiceRecordEntity> 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<ImportResultDesc> 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<WorkdiaryServiceRecordExcel> 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<WorkdiaryServiceTypeDTO> serviceTypes = SpringContextUtils.getBean(WorkdiaryServiceTypeService.class).page(null, 1, 100).getList(); |
|||
Map<String, WorkdiaryServiceTypeDTO> serviceTypeMap = serviceTypes.stream().collect(Collectors.toMap(WorkdiaryServiceTypeDTO::getServiceTypeName, Function.identity())); |
|||
|
|||
ArrayList<WorkdiaryServiceRecordEntity> 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<IcResiNonDynamicResultDTO> page = getResultDataOrThrowsException(userOpenFeignClient.listResiNonDynamic(new IcResiPageNonDynamicFormDTO(gridId, applicantName, mobile, false)), |
|||
ServiceConstant.EPMET_USER_SERVER, EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "居民未找到", "居民未找到"); |
|||
|
|||
List<IcResiNonDynamicResultDTO> 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<OptionResultDTO> 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; |
|||
} |
|||
} |
@ -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<WorkdiaryServiceTypeDao, WorkdiaryServiceTypeEntity> implements WorkdiaryServiceTypeService { |
|||
|
|||
@Autowired |
|||
private WorkdiaryServiceTypeRedis workdiaryServiceTypeRedis; |
|||
@Autowired |
|||
private RedisUtils redisUtils; |
|||
@Autowired |
|||
private DistributedLock distributedLock; |
|||
|
|||
@Override |
|||
public PageData<WorkdiaryServiceTypeDTO> page(Short enabled, Integer pageNo, Integer pageSize) { |
|||
List<WorkdiaryServiceTypeDTO> list = list(enabled, pageNo, pageSize); |
|||
return new PageData<>(list, new PageInfo<>(list).getTotal(), pageSize); |
|||
} |
|||
|
|||
@Override |
|||
public List<WorkdiaryServiceTypeDTO> list(Map<String, Object> params) { |
|||
List<WorkdiaryServiceTypeEntity> entityList = baseDao.selectList(getWrapper(params)); |
|||
|
|||
return ConvertUtils.sourceToTarget(entityList, WorkdiaryServiceTypeDTO.class); |
|||
} |
|||
|
|||
@Override |
|||
public List<WorkdiaryServiceTypeDTO> list(Short enabled, Integer pageNo, Integer pageSize) { |
|||
LambdaQueryWrapper<WorkdiaryServiceTypeEntity> stQuery = new LambdaQueryWrapper<>(); |
|||
stQuery.eq(WorkdiaryServiceTypeEntity::getCustomerId, EpmetRequestHolder.getLoginUserCustomerId()); |
|||
stQuery.eq(enabled != null, WorkdiaryServiceTypeEntity::getEnabled, enabled); |
|||
List<WorkdiaryServiceTypeDTO> 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<WorkdiaryServiceTypeDTO> listAvaliableServiceType(Integer pageNo, Integer pageSize) { |
|||
return this.page(Short.valueOf("1"), pageNo, pageSize); |
|||
} |
|||
|
|||
private QueryWrapper<WorkdiaryServiceTypeEntity> getWrapper(Map<String, Object> params){ |
|||
String id = (String)params.get(FieldConstant.ID_HUMP); |
|||
|
|||
QueryWrapper<WorkdiaryServiceTypeEntity> 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<WorkdiaryServiceTypeEntity> 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<String> 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; |
|||
} |
|||
|
|||
} |
@ -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 ='工作日志(服务)-服务类型' |
@ -0,0 +1,31 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
|
|||
<mapper namespace="com.epmet.dao.WorkdiaryServiceRecordDao"> |
|||
|
|||
<resultMap type="com.epmet.entity.WorkdiaryServiceRecordEntity" id="workdiaryServiceRecordMap"> |
|||
<result property="id" column="ID"/> |
|||
<result property="customerId" column="CUSTOMER_ID"/> |
|||
<result property="serviceType" column="SERVICE_TYPE"/> |
|||
<result property="agencyId" column="AGENCY_ID"/> |
|||
<result property="gridId" column="GRID_ID"/> |
|||
<result property="orgIdPath" column="ORG_ID_PATH"/> |
|||
<result property="applicantId" column="APPLICANT_ID"/> |
|||
<result property="applicantIdCard" column="APPLICANT_ID_CARD"/> |
|||
<result property="applicantName" column="APPLICANT_NAME"/> |
|||
<result property="applicantAddress" column="APPLICANT_ADDRESS"/> |
|||
<result property="applicantMobile" column="APPLICANT_MOBILE"/> |
|||
<result property="serviceContent" column="SERVICE_CONTENT"/> |
|||
<result property="serviceTime" column="SERVICE_TIME"/> |
|||
<result property="principalName" column="PRINCIPAL_NAME"/> |
|||
<result property="remark" column="REMARK"/> |
|||
<result property="delFlag" column="DEL_FLAG"/> |
|||
<result property="revision" column="REVISION"/> |
|||
<result property="createdBy" column="CREATED_BY"/> |
|||
<result property="createdTime" column="CREATED_TIME"/> |
|||
<result property="updatedBy" column="UPDATED_BY"/> |
|||
<result property="updatedTime" column="UPDATED_TIME"/> |
|||
</resultMap> |
|||
|
|||
|
|||
</mapper> |
@ -0,0 +1,27 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
|
|||
<mapper namespace="com.epmet.dao.WorkdiaryServiceTypeDao"> |
|||
|
|||
<resultMap type="com.epmet.entity.WorkdiaryServiceTypeEntity" id="workdiaryServiceTypeMap"> |
|||
<result property="id" column="ID"/> |
|||
<result property="customerId" column="CUSTOMER_ID"/> |
|||
<result property="serviceType" column="SERVICE_TYPE"/> |
|||
<result property="serviceTypeName" column="SERVICE_TYPE_NAME"/> |
|||
<result property="enabled" column="ENABLED"/> |
|||
<result property="delFlag" column="DEL_FLAG"/> |
|||
<result property="revision" column="REVISION"/> |
|||
<result property="createdBy" column="CREATED_BY"/> |
|||
<result property="createdTime" column="CREATED_TIME"/> |
|||
<result property="updatedBy" column="UPDATED_BY"/> |
|||
<result property="updatedTime" column="UPDATED_TIME"/> |
|||
</resultMap> |
|||
|
|||
<!--该客户最大的type是啥--> |
|||
<select id="getMaxType" resultType="java.lang.Short"> |
|||
select ifnull(max(SERVICE_TYPE), 0) max |
|||
from workdiary_service_type |
|||
where CUSTOMER_ID = #{customerId} |
|||
and DEL_FLAG = '0' |
|||
</select> |
|||
</mapper> |
Binary file not shown.
@ -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; |
|||
|
|||
} |
@ -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; |
|||
} |
Loading…
Reference in new issue