提交 db360dfe authored 作者: 邓砥奕's avatar 邓砥奕

[统计分析]实现业务统计、告警统计service层

上级 f639093e
......@@ -4,12 +4,14 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author dengdiyi
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("维修装备详情类")
public class DeviceDetailVo {
......
......@@ -17,6 +17,7 @@ import com.tykj.dev.device.task.service.TaskLogService;
import com.tykj.dev.device.task.service.TaskService;
import com.tykj.dev.device.task.subject.bto.TaskBto;
import com.tykj.dev.device.user.subject.entity.User;
import com.tykj.dev.device.user.subject.service.UserPublicService;
import com.tykj.dev.device.user.util.AuthenticationUtils;
import com.tykj.dev.misc.base.BusinessEnum;
import com.tykj.dev.misc.base.StatusEnum;
......@@ -65,6 +66,9 @@ public class DeviceRetiredController {
@Autowired
private AuthenticationUtils AuthenticationUtils;
@Autowired
private UserPublicService userPublicService;
public DeviceRetiredController(DeviceRetiredBillService deviceRetiredBillService, TaskService taskService, PackingLibraryService packingLibraryService, DeviceLibraryService deviceLibraryService, DeviceLogService deviceLogService, TaskLogService taskLogService) {
this.deviceRetiredBillService = deviceRetiredBillService;
this.taskService = taskService;
......@@ -118,8 +122,8 @@ public class DeviceRetiredController {
deviceRetiredDetailResultVo.getPackingLibrarys().add(packingLibraryService.getOne(deviceId));
}
deviceRetiredDetailResultVo.setRetiredStatus(deviceRetiredBillEntity.getRetiredStatus());
deviceRetiredDetailResultVo.setConfirmUserId(deviceRetiredBillEntity.getUserBId());
deviceRetiredDetailResultVo.setStartUserId(deviceRetiredBillEntity.getUserAId());
deviceRetiredDetailResultVo.setConfirmUser(userPublicService.getOne(deviceRetiredBillEntity.getUserBId()).getName());
deviceRetiredDetailResultVo.setStartUser(userPublicService.getOne(deviceRetiredBillEntity.getUserAId()).getName());
return ResultUtil.success(deviceRetiredDetailResultVo);
}
......
......@@ -18,11 +18,11 @@ import java.util.List;
@ApiModel("销毁详情查询类")
public class DeviceRetiredDetailResultVo {
@ApiModelProperty(value = "发起人ID", example = "1")
private Integer startUserId;
@ApiModelProperty(value = "发起人", example = "1")
private String startUser;
@ApiModelProperty(value = "审核人ID", example = "1")
private Integer confirmUserId;
@ApiModelProperty(value = "审核人", example = "1")
private String confirmUser;
@ApiModelProperty(value = "销毁状态(0:销毁装备出库待审核,1:销毁装备出库审核失败,2:已销毁)")
private Integer retiredStatus;
......
......@@ -32,6 +32,18 @@
<groupId>com.tykj</groupId>
<artifactId>dev-selfcheck</artifactId>
</dependency>
<dependency>
<groupId>com.tykj.dev</groupId>
<artifactId>rfid</artifactId>
</dependency>
<dependency>
<groupId>com.tykj</groupId>
<artifactId>dev-task</artifactId>
</dependency>
<dependency>
<groupId>com.tykj</groupId>
<artifactId>dev-finalcheck</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -26,6 +26,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
......@@ -97,12 +98,21 @@ public class StatisticalController {
/**
* 查询告警情况
* @return 各市装备生命状态对象集合
* @return 全省告警统计对象集合
*/
@GetMapping("/alarmSituation")
public ResponseEntity selectAlarmSituation(){
return ResponseEntity.ok(statisticalService.getRfidWarning());
}
return ResponseEntity.ok(new AlarmSituation());
/**
* 查询各市告警情况
* @return 各市告警情况对象集合
*/
@GetMapping("/alarmSituation/detail")
public ResponseEntity selectAlarmSituationDetail(){
List<AlarmSituation> alarmSituations = new ArrayList<>();
return ResponseEntity.ok(alarmSituations);
}
/**
......@@ -110,7 +120,7 @@ public class StatisticalController {
* @return 各市装备生命状态对象集合
*/
@GetMapping("/businessSituation/{type}")
public ResponseEntity selectBusinessSituation(@PathVariable Integer type){
return ResponseEntity.ok(new BusinessSituation());
public ResponseEntity selectBusinessSituation(@PathVariable Integer type) throws ParseException {
return ResponseEntity.ok(statisticalService.getBusinessNum(type));
}
}
package com.tykj.dev.statistical.service;
import com.tykj.dev.statistical.vo.DevLifeSector;
import com.tykj.dev.statistical.vo.DevNum;
import com.tykj.dev.statistical.vo.SelfInspection;
import com.tykj.dev.statistical.vo.YearSelfInspection;
import com.tykj.dev.statistical.vo.*;
import java.text.ParseException;
import java.util.List;
/**
......@@ -33,4 +31,14 @@ public interface StatisticalService {
*/
List<YearSelfInspection> getYearSelfCheck();
/**
* 获取年度告警统计信息
*/
AlarmSituation getRfidWarning();
/**
* @param type 类型(1:上半年,2:下半年)
* 获取业务统计信息
*/
BusinessSituation getBusinessNum(Integer type) throws ParseException;
}
package com.tykj.dev.statistical.service.impl;
import com.tykj.dev.device.finalcheck.entity.domain.FinalReport;
import com.tykj.dev.device.finalcheck.repisotry.FinalReportDao;
import com.tykj.dev.device.library.repository.DeviceLibraryDao;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import com.tykj.dev.device.selfcheck.base.SelfCheckSchedulerTask;
import com.tykj.dev.device.selfcheck.repository.SelfCheckBillDao;
import com.tykj.dev.device.selfcheck.subject.domin.SelfCheckBill;
import com.tykj.dev.device.task.repository.TaskDao;
import com.tykj.dev.device.task.subject.domin.Task;
import com.tykj.dev.device.user.subject.dao.AreaDao;
import com.tykj.dev.device.user.subject.dao.UnitsDao;
import com.tykj.dev.device.user.subject.entity.Area;
import com.tykj.dev.device.user.subject.entity.Units;
import com.tykj.dev.misc.exception.ApiException;
import com.tykj.dev.rfid.entity.domin.LibraryWarningLog;
import com.tykj.dev.rfid.repository.LibraryWarningLogDao;
import com.tykj.dev.statistical.service.StatisticalService;
import com.tykj.dev.statistical.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
......@@ -40,6 +49,15 @@ public class StatisticalServiceImpl implements StatisticalService {
@Autowired
private SelfCheckBillDao selfCheckBillDao;
@Autowired
private LibraryWarningLogDao libraryWarningLogDao;
@Autowired
private TaskDao taskDao;
@Autowired
private FinalReportDao finalReportDao;
/**
* 获取装备统计信息
*/
......@@ -213,6 +231,68 @@ public class StatisticalServiceImpl implements StatisticalService {
return yearSelfInspections;
}
/**
* 获取年度告警统计信息
*/
@Override
public AlarmSituation getRfidWarning() {
AlarmSituation alarmSituation = new AlarmSituation();
//获取当前年份
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
int year = calendar.get(Calendar.YEAR);
//获取本年度所有告警记录
List<LibraryWarningLog> libraryWarningLogs = libraryWarningLogDao.findAll().stream()
.filter(libraryWarningLog -> {
calendar.setTime(libraryWarningLog.getCreateTime());
return year==calendar.get(Calendar.YEAR);
})
.collect(Collectors.toList());
alarmSituation.setAlarmCount(libraryWarningLogs.size());
//获取盘库异常数量
int inventoryNum = (int)libraryWarningLogs.stream().filter(libraryWarningLog -> libraryWarningLog.getWarningType()==2).count();
//获取未处理数量
int unHandleNum = (int)libraryWarningLogs.stream().filter(libraryWarningLog -> libraryWarningLog.getWarningHandle()==0).count();
alarmSituation.setInventoryCount(inventoryNum);
alarmSituation.setInOutCount(libraryWarningLogs.size()-inventoryNum);
alarmSituation.setUntreatedCount(unHandleNum);
return alarmSituation;
}
/**
* @param type 类型(1:上半年,2:下半年)
* 获取业务统计信息
*/
@Override
public BusinessSituation getBusinessNum(Integer type) throws ParseException {
List<Task> tasks;
List<FinalReport> finalReports;
//上半年
if (type==1){
List<Date> dates = getFirstHalfYear();
tasks = taskDao.findAll().stream()
.filter(task -> task.getCreateTime().after(dates.get(0))&&task.getCreateTime().before(dates.get(1))&&(task.getParentTaskId()==null||task.getParentTaskId()==0))
.collect(Collectors.toList());
finalReports = finalReportDao.findAll().stream()
.filter(finalReport -> Date.from(finalReport.getCreateTime().atZone(ZoneId.systemDefault()).toInstant()).after(dates.get(0))&&Date.from(finalReport.getCreateTime().atZone(ZoneId.systemDefault()).toInstant()).before(dates.get(1)))
.collect(Collectors.toList());
return countBusiness(tasks,finalReports);
}
else if (type==2){
List<Date> dates = getLastHalfYear();
tasks = taskDao.findAll().stream()
.filter(task -> task.getCreateTime().after(dates.get(0))&&task.getCreateTime().before(dates.get(1))&&(task.getParentTaskId()==null||task.getParentTaskId()==0))
.collect(Collectors.toList());
finalReports = finalReportDao.findAll().stream()
.filter(finalReport -> Date.from(finalReport.getCreateTime().atZone(ZoneId.systemDefault()).toInstant()).after(dates.get(0))&&Date.from(finalReport.getCreateTime().atZone(ZoneId.systemDefault()).toInstant()).before(dates.get(1)))
.collect(Collectors.toList());
return countBusiness(tasks,finalReports);
}
else {
throw new ApiException("type只能为1或2");
}
}
/**
* @param devLifeSector 装备生命状态添统计
* @param deviceLibraries 统计装备
......@@ -307,4 +387,92 @@ public class StatisticalServiceImpl implements StatisticalService {
perQuarter.setNoCompleteCount(undoAreas.size());
perQuarter.setCompleteCount(sonAreas.size()-undoAreas.size());
}
/**
* 获取上半年开始时间和结束时间
*/
private List<Date> getFirstHalfYear() throws ParseException {
List<Date> dates = new ArrayList<>();
//获取当前年份
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
int year = calendar.get(Calendar.YEAR);
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
Date date1 = dateformat.parse(year+"-1-1");
Date date2 = dateformat.parse(year+"-7-1");
dates.add(date1);
dates.add(date2);
return dates;
}
/**
* 获取下半年开始时间和结束时间
*/
private List<Date> getLastHalfYear() throws ParseException {
List<Date> dates = new ArrayList<>();
//获取当前年份
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
int year = calendar.get(Calendar.YEAR);
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
Date date1 = dateformat.parse(year+"-7-1");
Date date2 = dateformat.parse((year+1)+"-1-1");
dates.add(date1);
dates.add(date2);
return dates;
}
private BusinessSituation countBusiness(List<Task> tasks,List<FinalReport> finalReports){
int withCount = 0;
int sendRepelCount = 0;
int selfInspection = 0;
int verification = 0;
int train = 0;
int finalAccounts = finalReports.size();
int putStorage = 0;
int apply = 0;
int fielding = 0;
int backPack = 0;
int destruction = 0;
int maintenance = 0;
for (Task task: tasks) {
switch (task.getBusinessType()){
case 1:
fielding++;
break;
case 2:
putStorage++;
break;
case 3:
withCount++;
break;
case 4:
selfInspection++;
break;
case 5:
maintenance++;
break;
case 7:
verification++;
break;
case 9:
apply++;
break;
case 13:
train++;
break;
case 14:
destruction++;
break;
case 15:
backPack++;
break;
case 16:
sendRepelCount++;
break;
default:break;
}
}
return new BusinessSituation(withCount,sendRepelCount,selfInspection,verification,train,finalAccounts,putStorage,apply,fielding,backPack,destruction,maintenance);
}
}
package com.tykj.dev.statistical.vo;
import lombok.Data;
/**
* @author zjm
* @version 1.0.0
......@@ -7,6 +9,7 @@ package com.tykj.dev.statistical.vo;
* @Description 告警概况
* @createTime 2020年10月16日 13:50:00
*/
@Data
public class AlarmSituation {
/**
* 总数
......@@ -15,7 +18,7 @@ public class AlarmSituation {
/**
* 出入
*/
private Integer inOutConut;
private Integer inOutCount;
/**
*盘库
*/
......@@ -24,4 +27,8 @@ public class AlarmSituation {
* 未处理
*/
private Integer untreatedCount;
/**
* 告警地区
*/
private String area;
}
package com.tykj.dev.statistical.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* @author zjm
* @version 1.0.0
......@@ -7,6 +10,8 @@ package com.tykj.dev.statistical.vo;
* @Description TODO
* @createTime 2020年10月16日 13:21:00
*/
@Data
@AllArgsConstructor
public class BusinessSituation {
/**
* 配发
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论