Browse Source

update: 添加卫生自查计划导出

zhongwei
liwen 10 months ago
parent
commit
9932411a79
  1. 13
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygienePlanEntity.java
  2. 3
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneRecordPageVO.java
  3. 18
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/HygieneController.java
  4. 11
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/HygieneRecordMapper.xml
  5. 7
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygienePlanService.java
  6. 110
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygienePlanServiceImpl.java
  7. 17
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java

13
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygienePlanEntity.java

@ -1,5 +1,6 @@
package com.hnac.hzims.safeproduct.entity;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
@ -23,13 +24,16 @@ import java.util.Date;
public class HygienePlanEntity extends BaseEntity {
@Size(max = 50, message = "计划名称字段长度不能超过50")
@ExcelProperty(value = "计划名称", index = 0)
@ApiModelProperty("计划名称")
private String name;
@Size(max = 50, message = "单位字段长度不能超过50")
@ExcelProperty(value = "单位", index = 1)
@ApiModelProperty("单位")
private String unit;
@ExcelProperty(value = "标准总分值", index = 2)
@ApiModelProperty("标准总分值")
private Integer standardScore;
@ -43,6 +47,15 @@ public class HygienePlanEntity extends BaseEntity {
@ApiModelProperty("计划结束时间")
private Date scheduledEndTime;
@ExcelProperty(value = "自查计划状态", index = 5)
@ApiModelProperty("自查计划状态")
private String hygienePlanStatus;
@ExcelProperty(value = "计划开始时间", index = 3)
@ApiModelProperty("计划开始时间")
private String startTime;
@ExcelProperty(value = "计划结束时间", index = 4)
@ApiModelProperty("计划结束时间")
private String endTime;
}

3
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/HygieneRecordPageVO.java

@ -17,6 +17,9 @@ public class HygieneRecordPageVO {
@ApiModelProperty("卫生自查记录id")
private Long id;
@ApiModelProperty("卫生自查计划id")
private Long hygienePlanId;
@ApiModelProperty("单位")
private String unit;

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

@ -114,7 +114,10 @@ public class HygieneController extends BladeController {
@GetMapping("/recordPage")
@ApiImplicitParams({
@ApiImplicitParam(name = "hygienePlanId", value = "卫生自查计划id", dataType = "query", paramType = "string")
@ApiImplicitParam(name = "hygienePlanId", value = "卫生自查计划id", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "unit", value = "单位", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "actualStartTime", value = "开始时间", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "actualEndTime", value = "结束时间", dataType = "query", paramType = "string")
})
@ApiOperation(value = "卫生自查记录分页")
@ApiOperationSupport(order = 10)
@ -148,4 +151,17 @@ public class HygieneController extends BladeController {
public void exportMonthData(@ApiIgnore @RequestParam Map<String, Object> param, Query query, HttpServletResponse response) {
hygienePlanService.exportMonthData(param, query, response);
}
@GetMapping("/exportHygienePlanData")
@ApiImplicitParams({
@ApiImplicitParam(name = "unit", value = "单位", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "name", value = "名称", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "scheduledStartTime", value = "计划开始时间", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "scheduledEndTime", value = "计划结束时间", dataType = "query", paramType = "string")
})
@ApiOperation(value = "卫生自查计划导出")
@ApiOperationSupport(order = 14)
public void exportHygienePlanData(@ApiIgnore @RequestParam Map<String, Object> param, HttpServletResponse response) {
hygienePlanService.exportHygienePlanData(param, response);
}
}

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

@ -14,7 +14,7 @@
<select id="recordPage" resultType="com.hnac.hzims.safeproduct.vo.HygieneRecordPageVO">
SELECT
id, unit, actual_start_time, actual_end_time, check_user, week_num
id, unit, actual_start_time, actual_end_time, check_user, week_num, hygiene_plan_id
FROM
hzims_hygiene_record
WHERE
@ -22,6 +22,15 @@
<if test="param.hygienePlanId != null and param.hygienePlanId != ''">
AND hygiene_plan_id = #{param.hygienePlanId}
</if>
<if test="param.unit != null and param.unit != ''">
AND unit like concat('%', #{param.unit}, '%')
</if>
<if test="param.actualStartTime != null and param.actualStartTime != ''">
AND actual_start_time >= #{param.actualStartTime}
</if>
<if test="param.actualEndTime != null and param.actualEndTime != ''">
AND actual_end_time &lt;= #{param.actualEndTime}
</if>
ORDER BY
create_time DESC
</select>

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

@ -85,4 +85,11 @@ public interface IHygienePlanService extends IService<HygienePlanEntity> {
* @return 卫生自查计划数据
*/
List<HygienePlanEntity> getWaitingHygienePlanInTimeRange(String startTime, String endTime);
/**
* 卫生自查计划数据导出
* @param param 入参
* @param response 响应类
*/
void exportHygienePlanData(Map<String, Object> param, HttpServletResponse response);
}

110
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygienePlanServiceImpl.java

@ -23,6 +23,7 @@ import com.hnac.hzims.safeproduct.vo.HygieneMonthVO;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -125,10 +126,7 @@ public class HygienePlanServiceImpl extends ServiceImpl<HygienePlanMapper, Hygie
}
String[] scores = zone.getCheckItemScore().split(",|,");
// 校验检查项总成绩是否为标准总成绩
R res = getSumScore(scores, hygienePlanDTO.getStandardScore());
if (!res.isSuccess()) {
return res;
}
getSumScore(scores, hygienePlanDTO.getStandardScore());
}
// 校验通过则批量新增责任区数据
return R.status(hygieneZoneService.saveBatch(zoneList));
@ -139,6 +137,7 @@ public class HygienePlanServiceImpl extends ServiceImpl<HygienePlanMapper, Hygie
/**
* 修改卫生自查计划
*/
@Transactional(rollbackFor = Exception.class)
@Override
public R updatePlan(HygienePlanDTO hygienePlanDTO) {
// 重名校验
@ -159,10 +158,7 @@ public class HygienePlanServiceImpl extends ServiceImpl<HygienePlanMapper, Hygie
for (HygieneZoneEntity zone : zoneList) {
String[] scores = zone.getCheckItemScore().split(",|,");
// 校验检查项总成绩是否为标准总成绩
R res = getSumScore(scores, hygienePlanDTO.getStandardScore());
if (!res.isSuccess()) {
return res;
}
getSumScore(scores, hygienePlanDTO.getStandardScore());
}
// 校验通过则批量修改责任区数据
return R.status(hygieneZoneService.updateBatchById(zoneList));
@ -217,17 +213,18 @@ public class HygienePlanServiceImpl extends ServiceImpl<HygienePlanMapper, Hygie
* 计算累计分值
* @param scores 各项分值
* @param standardScore 标准总分值
* @return 累计分值等于标准总分值时返回数据否则返回错误信息
*/
private R getSumScore(String[] scores, Integer standardScore) {
private void getSumScore(String[] scores, Integer standardScore) {
int sum = 0;
for (String score : scores) {
sum += Integer.parseInt(score);
if (sum > standardScore) {
return R.fail("累计分值已超过标准总分值");
throw new ServiceException("累计分值超过标准总分值");
}
}
if (sum < standardScore) {
throw new ServiceException("标准总分值未全部分配");
}
return sum < standardScore ? R.fail("标准总分值未全部分配") : R.data(sum);
}
/**
@ -297,4 +294,93 @@ public class HygienePlanServiceImpl extends ServiceImpl<HygienePlanMapper, Hygie
.le(HygienePlanEntity::getScheduledEndTime, endTime);
return this.list(queryWrapper);
}
/**
* 卫生自查计划数据导出
*/
@Override
public void exportHygienePlanData(Map<String, Object> param, HttpServletResponse response) {
ServletOutputStream outputStream = null;
try {
outputStream = response.getOutputStream();
String unit = String.valueOf(param.get("unit"));
String name = String.valueOf(param.get("name"));
String startTime = String.valueOf(param.get("scheduledStartTime"));
String endTime = String.valueOf(param.get("scheduledEndTime"));
List<HygienePlanEntity> hygienePlanList = getHygienePlanByUnitNameAndTime(unit, name, startTime, endTime);
// 数据处理
hygienePlanList.forEach(plan -> {
// 卫生自查状态
String status;
if (plan.getHygienePlanStatus().equals(HygieneStatusEnum.WAITING.getValue())) {
status = HygieneStatusEnum.WAITING.getDesc();
} else if (plan.getHygienePlanStatus().equals(HygieneStatusEnum.UNFINISHED.getValue())) {
status = HygieneStatusEnum.UNFINISHED.getDesc();
} else {
status = HygieneStatusEnum.FINISHED.getDesc();
}
plan.setHygienePlanStatus(status);
// 时间格式
plan.setStartTime(DateUtil.format(plan.getScheduledStartTime(), DateUtil.PATTERN_DATE));
plan.setEndTime(DateUtil.format(plan.getScheduledEndTime(), DateUtil.PATTERN_DATE));
});
// 设置响应头
// URLEncoder.encode防止中文乱码
String fileName = URLEncoder.encode("卫生自查计划表", "UTF-8");
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("UTF-8");
// ExcelWriter初始化
ExcelWriter excelWriter = EasyExcel
.write(response.getOutputStream())
.autoCloseStream(Boolean.TRUE)
.registerConverter(new LongStringConverter())
.registerWriteHandler(new SimpleColumnWidthStyleStrategy(25))
.build();
WriteSheet writeSheet = EasyExcel.writerSheet(1, "卫生自查计划表").head(HygienePlanEntity.class)
.build();
excelWriter.write(hygienePlanList, writeSheet);
excelWriter.finish();
} catch (Exception e) {
// 重置response
response.reset();
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
throw new ServiceException("卫生自查计划表数据导出异常: " + e.getMessage());
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
log.error("卫生自查计划表数据导出输出流关闭异常: " + e.getMessage());
}
}
}
}
/**
* 根据单位名称时间查询卫生自查计划
* @param unit 单位
* @param name 名称
* @param startTime 开始时间
* @param endTime 结束时间
* @return 卫生自查计划数据
*/
private List<HygienePlanEntity> getHygienePlanByUnitNameAndTime(String unit, String name, String startTime, String endTime) {
QueryWrapper<HygienePlanEntity> queryWrapper = new QueryWrapper<>();
if (!unit.equals("null") && !unit.equals("")) {
queryWrapper.lambda().like(HygienePlanEntity::getUnit, unit);
}
if (!name.equals("null") && !name.equals("")) {
queryWrapper.lambda().like(HygienePlanEntity::getName, name);
}
if (!startTime.equals("null") && !startTime.equals("")) {
queryWrapper.lambda().ge(HygienePlanEntity::getScheduledStartTime, startTime);
}
if (!endTime.equals("null") && !endTime.equals("")) {
queryWrapper.lambda().le(HygienePlanEntity::getScheduledEndTime, endTime);
}
queryWrapper.lambda().orderByDesc(HygienePlanEntity::getCreateTime);
return this.list(queryWrapper);
}
}

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

@ -20,12 +20,14 @@ import com.hnac.hzims.safeproduct.utils.BaseUtil;
import com.hnac.hzims.safeproduct.vo.HygieneRecordPageVO;
import com.hnac.hzims.safeproduct.vo.HygieneZoneDetailVO;
import com.hnac.hzims.safeproduct.vo.HygieneRecordDetailVO;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
@ -73,17 +75,19 @@ public class HygieneRecordServiceImpl extends ServiceImpl<HygieneRecordMapper, H
/**
* 新增卫生自查记录
*/
@Transactional(rollbackFor = Exception.class)
@Override
public R saveRecord(HygieneRecordDTO hygieneRecordDTO) {
HygieneRecordEntity hygieneRecordEntity = new HygieneRecordEntity();
BeanUtils.copyProperties(hygieneRecordDTO, hygieneRecordEntity);
// 编码生成
// 获取当月时间(yyyymm)
String currentMonth = DatePattern.SIMPLE_MONTH_FORMAT.format(new Date());
// 获取当月时间
String currentNormMonth = DatePattern.NORM_MONTH_FORMAT.format(new Date());
String currentSimpleMonth = DatePattern.SIMPLE_MONTH_FORMAT.format(new Date());
// 查询是否存在同月编号
String lastCode = getLastCode(currentMonth);
String lastCode = getLastCode(currentNormMonth);
// 若不存在,新增编号
String code = BaseUtil.getUniqueCode("WSZC", lastCode, currentMonth);
String code = BaseUtil.getUniqueCode("WSZC", lastCode, currentSimpleMonth);
hygieneRecordEntity.setCode(code);
// 周数计算
int weekNum = getWeekNum(hygieneRecordEntity.getActualEndTime());
@ -94,7 +98,7 @@ public class HygieneRecordServiceImpl extends ServiceImpl<HygieneRecordMapper, H
for (String score : scores) {
int sc = Integer.parseInt(score);
if (sc > hygienePlanEntity.getStandardScore()) {
return R.fail("评分不能大于标准总分值");
throw new ServiceException("评分不能大于标准总分值");
}
}
boolean save = this.save(hygieneRecordEntity);
@ -178,8 +182,7 @@ public class HygieneRecordServiceImpl extends ServiceImpl<HygieneRecordMapper, H
* @return 存在则返回上一编号否则返回null
*/
private String getLastCode(String currentMonth) {
String month = currentMonth.substring(currentMonth.length() - 2);
List<HygieneRecordEntity> list = getHygieneByMonth(month);
List<HygieneRecordEntity> list = getHygieneByMonth(currentMonth);
if (CollectionUtils.isEmpty(list)) {
return null;
}

Loading…
Cancel
Save