|
@@ -0,0 +1,189 @@
|
|
|
+package com.benyun.controller;
|
|
|
+
|
|
|
+
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.benyun.boot.core.vo.Result;
|
|
|
+import com.benyun.entity.Event;
|
|
|
+import com.benyun.vo.*;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import com.benyun.entity.EventLog;
|
|
|
+import com.benyun.service.EventLogService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.beetl.sql.core.engine.PageQuery;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author makejava
|
|
|
+ * create on 2023-03-22 09:25:07
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("eventLog")
|
|
|
+@RequiredArgsConstructor(onConstructor_ = {@Autowired})
|
|
|
+public class EventLogController {
|
|
|
+ /**
|
|
|
+ * 服务对象
|
|
|
+ */
|
|
|
+ private final EventLogService eventLogService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询所有数据
|
|
|
+ *
|
|
|
+ * @return 所有数据
|
|
|
+ */
|
|
|
+ @GetMapping("/queryAll")
|
|
|
+ public Result<List<EventLog>> queryAll() {
|
|
|
+ return Result.success(eventLogService.queryAll());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询数据
|
|
|
+ *
|
|
|
+ * @return 所有数据
|
|
|
+ */
|
|
|
+ @GetMapping("/queryPage")
|
|
|
+ public Result<List<EventLog>> queryPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize, EventLog eventLog) {
|
|
|
+ PageQuery<EventLog> pageQuery = new PageQuery<EventLog>();
|
|
|
+ pageQuery.setPageSize(pageSize);
|
|
|
+ pageQuery.setPageNumber(pageNum);
|
|
|
+ pageQuery.setParas(eventLog);
|
|
|
+ return eventLogService.queryByPage(pageQuery);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询数据2
|
|
|
+ *
|
|
|
+ * @return 所有数据
|
|
|
+ */
|
|
|
+ @GetMapping("/queryPage2")
|
|
|
+ public Result<EventLogPageVo> queryPage2(@RequestParam Integer pageNum,
|
|
|
+ @RequestParam Integer pageSize,
|
|
|
+ @RequestParam(required = false) String applyId,
|
|
|
+ @RequestParam(required = false) String eventId,
|
|
|
+ @RequestParam(required = false) String applyName,
|
|
|
+ @RequestParam(required = false) String eventName) {
|
|
|
+ PageQuery<EventLogVo> pageQuery = new PageQuery<EventLogVo>();
|
|
|
+ pageQuery.setPageSize(pageSize);
|
|
|
+ pageQuery.setPageNumber(pageNum);
|
|
|
+ if (StrUtil.isNotBlank(applyId))
|
|
|
+ pageQuery.setPara("applyId", applyId);
|
|
|
+ if (StrUtil.isNotBlank(eventId))
|
|
|
+ pageQuery.setPara("eventId", eventId);
|
|
|
+ if (StrUtil.isNotBlank(applyName))
|
|
|
+ pageQuery.setPara("applyName", "%" + applyName + "%");
|
|
|
+ if (StrUtil.isNotBlank(eventName))
|
|
|
+ pageQuery.setPara("eventName", "%" + eventName + "%");
|
|
|
+ return Result.success(eventLogService.queryByPage2(pageQuery));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过主键查询单条数据
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @return 单条数据
|
|
|
+ */
|
|
|
+ @GetMapping("/queryOne")
|
|
|
+ public Result<EventLogVo> queryOne(@RequestParam("id") Integer id) {
|
|
|
+ return Result.success(eventLogService.queryById(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增数据
|
|
|
+ *
|
|
|
+ * @param eventLog 实体对象
|
|
|
+ * @return 新增结果
|
|
|
+ */
|
|
|
+ @PostMapping("/create")
|
|
|
+ public Result<?> create(@RequestBody EventLog eventLog) {
|
|
|
+ eventLogService.insert(eventLog);
|
|
|
+ return Result.success(eventLog);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改数据
|
|
|
+ *
|
|
|
+ * @param eventLog 实体对象
|
|
|
+ * @return 修改结果
|
|
|
+ */
|
|
|
+ @PostMapping("/update")
|
|
|
+ public Result<?> update(@RequestBody EventLog eventLog) {
|
|
|
+ return eventLogService.updateById(eventLog) ? Result.success() : Result.failure();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除数据
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @return 删除结果
|
|
|
+ */
|
|
|
+ @PostMapping("/delete")
|
|
|
+ public Result<Boolean> delete(@RequestParam("id") Integer id) {
|
|
|
+ return Result.success(this.eventLogService.deleteById(id));
|
|
|
+ }
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 批量新增数据
|
|
|
+// *
|
|
|
+// * @param models 实体对象
|
|
|
+// * @return 新增结果
|
|
|
+// */
|
|
|
+// @PostMapping("/createList")
|
|
|
+// public Result<Boolean> createList(@RequestBody Map<String, Object> models) {
|
|
|
+// List<EventLog> eventLogList = JSON.parseArray(JSON.toJSONString(models.get("eventLogList")), EventLog.class);
|
|
|
+// eventLogService.insertList(eventLogList);
|
|
|
+// return Result.success(true);
|
|
|
+// }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量新增数据
|
|
|
+ *
|
|
|
+ * @param eventLogList 实体对象
|
|
|
+ * @return 新增结果
|
|
|
+ */
|
|
|
+ @PostMapping("/createList")
|
|
|
+ public Result<Boolean> createList(@RequestBody List<EventLog> eventLogList, HttpServletRequest request) {
|
|
|
+ String ip = getRealIp(request);
|
|
|
+ eventLogList.forEach(item -> {
|
|
|
+ item.setIpAddress(ip);
|
|
|
+ });
|
|
|
+ eventLogService.insertList(eventLogList);
|
|
|
+ return Result.success(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取id地址
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ */
|
|
|
+ public static String getRealIp(HttpServletRequest request) {
|
|
|
+ String ip = request.getHeader("x-forwarded-for");
|
|
|
+ if (ip != null && ip.length() > 15 && ip.indexOf(",") > 0) {
|
|
|
+ ip = ip.substring(0, ip.indexOf(","));
|
|
|
+ }
|
|
|
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
|
|
+ ip = request.getHeader("Proxy-Client-IP");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
|
|
+ ip = request.getHeader("WL-Proxy-Client-IP");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
|
|
+ ip = request.getRemoteAddr();
|
|
|
+ }
|
|
|
+
|
|
|
+ return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : ip;
|
|
|
+ }
|
|
|
+}
|