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

[统计分析]增加了首页自查、核查数量统计

上级 45f55d18
package com.tykj.dev.device.confirmcheck.entity.cache;
import com.tykj.dev.device.user.cache.UnitsCache;
import com.tykj.dev.device.user.cache.UserCache;
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.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -17,8 +21,24 @@ public class CacheBeanConfig {
@Autowired
private AreaDao areaRepo;
@Autowired
private UserDao userDao;
@Autowired
private UnitsDao unitsDao;
@Bean
public AreaCache initAreaCache() {
return new AreaCache(areaRepo.findAll());
}
@Bean
public UserCache initUserCache() {
return new UserCache(userDao.findAll());
}
@Bean
public UnitsCache initUnitCache() {
return new UnitsCache(unitsDao.findAll());
}
}
package com.tykj.dev.misc.utils;
import com.tykj.dev.misc.exception.ApiException;
import java.util.ArrayList;
import java.util.List;
/**
* @author dengdiyi
* 装备序列号生成工具类
*/
public class DeviceSeqUtil {
/**
* @param num 入库数量
* @param s 序列号区间字符串
* @return 生成的序列号列表
* 根据序列号规则和区间字符串按顺序生成一段序列号
*/
public static List<String> createDeviceSeqs(String s,Integer num){
List<String> seqs = new ArrayList<>();
if (s!=null&&s.length()>0) {
//按,分隔多个区间
String[] strings = s.split(",");
if (strings.length==1){
String num1 = strings[0].replaceAll(".*[^\\d](?=(\\d+))", "");
int minSeq = Integer.parseInt(num1);
for (int i =0;i<num;i++){
StringBuffer stringBuffer = new StringBuffer();
//拼接数字之前的字符串
stringBuffer.append(s, 0, s.length()-num1.length());
//将数字按长度格式化,缺位补0
String codeFormat = "%0"+ num1.length() +"d";
stringBuffer.append(String.format(codeFormat,minSeq));
seqs.add(stringBuffer.toString());
minSeq++;
}
}
else {
for (String str : strings) {
if (str.length() > 0) {
if (isSingle(str)) {
seqs.add(str);
} else {
seqs.addAll(getIntervalSeqs(str));
}
}
}
}
}
return seqs;
}
/**
* @param s 区间字符串
* 判断是单个序列号还是序列号区间,若是单个序列号返回true,否则返回false
*/
private static boolean isSingle(String s){
return !s.contains("-");
}
/**
* @param s 区间字符串
* 根据区间字符串获取该区间序列号列表
*/
private static List<String> getIntervalSeqs(String s){
List<String> stringList = new ArrayList<>();
//根据-分隔
String[] strings = s.split("-");
if(strings.length==2){
//左区间字符串
String s1 = strings[0];
//右区间字符串
String s2 = strings[1];
if (s1.length()!=s2.length()){
throw new ApiException("序列号区间前面字符位数不相同");
}
else {
//获得左区间最后几位的数字
String num1 = s1.replaceAll(".*[^\\d](?=(\\d+))", "");
//获得右区间最后几位的数字
String num2 = s2.replaceAll(".*[^\\d](?=(\\d+))", "");
if (num1.length() != num2.length()){
throw new ApiException("序列号区间后面数字位数不相同");
}
else {
int minSeq = Integer.parseInt(num1);
int maxSeq = Integer.parseInt(num2);
if (maxSeq<minSeq){
throw new ApiException("前区间数字大于后区间");
}
else {
while (minSeq<=maxSeq){
StringBuffer stringBuffer = new StringBuffer();
//拼接数字之前的字符串
stringBuffer.append(s1, 0, s1.length()-num1.length());
//将数字按长度格式化,缺位补0
String codeFormat = "%0"+ num1.length() +"d";
stringBuffer.append(String.format(codeFormat,minSeq));
stringList.add(stringBuffer.toString());
minSeq++;
}
}
}
}
}
else {
throw new ApiException("序列号区间包含多个-");
}
return stringList;
}
}
......@@ -44,6 +44,10 @@
<groupId>com.tykj</groupId>
<artifactId>dev-finalcheck</artifactId>
</dependency>
<dependency>
<groupId>com.tykj</groupId>
<artifactId>dev-confirmcheck</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -133,4 +133,14 @@ public class StatisticalController {
public ResponseEntity selectBusinessSituation(@PathVariable Integer type) throws ParseException {
return ResponseEntity.ok(statisticalService.getBusinessNum(type));
}
/**
* 查询各市最近一次自查核查数量
* @return 各市自查核查数量对象集合
*/
@ApiOperation(value = "查询各市最近一次自查核查数量")
@GetMapping("/checkNum")
public ResponseEntity selectCheckNum(){
return ResponseEntity.ok(statisticalService.getCheckNum());
}
}
......@@ -46,4 +46,9 @@ public interface StatisticalService {
* 获取本季度各市告警统计信息
*/
List<AlarmSituation> getRfidWarningDetail();
/**
* 获取各市最近一次自查和核查装备数量
*/
List<Check> getCheckNum();
}
package com.tykj.dev.statistical.service.impl;
import com.tykj.dev.device.confirmcheck.entity.cache.AreaCache;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckDetail;
import com.tykj.dev.device.confirmcheck.repository.DeviceCheckDetailDao;
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;
......@@ -13,6 +16,8 @@ import com.tykj.dev.device.task.subject.bto.TaskBto;
import com.tykj.dev.device.task.subject.domin.Task;
import com.tykj.dev.device.task.subject.vo.TaskSelectVo;
import com.tykj.dev.device.task.subject.vo.TaskUserVo;
import com.tykj.dev.device.user.cache.UnitsCache;
import com.tykj.dev.device.user.cache.UserCache;
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;
......@@ -56,6 +61,15 @@ public class StatisticalServiceImpl implements StatisticalService {
@Autowired
private TaskService taskService;
@Autowired
private UnitsCache unitsCache;
@Autowired
private AreaCache areaCache;
@Autowired
private DeviceCheckDetailDao deviceCheckDetailDao;
/**
* 获取装备统计信息
*/
......@@ -67,7 +81,7 @@ public class StatisticalServiceImpl implements StatisticalService {
//获取所有市
List<Area> areas = areaDao.findAreasByType(2);
//获取所有单位
List<Units> units = unitsDao.findAll();
List<Units> units = unitsCache.findAll();
//统计各市装备数量
areas.forEach(area -> {
DevNum devNum = new DevNum();
......@@ -343,6 +357,47 @@ public class StatisticalServiceImpl implements StatisticalService {
return alarmSituations;
}
/**
* 获取各市最近一次自查和核查装备数量
*/
@Override
public List<Check> getCheckNum() {
List<Check> checks = new ArrayList<>();
//获取所有自查单
List<SelfCheckBill> selfCheckBills = selfCheckBillDao.findAll();
//获取所有核查单
List<DeviceCheckDetail> deviceCheckDetails = deviceCheckDetailDao.findAll();
//获取所有市
List<Area> areas = areaDao.findAreasByType(2);
//遍历市,找到最近完成的自查和核查账单
for (Area a:areas) {
Check check = new Check();
check.setAreaName(a.getName());
List<Units> units = unitsDao.findAllByAreaId(a.getId());
if (units.size()==1) {
//获取市单位名称
String unitName = unitsDao.findAllByAreaId(a.getId()).get(0).getName();
//筛选出当前单位已完成的自查和核查账单,按更新时间排序
List<SelfCheckBill> selfCheckBillList = selfCheckBills.stream()
.filter(selfCheckBill -> selfCheckBill.getCheckUnit().equals(unitName) && selfCheckBill.getCheckedCount() != null)
.sorted(Comparator.comparing(SelfCheckBill::getUpdateTime).reversed())
.collect(Collectors.toList());
List<DeviceCheckDetail> deviceCheckDetailList = deviceCheckDetails.stream()
.filter(deviceCheckDetail -> deviceCheckDetail.getCheckUnit().equals(unitName) && deviceCheckDetail.getCheckedCount() != null)
.sorted(Comparator.comparing(DeviceCheckDetail::getUpdateTime).reversed())
.collect(Collectors.toList());
if (!selfCheckBillList.isEmpty()) {
check.setSelfCheckCount(selfCheckBillList.get(0).getCheckedCount());
}
if (!deviceCheckDetailList.isEmpty()) {
check.setConfirmCheckCount(deviceCheckDetailList.get(0).getCheckedCount());
}
}
checks.add(check);
}
return checks;
}
/**
* @param devLifeSector 装备生命状态添统计
* @param deviceLibraries 统计装备
......
package com.tykj.dev.statistical.vo;
import lombok.Data;
/**
* @author dengdiyi
* 区域最近一次自查和核查数量统计
*/
@Data
public class Check {
/**
* 市 名称
*/
private String areaName;
/**
* 自查数量
*/
private Integer selfCheckCount = 0;
/**
* 核查数量
*/
private Integer confirmCheckCount = 0;
}
......@@ -22,6 +22,7 @@ import com.tykj.dev.device.user.subject.service.UserPublicService;
import com.tykj.dev.device.user.util.UserUtils;
import com.tykj.dev.misc.base.BusinessEnum;
import com.tykj.dev.misc.base.StatusEnum;
import com.tykj.dev.misc.utils.DeviceSeqUtil;
import com.tykj.dev.misc.utils.ResultUtil;
import com.tykj.dev.misc.utils.StringSplitUtil;
import com.tykj.dev.socket.MyWebSocket;
......@@ -72,6 +73,12 @@ public class StorageBillController {
@Autowired
private MyWebSocket myWebSocket;
@ApiOperation(value = "获取序列号区间列表", notes = "可以通过这个接口获取序列号区间列表")
@GetMapping(value = "/getSeq/{num}/{string}")
public ResponseEntity getSeq(@PathVariable("string") String s,@PathVariable("num") Integer num){
return ResultUtil.success(DeviceSeqUtil.createDeviceSeqs(s,num));
}
@ApiOperation(value = "选择入库型号数量", notes = "可以通过这个接口选择入库型号数量")
@PostMapping(value = "/addStorageDetail")
public ResponseEntity addStorageDetail(@RequestBody List<StorageBillDetailVo> list) {
......
......@@ -13,6 +13,8 @@ import com.tykj.dev.device.task.subject.domin.TaskLog;
import com.tykj.dev.device.task.subject.vo.TaskSelectVo;
import com.tykj.dev.device.task.subject.vo.TaskUserVo;
import com.tykj.dev.device.task.utils.TaskUtils;
import com.tykj.dev.device.user.cache.UnitsCache;
import com.tykj.dev.device.user.cache.UserCache;
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.UserUtils;
......@@ -51,6 +53,12 @@ public class TaskServiceImpl implements TaskService {
@Autowired
private TaskLogDao taskLogDao;
@Autowired
private UserCache userCache;
@Autowired
private UnitsCache unitsCache;
/**
* <p>业务进行到下一个状态</p>
* <li>不指定待办用户</li>
......@@ -378,12 +386,12 @@ public class TaskServiceImpl implements TaskService {
Integer userId3 = userIds.get(taskUserVo.getCurrentPoint());
//当前指针userId大于0,待办人即当前id
if (userId3>0) {
taskUserVo.setProcessingUser(userPublicService.getOne(userId3).getName());
taskUserVo.setProcessingUser(userCache.findById(userId3).getName());
}
//当前指针userId等于0,待办人为所属单位下所有用户
else if (userId3==0&&taskUserVo.getOwnUnit()!=null){
StringBuffer stringBuffer = new StringBuffer();
List<User> users = userPublicService.getAllUser();
List<User> users = userCache.findAll();
users.stream().filter(user -> user.getUnitsId().equals(taskUserVo.getOwnUnit())).forEach(user -> {
stringBuffer.append(user.getName()).append(",");
});
......@@ -405,7 +413,7 @@ public class TaskServiceImpl implements TaskService {
}
}
//判断是否需要按发起时间排序
if (taskSelectVo.getOrders() != null) {
if (!taskSelectVo.getOrders().isEmpty()) {
if ("createTime".equals(taskSelectVo.getOrders().get(0).getCoulmn())) {
if ("ASC".equals(taskSelectVo.getOrders().get(0).getDirection().toString())) {
return taskUtils.orderByCreateTimeAsc2(taskUserVos);
......@@ -622,12 +630,12 @@ public class TaskServiceImpl implements TaskService {
Integer userId3 = userIds.get(taskUserVo.getCurrentPoint());
//当前指针userId大于0,待办人即当前id
if (userId3>0) {
taskUserVo.setProcessingUser(userPublicService.getOne(userId3).getName());
taskUserVo.setProcessingUser(userCache.findById(userId3).getName());
}
//当前指针userId等于0,待办人为所属单位下所有用户
else if (userId3==0&&taskUserVo.getOwnUnit()!=null){
StringBuffer stringBuffer = new StringBuffer();
List<User> users = userPublicService.getAllUser();
List<User> users = userCache.findAll();
users.stream().filter(user -> user.getUnitsId().equals(taskUserVo.getOwnUnit())).forEach(user -> {
stringBuffer.append(user.getName()).append(",");
});
......
package com.tykj.dev.device.user.cache;
import com.tykj.dev.device.user.subject.entity.Units;
import com.tykj.dev.device.user.subject.entity.User;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
public class UnitsCache {
private Map<Integer, Units> idMap;
public UnitsCache(List<Units> unitsList){
this.idMap = unitsList.stream().collect(Collectors.toMap(Units::getUnitId, Function.identity()));
}
public Map<Integer, Units> getIdMap() {
return idMap;
}
public Units findById(Integer id) {
return idMap.get(id);
}
public List<Units> findAll(){
return new ArrayList<>(idMap.values());
}
}
package com.tykj.dev.device.user.cache;
import com.tykj.dev.device.user.subject.entity.User;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
public class UserCache {
private Map<Integer, User> idMap;
public UserCache(List<User> userList){
this.idMap = userList.stream().collect(Collectors.toMap(User::getUserId, Function.identity()));
}
public User findById(Integer id) {
return idMap.get(id);
}
public Map<Integer, User> getIdMap() {
return idMap;
}
public List<User> findAll(){
return new ArrayList<>(idMap.values());
}
}
package com.tykj.dev.device.user.subject.service.impl;
import com.tykj.dev.device.user.cache.UnitsCache;
import com.tykj.dev.device.user.cache.UserCache;
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.dao.UserDao;
......@@ -33,6 +35,12 @@ public class UserPublicServiceImpl implements UserPublicService {
@Autowired
AreaDao areaDao;
@Autowired
UserCache userCache;
@Autowired
UnitsCache unitsCache;
@Override
public List<String> findByUnitNameDown(String unitName) {
Units units = unitsDao.findByName(unitName);
......@@ -71,11 +79,8 @@ public class UserPublicServiceImpl implements UserPublicService {
@Override
public String findUnitsNameByUserId(Integer userId) {
Optional<User> resultEntity = userDao.findById(userId);
if (resultEntity.isPresent()) {
return unitsDao.findById(resultEntity.get().getUnitsId()).get().getName();
}
return null;
User resultEntity = userCache.findById(userId);
return unitsCache.findById(resultEntity.getUnitsId()).getName();
}
@Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论