admin
2024-05-27 816ba1e56476f0e23f51711aae4b34507a04a59c
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package com.ruoyi.system.controller;
 
import java.beans.SimpleBeanInfo;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.Random;
import javax.servlet.http.HttpServletResponse;
 
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.service.ISysDictDataService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AiRule;
import com.ruoyi.system.service.IAiRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
 
/**
 * AI算法管理Controller
 *
 * @author ruoyi
 * @date 2023-03-07
 */
@RestController
@RequestMapping("/system/rule")
public class AiRuleController extends BaseController
{
    @Autowired
    private IAiRuleService aiRuleService;
    @Autowired
    private ISysDictDataService sysDictDataService;
 
    /**
     * 查询AI算法管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(AiRule aiRule)
    {
        startPage();
        List<AiRule> list = aiRuleService.selectAiRuleList(aiRule);
        return getDataTable(list);
    }
 
    /**
     * 导出AI算法管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:rule:export')")
    @Log(title = "AI算法管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AiRule aiRule)
    {
        List<AiRule> list = aiRuleService.selectAiRuleList(aiRule);
        for(AiRule rule:list){
            String ruleTypeName=sysDictDataService.selectDictLabel("sys_alarm_small_type",rule.getRuleType());
            rule.setRuleTypeName(ruleTypeName);
        }
        ExcelUtil<AiRule> util = new ExcelUtil<AiRule>(AiRule.class);
        util.exportExcel(response, list, "AI算法管理数据");
    }
 
    /**
     * 获取AI算法管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aiRuleService.selectAiRuleById(id));
    }
 
    /**
     * 新增AI算法管理
     */
    @PreAuthorize("@ss.hasPermi('system:rule:add')")
    @Log(title = "AI算法管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AiRule aiRule)
    {
        Date date =new Date();
        aiRule.setCreateBy(getUsername());
        aiRule.setCreateTime(date);
        aiRule.setDelFlag(0);
        String timeStr1= LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        String str="";
        //把随机生成的数字转成字符串
        str=getNum(str);
        while (true){
            boolean flag=aiRuleService.findByRuleNum("AI"+timeStr1+str);
            if(flag==true){
                str=getNum(str);
            }else{
                break;
            }
        }
        aiRule.setRuleNum("AI"+timeStr1+str);
 
 
        return toAjax(aiRuleService.insertAiRule(aiRule));
    }
 
    /**
     * 修改AI算法管理
     */
    @PreAuthorize("@ss.hasPermi('system:rule:edit')")
    @Log(title = "AI算法管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AiRule aiRule)
    {
        aiRule.setUpdateBy(getUsername());
        aiRule.setUpdateTime(new Date());
        aiRule.setDelFlag(0);
        return toAjax(aiRuleService.updateAiRule(aiRule));
    }
 
    /**
     * 删除AI算法管理
     */
    @PreAuthorize("@ss.hasPermi('system:rule:remove')")
    @Log(title = "AI算法管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aiRuleService.deleteAiRuleByIds(ids,getUsername(),new Date()));
    }
    /**
     * 下拉查询算法名称
     */
    @GetMapping("/selectList")
    public TableDataInfo selectList(AiRule aiRule)
    {
        aiRule.setRuleStatus("Y");
        List<AiRule> list = aiRuleService.selectAiRuleList(aiRule);
        return getDataTable(list);
    }
    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('system:rule:edit')")
    @Log(title = "算法管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody AiRule aiRule)
    {
        aiRule.setUpdateBy(getUsername());
        return toAjax(aiRuleService.updateRuleStatus(aiRule));
    }
    /**
     * 向前台发送当前用户的DeptId
     */
    @Log(title = "算法管理", businessType = BusinessType.UPDATE)
    @PutMapping("/sendDeptId")
    public AjaxResult sendDeptId()
    {
        getDeptId().toString();
        return success(Integer.parseInt(getDeptId().toString()));
    }
 
    public String getNum(String str){
        Random random=new Random();
        str = String.valueOf(random.nextInt(9));
        for (int i = 0; i < 5; i++) {
            str += random.nextInt(9);
        }
        return str;
    }
}