|
|
|
@ -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("累计分值超过标准总分值"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return sum < standardScore ? R.fail("标准总分值未全部分配") : R.data(sum); |
|
|
|
|
if (sum < standardScore) { |
|
|
|
|
throw new ServiceException("标准总分值未全部分配"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|