zbj//1.数据规模

This commit is contained in:
zhangbaojian
2023-04-10 17:54:13 +08:00
parent d2b95ebb7d
commit 3f0c3df939
7 changed files with 281 additions and 2 deletions

View File

@@ -45,7 +45,7 @@
<middle.server.url>192.168.1.18</middle.server.url>
<!--微服务模块发布地址-->
<!-- <service.server.url>198.120.100.195</service.server.url>-->
<service.server.url>192.168.1.114</service.server.url>
<service.server.url>192.168.1.166</service.server.url>
<!--docker仓库地址-->
<docker.server.url>192.168.1.13</docker.server.url>
<!--nacos的ip:port-->
@@ -54,7 +54,7 @@
<!-- <nacos.namespace></nacos.namespace>-->
<!-- <nacos.namespace>fd74182b-1fce-4dba-afa7-2623b0376205</nacos.namespace>-->
<!-- <nacos.namespace>ba3ba5d1-3480-4755-8b87-6b1fce16201c</nacos.namespace>-->
<nacos.namespace>fe40a052-d787-48f4-940f-688cabdff26a</nacos.namespace>
<nacos.namespace>012fcc94-a4d4-4dff-a75a-396a1b997f25</nacos.namespace>
<!--sentinel:port-->
<!-- <sentinel.url>192.168.1.14:8080</sentinel.url>-->
<sentinel.url>${middle.server.url}:8080</sentinel.url>

View File

@@ -0,0 +1,30 @@
package com.njcn.device.pq.pojo.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* @version 1.0.0
* @author: zbj
* @date: 2023/04/10
*/
@Data
public class DataScaleVO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 月份
*/
@ApiModelProperty("月份")
private String timeId;
/**
* 数据
*/
@ApiModelProperty("数据")
private Float dataStatis;
}

View File

@@ -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);
}
}

View File

@@ -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);
}

View File

@@ -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') &gt;= date_format(#{searchBeginTime},'%y%m%d')
</if>
<if test="searchEndTime != null and searchEndTime != ''">
and date_format(REGISTER_TIME,'%y%m%d') &lt;= 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') &gt;= date_format(#{searchBeginTime},'%y%m%d')
</if>
<if test="searchEndTime != null and searchEndTime != ''">
and date_format(pd.TIMEID,'%y%m%d') &lt;= date_format(#{searchEndTime},'%y%m%d')
</if>
</where>
GROUP BY DATE(pd.TIMEID);
</select>
</mapper>

View File

@@ -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);
}

View File

@@ -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;
}
}