zbj//1.灿能云用户规模
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package com.njcn.user.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.HomeostasisAreaVO;
|
||||
import com.njcn.device.pq.pojo.vo.UserScaleVO;
|
||||
import com.njcn.user.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("/getUserScale")
|
||||
@ApiOperation("灿能云用户规模")
|
||||
@ApiImplicitParam(name = "largeScreenParam", value = "灿能云用户规模", required = true)
|
||||
public HttpResult<List<UserScaleVO>> getUserScale(@RequestBody @Validated LargeScreenParam largeScreenParam) {
|
||||
String methodDescribe = getMethodDescribe("getUserScale");
|
||||
List<UserScaleVO> result = largeScreenService.getUserScale(largeScreenParam);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.njcn.user.mapper;
|
||||
|
||||
|
||||
import com.njcn.device.pq.pojo.param.LargeScreenParam;
|
||||
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<UserScaleVO> getUserScale (LargeScreenParam largeScreenParam);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?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.user.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>
|
||||
GROUP BY `timeId`;
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.njcn.user.service;
|
||||
|
||||
import com.njcn.device.pq.pojo.param.LargeScreenParam;
|
||||
import com.njcn.device.pq.pojo.vo.UserScaleVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @version 1.0.0
|
||||
* @author: zbj
|
||||
* @date: 2023/04/10
|
||||
*/
|
||||
public interface LargeScreenService {
|
||||
|
||||
List<UserScaleVO> getUserScale(LargeScreenParam largeScreenParam);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.njcn.user.service.impl;
|
||||
|
||||
import com.njcn.device.pq.pojo.param.LargeScreenParam;
|
||||
import com.njcn.device.pq.pojo.vo.HomeostasisAreaVO;
|
||||
import com.njcn.device.pq.pojo.vo.UserScaleVO;
|
||||
import com.njcn.user.mapper.LargeScreenMapper;
|
||||
import com.njcn.user.service.LargeScreenService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Year;
|
||||
import java.time.YearMonth;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @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<UserScaleVO> getUserScale(LargeScreenParam largeScreenParam) {
|
||||
//创建返回VO
|
||||
List<UserScaleVO> result = new ArrayList<>();
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
//获取当前年第一天日期
|
||||
Year year = Year.now();
|
||||
String firstDay = year.atDay(1).format(formatter);
|
||||
//获取当前天字符串日期
|
||||
LocalDate today = LocalDate.now();
|
||||
String endDay = today.format(formatter);
|
||||
//替换属性
|
||||
largeScreenParam.setSearchBeginTime(firstDay);
|
||||
largeScreenParam.setSearchEndTime(endDay);
|
||||
List<UserScaleVO> list = largeScreenMapper.getUserScale(largeScreenParam);
|
||||
//获取传入起始月结束月中所有月份
|
||||
List<String> monthList = selectDate(largeScreenParam.getSearchBeginTime(),
|
||||
largeScreenParam.getSearchEndTime());
|
||||
|
||||
for (String s : monthList) {
|
||||
UserScaleVO vo = new UserScaleVO();
|
||||
vo.setTimeId(s);
|
||||
result.add(vo);
|
||||
}
|
||||
//集合不为空
|
||||
if (list.size()>0){
|
||||
for (UserScaleVO userScaleVO : result) {
|
||||
for (UserScaleVO scaleVO : list) {
|
||||
if (Objects.equals(scaleVO.getTimeId(),userScaleVO.getTimeId())){
|
||||
userScaleVO.setMonthIncrementNum(scaleVO.getMonthIncrementNum());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (UserScaleVO vo : result) {
|
||||
if (vo.getMonthIncrementNum()==null){
|
||||
vo.setMonthIncrementNum(0);
|
||||
}
|
||||
}
|
||||
int count = 0;
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
count = count + result.get(i).getMonthIncrementNum();
|
||||
result.get(i).setIncrementNum(count);
|
||||
}
|
||||
return result;
|
||||
}else{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取传入起始月结束月中所有月份
|
||||
* @param startDate
|
||||
* @param endDate
|
||||
* @return
|
||||
*/
|
||||
public List<String> selectDate(String startDate, String endDate) {
|
||||
LocalDate start = LocalDate.parse(startDate, DateTimeFormatter.ISO_LOCAL_DATE);
|
||||
LocalDate end = LocalDate.parse(endDate, DateTimeFormatter.ISO_LOCAL_DATE);
|
||||
|
||||
List<String> allMonths = new ArrayList<>();
|
||||
YearMonth current = YearMonth.from(start);
|
||||
|
||||
while (!current.isAfter(YearMonth.from(end))) {
|
||||
allMonths.add(current.format(DateTimeFormatter.ofPattern("yyyy-MM")));
|
||||
current = current.plusMonths(1);
|
||||
}
|
||||
return allMonths;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user