44 changed files with 2436 additions and 270 deletions
@ -1 +0,0 @@ |
|||
1=magic 2=NDC 3=XZ 4=ZHEDA |
@ -0,0 +1,84 @@ |
|||
package org.nl.acs.device_driver.basedriver.agv.utils; |
|||
|
|||
|
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
|
|||
/** |
|||
* AGV系统类型 1:Magvic 2:NDC 3:先知 4:浙大 |
|||
*/ |
|||
public enum AgvSystemEnum { |
|||
Maigic(1, "Maigic", "Maigic系统"), |
|||
NDC(2, "NDC", "NDC系统"), |
|||
XianGong(3, "XianGong", "仙工系统"), |
|||
ZheDa(4, "ZheDa", "浙大系统"); |
|||
|
|||
//索引
|
|||
private int index; |
|||
//编码
|
|||
private String code; |
|||
//名字
|
|||
private String name; |
|||
//描述
|
|||
private String desc; |
|||
|
|||
// 构造方法
|
|||
AgvSystemEnum(int index, String code, String name) { |
|||
this.index = index; |
|||
this.code = code; |
|||
this.name = name; |
|||
|
|||
} |
|||
|
|||
public static JSONArray getList() { |
|||
JSONArray arr = new JSONArray(); |
|||
JSONObject json = new JSONObject(); |
|||
for (AgvSystemEnum em : AgvSystemEnum.values()) { |
|||
json.put("code", em.getCode()); |
|||
json.put("name", em.getName()); |
|||
arr.add(json); |
|||
} |
|||
return arr; |
|||
} |
|||
|
|||
public String getCode() { |
|||
return code; |
|||
} |
|||
|
|||
public void setCode(String code) { |
|||
this.code = code; |
|||
} |
|||
|
|||
public String getName() { |
|||
return name; |
|||
} |
|||
|
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
|
|||
public String getDesc() { |
|||
return desc; |
|||
} |
|||
|
|||
public void setDesc(String desc) { |
|||
this.desc = desc; |
|||
} |
|||
|
|||
public static String getName(String code) { |
|||
for (AgvSystemEnum c : AgvSystemEnum.values()) { |
|||
if (c.code == code) { |
|||
return c.name; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
public int getIndex() { |
|||
return index; |
|||
} |
|||
|
|||
public void setIndex(int index) { |
|||
this.index = index; |
|||
} |
|||
} |
@ -0,0 +1,123 @@ |
|||
package org.nl.acs.history; |
|||
|
|||
import cn.hutool.core.util.ObjectUtil; |
|||
import cn.hutool.core.util.StrUtil; |
|||
import org.nl.modules.system.domain.Dict; |
|||
import org.nl.modules.system.service.DictDetailService; |
|||
import org.nl.modules.system.service.DictService; |
|||
import org.nl.modules.system.service.dto.DictDetailDto; |
|||
import org.nl.modules.system.service.impl.DictDetailServiceImpl; |
|||
import org.nl.modules.system.service.impl.DictServiceImpl; |
|||
import org.nl.modules.wql.util.SpringContextHolder; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.concurrent.ConcurrentHashMap; |
|||
import java.util.function.Function; |
|||
import java.util.stream.Collectors; |
|||
|
|||
/** |
|||
* @author: geng by |
|||
* @createDate: 2023/3/15 |
|||
*/ |
|||
public class ErrorUtil { |
|||
|
|||
public static ConcurrentHashMap<String, List<DictDetailDto>> dictMap = new ConcurrentHashMap<>(); |
|||
|
|||
|
|||
public static String getDictDetail(String type, String error_code) { |
|||
getDict(); |
|||
List<DictDetailDto> dictDetailDtos = dictMap.get(type); |
|||
String detail = null; |
|||
if (ObjectUtil.isNotEmpty(dictDetailDtos)) { |
|||
for (int i = 0; i < dictDetailDtos.size(); i++) { |
|||
DictDetailDto dictDetailDto = dictDetailDtos.get(i); |
|||
String value = dictDetailDto.getValue(); |
|||
String label = dictDetailDto.getLabel(); |
|||
if (StrUtil.equals(value, error_code)) { |
|||
detail = label; |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
return detail == null ? "字典表未配置对应的报警信息" : detail; |
|||
} |
|||
|
|||
public static Map<Integer, String> getDictDetailByName(String type) { |
|||
getDict(); |
|||
List<DictDetailDto> dictDetailDtos = dictMap.get(type); |
|||
Map<Integer, String> map = new HashMap<>(); |
|||
if (ObjectUtil.isNotEmpty(dictDetailDtos)) { |
|||
List<DictDetailDto> dtos = dictDetailDtos |
|||
.stream() |
|||
.filter(dictDetailDto -> !dictDetailDto.getValue().equals("0")) |
|||
.filter(dictDetailDto -> !dictDetailDto.getValue().equals("-1")) |
|||
.collect(Collectors.toList()); |
|||
dtos.forEach(dictDetailDto -> map.put(Integer.parseInt(dictDetailDto.getValue()), dictDetailDto.getLabel())); |
|||
} |
|||
return map; |
|||
} |
|||
|
|||
|
|||
public static void getDict() { |
|||
if (ObjectUtil.isEmpty(dictMap)) { |
|||
DictDetailService dictDetailService = SpringContextHolder.getBean(DictDetailServiceImpl.class); |
|||
DictService dictService = SpringContextHolder.getBean(DictServiceImpl.class); |
|||
List<Dict> dictDtos = dictService.queryAll(); |
|||
for (int i = 0; i < dictDtos.size(); i++) { |
|||
Dict dictDto = dictDtos.get(i); |
|||
dictMap.put(dictDto.getName(), getDict(dictDto.getName(), t -> { |
|||
return dictDetailService.getDictByName(t); |
|||
})); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public static List<DictDetailDto> getDict(String name, Function<String, List<DictDetailDto>> f) { |
|||
return f.apply(name); |
|||
} |
|||
|
|||
public static Map<String, String> getAgvErrorMsg(Integer ageErrorNum) { |
|||
Map<Integer, String> agvMap = getDictDetailByName("agv_error_type"); |
|||
Integer[] keys = agvMap.keySet().toArray(new Integer[0]); |
|||
String message = ""; |
|||
String code = ""; |
|||
out: |
|||
for (int i = 1; i < 1 << keys.length; i++) { |
|||
int sum = 0; |
|||
StringBuffer sb = new StringBuffer(); |
|||
StringBuffer sbCode = new StringBuffer(); |
|||
inner: |
|||
for (int j = 0; j < keys.length; j++) { |
|||
if ((i & 1 << j) != 0) { |
|||
sum += keys[j]; |
|||
sb.append(agvMap.get(keys[j])).append(","); |
|||
sbCode.append(keys[j]).append(","); |
|||
} |
|||
} |
|||
if (sum == ageErrorNum) { |
|||
code = sbCode.toString(); |
|||
message = sb.toString(); |
|||
break out; |
|||
} |
|||
} |
|||
Map<String, String> map = new HashMap<>(); |
|||
String info = replace(message); |
|||
code = replace(code); |
|||
map.put("code", StrUtil.isEmpty(code) ? "-1" : code); |
|||
map.put("info", StrUtil.isEmpty(info) ? "AGV上报报警代码有误" : info); |
|||
return map; |
|||
} |
|||
|
|||
public static String replace(String message) { |
|||
if (StrUtil.isEmpty(message)) { |
|||
return null; |
|||
} |
|||
if (message.endsWith(",")) { |
|||
return message.substring(0, message.length() - 1); |
|||
} |
|||
return message; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,77 @@ |
|||
|
|||
package org.nl.acs.history.rest; |
|||
|
|||
|
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.nl.acs.history.service.DeviceErrorLogService; |
|||
import org.nl.acs.history.service.dto.DeviceErrorLogDto; |
|||
import org.nl.modules.logging.annotation.Log; |
|||
import org.springframework.data.domain.Pageable; |
|||
import org.springframework.http.HttpStatus; |
|||
import org.springframework.http.ResponseEntity; |
|||
import org.springframework.validation.annotation.Validated; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import javax.servlet.http.HttpServletResponse; |
|||
import java.io.IOException; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @author gengby |
|||
* @date 2023-03-15 |
|||
**/ |
|||
@RestController |
|||
@RequiredArgsConstructor |
|||
@Api(tags = "设备报警记录管理") |
|||
@RequestMapping("/api/deviceErrorLog") |
|||
@Slf4j |
|||
public class DeviceErrorLogController { |
|||
|
|||
private final DeviceErrorLogService acsDeviceErrorLogService; |
|||
|
|||
@GetMapping |
|||
@Log("查询设备报警记录") |
|||
@ApiOperation("查询设备报警记录") |
|||
//@PreAuthorize("@el.check('acsDeviceErrorLog:list')")
|
|||
public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page){ |
|||
return new ResponseEntity<>(acsDeviceErrorLogService.queryAll(whereJson,page),HttpStatus.OK); |
|||
} |
|||
|
|||
@PostMapping |
|||
@Log("新增设备报警记录") |
|||
@ApiOperation("新增设备报警记录") |
|||
//@PreAuthorize("@el.check('acsDeviceErrorLog:add')")
|
|||
public ResponseEntity<Object> create(@Validated @RequestBody DeviceErrorLogDto dto){ |
|||
acsDeviceErrorLogService.create(dto); |
|||
return new ResponseEntity<>(HttpStatus.CREATED); |
|||
} |
|||
|
|||
@PutMapping |
|||
@Log("修改设备报警记录") |
|||
@ApiOperation("修改设备报警记录") |
|||
//@PreAuthorize("@el.check('acsDeviceErrorLog:edit')")
|
|||
public ResponseEntity<Object> update(@Validated @RequestBody DeviceErrorLogDto dto){ |
|||
acsDeviceErrorLogService.update(dto); |
|||
return new ResponseEntity<>(HttpStatus.NO_CONTENT); |
|||
} |
|||
|
|||
@Log("删除设备报警记录") |
|||
@ApiOperation("删除设备报警记录") |
|||
//@PreAuthorize("@el.check('acsDeviceErrorLog:del')")
|
|||
@DeleteMapping |
|||
public ResponseEntity<Object> delete(@RequestBody String[] ids) { |
|||
acsDeviceErrorLogService.deleteAll(ids); |
|||
return new ResponseEntity<>(HttpStatus.OK); |
|||
} |
|||
|
|||
@Log("导出设备报警记录") |
|||
@ApiOperation("导出设备报警记录") |
|||
@GetMapping(value = "/download") |
|||
//@PreAuthorize("@el.check('acsDeviceErrorLog:list')")
|
|||
public void download(HttpServletResponse response, @RequestParam Map whereJson) throws IOException { |
|||
acsDeviceErrorLogService.download(acsDeviceErrorLogService.queryAll(whereJson), response); |
|||
} |
|||
} |
@ -0,0 +1,74 @@ |
|||
|
|||
package org.nl.acs.history.service; |
|||
|
|||
import org.nl.acs.history.service.dto.DeviceErrorLogDto; |
|||
import org.springframework.data.domain.Pageable; |
|||
|
|||
import javax.servlet.http.HttpServletResponse; |
|||
import java.io.IOException; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @description 服务接口 |
|||
* @author gengby |
|||
* @date 2023-03-15 |
|||
**/ |
|||
public interface DeviceErrorLogService { |
|||
|
|||
/** |
|||
* 查询数据分页 |
|||
* @param whereJson 条件 |
|||
* @param page 分页参数 |
|||
* @return Map<String,Object> |
|||
*/ |
|||
Map<String,Object> queryAll(Map whereJson, Pageable page); |
|||
|
|||
/** |
|||
* 查询所有数据不分页 |
|||
* @param whereJson 条件参数 |
|||
* @return List<AcsDeviceErrorLogDto> |
|||
*/ |
|||
List<DeviceErrorLogDto> queryAll(Map whereJson); |
|||
|
|||
/** |
|||
* 根据ID查询 |
|||
* @param error_log_uuid ID |
|||
* @return AcsDeviceErrorLog |
|||
*/ |
|||
DeviceErrorLogDto findById(String error_log_uuid); |
|||
|
|||
/** |
|||
* 根据编码查询 |
|||
* @param code code |
|||
* @return AcsDeviceErrorLog |
|||
*/ |
|||
DeviceErrorLogDto findByCode(String code); |
|||
|
|||
|
|||
/** |
|||
* 创建 |
|||
* @param dto / |
|||
*/ |
|||
void create(DeviceErrorLogDto dto); |
|||
|
|||
/** |
|||
* 编辑 |
|||
* @param dto / |
|||
*/ |
|||
void update(DeviceErrorLogDto dto); |
|||
|
|||
/** |
|||
* 多选删除 |
|||
* @param ids / |
|||
*/ |
|||
void deleteAll(String[] ids); |
|||
|
|||
/** |
|||
* 导出数据 |
|||
* @param dtos 待导出的数据 |
|||
* @param response / |
|||
* @throws IOException / |
|||
*/ |
|||
void download(List<DeviceErrorLogDto> dtos, HttpServletResponse response) throws IOException; |
|||
} |
@ -0,0 +1,29 @@ |
|||
package org.nl.acs.history.service.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @description / |
|||
* @author gengby |
|||
* @date 2023-03-15 |
|||
**/ |
|||
@Data |
|||
public class DeviceErrorLogDto implements Serializable { |
|||
|
|||
/** 报警日志标识 */ |
|||
private String error_log_uuid; |
|||
|
|||
/** 设备编码 */ |
|||
private String device_code; |
|||
|
|||
/** 报警编码 */ |
|||
private String error_code; |
|||
|
|||
/** 报警信息 */ |
|||
private String error_info; |
|||
|
|||
/** 报警时间 */ |
|||
private String error_time; |
|||
} |
@ -0,0 +1,137 @@ |
|||
|
|||
package org.nl.acs.history.service.impl; |
|||
|
|||
|
|||
import cn.hutool.core.date.DateUtil; |
|||
import cn.hutool.core.map.MapUtil; |
|||
import cn.hutool.core.util.IdUtil; |
|||
import cn.hutool.core.util.StrUtil; |
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.nl.acs.history.service.DeviceErrorLogService; |
|||
import org.nl.acs.history.service.dto.DeviceErrorLogDto; |
|||
import org.nl.modules.common.exception.BadRequestException; |
|||
import org.nl.modules.common.utils.FileUtil; |
|||
import org.nl.modules.common.utils.SecurityUtils; |
|||
import org.nl.modules.wql.core.bean.ResultBean; |
|||
import org.nl.modules.wql.core.bean.WQLObject; |
|||
import org.nl.modules.wql.util.WqlUtil; |
|||
import org.springframework.data.domain.Pageable; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import javax.servlet.http.HttpServletResponse; |
|||
import java.io.IOException; |
|||
import java.util.ArrayList; |
|||
import java.util.LinkedHashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @author gengby |
|||
* @description 服务实现 |
|||
* @date 2023-03-15 |
|||
**/ |
|||
@Service |
|||
@RequiredArgsConstructor |
|||
@Slf4j |
|||
public class DeviceErrorLogServiceImpl implements DeviceErrorLogService { |
|||
|
|||
@Override |
|||
public Map<String, Object> queryAll(Map whereJson, Pageable page) { |
|||
String device_code = MapUtil.getStr(whereJson, "device_code"); |
|||
String error_code = MapUtil.getStr(whereJson, "error_code"); |
|||
String error_info = MapUtil.getStr(whereJson, "error_info"); |
|||
WQLObject wo = WQLObject.getWQLObject("acs_device_error_log"); |
|||
String where = "1 = 1 "; |
|||
if (StrUtil.isNotEmpty(device_code)) { |
|||
where += "and device_code like '%" + device_code + "%'"; |
|||
} |
|||
if (StrUtil.isNotEmpty(error_code)) { |
|||
where += "and error_code like '%" + error_code + "%'"; |
|||
} |
|||
if (StrUtil.isNotEmpty(error_info)) { |
|||
where += "and error_info like '%" + error_info + "%'"; |
|||
} |
|||
ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), where, "error_time desc"); |
|||
final JSONObject json = rb.pageResult(); |
|||
return json; |
|||
} |
|||
|
|||
@Override |
|||
public List<DeviceErrorLogDto> queryAll(Map whereJson) { |
|||
WQLObject wo = WQLObject.getWQLObject("acs_device_error_log"); |
|||
JSONArray arr = wo.query().getResultJSONArray(0); |
|||
List<DeviceErrorLogDto> list = arr.toJavaList(DeviceErrorLogDto.class); |
|||
return list; |
|||
} |
|||
|
|||
@Override |
|||
public DeviceErrorLogDto findById(String error_log_uuid) { |
|||
WQLObject wo = WQLObject.getWQLObject("acs_device_error_log"); |
|||
JSONObject json = wo.query("error_log_uuid ='" + error_log_uuid + "'").uniqueResult(0); |
|||
final DeviceErrorLogDto obj = (DeviceErrorLogDto) JSONObject.toJavaObject(json, DeviceErrorLogDto.class); |
|||
return obj; |
|||
} |
|||
|
|||
@Override |
|||
public DeviceErrorLogDto findByCode(String code) { |
|||
WQLObject wo = WQLObject.getWQLObject("acs_device_error_log"); |
|||
JSONObject json = wo.query("code ='" + code + "'").uniqueResult(0); |
|||
final DeviceErrorLogDto obj = (DeviceErrorLogDto) JSONObject.toJavaObject(json, DeviceErrorLogDto.class); |
|||
return obj; |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public void create(DeviceErrorLogDto dto) { |
|||
String currentUsername = SecurityUtils.getCurrentUsername(); |
|||
String now = DateUtil.now(); |
|||
|
|||
dto.setError_log_uuid(IdUtil.simpleUUID()); |
|||
dto.setDevice_code(dto.getDevice_code()); |
|||
dto.setError_code(dto.getError_code()); |
|||
dto.setError_info(dto.getError_info()); |
|||
dto.setError_time(now); |
|||
WQLObject wo = WQLObject.getWQLObject("acs_device_error_log"); |
|||
JSONObject json = (JSONObject) JSONObject.toJSON(dto); |
|||
wo.insert(json); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public void update(DeviceErrorLogDto dto) { |
|||
DeviceErrorLogDto entity = this.findById(dto.getError_log_uuid()); |
|||
if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!"); |
|||
String currentUsername = SecurityUtils.getCurrentUsername(); |
|||
String now = DateUtil.now(); |
|||
WQLObject wo = WQLObject.getWQLObject("acs_device_error_log"); |
|||
JSONObject json = (JSONObject) JSONObject.toJSON(dto); |
|||
wo.update(json); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public void deleteAll(String[] ids) { |
|||
WQLObject wo = WQLObject.getWQLObject("acs_device_error_log"); |
|||
for (String error_log_uuid : ids) { |
|||
wo.delete("error_log_uuid = '" + error_log_uuid + "'"); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void download(List<DeviceErrorLogDto> all, HttpServletResponse response) throws IOException { |
|||
List<Map<String, Object>> list = new ArrayList<>(); |
|||
for (DeviceErrorLogDto acsDeviceErrorLog : all) { |
|||
Map<String, Object> map = new LinkedHashMap<>(); |
|||
map.put("设备编码", acsDeviceErrorLog.getDevice_code()); |
|||
map.put("报警编码", acsDeviceErrorLog.getError_code()); |
|||
map.put("报警信息", acsDeviceErrorLog.getError_info()); |
|||
map.put("报警时间", acsDeviceErrorLog.getError_time()); |
|||
list.add(map); |
|||
} |
|||
FileUtil.downloadExcel(list, response); |
|||
} |
|||
} |
@ -0,0 +1,47 @@ |
|||
|
|||
package org.nl.acs.udw.rest; |
|||
|
|||
|
|||
import cn.dev33.satoken.annotation.SaIgnore; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.nl.acs.udw.service.UdwManageService; |
|||
import org.nl.modules.logging.annotation.Log; |
|||
import org.springframework.data.domain.Pageable; |
|||
import org.springframework.http.HttpStatus; |
|||
import org.springframework.http.ResponseEntity; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import java.util.Map; |
|||
|
|||
@RestController |
|||
@RequiredArgsConstructor |
|||
@Api(tags = "内存点位管理") |
|||
@RequestMapping("/api/udw") |
|||
@Slf4j |
|||
public class UdwManagerController { |
|||
|
|||
private final UdwManageService udwManageService; |
|||
|
|||
// @GetMapping
|
|||
// @Log("查询内存点位")
|
|||
// @ApiOperation("查询内存点位")
|
|||
// @SaIgnore
|
|||
// public ResponseEntity<Object> query(@RequestParam JSONObject whereJson) {
|
|||
// return new ResponseEntity<>(udwManageService.queryByConditions(whereJson), HttpStatus.OK);
|
|||
// }
|
|||
|
|||
@GetMapping |
|||
@Log("查询内存点位") |
|||
@ApiOperation("查询内存点位") |
|||
@SaIgnore |
|||
//@PreAuthorize("@el.check('device:list')")
|
|||
public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page) { |
|||
return new ResponseEntity<>(udwManageService.queryAll(whereJson, page), HttpStatus.OK); |
|||
} |
|||
} |
@ -1,16 +1,157 @@ |
|||
package org.nl.acs.udw.service.impl; |
|||
|
|||
import cn.hutool.core.util.StrUtil; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import org.nl.acs.task.service.dto.TaskDto; |
|||
import org.nl.acs.udw.UnifiedData; |
|||
import org.nl.acs.udw.UnifiedDataAccessorFactory; |
|||
import org.nl.acs.udw.dto.UdwDto; |
|||
import org.nl.acs.udw.service.UdwManageService; |
|||
import org.springframework.data.domain.Pageable; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.Iterator; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.stream.Collectors; |
|||
|
|||
@Service |
|||
public class UdwManagerServiceImpl implements UdwManageService { |
|||
|
|||
public UdwManagerServiceImpl() { |
|||
} |
|||
|
|||
@Override |
|||
public List<UdwDto> queryByConditions(JSONObject where) { |
|||
return null; |
|||
String unified_key = null; |
|||
String keys = null; |
|||
|
|||
UnifiedDataUnit unifiedDataUnit = UnifiedDataAccessorFactory.getUnifiedDataAppService().getUnifiedDataUnit(unified_key); |
|||
if (unifiedDataUnit == null) { |
|||
return null; |
|||
} else { |
|||
String key; |
|||
UdwDto udwDto; |
|||
Map storage; |
|||
ArrayList udwDtos; |
|||
Iterator var14; |
|||
if (keys != null) { |
|||
storage = unifiedDataUnit.getStorage(); |
|||
udwDtos = new ArrayList(); |
|||
var14 = storage.keySet().iterator(); |
|||
|
|||
while(var14.hasNext()) { |
|||
key = (String)var14.next(); |
|||
if (key.indexOf(keys) != -1) { |
|||
udwDto = new UdwDto(); |
|||
udwDto.setUnified_key(unified_key); |
|||
udwDto.setKey(key); |
|||
udwDto.setValue(((UnifiedData)storage.get(key)).getValue()); |
|||
udwDtos.add(udwDto); |
|||
} |
|||
} |
|||
|
|||
return udwDtos; |
|||
} else { |
|||
storage = unifiedDataUnit.getStorage(); |
|||
udwDtos = new ArrayList(); |
|||
var14 = storage.keySet().iterator(); |
|||
|
|||
while(var14.hasNext()) { |
|||
key = (String)var14.next(); |
|||
udwDto = new UdwDto(); |
|||
udwDto.setUnified_key(unified_key); |
|||
udwDto.setKey(key); |
|||
udwDto.setValue(((UnifiedData)storage.get(key)).getValue()); |
|||
udwDtos.add(udwDto); |
|||
} |
|||
|
|||
return udwDtos; |
|||
} |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public Map<String, Object> queryAll(Map whereJson, Pageable page) { |
|||
|
|||
String unified_key = (String) whereJson.get("unified_key"); |
|||
String keys = (String) whereJson.get("code"); |
|||
if(StrUtil.isEmpty(unified_key)) |
|||
{ |
|||
unified_key = "opc_value"; |
|||
} |
|||
// String unified_key = (String) whereJson.get("unified_key");
|
|||
// String code = (String) whereJson.get("code");
|
|||
|
|||
// unified_key = whereJson.get("key").toString();
|
|||
// keys = whereJson.get("value").toString();
|
|||
|
|||
|
|||
//[[{"column":"unified_key","value":"cached","compareType":"equals","columnType":"object"}]]
|
|||
UnifiedDataUnit unifiedDataUnit = UnifiedDataAccessorFactory.getUnifiedDataAppService().getUnifiedDataUnit(unified_key); |
|||
if (unifiedDataUnit == null) { |
|||
return null; |
|||
} else { |
|||
String key; |
|||
UdwDto udwDto; |
|||
Map storage; |
|||
ArrayList udwDtos; |
|||
Iterator var14; |
|||
if (keys != null) { |
|||
storage = unifiedDataUnit.getStorage(); |
|||
udwDtos = new ArrayList(); |
|||
var14 = storage.keySet().iterator(); |
|||
|
|||
while(var14.hasNext()) { |
|||
key = (String)var14.next(); |
|||
if (key.indexOf(keys) != -1) { |
|||
udwDto = new UdwDto(); |
|||
udwDto.setUnified_key(unified_key); |
|||
udwDto.setKey(key); |
|||
udwDto.setValue(((UnifiedData)storage.get(key)).getValue()); |
|||
udwDtos.add(udwDto); |
|||
} |
|||
} |
|||
|
|||
Integer currentPageNumber = page.getPageNumber() + 1; |
|||
Integer pageMaxSize = page.getPageSize(); |
|||
|
|||
List orderbyDtoList = (List) udwDtos.stream().skip((currentPageNumber - 1) * pageMaxSize) |
|||
.limit(pageMaxSize) |
|||
.collect(Collectors.toList()); |
|||
|
|||
JSONObject jo = new JSONObject(); |
|||
jo.put("content", orderbyDtoList); |
|||
jo.put("totalElements", udwDtos.size()); |
|||
|
|||
return jo; |
|||
} else { |
|||
storage = unifiedDataUnit.getStorage(); |
|||
udwDtos = new ArrayList(); |
|||
var14 = storage.keySet().iterator(); |
|||
|
|||
while(var14.hasNext()) { |
|||
key = (String)var14.next(); |
|||
udwDto = new UdwDto(); |
|||
udwDto.setUnified_key(unified_key); |
|||
udwDto.setKey(key); |
|||
udwDto.setValue(((UnifiedData)storage.get(key)).getValue()); |
|||
udwDtos.add(udwDto); |
|||
} |
|||
Integer currentPageNumber = page.getPageNumber() + 1; |
|||
Integer pageMaxSize = page.getPageSize(); |
|||
|
|||
List orderbyDtoList = (List) udwDtos.stream().skip((currentPageNumber - 1) * pageMaxSize) |
|||
.limit(pageMaxSize) |
|||
.collect(Collectors.toList()); |
|||
|
|||
JSONObject jo = new JSONObject(); |
|||
jo.put("content", orderbyDtoList); |
|||
jo.put("totalElements", udwDtos.size()); |
|||
|
|||
return jo; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
@ -0,0 +1,23 @@ |
|||
package org.nl.modules.logging; |
|||
|
|||
import ch.qos.logback.core.PropertyDefinerBase; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
// 通过实现logback的PropertyDefinerBase方法,动态定义logback配置中的变量
|
|||
@Component |
|||
public class DeviceCodeDir extends PropertyDefinerBase { |
|||
|
|||
String deviceCodeDir = ""; |
|||
public void setPropertyValue(String deviceCode) { |
|||
deviceCodeDir = deviceCode ; |
|||
} |
|||
|
|||
@Override |
|||
public String getPropertyValue() { |
|||
if (deviceCodeDir == ""){ |
|||
deviceCodeDir = "默认"; |
|||
} |
|||
return "默认"; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,178 @@ |
|||
package org.nl.modules.lucene.common; |
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
import org.apache.commons.io.FileUtils; |
|||
import org.apache.lucene.analysis.Analyzer; |
|||
import org.apache.lucene.document.Document; |
|||
import org.apache.lucene.document.Field; |
|||
import org.apache.lucene.document.TextField; |
|||
import org.apache.lucene.index.IndexWriter; |
|||
import org.apache.lucene.index.IndexWriterConfig; |
|||
import org.apache.lucene.store.Directory; |
|||
import org.apache.lucene.store.FSDirectory; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.wltea.analyzer.lucene.IKAnalyzer; |
|||
|
|||
import java.io.BufferedReader; |
|||
import java.io.File; |
|||
import java.io.FileReader; |
|||
import java.io.IOException; |
|||
import java.nio.file.Paths; |
|||
import java.util.Set; |
|||
|
|||
/** |
|||
* lucene索引器 |
|||
*/ |
|||
public class Indexer { |
|||
/** |
|||
* 写索引实例 |
|||
*/ |
|||
private IndexWriter writer; |
|||
|
|||
public IndexWriter getWriter() { |
|||
return writer; |
|||
} |
|||
|
|||
/** |
|||
* 构造方法,实例化IndexWriter |
|||
* @param indexDir |
|||
* @throws Exception |
|||
*/ |
|||
public Indexer(String indexDir) throws Exception { |
|||
Directory dir = FSDirectory.open(Paths.get(indexDir)); |
|||
//标准分词器,会自动去掉空格啊,is a the等单词
|
|||
// Analyzer analyzer = new StandardAnalyzer();
|
|||
Analyzer analyzer = new IKAnalyzer(); |
|||
//将标准分词器配到写索引的配置中
|
|||
IndexWriterConfig config = new IndexWriterConfig(analyzer); |
|||
//实例化写索引对象
|
|||
writer = new IndexWriter(dir, config); |
|||
} |
|||
|
|||
/** |
|||
* 索引指定目录下的所有文件 |
|||
* @param dataDir |
|||
* @return |
|||
* @throws Exception |
|||
*/ |
|||
public int indexAll(String dataDir) throws Exception { |
|||
// 获取该路径下的所有文件
|
|||
File[] files = new File(dataDir).listFiles(); |
|||
if (null != files) { |
|||
for (File file : files) { |
|||
//调用下面的indexFile方法,对每个文件进行索引
|
|||
indexFile(file); |
|||
} |
|||
} |
|||
//返回索引的文件数
|
|||
// return writer.numDocs();
|
|||
return writer.numRamDocs(); |
|||
} |
|||
|
|||
/** |
|||
* 索引指定的文件 |
|||
* @param file |
|||
* @throws Exception |
|||
*/ |
|||
private void indexFile(File file) throws Exception { |
|||
System.out.println("索引文件的路径:" + file.getCanonicalPath()); |
|||
//调用下面的getDocument方法,获取该文件的document
|
|||
Document doc = getDocument(file); |
|||
//添加索引文档
|
|||
//Document doc = json2Doc(jsonDoc);
|
|||
// Document doc = new Document();
|
|||
// doc.add(new TextField("content", jsonDoc, Field.Store.YES));
|
|||
Field fieldContent=new TextField("fieldContent", FileUtils.readFileToString(null,"UTF-8"), Field.Store.YES); |
|||
|
|||
//将doc添加到索引中
|
|||
writer.addDocument(doc); |
|||
} |
|||
|
|||
/** |
|||
* 获取文档,文档里再设置每个字段,就类似于数据库中的一行记录 |
|||
* @param file |
|||
* @return |
|||
* @throws Exception |
|||
*/ |
|||
private Document getDocument(File file) throws Exception { |
|||
Document doc = new Document(); |
|||
//开始添加字段
|
|||
//添加内容
|
|||
doc.add(new TextField("contents", new FileReader(file))); |
|||
//添加文件名,并把这个字段存到索引文件里
|
|||
doc.add(new TextField("fileName", file.getName(), Field.Store.YES)); |
|||
//添加文件路径
|
|||
doc.add(new TextField("fullPath", file.getCanonicalPath(), Field.Store.YES)); |
|||
return doc; |
|||
} |
|||
public Document json2Doc(String strDoc) { |
|||
Document doc = new Document(); |
|||
JSONObject jsonDoc = JSONObject.parseObject(strDoc); |
|||
Set<String> keys = jsonDoc.keySet(); |
|||
for (String key : keys) { |
|||
doc.add(new TextField(key, jsonDoc.getString(key), Field.Store.YES)); |
|||
} |
|||
return doc; |
|||
} |
|||
|
|||
public void addLogIndex(String msg) throws IOException { |
|||
//步骤一:创建Directory对象,用于指定索引库的位置 RAMDirectory内存
|
|||
Directory directory = FSDirectory.open(new File("D:\\lucene\\index").toPath()); |
|||
//步骤二:创建一个IndexWriter对象,用于写索引
|
|||
// Analyzer analyzer = new StandardAnalyzer();
|
|||
IndexWriter indexWriter=new IndexWriter(directory,new IndexWriterConfig(new IKAnalyzer(false))); |
|||
// indexWriter.deleteAll();//清理所有索引库
|
|||
// IndexWriter indexWriter=new IndexWriter(directory,new IndexWriterConfig(new StandardAnalyzer()));
|
|||
//记录索引开始时间
|
|||
long startTime = System.currentTimeMillis(); |
|||
//步骤三:读取磁盘中文件,对应每一个文件创建一个文档对象
|
|||
Document document = new Document(); |
|||
// document.add(new TextField("fieldContent", device_id, Field.Store.YES));
|
|||
document.add(new TextField("fieldContent", msg, Field.Store.YES)); |
|||
indexWriter.addDocument(document); |
|||
//记录索引结束时间
|
|||
long endTime = System.currentTimeMillis(); |
|||
System.out.println("建立索引"+ "共耗时" + (endTime-startTime) + "毫秒"); |
|||
indexWriter.commit(); |
|||
//步骤八:关闭资源
|
|||
indexWriter.close(); |
|||
System.out.println("建立索引成功-----关闭资源"); |
|||
} |
|||
//系统的日志文件路径
|
|||
@Value("${logging.file.path}") |
|||
private String logUrl; |
|||
|
|||
public static void main(String[] args)throws IOException { |
|||
//步骤一:创建Directory对象,用于指定索引库的位置 RAMDirectory内存
|
|||
Directory directory = FSDirectory.open(new File("D:\\lucene\\index").toPath()); |
|||
//步骤二:创建一个IndexWriter对象,用于写索引
|
|||
// Analyzer analyzer = new StandardAnalyzer();
|
|||
IndexWriter indexWriter=new IndexWriter(directory,new IndexWriterConfig(new IKAnalyzer(false))); |
|||
|
|||
indexWriter.deleteAll();//清理所有索引库
|
|||
// IndexWriter indexWriter=new IndexWriter(directory,new IndexWriterConfig(new StandardAnalyzer()));
|
|||
//记录索引开始时间
|
|||
long startTime = System.currentTimeMillis(); |
|||
//步骤三:读取磁盘中文件,对应每一个文件创建一个文档对象
|
|||
File file=new File("D:\\testlog"); |
|||
//步骤四:获取文件列表
|
|||
File[] files = file.listFiles(); |
|||
for (File item:files) { |
|||
BufferedReader bufferedReader = new BufferedReader(new FileReader(item)); |
|||
String strLine = null; |
|||
while(null != (strLine = bufferedReader.readLine())){ |
|||
Document document = new Document(); |
|||
// document.add(new Field());
|
|||
document.add(new TextField("fieldContent", strLine, Field.Store.YES)); |
|||
indexWriter.addDocument(document); |
|||
} |
|||
} |
|||
//记录索引结束时间
|
|||
long endTime = System.currentTimeMillis(); |
|||
System.out.println("建立索引"+ "共耗时" + (endTime-startTime) + "毫秒"); |
|||
indexWriter.commit(); |
|||
//步骤八:关闭资源
|
|||
indexWriter.close(); |
|||
System.out.println("建立索引成功-----关闭资源"); |
|||
} |
|||
} |
@ -0,0 +1,66 @@ |
|||
package org.nl.modules.lucene.common; |
|||
|
|||
import cn.hutool.core.date.DateUtil; |
|||
import org.apache.lucene.index.CorruptIndexException; |
|||
import org.apache.lucene.index.IndexWriter; |
|||
import org.apache.lucene.index.IndexWriterConfig; |
|||
import org.apache.lucene.store.Directory; |
|||
import org.apache.lucene.store.FSDirectory; |
|||
import org.nl.modules.lucene.config.UrlConfig; |
|||
import org.wltea.analyzer.lucene.IKAnalyzer; |
|||
|
|||
import java.io.File; |
|||
import java.io.IOException; |
|||
import java.text.ParseException; |
|||
import java.text.SimpleDateFormat; |
|||
import java.util.Date; |
|||
|
|||
public class LuceneIndexWriter { |
|||
private static IndexWriter indexWriter; |
|||
|
|||
static { |
|||
try { |
|||
Directory directory = FSDirectory.open(new File(UrlConfig.luceneUrl).toPath()); |
|||
IndexWriterConfig config = new IndexWriterConfig(new IKAnalyzer()); |
|||
indexWriter = new IndexWriter(directory, config); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
/**当当前线程结束时,自动关闭IndexWriter,使用Runtime对象*/ |
|||
Runtime.getRuntime().addShutdownHook(new Thread(){ |
|||
@Override |
|||
public void run() { |
|||
try { |
|||
closeIndexWriter(); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
}); |
|||
} |
|||
/**在线程结束时,自动关闭IndexWriter*/ |
|||
public static IndexWriter getIndexWriter() { |
|||
return indexWriter; |
|||
} |
|||
/**关闭IndexWriter |
|||
* @throws IOException |
|||
* @throws CorruptIndexException */ |
|||
public static void closeIndexWriter() throws Exception { |
|||
if(indexWriter != null) { |
|||
indexWriter.close(); |
|||
} |
|||
} |
|||
|
|||
public static void main(String[] args) throws IOException { |
|||
indexWriter.deleteAll(); |
|||
} |
|||
|
|||
public static String getDate(String timeString) throws ParseException { |
|||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");//时间格式
|
|||
Date date = sdf.parse(timeString); |
|||
timeString = DateUtil.format(date, "yyyy-MM-dd HH:mm:ss.SSS");//格式化后的时间
|
|||
return timeString; |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,140 @@ |
|||
package org.nl.modules.lucene.common; |
|||
|
|||
import cn.hutool.core.date.DateTime; |
|||
import cn.hutool.core.date.DateUtil; |
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.lucene.document.Document; |
|||
import org.apache.lucene.index.DirectoryReader; |
|||
import org.apache.lucene.index.IndexReader; |
|||
import org.apache.lucene.index.Term; |
|||
import org.apache.lucene.search.*; |
|||
import org.apache.lucene.store.Directory; |
|||
import org.apache.lucene.store.FSDirectory; |
|||
import org.apache.lucene.util.BytesRef; |
|||
|
|||
import java.nio.file.Paths; |
|||
import java.util.ArrayList; |
|||
import java.util.Calendar; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* lucene查询器 |
|||
*/ |
|||
@Slf4j |
|||
public class Searcher { |
|||
|
|||
public static Map<String, Object> search(String indexDir, String ext,Map whereJson) throws Exception { |
|||
//获取要查询的路径,也就是索引所在的位置
|
|||
Directory dir = FSDirectory.open(Paths.get(indexDir)); |
|||
IndexReader reader = DirectoryReader.open(dir); |
|||
//构建IndexSearcher
|
|||
IndexSearcher searcher = new IndexSearcher(reader); |
|||
//标准分词器,会自动去掉空格啊,is a the等单词
|
|||
// Analyzer analyzer = new StandardAnalyzer();
|
|||
// Analyzer analyzer = new IKAnalyzer(false);
|
|||
//查询解析器
|
|||
// QueryParser queryParser = new QueryParser("fieldContent", analyzer);
|
|||
|
|||
//记录索引开始时间
|
|||
long startTime = System.currentTimeMillis(); |
|||
// 实际上Lucene本身不支持分页。因此我们需要自己进行逻辑分页。我们要准备分页参数:
|
|||
int pageSize = Integer.parseInt(whereJson.get("size").toString());// 每页条数
|
|||
int pageNum = Integer.parseInt(whereJson.get("page").toString());// 当前页码
|
|||
int start = pageNum * pageSize;// 当前页的起始条数
|
|||
int end = start + pageSize;// 当前页的结束条数(不能包含)
|
|||
// 创建排序对象,需要排序字段SortField,参数:字段的名称、字段的类型、是否反转如果是false,升序。true降序
|
|||
Sort sort = new Sort(new SortField("logTime", SortField.Type.DOC,true)); |
|||
|
|||
TopDocs docs = null; |
|||
BooleanQuery.Builder booleanQueryBuilder = new BooleanQuery.Builder(); |
|||
//时间范围查询
|
|||
String startDate = (String) whereJson.get("begin_time"); |
|||
String endDate = (String) whereJson.get("end_time"); |
|||
Calendar calendar=Calendar.getInstance(); |
|||
calendar.set(1970, 0, 1); |
|||
if (startDate == null){ |
|||
startDate = DateUtil.format(calendar.getTime(),"yyyy-MM-dd HH:mm:ss.SSS"); |
|||
}else{ |
|||
startDate = LuceneIndexWriter.getDate(startDate); |
|||
} |
|||
if (endDate == null){ |
|||
endDate = DateUtil.format(new DateTime(),"yyyy-MM-dd HH:mm:ss.SSS"); |
|||
} else { |
|||
endDate = LuceneIndexWriter.getDate(endDate); |
|||
} |
|||
TermRangeQuery termRangeQuery = new TermRangeQuery("logTime", new BytesRef(startDate), new BytesRef(endDate), true, true); |
|||
booleanQueryBuilder.add(termRangeQuery,BooleanClause.Occur.MUST); |
|||
if (whereJson.get("device_code") != null){ |
|||
Query termQuery = new TermQuery(new Term("device_code", (String) whereJson.get("device_code"))); |
|||
booleanQueryBuilder.add(termQuery,BooleanClause.Occur.MUST); |
|||
} |
|||
if (whereJson.get("method") != null){ |
|||
Query termQuery = new TermQuery(new Term("method", (String) whereJson.get("method"))); |
|||
booleanQueryBuilder.add(termQuery,BooleanClause.Occur.MUST); |
|||
} |
|||
if (whereJson.get("status_code") != null){ |
|||
Query termQuery = new TermQuery(new Term("status_code", (String) whereJson.get("status_code"))); |
|||
booleanQueryBuilder.add(termQuery,BooleanClause.Occur.MUST); |
|||
} |
|||
if (whereJson.get("requestparam") != null){ |
|||
WildcardQuery query = new WildcardQuery(new Term("requestparam", "*"+(String) whereJson.get("requestparam")+"*")); |
|||
booleanQueryBuilder.add(query,BooleanClause.Occur.MUST); |
|||
} |
|||
if (whereJson.get("responseparam") != null){ |
|||
WildcardQuery query = new WildcardQuery(new Term("responseparam", "*"+(String) whereJson.get("responseparam")+"*")); |
|||
booleanQueryBuilder.add(query,BooleanClause.Occur.MUST); |
|||
} |
|||
if (whereJson.get("blurry") != null) { |
|||
WildcardQuery query = new WildcardQuery(new Term("fieldContent", "*"+(String) whereJson.get("blurry")+"*")); |
|||
booleanQueryBuilder.add(query, BooleanClause.Occur.MUST); |
|||
} |
|||
docs = searcher.search(booleanQueryBuilder.build(), end,sort); |
|||
//记录索引时间
|
|||
long endTime = System.currentTimeMillis(); |
|||
log.info("匹配{}共耗时{}毫秒",booleanQueryBuilder.build(),(endTime-startTime)); |
|||
log.info("查询到{}条日志文件", docs.totalHits.value); |
|||
List<String> list = new ArrayList<>(); |
|||
ScoreDoc[] scoreDocs = docs.scoreDocs; |
|||
if (end > docs.totalHits.value) end = (int) docs.totalHits.value; |
|||
JSONArray array = new JSONArray(); |
|||
|
|||
for (int i = start; i < end; i++) { |
|||
ScoreDoc scoreDoc = scoreDocs[i]; |
|||
Document doc = reader.document(scoreDoc.doc); |
|||
JSONObject object = new JSONObject(); |
|||
object.put("content",doc.get("fieldContent")); |
|||
object.put("device_code",doc.get("device_code")); |
|||
object.put("logTime",doc.get("logTime")); |
|||
object.put("method",doc.get("method")); |
|||
object.put("status_code",doc.get("status_code")); |
|||
object.put("requestparam",doc.get("requestparam")); |
|||
object.put("responseparam",doc.get("responseparam")); |
|||
if(doc.get("fieldContent") != null) { |
|||
array.add(object); |
|||
} |
|||
} |
|||
for(Object logDto:array){ |
|||
log.info(logDto.toString()); |
|||
} |
|||
reader.close(); |
|||
JSONObject jo = new JSONObject(); |
|||
jo.put("content", array); |
|||
jo.put("totalElements", docs.totalHits.value); |
|||
return jo; |
|||
} |
|||
|
|||
public static void main(String[] args) { |
|||
String indexDir = "D:\\lucene\\index"; |
|||
//查询这个字符串
|
|||
String q = "07.832"; |
|||
Map whereJson = null; |
|||
try { |
|||
search(indexDir, q,whereJson); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,21 @@ |
|||
package org.nl.modules.lucene.config; |
|||
|
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
|
|||
/** |
|||
* @deprecated 设置静态参数初始化 |
|||
*/ |
|||
@Configuration |
|||
public class StaticConfig { |
|||
//日志索引目录
|
|||
@Value("${lucene.index.path}") |
|||
private String luceneDir; |
|||
|
|||
@Bean |
|||
public int initStatic() { |
|||
UrlConfig.setLuceneUrl(luceneDir); |
|||
return 0; |
|||
} |
|||
} |
@ -0,0 +1,13 @@ |
|||
package org.nl.modules.lucene.config; |
|||
|
|||
public class UrlConfig { |
|||
public static String luceneUrl; |
|||
|
|||
public static String getLuceneUrl() { |
|||
return luceneUrl; |
|||
} |
|||
|
|||
public static void setLuceneUrl(String luceneUrl) { |
|||
UrlConfig.luceneUrl = luceneUrl; |
|||
} |
|||
} |
@ -0,0 +1,15 @@ |
|||
package org.nl.modules.lucene.enums; |
|||
|
|||
public enum LogTypeEnum { |
|||
DEVICE_LOG("设备日志"), |
|||
INTERFACE_LOG("接口日志"); |
|||
|
|||
private String desc; |
|||
|
|||
LogTypeEnum(String desc) { |
|||
this.desc = desc; |
|||
} |
|||
public String getDesc() { |
|||
return desc; |
|||
} |
|||
} |
@ -0,0 +1,43 @@ |
|||
package org.nl.modules.lucene.rest; |
|||
|
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.nl.modules.logging.annotation.Log; |
|||
import org.nl.modules.lucene.service.LuceneService; |
|||
import org.springframework.data.domain.Pageable; |
|||
import org.springframework.http.HttpStatus; |
|||
import org.springframework.http.ResponseEntity; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import java.util.Map; |
|||
|
|||
|
|||
@RestController |
|||
@RequiredArgsConstructor |
|||
@Api(tags = "日志检索") |
|||
@RequestMapping("/api/lucene") |
|||
@Slf4j |
|||
public class LuceneController { |
|||
|
|||
private final LuceneService luceneService; |
|||
|
|||
@GetMapping("/labels/values") |
|||
@ApiOperation("获取标签") |
|||
public ResponseEntity<Object> labelsValues() { |
|||
return new ResponseEntity<>(luceneService.getLabelsValues(), HttpStatus.OK); |
|||
} |
|||
|
|||
|
|||
@GetMapping("/getAll") |
|||
@Log("日志检索") |
|||
@ApiOperation("日志检索") |
|||
//@PreAuthorize("@el.check('task:list')")
|
|||
public ResponseEntity<Object> get(@RequestParam Map whereJson, Pageable page) { |
|||
return new ResponseEntity<>(luceneService.getAll(whereJson, page), HttpStatus.OK); |
|||
} |
|||
} |
@ -0,0 +1,41 @@ |
|||
package org.nl.modules.lucene.service; |
|||
|
|||
|
|||
import org.nl.modules.lucene.service.dto.LuceneLogDto; |
|||
|
|||
import java.io.IOException; |
|||
|
|||
public interface LuceneExecuteLogService { |
|||
/** |
|||
* 设备光电变化实时光电信号 |
|||
* |
|||
* @param device_code 设备编号 |
|||
* @param key plc信号 |
|||
* @param value plc信号值 |
|||
*/ |
|||
void deviceItemValue(String device_code, String key, String value); |
|||
|
|||
/** |
|||
* 设备执行日志,会保留历史记录 |
|||
* |
|||
* @param luceneLogDto 日志结果对象 |
|||
*/ |
|||
void deviceExecuteLog(LuceneLogDto luceneLogDto); |
|||
|
|||
/** |
|||
* 接口日志,会保留历史记录 |
|||
* |
|||
* @param luceneLogDto 日志结果对象 |
|||
*/ |
|||
void interfaceExecuteLog(LuceneLogDto luceneLogDto) throws IOException; |
|||
|
|||
/** |
|||
* 设备执行日志,会保留历史记录 |
|||
* |
|||
* @param name 日志名称 |
|||
* @param message 日志信息 |
|||
*/ |
|||
void extLog(String name, String message); |
|||
|
|||
|
|||
} |
@ -0,0 +1,24 @@ |
|||
package org.nl.modules.lucene.service; |
|||
|
|||
import com.alibaba.fastjson.JSONArray; |
|||
import org.springframework.data.domain.Pageable; |
|||
|
|||
import java.util.Map; |
|||
|
|||
|
|||
public interface LuceneService { |
|||
/** |
|||
* 获取labels和values树 |
|||
* @return |
|||
*/ |
|||
JSONArray getLabelsValues(); |
|||
|
|||
/** |
|||
* 获取数据分页 |
|||
* |
|||
* @param whereJson 条件 |
|||
* @param page 分页参数 |
|||
* @return Map<String, Object> |
|||
*/ |
|||
Map<String, Object> getAll(Map whereJson, Pageable page); |
|||
} |
@ -0,0 +1,95 @@ |
|||
package org.nl.modules.lucene.service.dto; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Builder; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
@Data |
|||
@Builder |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class LuceneLogDto { |
|||
|
|||
/* 日志标识 */ |
|||
private String log_uuid; |
|||
/*日志类型*/ |
|||
private String logType; |
|||
/*设备编号*/ |
|||
private String device_code; |
|||
/*内容详情*/ |
|||
private String content; |
|||
|
|||
/* 任务编码 */ |
|||
private String task_code; |
|||
|
|||
/* 指令编码 */ |
|||
private String instruct_code; |
|||
|
|||
/* 任务标识 */ |
|||
private String task_id; |
|||
|
|||
/* 载具号 */ |
|||
private String vehicle_code; |
|||
|
|||
/* 备注 */ |
|||
private String remark; |
|||
|
|||
/* 日志类型 */ |
|||
private String log_type; |
|||
|
|||
/* 方法 */ |
|||
private String method; |
|||
|
|||
/* 请求参数 */ |
|||
private String requestparam; |
|||
|
|||
/* 响应参数 */ |
|||
private String responseparam; |
|||
|
|||
/* 请求地址 */ |
|||
private String requesturl; |
|||
|
|||
/* 状态码 */ |
|||
private String status_code; |
|||
|
|||
/* 是否删除 1:是;0:否 */ |
|||
private String is_delete; |
|||
|
|||
/* 创建者 */ |
|||
private String create_by; |
|||
|
|||
/* 创建时间 YYYY-MM-DD hh:mm:ss */ |
|||
private String create_time; |
|||
|
|||
/* 修改者 */ |
|||
private String update_by; |
|||
|
|||
/* 修改时间 */ |
|||
private String update_time; |
|||
|
|||
|
|||
public LuceneLogDto(final String opc_server_code, final String opc_plc_code, |
|||
final String device_code, final String to_home, final String last_home, |
|||
final String home) { |
|||
super(); |
|||
this.device_code = device_code; |
|||
this.content = "信号 [" |
|||
+ opc_server_code + "." |
|||
+ opc_plc_code + "." |
|||
+ device_code + "." |
|||
+ to_home + "] 发生变更 " |
|||
+ last_home + " -> " |
|||
+ home; |
|||
} |
|||
|
|||
public LuceneLogDto(final String device_code, final String remark) { |
|||
super(); |
|||
this.device_code = device_code; |
|||
this.content = "设备 [" |
|||
+ device_code |
|||
+ "] : " |
|||
+ remark; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,101 @@ |
|||
package org.nl.modules.lucene.service.impl; |
|||
|
|||
import cn.hutool.core.date.DateTime; |
|||
import cn.hutool.core.date.DateUtil; |
|||
import cn.hutool.core.util.ObjectUtil; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.SneakyThrows; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.lucene.document.Document; |
|||
import org.apache.lucene.document.Field; |
|||
import org.apache.lucene.document.StringField; |
|||
import org.apache.lucene.index.IndexWriter; |
|||
import org.nl.modules.lucene.common.LuceneIndexWriter; |
|||
import org.nl.modules.lucene.enums.LogTypeEnum; |
|||
import org.nl.modules.lucene.service.LuceneExecuteLogService; |
|||
import org.nl.modules.lucene.service.dto.LuceneLogDto; |
|||
import org.slf4j.MDC; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.io.IOException; |
|||
|
|||
/** |
|||
* @author jlm |
|||
* @description 服务实现 |
|||
* @date 2023-04-11 |
|||
*/ |
|||
@Service |
|||
@RequiredArgsConstructor |
|||
@Slf4j |
|||
public class LuceneExecuteLogServiceImpl implements LuceneExecuteLogService { |
|||
|
|||
@Override |
|||
public void deviceItemValue(String device_code, String key, String value) { |
|||
String now = DateUtil.now(); |
|||
} |
|||
|
|||
@SneakyThrows |
|||
@Override |
|||
public void deviceExecuteLog(LuceneLogDto luceneLogDto) { |
|||
luceneLogDto.setLogType(LogTypeEnum.DEVICE_LOG.getDesc()); |
|||
addIndex(luceneLogDto); |
|||
} |
|||
|
|||
@Override |
|||
public void interfaceExecuteLog(LuceneLogDto luceneLogDto) throws IOException { |
|||
luceneLogDto.setLogType(LogTypeEnum.INTERFACE_LOG.getDesc()); |
|||
addIndex(luceneLogDto); |
|||
} |
|||
|
|||
private void addIndex(LuceneLogDto luceneLogDto) throws IOException { |
|||
IndexWriter indexWriter = LuceneIndexWriter.getIndexWriter(); |
|||
//创建一个Document对象
|
|||
Document document = new Document(); |
|||
try { |
|||
//记录索引开始时间
|
|||
long startTime = System.currentTimeMillis(); |
|||
//向document对象中添加域。
|
|||
if (ObjectUtil.isNotEmpty(luceneLogDto.getDevice_code())) { |
|||
document.add(new StringField("device_code", luceneLogDto.getDevice_code(), Field.Store.YES)); |
|||
// document.add(new TextField("device_code", luceneLogDto.getDevice_code(), Field.Store.YES));
|
|||
} |
|||
if (ObjectUtil.isNotEmpty(luceneLogDto.getContent())) { |
|||
document.add(new StringField("fieldContent", luceneLogDto.getContent(), Field.Store.YES)); |
|||
} |
|||
if (ObjectUtil.isNotEmpty(luceneLogDto.getMethod())) { |
|||
document.add(new StringField("method", luceneLogDto.getMethod(), Field.Store.YES)); |
|||
} |
|||
if (ObjectUtil.isNotEmpty(luceneLogDto.getStatus_code())) { |
|||
document.add(new StringField("status_code", luceneLogDto.getStatus_code(), Field.Store.YES)); |
|||
} |
|||
if (ObjectUtil.isNotEmpty(luceneLogDto.getRequestparam())) { |
|||
document.add(new StringField("requestparam", luceneLogDto.getRequestparam(), Field.Store.YES)); |
|||
} |
|||
if (ObjectUtil.isNotEmpty(luceneLogDto.getResponseparam())) { |
|||
document.add(new StringField("responseparam", luceneLogDto.getResponseparam(), Field.Store.YES)); |
|||
} |
|||
document.add(new StringField("logType", luceneLogDto.getLogType(), Field.Store.YES)); |
|||
document.add(new StringField("logTime", DateUtil.format(new DateTime(), "yyyy-MM-dd HH:mm:ss.SSS"), Field.Store.YES)); |
|||
indexWriter.addDocument(document); |
|||
//记录索引结束时间
|
|||
long endTime = System.currentTimeMillis(); |
|||
log.info("建立索引共耗时{}毫秒", endTime - startTime); |
|||
indexWriter.commit(); |
|||
MDC.put("DEVICECODE", luceneLogDto.getDevice_code()); |
|||
} catch (Exception e) { |
|||
log.error(e.getMessage(), e); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void extLog(String name, String message) { |
|||
try { |
|||
MDC.put(name, name); |
|||
log.info("{}", message); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} finally { |
|||
MDC.remove(name); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,85 @@ |
|||
package org.nl.modules.lucene.service.impl; |
|||
|
|||
import cn.hutool.core.util.CharsetUtil; |
|||
import cn.hutool.http.HttpUtil; |
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.nl.modules.lucene.common.Searcher; |
|||
import org.nl.modules.lucene.service.LuceneService; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.data.domain.Pageable; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.Map; |
|||
|
|||
|
|||
@Service |
|||
@RequiredArgsConstructor |
|||
@Slf4j |
|||
public class LuceneServiceImpl implements LuceneService { |
|||
|
|||
@Value("${loki.url}") |
|||
private String lokiUrl; |
|||
|
|||
@Value("${loki.systemName}") |
|||
private String systemName; |
|||
|
|||
//日志索引目录
|
|||
@Value("${lucene.index.path}") |
|||
private String luceneUrl; |
|||
|
|||
/** |
|||
* 获取labels和values树 |
|||
* |
|||
* @return |
|||
*/ |
|||
@Override |
|||
public JSONArray getLabelsValues() { |
|||
JSONArray result = new JSONArray(); |
|||
// 获取所有标签
|
|||
String labelString = HttpUtil.get(lokiUrl + "/labels", CharsetUtil.CHARSET_UTF_8); |
|||
JSONObject parse = (JSONObject) JSONObject.parse(labelString); |
|||
JSONArray labels = parse.getJSONArray("data"); |
|||
for (int i=0; i<labels.size(); i++) { |
|||
// 获取标签下的所有值
|
|||
String valueString = HttpUtil.get(lokiUrl + "/label/" + labels.getString(i) + "/values", CharsetUtil.CHARSET_UTF_8); |
|||
JSONObject parse2 = (JSONObject) JSONObject.parse(valueString); |
|||
JSONArray values = parse2.getJSONArray("data"); |
|||
JSONArray children = new JSONArray(); |
|||
// 组成树形状态 两级
|
|||
for (int j=0; j<values.size(); j++) { |
|||
JSONObject leaf = new JSONObject(); |
|||
leaf.put("label", values.getString(j)); |
|||
leaf.put("value", values.getString(j)); |
|||
children.add(leaf); |
|||
} |
|||
|
|||
JSONObject node = new JSONObject(); |
|||
node.put("label", labels.getString(i)); |
|||
node.put("value", labels.getString(i)); |
|||
node.put("children", children); |
|||
result.add(node); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
@Override |
|||
public Map<String, Object> getAll(Map whereJson, Pageable page) { |
|||
JSONObject jo = new JSONObject(); |
|||
try { |
|||
JSONObject jsonObject = (JSONObject) Searcher.search(luceneUrl, "", whereJson); |
|||
JSONArray array = jsonObject.getJSONArray("content"); |
|||
int totalElements = Integer.parseInt(jsonObject.get("totalElements").toString()); |
|||
jo.put("content", array); |
|||
jo.put("totalElements", totalElements); |
|||
} catch (Exception e) { |
|||
log.error("索引查询为空", e); |
|||
throw new NullPointerException("索引查询为空"); |
|||
} |
|||
|
|||
return jo; |
|||
} |
|||
|
|||
} |
Binary file not shown.
@ -0,0 +1,34 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<included> |
|||
<springProperty scope="context" name="logPath" source="logging.file.path" defaultValue="logs"/> |
|||
<property name="LOG_HOME" value="${logPath}"/> |
|||
<define name="DEVICECODE" class="org.nl.modules.logging.DeviceCodeDir"/> |
|||
<!-- 按照每天生成日志文件 --> |
|||
<appender name="FILE_LUCENE" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
|||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> |
|||
<!--日志文件输出的文件名--> |
|||
<FileNamePattern>${LOG_HOME}/lucene/${DEVICECODE}/%d{yyyy-MM-dd}.%i.log</FileNamePattern> |
|||
<!--日志文件保留天数--> |
|||
<maxHistory>15</maxHistory> |
|||
<!--单个日志最大容量 至少10MB才能看得出来--> |
|||
<maxFileSize>200MB</maxFileSize> |
|||
<!--所有日志最多占多大容量--> |
|||
<totalSizeCap>2GB</totalSizeCap> |
|||
</rollingPolicy> |
|||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> |
|||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符--> |
|||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> |
|||
<charset>${log.charset}</charset> |
|||
</encoder> |
|||
|
|||
</appender> |
|||
|
|||
<!-- <logger name="org.nl.start.Init" level="info" additivity="false"> |
|||
<appender-ref ref="FILE3"/> |
|||
</logger>--> |
|||
|
|||
<!-- 打印sql --> |
|||
<logger name="org.nl.modules.lucene.service.impl.LuceneExecuteLogServiceImpl" level="info" additivity="false"> |
|||
<appender-ref ref="FILE_LUCENE"/> |
|||
</logger> |
|||
</included> |
@ -0,0 +1,27 @@ |
|||
import request from '@/utils/request' |
|||
|
|||
export function add(data) { |
|||
return request({ |
|||
url: 'api/deviceErrorLog', |
|||
method: 'post', |
|||
data |
|||
}) |
|||
} |
|||
|
|||
export function del(ids) { |
|||
return request({ |
|||
url: 'api/deviceErrorLog/', |
|||
method: 'delete', |
|||
data: ids |
|||
}) |
|||
} |
|||
|
|||
export function edit(data) { |
|||
return request({ |
|||
url: 'api/deviceErrorLog', |
|||
method: 'put', |
|||
data |
|||
}) |
|||
} |
|||
|
|||
export default { add, edit, del } |
@ -0,0 +1,28 @@ |
|||
import request from '@/utils/request' |
|||
|
|||
export function add(data) { |
|||
return request({ |
|||
url: 'api/task', |
|||
method: 'post', |
|||
data |
|||
}) |
|||
} |
|||
|
|||
export function del(ids) { |
|||
return request({ |
|||
url: 'api/task/', |
|||
method: 'delete', |
|||
data: ids |
|||
}) |
|||
} |
|||
|
|||
export function edit(data) { |
|||
return request({ |
|||
url: 'api/task', |
|||
method: 'put', |
|||
data |
|||
}) |
|||
} |
|||
|
|||
export default { edit, del } |
|||
|
@ -0,0 +1,145 @@ |
|||
<template> |
|||
<div class="app-container"> |
|||
<!--工具栏--> |
|||
<div class="head-container"> |
|||
<div v-if="crud.props.searchToggle"> |
|||
<!-- 搜索 --> |
|||
<label class="el-form-item-label">设备编码</label> |
|||
<el-input |
|||
v-model="query.device_code" |
|||
clearable |
|||
placeholder="设备编码" |
|||
style="width: 185px;" |
|||
class="filter-item" |
|||
@keyup.enter.native="crud.toQuery" |
|||
/> |
|||
<el-input |
|||
v-model="query.error_code" |
|||
clearable |
|||
placeholder="报警编码" |
|||
style="width: 185px;" |
|||
class="filter-item" |
|||
@keyup.enter.native="crud.toQuery" |
|||
/> |
|||
<el-input |
|||
v-model="query.error_info" |
|||
clearable |
|||
placeholder="报警信息" |
|||
style="width: 185px;" |
|||
class="filter-item" |
|||
@keyup.enter.native="crud.toQuery" |
|||
/> |
|||
<date-range-picker |
|||
v-model="query.error_time" |
|||
start-placeholder="error_timeStart" |
|||
end-placeholder="error_timeStart" |
|||
class="date-item" |
|||
/> |
|||
<rrOperation :crud="crud" /> |
|||
</div> |
|||
<!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'--> |
|||
<crudOperation :permission="permission" /> |
|||
<!--表单组件--> |
|||
<el-dialog |
|||
:close-on-click-modal="false" |
|||
:before-close="crud.cancelCU" |
|||
:visible.sync="crud.status.cu > 0" |
|||
:title="crud.status.title" |
|||
width="500px" |
|||
> |
|||
<el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px" /> |
|||
<div slot="footer" class="dialog-footer"> |
|||
<el-button type="text" @click="crud.cancelCU">取消</el-button> |
|||
<el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button> |
|||
</div> |
|||
</el-dialog> |
|||
<!--表格渲染--> |
|||
<el-table |
|||
ref="table" |
|||
v-loading="crud.loading" |
|||
:data="crud.data" |
|||
size="small" |
|||
style="width: 100%;" |
|||
@selection-change="crud.selectionChangeHandler" |
|||
> |
|||
<el-table-column type="selection" width="55" /> |
|||
<el-table-column prop="device_code" label="设备编码" /> |
|||
<el-table-column prop="error_code" label="报警编码" /> |
|||
<el-table-column prop="error_info" label="报警信息" /> |
|||
<el-table-column prop="error_time" label="报警时间" /> |
|||
<el-table-column |
|||
v-permission="['admin','acsDeviceErrorLog:edit','acsDeviceErrorLog:del']" |
|||
label="操作" |
|||
width="150px" |
|||
align="center" |
|||
> |
|||
<template slot-scope="scope"> |
|||
<udOperation |
|||
:data="scope.row" |
|||
:permission="permission" |
|||
:disabled-edit="true" |
|||
/> |
|||
</template> |
|||
</el-table-column> |
|||
</el-table> |
|||
<!--分页组件--> |
|||
<pagination /> |
|||
</div> |
|||
</div> |
|||
</template> |
|||
|
|||
<script> |
|||
import CRUD, { crud, form, header, presenter } from '@crud/crud' |
|||
import rrOperation from '@crud/RR.operation' |
|||
import crudOperation from '@crud/CRUD.operation' |
|||
import udOperation from '@crud/UD.operation' |
|||
import pagination from '@crud/Pagination' |
|||
import crudAcsDeviceErrorLog from '@/api/acs/history/acsDeviceErrorLog' |
|||
|
|||
const defaultForm = { error_log_uuid: null, device_code: null, error_code: null, error_info: null, error_time: null } |
|||
export default { |
|||
name: 'DeviceErrorLog', |
|||
components: { pagination, crudOperation, rrOperation, udOperation }, |
|||
mixins: [presenter(), header(), form(defaultForm), crud()], |
|||
cruds() { |
|||
return CRUD({ |
|||
title: '设备报警记录', |
|||
url: 'api/deviceErrorLog', |
|||
idField: 'error_log_uuid', |
|||
sort: 'error_log_uuid,desc', |
|||
crudMethod: { ...crudAcsDeviceErrorLog }, |
|||
optShow: { |
|||
add: false, |
|||
edit: false, |
|||
del: false, |
|||
download: false |
|||
} |
|||
}) |
|||
}, |
|||
data() { |
|||
return { |
|||
permission: { |
|||
add: ['admin', 'deviceErrorLog:add'], |
|||
edit: ['admin', 'deviceErrorLog:edit'], |
|||
del: ['admin', 'adeviceErrorLog:del'] |
|||
}, |
|||
rules: {}, |
|||
queryTypeOptions: [ |
|||
{ key: 'device_code', display_name: '设备编码' }, |
|||
{ key: 'error_code', display_name: '报警编码' }, |
|||
{ key: 'error_info', display_name: '报警信息' } |
|||
] |
|||
} |
|||
}, |
|||
methods: { |
|||
// 钩子:在获取表格数据之前执行,false 则代表不获取数据 |
|||
[CRUD.HOOK.beforeRefresh]() { |
|||
return true |
|||
} |
|||
} |
|||
} |
|||
</script> |
|||
|
|||
<style scoped> |
|||
|
|||
</style> |
@ -0,0 +1,181 @@ |
|||
<template> |
|||
<div class="app-container"> |
|||
<!--工具栏--> |
|||
<div class="head-container"> |
|||
<div v-if="crud.props.searchToggle"> |
|||
<!-- 搜索 --> |
|||
<el-select |
|||
v-model="form.unified_key" |
|||
placeholder="unified_key" |
|||
class="filter-item" |
|||
@change="crud.toQuery" |
|||
clearable |
|||
filterable |
|||
size="small"> |
|||
<el-option v-for="(item,index) in unified_key" :key="index" :label="item.label" :value="item.value"> |
|||
</el-option> |
|||
</el-select> |
|||
<el-input |
|||
v-model="query.code" |
|||
size="small" |
|||
clearable |
|||
placeholder="编号" |
|||
style="width: 200px;" |
|||
class="filter-item" |
|||
@keyup.enter.native="crud.toQuery" |
|||
/> |
|||
</div> |
|||
<!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'--> |
|||
<crudOperation :permission="permission" /> |
|||
<!--表单组件--> |
|||
<el-dialog |
|||
:close-on-click-modal="false" |
|||
:before-close="crud.cancelCU" |
|||
:visible.sync="crud.status.cu > 0" |
|||
:title="crud.status.title" |
|||
width="500px" |
|||
> |
|||
<el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px"> |
|||
<el-form-item label="unified_key"> |
|||
<el-input v-model="form.unified_key" style="width: 370px;" /> |
|||
</el-form-item> |
|||
<el-form-item label="编号"> |
|||
<el-input v-model="form.key" style="width: 370px;" /> |
|||
</el-form-item> |
|||
<el-form-item label="值"> |
|||
<el-input v-model="form.value" style="width: 370px;" /> |
|||
</el-form-item> |
|||
</el-form> |
|||
<div slot="footer" class="dialog-footer"> |
|||
<el-button type="text" @click="crud.cancelCU">取消</el-button> |
|||
<el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button> |
|||
</div> |
|||
</el-dialog> |
|||
<!--表格渲染--> |
|||
<el-table |
|||
ref="table" |
|||
v-loading="crud.loading" |
|||
:data="crud.data" |
|||
size="small" |
|||
style="width: 100%;" |
|||
@selection-change="crud.selectionChangeHandler" |
|||
> |
|||
<el-table-column prop="unified_key" label="unified_key" /> |
|||
<el-table-column prop="key" label="编号" /> |
|||
<el-table-column prop="value" label="值" /> |
|||
<el-table-column |
|||
v-permission="['admin','instruction:edit','instruction:del']" |
|||
fixed="left" |
|||
label="操作" |
|||
width="150px" |
|||
align="center" |
|||
> |
|||
<template slot-scope="scope"> |
|||
<el-button slot="right" size="mini" style="margin-left: -1px;margin-right: 2px" type="text" @click="dialogFormVisible = true"> |
|||
查询历史 |
|||
</el-button> |
|||
</template> |
|||
</el-table-column> |
|||
</el-table> |
|||
<!--分页组件--> |
|||
<pagination /> |
|||
<!--弹窗设置设备与图标绑定与角度--> |
|||
<el-dialog title="历史" :visible.sync="dialogFormVisible" width="35%"> |
|||
<el-form :model="form" size="small"> |
|||
<el-form-item label="unified_key" prop="unified_key" label-width="100px"> |
|||
<el-input v-model="form.unified_key" :disabled="true" /> |
|||
</el-form-item> |
|||
|
|||
<el-form-item label="code" prop="key" label-width="100px"> |
|||
<el-input v-model="form.key" :disabled="true" /> |
|||
</el-form-item> |
|||
|
|||
</el-form> |
|||
</el-dialog> |
|||
</div> |
|||
</div> |
|||
</template> |
|||
|
|||
<script> |
|||
import pagination from '@crud/Pagination' |
|||
import crudUdwData from '@/api/acs/history/udwData' |
|||
import CRUD, { crud, form, header, presenter } from '@crud/crud' |
|||
import crudOperation from '@crud/CRUD.operation' |
|||
import { getDicts } from '@/api/system/dict' |
|||
|
|||
const defaultForm = { |
|||
unified_key: '', |
|||
key: null, |
|||
value: null, |
|||
last_modify_date: null |
|||
} |
|||
export default { |
|||
dicts: [], |
|||
name: 'UdwData', |
|||
components: { pagination, crudOperation }, |
|||
mixins: [presenter(), header(), form(defaultForm), crud()], |
|||
cruds() { |
|||
return CRUD({ |
|||
title: '数据源', |
|||
url: 'api/udw/', |
|||
idField: 'key', |
|||
sort: 'key', |
|||
query: {}, |
|||
crudMethod: { ...crudUdwData }, |
|||
optShow: { |
|||
} |
|||
}) |
|||
}, |
|||
data() { |
|||
return { |
|||
unified_key: [ |
|||
{ |
|||
value: '1', |
|||
label: 'opc_value' |
|||
}, |
|||
{ |
|||
value: '2', |
|||
label: 'cached' |
|||
}, |
|||
{ |
|||
value: '3', |
|||
label: 'socket' |
|||
} |
|||
], |
|||
permission: { |
|||
}, |
|||
dialogFormVisible: false, |
|||
rules: { |
|||
}, |
|||
form: { |
|||
unified_key: 'opc_value', |
|||
key: null, |
|||
value: null, |
|||
last_modify_date: null |
|||
} |
|||
} |
|||
}, |
|||
created() { |
|||
getDicts().then(data => { |
|||
this.dicts = data |
|||
}) |
|||
}, |
|||
methods: { |
|||
// 钩子:在获取表格数据之前执行,false 则代表不获取数据 |
|||
[CRUD.HOOK.beforeRefresh]() { |
|||
return true |
|||
} |
|||
} |
|||
} |
|||
</script> |
|||
|
|||
<style scoped> |
|||
.el-dropdown-link { |
|||
cursor: pointer; |
|||
color: #409EFF; |
|||
} |
|||
|
|||
.el-icon-arrow-down { |
|||
font-size: 12px; |
|||
} |
|||
</style> |
@ -0,0 +1,18 @@ |
|||
import request from '@/utils/request' |
|||
|
|||
export function getLogData(param) { |
|||
return request({ |
|||
url: 'api/lucene/getAll', |
|||
method: 'get', |
|||
data: param |
|||
}) |
|||
} |
|||
|
|||
export function labelsValues() { |
|||
return request({ |
|||
url: 'api/loki/labels/values', |
|||
method: 'get' |
|||
}) |
|||
} |
|||
|
|||
export default { getLogData, labelsValues } |
Loading…
Reference in new issue