|
@@ -3,15 +3,18 @@ package com.jeesite.modules.mes.web;
|
|
|
import com.jeesite.common.config.Global;
|
|
import com.jeesite.common.config.Global;
|
|
|
import com.jeesite.common.lang.StringUtils;
|
|
import com.jeesite.common.lang.StringUtils;
|
|
|
import com.jeesite.common.web.BaseController;
|
|
import com.jeesite.common.web.BaseController;
|
|
|
|
|
+import com.jeesite.modules.mes.entity.MesEmployee;
|
|
|
|
|
+import com.jeesite.modules.mes.service.MesEmployeeService;
|
|
|
import com.jeesite.modules.sys.entity.EmpUser;
|
|
import com.jeesite.modules.sys.entity.EmpUser;
|
|
|
import com.jeesite.modules.sys.entity.EmployeeOffice;
|
|
import com.jeesite.modules.sys.entity.EmployeeOffice;
|
|
|
import com.jeesite.modules.sys.entity.Role;
|
|
import com.jeesite.modules.sys.entity.Role;
|
|
|
|
|
+import com.jeesite.modules.sys.entity.User;
|
|
|
import com.jeesite.modules.sys.service.EmpUserService;
|
|
import com.jeesite.modules.sys.service.EmpUserService;
|
|
|
|
|
+import com.jeesite.modules.sys.service.UserService;
|
|
|
import com.jeesite.modules.sys.web.user.EmpUserController;
|
|
import com.jeesite.modules.sys.web.user.EmpUserController;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.ui.Model;
|
|
|
-import org.springframework.validation.annotation.Validated;
|
|
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
@@ -30,6 +33,12 @@ public class EmpUserCustomController extends BaseController {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private EmpUserService empUserService;
|
|
private EmpUserService empUserService;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private UserService userService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private MesEmployeeService mesEmployeeService;
|
|
|
|
|
+
|
|
|
@ModelAttribute
|
|
@ModelAttribute
|
|
|
public EmpUser get(String userCode, boolean isNewRecord) {
|
|
public EmpUser get(String userCode, boolean isNewRecord) {
|
|
|
return empUserService.get(userCode, isNewRecord);
|
|
return empUserService.get(userCode, isNewRecord);
|
|
@@ -103,11 +112,16 @@ public class EmpUserCustomController extends BaseController {
|
|
|
|
|
|
|
|
@RequestMapping(value = "save")
|
|
@RequestMapping(value = "save")
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
- public String save(@Validated EmpUser empUser, String oldLoginCode, HttpServletRequest request) {
|
|
|
|
|
|
|
+ public String save(EmpUser empUser, String oldLoginCode, HttpServletRequest request) {
|
|
|
|
|
+ String loginCode = StringUtils.trim(empUser.getLoginCode());
|
|
|
|
|
+ empUser.setLoginCode(loginCode);
|
|
|
|
|
+ if (StringUtils.isBlank(loginCode)) {
|
|
|
|
|
+ return renderResult(Global.FALSE, "保存用户失败,登录账号不能为空。");
|
|
|
|
|
+ }
|
|
|
EmpUser existUser = new EmpUser();
|
|
EmpUser existUser = new EmpUser();
|
|
|
- existUser.setLoginCode(empUser.getLoginCode());
|
|
|
|
|
|
|
+ existUser.setLoginCode(loginCode);
|
|
|
List<EmpUser> uList = empUserService.findList(existUser);
|
|
List<EmpUser> uList = empUserService.findList(existUser);
|
|
|
- if (uList != null && !uList.isEmpty()) {
|
|
|
|
|
|
|
+ if (hasOtherUser(uList, empUser.getUserCode())) {
|
|
|
return renderResult(Global.FALSE, "保存用户失败,登录账号已存在(不能与原账号相同),请修改登录账号!");
|
|
return renderResult(Global.FALSE, "保存用户失败,登录账号已存在(不能与原账号相同),请修改登录账号!");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -115,11 +129,90 @@ public class EmpUserCustomController extends BaseController {
|
|
|
EmpUser where = new EmpUser();
|
|
EmpUser where = new EmpUser();
|
|
|
where.setUserName(empUser.getUserName());
|
|
where.setUserName(empUser.getUserName());
|
|
|
List<EmpUser> list = empUserService.findList(where);
|
|
List<EmpUser> list = empUserService.findList(where);
|
|
|
- if (list != null && !list.isEmpty()) {
|
|
|
|
|
|
|
+ if (hasOtherUser(list, empUser.getUserCode())) {
|
|
|
return renderResult(Global.FALSE, "保存用户失败,用户昵称已存在(不能与原昵称相同),请修改用户昵称!");
|
|
return renderResult(Global.FALSE, "保存用户失败,用户昵称已存在(不能与原昵称相同),请修改用户昵称!");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (StringUtils.isBlank(empUser.getUserType())) {
|
|
|
|
|
+ empUser.setUserType("employee");
|
|
|
|
|
+ }
|
|
|
|
|
+ MesEmployee selectedEmployee = findSelectedEmployee(empUser);
|
|
|
|
|
+ String selectedEmployeeError = checkSelectedEmployee(empUser, selectedEmployee);
|
|
|
|
|
+ if (StringUtils.isNotBlank(selectedEmployeeError)) {
|
|
|
|
|
+ return renderResult(Global.FALSE, selectedEmployeeError);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (selectedEmployee != null) {
|
|
|
|
|
+ User boundUser = findBoundUser(selectedEmployee);
|
|
|
|
|
+ if (boundUser != null && (StringUtils.isBlank(empUser.getUserCode())
|
|
|
|
|
+ || !StringUtils.equals(boundUser.getUserCode(), empUser.getUserCode()))) {
|
|
|
|
|
+ return renderResult(Global.FALSE, "保存用户失败,该员工已创建账号:" + boundUser.getLoginCode());
|
|
|
|
|
+ }
|
|
|
|
|
+ bindSelectedEmployeeUser(empUser, selectedEmployee);
|
|
|
|
|
+ userService.save(empUser);
|
|
|
|
|
+ return renderResult(Global.TRUE, "保存用户 '" + empUser.getLoginCode() + "' 成功");
|
|
|
|
|
+ }
|
|
|
return empUserController.save(empUser, oldLoginCode, request);
|
|
return empUserController.save(empUser, oldLoginCode, request);
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+
|
|
|
|
|
+ private MesEmployee findSelectedEmployee(EmpUser empUser) {
|
|
|
|
|
+ if (empUser.getEmployee() == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isNotBlank(empUser.getEmployee().getEmpCode())) {
|
|
|
|
|
+ MesEmployee employee = mesEmployeeService.get(new MesEmployee(empUser.getEmployee().getEmpCode()));
|
|
|
|
|
+ if (employee != null) {
|
|
|
|
|
+ return employee;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isNotBlank(empUser.getEmployee().getEmpNo())) {
|
|
|
|
|
+ MesEmployee where = new MesEmployee();
|
|
|
|
|
+ where.setEmpNo(StringUtils.trim(empUser.getEmployee().getEmpNo()));
|
|
|
|
|
+ List<MesEmployee> employees = mesEmployeeService.findList(where);
|
|
|
|
|
+ if (employees != null && !employees.isEmpty()) {
|
|
|
|
|
+ return employees.get(0);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String checkSelectedEmployee(EmpUser empUser, MesEmployee employee) {
|
|
|
|
|
+ if (employee != null && StringUtils.isNotBlank(employee.getUserCode())
|
|
|
|
|
+ && (StringUtils.isBlank(empUser.getUserCode()) || !StringUtils.equals(employee.getUserCode(), empUser.getUserCode()))) {
|
|
|
|
|
+ return "保存用户失败,该员工已创建账号:" + employee.getLoginCode();
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private User findBoundUser(MesEmployee employee) {
|
|
|
|
|
+ if (employee == null || StringUtils.isBlank(employee.getEmpCode())) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ User query = new User();
|
|
|
|
|
+ query.setUserType("employee");
|
|
|
|
|
+ query.setRefCode(employee.getEmpCode());
|
|
|
|
|
+ return userService.getByUserTypeAndRefCode(query);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void bindSelectedEmployeeUser(EmpUser empUser, MesEmployee employee) {
|
|
|
|
|
+ empUser.setUserType("employee");
|
|
|
|
|
+ if (StringUtils.isBlank(empUser.getMgrType())) {
|
|
|
|
|
+ empUser.setMgrType("0");
|
|
|
|
|
+ }
|
|
|
|
|
+ empUser.setRefCode(employee.getEmpCode());
|
|
|
|
|
+ empUser.setRefName(employee.getEmpName());
|
|
|
|
|
+ empUser.setEmployee(null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean hasOtherUser(List<EmpUser> userList, String userCode) {
|
|
|
|
|
+ if (userList == null || userList.isEmpty()) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (EmpUser user : userList) {
|
|
|
|
|
+ if (StringUtils.isBlank(userCode) || !StringUtils.equals(userCode, user.getUserCode())) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|