应用权限参数配置
diff --git a/src/main/java/com/supwisdom/dlpay/system/controller/ParamController.java b/src/main/java/com/supwisdom/dlpay/system/controller/ParamController.java
index 7308802..50ab6a2 100644
--- a/src/main/java/com/supwisdom/dlpay/system/controller/ParamController.java
+++ b/src/main/java/com/supwisdom/dlpay/system/controller/ParamController.java
@@ -5,18 +5,20 @@
import com.supwisdom.dlpay.framework.domain.TBusinesspara;
import com.supwisdom.dlpay.framework.domain.TSyspara;
import com.supwisdom.dlpay.framework.service.SystemUtilService;
-import com.supwisdom.dlpay.framework.util.PageResult;
-import com.supwisdom.dlpay.framework.util.StringUtil;
-import com.supwisdom.dlpay.framework.util.WebConstant;
+import com.supwisdom.dlpay.framework.util.*;
import com.supwisdom.dlpay.system.service.ParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
+import java.util.HashMap;
+import java.util.Map;
+
@Controller
public class ParamController {
@Autowired
@@ -206,7 +208,7 @@
}
@GetMapping("/param/apiclientparalist")
- @PreAuthorize("hasPermission('/param/apiclientparalist','')")
+ @PreAuthorize("hasPermission('/param/apiclientpara','')")
@ResponseBody
public PageResult<TApiClient> getApiclientDataList(@RequestParam("page") Integer pageNo,
@RequestParam("limit") Integer pageSize,
@@ -221,5 +223,128 @@
}
}
+ @GetMapping("/param/load4addapiclient")
+ @PreAuthorize("hasPermission('/param/load4addapiclient','')")
+ public String load4AddApiclientPara(Model model) {
+ Map<String, String> roles = new HashMap<>(0);
+ roles.put("ROLE_THIRD_COMMON", "ROLE_THIRD_COMMON");
+ roles.put("ROLE_THIRD_CONSUME", "ROLE_THIRD_CONSUME");
+ roles.put("ROLE_THIRD_DEPOSIT", "ROLE_THIRD_DEPOSIT");
+ roles.put("ROLE_THIRD_SHOP", "ROLE_THIRD_SHOP");
+ roles.put("ROLE_THIRD_ADMIN", "ROLE_THIRD_ADMIN");
+ model.addAttribute("rolelist", roles);
+ return "system/param/apiclientform";
+ }
+
+ @PostMapping("/param/updateapiclientstate")
+ @PreAuthorize("hasPermission('/param/updateapiclientstate','')")
+ @ResponseBody
+ public JsonResult updateApiclientState(@RequestParam("appid") String appid, @RequestParam("state") String state) {
+ if (StringUtil.isEmpty(appid) || (!TradeDict.STATUS_NORMAL.equals(state) && !TradeDict.STATUS_CLOSED.equals(state))) {
+ return JsonResult.error("参数传递错误");
+ }
+ try {
+ TApiClient apiClient = paramService.getApiClientByAppid(appid);
+ if (null == apiClient) {
+ return JsonResult.error("应用参数不存在");
+ } else if (state.equals(apiClient.getStatus())) {
+ return JsonResult.error("状态修改错误,请刷新查询");
+ }
+ apiClient.setStatus(state);
+ if (paramService.saveOrUpdateApiClient(apiClient)) {
+ return JsonResult.ok(TradeDict.STATUS_NORMAL.equals(state) ? "启用成功" : "关闭成功");
+ } else {
+ return JsonResult.error(TradeDict.STATUS_NORMAL.equals(state) ? "启用失败" : "关闭失败");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return JsonResult.error("系统处理异常").put("exception", e);
+ }
+ }
+
+ @PostMapping("/param/deleteapiclient")
+ @PreAuthorize("hasPermission('/param/deleteapiclient','')")
+ @ResponseBody
+ public JsonResult deleteApiclientParam(@RequestParam("appid") String appid) {
+ if (StringUtil.isEmpty(appid)) {
+ return JsonResult.error("参数传递错误");
+ }
+ try {
+ TApiClient apiClient = paramService.getApiClientByAppid(appid);
+ if (null == apiClient) {
+ return JsonResult.error("应用参数不存在");
+ }
+
+ if (paramService.deleteApiClient(apiClient)) {
+ return JsonResult.ok("删除成功");
+ } else {
+ return JsonResult.error("删除失败");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return JsonResult.error("系统处理异常").put("exception", e);
+ }
+ }
+
+ @PostMapping("/param/updateapiclientpara")
+ @PreAuthorize("hasPermission('/param/updateapiclientpara','')")
+ @ResponseBody
+ public JsonResult updateApiclientSecret(@RequestParam("appid") String appid,
+ @RequestParam(value = "secret", required = false) String secret,
+ @RequestParam(value = "roles", required = false) String roles) {
+ if (StringUtil.isEmpty(appid) || (StringUtil.isEmpty(secret) && StringUtil.isEmpty(roles))) {
+ return JsonResult.error("参数传递错误");
+ }
+ try {
+ TApiClient apiClient = paramService.getApiClientByAppid(appid);
+ if (null == apiClient) {
+ return JsonResult.error("应用参数不存在");
+ }
+ if (!StringUtil.isEmpty(secret)) {
+ apiClient.setSecret(secret);
+ }
+ if (!StringUtil.isEmpty(roles)) {
+ apiClient.setRoles(roles);
+ }
+ if (paramService.saveOrUpdateApiClient(apiClient)) {
+ return JsonResult.ok("修改成功");
+ } else {
+ return JsonResult.error("修改失败");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return JsonResult.error("系统处理异常").put("exception", e);
+ }
+ }
+
+ @PostMapping("/param/addapiclientpara")
+ @PreAuthorize("hasPermission('/param/addapiclientpara','')")
+ @ResponseBody
+ public JsonResult addApiclientPara(@RequestParam("appid") String appid,
+ @RequestParam("roles") String roles) {
+ if (StringUtil.isEmpty(appid) || StringUtil.isEmpty(roles)) {
+ return JsonResult.error("参数传递错误");
+ }
+ try {
+ TApiClient apiClient = paramService.getApiClientByAppid(appid);
+ if (null != apiClient) {
+ return JsonResult.error("APPID重复");
+ }
+ apiClient = new TApiClient();
+ apiClient.setAppid(appid.trim());
+ apiClient.setSecret(RandomUtils.getUUIDStr());
+ apiClient.setStatus(TradeDict.STATUS_NORMAL);
+ apiClient.setRoles(roles);
+ if (paramService.saveOrUpdateApiClient(apiClient)) {
+ return JsonResult.ok("新增成功");
+ } else {
+ return JsonResult.error("新增失败");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return JsonResult.error("系统处理异常").put("exception", e);
+ }
+ }
+
}
diff --git a/src/main/java/com/supwisdom/dlpay/system/service/ParamService.java b/src/main/java/com/supwisdom/dlpay/system/service/ParamService.java
index a28ebf8..3097754 100644
--- a/src/main/java/com/supwisdom/dlpay/system/service/ParamService.java
+++ b/src/main/java/com/supwisdom/dlpay/system/service/ParamService.java
@@ -32,4 +32,14 @@
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, readOnly = true)
PageResult<TApiClient> getApiClientparaPage(String appid, int pageNo, int pageSize);
+
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, readOnly = true)
+ TApiClient getApiClientByAppid(String appid);
+
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
+ boolean saveOrUpdateApiClient(TApiClient apiClient);
+
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
+ boolean deleteApiClient(TApiClient apiClient);
+
}
diff --git a/src/main/java/com/supwisdom/dlpay/system/service/impl/ParamServiceImpl.java b/src/main/java/com/supwisdom/dlpay/system/service/impl/ParamServiceImpl.java
index 89438bc..8d63932 100644
--- a/src/main/java/com/supwisdom/dlpay/system/service/impl/ParamServiceImpl.java
+++ b/src/main/java/com/supwisdom/dlpay/system/service/impl/ParamServiceImpl.java
@@ -113,4 +113,30 @@
return new PageResult<>(apiClientDao.findAll(pageable));
}
+ @Override
+ public TApiClient getApiClientByAppid(String appid) {
+ if (!StringUtil.isEmpty(appid)) {
+ return apiClientDao.findByAppid(appid.trim());
+ }
+ return null;
+ }
+
+ @Override
+ public boolean saveOrUpdateApiClient(TApiClient apiClient){
+ if(null!=apiClient){
+ apiClientDao.save(apiClient);
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean deleteApiClient(TApiClient apiClient) {
+ if (null != apiClient) {
+ apiClientDao.delete(apiClient);
+ return true;
+ }
+ return false;
+ }
+
}
diff --git a/src/main/resources/templates/system/param/apiclientform.html b/src/main/resources/templates/system/param/apiclientform.html
new file mode 100644
index 0000000..112645e
--- /dev/null
+++ b/src/main/resources/templates/system/param/apiclientform.html
@@ -0,0 +1,78 @@
+<form id="appid-form" lay-filter="form" class="layui-form model-form">
+ <div class="layui-form-item">
+ <label class="layui-form-label">APPID</label>
+ <div class="layui-input-block">
+ <input name="appid" placeholder="请输入APPID" type="text" class="layui-input" maxlength="30"
+ lay-verify="required|number" required/>
+ </div>
+ </div>
+ <div class="layui-form-item">
+ <label class="layui-form-label">角色</label>
+ <div class="layui-input-block">
+ <select name="roles" xm-select="roles" lay-verify="required">
+ <option th:each="role : ${rolelist}" th:value="${role.key}">[[${role.value}]]</option>
+ </select>
+ </div>
+ </div>
+
+ <div class="layui-form-item model-form-footer">
+ <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
+ <button class="layui-btn" lay-filter="form-submit" lay-submit id="submitbtn">保存</button>
+ </div>
+</form>
+
+
+<script>
+ layui.use(['layer', 'admin', 'form', 'formSelects'], function () {
+ var layer = layui.layer;
+ var admin = layui.admin;
+ var form = layui.form;
+ var formSelects = layui.formSelects;
+
+ var url = '/param/addapiclientpara';
+ // 回显user数据
+ var apiparam = admin.getTempData('t_appclient');
+ debugger
+ if (undefined != apiparam && null != apiparam) {
+ url = '/param/updateapiclientpara';
+ $('input[name="appid"]').attr('readonly', 'readonly');
+ $('input[name="appid"]').val(apiparam.appid);
+ var rds = apiparam.roles.split(",");
+ formSelects.value('roles', rds);
+ }
+ // 表单提交事件
+ form.on('submit(form-submit)', function (data) {
+ layer.load(2);
+ var token_name = $("meta[name='_csrf_token']").attr("content");
+ var token = $("meta[name='_csrf_token']").attr("value");
+ data.field[token_name] = token;
+ $.ajax({
+ type : "POST",
+ dataType : "json",
+ url : url,
+ data : data.field,
+ success : function(result) {
+ layer.closeAll('loading');
+ if (result.code == 200) {
+ layer.msg(result.msg, {icon: 1});
+ admin.finishPopupCenter();
+ } else if (data.code == 401) {
+ layer.msg(result.msg, {icon: 2, time: 1500}, function () {
+ location.replace('/login');
+ }, 1000);
+ return;
+ } else {
+ console.log('err:' + result.code);
+ layer.msg(result.msg, {icon: 2});
+ }
+ },
+ error : function(data) {
+ layer.closeAll('loading');
+ layer.msg("请求服务器失败!", {icon: 2});
+ }
+ });
+ return false;
+ });
+ });
+</script>
+
diff --git a/src/main/resources/templates/system/param/apiclientpara.html b/src/main/resources/templates/system/param/apiclientpara.html
index f82e9c0..4cc2ade 100644
--- a/src/main/resources/templates/system/param/apiclientpara.html
+++ b/src/main/resources/templates/system/param/apiclientpara.html
@@ -22,7 +22,7 @@
<!-- 表格操作列 -->
<script type="text/html" id="apiclient-table-bar">
- <a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
+ <a class="layui-btn layui-btn-xs" lay-event="editRole">修改角色</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
@@ -45,15 +45,11 @@
page: true,
cols: [
[
- {field: 'appid', title: 'APPID', width: 366, align: 'right', fixed: 'left', sort: true},
- {field: 'secret', title: '密钥', align: 'left', style:'cursor: pointer;', event: 'modifyValue'},
+ {field: 'appid', title: 'APPID', width: 120, align: 'right', fixed: 'left', sort: true},
+ {field: 'secret', title: '密钥', align: 'center', edit: 'text'},
{field: 'status', title: '状态', width: 100, templet: '#api-tpl-state',sort: true},
- {
- field: 'roles', title: '角色', templet: function (item) {
- return 'test';
- }
- },
- {align: 'center', title: '操作', width: 80, toolbar: '#apiclient-table-bar', fixed: 'right'}
+ {field: 'roles', title: '角色', align: 'center' },
+ {align: 'center', title: '操作', width: 150, toolbar: '#apiclient-table-bar', fixed: 'right'}
]
]
});
@@ -64,28 +60,60 @@
});
$('#btn-add').click(function () {
- admin.popupCenter({
- title: "新增应用权限",
- area:["600px","300px"],
- path: '/param/',
- finish: function () {
- table.reload('businessparaTable');
- }
- });
+ showEditModel();
});
$('#btn-reset').click(function () {
$("#search-appid").val("");
});
+ function showEditModel(data) {
+ var title = data ? '修改角色' : '新增应用';
+ admin.putTempData('t_appclient', data);
+ admin.popupCenter({
+ title: title,
+ path: '/param/load4addapiclient',
+ finish: function () {
+ table.reload('apiClientTable');
+ }
+ });
+ }
+
+ // 修改user状态
+ form.on('switch(api-tpl-state)', function (obj) {
+ var token = $("meta[name='_csrf_token']").attr("value");
+ admin.go('/param/updateapiclientstate', {
+ appid: obj.elem.value,
+ state: obj.elem.checked ? 'normal' : 'closed',
+ _csrf: token
+ }, function (data) {
+ if (data.code == 200) {
+ layer.msg(data.msg, {icon: 1});
+ } else if (data.code == 401) {
+ layer.msg(data.msg, {icon: 2, time: 1500}, function () {
+ location.replace('/login');
+ }, 1000);
+ return;
+ } else {
+ layer.msg(data.msg, {icon: 2});
+ $(obj.elem).prop('checked', !obj.elem.checked);
+ form.render('checkbox');
+ }
+ },function () {
+ layer.msg('请求失败了,请稍后再试', {icon: 2});
+ $(obj.elem).prop('checked', !obj.elem.checked);
+ form.render('checkbox');
+ });
+ });
+
//监听单元格
table.on('tool(apiClientTable-filter)', function (obj) {
var data = obj.data;
if('del' == obj.event){
- if(confirm("确定要删除业务参数["+data.parakey+"]吗?")){
+ if(confirm("确定要删除应用参数["+data.appid+"]吗?")){
layer.load(2);
- admin.go('/param/deletebusinesspara', {
- parakey: data.parakey,
+ admin.go('/param/deleteapiclient', {
+ appid: data.appid,
_csrf: $("meta[name='_csrf_token']").attr("value")
}, function (data) {
console.log(data.code);
@@ -100,44 +128,42 @@
} else {
layer.msg(data.msg, {icon: 2});
}
- table.reload('businessparaTable');
+ table.reload('apiClientTable');
}, function (ret) {
console.log(ret);
layer.closeAll('loading');
layer.msg('请求失败了,请稍后再试', {icon: 2});
});
}
- }else if('modifyValue' == obj.event){
- layer.prompt({
- formType: 2,
- title: '修改参数名为 ['+ data.parakey +'] 的值:',
- area: ['500px', '200px'],
- maxlength: 1000,
- value: data.paraval
- }, function(value, index){
- layer.close(index);
- admin.go('/param/businessparaupdate', {
- parakey: data.parakey,
- paraval: value,
- _csrf: $("meta[name='_csrf_token']").attr("value"),
- }, function (data) {
- if (data.code == 200) {
- layer.msg("修改成功", {icon: 1});
- obj.update({ paraval: value });
- } else if (data.code == 401) {
- layer.msg(data.msg, {icon: 2, time: 1500}, function () {
- location.replace('/login');
- }, 1000);
- return;
- } else {
- layer.msg(data.msg, {icon: 2});
- }
- },function () {
- layer.msg('修改失败了,请稍后再试', {icon: 2});
- });
- });
+ }else if('editRole' ==obj.event){
+ showEditModel(data);
}
});
+ table.on('edit(apiClientTable-filter)', function (obj) {
+ var row = obj.data; //得到所在行所有键值
+ var newval = obj.value; //得到修改后的值
+ admin.go('/param/updateapiclientpara', {
+ appid: row.appid,
+ secret: newval,
+ _csrf: $("meta[name='_csrf_token']").attr("value"),
+ }, function (data) {
+ if (data.code == 200) {
+ layer.msg("修改成功", {icon: 1});
+ } else if (data.code == 401) {
+ layer.msg(data.msg, {icon: 2, time: 1500}, function () {
+ location.replace('/login');
+ }, 1000);
+ return;
+ } else {
+ layer.msg(data.msg, {icon: 2});
+ table.reload('apiClientTable');
+ }
+ },function () {
+ layer.msg('修改失败了,请稍后再试', {icon: 2});
+ table.reload('apiClientTable');
+ });
+ })
+
});
</script>
\ No newline at end of file
diff --git a/src/main/resources/templates/system/param/businesspara.html b/src/main/resources/templates/system/param/businesspara.html
index d7a4783..80ddac4 100644
--- a/src/main/resources/templates/system/param/businesspara.html
+++ b/src/main/resources/templates/system/param/businesspara.html
@@ -34,7 +34,6 @@
table.render({
elem: '#businessparaTable',
url: '/param/businessparalist',
- toolbar:'',
page: true,
cols: [
[