package com.gkhy.safePlatform.emergency.service.impl; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.gkhy.safePlatform.commons.co.ContextCacheUser; import com.gkhy.safePlatform.commons.enums.ResultCodes; import com.gkhy.safePlatform.commons.query.PageQuery; import com.gkhy.safePlatform.commons.utils.BeanCopyUtils; import com.gkhy.safePlatform.commons.utils.StringUtils; import com.gkhy.safePlatform.commons.vo.ResultVO; import com.gkhy.safePlatform.commons.vo.SearchResultVO; import com.gkhy.safePlatform.emergency.entity.*; import com.gkhy.safePlatform.emergency.enums.EmergencyResultCodes; import com.gkhy.safePlatform.emergency.excepiton.EmergencyException; import com.gkhy.safePlatform.emergency.model.dto.req.*; import com.gkhy.safePlatform.emergency.model.dto.resp.*; import com.gkhy.safePlatform.emergency.query.EmergencyPlanLogQuery; import com.gkhy.safePlatform.emergency.query.db.EmergencyPlanLogDBQuery; import com.gkhy.safePlatform.emergency.service.EmergencyPlanLogService; import com.gkhy.safePlatform.emergency.service.baseService.*; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.stream.Collectors; @Service("emergencyPlanLogService") public class EmergencyPlanLogServiceImpl implements EmergencyPlanLogService { @Autowired private EmergencyPlanLogInfoService emergencyPlanLogInfoService; @Autowired private EmergencyPlanInfoService emergencyPlanInfoService; @Override public SearchResultVO> selectEmergencyPlanLogList(PageQuery query) { Long pageIndex = query.getPageIndex(); Long pageSize = query.getPageSize(); Page page = new Page<>(pageIndex, pageSize); EmergencyPlanLogDBQuery emergencyPlanLogDBQuery = new EmergencyPlanLogDBQuery(); if (query.getSearchParams() != null) { BeanUtils.copyProperties(query.getSearchParams(), emergencyPlanLogDBQuery); } List emergencyPlanLogListDoInfoList = emergencyPlanLogInfoService.selectEmergencyPlanLogList(page, emergencyPlanLogDBQuery); List respList = BeanCopyUtils.copyBeanList(emergencyPlanLogListDoInfoList, EmergencyPlanLogRespDTO.class); return new SearchResultVO<>( true, pageIndex, pageSize,page.getPages(), page.getTotal(), respList, ResultCodes.OK ); } @Override public ResultVO addEmergencyPlanLog(ContextCacheUser currentUser, EmergencyPlanLogReqDTO emergencyPlanLogReqDTO) { Long uid = currentUser.getUid(); String uname = currentUser.getRealName(); // 判断请求中是否存在应急预案id if (emergencyPlanLogReqDTO.getPlanId() == null) { throw new EmergencyException(EmergencyResultCodes.PLAN_NULL); } else { EmergencyPlanInfoDetailDO emergencyPlanInfoDetailDO = emergencyPlanInfoService.selectEmergencyPlanById(emergencyPlanLogReqDTO.getPlanId()); // 判断是否存在该应急预案 if (emergencyPlanInfoDetailDO == null) { throw new EmergencyException(EmergencyResultCodes.PLAN_NOT_EXIST); } else { Date nowDate = new Date(); // 新增应急预案启动记录 EmergencyPlanLogInfo emergencyPlanLogInfo = new EmergencyPlanLogInfo(); BeanUtils.copyProperties(emergencyPlanLogReqDTO, emergencyPlanLogInfo); emergencyPlanLogInfo.setDelFlag(false); emergencyPlanLogInfo.setCreateUid(uid); emergencyPlanLogInfo.setGmtCreate(nowDate); emergencyPlanLogInfo.setUserUid(uid); emergencyPlanLogInfo.setUserName(uname); emergencyPlanLogInfo.setStartCreate(nowDate); emergencyPlanLogInfoService.addEmergencyPlanLog(emergencyPlanLogInfo); return new ResultVO<>(ResultCodes.OK); } } } @Override public ResultVO getEmergencyPlanLogById(Long id) { EmergencyPlanLogRespDTO emergencyPlanLogDetailRespDTO = new EmergencyPlanLogRespDTO(); // 查询是否存在 EmergencyPlanLogInfoDO emergencyPlanLogInfoDetailDO = emergencyPlanLogInfoService.selectEmergencyPlanLogById(id); if (emergencyPlanLogInfoDetailDO == null) { throw new EmergencyException(EmergencyResultCodes.PLAN_LOG_NOT_EXIST); } else { BeanUtils.copyProperties(emergencyPlanLogInfoDetailDO, emergencyPlanLogDetailRespDTO); return new ResultVO<>(ResultCodes.OK, emergencyPlanLogDetailRespDTO); } } @Override public ResultVO updateEmergencyPlanLog(Long uid, EmergencyPlanLogReqDTO emergencyPlanLogReqDTO) { // 查询是否存在启动记录 EmergencyPlanLogInfoDO emergencyPlanLogInfoDetailDO = emergencyPlanLogInfoService.selectEmergencyPlanLogById(emergencyPlanLogReqDTO.getId()); if (emergencyPlanLogInfoDetailDO == null) { throw new EmergencyException(EmergencyResultCodes.PLAN_LOG_NOT_EXIST); } else { // 判断请求中是否存在应急预案id if (emergencyPlanLogReqDTO.getPlanId() == null) { throw new EmergencyException(EmergencyResultCodes.PLAN_NULL); } else { EmergencyPlanInfoDetailDO emergencyPlanInfoDetailDO = emergencyPlanInfoService.selectEmergencyPlanById(emergencyPlanLogReqDTO.getPlanId()); // 判断是否存在该应急预案 if (emergencyPlanInfoDetailDO == null) { throw new EmergencyException(EmergencyResultCodes.PLAN_NOT_EXIST); } else { EmergencyPlanLogInfo emergencyPlanLogInfo = new EmergencyPlanLogInfo(); BeanUtils.copyProperties(emergencyPlanLogReqDTO, emergencyPlanLogInfo); emergencyPlanLogInfo.setUpdateUid(uid); emergencyPlanLogInfo.setGmtModitify(new Date()); emergencyPlanLogInfoService.updateEmergencyPlanLog(emergencyPlanLogInfo); return new ResultVO<>(ResultCodes.OK); } } } } @Override public ResultVO batchDeleteEmergencyPlanLog(Long[] ids) { if (ids == null || ids.length==0){ throw new EmergencyException(EmergencyResultCodes.PLAN_LOG_NOT_EXIST); }else{ for (Long id : ids){ deleteEmergencyPlanLog(id); } return new ResultVO(ResultCodes.OK); } } private void deleteEmergencyPlanLog(Long id) { //查询是否存在 EmergencyPlanLogInfoDO emergencyPlanLogInfoDetailDO = emergencyPlanLogInfoService.selectEmergencyPlanLogById(id); if (emergencyPlanLogInfoDetailDO == null) { throw new EmergencyException(EmergencyResultCodes.PLAN_LOG_NOT_EXIST); } else { emergencyPlanLogInfoService.deleteEmergencyPlanLog(id); } } }