package com.jjt.hl.controller; import com.jjt.common.annotation.Log; import com.jjt.common.core.controller.BaseController; import com.jjt.common.core.domain.AjaxResult; import com.jjt.common.core.page.TableDataInfo; import com.jjt.common.enums.BusinessType; import com.jjt.common.utils.poi.ExcelUtil; import com.jjt.hl.domain.HlClass; import com.jjt.hl.domain.HlMetrics; import com.jjt.hl.service.IHlClassService; import com.jjt.hl.service.IHlMetricsService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.List; /** * 业务模型健康度指标Controller * * @author jjt * @date 2024-09-05 */ @Api(tags = "业务模型健康度指标") @RestController @RequestMapping("/hl/hm") public class HlMetricsController extends BaseController { @Resource private IHlMetricsService hlMetricsService; @Resource private IHlClassService hlClassService; @ApiOperation("根据分类ID查询指标") @GetMapping("/list/{hlClassId}") public AjaxResult list(@PathVariable("hlClassId") Long hlClassId) { HlClass hlClass = hlClassService.selectHlClassByHlClassId(hlClassId); HlMetrics hlMetrics = new HlMetrics(); hlMetrics.setHlClassId(hlClassId); List list = hlMetricsService.selectHlMetricsList(hlMetrics); if (list.size() > 0 && "1".equals(hlClass.getScoreType())) { //均分 int size = list.size(); BigDecimal total = hlClass.getHlScore(); int avg = total.divide(BigDecimal.valueOf(size), 0, RoundingMode.HALF_DOWN).intValue(); int one = avg * size == total.intValue() ? avg : total.intValue() - avg * (size-1); boolean flag = true; for (HlMetrics hm : list) { if (flag) { hm.setHlScore(BigDecimal.valueOf(one)); flag = false; } else { hm.setHlScore(BigDecimal.valueOf(avg)); } hlMetricsService.updateHlMetrics(hm); } } return AjaxResult.success(list); } @ApiOperation("根据分类ID查询选择指标列表") @GetMapping("/select/{hlClassId}") public AjaxResult select(@PathVariable("hlClassId") Long hlClassId) { HlClass hlClass = hlClassService.selectHlClassByHlClassId(hlClassId); List list = hlMetricsService.selectHlMetricsList4ModelId(hlClass.getModelId(), hlClass.getObjType()); return AjaxResult.success(list); } @ApiOperation("添加指标") @GetMapping("/add/{hlClassId}") public AjaxResult objAdd(@ApiParam(value = "分类ID", required = true) @PathVariable("hlClassId") Long hlClassId, @ApiParam(value = "指标ID数组", required = true) Long[] ids) { return success(hlMetricsService.insertMetrics(hlClassId, ids)); } /** * 查询业务模型健康度指标列表 */ @ApiOperation("查询业务模型健康度指标列表") @PreAuthorize("@ss.hasPermi('hl:hm:list')") @GetMapping("/list") public TableDataInfo list(HlMetrics hlMetrics) { startPage(); List list = hlMetricsService.selectHlMetricsList(hlMetrics); return getDataTable(list); } /** * 导出业务模型健康度指标列表 */ @ApiOperation("导出业务模型健康度指标列表") @PreAuthorize("@ss.hasPermi('hl:hm:export')") @Log(title = "业务模型健康度指标", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, HlMetrics hlMetrics) { List list = hlMetricsService.selectHlMetricsList(hlMetrics); ExcelUtil util = new ExcelUtil(HlMetrics.class); util.exportExcel(response, list, "业务模型健康度指标数据"); } /** * 获取业务模型健康度指标详细信息 */ @ApiOperation("获取业务模型健康度指标详细信息") @PreAuthorize("@ss.hasPermi('hl:hm:query')") @GetMapping(value = "/{hlMetricsId}") public AjaxResult getInfo(@PathVariable("hlMetricsId") Long hlMetricsId) { return success(hlMetricsService.selectHlMetricsByHlMetricsId(hlMetricsId)); } /** * 新增业务模型健康度指标 */ @ApiOperation("新增业务模型健康度指标") @PreAuthorize("@ss.hasPermi('hl:hm:add')") @Log(title = "业务模型健康度指标", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody HlMetrics hlMetrics) { return toAjax(hlMetricsService.insertHlMetrics(hlMetrics)); } /** * 修改业务模型健康度指标 */ @ApiOperation("修改业务模型健康度指标") @PreAuthorize("@ss.hasPermi('hl:hm:edit')") @Log(title = "业务模型健康度指标", businessType = BusinessType.UPDATE) @PostMapping("/edit") public AjaxResult edit(@RequestBody HlMetrics hlMetrics) { return toAjax(hlMetricsService.updateHlMetrics(hlMetrics)); } /** * 删除业务模型健康度指标 */ @ApiOperation("删除业务模型健康度指标") @PreAuthorize("@ss.hasPermi('hl:hm:remove')") @Log(title = "业务模型健康度指标", businessType = BusinessType.DELETE) @GetMapping("/del/{hlMetricsIds}") public AjaxResult remove(@PathVariable Long[] hlMetricsIds) { return toAjax(hlMetricsService.deleteHlMetricsByHlMetricsIds(hlMetricsIds)); } }