diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/HygieneExportDTO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/HygieneExportDTO.java new file mode 100644 index 0000000..4e8298e --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/HygieneExportDTO.java @@ -0,0 +1,21 @@ +package com.hnac.hzims.safeproduct.dto; + +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author liwen + * @date 2023-12-27 + */ +@Data +@ExcelIgnoreUnannotated +@ApiModel(value = "卫生自查数据导出DTO类") +public class HygieneExportDTO { + + @ApiModelProperty("卫生自查状态") + @ExcelProperty(value = "卫生自查状态", index = 8) + private String hygieneStatus; +} 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 new file mode 100644 index 0000000..84d558f --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygienePlanEntity.java @@ -0,0 +1,59 @@ +package com.hnac.hzims.safeproduct.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.base.BaseEntity; + +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.util.Date; + +/** + * @author liwen + * @date 2023-12-28 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("hzims_hygiene_plan") +@ApiModel(value = "卫生自查计划实体类") +public class HygienePlanEntity extends BaseEntity { + + @NotNull + @Size(max = 50, message = "单位字段长度不能超过50") + @ApiModelProperty("单位") + private String unit; + + @ApiModelProperty("责任区") + private String zone; + + @ApiModelProperty("责任人") + private String principal; + + @ApiModelProperty("检查项") + private String checkItem; + + @ApiModelProperty("检查项分值") + private String checkItemScore; + + @ApiModelProperty("标准总分值") + private Integer standardScore; + + @NotNull + @JsonFormat(pattern = "yyyy-MM-dd") + @ApiModelProperty("计划开始时间") + private Date scheduledStartTime; + + @NotNull + @JsonFormat(pattern = "yyyy-MM-dd") + @ApiModelProperty("计划结束时间") + private Date scheduledEndTime; + + @NotNull + @Size(max = 20, message = "卫生自查状态字段长度不能超过20") + @ApiModelProperty("卫生自查状态") + private String hygieneStatus; +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygieneRecordEntity.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygieneRecordEntity.java new file mode 100644 index 0000000..9122e7e --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygieneRecordEntity.java @@ -0,0 +1,51 @@ +package com.hnac.hzims.safeproduct.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.base.BaseEntity; + +import javax.validation.constraints.Size; +import java.util.Date; + +/** + * @author liwen + * @date 2023-12-28 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("hzims_hygiene_record") +@ApiModel(value = "卫生自查记录实体类") +public class HygieneRecordEntity extends BaseEntity { + + @ApiModelProperty("卫生自查计划id") + private Long hygienePlanId; + + @Size(max = 50, message = "编码字段长度不能超过50") + @ApiModelProperty("编码") + private String code; + + @ApiModelProperty("实际开始时间") + private Date actualStartTime; + + @ApiModelProperty("实际结束时间") + private Date actualEndTime; + + @ApiModelProperty("检查人") + private String checkUser; + + @ApiModelProperty("检查结果") + private String checkResult; + + @ApiModelProperty("综合评分") + private Integer comprehensiveScore; + + @ApiModelProperty("周数") + private Integer weekNum; + + @Size(max = 1000, message = "检查图片字段长度不能超过1000") + @ApiModelProperty("检查图片") + private String imgPath; +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/HygieneStatusEnum.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/HygieneStatusEnum.java new file mode 100644 index 0000000..2c86fcb --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/HygieneStatusEnum.java @@ -0,0 +1,31 @@ +package com.hnac.hzims.safeproduct.enums; + +/** + * 卫生自查状态枚举类 + * + * @author liwen + * @date 2023-12-29 + */ +public enum HygieneStatusEnum { + + WAITING("WAITING", "未开始"), + UNFINISHED("UNFINISHED", "未完成"), + FINISHED("FINISHED", "已完成"); + + private final String value; + + private final String desc; + + HygieneStatusEnum(String value, String desc) { + this.value = value; + this.desc = desc; + } + + public String getValue() { + return value; + } + + public String getDesc() { + return desc; + } +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneMonthVO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneMonthVO.java new file mode 100644 index 0000000..62b1c2b --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneMonthVO.java @@ -0,0 +1,31 @@ +package com.hnac.hzims.safeproduct.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @author liwen + * @date 2023-12-27 + */ +@Data +@ApiModel(value = "卫生自查月度统计VO类") +public class HygieneMonthVO { + + @ApiModelProperty("单位") + private String unit; + + @ApiModelProperty("应检查次数") + private Long scheduledCheckNum; + + @ApiModelProperty("已检查次数") + private Long finishedCheckNum; + + @ApiModelProperty("未检查次数") + private Long unfinishedCheckNum; + + @ApiModelProperty("完成率") + private BigDecimal completionRate; +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneRecordDetailVO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneRecordDetailVO.java new file mode 100644 index 0000000..341b402 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneRecordDetailVO.java @@ -0,0 +1,46 @@ +package com.hnac.hzims.safeproduct.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; + +/** + * @author liwen + * @date 2023-12-29 + */ +@Data +@ApiModel(value = "卫生自查记录详情VO类") +public class HygieneRecordDetailVO { + + @ApiModelProperty("责任区") + private String zone; + + @ApiModelProperty("责任人") + private String principal; + + @ApiModelProperty("检查项") + private String checkItem; + + @ApiModelProperty("检查项分值") + private String checkItemScore; + + @ApiModelProperty("编码") + private String code; + + @ApiModelProperty("检查时间") + private Date checkTime; + + @ApiModelProperty("检查人") + private String checkUser; + + @ApiModelProperty("检查结果") + private String checkResult; + + @ApiModelProperty("综合评分") + private Integer comprehensiveScore; + + @ApiModelProperty("周数") + private Integer weekNum; +} 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 new file mode 100644 index 0000000..ce00552 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/HygieneController.java @@ -0,0 +1,142 @@ +package com.hnac.hzims.safeproduct.controller; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.common.utils.Condition; +import com.hnac.hzims.safeproduct.entity.HygienePlanEntity; +import com.hnac.hzims.safeproduct.entity.HygieneRecordEntity; +import com.hnac.hzims.safeproduct.service.IHygienePlanService; +import com.hnac.hzims.safeproduct.service.IHygieneRecordService; +import com.hnac.hzims.safeproduct.vo.HygieneMonthVO; +import com.hnac.hzims.safeproduct.vo.HygieneRecordDetailVO; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import org.springblade.core.boot.ctrl.BladeController; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; + +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; +import java.util.Map; + +/** + * 卫生自查接口类 + * + * @author liwen + * @date 2023-12-27 + */ +@RestController +@AllArgsConstructor +@RequestMapping("/hygiene") +@Api(value = "卫生自查", tags = "卫生自查接口") +public class HygieneController extends BladeController { + + private final IHygienePlanService hygienePlanService; + + private final IHygieneRecordService hygieneRecordService; + + @PostMapping("/savePlan") + @ApiOperation(value = "新增卫生自查计划") + @ApiOperationSupport(order = 1) + public R savePlan(@Valid @RequestBody HygienePlanEntity hygienePlanEntity) { + return hygienePlanService.savePlan(hygienePlanEntity); + } + + @PostMapping("/updatePlan") + @ApiOperation(value = "修改卫生自查计划") + @ApiOperationSupport(order = 2) + public R updatePlan(@Valid @RequestBody HygienePlanEntity hygienePlanEntity) { + return hygienePlanService.updatePlan(hygienePlanEntity); + } + + @PostMapping("/removePlan") + @ApiOperation(value = "删除卫生自查计划") + @ApiOperationSupport(order = 3) + public R removePlan(@RequestParam Long id) { + return R.status(hygienePlanService.removePlan(id)); + } + + @GetMapping("/planDetail") + @ApiOperation(value = "卫生自查计划详情") + @ApiOperationSupport(order = 4) + public R planDetail(@RequestParam Long id) { + return R.data(hygienePlanService.getById(id)); + } + + @GetMapping("/planPage") + @ApiImplicitParams({ + @ApiImplicitParam(name = "zone", value = "责任区", dataType = "query", paramType = "string"), + @ApiImplicitParam(name = "principal", value = "责任人", dataType = "query", paramType = "string") + }) + @ApiOperation(value = "卫生自查计划分页") + @ApiOperationSupport(order = 5) + public R> planPage(@ApiIgnore @RequestParam Map param, Query query) { + IPage page = hygienePlanService.planPage(param, query); + return R.data(page); + } + + @PostMapping("/saveRecord") + @ApiOperation(value = "新增卫生自查记录") + @ApiOperationSupport(order = 6) + public R saveRecord(@Valid @RequestBody HygieneRecordEntity hygieneRecordEntity) { + return hygieneRecordService.saveRecord(hygieneRecordEntity); + } + + @PostMapping("/updateRecord") + @ApiOperation(value = "修改卫生自查记录") + @ApiOperationSupport(order = 7) + public R updateRecord(@Valid @RequestBody HygieneRecordEntity hygieneRecordEntity) { + return hygieneRecordService.updateRecord(hygieneRecordEntity); + } + + @PostMapping("/removeRecord") + @ApiOperation(value = "删除卫生自查记录") + @ApiOperationSupport(order = 8) + public R removeRecord(@RequestParam Long id) { + return R.status(hygieneRecordService.removeById(id)); + } + + @GetMapping("/recordDetail") + @ApiOperation(value = "卫生自查记录详情") + @ApiOperationSupport(order = 9) + public R recordDetail(@RequestParam Long id) { + return R.data(hygieneRecordService.getRecordDetail(id)); + } + + @GetMapping("/recordPage") + @ApiImplicitParams({ + @ApiImplicitParam(name = "hygienePlanId", value = "卫生自查计划id", dataType = "query", paramType = "string") + }) + @ApiOperation(value = "卫生自查记录分页") + @ApiOperationSupport(order = 10) + public R> recordPage(@ApiIgnore @RequestParam Map param, Query query) { + IPage page = hygieneRecordService.page(Condition.getPage(query), Condition.getQueryWrapper(param, + HygieneRecordEntity.class)); + return R.data(page); + } + + @GetMapping("/dataByMonth") + @ApiOperation(value = "月度统计表") + @ApiOperationSupport(order = 11) + public R> dataByMonth(@RequestParam String month, Query query) { + IPage page = hygienePlanService.dataByMonth(month, query); + return R.data(page); + } + + @GetMapping("/exportHygieneData") + @ApiImplicitParams({ + @ApiImplicitParam(name = "unit", 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 = 13) + public void exportHygieneData(@ApiIgnore @RequestParam Map param, HttpServletResponse response) { + hygienePlanService.exportHygieneData(param, response); + } +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygienePlanMapper.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygienePlanMapper.java new file mode 100644 index 0000000..a17a2da --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygienePlanMapper.java @@ -0,0 +1,45 @@ +package com.hnac.hzims.safeproduct.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.hnac.hzims.safeproduct.dto.HygieneExportDTO; +import com.hnac.hzims.safeproduct.entity.HygienePlanEntity; +import com.hnac.hzims.safeproduct.vo.HygieneMonthVO; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * 卫生自查计划Mapper类 + * + * @author liwen + * @date 2023-12-27 + */ +@Mapper +public interface HygienePlanMapper extends BaseMapper { + + /** + * 查询当月各单位的卫生自查总数 + * @param page 分页类 + * @param month 月份 + * @return 当月的卫生自查总数据 + */ + IPage selectByMonth(IPage page, String month); + + /** + * 查询当月各单位已完成的卫生自查数据 + * @param page 分页类 + * @param month 月份 + * @return 当月的已完成数据 + */ + IPage selectFinishedDataByMonth(IPage page, String month); + + /** + * 根据单位和计划时间查询卫生自查记录 + * @param unit 单位 + * @param startTime 计划开始时间 + * @param endTime 计划结束时间 + * @return 卫生自查记录 + */ + List getHygieneByUnitAndDate(String unit, String startTime, String endTime); +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygienePlanMapper.xml b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygienePlanMapper.xml new file mode 100644 index 0000000..a47decf --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygienePlanMapper.xml @@ -0,0 +1,52 @@ + + + + + + + + + \ No newline at end of file diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygieneRecordMapper.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygieneRecordMapper.java new file mode 100644 index 0000000..96ac415 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygieneRecordMapper.java @@ -0,0 +1,23 @@ +package com.hnac.hzims.safeproduct.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hnac.hzims.safeproduct.entity.HygieneRecordEntity; +import com.hnac.hzims.safeproduct.vo.HygieneRecordDetailVO; +import org.apache.ibatis.annotations.Mapper; + +/** + * 卫生自查记录Mapper类 + * + * @author liwen + * @date 2023-12-27 + */ +@Mapper +public interface HygieneRecordMapper extends BaseMapper { + + /** + * 查询卫生自查记录详情 + * @param id 卫生自查记录id + * @return 卫生自查记录详情VO类 + */ + HygieneRecordDetailVO getRecordDetail(Long id); +} 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 new file mode 100644 index 0000000..9913b1a --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygieneRecordMapper.xml @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file 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 new file mode 100644 index 0000000..6b62e72 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygienePlanService.java @@ -0,0 +1,64 @@ +package com.hnac.hzims.safeproduct.service; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.IService; +import com.hnac.hzims.safeproduct.entity.HygienePlanEntity; +import com.hnac.hzims.safeproduct.vo.HygieneMonthVO; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; + +import javax.servlet.http.HttpServletResponse; +import java.util.Map; + +/** + * 卫生自查计划服务类 + * + * @author liwen + * @date 2023-12-27 + */ +public interface IHygienePlanService extends IService { + + /** + * 删除卫生自查计划 + * @param id 卫生自查计划id + * @return true-成功,false-失败 + */ + boolean removePlan(Long id); + + /** + * 卫生自查计划分页 + * @param param 入参 + * @param query 分页类 + * @return 卫生自查计划数据 + */ + IPage planPage(Map param, Query query); + + /** + * 新增卫生自查计划 + * @param hygienePlanEntity 卫生自查计划实体类 + * @return 结果封装类 + */ + R savePlan(HygienePlanEntity hygienePlanEntity); + + /** + * 修改卫生自查计划 + * @param hygienePlanEntity 卫生自查计划实体类 + * @return 结果封装类 + */ + R updatePlan(HygienePlanEntity hygienePlanEntity); + + /** + * 卫生自查月度数据 + * @param month 月份 + * @param query 分页类 + * @return 月度统计分页 + */ + IPage dataByMonth(String month, Query query); + + /** + * 卫生自查数据导出 + * @param param 入参 + * @param response 响应类 + */ + void exportHygieneData(Map param, HttpServletResponse response); +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygieneRecordService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygieneRecordService.java new file mode 100644 index 0000000..93ac01e --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygieneRecordService.java @@ -0,0 +1,43 @@ +package com.hnac.hzims.safeproduct.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.hnac.hzims.safeproduct.entity.HygieneRecordEntity; +import com.hnac.hzims.safeproduct.vo.HygieneRecordDetailVO; +import org.springblade.core.tool.api.R; + +/** + * 卫生自查记录服务类 + * + * @author liwen + * @date 2023-12-27 + */ +public interface IHygieneRecordService extends IService { + + /** + * 删除关联卫生自查记录 + * @param hygienePlanId 卫生自查计划id + * @return true-成功,false-失败 + */ + boolean removeReferenceRecord(Long hygienePlanId); + + /** + * 新增卫生自查记录 + * @param hygieneRecordEntity 卫生自查记录实体类 + * @return 封装结果类 + */ + R saveRecord(HygieneRecordEntity hygieneRecordEntity); + + /** + * 修改卫生自查记录 + * @param hygieneRecordEntity 卫生自查记录实体类 + * @return true-成功,false-失败 + */ + R updateRecord(HygieneRecordEntity hygieneRecordEntity); + + /** + * 查询卫生自查记录详情 + * @param id 卫生自查记录id + * @return 卫生自查记录详情VO类 + */ + HygieneRecordDetailVO getRecordDetail(Long id); +} 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 new file mode 100644 index 0000000..4ca5f3c --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygienePlanServiceImpl.java @@ -0,0 +1,213 @@ +package com.hnac.hzims.safeproduct.service.impl; + +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.converters.longconverter.LongStringConverter; +import com.alibaba.excel.write.metadata.WriteSheet; +import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.hnac.hzims.common.utils.Condition; +import com.hnac.hzims.safeproduct.dto.HygieneExportDTO; +import com.hnac.hzims.safeproduct.entity.HygienePlanEntity; +import com.hnac.hzims.safeproduct.enums.HygieneStatusEnum; +import com.hnac.hzims.safeproduct.mapper.HygienePlanMapper; +import com.hnac.hzims.safeproduct.service.IHygienePlanService; +import com.hnac.hzims.safeproduct.service.IHygieneRecordService; +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.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.net.URLEncoder; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +/** + * 卫生自查计划服务实现类 + * + * @author liwen + * @date 2023-12-27 + */ +@Service +public class HygienePlanServiceImpl extends ServiceImpl implements IHygienePlanService { + + @Autowired + IHygieneRecordService hygieneRecordService; + + /** + * 删除卫生自查计划 + */ + @Override + public boolean removePlan(Long id) { + boolean remove = this.removeById(id); + if (remove) { + return hygieneRecordService.removeReferenceRecord(id); + } + return false; + } + + /** + * 卫生自查计划分页 + */ + @Override + public IPage planPage(Map param, Query query) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + String zone = String.valueOf(param.get("zone")); + String principal = String.valueOf(param.get("principal")); + if (!zone.equals("null") && !zone.equals("")) { + queryWrapper.lambda().like(HygienePlanEntity::getZone, zone); + } + if (!principal.equals("null") && !principal.equals("")) { + queryWrapper.lambda().ge(HygienePlanEntity::getPrincipal, principal); + } + return this.page(Condition.getPage(query), queryWrapper); + } + + /** + * 新增卫生自查计划 + */ + @Override + public R savePlan(HygienePlanEntity hygienePlanEntity) { + String[] scores = hygienePlanEntity.getCheckItemScore().split(",|,"); + Integer standardScore = hygienePlanEntity.getStandardScore(); + R res = getSumScore(scores, standardScore); + return res.isSuccess() ? R.status(this.save(hygienePlanEntity)) : res; + } + + /** + * 修改卫生自查计划 + */ + @Override + public R updatePlan(HygienePlanEntity hygienePlanEntity) { + String[] scores = hygienePlanEntity.getCheckItemScore().split(",|,"); + Integer standardScore = hygienePlanEntity.getStandardScore(); + R res = getSumScore(scores, standardScore); + return res.isSuccess() ? R.status(this.updateById(hygienePlanEntity)) : res; + } + + /** + * 卫生自查月度数据 + */ + @Override + public IPage dataByMonth(String month, Query query) { + // 查询当月各单位的卫生自查总数 + IPage page = new Page<>(query.getCurrent(), query.getSize()); + IPage unitPage = baseMapper.selectByMonth(page, month); + List unitList = unitPage.getRecords(); + // 查询当月各单位已完成的卫生自查数据 + IPage page1 = new Page<>(query.getCurrent(), query.getSize()); + IPage finishedPage = baseMapper.selectFinishedDataByMonth(page1, month); + List finishedList = finishedPage.getRecords(); + // 处理统计数据 + for (HygieneMonthVO unit : unitList) { + Long taskNum = unit.getScheduledCheckNum(); + Optional finishedHygiene = finishedList.stream().filter(x -> x.getUnit().equals(unit.getUnit())).findFirst(); + Long finishedTaskNum = finishedHygiene.isPresent() ? finishedHygiene.get().getFinishedCheckNum() : 0L; + unit.setFinishedCheckNum(finishedTaskNum); + unit.setUnfinishedCheckNum(taskNum - finishedTaskNum); + BigDecimal taskDecimal = new BigDecimal(taskNum); + BigDecimal finishedDecimal = new BigDecimal(finishedTaskNum); + unit.setCompletionRate(finishedDecimal.divide(taskDecimal, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")) + .setScale(2, RoundingMode.HALF_UP)); + } + unitPage.setRecords(unitList); + return unitPage; + } + + /** + * 卫生自查数据导出 + */ + @Override + public void exportHygieneData(Map param, HttpServletResponse response) { + ServletOutputStream outputStream = null; + try { + outputStream = response.getOutputStream(); + String unit = String.valueOf(param.get("unit")); + String startTime = String.valueOf(param.get("scheduledStartTime")); + String endTime = String.valueOf(param.get("scheduledEndTime")); + List rehearsalList = getHygieneByUnitAndDate(unit, startTime, endTime); + // 处理卫生自查状态信息 + rehearsalList.forEach(record -> { + String status; + if (record.getHygieneStatus().equals(HygieneStatusEnum.WAITING.getValue())) { + status = HygieneStatusEnum.WAITING.getDesc(); + } else if (record.getHygieneStatus().equals(HygieneStatusEnum.UNFINISHED.getValue())) { + status = HygieneStatusEnum.UNFINISHED.getDesc(); + } else { + status = HygieneStatusEnum.FINISHED.getDesc(); + } + record.setHygieneStatus(status); + }); + // 设置响应头 + // 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(HygieneExportDTO.class) + .build(); + excelWriter.write(rehearsalList, 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 scores 各项分值 + * @param standardScore 标准总分值 + * @return 累计分值等于标准总分值时,返回数据,否则返回错误信息 + */ + private R getSumScore(String[] scores, Integer standardScore) { + int sum = 0; + for (String score : scores) { + sum += Integer.parseInt(score); + if (sum > standardScore) { + return R.fail("累计分值已超过标准总分值"); + } + } + return sum < standardScore ? R.fail("标准总分值未全部分配") : R.data(sum); + } + + /** + * 根据单位和计划时间查询卫生自查记录 + * @param unit 单位 + * @param startTime 计划开始时间 + * @param endTime 计划结束时间 + * @return 卫生自查记录 + */ + public List getHygieneByUnitAndDate(String unit, String startTime, String endTime) { + return baseMapper.getHygieneByUnitAndDate(unit, startTime, endTime); + } +} 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 new file mode 100644 index 0000000..321078c --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java @@ -0,0 +1,154 @@ +package com.hnac.hzims.safeproduct.service.impl; + +import cn.hutool.core.date.DatePattern; +import com.alibaba.excel.util.CollectionUtils; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.hnac.hzims.common.logs.utils.StringUtils; +import com.hnac.hzims.safeproduct.entity.HygienePlanEntity; +import com.hnac.hzims.safeproduct.entity.HygieneRecordEntity; +import com.hnac.hzims.safeproduct.mapper.HygienePlanMapper; +import com.hnac.hzims.safeproduct.mapper.HygieneRecordMapper; +import com.hnac.hzims.safeproduct.service.IHygieneRecordService; +import com.hnac.hzims.safeproduct.vo.HygieneRecordDetailVO; +import org.springblade.core.tool.api.R; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.time.LocalDate; +import java.time.ZoneId; +import java.time.temporal.WeekFields; +import java.util.Date; +import java.util.List; +import java.util.Locale; +import java.util.stream.Collectors; + +/** + * 卫生自查记录服务实现类 + * + * @author liwen + * @date 2023-12-27 + */ +@Service +public class HygieneRecordServiceImpl extends ServiceImpl implements IHygieneRecordService { + + @Resource + HygienePlanMapper hygienePlanMapper; + + /** + * 删除关联卫生自查记录 + */ + @Override + public boolean removeReferenceRecord(Long hygienePlanId) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(HygieneRecordEntity::getHygienePlanId, hygienePlanId); + List list = this.list(queryWrapper); + // 若无关联卫生自查记录,直接返回true + if (CollectionUtils.isEmpty(list)) { + return true; + } + // 删除关联卫生自查记录 + List ids = list.stream().map(HygieneRecordEntity::getId).collect(Collectors.toList()); + return this.removeByIds(ids); + } + + /** + * 新增卫生自查记录 + */ + @Override + public R saveRecord(HygieneRecordEntity hygieneRecordEntity) { + // 编码生成 + // 获取当月时间(yyyymm) + String currentMonth = DatePattern.SIMPLE_MONTH_FORMAT.format(new Date()); + // 查询是否存在同月编号 + String lastCode = getLastCode(currentMonth); + // 若不存在,新增编号 + String code; + if (StringUtils.isNull(lastCode)) { + code = "WSZC" + currentMonth + "001"; + } else { // 若存在,编号递增 + String oldNum = lastCode.substring(lastCode.length() - 3); + int value = Integer.parseInt(oldNum) + 1; + // 根据数位拼接编号 + if (value < 10) { + code = "WSZC" + currentMonth + "00" + value; + } else if (value < 100) { + code = "WSZC" + currentMonth + "0" + value; + } else { + code = "WSZC" + currentMonth + value; + } + } + hygieneRecordEntity.setCode(code); + // 周数计算 + int weekNum = getWeekNum(hygieneRecordEntity.getActualEndTime()); + hygieneRecordEntity.setWeekNum(weekNum); + // 综合评分判断 + HygienePlanEntity hygienePlanEntity = hygienePlanMapper.selectById(hygieneRecordEntity.getHygienePlanId()); + if (hygieneRecordEntity.getComprehensiveScore().compareTo(hygienePlanEntity.getStandardScore()) > 0) { + return R.fail("评分不能大于标准总分值"); + } + return R.status(this.save(hygieneRecordEntity)); + } + + /** + * 修改卫生自查记录 + */ + @Override + public R updateRecord(HygieneRecordEntity hygieneRecordEntity) { + // 周数计算 + int weekNum = getWeekNum(hygieneRecordEntity.getActualEndTime()); + hygieneRecordEntity.setWeekNum(weekNum); + // 综合评分判断 + HygienePlanEntity hygienePlanEntity = hygienePlanMapper.selectById(hygieneRecordEntity.getHygienePlanId()); + if (hygieneRecordEntity.getComprehensiveScore().compareTo(hygienePlanEntity.getStandardScore()) > 0) { + return R.fail("评分不能大于标准总分值"); + } + return R.status(this.updateById(hygieneRecordEntity)); + } + + /** + * 查询卫生自查记录详情 + */ + @Override + public HygieneRecordDetailVO getRecordDetail(Long id) { + return baseMapper.getRecordDetail(id); + } + + /** + * 查询是否存在同月编号 + * @param currentMonth 当月 + * @return 存在则返回上一编号,否则返回null + */ + private String getLastCode(String currentMonth) { + String month = currentMonth.substring(currentMonth.length() - 2); + List list = getHygieneByMonth(month); + if (CollectionUtils.isEmpty(list)) { + return null; + } + return list.get(0).getCode(); + } + + /** + * 查询当月卫生自查记录 + * @param month 当月 + * @return 当月卫生自查数据表 + */ + private List getHygieneByMonth(String month) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().like(HygieneRecordEntity::getCreateTime, month) + .orderByDesc(HygieneRecordEntity::getCode); + return this.list(queryWrapper); + } + + /** + * 计算日期为当月第几周 + * @param date 日期 + * @return 当月周数 + */ + private int getWeekNum(Date date) { + // 周数 + LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + // 计算检查时间为本月的第几周 + return localDate.get(WeekFields.of(Locale.getDefault()).weekOfMonth()); + } +} diff --git a/hzims-service/safeproduct/src/main/resources/db/1.0.1.sql b/hzims-service/safeproduct/src/main/resources/db/1.0.1.sql index 6bf9836..57e4455 100644 --- a/hzims-service/safeproduct/src/main/resources/db/1.0.1.sql +++ b/hzims-service/safeproduct/src/main/resources/db/1.0.1.sql @@ -15,8 +15,8 @@ CREATE TABLE `hzims_rehearsal_plan` ( `id` bigint(20) NOT NULL COMMENT '主键id', `unit` varchar(50) NOT NULL COMMENT '单位', `subject` varchar(50) NOT NULL COMMENT '演练科目', - `scheduled_start_time` datetime NOT NULL COMMENT '演练计划开始时间', - `scheduled_end_time` datetime NOT NULL COMMENT '演练计划结束时间', + `scheduled_start_time` date NOT NULL COMMENT '演练计划开始时间', + `scheduled_end_time` date NOT NULL COMMENT '演练计划结束时间', `location` varchar(255) NOT NULL COMMENT '演练地点', `commander` varchar(10) NOT NULL COMMENT '总指挥', `rehearsal_method` varchar(20) DEFAULT '' COMMENT '演练方式', @@ -56,8 +56,8 @@ CREATE TABLE `hzims_rehearsal_record` ( CREATE TABLE `hzims_train_plan` ( `id` bigint(20) NOT NULL COMMENT '主键id', `unit` varchar(50) NOT NULL COMMENT '单位', - `scheduled_start_time` datetime NOT NULL COMMENT '计划培训开始时间', - `scheduled_end_time` datetime NOT NULL COMMENT '计划培训结束时间', + `scheduled_start_time` date NOT NULL COMMENT '计划培训开始时间', + `scheduled_end_time` date NOT NULL COMMENT '计划培训结束时间', `lesson` varchar(255) NOT NULL COMMENT '培训课程', `location` varchar(255) NOT NULL COMMENT '培训地点', `train_method` varchar(20) DEFAULT '' COMMENT '培训方式', @@ -134,4 +134,86 @@ CREATE TABLE `hzims_test_score` ( `status` int(2) NOT NULL DEFAULT '1' COMMENT '状态', `is_deleted` int(2) NOT NULL DEFAULT '0' COMMENT '逻辑删除状态:0-未删除,1-删除', PRIMARY KEY (`id`) USING BTREE -) ENGINE=INNODB CHARACTER SET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='考试成绩表' ROW_FORMAT=Dynamic; \ No newline at end of file +) ENGINE=INNODB CHARACTER SET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='考试成绩表' ROW_FORMAT=Dynamic; + +CREATE TABLE `hzims_conference_plan` ( + `id` bigint(20) NOT NULL COMMENT '主键id', + `unit` varchar(50) NOT NULL COMMENT '单位', + `theme` varchar(50) NOT NULL COMMENT '会议主题', + `scheduled_start_time` date NOT NULL COMMENT '会议计划开始时间', + `scheduled_end_time` date NOT NULL COMMENT '会议计划结束时间', + `location` varchar(255) NOT NULL COMMENT '会议地点', + `host` varchar(10) NOT NULL COMMENT '主持人', + `conference_method` varchar(20) DEFAULT '' COMMENT '会议方式', + `conference_status` varchar(20) NOT NULL DEFAULT 'WAITING' COMMENT '会议状态', + `create_user` bigint(20) NOT NULL DEFAULT '-1' COMMENT '创建人', + `create_dept` bigint(20) NOT NULL DEFAULT '-1' COMMENT '创建部门', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_user` bigint(20) DEFAULT '-1' COMMENT '更新人', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间', + `status` int(2) NOT NULL DEFAULT '1' COMMENT '状态', + `is_deleted` int(2) NOT NULL DEFAULT '0' COMMENT '逻辑删除状态:0-未删除,1-删除', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=INNODB CHARACTER SET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='会议计划表' ROW_FORMAT=Dynamic; + +CREATE TABLE `hzims_conference_record` ( + `id` bigint(20) NOT NULL COMMENT '主键id', + `conference_plan_id` bigint(20) NOT NULL COMMENT '会议计划id', + `code` varchar(50) NOT NULL COMMENT '编号', + `people_name` varchar(5000) DEFAULT '' COMMENT '参会人员', + `actual_start_time` datetime DEFAULT NULL COMMENT '会议实际开始时间', + `actual_end_time` datetime DEFAULT NULL COMMENT '会议实际结束时间', + `recorder` varchar(20) DEFAULT '' COMMENT '记录人', + `content` varchar(250) DEFAULT '' DEFAULT '' COMMENT '会议内容', + `img_path` varchar(1000) NOT NULL DEFAULT '' COMMENT '会议图片', + `file_path` varchar(1000) NOT NULL DEFAULT '' COMMENT '会议附件', + `create_user` bigint(20) NOT NULL DEFAULT '-1' COMMENT '创建人', + `create_dept` bigint(20) NOT NULL DEFAULT '-1' COMMENT '创建部门', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_user` bigint(20) DEFAULT '-1' COMMENT '更新人', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间', + `status` int(2) NOT NULL DEFAULT '1' COMMENT '状态', + `is_deleted` int(2) NOT NULL DEFAULT '0' COMMENT '逻辑删除状态:0-未删除,1-删除', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=INNODB CHARACTER SET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='会议记录表' ROW_FORMAT=Dynamic; + +CREATE TABLE `hzims_hygiene_plan` ( + `id` bigint(20) NOT NULL COMMENT '主键id', + `unit` varchar(50) NOT NULL COMMENT '单位', + `zone` varchar(50) NOT NULL COMMENT '责任区', + `principal` varchar(20) NOT NULL COMMENT '责任人', + `check_item` mediumtext NOT NULL COMMENT '检查项', + `check_item_score` varchar(255) NOT NULL COMMENT '检查项分值', + `standard_score` int(10) NOT NULL DEFAULT '100' COMMENT '标准总分值', + `scheduled_start_time` date NOT NULL COMMENT '计划开始时间', + `scheduled_end_time` date NOT NULL COMMENT '计划结束时间', + `hygiene_status` varchar(20) NOT NULL DEFAULT 'WAITING' COMMENT '卫生自查状态', + `create_user` bigint(20) NOT NULL DEFAULT '-1' COMMENT '创建人', + `create_dept` bigint(20) NOT NULL DEFAULT '-1' COMMENT '创建部门', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_user` bigint(20) DEFAULT '-1' COMMENT '更新人', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间', + `status` int(2) NOT NULL DEFAULT '1' COMMENT '状态', + `is_deleted` int(2) NOT NULL DEFAULT '0' COMMENT '逻辑删除状态:0-未删除,1-删除', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=INNODB CHARACTER SET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='卫生自查表' ROW_FORMAT=Dynamic; + +CREATE TABLE `hzims_hygiene_record` ( + `id` bigint(20) NOT NULL COMMENT '主键id', + `code` varchar(50) NOT NULL COMMENT '编号', + `actual_start_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '实际开始时间', + `actual_end_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '实际结束时间', + `check_user` varchar(20) NOT NULL DEFAULT '' COMMENT '检查人', + `check_result` mediumtext NOT NULL COMMENT '检查结果', + `comprehensive_score` int(10) NOT NULL COMMENT '综合评分', + `week_num` int(10) NOT NULL COMMENT '周数', + `img_path` varchar(1000) NOT NULL DEFAULT '' COMMENT '检查图片', + `create_user` bigint(20) NOT NULL DEFAULT '-1' COMMENT '创建人', + `create_dept` bigint(20) NOT NULL DEFAULT '-1' COMMENT '创建部门', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_user` bigint(20) DEFAULT '-1' COMMENT '更新人', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间', + `status` int(2) NOT NULL DEFAULT '1' COMMENT '状态', + `is_deleted` int(2) NOT NULL DEFAULT '0' COMMENT '逻辑删除状态:0-未删除,1-删除', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=INNODB CHARACTER SET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='卫生自查记录表' ROW_FORMAT=Dynamic; \ No newline at end of file