ustcyc
2025-01-07 5fd51c437819f1c9d027a936db4ba2ee7cd2e053
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package com.zhitan.web.controller.benchmarkmanage;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhitan.benchmarkmanage.domain.EnergyBenchmarkManage;
import com.zhitan.benchmarkmanage.service.IEnergyBenchmarkManageService;
import com.zhitan.common.annotation.Log;
import com.zhitan.common.core.controller.BaseController;
import com.zhitan.common.core.domain.AjaxResult;
import com.zhitan.common.core.domain.model.LoginUser;
import com.zhitan.common.core.page.TableDataInfo;
import com.zhitan.common.enums.BusinessType;
import com.zhitan.common.utils.ServletUtils;
import com.zhitan.common.utils.StringUtils;
import com.zhitan.common.utils.poi.ExcelUtil;
import com.zhitan.framework.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.UUID;
 
/**
 * 标杆值管理Controller
 *
 * @author ZhiTan
 * @date 2024-11-12
 */
@RestController
@RequestMapping("/benchmarkManage")
public class EnergyBenchmarkManageController extends BaseController
{
    @Resource
    private IEnergyBenchmarkManageService energyBenchmarkManageService;
 
    @Autowired
    private TokenService tokenService;
 
    /**
     * 查询标杆值管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:benchmarkManage:list')")
    @GetMapping("/list")
    public TableDataInfo list(EnergyBenchmarkManage energyBenchmarkManage, @RequestParam Long pageNum, @RequestParam Long pageSize)
    {
        //        startPage();
        Page<EnergyBenchmarkManage> list = energyBenchmarkManageService.selectBenchmarkManagePage(energyBenchmarkManage,pageNum,pageSize);
        return getDataTable(list);
    }
 
 
    /**
     * 导出标杆值管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:benchmarkManage:export')")
    @Log(title = "标杆值管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EnergyBenchmarkManage energyBenchmarkManage)
    {
        List<EnergyBenchmarkManage> list = energyBenchmarkManageService.selectEnergyBenchmarkManageList(energyBenchmarkManage);
        ExcelUtil<EnergyBenchmarkManage> util = new ExcelUtil<EnergyBenchmarkManage>(EnergyBenchmarkManage.class);
        util.exportExcel(response, list, "标杆值管理数据");
    }
 
    /**
     * 获取标杆值管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:benchmarkManage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(energyBenchmarkManageService.selectEnergyBenchmarkManageById(id));
    }
 
    /**
     * 新增标杆值管理
     */
    @PreAuthorize("@ss.hasPermi('system:benchmarkManage:add')")
    @Log(title = "标杆值管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EnergyBenchmarkManage energyBenchmarkManage)
    {
        if (StringUtils.isBlank(energyBenchmarkManage.getCode())) {
            return error("请输入标杆编号!");
        }
 
        //校验唯一
        EnergyBenchmarkManage queryParams=new EnergyBenchmarkManage();
        queryParams.setCode(energyBenchmarkManage.getCode());
        List<EnergyBenchmarkManage> codeReptList = energyBenchmarkManageService.getList(queryParams);
        if (null!=codeReptList && !codeReptList.isEmpty()) {
            return error("标杆编号重复!");
        }
        queryParams=new EnergyBenchmarkManage();
        queryParams.setType(energyBenchmarkManage.getType());
        queryParams.setGrade(energyBenchmarkManage.getGrade());
        List<EnergyBenchmarkManage> dataReptList = energyBenchmarkManageService.getList(queryParams);
        if (null!=dataReptList && !dataReptList.isEmpty()) {
            return error("标杆信息已维护!");
        }
        energyBenchmarkManage.setId(UUID.randomUUID().toString());
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        energyBenchmarkManage.setCreateBy(loginUser.getUsername());
        return toAjax(energyBenchmarkManageService.insertEnergyBenchmarkManage(energyBenchmarkManage));
    }
 
    /**
     * 修改标杆值管理
     */
    @PreAuthorize("@ss.hasPermi('system:benchmarkManage:edit')")
    @Log(title = "标杆值管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EnergyBenchmarkManage energyBenchmarkManage)
    {
        if (StringUtils.isBlank(energyBenchmarkManage.getCode())) {
            return error("请输入标杆编号!");
        }
        EnergyBenchmarkManage queryParams=new EnergyBenchmarkManage();
        queryParams.setCode(energyBenchmarkManage.getCode());
        List<EnergyBenchmarkManage> codeReptList = energyBenchmarkManageService.getList(queryParams);
        if (null!=codeReptList && !codeReptList.isEmpty()) {
            return error("标杆编号重复!");
        }
        queryParams=new EnergyBenchmarkManage();
        queryParams.setType(energyBenchmarkManage.getType());
        queryParams.setGrade(energyBenchmarkManage.getGrade());
        List<EnergyBenchmarkManage> dataReptList = energyBenchmarkManageService.getList(queryParams);
        if (null!=dataReptList && !dataReptList.isEmpty()) {
            return error("标杆信息已维护!");
        }
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        energyBenchmarkManage.setUpdateBy(loginUser.getUsername());
        return toAjax(energyBenchmarkManageService.updateEnergyBenchmarkManage(energyBenchmarkManage));
    }
 
    /**
     * 删除标杆值管理
     */
    @PreAuthorize("@ss.hasPermi('system:benchmarkManage:remove')")
    @Log(title = "标杆值管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(energyBenchmarkManageService.deleteEnergyBenchmarkManageByIds(ids));
    }
}