|
@@ -2,28 +2,28 @@ package com.ruoyi.care.service.impl;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
|
import java.nio.file.StandardCopyOption;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
+import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
-import com.ruoyi.care.domain.CareApplications;
|
|
|
-import com.ruoyi.care.domain.CareNurseRecords;
|
|
|
-import com.ruoyi.care.domain.CareRecords;
|
|
|
-import com.ruoyi.care.mapper.CareApplicationsMapper;
|
|
|
-import com.ruoyi.care.mapper.CareNurseRecordsMapper;
|
|
|
-import com.ruoyi.care.mapper.CareRecordsMapper;
|
|
|
+import com.ruoyi.care.domain.*;
|
|
|
+import com.ruoyi.care.mapper.*;
|
|
|
import com.ruoyi.common.config.RuoYiConfig;
|
|
|
import com.ruoyi.common.enums.CareApplyStatus;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
+import com.ruoyi.system.mapper.SysWorkConfigMapper;
|
|
|
import org.apache.commons.lang3.time.FastDateFormat;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import com.ruoyi.care.mapper.CareNurseClocksMapper;
|
|
|
-import com.ruoyi.care.domain.CareNurseClocks;
|
|
|
import com.ruoyi.care.service.ICareNurseClocksService;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -44,6 +44,11 @@ public class CareNurseClocksServiceImpl implements ICareNurseClocksService
|
|
|
private CareNurseRecordsMapper careNurseRecordsMapper;
|
|
|
@Autowired
|
|
|
private CareRecordsMapper careRecordsMapper;
|
|
|
+ @Autowired
|
|
|
+ private SysWorkConfigMapper sysWorkConfigMapper;
|
|
|
+ @Autowired
|
|
|
+ private CarePersonsMapper carePersonsMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 查询护理任务打卡
|
|
|
*
|
|
@@ -78,6 +83,40 @@ public class CareNurseClocksServiceImpl implements ICareNurseClocksService
|
|
|
@Transactional
|
|
|
public int insertCareNurseClocks(CareNurseClocks careNurseClocks,Long userId)
|
|
|
{
|
|
|
+ //判断当前日期是否可以打卡,非残疾人出院前两天不再护理,残疾人截至到出院当天,若无法打卡,则抛出异常
|
|
|
+ CareApplications careApplications = careApplicationsMapper.selectCareApplicationsByApplyId(Long.parseLong(careNurseClocks.getApplyId()));
|
|
|
+ String leaveTimeStr = careApplications.getLeaveTime();
|
|
|
+
|
|
|
+ // 定义日期格式化器
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ // 将字符串转换为LocalDateTime对象
|
|
|
+ LocalDateTime leaveTime = LocalDateTime.parse(leaveTimeStr, formatter);
|
|
|
+ LocalDateTime currentTime = LocalDateTime.now();
|
|
|
+
|
|
|
+ boolean isDisabled = !careApplications.getDisability().equals("N");
|
|
|
+
|
|
|
+ if (isDisabled) {
|
|
|
+ // 残疾人:截至到出院当天
|
|
|
+ if (currentTime.isAfter(leaveTime)) {
|
|
|
+ throw new ServiceException("无法打卡:当前时间已超过出院时间!");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 非残疾人:出院前两天不再护理
|
|
|
+ LocalDateTime cutoffTime = leaveTime.minus(2, ChronoUnit.DAYS);
|
|
|
+ if (currentTime.isAfter(cutoffTime)) {
|
|
|
+ throw new ServiceException("无法打卡:非残疾人出院前两天不再提供护理服务!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //若特困人员在中转或者擅自离院,不提供护理
|
|
|
+ CarePersons carePersons=carePersonsMapper.selectCarePersonsByPersonId(careApplications.getPersonId());
|
|
|
+ if(carePersons.getStatus().equals("02")){
|
|
|
+ throw new ServiceException("无法打卡:当前特困人员处于中转状态!");
|
|
|
+ }else if(carePersons.getStatus().equals("03")){
|
|
|
+ throw new ServiceException("无法打卡:当前特困人员处于擅自离院状态!");
|
|
|
+ }
|
|
|
+
|
|
|
String psths[]=careNurseClocks.getImgPaths().split(",");
|
|
|
int result=0;
|
|
|
//获取当前节点记录
|
|
@@ -100,19 +139,28 @@ public class CareNurseClocksServiceImpl implements ICareNurseClocksService
|
|
|
careNurseRecords.setApplyId(Long.parseLong(careNurseClocks.getApplyId()));
|
|
|
List<CareNurseRecords> lst=careNurseRecordsMapper.selectCareNurseRecordsList(careNurseRecords);
|
|
|
if(lst.size()>0){
|
|
|
+ CareNurseRecords careNurseRecord=lst.get(0);
|
|
|
careRecordsMapper.updateCareRecords(curr);
|
|
|
+
|
|
|
+ //计算计时天数
|
|
|
+ careNurseRecord=calDayApplyRecord(careNurseRecord,careNurseClocks.getNursingTime());
|
|
|
+ careNurseRecordsMapper.updateCareNurseRecords(careNurseRecord);
|
|
|
+
|
|
|
//已经开始了直接新增打卡记录
|
|
|
result= careNurseClocksMapper.insertCareNurseClocks(careNurseClocks);
|
|
|
}else{
|
|
|
//修改申请状态为正在进行,并添加护理记录及打卡记录
|
|
|
- CareApplications careApplications=careApplicationsMapper.selectCareApplicationsByApplyId(Long.parseLong(careNurseClocks.getApplyId()));
|
|
|
careApplications.setDealStatus("in_progress");
|
|
|
careApplicationsMapper.updateCareApplications(careApplications);
|
|
|
|
|
|
careNurseRecords=new CareNurseRecords();
|
|
|
careNurseRecords.setNursingTime(careNurseClocks.getNursingTime().substring(0,10));
|
|
|
careNurseRecords.setApplyId(Long.parseLong(careNurseClocks.getApplyId()));
|
|
|
- careNurseRecordsMapper.insertCareNurseRecords(careNurseRecords);
|
|
|
+ careNurseRecords.setClockNum(1);//当天第一次打卡
|
|
|
+ careNurseRecords.setCalDays(new BigDecimal(0));//当天第一次打卡,计算天数为0
|
|
|
+ careNurseRecords.setCalDayReason("今天第一次打卡,计算天数暂定为0");
|
|
|
+ careNurseRecords.setCreateTime(DateUtils.getNowDate());
|
|
|
+ careNurseRecordsMapper.insertCareNurseRecords(careNurseRecords);
|
|
|
|
|
|
//获取打卡次数
|
|
|
CareNurseRecords recordCount=new CareNurseRecords();
|
|
@@ -138,6 +186,89 @@ public class CareNurseClocksServiceImpl implements ICareNurseClocksService
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public int die(CarePersonDie carePersonDie, Long userId) {
|
|
|
+ //特困人员死亡后:1、保存死亡时间及死亡证明 2、修改特困人员表状态 3、计算死亡当天护理天数
|
|
|
+ CareApplications careApplications =careApplicationsMapper.selectCareApplicationsByApplyId(carePersonDie.getApplyId());
|
|
|
+ careApplications.setDieTime(carePersonDie.getDieTime());
|
|
|
+ careApplications.setDieImg(carePersonDie.getImgPaths());
|
|
|
+ careApplicationsMapper.updateCareApplications(careApplications);
|
|
|
+
|
|
|
+ CarePersons persons=carePersonsMapper.selectCarePersonsByPersonId(careApplications.getPersonId());
|
|
|
+ persons.setDieTime(carePersonDie.getDieTime());
|
|
|
+ persons.setIsDie("01");
|
|
|
+ carePersonsMapper.updateCarePersons(persons);
|
|
|
+
|
|
|
+ //获取最后一次打卡记录
|
|
|
+ CareNurseClocks careNurseClock=careNurseClocksMapper.selectLastClock(careApplications.getApplyId());
|
|
|
+ CareNurseRecords careNurseRecord=careNurseRecordsMapper.selectCareNurseRecordsByNursingRecordId(careNurseClock.getNursingRecordId());
|
|
|
+ //计算计时天数
|
|
|
+ careNurseRecord=calDayApplyRecord(careNurseRecord,careNurseClock.getNursingTime());
|
|
|
+ return careNurseRecordsMapper.updateCareNurseRecords(careNurseRecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ private CareNurseRecords calDayApplyRecord(CareNurseRecords careNurseRecords,String nurseTime) {
|
|
|
+ BigDecimal day=new BigDecimal(0);
|
|
|
+ String reason="";
|
|
|
+ //获取第一次打卡时间 判断是上午开始还是下午开始的
|
|
|
+ Date firstTime=careNurseRecords.getCreateTime();
|
|
|
+
|
|
|
+ // 判断是上午还是下午
|
|
|
+ boolean isFirstClockInMorning = isMorning(firstTime);
|
|
|
+
|
|
|
+ //获取当天打卡次数
|
|
|
+ CareNurseClocks param=new CareNurseClocks();
|
|
|
+ param.setApplyId(careNurseRecords.getApplyId().toString());
|
|
|
+ List<CareNurseClocks> lst=careNurseClocksMapper.selectCareNurseClocksList(param);
|
|
|
+ Integer count=lst.size();
|
|
|
+
|
|
|
+ //获取半天次数和全天次数
|
|
|
+ Long allday=sysWorkConfigMapper.selectSysWorkConfigByType("day_clock_num").getNumber();
|
|
|
+ Long halfday=sysWorkConfigMapper.selectSysWorkConfigByType("half_day_num").getNumber();
|
|
|
+
|
|
|
+ //如果第一次是上午打卡,若当前是上午且次数已经达到半天次数,则返回0.5天,若次数未达到,则等待下午打卡;若当前是下午,且次数达到一天,则返回1天
|
|
|
+ //如果第一次是下午打卡,若当前是上午且次数已经达到半天次数,则返回0.5天,若次数未达到,则返回0
|
|
|
+
|
|
|
+ //判断当前是上午还是下午
|
|
|
+ Date currentTime = new Date(nurseTime);
|
|
|
+ if (isFirstClockInMorning) {// 第一次打卡在上午
|
|
|
+ if (isMorning(currentTime)) {
|
|
|
+ if (count >= halfday) {
|
|
|
+ day= new BigDecimal(0.5); // 上午已达半天次数
|
|
|
+ reason="当天从上午开始打卡,截至最后一次打卡已达半天次数,故计算天数0.5天";
|
|
|
+ }
|
|
|
+ } else { // 当前是下午
|
|
|
+ if (count >= allday) {
|
|
|
+ day= new BigDecimal(1); // 已达全天次数
|
|
|
+ reason="当天从上午开始打卡,截至最后一次打卡已达全天次数,故计算天数1天";
|
|
|
+ } else {
|
|
|
+ day= new BigDecimal(0.5); // 未达到全天次数,但已过半天
|
|
|
+ reason="当天从上午开始打卡,截至最后一次打卡未达到全天次数,但已过半天,故计算天数0.5天";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else { // 第一次打卡在下午
|
|
|
+ if (!isMorning(currentTime)) {// 当前也是下午
|
|
|
+ if (count >= halfday) {
|
|
|
+ day= new BigDecimal(0.5); // 达到半天次数
|
|
|
+ reason="当天从下午开始打卡,截至最后一次打卡达到半天次数,故计算天数0.5天";
|
|
|
+ }else{
|
|
|
+ reason="当天从下午开始打卡,截至最后一次打卡未达到半天次数,故计算天数0天";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ careNurseRecords.setCalDays(day);
|
|
|
+ careNurseRecords.setCalDayReason(reason);
|
|
|
+ return careNurseRecords;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isMorning(Date date) {
|
|
|
+ // 根据日期对象判断是否为上午
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ cal.setTime(date);
|
|
|
+ int hour = cal.get(Calendar.HOUR_OF_DAY);
|
|
|
+ return hour < 12;
|
|
|
+ }
|
|
|
/**
|
|
|
* 修改护理任务打卡
|
|
|
*
|
|
@@ -147,6 +278,39 @@ public class CareNurseClocksServiceImpl implements ICareNurseClocksService
|
|
|
@Override
|
|
|
public int updateCareNurseClocks(CareNurseClocks careNurseClocks)
|
|
|
{
|
|
|
+ //判断当前日期是否可以打卡,非残疾人出院前两天不再护理,残疾人截至到出院当天,若无法打卡,则抛出异常
|
|
|
+ CareApplications careApplications = careApplicationsMapper.selectCareApplicationsByApplyId(Long.parseLong(careNurseClocks.getApplyId()));
|
|
|
+ String leaveTimeStr = careApplications.getLeaveTime();
|
|
|
+
|
|
|
+ // 定义日期格式化器
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ // 将字符串转换为LocalDateTime对象
|
|
|
+ LocalDateTime leaveTime = LocalDateTime.parse(leaveTimeStr, formatter);
|
|
|
+ LocalDateTime currentTime = LocalDateTime.parse(careNurseClocks.getNursingTime(), formatter);
|
|
|
+
|
|
|
+ boolean isDisabled = !careApplications.getDisability().equals("N");
|
|
|
+
|
|
|
+ if (isDisabled) {
|
|
|
+ // 残疾人:截至到出院当天
|
|
|
+ if (currentTime.isAfter(leaveTime)) {
|
|
|
+ throw new ServiceException("无法打卡:当前时间已超过出院时间!");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 非残疾人:出院前两天不再护理
|
|
|
+ LocalDateTime cutoffTime = leaveTime.minus(2, ChronoUnit.DAYS);
|
|
|
+ if (currentTime.isAfter(cutoffTime)) {
|
|
|
+ throw new ServiceException("无法打卡:非残疾人出院前两天不再提供护理服务!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //若特困人员在中转或者擅自离院,不提供护理
|
|
|
+ CarePersons carePersons=carePersonsMapper.selectCarePersonsByPersonId(careApplications.getPersonId());
|
|
|
+ if(carePersons.getStatus().equals("02")){
|
|
|
+ throw new ServiceException("无法打卡:当前特困人员处于中转状态!");
|
|
|
+ }else if(carePersons.getStatus().equals("03")){
|
|
|
+ throw new ServiceException("无法打卡:当前特困人员处于擅自离院状态!");
|
|
|
+ }
|
|
|
String psths[]=careNurseClocks.getImgPaths().split(",");
|
|
|
int result=0;
|
|
|
|
|
@@ -159,11 +323,15 @@ public class CareNurseClocksServiceImpl implements ICareNurseClocksService
|
|
|
careNurseRecords.setApplyId(Long.parseLong(careNurseClocks.getApplyId()));
|
|
|
List<CareNurseRecords> lst=careNurseRecordsMapper.selectCareNurseRecordsList(careNurseRecords);
|
|
|
if(lst.size()>0){
|
|
|
+ CareNurseRecords careNurseRecord=lst.get(0);
|
|
|
+ //计算计时天数
|
|
|
+ careNurseRecord=calDayApplyRecord(careNurseRecord,careNurseClocks.getNursingTime());
|
|
|
+ careNurseRecordsMapper.updateCareNurseRecords(careNurseRecord);
|
|
|
+
|
|
|
//已经开始了直接新增打卡记录
|
|
|
result= careNurseClocksMapper.updateCareNurseClocks(careNurseClocks);
|
|
|
}else{
|
|
|
//修改申请状态为正在进行,并添加护理记录及打卡记录
|
|
|
- CareApplications careApplications=careApplicationsMapper.selectCareApplicationsByApplyId(Long.parseLong(careNurseClocks.getApplyId()));
|
|
|
careApplications.setDealStatus("in_progress");
|
|
|
careApplicationsMapper.updateCareApplications(careApplications);
|
|
|
|