zbj//1.数据规模
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package com.njcn.system.controller;
|
||||
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.device.pq.pojo.param.LargeScreenParam;
|
||||
import com.njcn.device.pq.pojo.vo.DataScaleVO;
|
||||
import com.njcn.system.service.LargeScreenService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
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 java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @version 1.0.0
|
||||
* @author: zbj
|
||||
* @date: 2023/04/10
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "大屏")
|
||||
@RestController
|
||||
@RequestMapping("/largeScreen")
|
||||
@RequiredArgsConstructor
|
||||
public class LargeScreenController extends BaseController {
|
||||
|
||||
private final LargeScreenService largeScreenService;
|
||||
|
||||
/**
|
||||
* 数据规模
|
||||
*/
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/getDataScale")
|
||||
@ApiOperation("数据规模")
|
||||
@ApiImplicitParam(name = "largeScreenParam", value = "数据规模", required = true)
|
||||
public HttpResult<List<DataScaleVO>> getDataScale(@RequestBody @Validated LargeScreenParam largeScreenParam) {
|
||||
String methodDescribe = getMethodDescribe("getDataScale");
|
||||
List<DataScaleVO> result = largeScreenService.getDataScale(largeScreenParam);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.njcn.system.mapper;
|
||||
|
||||
|
||||
import com.njcn.device.pq.pojo.param.LargeScreenParam;
|
||||
import com.njcn.device.pq.pojo.vo.DataScaleVO;
|
||||
import com.njcn.device.pq.pojo.vo.UserScaleVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @version 1.0.0
|
||||
* @author: zbj
|
||||
* @date: 2023/04/10
|
||||
*/
|
||||
public interface LargeScreenMapper {
|
||||
|
||||
List<DataScaleVO> getDataScale (LargeScreenParam largeScreenParam);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.system.mapper.LargeScreenMapper">
|
||||
|
||||
<select id="getUserScale" resultType="com.njcn.device.pq.pojo.vo.UserScaleVO">
|
||||
SELECT DATE_FORMAT(REGISTER_TIME, '%Y-%m') AS `timeId`, COUNT(*) AS `monthIncrementNum`
|
||||
FROM app_user
|
||||
<where>
|
||||
STATE = '1'
|
||||
<if test="searchBeginTime != null and searchBeginTime != ''">
|
||||
and date_format(REGISTER_TIME,'%y%m%d') >= date_format(#{searchBeginTime},'%y%m%d')
|
||||
</if>
|
||||
<if test="searchEndTime != null and searchEndTime != ''">
|
||||
and date_format(REGISTER_TIME,'%y%m%d') <= date_format(#{searchEndTime},'%y%m%d')
|
||||
</if>
|
||||
</where>
|
||||
GROUP BY `timeId`;
|
||||
</select>
|
||||
|
||||
<select id="getDataScale" resultType="com.njcn.device.pq.pojo.vo.DataScaleVO">
|
||||
SELECT DATE(pd.TIMEID) as "timeId", round(sum(DATASTATIS),2) as "dataStatis"
|
||||
FROM pqs_datastatis pd
|
||||
<where>
|
||||
<if test="searchBeginTime != null and searchBeginTime != ''">
|
||||
and date_format(pd.TIMEID,'%y%m%d') >= date_format(#{searchBeginTime},'%y%m%d')
|
||||
</if>
|
||||
<if test="searchEndTime != null and searchEndTime != ''">
|
||||
and date_format(pd.TIMEID,'%y%m%d') <= date_format(#{searchEndTime},'%y%m%d')
|
||||
</if>
|
||||
</where>
|
||||
GROUP BY DATE(pd.TIMEID);
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.njcn.system.service;
|
||||
|
||||
import com.njcn.device.pq.pojo.param.LargeScreenParam;
|
||||
import com.njcn.device.pq.pojo.vo.DataScaleVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @version 1.0.0
|
||||
* @author: zbj
|
||||
* @date: 2023/04/10
|
||||
*/
|
||||
public interface LargeScreenService {
|
||||
|
||||
List<DataScaleVO> getDataScale(LargeScreenParam largeScreenParam);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.njcn.system.service.impl;
|
||||
|
||||
import com.njcn.device.pq.pojo.param.LargeScreenParam;
|
||||
import com.njcn.device.pq.pojo.vo.DataScaleVO;
|
||||
import com.njcn.system.mapper.LargeScreenMapper;
|
||||
import com.njcn.system.service.LargeScreenService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @version 1.0.0
|
||||
* @author: zbj
|
||||
* @date: 2023/04/10
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class LargeScreenServiceImpl implements LargeScreenService {
|
||||
|
||||
private final LargeScreenMapper largeScreenMapper;
|
||||
|
||||
/**
|
||||
* 数据规模
|
||||
*/
|
||||
@Override
|
||||
public List<DataScaleVO> getDataScale(LargeScreenParam largeScreenParam) {
|
||||
//创建返回VO
|
||||
List<DataScaleVO> result = new ArrayList<>();
|
||||
//创建模板
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
//获取当前日期
|
||||
LocalDate today = LocalDate.now();
|
||||
String endTime = today.format(formatter);
|
||||
String startTime = "";
|
||||
//获取30天前的日期
|
||||
try {
|
||||
startTime = getDate(endTime);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
largeScreenParam.setSearchBeginTime(startTime);
|
||||
largeScreenParam.setSearchEndTime(endTime);
|
||||
List<DataScaleVO> list = largeScreenMapper.getDataScale(largeScreenParam);
|
||||
//获取区间中所有日期
|
||||
List<String> days = null;
|
||||
try {
|
||||
days = selectDate(startTime, endTime);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//加上今天
|
||||
days.add(endTime);
|
||||
for (String s : days) {
|
||||
DataScaleVO vo = new DataScaleVO();
|
||||
vo.setTimeId(s);
|
||||
result.add(vo);
|
||||
}
|
||||
//集合不为空
|
||||
if (list.size() > 0) {
|
||||
for (DataScaleVO dataScaleVO : result) {
|
||||
for (DataScaleVO scaleVO : list) {
|
||||
if (Objects.equals(scaleVO.getTimeId(), dataScaleVO.getTimeId())) {
|
||||
dataScaleVO.setDataStatis(scaleVO.getDataStatis());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (DataScaleVO vo : result) {
|
||||
if (vo.getDataStatis() == null) {
|
||||
vo.setDataStatis(0.0f);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 传入字符串日期获取当前日期30天日期
|
||||
*
|
||||
* @param stringDate
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String getDate(String stringDate) throws Exception {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date date = sdf.parse(stringDate); // 将字符串日期转换为Date对象
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
calendar.add(Calendar.DAY_OF_MONTH, -30); // 计算30天前的日期
|
||||
Date newDate = calendar.getTime(); // 获取新日期
|
||||
String newDateStr = sdf.format(newDate); // 将新日期转换为字符串日期
|
||||
return newDateStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取传入起始月结束月中所有天
|
||||
*
|
||||
* @param startTime
|
||||
* @param endTime
|
||||
* @return
|
||||
*/
|
||||
public List<String> selectDate(String startTime, String endTime) throws Exception {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
Date startDate = sdf.parse(startTime);
|
||||
Date endDate = sdf.parse(endTime);
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(startDate);
|
||||
|
||||
List<String> dates = new ArrayList<>();
|
||||
while (calendar.getTime().before(endDate)) {
|
||||
Date date = calendar.getTime();
|
||||
String dateStr = sdf.format(date);
|
||||
dates.add(dateStr);
|
||||
calendar.add(Calendar.DATE, 1);
|
||||
}
|
||||
return dates;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user