AppPageReportController.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package com.huaxu.controller;
  2. import com.huaxu.dto.generalView.DeviceWaterSupply;
  3. import com.huaxu.model.AjaxMessage;
  4. import com.huaxu.model.ResultStatus;
  5. import com.huaxu.service.AppPageReportService;
  6. import io.swagger.annotations.Api;
  7. import io.swagger.annotations.ApiOperation;
  8. import io.swagger.annotations.ApiParam;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.bind.annotation.RequestMethod;
  12. import org.springframework.web.bind.annotation.RequestParam;
  13. import org.springframework.web.bind.annotation.RestController;
  14. import java.math.BigDecimal;
  15. import java.time.LocalDate;
  16. import java.util.HashMap;
  17. import java.util.List;
  18. import java.util.Map;
  19. /**
  20. * @description
  21. * @auto wangbo
  22. * @data 2021/3/18 10:50
  23. */
  24. @RestController
  25. @RequestMapping("/appPageReport")
  26. @Api(tags = "App总览报表")
  27. public class AppPageReportController {
  28. @Autowired
  29. private AppPageReportService appPageReportService;
  30. /**
  31. * @Author wangbo
  32. * @Description App生产总览数据-本月数据
  33. * @param companyOrgId 公司ID
  34. * @return
  35. */
  36. @RequestMapping(value = "getProductionDataForSameMonth",method = RequestMethod.GET)
  37. @ApiOperation(value = "App总览——生产数据(本月)")
  38. public AjaxMessage<Map<String,Object>> getProductionDataForMonth(
  39. @ApiParam(value = "公司id,总公司传空值") @RequestParam(required = false) Integer companyOrgId){
  40. Map<String,Object> map = new HashMap<String,Object>();
  41. List<DeviceWaterSupply> supplyWaterList = appPageReportService.deviceWaterReportForMonth(companyOrgId,"水源",4,1);
  42. List<DeviceWaterSupply> makingWaterList = appPageReportService.deviceWaterReportForMonth(companyOrgId,"水厂",3,1);
  43. List<DeviceWaterSupply> sellerWaterList = appPageReportService.deviceSellerWaterReportForMonth(companyOrgId,1);
  44. map.put("取水量", supplyWaterList);
  45. map.put("制水量", makingWaterList);
  46. map.put("售水量", sellerWaterList);
  47. CalculationWaterData(supplyWaterList,makingWaterList,sellerWaterList,map);
  48. return new AjaxMessage<>(ResultStatus.OK,map);
  49. }
  50. /**
  51. * @Author wangbo
  52. * @Description App生产总览数据-本年数据
  53. * @param companyOrgId 公司ID
  54. * @return
  55. */
  56. @RequestMapping(value = "getProductionDataForSameYear",method = RequestMethod.GET)
  57. @ApiOperation(value = "App总览——生产数据(本年)")
  58. public AjaxMessage<Map<String,Object>> getProductionDataForSameYear(
  59. @ApiParam(value = "公司id,总公司传空值") @RequestParam(required = false) Integer companyOrgId){
  60. LocalDate localDate = LocalDate.now();
  61. Map<String,Object> map = new HashMap<String,Object>();
  62. List<DeviceWaterSupply> supplyWaterList = appPageReportService.deviceWaterReportForMonth(companyOrgId,"水源",4,localDate.getMonthValue());
  63. List<DeviceWaterSupply> makingWaterList = appPageReportService.deviceWaterReportForMonth(companyOrgId,"水厂",3,localDate.getMonthValue());
  64. List<DeviceWaterSupply> sellerWaterList = appPageReportService.deviceSellerWaterReportForMonth(companyOrgId,localDate.getMonthValue());
  65. map.put("取水量", supplyWaterList);
  66. map.put("制水量", makingWaterList);
  67. map.put("售水量", sellerWaterList);
  68. CalculationWaterData(supplyWaterList,makingWaterList,sellerWaterList,map);
  69. return new AjaxMessage<>(ResultStatus.OK,map);
  70. }
  71. /**
  72. * @Author wangbo
  73. * @Description App生产总览数据-近一年数据
  74. * @param companyOrgId 公司ID
  75. * @return
  76. */
  77. @RequestMapping(value = "getProductionDataFor12Month",method = RequestMethod.GET)
  78. @ApiOperation(value = "App总览——生产数据(近一年)")
  79. public AjaxMessage<Map<String,Object>> getProductionDataFor12Month(
  80. @ApiParam(value = "公司id,总公司传空值") @RequestParam(required = false) Integer companyOrgId){
  81. Map<String,Object> map = new HashMap<String,Object>();
  82. List<DeviceWaterSupply> supplyWaterList = appPageReportService.deviceWaterReportForMonth(companyOrgId,"水源",4,12);
  83. List<DeviceWaterSupply> makingWaterList = appPageReportService.deviceWaterReportForMonth(companyOrgId,"水厂",3,12);
  84. List<DeviceWaterSupply> sellerWaterList = appPageReportService.deviceSellerWaterReportForMonth(companyOrgId,12);
  85. map.put("取水量", supplyWaterList);
  86. map.put("制水量", makingWaterList);
  87. map.put("售水量", sellerWaterList);
  88. CalculationWaterData(supplyWaterList,makingWaterList,sellerWaterList,map);
  89. return new AjaxMessage<>(ResultStatus.OK,map);
  90. }
  91. /**
  92. * @Author wangbo
  93. * @Description 计算产销差
  94. * @param makingWaterList 制水量数据
  95. * @param sellerWaterList 售水量数据
  96. * @param map
  97. * @return
  98. */
  99. private void CalculationWaterData(List<DeviceWaterSupply> supplyWaterList, List<DeviceWaterSupply> makingWaterList,List<DeviceWaterSupply> sellerWaterList,Map<String,Object> map){
  100. BigDecimal supplyWaterAmount = new BigDecimal(0);
  101. BigDecimal makingWaterAmount = new BigDecimal(0);
  102. BigDecimal sellerWaterAmount = new BigDecimal(0);
  103. for(DeviceWaterSupply water : supplyWaterList){
  104. supplyWaterAmount = supplyWaterAmount.add(water.getAmount());
  105. }
  106. for(DeviceWaterSupply water : makingWaterList){
  107. makingWaterAmount = makingWaterAmount.add(water.getAmount());
  108. }
  109. for(DeviceWaterSupply water : sellerWaterList){
  110. sellerWaterAmount = sellerWaterAmount.add(water.getAmount());
  111. }
  112. BigDecimal nrw = makingWaterAmount ==BigDecimal.ZERO ? BigDecimal.ZERO : makingWaterAmount.subtract(sellerWaterAmount).multiply(new BigDecimal(100)).divide(makingWaterAmount,2);
  113. map.put("取水总量",supplyWaterAmount);
  114. map.put("制水总量",makingWaterAmount);
  115. map.put("售水总量",sellerWaterAmount);
  116. map.put("产销差",nrw);
  117. }
  118. }