Browse Source

add: 卫生自查模块

zhongwei
liwen 11 months ago
parent
commit
e20f99af84
  1. 21
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/HygieneExportDTO.java
  2. 59
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygienePlanEntity.java
  3. 51
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygieneRecordEntity.java
  4. 31
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/HygieneStatusEnum.java
  5. 31
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneMonthVO.java
  6. 46
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneRecordDetailVO.java
  7. 142
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/HygieneController.java
  8. 45
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygienePlanMapper.java
  9. 52
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygienePlanMapper.xml
  10. 23
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygieneRecordMapper.java
  11. 15
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygieneRecordMapper.xml
  12. 64
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygienePlanService.java
  13. 43
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygieneRecordService.java
  14. 213
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygienePlanServiceImpl.java
  15. 154
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java
  16. 90
      hzims-service/safeproduct/src/main/resources/db/1.0.1.sql

21
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;
}

59
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;
}

51
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;
}

31
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;
}
}

31
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;
}

46
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;
}

142
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<HygienePlanEntity> 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<IPage<HygienePlanEntity>> planPage(@ApiIgnore @RequestParam Map<String, Object> param, Query query) {
IPage<HygienePlanEntity> 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<HygieneRecordDetailVO> 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<IPage<HygieneRecordEntity>> recordPage(@ApiIgnore @RequestParam Map<String, Object> param, Query query) {
IPage<HygieneRecordEntity> page = hygieneRecordService.page(Condition.getPage(query), Condition.getQueryWrapper(param,
HygieneRecordEntity.class));
return R.data(page);
}
@GetMapping("/dataByMonth")
@ApiOperation(value = "月度统计表")
@ApiOperationSupport(order = 11)
public R<IPage<HygieneMonthVO>> dataByMonth(@RequestParam String month, Query query) {
IPage<HygieneMonthVO> 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<String, Object> param, HttpServletResponse response) {
hygienePlanService.exportHygieneData(param, response);
}
}

45
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<HygienePlanEntity> {
/**
* 查询当月各单位的卫生自查总数
* @param page 分页类
* @param month 月份
* @return 当月的卫生自查总数据
*/
IPage<HygieneMonthVO> selectByMonth(IPage<HygieneMonthVO> page, String month);
/**
* 查询当月各单位已完成的卫生自查数据
* @param page 分页类
* @param month 月份
* @return 当月的已完成数据
*/
IPage<HygieneMonthVO> selectFinishedDataByMonth(IPage<HygieneMonthVO> page, String month);
/**
* 根据单位和计划时间查询卫生自查记录
* @param unit 单位
* @param startTime 计划开始时间
* @param endTime 计划结束时间
* @return 卫生自查记录
*/
List<HygieneExportDTO> getHygieneByUnitAndDate(String unit, String startTime, String endTime);
}

52
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygienePlanMapper.xml

@ -0,0 +1,52 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hnac.hzims.safeproduct.mapper.HygienePlanMapper">
<select id="selectByMonth" resultType="com.hnac.hzims.safeproduct.vo.HygieneMonthVO">
SELECT
unit, count(1) as scheduled_check_num
FROM
hzims_hygiene_plan
WHERE
is_deleted = 0
AND scheduled_end_time like concat('%', #{month}, '%')
GROUP BY
unit
ORDER BY
unit
</select>
<select id="selectFinishedDataByMonth" resultType="com.hnac.hzims.safeproduct.vo.HygieneMonthVO">
SELECT
unit, count(1) as finished_task_num
FROM
hzims_hygiene_plan
WHERE
is_deleted = 0
AND scheduled_end_time like concat('%', #{month}, '%')
AND hygiene_status = 'FINISHED'
GROUP BY
unit
ORDER BY
unit
</select>
<select id="getHygieneByUnitAndDate" resultType="com.hnac.hzims.safeproduct.dto.HygieneExportDTO">
SELECT
t1.unit, t1.zone, t1.principal, t1.check_item, t1.check_item_score, t2.code, t2.check_result, t2.comprehensive_score,
t2.check_user, t2.actual_start_time, t2.actual_end_time, t1.hygiene_status
FROM
hzims_hygiene_plan t1
LEFT JOIN hzims_hygiene_record t2 ON t1.id = t2.hygiene_plan_id
WHERE
t1.is_deleted = 0
<if test="unit != 'null' and unit != ''">
AND t1.unit like concat('%', #{unit}, '%')
</if>
<if test="startTime != 'null' and startTime != ''">
AND t1.scheduled_start_time >= #{startTime}
</if>
<if test="endTime != 'null' and endTime != ''">
AND t1.scheduled_end_time &lt; #{endTime}
</if>
</select>
</mapper>

23
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<HygieneRecordEntity> {
/**
* 查询卫生自查记录详情
* @param id 卫生自查记录id
* @return 卫生自查记录详情VO类
*/
HygieneRecordDetailVO getRecordDetail(Long id);
}

15
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygieneRecordMapper.xml

@ -0,0 +1,15 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hnac.hzims.safeproduct.mapper.HygieneRecordMapper">
<select id="getRecordDetail" resultType="com.hnac.hzims.safeproduct.vo.HygieneRecordDetailVO">
SELECT
t2.zone, t2.principal, t2.check_item, t2.check_item_score, t1.code, t1.check_time, t1.check_user,
t1.check_result, t1.comprehensive_score, t1.week_num
FROM
hzims_hygiene_record t1
LEFT JOIN hzims_hygiene_plan t2 ON t1.hygiene_plan_id = h2.id
WHERE
t1.is_deleted = 0
AND t1.id = #{id}
</select>
</mapper>

64
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<HygienePlanEntity> {
/**
* 删除卫生自查计划
* @param id 卫生自查计划id
* @return true-成功false-失败
*/
boolean removePlan(Long id);
/**
* 卫生自查计划分页
* @param param 入参
* @param query 分页类
* @return 卫生自查计划数据
*/
IPage<HygienePlanEntity> planPage(Map<String, Object> param, Query query);
/**
* 新增卫生自查计划
* @param hygienePlanEntity 卫生自查计划实体类
* @return 结果封装类
*/
R savePlan(HygienePlanEntity hygienePlanEntity);
/**
* 修改卫生自查计划
* @param hygienePlanEntity 卫生自查计划实体类
* @return 结果封装类
*/
R updatePlan(HygienePlanEntity hygienePlanEntity);
/**
* 卫生自查月度数据
* @param month 月份
* @param query 分页类
* @return 月度统计分页
*/
IPage<HygieneMonthVO> dataByMonth(String month, Query query);
/**
* 卫生自查数据导出
* @param param 入参
* @param response 响应类
*/
void exportHygieneData(Map<String, Object> param, HttpServletResponse response);
}

43
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<HygieneRecordEntity> {
/**
* 删除关联卫生自查记录
* @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);
}

213
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<HygienePlanMapper, HygienePlanEntity> 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<HygienePlanEntity> planPage(Map<String, Object> param, Query query) {
QueryWrapper<HygienePlanEntity> 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<HygieneMonthVO> dataByMonth(String month, Query query) {
// 查询当月各单位的卫生自查总数
IPage<HygieneMonthVO> page = new Page<>(query.getCurrent(), query.getSize());
IPage<HygieneMonthVO> unitPage = baseMapper.selectByMonth(page, month);
List<HygieneMonthVO> unitList = unitPage.getRecords();
// 查询当月各单位已完成的卫生自查数据
IPage<HygieneMonthVO> page1 = new Page<>(query.getCurrent(), query.getSize());
IPage<HygieneMonthVO> finishedPage = baseMapper.selectFinishedDataByMonth(page1, month);
List<HygieneMonthVO> finishedList = finishedPage.getRecords();
// 处理统计数据
for (HygieneMonthVO unit : unitList) {
Long taskNum = unit.getScheduledCheckNum();
Optional<HygieneMonthVO> 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<String, Object> 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<HygieneExportDTO> 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<HygieneExportDTO> getHygieneByUnitAndDate(String unit, String startTime, String endTime) {
return baseMapper.getHygieneByUnitAndDate(unit, startTime, endTime);
}
}

154
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<HygieneRecordMapper, HygieneRecordEntity> implements IHygieneRecordService {
@Resource
HygienePlanMapper hygienePlanMapper;
/**
* 删除关联卫生自查记录
*/
@Override
public boolean removeReferenceRecord(Long hygienePlanId) {
QueryWrapper<HygieneRecordEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(HygieneRecordEntity::getHygienePlanId, hygienePlanId);
List<HygieneRecordEntity> list = this.list(queryWrapper);
// 若无关联卫生自查记录,直接返回true
if (CollectionUtils.isEmpty(list)) {
return true;
}
// 删除关联卫生自查记录
List<Long> 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<HygieneRecordEntity> list = getHygieneByMonth(month);
if (CollectionUtils.isEmpty(list)) {
return null;
}
return list.get(0).getCode();
}
/**
* 查询当月卫生自查记录
* @param month 当月
* @return 当月卫生自查数据表
*/
private List<HygieneRecordEntity> getHygieneByMonth(String month) {
QueryWrapper<HygieneRecordEntity> 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());
}
}

90
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', `id` bigint(20) NOT NULL COMMENT '主键id',
`unit` varchar(50) NOT NULL COMMENT '单位', `unit` varchar(50) NOT NULL COMMENT '单位',
`subject` varchar(50) NOT NULL COMMENT '演练科目', `subject` varchar(50) NOT NULL COMMENT '演练科目',
`scheduled_start_time` datetime NOT NULL COMMENT '演练计划开始时间', `scheduled_start_time` date NOT NULL COMMENT '演练计划开始时间',
`scheduled_end_time` datetime NOT NULL COMMENT '演练计划结束时间', `scheduled_end_time` date NOT NULL COMMENT '演练计划结束时间',
`location` varchar(255) NOT NULL COMMENT '演练地点', `location` varchar(255) NOT NULL COMMENT '演练地点',
`commander` varchar(10) NOT NULL COMMENT '总指挥', `commander` varchar(10) NOT NULL COMMENT '总指挥',
`rehearsal_method` varchar(20) DEFAULT '' COMMENT '演练方式', `rehearsal_method` varchar(20) DEFAULT '' COMMENT '演练方式',
@ -56,8 +56,8 @@ CREATE TABLE `hzims_rehearsal_record` (
CREATE TABLE `hzims_train_plan` ( CREATE TABLE `hzims_train_plan` (
`id` bigint(20) NOT NULL COMMENT '主键id', `id` bigint(20) NOT NULL COMMENT '主键id',
`unit` varchar(50) NOT NULL COMMENT '单位', `unit` varchar(50) NOT NULL COMMENT '单位',
`scheduled_start_time` datetime NOT NULL COMMENT '计划培训开始时间', `scheduled_start_time` date NOT NULL COMMENT '计划培训开始时间',
`scheduled_end_time` datetime NOT NULL COMMENT '计划培训结束时间', `scheduled_end_time` date NOT NULL COMMENT '计划培训结束时间',
`lesson` varchar(255) NOT NULL COMMENT '培训课程', `lesson` varchar(255) NOT NULL COMMENT '培训课程',
`location` varchar(255) NOT NULL COMMENT '培训地点', `location` varchar(255) NOT NULL COMMENT '培训地点',
`train_method` varchar(20) DEFAULT '' COMMENT '培训方式', `train_method` varchar(20) DEFAULT '' COMMENT '培训方式',
@ -135,3 +135,85 @@ CREATE TABLE `hzims_test_score` (
`is_deleted` int(2) NOT NULL DEFAULT '0' COMMENT '逻辑删除状态:0-未删除,1-删除', `is_deleted` int(2) NOT NULL DEFAULT '0' COMMENT '逻辑删除状态:0-未删除,1-删除',
PRIMARY KEY (`id`) USING BTREE PRIMARY KEY (`id`) USING BTREE
) ENGINE=INNODB CHARACTER SET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='考试成绩表' ROW_FORMAT=Dynamic; ) 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;
Loading…
Cancel
Save