From 521047959c15fcd546853b9162e5284aea3b0658 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期二, 19 十二月 2023 16:40:32 +0800
Subject: [PATCH] #
---
zy-asrs-common/src/main/java/com/zy/asrs/common/sys/controller/HostController.java | 100 ++++++++++++++++++++
zy-asrs-common/src/main/java/com/zy/asrs/common/sys/controller/ConfigController.java | 146 +++++++++++++++++++++++++++++
zy-asrs-framework/src/main/resources/templates/Controller.txt | 2
3 files changed, 246 insertions(+), 2 deletions(-)
diff --git a/zy-asrs-common/src/main/java/com/zy/asrs/common/sys/controller/ConfigController.java b/zy-asrs-common/src/main/java/com/zy/asrs/common/sys/controller/ConfigController.java
new file mode 100644
index 0000000..f4c296c
--- /dev/null
+++ b/zy-asrs-common/src/main/java/com/zy/asrs/common/sys/controller/ConfigController.java
@@ -0,0 +1,146 @@
+package com.zy.asrs.common.sys.controller;
+
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.zy.asrs.common.domain.entity.Parameter;
+import com.zy.asrs.common.sys.entity.Config;
+import com.zy.asrs.common.sys.service.ConfigService;
+import com.zy.asrs.common.web.BaseController;
+import com.zy.asrs.framework.annotations.ManagerAuth;
+import com.zy.asrs.framework.common.Cools;
+import com.zy.asrs.framework.common.R;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.*;
+
+@RestController
+public class ConfigController extends BaseController {
+
+ @Autowired
+ private ConfigService configService;
+
+ @RequestMapping(value = "/config/{id}/auth")
+ @ManagerAuth
+ public R get(@PathVariable("id") Long id) {
+ return R.ok(configService.getById(String.valueOf(id)));
+ }
+
+ @RequestMapping(value = "/config/list/auth")
+ @ManagerAuth
+ public R list(@RequestParam(defaultValue = "1")Integer curr,
+ @RequestParam(defaultValue = "10")Integer limit,
+ @RequestParam(required = false)String condition,
+ @RequestParam Map<String, Object> param){
+ LambdaQueryWrapper<Config> wrapper = new LambdaQueryWrapper<>();
+ return R.ok(configService.page(new Page<>(curr, limit), wrapper));
+ }
+
+ @RequestMapping(value = "/config/edit/auth")
+ @ManagerAuth
+ public R edit(Config config) {
+ if (Cools.isEmpty(config)){
+ return R.error();
+ }
+ if (config.getType() == 2){
+ if (!checkJson(config.getValue())){
+ return R.error("json瑙f瀽澶辫触");
+ }
+ }
+ if (null == config.getId()){
+ configService.save(config);
+ } else {
+ configService.updateById(config);
+ Parameter.reset();
+ }
+ return R.ok();
+ }
+
+ @RequestMapping(value = "/config/add/auth")
+ @ManagerAuth
+ public R add(Config config) {
+ if (config.getType() == 2){
+ if (!checkJson(config.getValue())){
+ return R.error("json瑙f瀽澶辫触");
+ }
+ }
+ configService.save(config);
+ return R.ok();
+ }
+
+ @RequestMapping(value = "/config/update/auth")
+ @ManagerAuth
+ public R update(Config config){
+ if (Cools.isEmpty(config) || null==config.getId()){
+ return R.error();
+ }
+ if (config.getType() == 2){
+ if (!checkJson(config.getValue())){
+ return R.error("json瑙f瀽澶辫触");
+ }
+ }
+ configService.updateById(config);
+ Parameter.reset();
+ return R.ok();
+ }
+
+ @RequestMapping(value = "/config/delete/auth")
+ @ManagerAuth
+ public R delete(Integer[] ids){
+ if (Cools.isEmpty(ids)){
+ return R.error();
+ }
+ configService.removeByIds(Arrays.asList(ids));
+ return R.ok();
+ }
+
+ @RequestMapping(value = "/configQuery/auth")
+ @ManagerAuth
+ public R query(String condition) {
+ LambdaQueryWrapper<Config> wrapper = new LambdaQueryWrapper<>();
+ wrapper.like(Config::getName, condition);
+ Page<Config> page = configService.page(new Page<>(0, 10), wrapper);
+ List<Map<String, Object>> result = new ArrayList<>();
+ for (Config config : page.getRecords()){
+ Map<String, Object> map = new HashMap<>();
+ map.put("id", config.getId());
+ map.put("value", config.getId());
+ result.add(map);
+ }
+ return R.ok(result);
+ }
+
+ /**
+ * 鍒锋柊閰嶇疆
+ */
+ @RequestMapping(value = "/config/refresh/auth")
+// @ManagerAuth
+ public R refresh(){
+ Parameter parameter;
+ try {
+ parameter = Parameter.reset();
+ } catch (Exception e) {
+ e.printStackTrace();
+ return R.error();
+ }
+ if (Cools.isEmpty(parameter)){
+ return R.error();
+ }
+ return R.ok();
+ }
+
+
+ private static boolean checkJson(String val){
+ Object parse = null;
+ try {
+ parse = JSON.parse(val);
+ } catch (Exception ignore){
+ }
+ return parse != null;
+ }
+
+}
diff --git a/zy-asrs-common/src/main/java/com/zy/asrs/common/sys/controller/HostController.java b/zy-asrs-common/src/main/java/com/zy/asrs/common/sys/controller/HostController.java
new file mode 100644
index 0000000..2805b16
--- /dev/null
+++ b/zy-asrs-common/src/main/java/com/zy/asrs/common/sys/controller/HostController.java
@@ -0,0 +1,100 @@
+package com.zy.asrs.common.sys.controller;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.zy.asrs.common.sys.entity.Host;
+import com.zy.asrs.common.sys.service.HostService;
+import com.zy.asrs.common.web.BaseController;
+import com.zy.asrs.framework.annotations.ManagerAuth;
+import com.zy.asrs.framework.common.Cools;
+import com.zy.asrs.framework.common.R;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.*;
+
+@RestController
+public class HostController extends BaseController {
+
+ @Autowired
+ private HostService hostService;
+
+ @RequestMapping(value = "/host/{id}/auth")
+ @ManagerAuth
+ public R get(@PathVariable("id") Long id) {
+ return R.ok(hostService.getById(String.valueOf(id)));
+ }
+
+ @RequestMapping(value = "/host/list/auth")
+ @ManagerAuth
+ public R list(@RequestParam(defaultValue = "1")Integer curr,
+ @RequestParam(defaultValue = "10")Integer limit,
+ @RequestParam(required = false)String orderByField,
+ @RequestParam(required = false)String orderByType,
+ @RequestParam Map<String, Object> param){
+ LambdaQueryWrapper<Host> wrapper = new LambdaQueryWrapper<>();
+ return R.ok(hostService.page(new Page<>(curr, limit), wrapper));
+ }
+
+ @RequestMapping(value = "/host/edit/auth")
+ @ManagerAuth
+ public R edit(Host host) {
+ if (Cools.isEmpty(host)){
+ return R.error();
+ }
+ if (null == host.getId()){
+ hostService.save(host);
+ } else {
+ hostService.updateById(host);
+ }
+ return R.ok();
+ }
+
+ @RequestMapping(value = "/host/add/auth")
+ @ManagerAuth
+ public R add(Host host) {
+ hostService.save(host);
+ return R.ok();
+ }
+
+ @RequestMapping(value = "/host/update/auth")
+ @ManagerAuth
+ public R update(Host host){
+ if (Cools.isEmpty(host) || null==host.getId()){
+ return R.error();
+ }
+ hostService.updateById(host);
+ return R.ok();
+ }
+
+ @RequestMapping(value = "/host/delete/auth")
+ @ManagerAuth
+ public R delete(Integer[] ids){
+ if (Cools.isEmpty(ids)){
+ return R.error();
+ }
+ hostService.removeByIds(Arrays.asList(ids));
+ return R.ok();
+ }
+
+
+ @RequestMapping(value = "/hostQuery/auth")
+ @ManagerAuth
+ public R query(String condition) {
+ LambdaQueryWrapper<Host> wrapper = new LambdaQueryWrapper<>();
+ wrapper.like(Host::getName, condition);
+ Page<Host> page = hostService.page(new Page<>(0, 10), wrapper);
+ List<Map<String, Object>> result = new ArrayList<>();
+ for (Host host : page.getRecords()){
+ Map<String, Object> map = new HashMap<>();
+ map.put("id", host.getId());
+ map.put("value", host.getName());
+ result.add(map);
+ }
+ return R.ok(result);
+ }
+
+}
diff --git a/zy-asrs-framework/src/main/resources/templates/Controller.txt b/zy-asrs-framework/src/main/resources/templates/Controller.txt
index 7d3460e..c26fd3f 100644
--- a/zy-asrs-framework/src/main/resources/templates/Controller.txt
+++ b/zy-asrs-framework/src/main/resources/templates/Controller.txt
@@ -32,8 +32,6 @@
@ManagerAuth
public R page(@RequestParam(defaultValue = "1")Integer curr,
@RequestParam(defaultValue = "10")Integer limit,
- @RequestParam(required = false)String orderByField,
- @RequestParam(required = false)String orderByType,
@RequestParam(required = false)String condition,
@RequestParam Map<String, Object> param){
LambdaQueryWrapper<@{ENTITYNAME}> wrapper = new LambdaQueryWrapper<>();
--
Gitblit v1.9.1