|
|
|
|
@ -2,7 +2,7 @@ package org.springblade.modules.business.service.impl; |
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
import org.springblade.common.constant.BusinessConstant; |
|
|
|
|
import org.springblade.common.utils.CommonDateUtil; |
|
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
|
@ -11,22 +11,17 @@ import org.springblade.core.secure.utils.AuthUtil; |
|
|
|
|
import org.springblade.core.tool.utils.BeanUtil; |
|
|
|
|
import org.springblade.core.tool.utils.DateUtil; |
|
|
|
|
import org.springblade.core.tool.utils.Func; |
|
|
|
|
import org.springblade.core.tool.utils.SpringUtil; |
|
|
|
|
import org.springblade.modules.business.dto.ApmRecordCountDTO; |
|
|
|
|
import org.springblade.modules.business.entity.ApmConfig; |
|
|
|
|
import org.springblade.modules.business.entity.ApmRecord; |
|
|
|
|
import org.springblade.modules.business.mapper.ApmConfigMapper; |
|
|
|
|
import org.springblade.modules.business.service.IApmConfigService; |
|
|
|
|
import org.springblade.modules.business.service.IApmRecordService; |
|
|
|
|
import org.springblade.modules.business.service.IBlacklistService; |
|
|
|
|
import org.springblade.modules.business.vo.ApmConfigListVO; |
|
|
|
|
import org.springblade.modules.business.wrapper.ApmConfigListWrapper; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.function.Function; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
@ -36,13 +31,10 @@ import java.util.stream.Collectors; |
|
|
|
|
* @author Chill |
|
|
|
|
*/ |
|
|
|
|
@Service |
|
|
|
|
@RequiredArgsConstructor |
|
|
|
|
public class ApmConfigServiceImpl extends BaseServiceImpl<ApmConfigMapper, ApmConfig> implements IApmConfigService { |
|
|
|
|
|
|
|
|
|
private static final IApmRecordService recordService; |
|
|
|
|
|
|
|
|
|
static { |
|
|
|
|
recordService = SpringUtil.getBean(IApmRecordService.class); |
|
|
|
|
} |
|
|
|
|
private final IApmRecordService recordService; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Map<String, List<String>> alreadyConfigDay(Long createDept, String startTime, String endTime) { |
|
|
|
|
@ -63,13 +55,13 @@ public class ApmConfigServiceImpl extends BaseServiceImpl<ApmConfigMapper, ApmCo |
|
|
|
|
@Override |
|
|
|
|
public IPage<ApmConfigListVO> selectPage(IPage<ApmConfig> page, Long createDept, String startTime, String endTime, String project) { |
|
|
|
|
// 由于每个时段保存了一条记录, 故分页时, 先使用distinct查询(医院, 项目 配置天)进行分页
|
|
|
|
|
List<ApmConfig> pageRecord = baseMapper.selectPage(page, createDept, startTime, endTime, project); |
|
|
|
|
List<ApmConfig> pageRecord = baseMapper.selectConfigPage(page, createDept, startTime, endTime, project); |
|
|
|
|
page.setRecords(pageRecord); |
|
|
|
|
|
|
|
|
|
IPage<ApmConfigListVO> result = ApmConfigListWrapper.build().pageVO(page); |
|
|
|
|
result.getRecords().forEach(vo -> { |
|
|
|
|
// 根据(医院, 项目 配置天)获取配置详细
|
|
|
|
|
List<ApmConfig> configList = baseMapper.selectList(vo.getCreateDept(), DateUtil.format(vo.getApmDay(), DateUtil.PATTERN_DATETIME), vo.getProject()); |
|
|
|
|
List<ApmConfig> configList = baseMapper.selectConfigList(vo.getCreateDept(), DateUtil.format(vo.getApmDay(), DateUtil.PATTERN_DATETIME), vo.getProject()); |
|
|
|
|
|
|
|
|
|
// 获取该天的所有预约统计
|
|
|
|
|
List<ApmRecordCountDTO> apmCountList = recordService.countAmpNum(createDept, DateUtil.format(vo.getApmDay(), DateUtil.PATTERN_DATETIME)); |
|
|
|
|
@ -169,23 +161,15 @@ public class ApmConfigServiceImpl extends BaseServiceImpl<ApmConfigMapper, ApmCo |
|
|
|
|
@Override |
|
|
|
|
public String saveCheck(Long createDept, List<String> dayList, List<ApmConfigListVO> configListVOS) { |
|
|
|
|
String msg = ""; |
|
|
|
|
List<String> daySearchList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
List<ApmConfig> alreadyConfList = baseMapper.selectList(Wrappers.<ApmConfig>lambdaQuery() |
|
|
|
|
.eq(ApmConfig::getCreateDept, createDept) |
|
|
|
|
.in(ApmConfig::getApmDay, dayList)); |
|
|
|
|
Map<String, ApmConfig> alreadyConfMap = new HashMap<>(); |
|
|
|
|
if (Func.isNotEmpty(alreadyConfList)) { |
|
|
|
|
alreadyConfMap = alreadyConfList.stream().collect(Collectors.toMap( |
|
|
|
|
config -> config.getProject() + config.getApmDay() + config.getProject() + config.getTimeFrame(), Function.identity() |
|
|
|
|
)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 1. 先根据用户角色判断放号的天是否短于提前几天放号的配置
|
|
|
|
|
BladeUser user = AuthUtil.getUser(); |
|
|
|
|
int configSubDays = BusinessConstant.ROLE_NAME_HOSPITAL.equals(user.getRoleName()) ? BusinessConstant.HOSPITAL_APM_CONFIG_RANGE : 1; |
|
|
|
|
|
|
|
|
|
List<ApmConfig> configList = new ArrayList<>(); |
|
|
|
|
for (String day : dayList) { |
|
|
|
|
int subDays = CommonDateUtil.daysBetween(DateUtil.now(), DateUtil.parse(day, DateUtil.PATTERN_DATETIME)); |
|
|
|
|
Date configApmDay = DateUtil.parse(day + BusinessConstant.DATE_STR_HMS, DateUtil.PATTERN_DATETIME); |
|
|
|
|
int subDays = CommonDateUtil.daysBetween(DateUtil.now(), configApmDay); |
|
|
|
|
if (subDays < configSubDays) { |
|
|
|
|
return "保存失败, 只能保存" + configSubDays + "天之后的放号配置"; |
|
|
|
|
} |
|
|
|
|
@ -197,15 +181,48 @@ public class ApmConfigServiceImpl extends BaseServiceImpl<ApmConfigMapper, ApmCo |
|
|
|
|
Integer numberNum = detail.containsKey(BusinessConstant.MAP_KEY_APM_CONFIG_LIST_NUMBER_NUM) ? (Integer) detail.get(BusinessConstant.MAP_KEY_APM_CONFIG_LIST_NUMBER_NUM) : 0; |
|
|
|
|
|
|
|
|
|
ApmConfig config = BeanUtil.copy(vo, ApmConfig.class); |
|
|
|
|
config.setApmDay(DateUtil.parse(day, DateUtil.PATTERN_DATETIME)); |
|
|
|
|
config.setApmDay(configApmDay); |
|
|
|
|
config.setPeriod(period); |
|
|
|
|
config.setTimeFrame(timeFrame); |
|
|
|
|
config.setNumberNum(numberNum); |
|
|
|
|
configList.add(config); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
daySearchList.add(day + BusinessConstant.DATE_STR_HMS); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 根据医院, 日期 查询该日期是否已有放号配置, 若有且已被预约, 放号数量只能增加, 不能减少
|
|
|
|
|
List<ApmConfig> alreadyConfList = baseMapper.selectList(Wrappers.<ApmConfig>lambdaQuery() |
|
|
|
|
.eq(ApmConfig::getCreateDept, createDept) |
|
|
|
|
.in(ApmConfig::getApmDay, daySearchList)); |
|
|
|
|
Map<String, ApmConfig> alreadyConfMap = new HashMap<>(); |
|
|
|
|
if (Func.isNotEmpty(alreadyConfList)) { |
|
|
|
|
alreadyConfMap = alreadyConfList.stream().collect(Collectors.toMap( |
|
|
|
|
config -> config.getProject() + config.getApmDay() + config.getProject() + config.getTimeFrame(), Function.identity() |
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
List<ApmRecordCountDTO> records = recordService.countAmpNum(createDept, daySearchList); |
|
|
|
|
if (Func.isEmpty(records)) { |
|
|
|
|
records = new ArrayList<>(); |
|
|
|
|
} |
|
|
|
|
Map<String, Integer> alreadyConfCountMap = records.stream().collect(Collectors.toMap( |
|
|
|
|
dto -> dto.getProject() + dto.getApmDay() + dto.getProject() + dto.getTimeFrame(), dto -> dto.getApmNum() |
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
for (ApmConfig config : configList) { |
|
|
|
|
String key = config.getProject() + config.getApmDay() + config.getProject() + config.getTimeFrame(); |
|
|
|
|
|
|
|
|
|
// 若此次修改的放号没有对应的放号配置或已预约统计为0, 验证通过
|
|
|
|
|
if (alreadyConfCountMap.containsKey(key) || alreadyConfCountMap.containsKey(key)) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (config.getNumberNum() < alreadyConfCountMap.get(key)) { |
|
|
|
|
return "保存失败, 放号数量不能低于已预约的数量"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return msg; |
|
|
|
|
} |
|
|
|
|
@ -217,9 +234,12 @@ public class ApmConfigServiceImpl extends BaseServiceImpl<ApmConfigMapper, ApmCo |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
List<ApmConfig> configList = new ArrayList<>(); |
|
|
|
|
List<String> daySearchList = new ArrayList<>(); |
|
|
|
|
List<String> projectList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
for (String day : dayList) { |
|
|
|
|
for (ApmConfigListVO vo : configListVOS) { |
|
|
|
|
projectList.add(vo.getProject()); |
|
|
|
|
for (Map<String, Object> detail : vo.getDetailList()) { |
|
|
|
|
String period = detail.containsKey(BusinessConstant.MAP_KEY_APM_CONFIG_LIST_PERIOD) ? (String) detail.get(BusinessConstant.MAP_KEY_APM_CONFIG_LIST_PERIOD) : ""; |
|
|
|
|
String timeFrame = detail.containsKey(BusinessConstant.MAP_KEY_APM_CONFIG_LIST_TIME_FRAME) ? (String) detail.get(BusinessConstant.MAP_KEY_APM_CONFIG_LIST_TIME_FRAME) : ""; |
|
|
|
|
@ -233,8 +253,14 @@ public class ApmConfigServiceImpl extends BaseServiceImpl<ApmConfigMapper, ApmCo |
|
|
|
|
configList.add(config); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
daySearchList.add(day + BusinessConstant.DATE_STR_HMS); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 首先, 根据(医院,体检项目,日期)将放号配置删除, 然后重新添加放号配置
|
|
|
|
|
|
|
|
|
|
baseMapper.deleteConfig(createDept, daySearchList, projectList); |
|
|
|
|
|
|
|
|
|
saveBatch(configList); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|