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

[统计分析]实现装备统计、自查统计service层,添加统计分析模块启动类

上级 e7b35eae
...@@ -46,7 +46,7 @@ public class SelfCheckSchedulerTask { ...@@ -46,7 +46,7 @@ public class SelfCheckSchedulerTask {
/** /**
* 季度 * 季度
*/ */
private String cron2 = "0 0 0 1 3,6,9,12 ? "; private String cron2 = "0 0 0 1 1,4,7,10 ? ";
/** /**
* 年度 * 年度
*/ */
......
...@@ -104,7 +104,7 @@ public class SelfCheckController { ...@@ -104,7 +104,7 @@ public class SelfCheckController {
/** /**
* 季度 * 季度
*/ */
private String cron2 = "0 0 0 1 3,6,9,12 ? "; private String cron2 = "0 0 0 1 1,4,7,10 ? ";
/** /**
* 年度 * 年度
*/ */
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<artifactId>equip</artifactId> <artifactId>equip</artifactId>
...@@ -24,6 +24,14 @@ ...@@ -24,6 +24,14 @@
<groupId>com.tykj.dev</groupId> <groupId>com.tykj.dev</groupId>
<artifactId>config</artifactId> <artifactId>config</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.tykj</groupId>
<artifactId>dev-library</artifactId>
</dependency>
<dependency>
<groupId>com.tykj</groupId>
<artifactId>dev-selfcheck</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
...@@ -9,8 +9,16 @@ package com.tykj.dev.statistical.controller; ...@@ -9,8 +9,16 @@ package com.tykj.dev.statistical.controller;
*/ */
import com.tykj.dev.config.swagger.AutoDocument; import com.tykj.dev.config.swagger.AutoDocument;
import com.tykj.dev.device.library.repository.DeviceLibraryDao;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
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.statistical.service.StatisticalService;
import com.tykj.dev.statistical.vo.*; import com.tykj.dev.statistical.vo.*;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.RequestEntity; import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -20,6 +28,7 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -20,6 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
@RestController @RestController
@Api(tags = "统计业务模块", description = "统计相关接口") @Api(tags = "统计业务模块", description = "统计相关接口")
...@@ -27,6 +36,8 @@ import java.util.List; ...@@ -27,6 +36,8 @@ import java.util.List;
@RequestMapping("/statistical") @RequestMapping("/statistical")
public class StatisticalController { public class StatisticalController {
@Autowired
private StatisticalService statisticalService;
/** /**
* 查询各市的装备数量 * 查询各市的装备数量
...@@ -34,35 +45,41 @@ public class StatisticalController { ...@@ -34,35 +45,41 @@ public class StatisticalController {
*/ */
@GetMapping("/devNum") @GetMapping("/devNum")
public ResponseEntity selectDevNum(){ public ResponseEntity selectDevNum(){
List<DevNum> nums=new ArrayList<>(); return ResponseEntity.ok(statisticalService.getDeviceNum());
return ResponseEntity.ok(nums);
} }
/** /**
* 查询各市装备生命状态数量 * 查询全省或各市装备生命状态数量
* @return 各市装备生命状态对象集合 * @return 全省或各市装备生命状态对象集合
*/ */
@GetMapping("/StateofLife") @GetMapping("/StateofLife/{type}")
public ResponseEntity selectStateofLife(){ public ResponseEntity selectStateofLife(@PathVariable Integer type){
List<DevLifeSector> nums=new ArrayList<>(); return ResponseEntity.ok(statisticalService.getLifeStatus(type));
return ResponseEntity.ok(nums);
} }
/** /**
* 查询各市自查情况数量 * 查询当前季度各市自查情况
* @return 各市装备生命状态对象集合 * @return 各市自查状态对象集合
*/ */
@GetMapping("/selfInspection/{type}") @GetMapping("/selfInspection")
public ResponseEntity selectSelfInspection(@PathVariable Integer type){ public ResponseEntity selectSelfInspection(){
List<SelfInspection> nums=new ArrayList<>(); return ResponseEntity.ok(statisticalService.getSelfCheck());
return ResponseEntity.ok(nums); }
/**
* 查询年度各季度各市自查情况
* @return 各市自查状态对象集合
*/
@GetMapping("/selfInspection/year")
public ResponseEntity selectYearSelfInspection(){
return ResponseEntity.ok(statisticalService.getYearSelfCheck());
} }
/** /**
* 查询各市核查情况数量 * 查询各市核查情况数量
* @return 各市装备生命状态对象集合 * @return 各市核查状态对象集合
*/ */
@GetMapping("/selfInspection/{type}") @GetMapping("/confirmInspection/{type}")
public ResponseEntity selectVerification(@PathVariable Integer type){ public ResponseEntity selectVerification(@PathVariable Integer type){
List<Verification> nums=new ArrayList<>(); List<Verification> nums=new ArrayList<>();
return ResponseEntity.ok(nums); return ResponseEntity.ok(nums);
......
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 java.util.List;
/**
* @author dengdiyi
*/
public interface StatisticalService {
/**
* 获取装备统计信息
*/
List<DevNum> getDeviceNum();
/**
* @param type 类型(1:省,2:市)
* 获取装备生命状态统计信息
*/
List<DevLifeSector> getLifeStatus(Integer type);
/**
* 获取季度自查统计信息
*/
List<SelfInspection> getSelfCheck();
/**
* 获取年度自查统计信息
*/
List<YearSelfInspection> getYearSelfCheck();
}
package com.tykj.dev.statistical.service.impl;
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.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.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.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author dengdiyi
*/
@Service
public class StatisticalServiceImpl implements StatisticalService {
@Autowired
private DeviceLibraryDao deviceLibraryDao;
@Autowired
private AreaDao areaDao;
@Autowired
private UnitsDao unitsDao;
@Autowired
private SelfCheckBillDao selfCheckBillDao;
/**
* 获取装备统计信息
*/
@Override
public List<DevNum> getDeviceNum() {
List<DevNum> nums=new ArrayList<>();
//获取所有装备
List<DeviceLibrary> deviceLibraries = deviceLibraryDao.findAll();
//获取所有市
List<Area> areas = areaDao.findAreasByType(2);
//获取所有单位
List<Units> units = unitsDao.findAll();
//统计各市装备数量
areas.forEach(area -> {
DevNum devNum = new DevNum();
devNum.setAreaName(area.getName());
//获取市以及子区县所有区域id
List<Integer> areaIds = areaDao.findAllByFatherId(area.getId()).stream()
.map(Area::getId)
.collect(Collectors.toList());
areaIds.add(area.getId());
//根据区域id找单位id集合
List<String> names = units.stream()
.filter(units1 -> areaIds.contains(units1.getAreaId()))
.map(Units::getName)
.collect(Collectors.toList());
//筛选出所属单位在id集合中的装备
List<DeviceLibrary> deviceLibraryList = deviceLibraries.stream()
.filter(deviceLibrary -> names.contains(deviceLibrary.getOwnUnit()))
.collect(Collectors.toList());
//获取装备总数量
devNum.setCount(deviceLibraryList.size());
nums.add(devNum);
});
return nums;
}
/**
* @param type 类型(1:省,2:市)
* 获取装备生命状态统计信息
*/
@Override
public List<DevLifeSector> getLifeStatus(Integer type) {
List<DevLifeSector> nums=new ArrayList<>();
//获取所有装备
List<DeviceLibrary> deviceLibraries = deviceLibraryDao.findAll();
//省
if (type==1){
DevLifeSector devLifeSector = new DevLifeSector();
//获取省区域名
List<Area> areas = areaDao.findAreasByType(1);
if (areas.size()==1){
devLifeSector.setAreaName(areas.get(0).getName());
countDevice(devLifeSector,deviceLibraries);
nums.add(devLifeSector);
}
return nums;
}
//市
else if (type==2){
List<Area> areas = areaDao.findAreasByType(2);
//每个市进行统计
for (Area area: areas) {
DevLifeSector devLifeSector = new DevLifeSector();
devLifeSector.setAreaName(area.getName());
//获取市以及子区县所有区域
List<Area> areas1 = areaDao.findAllByFatherId(area.getId());
areas1.add(area);
//获取所有单位名称
List<String> unitNames = new ArrayList<>();
areas1.forEach(area1 -> {
List<Units> units = unitsDao.findAllByAreaId(area1.getId());
if (units.size()==1){
unitNames.add(units.get(0).getName());
}
});
//筛选出当前区域单位装备
List<DeviceLibrary> deviceLibraries1 = deviceLibraries.stream()
.filter(deviceLibrary -> unitNames.contains(deviceLibrary.getOwnUnit()))
.collect(Collectors.toList());
countDevice(devLifeSector,deviceLibraries1);
nums.add(devLifeSector);
}
return nums;
}
else {
throw new ApiException(ResponseEntity.ok("type只能为1,2"));
}
}
/**
* 获取季度自查统计信息
*/
@Override
public List<SelfInspection> getSelfCheck() {
List<SelfInspection> nums=new ArrayList<>();
//获取所有自查单
List<SelfCheckBill> selfCheckBills = selfCheckBillDao.findAll();
//获取所有市
List<Area> areas = areaDao.findAreasByType(2);
//遍历每个市
for (Area area:areas) {
//获取当前区域所有区县
List<Area> sonAreas = areaDao.findAllByFatherId(area.getId());
SelfInspection selfInspection = new SelfInspection();
selfInspection.setAreaName(area.getName());
//计算当前季度
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
String quarter = calendar.get(Calendar.YEAR)+"年"+SelfCheckSchedulerTask.getQuarter(calendar.get(Calendar.MONTH)+1);
//获取未完成区县
List<Area> areas1 = getSelfCheckUndoAreas(area.getId(),quarter,selfCheckBills);
//set未完成数量
selfInspection.setNoCompleteCount(areas1.size());
//set已完成数量
selfInspection.setCompleteCount(sonAreas.size()-areas1.size());
nums.add(selfInspection);
}
return nums;
}
/**
* 获取年度自查统计信息
*/
@Override
public List<YearSelfInspection> getYearSelfCheck() {
List<YearSelfInspection> yearSelfInspections = new ArrayList<>();
//获取所有自查单
List<SelfCheckBill> selfCheckBills = selfCheckBillDao.findAll();
//获取所有市
List<Area> areas = areaDao.findAreasByType(2);
//判断当前季度
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
String quarter1 = calendar.get(Calendar.YEAR)+"年第一季度";
String quarter2 = calendar.get(Calendar.YEAR)+"年第二季度";
String quarter3 = calendar.get(Calendar.YEAR)+"年第三季度";
String quarter4 = calendar.get(Calendar.YEAR)+"年第四季度";
//遍历所有市
areas.forEach(area -> {
YearSelfInspection yearSelfInspection = new YearSelfInspection();
PerQuarter firstQuarter = new PerQuarter();
PerQuarter secondQuarter = new PerQuarter();
PerQuarter thirdQuarter = new PerQuarter();
PerQuarter fourthQuarter = new PerQuarter();
yearSelfInspection.setAreaName(area.getName());
List<Area> undoAreas = getSelfCheckUndoAreas(area.getId(),quarter1,selfCheckBills);
List<Area> undoAreas2 = getSelfCheckUndoAreas(area.getId(),quarter2,selfCheckBills);
List<Area> undoAreas3 = getSelfCheckUndoAreas(area.getId(),quarter3,selfCheckBills);
List<Area> undoAreas4 = getSelfCheckUndoAreas(area.getId(),quarter4,selfCheckBills);
//获取当前区域所有区县
List<Area> sonAreas = areaDao.findAllByFatherId(area.getId());
if (!undoAreas.isEmpty()) {
setPerQuarter(firstQuarter, sonAreas, undoAreas);
}
if (!undoAreas2.isEmpty()) {
setPerQuarter(secondQuarter, sonAreas, undoAreas2);
}
if (!undoAreas3.isEmpty()) {
setPerQuarter(thirdQuarter, sonAreas, undoAreas3);
}
if (!undoAreas4.isEmpty()) {
setPerQuarter(fourthQuarter, sonAreas, undoAreas4);
}
yearSelfInspection.setFirstQuarter(firstQuarter);
yearSelfInspection.setSecondQuarter(secondQuarter);
yearSelfInspection.setThirdQuarter(thirdQuarter);
yearSelfInspection.setFourthQuarter(fourthQuarter);
yearSelfInspections.add(yearSelfInspection);
});
return yearSelfInspections;
}
/**
* @param devLifeSector 装备生命状态添统计
* @param deviceLibraries 统计装备
* 计算并set devLifeSector中各种生命状态装备数量
*/
private void countDevice(DevLifeSector devLifeSector,List<DeviceLibrary> deviceLibraries){
int inLibrary = 0;
int destroy = 0;
int retired = 0;
int use = 0;
int scrap = 0;
int repair = 0;
int transport = 0;
for (DeviceLibrary d:deviceLibraries) {
switch (d.getLifeStatus()){
case 2:
inLibrary++;
break;
case 3:
transport++;
break;
case 4:
repair++;
break;
case 5:
scrap++;
break;
case 10:
destroy++;
break;
case 12:
retired++;
break;
case 13:
scrap++;
break;
case 14:
use++;
break;
default:break;
}
}
devLifeSector.setDestructionCount(destroy);
devLifeSector.setInStock(inLibrary);
devLifeSector.setLockCount(transport);
devLifeSector.setMaintenanceCount(repair);
devLifeSector.setRetiredCount(retired);
devLifeSector.setScrapCount(scrap);
devLifeSector.setUseCount(use);
}
/**
* @param areaId 市区域id
* @param quarter 季度(例如:2020年第一季度,2020年第二季度,2020年第三季度,2020年第四季度)
* @param selfCheckBills 自查单
* @return 未完成区域
* 计算并返回某季度某区域未完成区县
*/
private List<Area> getSelfCheckUndoAreas(int areaId,String quarter,List<SelfCheckBill> selfCheckBills){
//获取所有区县
List<Area> sonAreas = areaDao.findAllByFatherId(areaId);
//未完成区域
List<Area> undoAreas = new ArrayList<>();
//遍历区县
sonAreas.forEach(area -> {
//获取区域对应单位
List<Units> units = unitsDao.findAllByAreaId(area.getId());
if (units.size()==1){
//筛选出标题包含当前年份季度的
List<SelfCheckBill> selfCheckBillList = selfCheckBills.stream()
.filter(selfCheckBill -> selfCheckBill.getTitle().contains(quarter)&&selfCheckBill.getCheckUnit().equals(units.get(0).getName()))
.collect(Collectors.toList());
if(selfCheckBillList.size()==1){
SelfCheckBill selfCheckBill = selfCheckBillList.get(0);
//如果未完成
if (selfCheckBill.getCheckStatus()!=2){
undoAreas.add(area);
}
}
}
});
return undoAreas;
}
/**
* @param perQuarter 被set的对象
* @param sonAreas 子区县
* @param undoAreas 未完成自查区县
*/
private void setPerQuarter(PerQuarter perQuarter,List<Area> sonAreas,List<Area> undoAreas){
perQuarter.setNoCompleteUnits(undoAreas.stream().map(Area::getName).collect(Collectors.toList()));
perQuarter.setNoCompleteCount(undoAreas.size());
perQuarter.setCompleteCount(sonAreas.size()-undoAreas.size());
}
}
package com.tykj.dev.statistical;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author zjm
* @version 1.0.0
* @ClassName userApp.java
* @Description TODO
* @createTime 2020年09月01日 14:32:00
*/
@SpringBootApplication(scanBasePackages = {
"com.tykj.dev.*",
}
)
public class statisticalApp {
public static void main(String[] args) {
SpringApplication.run(statisticalApp.class, args);
}
}
package com.tykj.dev.statistical.vo; package com.tykj.dev.statistical.vo;
import lombok.Data;
/** /**
* @author zjm * @author zjm
* @version 1.0.0 * @version 1.0.0
...@@ -7,6 +9,7 @@ package com.tykj.dev.statistical.vo; ...@@ -7,6 +9,7 @@ package com.tykj.dev.statistical.vo;
* @Description 各市扇形生命状态统计 * @Description 各市扇形生命状态统计
* @createTime 2020年10月16日 09:55:00 * @createTime 2020年10月16日 09:55:00
*/ */
@Data
public class DevLifeSector { public class DevLifeSector {
/** /**
* 市名称 * 市名称
...@@ -21,7 +24,7 @@ public class DevLifeSector { ...@@ -21,7 +24,7 @@ public class DevLifeSector {
/** /**
* 维修数量 * 维修数量
*/ */
private Integer maintenanceConut; private Integer maintenanceCount;
/** /**
* 报废数量 * 报废数量
......
package com.tykj.dev.statistical.vo; package com.tykj.dev.statistical.vo;
import lombok.Data;
/** /**
* @author zjm * @author zjm
* @version 1.0.0 * @version 1.0.0
...@@ -7,6 +9,7 @@ package com.tykj.dev.statistical.vo; ...@@ -7,6 +9,7 @@ package com.tykj.dev.statistical.vo;
* @Description 统计分析 市级 本市装备数量 * @Description 统计分析 市级 本市装备数量
* @createTime 2020年10月15日 10:35:00 * @createTime 2020年10月15日 10:35:00
*/ */
@Data
public class DevNum { public class DevNum {
/** /**
* 区域名称 * 区域名称
...@@ -16,6 +19,6 @@ public class DevNum { ...@@ -16,6 +19,6 @@ public class DevNum {
/** /**
* 区域装备总数 * 区域装备总数
*/ */
private Integer conut; private Integer count;
} }
package com.tykj.dev.statistical.vo;
import lombok.Data;
import java.util.List;
/**
* @author dengdiyi
* 年度中每季度自查统计
*/
@Data
public class PerQuarter {
/**
* 完成数量
*/
private Integer completeCount;
/**
* 未完成数量
*/
private Integer noCompleteCount;
/**
* 未完成单位
*/
private List<String> noCompleteUnits;
}
package com.tykj.dev.statistical.vo; package com.tykj.dev.statistical.vo;
import lombok.Data;
/** /**
* @author zjm * @author zjm
* @version 1.0.0 * @version 1.0.0
...@@ -7,6 +9,7 @@ package com.tykj.dev.statistical.vo; ...@@ -7,6 +9,7 @@ package com.tykj.dev.statistical.vo;
* @Description 自查各市完成情况 * @Description 自查各市完成情况
* @createTime 2020年10月16日 10:30:00 * @createTime 2020年10月16日 10:30:00
*/ */
@Data
public class SelfInspection { public class SelfInspection {
/** /**
* 市 名称 * 市 名称
......
package com.tykj.dev.statistical.vo;
import lombok.Data;
/**
* @author dengdiyi
* 年度自查统计详情vo
*/
@Data
public class YearSelfInspection {
/**
* 市 名称
*/
private String areaName;
/**
* 第一季度统计
*/
private PerQuarter firstQuarter;
/**
* 第二季度统计
*/
private PerQuarter secondQuarter;
/**
* 第三季度统计
*/
private PerQuarter thirdQuarter;
/**
* 第四季度统计
*/
private PerQuarter fourthQuarter;
}
...@@ -358,6 +358,17 @@ ...@@ -358,6 +358,17 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>com.tykj</groupId>
<artifactId>dev-statistical</artifactId>
<version>1.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>com.tykj.dev</groupId>
<artifactId>union</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Spring Security Test --> <!-- Spring Security Test -->
<dependency> <dependency>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论