Browse Source

修改数据统计

wyyay 2 years atrás
parent
commit
9c6a7c908e

+ 240 - 0
vehicle-admin/src/main/java/com/ozs/web/controller/accountmanagment/DataStatisticController.java

@@ -0,0 +1,240 @@
+package com.ozs.web.controller.accountmanagment;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.ozs.common.annotation.Log;
+import com.ozs.common.core.controller.BaseController;
+import com.ozs.common.core.domain.AjaxResult;
+import com.ozs.common.core.domain.entity.SysUser;
+import com.ozs.common.enums.BusinessType;
+import com.ozs.common.utils.AppendUtils;
+import com.ozs.common.utils.StringUtils;
+import com.ozs.common.utils.poi.ExcelUtil;
+import com.ozs.entity.BaseUser;
+import com.ozs.entity.vo.AlarmStatisticDto;
+import com.ozs.entity.vo.AlarmStatisticMonthDto;
+import com.ozs.entity.vo.AlarmStatisticResVo;
+import com.ozs.entity.vo.AlarmStatisticVo;
+import com.ozs.service.BaseUserService;
+import com.ozs.service.MsgAlarmService;
+import com.ozs.system.service.ISysDictDataService;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.ObjectUtils;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import java.util.*;
+
+/**
+ * @author wyy
+ * @subject
+ * @creat 2023/4/13
+ */
+@RestController
+@RequestMapping("/service/dataStatistic")
+public class DataStatisticController extends BaseController {
+    private static final Logger log = LoggerFactory.getLogger(DataStatisticController.class);
+    @Resource
+    MsgAlarmService msgAlarmService;
+    @Resource
+    private BaseUserService baseUserService;
+    @Autowired
+    private ISysDictDataService dictDataService;
+    /**
+     * web数据统计
+     *
+     * @param alarmStatisticResVo
+     * @return
+     */
+    @Log(title = "报警信息管理", businessType = BusinessType.OTHER)
+    @PostMapping("/dataStatistic")
+    @ApiOperation(value = "web数据统计 报警数据详情")
+    @ApiImplicitParams(value = {
+            @ApiImplicitParam(paramType = "query", name = "railwayCode", value = "线路编码"),
+            @ApiImplicitParam(paramType = "query", name = "currentYear", value = "当前年份"),
+            @ApiImplicitParam(paramType = "query", name = "currentMonth", value = "当前月份"),
+            @ApiImplicitParam(paramType = "query", name = "alarmType", value = "灾害类型"),
+    })
+    public AjaxResult dataStatistic(@RequestBody AlarmStatisticResVo alarmStatisticResVo) {
+        Integer pageNum = alarmStatisticResVo.getPageNum().intValue();
+        Integer pageSize = alarmStatisticResVo.getPageSize().intValue();
+        List<AlarmStatisticDto> list = msgAlarmService.list(alarmStatisticResVo.getRailwayCode(), alarmStatisticResVo.getCurrentYear(),
+                alarmStatisticResVo.getCurrentMonth(), pageNum, pageSize);
+        if (!ObjectUtils.isEmpty(list)) {
+            list.forEach(l -> {
+                if (!ObjectUtils.isEmpty(l.getAlarmMile())) {
+                    l.setAlarmMiles(AppendUtils.stringAppend(Integer.valueOf(l.getAlarmMile())));
+                }
+                if (StringUtils.isNotEmpty(l.getReleasedBy())) {
+                    BaseUser buser = baseUserService.getUser(l.getReleasedBy());
+                    l.setReleasedByName(buser.getNickName());
+                }
+
+                if (!ObjectUtils.isEmpty(l.getLineDir())) {
+                    l.setLineDirName(l.getLineDir() == 1 ? "上行" : "下行");
+                }
+                if (!ObjectUtils.isEmpty(l.getAlarmType())) {
+                    l.setAlarmTypeName(dictDataService.selectDictLabel("sys_alarm_type", String.valueOf(l.getAlarmType())));
+                }
+                if (!ObjectUtils.isEmpty(l.getIsRelease())) {
+                    l.setIsReleaseName(l.getIsRelease() == 1 ? "已解除" : "未解除");
+                }
+            });
+        }
+        IPage page = msgAlarmService.listToPage(list, pageNum, pageSize);
+        return AjaxResult.success(page);
+    }
+
+    /**
+     * web数据统计
+     *
+     * @param
+     * @return
+     */
+    @Log(title = "报警信息管理", businessType = BusinessType.OTHER)
+    @PostMapping("/alarmMonthStatistic")
+    @ApiOperation(value = "web数据统计 报警月统计数据")
+    @ApiImplicitParams(value = {
+            @ApiImplicitParam(paramType = "query", name = "railwayCode", value = "线路编码"),
+            @ApiImplicitParam(paramType = "query", name = "currentYear", value = "当前年份"),
+            @ApiImplicitParam(paramType = "query", name = "currentMonth", value = "当前月份"),
+            @ApiImplicitParam(paramType = "query", name = "alarmType", value = "灾害类型"),
+    })
+    public AjaxResult alarmMonthStatistic(@RequestBody AlarmStatisticResVo alarmStatisticResVo) {
+        List<Integer> numbs = new ArrayList<>();
+        Integer listSize;
+        List<AlarmStatisticMonthDto> list = null;
+        if (ObjectUtils.isEmpty(alarmStatisticResVo.getCurrentMonth())) {
+            list = msgAlarmService.getCount(alarmStatisticResVo.getRailwayCode(), alarmStatisticResVo.getCurrentYear(),
+                    alarmStatisticResVo.getCurrentMonth());
+            listSize = 12;
+        } else {
+            if (alarmStatisticResVo.getCurrentMonth().equals(2)) {//2
+                listSize = 28;
+            } else if (alarmStatisticResVo.getCurrentMonth().equals(4) || alarmStatisticResVo.getCurrentMonth().equals(6) ||
+                    alarmStatisticResVo.getCurrentMonth().equals(9) || alarmStatisticResVo.getCurrentMonth().equals(11)) {//4,6,9,11
+                listSize = 30;
+            } else {//1,3,5,7,8,10,12
+                listSize = 31;
+            }
+            list = msgAlarmService.getDayCount(alarmStatisticResVo.getRailwayCode(), alarmStatisticResVo.getCurrentYear(),
+                    alarmStatisticResVo.getCurrentMonth());
+        }
+        for (int i = 1; i <= listSize; i++) {
+            numbs.add(i);
+        }
+
+        List<Integer> list1 = new ArrayList<>();
+        if (!CollectionUtils.isEmpty(list) && Objects.nonNull(list.get(0))) {
+            list.forEach(l -> {
+                list1.add(l.getMonthsta());
+            });
+        }
+        AlarmStatisticMonthDto dto;
+        for (int i = 0; i < numbs.size(); i++) {
+            if (!list1.contains(numbs.get(i))) {
+                dto = new AlarmStatisticMonthDto();
+                dto.setMonthsta(numbs.get(i));
+                dto.setFrequency(0);
+                list.add(dto);
+            }
+        }
+        if (!CollectionUtils.isEmpty(list) && Objects.nonNull(list.get(0))) {
+            Collections.sort(list, new Comparator<AlarmStatisticMonthDto>() {
+                @Override
+                public int compare(AlarmStatisticMonthDto o1, AlarmStatisticMonthDto o2) {
+
+                    return o1.getMonthsta().compareTo(o2.getMonthsta());
+                }
+            });
+        }
+        return AjaxResult.success(list);
+    }
+
+
+    /**
+     * web数据统计 数据导出
+     *
+     * @param
+     * @return
+     */
+    @Log(title = "报警信息管理", businessType = BusinessType.EXPORT)
+    @PostMapping("/exportDataStatistic")
+    @ApiOperation(value = "web数据统计-数据导出")
+    @ApiImplicitParams(value = {
+            @ApiImplicitParam(paramType = "query", name = "railwayCode", value = "线路编码"),
+            @ApiImplicitParam(paramType = "query", name = "currentYear", value = "当前年份"),
+            @ApiImplicitParam(paramType = "query", name = "currentMonth", value = "当前月份"),
+            @ApiImplicitParam(paramType = "query", name = "alarmType", value = "灾害类型"),
+    })
+    public void exportDataStatistic(HttpServletResponse response, @RequestBody AlarmStatisticResVo alarmStatisticResVo) {
+        try {
+            List<AlarmStatisticDto> list = msgAlarmService.exportExcel(alarmStatisticResVo);
+            if (!CollectionUtils.isEmpty(list) && Objects.nonNull(list.get(0))) {
+                list.forEach(l -> {
+                    if (!ObjectUtils.isEmpty(l.getAlarmMile())) {
+                        l.setAlarmMiles(AppendUtils.stringAppend(Integer.valueOf(l.getAlarmMile())));
+                    }
+                    if (StringUtils.isNotEmpty(l.getReleasedBy())) {
+                        BaseUser buser = baseUserService.getUser(l.getReleasedBy());
+                        l.setReleasedByName(buser.getNickName());
+                    }
+                    if (!ObjectUtils.isEmpty(l.getAlarmType())) {
+                        String alarmType = l.getAlarmType();
+                        String alarmTypeName = dictDataService.selectDictLabel("sys_alarm_type", alarmType);
+                        l.setAlarmTypeName(alarmTypeName);
+                    }
+                    if (!ObjectUtils.isEmpty(l.getLineDir())) {
+                        l.setLineDirName(l.getLineDir() == 1 ? "上行" : "下行");
+                    }
+                    if (!ObjectUtils.isEmpty(l.getIsRelease())) {
+                        l.setIsReleaseName(l.getIsRelease() == 1 ? "已解除" : "未解除");
+                    }
+                });
+            }
+
+            ExcelUtil<AlarmStatisticDto> util = new ExcelUtil<>(AlarmStatisticDto.class);
+            util.exportExcel(response, list, "报警数据详情");
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.info(e.getMessage());
+        }
+    }
+
+    /**
+     * web数据统计 报警月统计数据导出
+     *
+     * @param
+     * @return
+     */
+    @Log(title = "报警信息管理", businessType = BusinessType.EXPORT)
+    @PostMapping("/exportDataStatisticMonth")
+    @ApiOperation(value = "报警月统计数据导出")
+    @ApiImplicitParams(value = {
+            @ApiImplicitParam(paramType = "query", name = "railwayCode", value = "线路编码"),
+            @ApiImplicitParam(paramType = "query", name = "currentYear", value = "当前年份"),
+            @ApiImplicitParam(paramType = "query", name = "currentMonth", value = "当前月份"),
+            @ApiImplicitParam(paramType = "query", name = "alarmType", value = "灾害类型"),
+    })
+    public void exportDataStatisticMonth(HttpServletResponse response, @RequestBody AlarmStatisticResVo alarmStatisticResVo) {
+        List<AlarmStatisticMonthDto> list = null;
+        if (ObjectUtils.isEmpty(alarmStatisticResVo.getCurrentMonth())) {
+            list = msgAlarmService.getCount(alarmStatisticResVo.getRailwayCode(), alarmStatisticResVo.getCurrentYear(),
+                    alarmStatisticResVo.getCurrentMonth());
+        } else {
+            list = msgAlarmService.getDayCount(alarmStatisticResVo.getRailwayCode(), alarmStatisticResVo.getCurrentYear(),
+                    alarmStatisticResVo.getCurrentMonth());
+        }
+        ExcelUtil<AlarmStatisticMonthDto> util = new ExcelUtil<>(AlarmStatisticMonthDto.class);
+        util.exportExcel(response, list, "报警月统计数据");
+    }
+}