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 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 list = aiRuleService.selectAiRuleList(aiRule); for(AiRule rule:list){ String ruleTypeName=sysDictDataService.selectDictLabel("sys_alarm_small_type",rule.getRuleType()); rule.setRuleTypeName(ruleTypeName); } ExcelUtil util = new ExcelUtil(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 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; } }