Browse Source

add: 新增卫生考核表导出功能

zhongwei
liwen 3 months ago
parent
commit
abaf2b8217
  1. 1
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/constants/SafeProductConstant.java
  2. 59
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/HygieneEvaluationExportDTO.java
  3. 50
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/HygieneController.java
  4. 7
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygieneRecordService.java
  5. 99
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java
  6. 40
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java
  7. BIN
      hzims-service/safeproduct/src/main/resources/template/卫生考核表.xlsx

1
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/constants/SafeProductConstant.java

@ -20,6 +20,7 @@ public interface SafeProductConstant {
*/ */
String DOCX_SUFFIX = ".docx"; String DOCX_SUFFIX = ".docx";
String PDF_SUFFIX = ".pdf"; String PDF_SUFFIX = ".pdf";
String XLSX_SUFFIX = ".xlsx";
/** /**
* 培训管理 * 培训管理

59
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/HygieneEvaluationExportDTO.java

@ -0,0 +1,59 @@
package com.hnac.hzims.safeproduct.dto;
import com.hnac.hzims.safeproduct.vo.HygieneEvaluationPeopleVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @author liwen
* @date 2024-08-20
*/
@Data
@ApiModel(value = "卫生考核导出DTO类")
public class HygieneEvaluationExportDTO {
@ApiModelProperty(value = "年份")
private String year;
@ApiModelProperty(value = "月份")
private String month;
@ApiModelProperty(value = "第一周开始日")
private String firstWeekStart;
@ApiModelProperty(value = "第一周结束日")
private String firstWeekEnd;
@ApiModelProperty(value = "第二周开始日")
private String secondWeekStart;
@ApiModelProperty(value = "第二周结束日")
private String secondWeekEnd;
@ApiModelProperty(value = "第三周开始日")
private String thirdWeekStart;
@ApiModelProperty(value = "第三周结束日")
private String thirdWeekEnd;
@ApiModelProperty(value = "第四周开始日")
private String fourthWeekStart;
@ApiModelProperty(value = "第四周结束日")
private String fourthWeekEnd;
@ApiModelProperty(value = "第五周开始日")
private String fifthWeekStart;
@ApiModelProperty(value = "第五周结束日")
private String fifthWeekEnd;
@ApiModelProperty(value = "备注")
private String remark;
@ApiModelProperty(value = "考核人员列表")
private List<HygieneEvaluationPeopleVO> evaluationList;
}

50
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/HygieneController.java

@ -39,7 +39,7 @@ import java.util.Map;
@RestController @RestController
@AllArgsConstructor @AllArgsConstructor
@RequestMapping("/hygiene") @RequestMapping("/hygiene")
@Business(module = Constants.APP_NAME, value = "卫生自查", ignore = false) @Business(module = Constants.APP_NAME, value = "卫生自查")
@Api(value = "卫生自查", tags = "卫生自查接口") @Api(value = "卫生自查", tags = "卫生自查接口")
public class HygieneController extends BladeController { public class HygieneController extends BladeController {
@ -52,7 +52,7 @@ public class HygieneController extends BladeController {
@PostMapping("/savePlan") @PostMapping("/savePlan")
@ApiOperation(value = "新增卫生自查计划") @ApiOperation(value = "新增卫生自查计划")
@ApiOperationSupport(order = 1) @ApiOperationSupport(order = 1)
@Operate(label = "新增卫生自查计划", type = BusinessType.INSERT, ignore = false) @Operate(label = "新增卫生自查计划", type = BusinessType.INSERT)
public R savePlan(@Valid @RequestBody HygienePlanDTO hygienePlanDTO) { public R savePlan(@Valid @RequestBody HygienePlanDTO hygienePlanDTO) {
return hygienePlanService.savePlan(hygienePlanDTO); return hygienePlanService.savePlan(hygienePlanDTO);
} }
@ -60,7 +60,7 @@ public class HygieneController extends BladeController {
@PostMapping("/updatePlan") @PostMapping("/updatePlan")
@ApiOperation(value = "修改卫生自查计划") @ApiOperation(value = "修改卫生自查计划")
@ApiOperationSupport(order = 2) @ApiOperationSupport(order = 2)
@Operate(label = "修改卫生自查计划", type = BusinessType.UPDATE, ignore = false) @Operate(label = "修改卫生自查计划", type = BusinessType.UPDATE)
public R updatePlan(@Valid @RequestBody HygienePlanDTO hygienePlanDTO) { public R updatePlan(@Valid @RequestBody HygienePlanDTO hygienePlanDTO) {
return hygienePlanService.updatePlan(hygienePlanDTO); return hygienePlanService.updatePlan(hygienePlanDTO);
} }
@ -68,7 +68,7 @@ public class HygieneController extends BladeController {
@PostMapping("/removePlan") @PostMapping("/removePlan")
@ApiOperation(value = "删除卫生自查计划") @ApiOperation(value = "删除卫生自查计划")
@ApiOperationSupport(order = 3) @ApiOperationSupport(order = 3)
@Operate(label = "删除卫生自查计划", type = BusinessType.DELETE, ignore = false) @Operate(label = "删除卫生自查计划", type = BusinessType.DELETE)
public R removePlan(@RequestParam Long id) { public R removePlan(@RequestParam Long id) {
return R.status(hygienePlanService.removePlan(id)); return R.status(hygienePlanService.removePlan(id));
} }
@ -76,7 +76,7 @@ public class HygieneController extends BladeController {
@GetMapping("/planDetail") @GetMapping("/planDetail")
@ApiOperation(value = "卫生自查计划详情") @ApiOperation(value = "卫生自查计划详情")
@ApiOperationSupport(order = 4) @ApiOperationSupport(order = 4)
@Operate(label = "卫生自查计划详情", type = BusinessType.QUERY, ignore = false) @Operate(label = "卫生自查计划详情", type = BusinessType.QUERY)
public R<HygienePlanDetailVO> planDetail(@RequestParam Long id) { public R<HygienePlanDetailVO> planDetail(@RequestParam Long id) {
return R.data(hygienePlanService.getPlan(id)); return R.data(hygienePlanService.getPlan(id));
} }
@ -90,7 +90,7 @@ public class HygieneController extends BladeController {
}) })
@ApiOperation(value = "卫生自查计划分页") @ApiOperation(value = "卫生自查计划分页")
@ApiOperationSupport(order = 5) @ApiOperationSupport(order = 5)
@Operate(label = "卫生自查计划分页", type = BusinessType.QUERY, ignore = false) @Operate(label = "卫生自查计划分页", type = BusinessType.QUERY)
public R<IPage<HygienePlanEntity>> planPage(@ApiIgnore @RequestParam Map<String, Object> param, Query query) { public R<IPage<HygienePlanEntity>> planPage(@ApiIgnore @RequestParam Map<String, Object> param, Query query) {
IPage<HygienePlanEntity> page = hygienePlanService.planPage(param, query); IPage<HygienePlanEntity> page = hygienePlanService.planPage(param, query);
return R.data(page); return R.data(page);
@ -99,7 +99,7 @@ public class HygieneController extends BladeController {
@PostMapping("/saveRecord") @PostMapping("/saveRecord")
@ApiOperation(value = "新增卫生自查记录") @ApiOperation(value = "新增卫生自查记录")
@ApiOperationSupport(order = 6) @ApiOperationSupport(order = 6)
@Operate(label = "新增卫生自查记录", type = BusinessType.INSERT, ignore = false) @Operate(label = "新增卫生自查记录", type = BusinessType.INSERT)
public R saveRecord(@Valid @RequestBody HygieneRecordDTO hygieneRecordDTO) { public R saveRecord(@Valid @RequestBody HygieneRecordDTO hygieneRecordDTO) {
return hygieneRecordService.saveRecord(hygieneRecordDTO); return hygieneRecordService.saveRecord(hygieneRecordDTO);
} }
@ -107,7 +107,7 @@ public class HygieneController extends BladeController {
@PostMapping("/updateRecord") @PostMapping("/updateRecord")
@ApiOperation(value = "修改卫生自查记录") @ApiOperation(value = "修改卫生自查记录")
@ApiOperationSupport(order = 7) @ApiOperationSupport(order = 7)
@Operate(label = "修改卫生自查记录", type = BusinessType.UPDATE, ignore = false) @Operate(label = "修改卫生自查记录", type = BusinessType.UPDATE)
public R updateRecord(@Valid @RequestBody HygieneRecordDTO hygieneRecordDTO) { public R updateRecord(@Valid @RequestBody HygieneRecordDTO hygieneRecordDTO) {
return hygieneRecordService.updateRecord(hygieneRecordDTO); return hygieneRecordService.updateRecord(hygieneRecordDTO);
} }
@ -115,7 +115,7 @@ public class HygieneController extends BladeController {
@PostMapping("/removeRecord") @PostMapping("/removeRecord")
@ApiOperation(value = "删除卫生自查记录") @ApiOperation(value = "删除卫生自查记录")
@ApiOperationSupport(order = 8) @ApiOperationSupport(order = 8)
@Operate(label = "删除卫生自查记录", type = BusinessType.DELETE, ignore = false) @Operate(label = "删除卫生自查记录", type = BusinessType.DELETE)
public R removeRecord(@RequestParam Long id) { public R removeRecord(@RequestParam Long id) {
return R.status(hygieneRecordService.removeById(id)); return R.status(hygieneRecordService.removeById(id));
} }
@ -123,7 +123,7 @@ public class HygieneController extends BladeController {
@GetMapping("/recordDetail") @GetMapping("/recordDetail")
@ApiOperation(value = "卫生自查记录详情") @ApiOperation(value = "卫生自查记录详情")
@ApiOperationSupport(order = 9) @ApiOperationSupport(order = 9)
@Operate(label = "卫生自查记录详情", type = BusinessType.QUERY, ignore = false) @Operate(label = "卫生自查记录详情", type = BusinessType.QUERY)
public R<HygieneRecordDetailVO> recordDetail(@RequestParam Long id) { public R<HygieneRecordDetailVO> recordDetail(@RequestParam Long id) {
return R.data(hygieneRecordService.getRecordDetail(id)); return R.data(hygieneRecordService.getRecordDetail(id));
} }
@ -137,7 +137,7 @@ public class HygieneController extends BladeController {
}) })
@ApiOperation(value = "卫生自查记录分页") @ApiOperation(value = "卫生自查记录分页")
@ApiOperationSupport(order = 10) @ApiOperationSupport(order = 10)
@Operate(label = "卫生自查记录分页", type = BusinessType.QUERY, ignore = false) @Operate(label = "卫生自查记录分页", type = BusinessType.QUERY)
public R<IPage<HygieneRecordPageVO>> recordPage(@ApiIgnore @RequestParam Map<String, Object> param, Query query) { public R<IPage<HygieneRecordPageVO>> recordPage(@ApiIgnore @RequestParam Map<String, Object> param, Query query) {
IPage<HygieneRecordPageVO> page = hygieneRecordService.recordPage(param, query); IPage<HygieneRecordPageVO> page = hygieneRecordService.recordPage(param, query);
return R.data(page); return R.data(page);
@ -146,7 +146,7 @@ public class HygieneController extends BladeController {
@GetMapping("/dataByMonth") @GetMapping("/dataByMonth")
@ApiOperation(value = "月度统计表") @ApiOperation(value = "月度统计表")
@ApiOperationSupport(order = 11) @ApiOperationSupport(order = 11)
@Operate(label = "月度统计表", type = BusinessType.QUERY, ignore = false) @Operate(label = "月度统计表", type = BusinessType.QUERY)
public R<IPage<HygieneMonthVO>> dataByMonth(@RequestParam String month, String unit, Query query) { public R<IPage<HygieneMonthVO>> dataByMonth(@RequestParam String month, String unit, Query query) {
IPage<HygieneMonthVO> page = hygienePlanService.dataByMonth(month, unit, query); IPage<HygieneMonthVO> page = hygienePlanService.dataByMonth(month, unit, query);
return R.data(page); return R.data(page);
@ -155,7 +155,7 @@ public class HygieneController extends BladeController {
@GetMapping("/exportHygieneRecordData") @GetMapping("/exportHygieneRecordData")
@ApiOperation(value = "卫生自查记录表导出") @ApiOperation(value = "卫生自查记录表导出")
@ApiOperationSupport(order = 12) @ApiOperationSupport(order = 12)
@Operate(label = "卫生自查记录表导出", type = BusinessType.EXPORT, ignore = false) @Operate(label = "卫生自查记录表导出", type = BusinessType.EXPORT)
public void exportHygieneRecordData(@RequestParam Long id, HttpServletResponse response) { public void exportHygieneRecordData(@RequestParam Long id, HttpServletResponse response) {
hygieneRecordService.exportHygieneRecordData(id, response); hygieneRecordService.exportHygieneRecordData(id, response);
} }
@ -167,7 +167,7 @@ public class HygieneController extends BladeController {
}) })
@ApiOperation(value = "月度数据导出") @ApiOperation(value = "月度数据导出")
@ApiOperationSupport(order = 13) @ApiOperationSupport(order = 13)
@Operate(label = "月度数据导出", type = BusinessType.EXPORT, ignore = false) @Operate(label = "月度数据导出", type = BusinessType.EXPORT)
public void exportMonthData(@ApiIgnore @RequestParam Map<String, Object> param, Query query, HttpServletResponse response) { public void exportMonthData(@ApiIgnore @RequestParam Map<String, Object> param, Query query, HttpServletResponse response) {
hygienePlanService.exportMonthData(param, query, response); hygienePlanService.exportMonthData(param, query, response);
} }
@ -181,7 +181,7 @@ public class HygieneController extends BladeController {
}) })
@ApiOperation(value = "卫生自查计划导出") @ApiOperation(value = "卫生自查计划导出")
@ApiOperationSupport(order = 14) @ApiOperationSupport(order = 14)
@Operate(label = "卫生自查计划导出", type = BusinessType.EXPORT, ignore = false) @Operate(label = "卫生自查计划导出", type = BusinessType.EXPORT)
public void exportHygienePlanData(@ApiIgnore @RequestParam Map<String, Object> param, HttpServletResponse response) { public void exportHygienePlanData(@ApiIgnore @RequestParam Map<String, Object> param, HttpServletResponse response) {
hygienePlanService.exportHygienePlanData(param, response); hygienePlanService.exportHygienePlanData(param, response);
} }
@ -189,7 +189,7 @@ public class HygieneController extends BladeController {
@PostMapping("/saveHygieneTemplate") @PostMapping("/saveHygieneTemplate")
@ApiOperation(value = "新增卫生自查模板") @ApiOperation(value = "新增卫生自查模板")
@ApiOperationSupport(order = 15) @ApiOperationSupport(order = 15)
@Operate(label = "新增卫生自查模板", type = BusinessType.INSERT, ignore = false) @Operate(label = "新增卫生自查模板", type = BusinessType.INSERT)
public R saveHygieneTemplate(@RequestBody HygieneTemplateDTO hygieneTemplateDTO) { public R saveHygieneTemplate(@RequestBody HygieneTemplateDTO hygieneTemplateDTO) {
boolean save = hygieneTemplateService.saveHygieneTemplate(hygieneTemplateDTO); boolean save = hygieneTemplateService.saveHygieneTemplate(hygieneTemplateDTO);
return R.status(save); return R.status(save);
@ -198,7 +198,7 @@ public class HygieneController extends BladeController {
@PostMapping("/updateHygieneTemplate") @PostMapping("/updateHygieneTemplate")
@ApiOperation(value = "修改卫生自查模板") @ApiOperation(value = "修改卫生自查模板")
@ApiOperationSupport(order = 16) @ApiOperationSupport(order = 16)
@Operate(label = "修改卫生自查模板", type = BusinessType.UPDATE, ignore = false) @Operate(label = "修改卫生自查模板", type = BusinessType.UPDATE)
public R updateHygieneTemplate(@RequestBody HygieneTemplateDTO hygieneTemplateDTO) { public R updateHygieneTemplate(@RequestBody HygieneTemplateDTO hygieneTemplateDTO) {
boolean update = hygieneTemplateService.updateHygieneTemplate(hygieneTemplateDTO); boolean update = hygieneTemplateService.updateHygieneTemplate(hygieneTemplateDTO);
return R.status(update); return R.status(update);
@ -207,7 +207,7 @@ public class HygieneController extends BladeController {
@PostMapping("/removeHygieneTemplate") @PostMapping("/removeHygieneTemplate")
@ApiOperation(value = "删除卫生自查模板") @ApiOperation(value = "删除卫生自查模板")
@ApiOperationSupport(order = 17) @ApiOperationSupport(order = 17)
@Operate(label = "删除卫生自查模板", type = BusinessType.DELETE, ignore = false) @Operate(label = "删除卫生自查模板", type = BusinessType.DELETE)
public R removeHygieneTemplate(@RequestParam Long id) { public R removeHygieneTemplate(@RequestParam Long id) {
boolean remove = hygieneTemplateService.removeHygieneTemplate(id); boolean remove = hygieneTemplateService.removeHygieneTemplate(id);
return R.status(remove); return R.status(remove);
@ -216,7 +216,7 @@ public class HygieneController extends BladeController {
@GetMapping("/hygieneTemplateDetail") @GetMapping("/hygieneTemplateDetail")
@ApiOperation(value = "卫生自查模板详情") @ApiOperation(value = "卫生自查模板详情")
@ApiOperationSupport(order = 18) @ApiOperationSupport(order = 18)
@Operate(label = "卫生自查模板详情", type = BusinessType.QUERY, ignore = false) @Operate(label = "卫生自查模板详情", type = BusinessType.QUERY)
public R<HygieneTemplateDetailVO> hygieneTemplateDetail(@RequestParam Long id) { public R<HygieneTemplateDetailVO> hygieneTemplateDetail(@RequestParam Long id) {
HygieneTemplateDetailVO detail = hygieneTemplateService.getHygieneTemplateDetail(id); HygieneTemplateDetailVO detail = hygieneTemplateService.getHygieneTemplateDetail(id);
return R.data(detail); return R.data(detail);
@ -225,7 +225,7 @@ public class HygieneController extends BladeController {
@GetMapping("/hygieneTemplatePage") @GetMapping("/hygieneTemplatePage")
@ApiOperation(value = "卫生自查模板分页") @ApiOperation(value = "卫生自查模板分页")
@ApiOperationSupport(order = 19) @ApiOperationSupport(order = 19)
@Operate(label = "卫生自查模板分页", type = BusinessType.QUERY, ignore = false) @Operate(label = "卫生自查模板分页", type = BusinessType.QUERY)
public R<IPage<HygieneTemplateEntity>> hygieneTemplatePage(@ApiIgnore @RequestParam Map<String, Object> param, Query query) { public R<IPage<HygieneTemplateEntity>> hygieneTemplatePage(@ApiIgnore @RequestParam Map<String, Object> param, Query query) {
IPage<HygieneTemplateEntity> page = hygieneTemplateService.getHygieneTemplatePage(param, query); IPage<HygieneTemplateEntity> page = hygieneTemplateService.getHygieneTemplatePage(param, query);
return R.data(page); return R.data(page);
@ -240,7 +240,7 @@ public class HygieneController extends BladeController {
}) })
@ApiOperation(value = "卫生月度详情列表") @ApiOperation(value = "卫生月度详情列表")
@ApiOperationSupport(order = 20) @ApiOperationSupport(order = 20)
@Operate(label = "卫生月度详情列表", type = BusinessType.QUERY, ignore = false) @Operate(label = "卫生月度详情列表", type = BusinessType.QUERY)
public R<IPage<HygienePlanEntity>> detailListByMonth(@ApiIgnore @RequestParam Map<String, Object> param, Query query) { public R<IPage<HygienePlanEntity>> detailListByMonth(@ApiIgnore @RequestParam Map<String, Object> param, Query query) {
IPage<HygienePlanEntity> page = hygienePlanService.getDetailListByMonth(param, query); IPage<HygienePlanEntity> page = hygienePlanService.getDetailListByMonth(param, query);
return R.data(page); return R.data(page);
@ -254,4 +254,12 @@ public class HygieneController extends BladeController {
HygieneEvaluationPageVO page = hygieneRecordService.getEvaluationPage(month); HygieneEvaluationPageVO page = hygieneRecordService.getEvaluationPage(month);
return R.data(page); return R.data(page);
} }
@GetMapping("/exportEvaluationData")
@ApiOperation(value = "卫生考核数据导出")
@ApiOperationSupport(order = 22)
@Operate(label = "卫生考核数据导出", type = BusinessType.EXPORT)
public void exportEvaluationData(@RequestParam String month, HttpServletResponse response) {
hygieneRecordService.exportEvaluationData(month, response);
}
} }

7
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygieneRecordService.java

@ -78,4 +78,11 @@ public interface IHygieneRecordService extends IService<HygieneRecordEntity> {
* @return 考核记录表VO类 * @return 考核记录表VO类
*/ */
HygieneEvaluationPageVO getEvaluationPage(String month); HygieneEvaluationPageVO getEvaluationPage(String month);
/**
* 卫生考核数据导出
* @param month 当前月份
* @param response 响应类
*/
void exportEvaluationData(String month, HttpServletResponse response);
} }

99
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java

@ -1,17 +1,24 @@
package com.hnac.hzims.safeproduct.service.impl; package com.hnac.hzims.safeproduct.service.impl;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DatePattern;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnac.hzims.common.utils.DateUtil; import com.hnac.hzims.common.utils.DateUtil;
import com.hnac.hzims.safeproduct.constants.SafeProductConstant; import com.hnac.hzims.safeproduct.constants.SafeProductConstant;
import com.hnac.hzims.safeproduct.dto.HygieneEvaluationExportDTO;
import com.hnac.hzims.safeproduct.dto.HygieneRecordDTO; import com.hnac.hzims.safeproduct.dto.HygieneRecordDTO;
import com.hnac.hzims.safeproduct.entity.HygienePlanEntity; import com.hnac.hzims.safeproduct.entity.HygienePlanEntity;
import com.hnac.hzims.safeproduct.entity.HygieneRecordEntity; import com.hnac.hzims.safeproduct.entity.HygieneRecordEntity;
import com.hnac.hzims.safeproduct.entity.HygieneZoneEntity; import com.hnac.hzims.safeproduct.entity.HygieneZoneEntity;
import com.hnac.hzims.safeproduct.enums.RehearsalStatusEnum; import com.hnac.hzims.safeproduct.enums.RehearsalStatusEnum;
import com.hnac.hzims.safeproduct.hazard.util.ExcelConvertPdf;
import com.hnac.hzims.safeproduct.mapper.HygienePlanMapper; import com.hnac.hzims.safeproduct.mapper.HygienePlanMapper;
import com.hnac.hzims.safeproduct.mapper.HygieneRecordMapper; import com.hnac.hzims.safeproduct.mapper.HygieneRecordMapper;
import com.hnac.hzims.safeproduct.service.IHygieneRecordService; import com.hnac.hzims.safeproduct.service.IHygieneRecordService;
@ -19,6 +26,9 @@ import com.hnac.hzims.safeproduct.service.IHygieneZoneService;
import com.hnac.hzims.safeproduct.utils.BaseUtil; import com.hnac.hzims.safeproduct.utils.BaseUtil;
import com.hnac.hzims.safeproduct.vo.*; import com.hnac.hzims.safeproduct.vo.*;
import com.hnac.hzinfo.exception.HzServiceException; import com.hnac.hzinfo.exception.HzServiceException;
import com.itextpdf.text.DocumentException;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.support.Query; import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
@ -32,7 +42,14 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.DayOfWeek; import java.time.DayOfWeek;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId; import java.time.ZoneId;
@ -268,21 +285,21 @@ public class HygieneRecordServiceImpl extends ServiceImpl<HygieneRecordMapper, H
String[] scores = comprehensiveScoreList.get(i).split(","); String[] scores = comprehensiveScoreList.get(i).split(",");
// 查询责任区对应的负责人名称 // 查询责任区对应的负责人名称
List<HygieneZoneEntity> peopleNameList = baseMapper.selectHygieneZoneByIds(Arrays.asList(zoneIds)); List<HygieneZoneEntity> peopleNameList = baseMapper.selectHygieneZoneByIds(Arrays.asList(zoneIds));
// 遍历责任区数据 // 遍历责任区数据
for (int j = 0; j < zoneIds.length; j++) { for (int j = 0; j < zoneIds.length; j++) {
List<HygieneEvaluationScoreVO> scoreList = new ArrayList<>(); List<HygieneEvaluationScoreVO> scoreList = new ArrayList<>();
HygieneEvaluationPeopleVO peopleVO = new HygieneEvaluationPeopleVO(); HygieneEvaluationPeopleVO peopleVO = new HygieneEvaluationPeopleVO();
// 查询责任区的负责人名称
String zoneId = zoneIds[j]; String zoneId = zoneIds[j];
Optional<HygieneZoneEntity> zoneOptional = peopleNameList.stream().filter(x -> x.getId().equals(Long.valueOf(zoneId))).findFirst(); Optional<HygieneZoneEntity> zoneOptional = peopleNameList.stream().filter(x -> x.getId().equals(Long.valueOf(zoneId))).findFirst();
if (zoneOptional.isPresent()) { if (zoneOptional.isPresent()) {
// 卫生记录周数
Integer weekNo = hygieneRecordEntity.getWeekNum(); Integer weekNo = hygieneRecordEntity.getWeekNum();
// 考核人名称 // 负责人名称
String principal = zoneOptional.get().getPrincipal(); String principal = zoneOptional.get().getPrincipal();
// 判断单位内该名称是否已存在 // 判断单位内该名称是否已存在,存在则补充新的考核分数据,否则新增其考核分数据
Optional<HygieneEvaluationPeopleVO> checkPeople = evaluationList.stream().filter(x -> x.getPrincipal().equals(principal) && Optional<HygieneEvaluationPeopleVO> checkPeople = evaluationList.stream().filter(x -> x.getPrincipal().equals(principal) &&
x.getUnit().equals(hygieneRecordEntity.getUnit())).findFirst(); x.getUnit().equals(hygieneRecordEntity.getUnit())).findFirst();
if (checkPeople.isPresent()) { if (checkPeople.isPresent()) {
peopleVO = checkPeople.get(); peopleVO = checkPeople.get();
scoreList = peopleVO.getScoreList(); scoreList = peopleVO.getScoreList();
@ -307,11 +324,85 @@ public class HygieneRecordServiceImpl extends ServiceImpl<HygieneRecordMapper, H
evaluationList.add(peopleVO); evaluationList.add(peopleVO);
} }
} }
// 考核人员列表
pageVO.setEvaluationList(evaluationList); pageVO.setEvaluationList(evaluationList);
return pageVO; return pageVO;
} }
/** /**
* 卫生考核数据导出
*/
@Override
public void exportEvaluationData(String month, HttpServletResponse response) {
HygieneEvaluationPageVO page = this.getEvaluationPage(month);
if (ObjectUtil.isEmpty(page)) {
throw new HzServiceException(ResultCode.FAILURE, "无卫生考核数据");
}
// 数据处理
HygieneEvaluationExportDTO exportDTO = new HygieneEvaluationExportDTO();
exportDTO.setRemark(page.getRemark());
// 年份、月份
String[] time = month.split("-");
exportDTO.setYear(time[0]);
exportDTO.setMonth(time[1]);
// 周数据
List<HygieneWeekVO> weekList = page.getWeekList();
weekList.forEach(week -> {
String start = DateUtil.format(week.getStartDate(), "yyyy-MM-dd");
start = start.substring(start.indexOf("-") + 1);
String end = DateUtil.format(week.getEndDate(), "yyyy-MM-dd");
end = end.substring(end.indexOf("-") + 1);
switch (week.getWeekNum()) {
case 1:
exportDTO.setFirstWeekStart(start);
exportDTO.setFirstWeekEnd(end);
break;
case 2:
exportDTO.setSecondWeekStart(start);
exportDTO.setSecondWeekEnd(end);
break;
case 3:
exportDTO.setThirdWeekStart(start);
exportDTO.setThirdWeekEnd(end);
break;
case 4:
exportDTO.setFourthWeekStart(start);
exportDTO.setFourthWeekEnd(end);
break;
case 5:
exportDTO.setFifthWeekStart(start);
exportDTO.setFifthWeekEnd(end);
break;
}
});
// 考核人员数据
exportDTO.setEvaluationList(page.getEvaluationList());
// 封装参数
Map<String, Object> params = BaseUtil.obj2Map(exportDTO);
TemplateExportParams templateParams = new TemplateExportParams("template/卫生考核表.xlsx", true);
// 导出
try {
String fileName = URLEncoder.encode("卫生考核表.xlsx", "UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
response.setContentType("application/vnd.ms-excel;charset=utf-8");
Workbook workbook = ExcelExportUtil.exportExcel(templateParams, params);
Sheet sheet = workbook.getSheetAt(0);
BaseUtil.mergeCell(0, 0, JSONArray.parseArray(JSON.toJSONString(exportDTO)), "unit").forEach(sheet::addMergedRegion);
BaseUtil.mergeCell(0, 7, JSONArray.parseArray(JSON.toJSONString(exportDTO)), "remark").forEach(sheet::addMergedRegion);
String pdfPath = "D://" + "/卫生考核表" + SafeProductConstant.PDF_SUFFIX;
OutputStream outputStream = Files.newOutputStream(Paths.get(pdfPath));
ExcelConvertPdf.excelConvertPdf(workbook, outputStream);
BaseUtil.readPdf(response, pdfPath);
} catch (UnsupportedEncodingException e) {
log.error("卫生考核表导出异常-UnsupportedEncodingException:" + e.getMessage());
} catch (DocumentException e) {
log.error("卫生考核表导出异常-DocumentException:" + e.getMessage());
} catch (IOException e) {
log.error("卫生考核表导出异常-IOException:" + e.getMessage());
}
}
/**
* 查询是否存在同月编号 * 查询是否存在同月编号
* @param currentMonth 当月 * @param currentMonth 当月
* @return 存在则返回上一编号否则返回null * @return 存在则返回上一编号否则返回null

40
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java

@ -1,10 +1,13 @@
package com.hnac.hzims.safeproduct.utils; package com.hnac.hzims.safeproduct.utils;
import cn.afterturn.easypoi.word.WordExportUtil; import cn.afterturn.easypoi.word.WordExportUtil;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.common.logs.utils.StringUtils;
import com.hnac.hzims.safeproduct.constants.SafeProductConstant; import com.hnac.hzims.safeproduct.constants.SafeProductConstant;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xwpf.usermodel.*; import org.apache.poi.xwpf.usermodel.*;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
@ -421,4 +424,41 @@ public class BaseUtil {
throw new ServiceException("标准总分值未全部分配"); throw new ServiceException("标准总分值未全部分配");
} }
} }
/**
*
* @param initRow 起始行数
* @param initColumn 起始列数
* @param data 数据
* @param attribute 合并属性
* @return 单元格列表
*/
public static List<CellRangeAddress> mergeCell(int initRow, int initColumn, com.alibaba.fastjson.JSONArray data, String attribute) {
List<CellRangeAddress> result = Lists.newArrayList();
String initAttribute = com.alibaba.fastjson.JSONObject.parseObject(JSON.toJSONString(data.get(0))).getString(attribute);
int mergeCount = 1;
for (int index = 0; index < data.size(); index++) {
if (index == 0) {
continue;
}
com.alibaba.fastjson.JSONObject object = com.alibaba.fastjson.JSONObject.parseObject(JSON.toJSONString(data.get(index)));
if (object.getString(attribute).equals(initAttribute)) {
mergeCount++;
}
else {
if (mergeCount > 1) {
result.add(new CellRangeAddress(initRow, initRow+mergeCount-1, initColumn, initColumn));
}
initRow = initRow+mergeCount;
initAttribute = object.getString(attribute);
mergeCount = 1;
}
if (index == data.size() -1) {
if (mergeCount > 1) {
result.add(new CellRangeAddress(initRow, initRow + mergeCount-1, initColumn, initColumn));
}
}
}
return result;
}
} }

BIN
hzims-service/safeproduct/src/main/resources/template/卫生考核表.xlsx

Binary file not shown.
Loading…
Cancel
Save