BizObjMetricsController.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package com.jjt.biz.controller;
  2. import com.jjt.biz.domain.BizObjMetrics;
  3. import com.jjt.biz.service.IBizObjMetricsService;
  4. import com.jjt.common.annotation.Log;
  5. import com.jjt.common.core.controller.BaseController;
  6. import com.jjt.common.core.domain.AjaxResult;
  7. import com.jjt.common.core.page.TableDataInfo;
  8. import com.jjt.common.enums.BusinessType;
  9. import com.jjt.common.utils.poi.ExcelUtil;
  10. import io.swagger.annotations.Api;
  11. import io.swagger.annotations.ApiOperation;
  12. import org.springframework.security.access.prepost.PreAuthorize;
  13. import org.springframework.web.bind.annotation.*;
  14. import javax.annotation.Resource;
  15. import javax.servlet.http.HttpServletResponse;
  16. import java.text.DecimalFormat;
  17. import java.time.LocalDateTime;
  18. import java.time.ZoneOffset;
  19. import java.util.*;
  20. /**
  21. * 业务对象指标Controller
  22. *
  23. * @author jjt
  24. * @date 2024-08-09
  25. */
  26. @Api(tags = "业务对象指标")
  27. @RestController
  28. @RequestMapping("/obj/metrics")
  29. public class BizObjMetricsController extends BaseController {
  30. @Resource
  31. private IBizObjMetricsService bizObjMetricsService;
  32. /**
  33. * 查询业务对象指标列表
  34. */
  35. @ApiOperation("查询业务对象指标列表")
  36. @PreAuthorize("@ss.hasPermi('obj:metrics:list')")
  37. @GetMapping("/list")
  38. public TableDataInfo list(BizObjMetrics bizObjMetrics) {
  39. startPage();
  40. List<BizObjMetrics> list = bizObjMetricsService.selectBizObjMetricsList(bizObjMetrics);
  41. return getDataTable(list);
  42. }
  43. /**
  44. * 导出业务对象指标列表
  45. */
  46. @ApiOperation("导出业务对象指标列表")
  47. @PreAuthorize("@ss.hasPermi('obj:metrics:export')")
  48. @Log(title = "业务对象指标", businessType = BusinessType.EXPORT)
  49. @PostMapping("/export")
  50. public void export(HttpServletResponse response, BizObjMetrics bizObjMetrics) {
  51. List<BizObjMetrics> list = bizObjMetricsService.selectBizObjMetricsList(bizObjMetrics);
  52. ExcelUtil<BizObjMetrics> util = new ExcelUtil<BizObjMetrics>(BizObjMetrics.class);
  53. util.exportExcel(response, list, "业务对象指标数据");
  54. }
  55. /**
  56. * 获取业务对象指标详细信息
  57. */
  58. @ApiOperation("获取业务对象指标详细信息")
  59. @PreAuthorize("@ss.hasPermi('obj:metrics:query')")
  60. @GetMapping(value = "/{objMetricsId}")
  61. public AjaxResult getInfo(@PathVariable("objMetricsId") Long objMetricsId) {
  62. BizObjMetrics metrics = bizObjMetricsService.selectBizObjMetricsByObjMetricsId(objMetricsId);
  63. return success(bizObjMetricsService.selectBizObjMetricsByObjMetricsId(objMetricsId));
  64. }
  65. /**
  66. * 获取业务对象指标详细信息
  67. */
  68. @ApiOperation("获取业务对象历史趋势")
  69. @GetMapping(value = "/history/{objMetricsId}")
  70. public AjaxResult history(@PathVariable("objMetricsId") Long objMetricsId) {
  71. List<Long> times = new ArrayList<>();
  72. List<Float> values = new ArrayList<>();
  73. LocalDateTime ed = LocalDateTime.now();
  74. LocalDateTime st = ed.minusDays(7);
  75. Random r = new Random();
  76. DecimalFormat df = new DecimalFormat("#0.00");
  77. do {
  78. long time = st.toEpochSecond(ZoneOffset.ofHours(8)) * 1000;
  79. times.add(time);
  80. float f = r.nextFloat() * 100;
  81. // System.err.println(df.format(f));
  82. values.add(Float.parseFloat(df.format(f)));
  83. st = st.plusMinutes(15);
  84. } while (!st.isAfter(ed));
  85. Map<String, Object> map = new HashMap<>(16);
  86. map.put("times", times);
  87. map.put("values", values);
  88. return AjaxResult.success(map);
  89. }
  90. /**
  91. * 新增业务对象指标
  92. */
  93. @ApiOperation("新增业务对象指标")
  94. @PreAuthorize("@ss.hasPermi('obj:metrics:add')")
  95. @Log(title = "业务对象指标", businessType = BusinessType.INSERT)
  96. @PostMapping
  97. public AjaxResult add(@RequestBody BizObjMetrics bizObjMetrics) {
  98. return toAjax(bizObjMetricsService.insertBizObjMetrics(bizObjMetrics));
  99. }
  100. /**
  101. * 修改业务对象指标
  102. */
  103. @ApiOperation("修改业务对象指标")
  104. @PreAuthorize("@ss.hasPermi('obj:metrics:edit')")
  105. @Log(title = "业务对象指标", businessType = BusinessType.UPDATE)
  106. @PutMapping
  107. public AjaxResult edit(@RequestBody BizObjMetrics bizObjMetrics) {
  108. return toAjax(bizObjMetricsService.updateBizObjMetrics(bizObjMetrics));
  109. }
  110. /**
  111. * 删除业务对象指标
  112. */
  113. @ApiOperation("删除业务对象指标")
  114. @PreAuthorize("@ss.hasPermi('obj:metrics:remove')")
  115. @Log(title = "业务对象指标", businessType = BusinessType.DELETE)
  116. @DeleteMapping("/{objMetricsIds}")
  117. public AjaxResult remove(@PathVariable Long[] objMetricsIds) {
  118. return toAjax(bizObjMetricsService.deleteBizObjMetricsByObjMetricsIds(objMetricsIds));
  119. }
  120. }