diff --git a/pqs-device/pq-device/pq-device-api/src/main/java/com/njcn/device/pq/pojo/vo/UserScaleVO.java b/pqs-device/pq-device/pq-device-api/src/main/java/com/njcn/device/pq/pojo/vo/UserScaleVO.java new file mode 100644 index 000000000..418695604 --- /dev/null +++ b/pqs-device/pq-device/pq-device-api/src/main/java/com/njcn/device/pq/pojo/vo/UserScaleVO.java @@ -0,0 +1,36 @@ +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 UserScaleVO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 月份 + */ + @ApiModelProperty("月份") + private String timeId; + + /** + * 累计增量 + */ + @ApiModelProperty("累计增量") + private Integer incrementNum; + + /** + * 当月增量 + */ + @ApiModelProperty("当月增量") + private Integer monthIncrementNum; + +} diff --git a/pqs-user/user-boot/src/main/java/com/njcn/user/controller/LargeScreenController.java b/pqs-user/user-boot/src/main/java/com/njcn/user/controller/LargeScreenController.java new file mode 100644 index 000000000..86c1ab0bc --- /dev/null +++ b/pqs-user/user-boot/src/main/java/com/njcn/user/controller/LargeScreenController.java @@ -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> getUserScale(@RequestBody @Validated LargeScreenParam largeScreenParam) { + String methodDescribe = getMethodDescribe("getUserScale"); + List result = largeScreenService.getUserScale(largeScreenParam); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); + } +} diff --git a/pqs-user/user-boot/src/main/java/com/njcn/user/mapper/LargeScreenMapper.java b/pqs-user/user-boot/src/main/java/com/njcn/user/mapper/LargeScreenMapper.java new file mode 100644 index 000000000..4d3666d47 --- /dev/null +++ b/pqs-user/user-boot/src/main/java/com/njcn/user/mapper/LargeScreenMapper.java @@ -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 getUserScale (LargeScreenParam largeScreenParam); + +} diff --git a/pqs-user/user-boot/src/main/java/com/njcn/user/mapper/mapping/LargeScreenMapper.xml b/pqs-user/user-boot/src/main/java/com/njcn/user/mapper/mapping/LargeScreenMapper.xml new file mode 100644 index 000000000..8ec0b0fca --- /dev/null +++ b/pqs-user/user-boot/src/main/java/com/njcn/user/mapper/mapping/LargeScreenMapper.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/pqs-user/user-boot/src/main/java/com/njcn/user/service/LargeScreenService.java b/pqs-user/user-boot/src/main/java/com/njcn/user/service/LargeScreenService.java new file mode 100644 index 000000000..c23a18e8c --- /dev/null +++ b/pqs-user/user-boot/src/main/java/com/njcn/user/service/LargeScreenService.java @@ -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 getUserScale(LargeScreenParam largeScreenParam); + +} diff --git a/pqs-user/user-boot/src/main/java/com/njcn/user/service/impl/LargeScreenServiceImpl.java b/pqs-user/user-boot/src/main/java/com/njcn/user/service/impl/LargeScreenServiceImpl.java new file mode 100644 index 000000000..d7df2ed2d --- /dev/null +++ b/pqs-user/user-boot/src/main/java/com/njcn/user/service/impl/LargeScreenServiceImpl.java @@ -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 getUserScale(LargeScreenParam largeScreenParam) { + //创建返回VO + List 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 list = largeScreenMapper.getUserScale(largeScreenParam); + //获取传入起始月结束月中所有月份 + List 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 selectDate(String startDate, String endDate) { + LocalDate start = LocalDate.parse(startDate, DateTimeFormatter.ISO_LOCAL_DATE); + LocalDate end = LocalDate.parse(endDate, DateTimeFormatter.ISO_LOCAL_DATE); + + List 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; + } +}