系统中心
diff --git a/src/main/java/com/supwisdom/dlpay/api/domain/TPointsTransdtl.java b/src/main/java/com/supwisdom/dlpay/api/domain/TPointsTransdtl.java
index f56a53a..dba4514 100644
--- a/src/main/java/com/supwisdom/dlpay/api/domain/TPointsTransdtl.java
+++ b/src/main/java/com/supwisdom/dlpay/api/domain/TPointsTransdtl.java
@@ -25,7 +25,7 @@
@Column(name="BEFPOINTS", length = 15)
private Long befpoints;
- @Column(name="BEFPOINTS", length = 15)
+ @Column(name="AFTPOINTS", length = 15)
private Long aftpoints;
@Column(name="STATUS", length = 15)
diff --git a/src/main/java/com/supwisdom/dlpay/framework/dao/OperLogDao.java b/src/main/java/com/supwisdom/dlpay/framework/dao/OperLogDao.java
new file mode 100644
index 0000000..e8fa58e
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/framework/dao/OperLogDao.java
@@ -0,0 +1,10 @@
+package com.supwisdom.dlpay.framework.dao;
+
+import com.supwisdom.dlpay.framework.domain.TOperLog;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface OperLogDao extends JpaRepository<TOperLog, String> {
+ Page<TOperLog> findAllByOpernameContaining(String opername, Pageable pageable);
+}
diff --git a/src/main/java/com/supwisdom/dlpay/framework/dao/OperRoleDao.java b/src/main/java/com/supwisdom/dlpay/framework/dao/OperRoleDao.java
index c3fe0d1..fa3dd5a 100644
--- a/src/main/java/com/supwisdom/dlpay/framework/dao/OperRoleDao.java
+++ b/src/main/java/com/supwisdom/dlpay/framework/dao/OperRoleDao.java
@@ -14,4 +14,8 @@
List<String> getRolecodeByOperid(String operid);
void deleteByRoleId(String roleId);
+
+ List<TOperRole> findAllByOperid(String operid);
+
+ void deleteByOperid(String operid);
}
diff --git a/src/main/java/com/supwisdom/dlpay/framework/domain/TOperLog.java b/src/main/java/com/supwisdom/dlpay/framework/domain/TOperLog.java
new file mode 100644
index 0000000..1243efd
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/framework/domain/TOperLog.java
@@ -0,0 +1,99 @@
+package com.supwisdom.dlpay.framework.domain;
+
+import org.hibernate.annotations.GenericGenerator;
+
+import javax.persistence.*;
+
+@Entity
+@Table(name = "TB_OPER_LOG")
+public class TOperLog {
+ @Id
+ @GenericGenerator(name = "idGenerator", strategy = "uuid")
+ @GeneratedValue(generator = "idGenerator")
+ @Column(name = "ID", nullable = false, length = 32)
+ private String id;
+
+ @Column(name = "OPERID", nullable = false, length = 32)
+ private String operid;
+ @Column(name = "OPERNAME")
+ private String opername;
+
+ @Column(name = "RESNAME")
+ private String resname;
+
+ @Column(name = "RESPATH")
+ private String respath;
+
+ @Column(name = "LOGDATE")
+ private String logdate;
+
+ @Column(name = "FUNCTIONID")
+ private Integer functionid;
+
+ @Column(name = "FUNCTIONNAME")
+ private String functionname;
+
+ public Integer getFunctionid() {
+ return functionid;
+ }
+
+ public void setFunctionid(Integer functionid) {
+ this.functionid = functionid;
+ }
+
+ public String getFunctionname() {
+ return functionname;
+ }
+
+ public void setFunctionname(String functionname) {
+ this.functionname = functionname;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getOperid() {
+ return operid;
+ }
+
+ public void setOperid(String operid) {
+ this.operid = operid;
+ }
+
+ public String getOpername() {
+ return opername;
+ }
+
+ public void setOpername(String opername) {
+ this.opername = opername;
+ }
+
+ public String getResname() {
+ return resname;
+ }
+
+ public void setResname(String resname) {
+ this.resname = resname;
+ }
+
+ public String getRespath() {
+ return respath;
+ }
+
+ public void setRespath(String respath) {
+ this.respath = respath;
+ }
+
+ public String getLogdate() {
+ return logdate;
+ }
+
+ public void setLogdate(String logdate) {
+ this.logdate = logdate;
+ }
+}
diff --git a/src/main/java/com/supwisdom/dlpay/framework/domain/TOperator.java b/src/main/java/com/supwisdom/dlpay/framework/domain/TOperator.java
index 62ae6b5..cfcbeea 100644
--- a/src/main/java/com/supwisdom/dlpay/framework/domain/TOperator.java
+++ b/src/main/java/com/supwisdom/dlpay/framework/domain/TOperator.java
@@ -48,6 +48,8 @@
@Column(name = "CLOSEDATE", length = 8)
private String closedate;
+ @Transient
+ private String roleids;
@Transient
private Collection<? extends GrantedAuthority> authorities; //权限
@@ -200,4 +202,12 @@
public boolean isEnabled() {
return !TradeDict.STATUS_CLOSED.equals(this.status); //注销操作员不启用
}
+
+ public String getRoleids() {
+ return roleids;
+ }
+
+ public void setRoleids(String roleids) {
+ this.roleids = roleids;
+ }
}
diff --git a/src/main/java/com/supwisdom/dlpay/framework/security/MyPermissionEvaluator.java b/src/main/java/com/supwisdom/dlpay/framework/security/MyPermissionEvaluator.java
index db6a4f1..02dbce4 100644
--- a/src/main/java/com/supwisdom/dlpay/framework/security/MyPermissionEvaluator.java
+++ b/src/main/java/com/supwisdom/dlpay/framework/security/MyPermissionEvaluator.java
@@ -1,10 +1,10 @@
package com.supwisdom.dlpay.framework.security;
-import com.supwisdom.dlpay.framework.domain.TPermission;
-import com.supwisdom.dlpay.framework.domain.TResource;
-import com.supwisdom.dlpay.framework.domain.TRole;
-import com.supwisdom.dlpay.framework.domain.TRoleFunction;
+import com.supwisdom.dlpay.framework.domain.*;
+import com.supwisdom.dlpay.framework.util.DateUtil;
import com.supwisdom.dlpay.framework.util.StringUtil;
+import com.supwisdom.dlpay.system.service.FunctionService;
+import com.supwisdom.dlpay.system.service.OperatorService;
import com.supwisdom.dlpay.system.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.PermissionEvaluator;
@@ -15,28 +15,46 @@
import java.io.Serializable;
import java.util.Collection;
+import java.util.List;
@Component
public class MyPermissionEvaluator implements PermissionEvaluator {
@Autowired
private RoleService roleService;
-
+ @Autowired
+ private OperatorService operatorService;
+ @Autowired
+ private FunctionService functionService;
@Override
public boolean hasPermission(Authentication authentication, Object targetUri, Object permission) {
//TODO save logger
if (targetUri != null) {
UserDetails userDetails = (UserDetails) authentication.getPrincipal();
if (userDetails != null) {
- Collection<GrantedAuthority> authorities = (Collection<GrantedAuthority>) userDetails.getAuthorities();
- for (GrantedAuthority authority : authorities) {
- String roleName = authority.getAuthority();
- TRole role = roleService.findRoleByRolecode(roleName);
- if (role != null) {
- TResource resource = roleService.findResourceByURI(String.valueOf(targetUri));
- if (resource != null) {
- TPermission permission1 = roleService.findByRoleIdAndResid(role.getRoleId(),resource.getId());
- if (permission1 != null) {
- return true;
+ TOperator operator = operatorService.getOperatorByCode(userDetails.getUsername());
+ if (operator != null) {
+ List<TOperRole> operRoles = operatorService.getOperRoleByOperId(operator.getOperid());
+ for (TOperRole operRole : operRoles) {
+ TRole role = roleService.findRoleByRoleid(operRole.getRoleId());
+ if (role != null) {
+ TResource resource = roleService.findResourceByURI(String.valueOf(targetUri));
+ if (resource != null) {
+ TPermission permission1 = roleService.findByRoleIdAndResid(role.getRoleId(), resource.getId());
+ if (permission1 != null) {
+ TOperLog log = new TOperLog();
+ log.setLogdate(DateUtil.getNow());
+ log.setOperid(operator.getOperid());
+ log.setOpername(operator.getOpercode());
+ log.setResname(resource.getName());
+ log.setRespath(resource.getUri());
+ TFunction function =functionService.getFunctionById(resource.getFunctionId());
+ if(function!=null){
+ log.setFunctionid(function.getId());
+ log.setFunctionname(function.getName());
+ }
+ operatorService.saveOperLog(log);
+ return true;
+ }
}
}
}
diff --git a/src/main/java/com/supwisdom/dlpay/framework/util/WebConstant.java b/src/main/java/com/supwisdom/dlpay/framework/util/WebConstant.java
index 4896a74..c6237a9 100644
--- a/src/main/java/com/supwisdom/dlpay/framework/util/WebConstant.java
+++ b/src/main/java/com/supwisdom/dlpay/framework/util/WebConstant.java
@@ -4,4 +4,5 @@
public static final int PAGENO_DEFAULT = 1;
public static final int PAGESIZE_DEFAULT = 10;
public static final String OPERPWD_DEFAULT = "123456";
+ public static final String OPERTYPE_DEFAULT = "oper";
}
diff --git a/src/main/java/com/supwisdom/dlpay/system/bean/LogBean.java b/src/main/java/com/supwisdom/dlpay/system/bean/LogBean.java
new file mode 100644
index 0000000..2ffbf62
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/system/bean/LogBean.java
@@ -0,0 +1,13 @@
+package com.supwisdom.dlpay.system.bean;
+
+public class LogBean extends PageBean{
+ private String opername;
+
+ public String getOpername() {
+ return opername;
+ }
+
+ public void setOpername(String opername) {
+ this.opername = opername;
+ }
+}
diff --git a/src/main/java/com/supwisdom/dlpay/system/controller/FunctionController.java b/src/main/java/com/supwisdom/dlpay/system/controller/FunctionController.java
index fbe505d..bbd7a5c 100644
--- a/src/main/java/com/supwisdom/dlpay/system/controller/FunctionController.java
+++ b/src/main/java/com/supwisdom/dlpay/system/controller/FunctionController.java
@@ -9,6 +9,7 @@
import com.supwisdom.dlpay.system.bean.FunctionSearchBean;
import com.supwisdom.dlpay.system.service.FunctionService;
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.*;
@@ -27,6 +28,7 @@
}
@GetMapping("/function/list")
+ @PreAuthorize("hasPermission('/function/index','')")
@ResponseBody
public PageResult<TFunction> getDataList(@RequestParam("page") Integer pageNo,
@RequestParam("limit") Integer pageSize,
@@ -46,11 +48,13 @@
}
@GetMapping("/function/loadadd")
+ @PreAuthorize("hasPermission('/function/loadadd','')")
public String loadadd() {
return "system/function/form";
}
@PostMapping("/function/add")
+ @PreAuthorize("hasPermission('/function/add','')")
@ResponseBody
public JsonResult add(@RequestBody TFunction function) {
if (function != null) {
@@ -60,6 +64,7 @@
}
}
@PostMapping("/function/delfunc")
+ @PreAuthorize("hasPermission('/function/delfunc','')")
@ResponseBody
public JsonResult delfunc(@RequestParam Integer funcid) {
return functionService.deleteFunction(funcid);
@@ -78,6 +83,7 @@
}
@GetMapping("/function/loadsubadd")
+ @PreAuthorize("hasPermission('/function/loadsubadd','')")
public String loadsubadd(Model model) {
List<TFunction> functionList = functionService.getParentFunction();
model.addAttribute("list", functionList);
@@ -85,6 +91,7 @@
}
@GetMapping("/function/loadres")
+ @PreAuthorize("hasPermission('/function/loadres','')")
public String loadres(@RequestParam Integer functionid, Model model) {
TFunction function = functionService.getFunctionById(functionid);
List<TResource> resources = functionService.getResources(functionid);
@@ -93,6 +100,7 @@
return "system/function/reslist";
}
@GetMapping("/function/reslist")
+ @PreAuthorize("hasPermission('/function/loadres','')")
@ResponseBody
public PageResult<TResource> reslist(@RequestParam Integer functionid, Model model) {
List<TResource> resources = functionService.getResources(functionid);
@@ -106,6 +114,7 @@
}
@PostMapping("/function/addres")
+ @PreAuthorize("hasPermission('/function/addres','')")
@ResponseBody
public JsonResult addres(@RequestBody TResource resource) {
if (resource != null) {
@@ -121,6 +130,7 @@
return "system/function/resform";
}
@PostMapping("/function/delres")
+ @PreAuthorize("hasPermission('/function/delres','')")
@ResponseBody
public JsonResult delres(@RequestParam Integer resid) {
return functionService.deleteResource(resid);
diff --git a/src/main/java/com/supwisdom/dlpay/system/controller/OperatorController.java b/src/main/java/com/supwisdom/dlpay/system/controller/OperatorController.java
index 85acf8b..173cc64 100644
--- a/src/main/java/com/supwisdom/dlpay/system/controller/OperatorController.java
+++ b/src/main/java/com/supwisdom/dlpay/system/controller/OperatorController.java
@@ -1,10 +1,15 @@
package com.supwisdom.dlpay.system.controller;
import com.supwisdom.dlpay.api.bean.JsonResult;
+import com.supwisdom.dlpay.framework.domain.TFunction;
+import com.supwisdom.dlpay.framework.domain.TOperLog;
+import com.supwisdom.dlpay.framework.domain.TOperRole;
import com.supwisdom.dlpay.framework.domain.TOperator;
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.system.bean.FunctionSearchBean;
+import com.supwisdom.dlpay.system.bean.LogBean;
import com.supwisdom.dlpay.system.bean.OperatorSearchBean;
import com.supwisdom.dlpay.system.service.OperatorService;
import com.supwisdom.dlpay.system.service.RoleService;
@@ -15,98 +20,143 @@
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
+import java.util.List;
+
@Controller
@RequestMapping("/operator")
public class OperatorController {
- @Autowired
- private OperatorService operatorService;
- @Autowired
- private RoleService roleService;
+ @Autowired
+ private OperatorService operatorService;
+ @Autowired
+ private RoleService roleService;
- @GetMapping("/index")
- @PreAuthorize("hasPermission('/operator/index','')")
- public String indexView(Model model) {
- return "system/operator/index";
- }
+ @GetMapping("/index")
+ @PreAuthorize("hasPermission('/operator/index','')")
+ public String indexView(Model model) {
+ return "system/operator/index";
+ }
- @GetMapping("/list")
- @ResponseBody
- public PageResult<TOperator> getDataList(@RequestParam("page") Integer pageNo,
- @RequestParam("limit") Integer pageSize,
- @RequestParam(value = "searchkey", required = false) String searchKey,
- @RequestParam(value = "searchvalue", required = false) String searchValue,
- Model model) {
- try {
+ @GetMapping("/list")
+ @ResponseBody
+ public PageResult<TOperator> getDataList(@RequestParam("page") Integer pageNo,
+ @RequestParam("limit") Integer pageSize,
+ @RequestParam(value = "searchkey", required = false) String searchKey,
+ @RequestParam(value = "searchvalue", required = false) String searchValue,
+ Model model) {
+ try {
- if (null == pageNo || pageNo < 1) pageNo = WebConstant.PAGENO_DEFAULT;
- if (null == pageSize || pageSize < 1) pageSize = WebConstant.PAGESIZE_DEFAULT;
- OperatorSearchBean searchBean = new OperatorSearchBean();
- if (!StringUtil.isEmpty(searchValue)) {
- if ("opercode".equals(searchKey)) {
- searchBean.setOpercode(searchValue.trim());
- } else if ("opername".equals(searchKey)) {
- searchBean.setOpername(searchValue.trim());
- } else if ("mobile".equals(searchValue.trim())) {
- searchBean.setMobile(searchValue.trim());
+ if (null == pageNo || pageNo < 1) pageNo = WebConstant.PAGENO_DEFAULT;
+ if (null == pageSize || pageSize < 1) pageSize = WebConstant.PAGESIZE_DEFAULT;
+ OperatorSearchBean searchBean = new OperatorSearchBean();
+ if (!StringUtil.isEmpty(searchValue)) {
+ if ("opercode".equals(searchKey)) {
+ searchBean.setOpercode(searchValue.trim());
+ } else if ("opername".equals(searchKey)) {
+ searchBean.setOpername(searchValue.trim());
+ } else if ("mobile".equals(searchValue.trim())) {
+ searchBean.setMobile(searchValue.trim());
+ }
+ }
+ return operatorService.getOperatorsByPage(pageNo, pageSize, searchBean);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return new PageResult<>(99, "系统查询错误");
}
- }
- return operatorService.getOperatorsByPage(pageNo, pageSize, searchBean);
- } catch (Exception e) {
- e.printStackTrace();
- return new PageResult<>(99, "系统查询错误");
}
- }
- @GetMapping("/load4add")
- @PreAuthorize("hasPermission('/operator/load4add','')")
- public String load4addOperator(Model model) {
- model.addAttribute("roles", roleService.findAllRoles());
- return "system/operator/operator";
- }
-
- @GetMapping("/checkopercode")
- @ResponseBody
- public JsonResult checkOpercode(@RequestParam("opercode") String opercode,
- @RequestParam(value = "operid", required = false) String operid) {
- if (operatorService.checkOpercodeExists(opercode, operid)) {
- return JsonResult.error("账号重复");
+ @GetMapping("/load4add")
+ @PreAuthorize("hasPermission('/operator/load4add','')")
+ public String load4addOperator(Model model) {
+ model.addAttribute("roles", roleService.findAllRoles());
+ return "system/operator/operator";
}
- return JsonResult.ok("success");
- }
- @PostMapping("/add")
- @ResponseBody
- public JsonResult add(@RequestParam("operid") String operid, @RequestParam("opercode") String opercode,
- @RequestParam("opername") String opername, @RequestParam("sex") String sex,
- @RequestParam("mobile") String mobile, @RequestParam("email") String email,
- @RequestParam("roleId") String roleId, Model map) {
- if (operatorService.checkOpercodeExists(opercode, operid)) {
- return JsonResult.error("账号重复");
+ @GetMapping("/checkopercode")
+ @ResponseBody
+ public JsonResult checkOpercode(@RequestParam("opercode") String opercode,
+ @RequestParam(value = "operid", required = false) String operid) {
+ if (operatorService.checkOpercodeExists(opercode, operid)) {
+ return JsonResult.error("账号重复");
+ }
+ return JsonResult.ok("success");
}
- TOperator operator = new TOperator();
- operator.setOpername(opername);
- operator.setOpercode(opercode);
- operator.setOperid(operid);
- operator.setMobile(mobile);
- operator.setEmail(email);
- operator.setSex(sex);
- BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
- operator.setOperpwd(encoder.encode("123456"));
- operatorService.saveOperator(operator,roleId);
- return JsonResult.ok("添加成功");
- }
-
- @PostMapping("/update")
- @ResponseBody
- public JsonResult update(TOperator oper, String roleId) {
- oper.setOperpwd(WebConstant.OPERPWD_DEFAULT);
- if (true) {
- return JsonResult.ok("添加成功");
- } else {
- return JsonResult.error("添加失败");
+ @PostMapping("/getoperatorrole")
+ @ResponseBody
+ public JsonResult getoperatorrole( @RequestParam(value = "operid") String operid) {
+ List<TOperRole> roles = operatorService.getOperRoleByOperId(operid);
+ JsonResult ret = JsonResult.ok("success");
+ ret.put("roles",roles);
+ return ret;
}
- }
+ @PostMapping("/add")
+ @PreAuthorize("hasPermission('/operator/add','')")
+ @ResponseBody
+ public JsonResult add(@RequestParam("operid") String operid, @RequestParam("opercode") String opercode,
+ @RequestParam("opername") String opername, @RequestParam("sex") String sex,
+ @RequestParam("mobile") String mobile, @RequestParam("email") String email,
+ @RequestParam("roleId") String roleId, Model map) {
+ if (operatorService.checkOpercodeExists(opercode, operid)) {
+ return JsonResult.error("账号重复");
+ }
+ TOperator operator = new TOperator();
+ operator.setOpername(opername);
+ operator.setOpercode(opercode);
+ operator.setOperid(operid);
+ operator.setMobile(mobile);
+ operator.setEmail(email);
+ operator.setSex(sex);
+ boolean ret = operatorService.saveOperator(operator, roleId);
+ if (ret) {
+ return JsonResult.ok("操作成功");
+ } else {
+ return JsonResult.error("操作失败");
+ }
+ }
+ @PostMapping("/resetpwd")
+ @PreAuthorize("hasPermission('/operator/resetpwd','')")
+ @ResponseBody
+ public JsonResult resetpwd(@RequestParam("operid") String operid) {
+ if (operatorService.resetPwd(operid)) {
+ return JsonResult.ok("操作成功,密码重置为123456");
+ } else {
+ return JsonResult.error("操作失败");
+ }
+ }
+ @PostMapping("/updatestate")
+ @PreAuthorize("hasPermission('/operator/updatestate','')")
+ @ResponseBody
+ public JsonResult updatestate(@RequestParam("operid") String operid,@RequestParam("state") String state) {
+ if (operatorService.updateState(operid,state)) {
+ return JsonResult.ok("操作成功");
+ } else {
+ return JsonResult.error("操作失败");
+ }
+ }
+ @GetMapping("/logs")
+ public String logs() {
+ return "system/operator/logs";
+ }
+
+ @GetMapping("/logslist")
+ @PreAuthorize("hasPermission('/operator/logslist','')")
+ @ResponseBody
+ public PageResult<TOperLog> logslist(@RequestParam("page") Integer pageNo,
+ @RequestParam("limit") Integer pageSize,
+ @RequestParam(value = "searchkey", required = false) String searchKey) {
+ try {
+ if (null == pageNo || pageNo < 1) pageNo = WebConstant.PAGENO_DEFAULT;
+ if (null == pageSize || pageSize < 1) pageSize = WebConstant.PAGESIZE_DEFAULT;
+ LogBean searchBean = new LogBean();
+ searchBean.setPageNo(pageNo);
+ searchBean.setOpername(searchKey);
+ searchBean.setPageSize(pageSize);
+ return operatorService.getOperLogs(searchBean);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return new PageResult<>(99, "系统查询错误");
+ }
+ }
}
diff --git a/src/main/java/com/supwisdom/dlpay/system/controller/RoleController.java b/src/main/java/com/supwisdom/dlpay/system/controller/RoleController.java
index bfe0127..e8e4eb7 100644
--- a/src/main/java/com/supwisdom/dlpay/system/controller/RoleController.java
+++ b/src/main/java/com/supwisdom/dlpay/system/controller/RoleController.java
@@ -1,35 +1,30 @@
package com.supwisdom.dlpay.system.controller;
import com.supwisdom.dlpay.api.bean.JsonResult;
-import com.supwisdom.dlpay.framework.domain.TFunction;
import com.supwisdom.dlpay.framework.domain.TRole;
-import com.supwisdom.dlpay.framework.domain.TRoleFunction;
import com.supwisdom.dlpay.framework.util.PageResult;
import com.supwisdom.dlpay.framework.util.WebConstant;
import com.supwisdom.dlpay.system.bean.FunctionSearchBean;
import com.supwisdom.dlpay.system.bean.ZTreeNode;
-import com.supwisdom.dlpay.system.service.FunctionService;
import com.supwisdom.dlpay.system.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
-import java.util.Arrays;
import java.util.List;
@Controller
public class RoleController {
@Autowired
private RoleService roleService;
- @Autowired
- private FunctionService functionService;
-
@GetMapping("/role/index")
public String indexView() {
return "system/role/index";
}
@GetMapping("/role/list")
+ @PreAuthorize("hasPermission('/role/index','')")
@ResponseBody
public PageResult<TRole> getDataList(@RequestParam("page") Integer pageNo,
@RequestParam("limit") Integer pageSize,
@@ -49,11 +44,13 @@
}
@GetMapping("/role/loadadd")
+ @PreAuthorize("hasPermission('/role/loadadd','')")
public String loadadd() {
return "system/role/form";
}
@PostMapping("/role/add")
+ @PreAuthorize("hasPermission('/role/add','')")
@ResponseBody
public JsonResult add(@RequestBody TRole role) {
if (role != null) {
@@ -64,11 +61,13 @@
}
@GetMapping("/role/loadfunc")
+ @PreAuthorize("hasPermission('/role/loadfunc','')")
public String loadfunc() {
return "system/role/func";
}
@PostMapping("/role/addfunc")
+ @PreAuthorize("hasPermission('/role/addfunc','')")
@ResponseBody
public JsonResult addfunc(@RequestParam String roleId,
@RequestParam String funcs) {
@@ -84,6 +83,7 @@
return result;
}
@PostMapping("/role/del")
+ @PreAuthorize("hasPermission('/role/del','')")
@ResponseBody
public JsonResult del(@RequestParam String roleid) {
return roleService.deleteRole(roleid);
diff --git a/src/main/java/com/supwisdom/dlpay/system/service/OperatorService.java b/src/main/java/com/supwisdom/dlpay/system/service/OperatorService.java
index bbaff0a..a975eb2 100644
--- a/src/main/java/com/supwisdom/dlpay/system/service/OperatorService.java
+++ b/src/main/java/com/supwisdom/dlpay/system/service/OperatorService.java
@@ -1,11 +1,16 @@
package com.supwisdom.dlpay.system.service;
+import com.supwisdom.dlpay.framework.domain.TOperLog;
+import com.supwisdom.dlpay.framework.domain.TOperRole;
import com.supwisdom.dlpay.framework.domain.TOperator;
import com.supwisdom.dlpay.framework.util.PageResult;
+import com.supwisdom.dlpay.system.bean.LogBean;
import com.supwisdom.dlpay.system.bean.OperatorSearchBean;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
+import java.util.List;
+
public interface OperatorService {
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, readOnly = true)
PageResult<TOperator> getOperatorsByPage(int pageNo, int pageSize, OperatorSearchBean searchBean);
@@ -15,4 +20,22 @@
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
boolean saveOperator(TOperator operator,String roles);
+
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, readOnly = true)
+ TOperator getOperatorByCode(String opercode);
+
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, readOnly = true)
+ List<TOperRole> getOperRoleByOperId(String operid);
+
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
+ boolean resetPwd(String operid);
+
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
+ boolean updateState(String operid,String state);
+
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
+ boolean saveOperLog(TOperLog log);
+
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class, readOnly = true)
+ PageResult<TOperLog> getOperLogs(LogBean param);
}
diff --git a/src/main/java/com/supwisdom/dlpay/system/service/RoleService.java b/src/main/java/com/supwisdom/dlpay/system/service/RoleService.java
index 222dd8d..6acfe7d 100644
--- a/src/main/java/com/supwisdom/dlpay/system/service/RoleService.java
+++ b/src/main/java/com/supwisdom/dlpay/system/service/RoleService.java
@@ -18,7 +18,7 @@
List<TRole> findAllRoles();
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class,readOnly = true)
- TRole findRoleByRolecode(String rolecode);
+ TRole findRoleByRoleid(String roleid);
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class,readOnly = true)
TResource findResourceByURI(String uri);
diff --git a/src/main/java/com/supwisdom/dlpay/system/service/impl/OperatorServiceImpl.java b/src/main/java/com/supwisdom/dlpay/system/service/impl/OperatorServiceImpl.java
index 167e955..5990930 100644
--- a/src/main/java/com/supwisdom/dlpay/system/service/impl/OperatorServiceImpl.java
+++ b/src/main/java/com/supwisdom/dlpay/system/service/impl/OperatorServiceImpl.java
@@ -1,13 +1,13 @@
package com.supwisdom.dlpay.system.service.impl;
+import com.supwisdom.dlpay.framework.dao.OperLogDao;
import com.supwisdom.dlpay.framework.dao.OperRoleDao;
import com.supwisdom.dlpay.framework.dao.OperatorDao;
+import com.supwisdom.dlpay.framework.domain.TOperLog;
import com.supwisdom.dlpay.framework.domain.TOperRole;
import com.supwisdom.dlpay.framework.domain.TOperator;
-import com.supwisdom.dlpay.framework.util.DateUtil;
-import com.supwisdom.dlpay.framework.util.PageResult;
-import com.supwisdom.dlpay.framework.util.StringUtil;
-import com.supwisdom.dlpay.framework.util.TradeDict;
+import com.supwisdom.dlpay.framework.util.*;
+import com.supwisdom.dlpay.system.bean.LogBean;
import com.supwisdom.dlpay.system.bean.OperatorSearchBean;
import com.supwisdom.dlpay.system.service.OperatorService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -16,6 +16,7 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import javax.persistence.criteria.CriteriaBuilder;
@@ -24,6 +25,7 @@
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
@Service
public class OperatorServiceImpl implements OperatorService {
@@ -31,6 +33,8 @@
private OperatorDao operatorDao;
@Autowired
private OperRoleDao operRoleDao;
+ @Autowired
+ private OperLogDao operLogDao;
@Override
public PageResult<TOperator> getOperatorsByPage(int pageNo, int pageSize, OperatorSearchBean searchBean) {
@@ -67,17 +71,93 @@
}
@Override
- public boolean saveOperator(TOperator operator,String roles) {
- String[] roleids= roles.split(",");
- operator.setOpendate(DateUtil.getNow());
- operator.setStatus(TradeDict.STATUS_NORMAL);
- operatorDao.save(operator);
- for(String role:roleids){
- TOperRole operRole = new TOperRole();
- operRole.setOperid(operator.getOperid());
- operRole.setRoleId(role);
- operRoleDao.save(operRole);
+ public boolean saveOperator(TOperator operator, String roles) {
+ if (StringUtil.isEmpty(operator.getOperid())) {
+ String[] roleids = roles.split(",");
+ operator.setOpendate(DateUtil.getNow("yyyyMMdd"));
+ operator.setStatus(TradeDict.STATUS_NORMAL);
+ operator.setOpertype(WebConstant.OPERTYPE_DEFAULT);
+ BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
+ operator.setOperpwd(encoder.encode(WebConstant.OPERPWD_DEFAULT));
+ operator = operatorDao.save(operator);
+ for (String role : roleids) {
+ TOperRole operRole = new TOperRole();
+ operRole.setOperid(operator.getOperid());
+ operRole.setRoleId(role);
+ operRoleDao.save(operRole);
+ }
+ } else {
+ Optional<TOperator> temp = operatorDao.findById(operator.getOperid());
+ if (!temp.isPresent()) {
+ return false;
+ }
+ TOperator op = temp.get();
+ op.setSex(operator.getSex());
+ op.setEmail(operator.getEmail());
+ op.setMobile(operator.getMobile());
+ op.setOpername(operator.getOpername());
+ op.setOpercode(operator.getOpercode());
+ operatorDao.save(op);
+ operRoleDao.deleteByOperid(op.getOperid());
+ String[] roleids = roles.split(",");
+ for (String role : roleids) {
+ TOperRole operRole = new TOperRole();
+ operRole.setOperid(op.getOperid());
+ operRole.setRoleId(role);
+ operRoleDao.save(operRole);
+ }
}
return true;
}
+
+ @Override
+ public TOperator getOperatorByCode(String opercode) {
+ return operatorDao.findByOpercode(opercode);
+ }
+
+ @Override
+ public List<TOperRole> getOperRoleByOperId(String operid) {
+ return operRoleDao.findAllByOperid(operid);
+ }
+
+ @Override
+ public boolean resetPwd(String operid) {
+ Optional<TOperator> temp = operatorDao.findById(operid);
+ if (!temp.isPresent()) {
+ return false;
+ }
+ TOperator op = temp.get();
+ BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
+ op.setOperpwd(encoder.encode(WebConstant.OPERPWD_DEFAULT));
+ operatorDao.save(op);
+ return true;
+ }
+
+ @Override
+ public boolean updateState(String operid, String state) {
+ Optional<TOperator> temp = operatorDao.findById(operid);
+ if (!temp.isPresent()) {
+ return false;
+ }
+ TOperator op = temp.get();
+ op.setStatus(state);
+ operatorDao.save(op);
+ return true;
+ }
+
+ @Override
+ public boolean saveOperLog(TOperLog log) {
+ operLogDao.save(log);
+ return true;
+ }
+
+ @Override
+ public PageResult<TOperLog> getOperLogs(LogBean param) {
+ Pageable pageable = PageRequest.of(param.getPageNo() - 1, param.getPageSize()
+ , Sort.by(Sort.Direction.DESC,"logdate"));
+ if (!StringUtil.isEmpty(param.getOpername())) {
+ return new PageResult<>(operLogDao.findAllByOpernameContaining(param.getOpername(), pageable));
+ }
+ return new PageResult<>(operLogDao.findAll(pageable));
+ }
}
diff --git a/src/main/java/com/supwisdom/dlpay/system/service/impl/RoleServiceImpl.java b/src/main/java/com/supwisdom/dlpay/system/service/impl/RoleServiceImpl.java
index 0e30b2a..ea049e3 100644
--- a/src/main/java/com/supwisdom/dlpay/system/service/impl/RoleServiceImpl.java
+++ b/src/main/java/com/supwisdom/dlpay/system/service/impl/RoleServiceImpl.java
@@ -48,8 +48,12 @@
}
@Override
- public TRole findRoleByRolecode(String rolecode) {
- return roleDao.findByRoleCode(rolecode);
+ public TRole findRoleByRoleid(String roleid) {
+ Optional<TRole> role = roleDao.findById(roleid);
+ if(role.isPresent()){
+ return role.get();
+ }
+ return null;
}
@Override
@@ -79,10 +83,6 @@
if (temp != null) {
return JsonResult.error("角色名称已存在");
}
- temp = roleDao.findByRoleCodeAndRoleIdNot(role.getRoleCode(), role.getRoleId());
- if (temp != null) {
- return JsonResult.error("角色代码已存在");
- }
Optional<TRole> opt = roleDao.findById(role.getRoleId());
if (opt == null || !opt.isPresent()) {
return JsonResult.error("角色已被删除");
@@ -98,13 +98,10 @@
if (temp != null) {
return JsonResult.error("角色名称已存在");
}
- temp = roleDao.findByRoleCode(role.getRoleCode());
- if (temp != null) {
- return JsonResult.error("角色代码已存在");
- }
+
role.setCreatetime(DateUtil.getNow());
role.setEditflag(1);
- role.setRoleCode(role.getRoleCode());
+ role.setRoleCode("ROLE_ADMIN");
roleDao.save(role);
}
return JsonResult.ok("成功");
diff --git a/src/main/resources/static/custom/module/admin.js b/src/main/resources/static/custom/module/admin.js
index 334e29e..e9b34ef 100755
--- a/src/main/resources/static/custom/module/admin.js
+++ b/src/main/resources/static/custom/module/admin.js
@@ -208,6 +208,26 @@
} catch (e) {
}
}
+ },
+ formatDate:function (str) {
+ if (str == null || str == "") {
+ return;
+ }
+ switch (str.length) {
+ case 8:
+ str = str.substring(0, 4) + "-" + str.substring(4, 6) + "-" + str.substring(6, 8);
+ return str;
+ case 12:
+ str = str.substring(0, 4) + "-" + str.substring(4, 6) + "-" + str.substring(6, 8) + " " + str.substring(8, 10)
+ + ":" + str.substring(10, 12);
+ return str;
+ case 14:
+ str = str.substring(0, 4) + "-" + str.substring(4, 6) + "-" + str.substring(6, 8) + " " + str.substring(8, 10)
+ + ":" + str.substring(10, 12) + ":" + str.substring(12, 14);
+ return str;
+ default:
+ return str;
+ }
}
};
diff --git a/src/main/resources/templates/system/operator/index.html b/src/main/resources/templates/system/operator/index.html
index 14861c7..09b5f2e 100644
--- a/src/main/resources/templates/system/operator/index.html
+++ b/src/main/resources/templates/system/operator/index.html
@@ -18,30 +18,30 @@
<input id="oper-search-value" class="layui-input search-input" type="text" placeholder="输入关键字"/> 
<button id="oper-btn-search" class="layui-btn icon-btn"><i class="layui-icon"></i>搜索</button>
<button id="oper-btn-add" class="layui-btn icon-btn" lay-tips="新用户密码为123456"
- sec:authorize="hasPermission('/operator/load4add','query')" ><i
+ sec:authorize="hasPermission('/operator/load4add','')" ><i
class="layui-icon"></i>添加
</button>
</div>
- <table class="layui-table" id="oper-table"></table>
+ <table class="layui-table" id="oper-table" lay-filter="oper-table"></table>
</div>
</div>
<!-- 表格状态列 -->
<script type="text/html" id="oper-tpl-state">
{{# if(d.opercode == 'system') { }}
- <input type="checkbox" lay-filter="oper-tpl-state" value="{{d.operid}}" lay-skin="switch" lay-text="正常|锁定"
+ <input type="checkbox" lay-filter="oper-tpl-state" value="{{d.operid}}" lay-skin="switch" lay-text="正常|注销"
{{d.status=='normal'?'checked':''}} disabled/>
{{# }else{ }}
- <input type="checkbox" lay-filter="oper-tpl-state" value="{{d.operid}}" lay-skin="switch" lay-text="正常|锁定"
+ <input type="checkbox" lay-filter="oper-tpl-state" value="{{d.operid}}" lay-skin="switch" lay-text="正常|注销"
{{d.status=='normal'?'checked':''}} />
{{# } }}
</script>
<!-- 表格操作列 -->
<script type="text/html" id="oper-table-bar">
- <a class="layui-btn layui-btn-primary layui-btn-xs">修改</a>
- <a class="layui-btn layui-btn-xs">重置密码</a>
+ <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
+ <a class="layui-btn layui-btn-xs" lay-event="resetpwd">重置密码</a>
</script>
<script>
@@ -111,45 +111,74 @@
};
// 工具条点击事件
- table.on('tool(user-table)', function (obj) {
+ table.on('tool(oper-table)', function (obj) {
console.log(obj);
var data = obj.data;
var layEvent = obj.event;
if (layEvent === 'edit') { // 修改
- showEditModel(data);
- } else if (layEvent === 'reset') { // 重置密码
+ layer.load(2);
+ let token = $("meta[name='_csrf_token']").attr("value");
+ admin.go('/operator/getoperatorrole', {
+ operid: data.operid,
+ _csrf: token
+ }, function (ret) {
+ console.log(ret.code);
+ layer.closeAll('loading');
+ if (ret.code == 200) {
+ data['roles'] = ret.roles;
+ showEditModel(data);
+ } else if (ret.code == 401) {
+ layer.msg(ret.msg, {icon: 2, time: 1500}, function () {
+ location.replace('/login');
+ }, 1000);
+ return;
+ }
+ else {
+ layer.msg(ret.msg, {icon: 2});
+ }
+ },function(){
+ layer.closeAll('loading');
+ layer.msg('请求失败了,请稍后再试', {icon: 2});
+ });
+ } else if (layEvent === 'resetpwd') { // 重置密码
layer.confirm('确定重置此用户的密码吗?', function (i) {
layer.close(i);
layer.load(2);
- admin.go('/system/user/restPsw', {
- userId: obj.data.userId
- }, function (data) {
- console.log(data.code);
+ let token = $("meta[name='_csrf_token']").attr("value");
+ admin.go('/operator/resetpwd', {
+ operid: data.operid,
+ _csrf: token
+ }, function (ret) {
+ console.log(ret.code);
layer.closeAll('loading');
- if (data.code == 200) {
- layer.msg(data.msg, {icon: 1});
- } else if (data.code == 401) {
- layer.msg(data.msg, {icon: 2, time: 1500}, function () {
+ if (ret.code == 200) {
+ layer.msg(ret.msg, {icon: 1});
+ } else if (ret.code == 401) {
+ layer.msg(ret.msg, {icon: 2, time: 1500}, function () {
location.replace('/login');
}, 1000);
return;
}
else {
- layer.msg(data.msg, {icon: 2});
+ layer.msg(ret.msg, {icon: 2});
}
+ },function(){
+ layer.closeAll('loading');
+ layer.msg('请求失败了,请稍后再试', {icon: 2});
});
});
}
});
-
// 修改user状态
- form.on('switch(user-tpl-state)', function (obj) {
+ form.on('switch(oper-tpl-state)', function (obj) {
layer.load(2);
- admin.go('/system/user/updateState', {
- userId: obj.elem.value,
- state: obj.elem.checked ? 0 : 1
+ let token = $("meta[name='_csrf_token']").attr("value");
+ admin.go('/operator/updatestate', {
+ operid: obj.elem.value,
+ _csrf: token,
+ state: obj.elem.checked ? 'normal' : 'closed'
}, function (data) {
layer.closeAll('loading');
if (data.code == 200) {
@@ -165,6 +194,9 @@
$(obj.elem).prop('checked', !obj.elem.checked);
form.render('checkbox');
}
+ },function () {
+ layer.closeAll('loading');
+ layer.msg('请求失败了,请稍后再试', {icon: 2});
});
});
diff --git a/src/main/resources/templates/system/operator/logs.html b/src/main/resources/templates/system/operator/logs.html
new file mode 100644
index 0000000..4213ac0
--- /dev/null
+++ b/src/main/resources/templates/system/operator/logs.html
@@ -0,0 +1,50 @@
+<div class="layui-card">
+ <div class="layui-card-header">
+ <h2 class="header-title">操作日志</h2>
+ <span class="layui-breadcrumb pull-right">
+ <a href="#!_operator_index">系统中心</a>
+ <a><cite>操作日志</cite></a>
+ </span>
+ </div>
+ <div class="layui-card-body">
+ <div class="layui-form toolbar">
+ 搜索:
+ <input id="search-value" class="layui-input search-input" type="text" placeholder="输入管理员账号"/> 
+ <button id="btn-search" class="layui-btn icon-btn" data-type="search"><i class="layui-icon"></i>搜索
+ </button>
+ </div>
+ <table class="layui-table" id="logtable" lay-filter="logtable"></table>
+ </div>
+</div>
+<script>
+ layui.use(['form', 'table', 'layer', 'admin', 'element'], function () {
+ let form = layui.form;
+ let table = layui.table;
+ let admin = layui.admin;
+ form.render('select');
+ // 渲染表格
+ table.render({
+ elem: '#logtable',
+ url: '/operator/logslist',
+ page: true,
+ cols: [
+ [
+ {field: 'opername', title: '管理员账号', width: 160,fixed: 'left', sort: true},
+ {field: 'functionname', title: '所属功能', width: 160,fixed: 'left', sort: true},
+ {field: 'resname', title: '操作内容', width: 160,fixed: 'left', sort: true},
+ {field: 'respath', title: '操作路径', width: 200,},
+ {
+ field: 'logdate', align: 'center', title: '操作时间', fixed: 'right', templet: function (item) {
+ return admin.formatDate(item.logdate);
+ }
+ }
+ ]
+ ]
+ });
+ // 搜索按钮点击事件
+ $('#btn-search').click(function () {
+ let key = $('#search-value').val();
+ table.reload('logtable', {where: {searchkey: key}, page: {curr: 1}});
+ });
+ });
+</script>
\ No newline at end of file
diff --git a/src/main/resources/templates/system/operator/operator.html b/src/main/resources/templates/system/operator/operator.html
index 6676bf4..a048c1a 100644
--- a/src/main/resources/templates/system/operator/operator.html
+++ b/src/main/resources/templates/system/operator/operator.html
@@ -25,13 +25,13 @@
<div class="layui-form-item">
<label class="layui-form-label">手机号</label>
<div class="layui-input-block">
- <input name="mobile" placeholder="请输入手机号" type="text" class="layui-input" lay-verify="mobile" required/>
+ <input name="mobile" placeholder="请输入手机号" type="text" class="layui-input" lay-verify="mobile" />
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">邮箱</label>
<div class="layui-input-block">
- <input name="email" placeholder="请输入邮箱" type="text" class="layui-input" lay-verify="swEmail" required/>
+ <input name="email" placeholder="请输入邮箱" type="text" class="layui-input" lay-verify="swEmail" />
</div>
</div>
@@ -104,7 +104,6 @@
var user = admin.getTempData('t_user');
if (user) {
$('input[name="opercode"]').attr('readonly', 'readonly');
- url = '/operator/update';
form.val('oper-form', user);
var rds = new Array();
for (var i = 0; i < user.roles.length; i++) {
@@ -125,17 +124,17 @@
data : data.field,
success : function(result) {
layer.closeAll('loading');
- if (data.code == 200) {
- layer.msg(data.msg, {icon: 1});
+ if (result.code == 200) {
+ layer.msg(result.msg, {icon: 1});
admin.finishPopupCenter();
} else if (data.code == 401) {
- layer.msg(data.msg, {icon: 2, time: 1500}, function () {
+ layer.msg(result.msg, {icon: 2, time: 1500}, function () {
location.replace('/login');
}, 1000);
return;
} else {
- console.log('err:' + data.code);
- layer.msg(data.msg, {icon: 2});
+ console.log('err:' + result.code);
+ layer.msg(result.msg, {icon: 2});
}
},
error : function(data) {
diff --git a/src/main/resources/templates/system/role/form.html b/src/main/resources/templates/system/role/form.html
index f8714f3..fcfcbf3 100755
--- a/src/main/resources/templates/system/role/form.html
+++ b/src/main/resources/templates/system/role/form.html
@@ -9,13 +9,6 @@
</div>
</div>
<div class="layui-form-item">
- <label class="layui-form-label">角色代码</label>
- <div class="layui-input-block">
- <input name="roleCode" placeholder="请输入角色代码" type="text" class="layui-input" maxlength="20"
- lay-verify="required|roleCode" required/>
- </div>
- </div>
- <div class="layui-form-item">
<label class="layui-form-label">角色描述</label>
<div class="layui-input-block">
<textarea name="roleDesc" placeholder="请输入描述" class="layui-textarea"></textarea>