Commit ecacdf0a authored by 肖莹's avatar 肖莹

添加应用管理配置的日志

parent 53d4f750
......@@ -6,7 +6,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Objects;
import com.archser.aserver.interceptor.JwtInterceptor;
import com.archser.aserver.model.Config;
import com.archser.aserver.service.LogService;
import com.archser.aserver.service.SystemService;
import com.archser.aserver.validator.SettingValidator;
import com.jfinal.aop.Before;
......@@ -28,176 +30,212 @@ import sun.misc.BASE64Encoder;
@SuppressWarnings("restriction")
public class SettingController extends Controller {
/**
* 通用的获取配置方法
*
* @param name
*/
@Before(SettingValidator.class)
public void index(String name) {
String val = null;
try {
val = this.getConfig(name);
} catch (Exception e) {
this.renderJson(Ret.fail("msg", e.getMessage()));
}
this.renderJson(Ret.ok(name, val));
}
/**
* 获取所有配置
*/
public void all() {
this.renderJson(Ret.ok("configs", Config.dao.findAll()));
}
@Inject
private SystemService systemService;
/**
*
*/
public void findConfigList() {
String searchText = this.getPara("searchText");
List<Config> configs = systemService.findConfigList(searchText);
this.renderJson(Ret.ok("configs", configs));
}
/**
* 获取单点登录地址<br>
* 常用配置项
*/
@Clear
// @Before(UnifiedErrorInterceptor.class)
public void sso() {
String val = null;
try {
val = this.getConfig("sso");
} catch (Exception e) {
this.renderJson(Ret.fail("msg", e.getMessage()));
}
this.renderJson(Ret.ok("sso", val));
}
/**
* 获取设置信息<br>
* 常用配置项
*/
public void search() {
String val = null;
try {
val = this.getConfig("search");
} catch (Exception e) {
this.renderJson(Ret.fail("msg", e.getMessage()));
}
this.renderJson(Ret.ok("search", val));
}
/**
* 获取设置信息<br>
* 常用配置项
*/
public void logoUrl() {
String filePath = PathKit.getWebRootPath() + File.separator + "logo" + File.separator + "logo.png";
this.renderJson(Ret.ok("logoUrl", ImageToBase64(filePath)));
}
private static String ImageToBase64(String imgPath) {
byte[] data = null;
// 读取图片字节数组
try {
InputStream in = new FileInputStream(imgPath);
data = new byte[in.available()];
in.read(data);
in.close();
} catch (IOException e) {
e.printStackTrace();
}
// 对字节数组Base64编码
BASE64Encoder encoder = new BASE64Encoder();
// 返回Base64编码过的字节数组字符串
return encoder.encode(Objects.requireNonNull(data));
// System.out.println("本地图片转换Base64:" + encoder.encode(Objects.requireNonNull(data)));
}
// public void logoUrl() {
// String val = null;
// try {
// val = this.getConfig("logoUrl");
// } catch (Exception e) {
// this.renderJson(Ret.fail("msg", e.getMessage()));
// }
// this.renderJson(Ret.ok("logoUrl", val));
// }
public void getServerName() {
String val = null;
try {
val = this.getConfig("serverName");
} catch (Exception e) {
this.renderJson(Ret.fail("msg", e.getMessage()));
}
this.renderJson(Ret.ok("serverName", val));
}
/**
* 获取配置项目
*
* @param name
* @return
* @throws Exception
*/
private String getConfig(String name) throws Exception {
String val = Db.queryStr(Db.getSql("getConfigByName"), name);
if (val == null) {
throw new Exception("配置项不存在(name='" + name + "')");
}
return val;
}
/**
* @used 添加修改配置
*/
@Before(Tx.class)
public void add() {
Config config = getModel(Config.class, "", true);
if (config == null) {
renderJson(Ret.fail("msg", "请填写完整数据"));
} else if (config.getId() == null || config.getId() == 0) {
config.set("ID", Config.SEQ_NEXTVAL);
config.save();
renderJson(Ret.ok("ok", "添加成功"));
} else if (config.getId() != 0) {
config.update();
renderJson(Ret.ok("ok", "修改成功"));
}
}
/**
* @used 删除配置
*/
@Before(Tx.class)
public void dele() {
String ids = this.getPara("ids");
String[] idsArray = ids.split(",");
if (ids == null || idsArray.length == 0) {
renderJson(Ret.fail("msg", "请选择数据"));
}
Boolean success = false;
for (String id : idsArray) {
Config config = new Config();
config.setId(Integer.valueOf(id));
success = config.delete();
}
if (success) {
renderJson(Ret.ok());
} else {
renderJson(Ret.fail("msg", "删除数据出错"));
}
}
@Inject
private LogService logService;
/**
* 通用的获取配置方法
*
* @param name
*/
@Before(SettingValidator.class)
public void index(String name) {
String val = null;
try {
val = this.getConfig(name);
} catch (Exception e) {
this.renderJson(Ret.fail("msg", e.getMessage()));
}
this.renderJson(Ret.ok(name, val));
}
/**
* 获取所有配置
*/
public void all() {
this.renderJson(Ret.ok("configs", Config.dao.findAll()));
}
@Inject
private SystemService systemService;
/**
*
*/
public void findConfigList() {
String searchText = this.getPara("searchText");
List<Config> configs = systemService.findConfigList(searchText);
/** xiaoying 20200715 YZJ-4212 功能操作中没有应用管理的日志 start */
if (configs != null && configs.size() != 0) {
this.renderJson(Ret.ok("configs", configs));
logService.saveAsLog("operate", getAttr("username"), JwtInterceptor.getIpAddr(getRequest()),
"应用管理-配置-查询数据包含:" + searchText + "的数据", "aserver");
} else {
logService.saveAsLog("operate", getAttr("username"), JwtInterceptor.getIpAddr(getRequest()),
"应用管理-配置-查询数据失败", "aserver");
}
/** xiaoying 20200715 YZJ-4212 功能操作中没有应用管理的日志 end */
}
/**
* 获取单点登录地址<br>
* 常用配置项
*/
@Clear
// @Before(UnifiedErrorInterceptor.class)
public void sso() {
String val = null;
try {
val = this.getConfig("sso");
} catch (Exception e) {
this.renderJson(Ret.fail("msg", e.getMessage()));
}
this.renderJson(Ret.ok("sso", val));
}
/**
* 获取设置信息<br>
* 常用配置项
*/
public void search() {
String val = null;
try {
val = this.getConfig("search");
} catch (Exception e) {
this.renderJson(Ret.fail("msg", e.getMessage()));
}
this.renderJson(Ret.ok("search", val));
}
/**
* 获取设置信息<br>
* 常用配置项
*/
public void logoUrl() {
String filePath =
PathKit.getWebRootPath() + File.separator + "logo" + File.separator + "logo.png";
this.renderJson(Ret.ok("logoUrl", ImageToBase64(filePath)));
}
private static String ImageToBase64(String imgPath) {
byte[] data = null;
// 读取图片字节数组
try {
InputStream in = new FileInputStream(imgPath);
data = new byte[in.available()];
in.read(data);
in.close();
} catch (IOException e) {
e.printStackTrace();
}
// 对字节数组Base64编码
BASE64Encoder encoder = new BASE64Encoder();
// 返回Base64编码过的字节数组字符串
return encoder.encode(Objects.requireNonNull(data));
// System.out.println("本地图片转换Base64:" + encoder.encode(Objects.requireNonNull(data)));
}
// public void logoUrl() {
// String val = null;
// try {
// val = this.getConfig("logoUrl");
// } catch (Exception e) {
// this.renderJson(Ret.fail("msg", e.getMessage()));
// }
// this.renderJson(Ret.ok("logoUrl", val));
// }
public void getServerName() {
String val = null;
try {
val = this.getConfig("serverName");
} catch (Exception e) {
this.renderJson(Ret.fail("msg", e.getMessage()));
}
this.renderJson(Ret.ok("serverName", val));
}
/**
* 获取配置项目
*
* @param name
* @return
* @throws Exception
*/
private String getConfig(String name) throws Exception {
String val = Db.queryStr(Db.getSql("getConfigByName"), name);
if (val == null) {
throw new Exception("配置项不存在(name='" + name + "')");
}
return val;
}
/**
* @used 添加修改配置
*/
@Before(Tx.class)
public void add() {
Config config = getModel(Config.class, "", true);
Boolean success = false;
if (config == null) {
renderJson(Ret.fail("msg", "请填写完整数据"));
} else if (config.getId() == null || config.getId() == 0) {
config.set("ID", Config.SEQ_NEXTVAL);
success = config.save();
/** xiaoying 20200715 YZJ-4212 功能操作中没有应用管理的日志 start */
if (success) {
renderJson(Ret.ok("ok", "添加成功"));
logService.saveAsLog("operate", getAttr("username"), JwtInterceptor.getIpAddr(getRequest()),
"应用管理-配置-添加配置-配置名称为-" + config.getName() + "-添加成功", "aserver");
} else {
logService.saveAsLog("operate", getAttr("username"), JwtInterceptor.getIpAddr(getRequest()),
"应用管理-配置-添加配置-配置名称为-" + config.getName() + "-添加失败", "aserver");
}
} else if (config.getId() != 0) {
success = config.update();
if (success) {
renderJson(Ret.ok("ok", "修改成功"));
logService.saveAsLog("operate", getAttr("username"), JwtInterceptor.getIpAddr(getRequest()),
"应用管理-配置-编辑配置-配置名称为-" + config.getName() + "-修改成功", "aserver");
} else {
logService.saveAsLog("operate", getAttr("username"), JwtInterceptor.getIpAddr(getRequest()),
"应用管理-配置-编辑配置-配置名称为-" + config.getName() + "-修改失败", "aserver");
}
/** xiaoying 20200715 YZJ-4212 功能操作中没有应用管理的日志 end */
}
}
/**
* @used 删除配置
*/
@Before(Tx.class)
public void dele() {
String ids = this.getPara("ids");
String[] idsArray = ids.split(",");
if (ids == null || idsArray.length == 0) {
renderJson(Ret.fail("msg", "请选择数据"));
}
Boolean success = false;
StringBuilder sb = new StringBuilder();
/** xiaoying 20200715 YZJ-4212 功能操作中没有应用管理的日志 start */
for (String id : idsArray) {
sb.append(Config.dao.findById(Integer.valueOf(id)).getName() + ",");
success = Config.dao.deleteById(Integer.valueOf(id));
}
if (success) {
renderJson(Ret.ok());
logService.saveAsLog("operate", getAttr("username"), JwtInterceptor.getIpAddr(getRequest()),
"应用管理-配置-删除配置-配置名称为-" + sb.substring(0, sb.lastIndexOf(",")) + "-删除成功", "aserver");
} else {
renderJson(Ret.fail("msg", "删除数据出错"));
logService.saveAsLog("operate", getAttr("username"), JwtInterceptor.getIpAddr(getRequest()),
"应用管理-配置-删除配置-配置名称为-" + sb.substring(0, sb.lastIndexOf(",")) + "-删除失败", "aserver");
}
/** xiaoying 20200715 YZJ-4212 功能操作中没有应用管理的日志 end */
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment