|
|
@@ -0,0 +1,249 @@
|
|
|
+package com.sooka.sponest.monitor.ai.controller;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.dahuatech.hutool.http.Method;
|
|
|
+import com.dahuatech.icc.exception.ClientException;
|
|
|
+import com.dahuatech.icc.oauth.model.v202010.GeneralResponse;
|
|
|
+import com.dahuatech.icc.oauth.model.v202010.OauthConfigUserPwdInfo;
|
|
|
+import com.dahuatech.icc.oauth.utils.HttpUtils;
|
|
|
+import com.ruoyi.common.core.constant.UserConstants;
|
|
|
+import com.ruoyi.common.core.utils.uuid.IdUtils;
|
|
|
+import com.ruoyi.common.core.web.controller.BaseController;
|
|
|
+import com.ruoyi.common.core.web.domain.AjaxResult;
|
|
|
+import com.ruoyi.common.core.web.page.TableDataInfo;
|
|
|
+import com.ruoyi.common.security.annotation.RequiresPermissions;
|
|
|
+import com.sooka.sponest.monitor.ai.domain.BusAiSingleType;
|
|
|
+import com.sooka.sponest.monitor.ai.service.IBusAiSingleTypeService;
|
|
|
+import com.sooka.sponest.monitor.ai.util.DHOauthUtil;
|
|
|
+import org.apache.commons.collections4.MapUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 报警类型Controller
|
|
|
+ *
|
|
|
+ * @author lyq
|
|
|
+ * @date 2025-09-15
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/admin-api/ai/singletype")
|
|
|
+public class BusAiSingleTypeController extends BaseController
|
|
|
+{
|
|
|
+ @Autowired
|
|
|
+ private IBusAiSingleTypeService busAiSingleTypeService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同步报警类型
|
|
|
+ */
|
|
|
+ @RequiresPermissions("ai:singletype:list")
|
|
|
+ @GetMapping("/sync")
|
|
|
+ public AjaxResult sync()
|
|
|
+ {
|
|
|
+ List<Long> alarmTypeList = new ArrayList<>();
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("pageNum", 1);
|
|
|
+ params.put("pageSize", 500);
|
|
|
+
|
|
|
+ OauthConfigUserPwdInfo config = DHOauthUtil.getInstance().getOauthConfig();
|
|
|
+ GeneralResponse response = null;
|
|
|
+ while (true) {
|
|
|
+ try {
|
|
|
+ response = HttpUtils.executeJson("/evo-apigw/evo-event/1.0.0/alarm/types/page", params, null, Method.POST, config, GeneralResponse.class);
|
|
|
+ } catch (ClientException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ JSONObject result = JSONObject.parseObject(response.getResult());
|
|
|
+ if (result.getBoolean("success")) {
|
|
|
+ List<Long> types = JSONObject.parseArray(result.getJSONObject("data").getString("pageData"), BusAiSingleType.class).stream().map(BusAiSingleType::getAlarmType).collect(Collectors.toList());
|
|
|
+ if (types.isEmpty()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ alarmTypeList.addAll(types);
|
|
|
+ params.put("pageNum", MapUtils.getInteger(params, "pageNum") + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int num = 0;
|
|
|
+ String url = "/evo-apigw/evo-event/1.0.0/alarm/single-type";
|
|
|
+ List<BusAiSingleType> busAiSingleTypes = busAiSingleTypeService.selectBusAiSingleTypeList(new BusAiSingleType());
|
|
|
+ for (BusAiSingleType item : busAiSingleTypes) {
|
|
|
+ if (alarmTypeList.contains(item.getAlarmType())) {
|
|
|
+ try {
|
|
|
+ response = HttpUtils.executeJson(url, item, null, Method.PUT, config, GeneralResponse.class);
|
|
|
+ } catch (ClientException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ response = HttpUtils.executeJson(url, item, null, Method.POST, config, GeneralResponse.class);
|
|
|
+ } catch (ClientException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONObject result = JSONObject.parseObject(response.getResult());
|
|
|
+ if (result.getBoolean("success")) {
|
|
|
+ item.setSyncStatus("1");
|
|
|
+ busAiSingleTypeService.updateBusAiSingleType(item);
|
|
|
+ num++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return num > 0 ? success() : error();
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequiresPermissions("ai:singletype:list")
|
|
|
+ @GetMapping("/syncDH")
|
|
|
+ public AjaxResult syncDH()
|
|
|
+ {
|
|
|
+ List<BusAiSingleType> busAiSingleTypes = new ArrayList<>();
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("pageNum", 1);
|
|
|
+ params.put("pageSize", 500);
|
|
|
+
|
|
|
+ OauthConfigUserPwdInfo config = DHOauthUtil.getInstance().getOauthConfig();
|
|
|
+ GeneralResponse response = null;
|
|
|
+ while (true) {
|
|
|
+ try {
|
|
|
+ response = HttpUtils.executeJson("/evo-apigw/evo-event/1.0.0/alarm/types/page", params, null, Method.POST, config, GeneralResponse.class);
|
|
|
+ } catch (ClientException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ JSONObject result = JSONObject.parseObject(response.getResult());
|
|
|
+ if (result.getBoolean("success")) {
|
|
|
+ List<BusAiSingleType> types = JSONObject.parseArray(result.getJSONObject("data").getString("pageData"), BusAiSingleType.class);
|
|
|
+ if (types.isEmpty()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ busAiSingleTypes.addAll(types);
|
|
|
+ params.put("pageNum", MapUtils.getInteger(params, "pageNum") + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int num = 0;
|
|
|
+ List<Long> alarmTypeList = busAiSingleTypeService.selectBusAiSingleTypeList(new BusAiSingleType()).stream().map(BusAiSingleType::getAlarmType).collect(Collectors.toList());
|
|
|
+ List<JSONObject> list = (List<JSONObject>) listAffiliation().get("data");
|
|
|
+ for (BusAiSingleType item : busAiSingleTypes) {
|
|
|
+ item.setSyncStatus("1");
|
|
|
+ if (alarmTypeList.contains(item.getAlarmType())) {
|
|
|
+ busAiSingleTypeService.updateByAlarmType(item);
|
|
|
+ } else {
|
|
|
+ item.setId(IdUtils.fastSimpleUUID());
|
|
|
+ item.setLanguage("zh-CN");
|
|
|
+ item.setAffiliationName(item.getAffiliationName().split(",")[0]);
|
|
|
+ item.setAffiliation(list.stream().filter(i -> i.getString("affiliationName").equals(item.getAffiliationName())).findFirst().get().getInteger("affiliation"));
|
|
|
+ busAiSingleTypeService.insertBusAiSingleType(item);
|
|
|
+ }
|
|
|
+ num++;
|
|
|
+ }
|
|
|
+ return num > 0 ? success() : error();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询报警类型列表
|
|
|
+ */
|
|
|
+ @RequiresPermissions("ai:singletype:list")
|
|
|
+ @GetMapping("/list")
|
|
|
+ public TableDataInfo list(BusAiSingleType busAiSingleType)
|
|
|
+ {
|
|
|
+ startPage();
|
|
|
+ List<BusAiSingleType> list = busAiSingleTypeService.selectBusAiSingleTypeList(busAiSingleType);
|
|
|
+ return getDataTable(list);
|
|
|
+ }
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 导出报警类型列表
|
|
|
+// */
|
|
|
+// @PreAuthorize("@ss.hasPermission('ai:singletype:export')")
|
|
|
+// @Log(title = "报警类型", businessType = BusinessType.EXPORT)
|
|
|
+// @PostMapping("/export")
|
|
|
+// public void export(HttpServletResponse response, BusAiSingleType busAiSingleType)
|
|
|
+// {
|
|
|
+// List<BusAiSingleType> list = busAiSingleTypeService.selectBusAiSingleTypeList(busAiSingleType);
|
|
|
+// ExcelUtil<BusAiSingleType> util = new ExcelUtil<BusAiSingleType>(BusAiSingleType.class);
|
|
|
+// util.exportExcel(response, list, "报警类型数据");
|
|
|
+// }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取报警类型详细信息
|
|
|
+ */
|
|
|
+ @RequiresPermissions("ai:singletype:query")
|
|
|
+ @GetMapping(value = "/{id}")
|
|
|
+ public AjaxResult getInfo(@PathVariable("id") String id)
|
|
|
+ {
|
|
|
+ return success(busAiSingleTypeService.selectBusAiSingleTypeById(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增报警类型
|
|
|
+ */
|
|
|
+ @RequiresPermissions("ai:singletype:add")
|
|
|
+ @PostMapping
|
|
|
+ public AjaxResult add(@RequestBody BusAiSingleType busAiSingleType, HttpServletRequest request)
|
|
|
+ {
|
|
|
+ if (UserConstants.NOT_UNIQUE.equals(busAiSingleTypeService.checkAlarmTypeUnique(busAiSingleType))) {
|
|
|
+ return error("新增报警类型失败,报警编号'" + busAiSingleType.getAlarmType() + "'已存在");
|
|
|
+ }
|
|
|
+ if (UserConstants.NOT_UNIQUE.equals(busAiSingleTypeService.checkAlarmTypeNameUnique(busAiSingleType))) {
|
|
|
+ return error("新增报警类型'" + busAiSingleType.getAlarmTypeName() + "'失败,名称已存在");
|
|
|
+ }
|
|
|
+ busAiSingleType.setLanguage(request.getHeader("Accept-Language").split(",")[0]);
|
|
|
+ return busAiSingleTypeService.insertBusAiSingleType(busAiSingleType) > 0 ? success() : error();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改报警类型
|
|
|
+ */
|
|
|
+ @RequiresPermissions("ai:singletype:edit")
|
|
|
+ @PutMapping
|
|
|
+ public AjaxResult edit(@RequestBody BusAiSingleType busAiSingleType)
|
|
|
+ {
|
|
|
+ if (UserConstants.NOT_UNIQUE.equals(busAiSingleTypeService.checkAlarmTypeNameUnique(busAiSingleType))) {
|
|
|
+ return error("修改报警类型'" + busAiSingleType.getAlarmTypeName() + "'失败,名称已存在");
|
|
|
+ }
|
|
|
+ return busAiSingleTypeService.updateBusAiSingleType(busAiSingleType) > 0 ? success() : error();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除报警类型
|
|
|
+ */
|
|
|
+ @RequiresPermissions("ai:singletype:remove")
|
|
|
+ @DeleteMapping("/{ids}")
|
|
|
+ public AjaxResult remove(@PathVariable String[] ids)
|
|
|
+ {
|
|
|
+ BusAiSingleType singleType = busAiSingleTypeService.selectBusAiSingleTypeById(ids[0]);
|
|
|
+ OauthConfigUserPwdInfo config = DHOauthUtil.getInstance().getOauthConfig();
|
|
|
+ try {
|
|
|
+ HttpUtils.executeJson("/evo-apigw/evo-event/1.0.0/alarm/single-type?alarmType=" + singleType.getAlarmType(), null, null, Method.DELETE, config, GeneralResponse.class);
|
|
|
+ } catch (ClientException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return busAiSingleTypeService.deleteBusAiSingleTypeByIds(ids) > 0 ? success() : error();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询归属列表
|
|
|
+ */
|
|
|
+ @RequiresPermissions("ai:singletype:list")
|
|
|
+ @GetMapping("/listAffiliation")
|
|
|
+ public AjaxResult listAffiliation()
|
|
|
+ {
|
|
|
+ String url = "/evo-apigw/evo-event/1.0.0/alarm/types/affiliation";
|
|
|
+ OauthConfigUserPwdInfo config = DHOauthUtil.getInstance().getOauthConfig();
|
|
|
+ GeneralResponse response = null;
|
|
|
+ try {
|
|
|
+ response = HttpUtils.executeJson(url, null, null, Method.GET, config, GeneralResponse.class);
|
|
|
+ } catch (ClientException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ List<JSONObject> resultList = new ArrayList();
|
|
|
+ JSONObject result = JSONObject.parseObject(response.getResult());
|
|
|
+ if (result.getBoolean("success")) {
|
|
|
+ resultList = JSONObject.parseArray(result.getJSONObject("data").getString("affiliationList"), JSONObject.class);
|
|
|
+ }
|
|
|
+ return success(resultList);
|
|
|
+ }
|
|
|
+}
|