diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygienePlanEntity.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygienePlanEntity.java index f93c6c8..fd77873 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygienePlanEntity.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygienePlanEntity.java @@ -1,5 +1,6 @@ package com.hnac.hzims.safeproduct.entity; +import com.alibaba.excel.annotation.ExcelProperty; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModel; @@ -23,13 +24,16 @@ import java.util.Date; public class HygienePlanEntity extends BaseEntity { @Size(max = 50, message = "计划名称字段长度不能超过50") + @ExcelProperty(value = "计划名称", index = 0) @ApiModelProperty("计划名称") private String name; @Size(max = 50, message = "单位字段长度不能超过50") + @ExcelProperty(value = "单位", index = 1) @ApiModelProperty("单位") private String unit; + @ExcelProperty(value = "标准总分值", index = 2) @ApiModelProperty("标准总分值") private Integer standardScore; @@ -43,6 +47,15 @@ public class HygienePlanEntity extends BaseEntity { @ApiModelProperty("计划结束时间") private Date scheduledEndTime; + @ExcelProperty(value = "自查计划状态", index = 5) @ApiModelProperty("自查计划状态") private String hygienePlanStatus; + + @ExcelProperty(value = "计划开始时间", index = 3) + @ApiModelProperty("计划开始时间") + private String startTime; + + @ExcelProperty(value = "计划结束时间", index = 4) + @ApiModelProperty("计划结束时间") + private String endTime; } diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneRecordPageVO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneRecordPageVO.java index 9cc2f9a..17793cc 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneRecordPageVO.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneRecordPageVO.java @@ -17,6 +17,9 @@ public class HygieneRecordPageVO { @ApiModelProperty("卫生自查记录id") private Long id; + @ApiModelProperty("卫生自查计划id") + private Long hygienePlanId; + @ApiModelProperty("单位") private String unit; diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/HygieneController.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/HygieneController.java index 0a271f9..0af5879 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/HygieneController.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/HygieneController.java @@ -114,7 +114,10 @@ public class HygieneController extends BladeController { @GetMapping("/recordPage") @ApiImplicitParams({ - @ApiImplicitParam(name = "hygienePlanId", value = "卫生自查计划id", dataType = "query", paramType = "string") + @ApiImplicitParam(name = "hygienePlanId", value = "卫生自查计划id", dataType = "query", paramType = "string"), + @ApiImplicitParam(name = "unit", value = "单位", dataType = "query", paramType = "string"), + @ApiImplicitParam(name = "actualStartTime", value = "开始时间", dataType = "query", paramType = "string"), + @ApiImplicitParam(name = "actualEndTime", value = "结束时间", dataType = "query", paramType = "string") }) @ApiOperation(value = "卫生自查记录分页") @ApiOperationSupport(order = 10) @@ -148,4 +151,17 @@ public class HygieneController extends BladeController { public void exportMonthData(@ApiIgnore @RequestParam Map param, Query query, HttpServletResponse response) { hygienePlanService.exportMonthData(param, query, response); } + + @GetMapping("/exportHygienePlanData") + @ApiImplicitParams({ + @ApiImplicitParam(name = "unit", value = "单位", dataType = "query", paramType = "string"), + @ApiImplicitParam(name = "name", value = "名称", dataType = "query", paramType = "string"), + @ApiImplicitParam(name = "scheduledStartTime", value = "计划开始时间", dataType = "query", paramType = "string"), + @ApiImplicitParam(name = "scheduledEndTime", value = "计划结束时间", dataType = "query", paramType = "string") + }) + @ApiOperation(value = "卫生自查计划导出") + @ApiOperationSupport(order = 14) + public void exportHygienePlanData(@ApiIgnore @RequestParam Map param, HttpServletResponse response) { + hygienePlanService.exportHygienePlanData(param, response); + } } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygieneRecordMapper.xml b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygieneRecordMapper.xml index 36b935f..9f06eb5 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygieneRecordMapper.xml +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygieneRecordMapper.xml @@ -14,7 +14,7 @@ diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygienePlanService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygienePlanService.java index 5337d07..a564531 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygienePlanService.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygienePlanService.java @@ -85,4 +85,11 @@ public interface IHygienePlanService extends IService { * @return 卫生自查计划数据 */ List getWaitingHygienePlanInTimeRange(String startTime, String endTime); + + /** + * 卫生自查计划数据导出 + * @param param 入参 + * @param response 响应类 + */ + void exportHygienePlanData(Map param, HttpServletResponse response); } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygienePlanServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygienePlanServiceImpl.java index 4cf06fd..2c3b176 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygienePlanServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygienePlanServiceImpl.java @@ -23,6 +23,7 @@ import com.hnac.hzims.safeproduct.vo.HygieneMonthVO; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.DateUtil; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -125,10 +126,7 @@ public class HygienePlanServiceImpl extends ServiceImpl standardScore) { - return R.fail("累计分值已超过标准总分值"); + throw new ServiceException("累计分值超过标准总分值"); } } - return sum < standardScore ? R.fail("标准总分值未全部分配") : R.data(sum); + if (sum < standardScore) { + throw new ServiceException("标准总分值未全部分配"); + } } /** @@ -297,4 +294,93 @@ public class HygienePlanServiceImpl extends ServiceImpl param, HttpServletResponse response) { + ServletOutputStream outputStream = null; + try { + outputStream = response.getOutputStream(); + String unit = String.valueOf(param.get("unit")); + String name = String.valueOf(param.get("name")); + String startTime = String.valueOf(param.get("scheduledStartTime")); + String endTime = String.valueOf(param.get("scheduledEndTime")); + List hygienePlanList = getHygienePlanByUnitNameAndTime(unit, name, startTime, endTime); + // 数据处理 + hygienePlanList.forEach(plan -> { + // 卫生自查状态 + String status; + if (plan.getHygienePlanStatus().equals(HygieneStatusEnum.WAITING.getValue())) { + status = HygieneStatusEnum.WAITING.getDesc(); + } else if (plan.getHygienePlanStatus().equals(HygieneStatusEnum.UNFINISHED.getValue())) { + status = HygieneStatusEnum.UNFINISHED.getDesc(); + } else { + status = HygieneStatusEnum.FINISHED.getDesc(); + } + plan.setHygienePlanStatus(status); + // 时间格式 + plan.setStartTime(DateUtil.format(plan.getScheduledStartTime(), DateUtil.PATTERN_DATE)); + plan.setEndTime(DateUtil.format(plan.getScheduledEndTime(), DateUtil.PATTERN_DATE)); + }); + // 设置响应头 + // URLEncoder.encode防止中文乱码 + String fileName = URLEncoder.encode("卫生自查计划表", "UTF-8"); + response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); + response.setContentType("application/vnd.ms-excel"); + response.setCharacterEncoding("UTF-8"); + // ExcelWriter初始化 + ExcelWriter excelWriter = EasyExcel + .write(response.getOutputStream()) + .autoCloseStream(Boolean.TRUE) + .registerConverter(new LongStringConverter()) + .registerWriteHandler(new SimpleColumnWidthStyleStrategy(25)) + .build(); + WriteSheet writeSheet = EasyExcel.writerSheet(1, "卫生自查计划表").head(HygienePlanEntity.class) + .build(); + excelWriter.write(hygienePlanList, writeSheet); + excelWriter.finish(); + } catch (Exception e) { + // 重置response + response.reset(); + response.setContentType("application/json"); + response.setCharacterEncoding("utf-8"); + throw new ServiceException("卫生自查计划表数据导出异常: " + e.getMessage()); + } finally { + if (outputStream != null) { + try { + outputStream.close(); + } catch (IOException e) { + log.error("卫生自查计划表数据导出输出流关闭异常: " + e.getMessage()); + } + } + } + } + + /** + * 根据单位、名称、时间查询卫生自查计划 + * @param unit 单位 + * @param name 名称 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @return 卫生自查计划数据 + */ + private List getHygienePlanByUnitNameAndTime(String unit, String name, String startTime, String endTime) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (!unit.equals("null") && !unit.equals("")) { + queryWrapper.lambda().like(HygienePlanEntity::getUnit, unit); + } + if (!name.equals("null") && !name.equals("")) { + queryWrapper.lambda().like(HygienePlanEntity::getName, name); + } + if (!startTime.equals("null") && !startTime.equals("")) { + queryWrapper.lambda().ge(HygienePlanEntity::getScheduledStartTime, startTime); + } + if (!endTime.equals("null") && !endTime.equals("")) { + queryWrapper.lambda().le(HygienePlanEntity::getScheduledEndTime, endTime); + } + queryWrapper.lambda().orderByDesc(HygienePlanEntity::getCreateTime); + return this.list(queryWrapper); + } } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java index e37c3fd..608f1ed 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java @@ -20,12 +20,14 @@ import com.hnac.hzims.safeproduct.utils.BaseUtil; import com.hnac.hzims.safeproduct.vo.HygieneRecordPageVO; import com.hnac.hzims.safeproduct.vo.HygieneZoneDetailVO; import com.hnac.hzims.safeproduct.vo.HygieneRecordDetailVO; +import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; @@ -73,17 +75,19 @@ public class HygieneRecordServiceImpl extends ServiceImpl hygienePlanEntity.getStandardScore()) { - return R.fail("评分不能大于标准总分值"); + throw new ServiceException("评分不能大于标准总分值"); } } boolean save = this.save(hygieneRecordEntity); @@ -178,8 +182,7 @@ public class HygieneRecordServiceImpl extends ServiceImpl list = getHygieneByMonth(month); + List list = getHygieneByMonth(currentMonth); if (CollectionUtils.isEmpty(list)) { return null; }