| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.constant.YamlProperties; |
| | | import com.whyc.dto.AlarmDaoFactory; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.AlarmManualClearMapper; |
| | | import com.whyc.pojo.AlarmManualClear; |
| | | import com.whyc.pojo.BattalarmData; |
| | | import com.whyc.pojo.DevalarmData; |
| | | import com.whyc.pojo.*; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.DateUtil; |
| | | import com.whyc.util.ThreadLocalUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.system.ApplicationHome; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.whyc.util.ActionUtil.createFilefolderIFNotExist; |
| | | |
| | | @Service |
| | | public class AlarmManualClearService { |
| | |
| | | private PowerInfService powerInfService; |
| | | |
| | | @Autowired |
| | | private BattalarmDataService battAlarmService; |
| | | private BattAlarmDataVerifyService battAlarmService; |
| | | |
| | | @Autowired |
| | | private BattalarmDataHistoryService battAlarmHistoryService; |
| | | |
| | | @Autowired |
| | | private DevalarmDataService devAlarmService; |
| | | private DevAlarmDataVerifyService devAlarmService; |
| | | |
| | | @Autowired |
| | | private DevalarmDataHistoryService devAlarmHistoryService; |
| | | |
| | | @Autowired |
| | | private PwrdevAlarmService powerAlarmService; |
| | | private PwrDevAlarmVerifyService powerAlarmService; |
| | | |
| | | @Autowired |
| | | private PwrdevAlarmHistoryService powerAlarmHistoryService; |
| | | |
| | | @Transactional |
| | | public Response submit(AlarmManualClear clear) { |
| | | public Response submit(List<MultipartFile> file, AlarmManualClear clear) { |
| | | int userId = ActionUtil.getUser().getUId().intValue(); |
| | | clear.setDealUserId(userId); |
| | | clear.setCreateTime(new Date()); |
| | | Date date = new Date(); |
| | | clear.setCreateTime(date); |
| | | //插入对应的站点id,用于后期用户相关 |
| | | Integer alarmType = clear.getAlarmType(); |
| | | String stationId; |
| | | Integer num = clear.getNum(); |
| | | if(alarmType == 1){ //电池告警 |
| | | stationId = battInfService.getStationIdByBattGroupId(clear.getBattGroupId()); |
| | | //添加到历史告警,移除实时告警 |
| | | BattalarmData data = battAlarmService.getById(num); |
| | | //添加到历史告警,移除告警确认数据 |
| | | BattAlarmDataVerify data = battAlarmService.getById(num); |
| | | battAlarmHistoryService.add(data); |
| | | battAlarmService.delete(num); |
| | | } else if (alarmType == 2) { //设备告警 |
| | | stationId = battInfService.getStationIdByDeviceId(clear.getDeviceId()); |
| | | DevalarmData data = devAlarmService.getById(num); |
| | | DevAlarmDataVerify data = devAlarmService.getById(num); |
| | | devAlarmHistoryService.add(data); |
| | | devAlarmService.delete(num); |
| | | |
| | | }else{ //电源告警 |
| | | stationId = powerInfService.getStationIdByPowerDeviceId(clear.getPowerDeviceId()); |
| | | PwrDevAlarmVerify data = powerAlarmService.getById(num); |
| | | powerAlarmHistoryService.add(data); |
| | | powerAlarmService.delete(num); |
| | | } |
| | | clear.setStationId(stationId); |
| | | mapper.insert(clear); |
| | | return new Response().set(1,"提交完成"); |
| | | //处理文件 |
| | | String fileDirName = ""; |
| | | ApplicationHome applicationHome = new ApplicationHome(getClass()); |
| | | File jarFile = applicationHome.getDir(); |
| | | //测试版 |
| | | if (YamlProperties.runModel == 1) { |
| | | fileDirName = jarFile.getParentFile().toString(); |
| | | } else { |
| | | //打包版 |
| | | fileDirName = jarFile.toString(); |
| | | } |
| | | //文件夹按月度存储 |
| | | //String root=fileDirName+"/fg_file/alarm_manual_clear/"+ DateUtil.YYYY_MM.format(date) + "/"; |
| | | String root=fileDirName+"/fg_file/alarm_manual_clear/"+ ThreadLocalUtil.format(date,5) + "/"; |
| | | List<String> filePathList = new ArrayList<>(); |
| | | try { |
| | | for (int i = 0; i < file.size(); i++) { |
| | | String fileFileName = file.get(i).getOriginalFilename(); |
| | | //String filePath = root + DateUtil.YYYY_MM_DD_HH_MM_SS_UNION.format(date)+"_"+fileFileName; |
| | | String filePath = root + ThreadLocalUtil.format(date,7)+"_"+fileFileName; |
| | | createFilefolderIFNotExist(filePath); |
| | | file.get(i).transferTo(new File(filePath)); |
| | | String httpFilePath = filePath.replace(fileDirName, ""); |
| | | filePathList.add(httpFilePath); |
| | | } |
| | | StringBuilder filePathUnion = new StringBuilder(); |
| | | int size = filePathList.size(); |
| | | for (int i = 0; i < size; i++) { |
| | | String filePath = filePathList.get(i); |
| | | filePathUnion.append(filePath); |
| | | if(i!= size -1) { |
| | | filePathUnion.append(";"); |
| | | } |
| | | } |
| | | clear.setFileUrl(filePathUnion.toString()); |
| | | mapper.insert(clear); |
| | | return new Response().set(1,"提交完成"); |
| | | } catch (IOException e) { |
| | | return new Response().set(0,"接口发生异常:"+e.toString()); |
| | | } |
| | | } |
| | | |
| | | public Response getRecordByAlarmInfo(AlarmManualClear clear) { |
| | |
| | | |
| | | } |
| | | |
| | | public Response getPage(int pageNum,int pageSize) { |
| | | public Response getPage(AlarmManualClear param) { |
| | | int userId = ActionUtil.getUser().getUId().intValue(); |
| | | //查询所有的记录分页 |
| | | PageHelper.startPage(pageNum,pageSize); |
| | | List<AlarmManualClear> list = mapper.getAll(userId); |
| | | param.setDealUserId(userId); |
| | | PageHelper.startPage(param.getPageNum(),param.getPageSize()); |
| | | List<AlarmManualClear> list = mapper.getAll(param); |
| | | PageInfo<AlarmManualClear> pageInfo = new PageInfo<>(list); |
| | | ////装配电池/设备/电源信息 |
| | | //List<AlarmManualClear> dataList = pageInfo.getList(); |
| | |
| | | }); |
| | | return new Response().set(1,pageInfo); |
| | | } |
| | | |
| | | /** |
| | | * 查询实施表中所有的main_id |
| | | * @return |
| | | */ |
| | | public List<Integer> getAllMainIds(){ |
| | | return mapper.getAllMainIds(); |
| | | } |
| | | } |