添加机构,重写机构和用户关系
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
package com.jsh.erp.service.orgaUserRel;
|
||||
|
||||
import com.jsh.erp.service.ICommonQuery;
|
||||
import com.jsh.erp.service.organization.OrganizationResource;
|
||||
import com.jsh.erp.service.organization.OrganizationService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @Author: cjl
|
||||
* @Date: 2019/3/11 18:10
|
||||
*/
|
||||
@Service(value = "orgaUserRel_component")
|
||||
@OrgaUserRelResource
|
||||
public class OrgaUserRelComponent implements ICommonQuery {
|
||||
@Resource
|
||||
private OrgaUserRelService orgaUserRelService;
|
||||
@Override
|
||||
public Object selectOne(String condition) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<?> select(Map<String, String> parameterMap) {
|
||||
return getOrgaUserRelList(parameterMap);
|
||||
}
|
||||
private List<?> getOrgaUserRelList(Map<String, String> map) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Long counts(Map<String, String> parameterMap) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insert(String beanJson, HttpServletRequest request) {
|
||||
return orgaUserRelService.insertOrgaUserRel(beanJson,request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(String beanJson, Long id) {
|
||||
return orgaUserRelService.updateOrgaUserRel(beanJson,id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Long id) {
|
||||
return orgaUserRelService.deleteOrgaUserRel(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int batchDelete(String ids) {
|
||||
return orgaUserRelService.batchDeleteOrgaUserRel(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int checkIsNameExist(Long id, String name) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.jsh.erp.service.orgaUserRel;
|
||||
|
||||
import com.jsh.erp.service.ResourceInfo;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Description
|
||||
* 机构用户关系
|
||||
* @Author: cjl
|
||||
* @Date: 2019/3/11 18:11
|
||||
*/
|
||||
@ResourceInfo(value = "orgaUserRel", type = 115)
|
||||
@Inherited
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface OrgaUserRelResource {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package com.jsh.erp.service.orgaUserRel;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jsh.erp.constants.BusinessConstants;
|
||||
import com.jsh.erp.datasource.entities.*;
|
||||
import com.jsh.erp.datasource.mappers.OrgaUserRelMapper;
|
||||
import com.jsh.erp.datasource.mappers.OrgaUserRelMapperEx;
|
||||
import com.jsh.erp.service.organization.OrganizationService;
|
||||
import com.jsh.erp.service.user.UserService;
|
||||
import com.jsh.erp.utils.StringUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @Author: cjl
|
||||
* @Date: 2019/3/11 18:11
|
||||
*/
|
||||
@Service
|
||||
public class OrgaUserRelService {
|
||||
private Logger logger = LoggerFactory.getLogger(OrganizationService.class);
|
||||
|
||||
@Resource
|
||||
private OrgaUserRelMapper orgaUserRelMapper;
|
||||
@Resource
|
||||
private OrgaUserRelMapperEx orgaUserRelMapperEx;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public int insertOrgaUserRel(String beanJson, HttpServletRequest request) {
|
||||
OrgaUserRel orgaUserRel = JSONObject.parseObject(beanJson, OrgaUserRel.class);
|
||||
return orgaUserRelMapper.insertSelective(orgaUserRel);
|
||||
}
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public int updateOrgaUserRel(String beanJson, Long id) {
|
||||
OrgaUserRel orgaUserRel = JSONObject.parseObject(beanJson, OrgaUserRel.class);
|
||||
orgaUserRel.setId(id);
|
||||
return orgaUserRelMapper.updateByPrimaryKeySelective(orgaUserRel);
|
||||
}
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public int deleteOrgaUserRel(Long id) {
|
||||
return orgaUserRelMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public int batchDeleteOrgaUserRel(String ids) {
|
||||
List<Long> idList = StringUtil.strToLongList(ids);
|
||||
OrgaUserRelExample example = new OrgaUserRelExample();
|
||||
example.createCriteria().andIdIn(idList);
|
||||
return orgaUserRelMapper.deleteByExample(example);
|
||||
}
|
||||
/**
|
||||
* create by: cjl
|
||||
* description:
|
||||
* 新增机构用户关联关系,反显id
|
||||
* create time: 2019/3/12 9:40
|
||||
* @Param: orgaUserRel
|
||||
* @return void
|
||||
*/
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public OrgaUserRel addOrgaUserRel(OrgaUserRel orgaUserRel) throws Exception{
|
||||
Date date = new Date();
|
||||
User userInfo=userService.getCurrentUser();
|
||||
//创建时间
|
||||
if(orgaUserRel.getCreateTime()==null){
|
||||
orgaUserRel.setCreateTime(date);
|
||||
}
|
||||
//创建人
|
||||
if(orgaUserRel.getCreator()==null){
|
||||
orgaUserRel.setCreator(userInfo==null?null:userInfo.getId());
|
||||
}
|
||||
//更新时间
|
||||
if(orgaUserRel.getUpdateTime()==null){
|
||||
orgaUserRel.setUpdateTime(date);
|
||||
}
|
||||
//更新人
|
||||
if(orgaUserRel.getUpdater()==null){
|
||||
orgaUserRel.setUpdater(userInfo==null?null:userInfo.getId());
|
||||
}
|
||||
orgaUserRel.setDeleteFlag(BusinessConstants.DELETE_FLAG_EXISTS);
|
||||
int i=orgaUserRelMapperEx.addOrgaUserRel(orgaUserRel);
|
||||
if(i>0){
|
||||
return orgaUserRel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* create by: cjl
|
||||
* description:
|
||||
* 更新机构用户关联关系
|
||||
* create time: 2019/3/12 9:40
|
||||
* @Param: orgaUserRel
|
||||
* @return void
|
||||
*/
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public OrgaUserRel updateOrgaUserRel(OrgaUserRel orgaUserRel) {
|
||||
User userInfo=userService.getCurrentUser();
|
||||
//更新时间
|
||||
if(orgaUserRel.getUpdateTime()==null){
|
||||
orgaUserRel.setUpdateTime(new Date());
|
||||
}
|
||||
//更新人
|
||||
if(orgaUserRel.getUpdater()==null){
|
||||
orgaUserRel.setUpdater(userInfo==null?null:userInfo.getId());
|
||||
}
|
||||
int i= orgaUserRelMapperEx.updateOrgaUserRel(orgaUserRel);
|
||||
if(i>0){
|
||||
return orgaUserRel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,24 @@
|
||||
package com.jsh.erp.service.user;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.druid.util.StringUtils;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jsh.erp.constants.BusinessConstants;
|
||||
import com.jsh.erp.constants.ExceptionConstants;
|
||||
import com.jsh.erp.datasource.entities.OrgaUserRel;
|
||||
import com.jsh.erp.datasource.entities.User;
|
||||
import com.jsh.erp.datasource.entities.UserEx;
|
||||
import com.jsh.erp.datasource.entities.UserExample;
|
||||
import com.jsh.erp.datasource.mappers.UserMapper;
|
||||
import com.jsh.erp.datasource.mappers.UserMapperEx;
|
||||
import com.jsh.erp.utils.*;
|
||||
import com.jsh.erp.exception.BusinessRunTimeException;
|
||||
import com.jsh.erp.service.orgaUserRel.OrgaUserRelService;
|
||||
import com.jsh.erp.utils.ExceptionCodeConstants;
|
||||
import com.jsh.erp.utils.JshException;
|
||||
import com.jsh.erp.utils.StringUtil;
|
||||
import com.jsh.erp.utils.Tools;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
@@ -17,6 +27,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -29,6 +40,8 @@ public class UserService {
|
||||
|
||||
@Resource
|
||||
private UserMapperEx userMapperEx;
|
||||
@Resource
|
||||
private OrgaUserRelService orgaUserRelService;
|
||||
|
||||
public User getUser(long id) {
|
||||
return userMapper.selectByPrimaryKey(id);
|
||||
@@ -187,4 +200,202 @@ public class UserService {
|
||||
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
|
||||
return (User)request.getSession().getAttribute("user");
|
||||
}
|
||||
|
||||
public List<UserEx> getUserList(Map<String, Object> parameterMap) throws Exception{
|
||||
return userMapperEx.getUserList(parameterMap);
|
||||
}
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public void addUserAndOrgUserRel(UserEx ue) throws Exception{
|
||||
//检查用户名和登录名
|
||||
checkUserNameAndLoginName(ue);
|
||||
//新增用户信息
|
||||
ue= this.addUser(ue);
|
||||
if(ue==null){
|
||||
logger.error("异常码[{}],异常提示[{}],参数,[{}]",
|
||||
ExceptionConstants.USER_ADD_FAILED_CODE,ExceptionConstants.USER_ADD_FAILED_MSG);
|
||||
throw new BusinessRunTimeException(ExceptionConstants.USER_ADD_FAILED_CODE,
|
||||
ExceptionConstants.USER_ADD_FAILED_MSG);
|
||||
}
|
||||
if(ue.getOrgaId()==null){
|
||||
//如果没有选择机构,就不建机构和用户的关联关系
|
||||
return;
|
||||
}
|
||||
//新增用户和机构关联关系
|
||||
OrgaUserRel oul=new OrgaUserRel();
|
||||
//机构id
|
||||
oul.setOrgaId(ue.getOrgaId());
|
||||
//用户id
|
||||
oul.setUserId(ue.getId());
|
||||
//用户在机构中的排序
|
||||
oul.setUserBlngOrgaDsplSeq(ue.getUserBlngOrgaDsplSeq());
|
||||
|
||||
oul=orgaUserRelService.addOrgaUserRel(oul);
|
||||
if(oul==null){
|
||||
logger.error("异常码[{}],异常提示[{}],参数,[{}]",
|
||||
ExceptionConstants.ORGA_USER_REL_ADD_FAILED_CODE,ExceptionConstants.ORGA_USER_REL_ADD_FAILED_MSG);
|
||||
throw new BusinessRunTimeException(ExceptionConstants.ORGA_USER_REL_ADD_FAILED_CODE,
|
||||
ExceptionConstants.ORGA_USER_REL_ADD_FAILED_MSG);
|
||||
}
|
||||
}
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public UserEx addUser(UserEx ue) throws Exception{
|
||||
/**
|
||||
* 新增用户默认设置
|
||||
* 1、密码默认123456
|
||||
* 2是否系统自带默认为非系统自带
|
||||
* 3是否管理者默认为员工
|
||||
* 4默认用户状态为正常
|
||||
* */
|
||||
ue.setPassword(Tools.md5Encryp(BusinessConstants.USER_DEFAULT_PASSWORD));
|
||||
ue.setIsystem(BusinessConstants.USER_NOT_SYSTEM);
|
||||
if(ue.getIsmanager()==null){
|
||||
ue.setIsmanager(BusinessConstants.USER_NOT_MANAGER);
|
||||
}
|
||||
ue.setStatus(BusinessConstants.USER_STATUS_NORMAL);
|
||||
int i=userMapperEx.addUser(ue);
|
||||
if(i>0){
|
||||
return ue;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public void updateUserAndOrgUserRel(UserEx ue) throws Exception{
|
||||
//检查用户名和登录名
|
||||
checkUserNameAndLoginName(ue);
|
||||
//更新用户信息
|
||||
ue=this.updateUser(ue);
|
||||
if(ue==null){
|
||||
logger.error("异常码[{}],异常提示[{}],参数,[{}]",
|
||||
ExceptionConstants.USER_EDIT_FAILED_CODE,ExceptionConstants.USER_EDIT_FAILED_MSG);
|
||||
throw new BusinessRunTimeException(ExceptionConstants.USER_EDIT_FAILED_CODE,
|
||||
ExceptionConstants.USER_EDIT_FAILED_MSG);
|
||||
}
|
||||
if(ue.getOrgaId()==null){
|
||||
//如果没有选择机构,就不建机构和用户的关联关系
|
||||
return;
|
||||
}
|
||||
//更新用户和机构关联关系
|
||||
OrgaUserRel oul=new OrgaUserRel();
|
||||
//机构和用户关联关系id
|
||||
oul.setId(ue.getOrgaUserRelId());
|
||||
//机构id
|
||||
oul.setOrgaId(ue.getOrgaId());
|
||||
//用户id
|
||||
oul.setUserId(ue.getId());
|
||||
//用户在机构中的排序
|
||||
oul.setUserBlngOrgaDsplSeq(ue.getUserBlngOrgaDsplSeq());
|
||||
if(oul.getId()!=null){
|
||||
//已存在机构和用户的关联关系,更新
|
||||
oul=orgaUserRelService.updateOrgaUserRel(oul);
|
||||
}else{
|
||||
//不存在机构和用户的关联关系,新建
|
||||
oul=orgaUserRelService.addOrgaUserRel(oul);
|
||||
}
|
||||
if(oul==null){
|
||||
logger.error("异常码[{}],异常提示[{}],参数,[{}]",
|
||||
ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_CODE,ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_MSG);
|
||||
throw new BusinessRunTimeException(ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_CODE,
|
||||
ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_MSG);
|
||||
}
|
||||
|
||||
}
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public UserEx updateUser(UserEx ue){
|
||||
int i=userMapperEx.updateUser(ue);
|
||||
if(i>0){
|
||||
return ue;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* create by: cjl
|
||||
* description:
|
||||
* 检查用户名称和登录名不能重复
|
||||
* create time: 2019/3/12 11:36
|
||||
* @Param: userEx
|
||||
* @return void
|
||||
*/
|
||||
public void checkUserNameAndLoginName(UserEx userEx){
|
||||
List<User> list=null;
|
||||
if(userEx==null){
|
||||
return;
|
||||
}
|
||||
Long userId=userEx.getId();
|
||||
//检查登录名
|
||||
if(!StringUtils.isEmpty(userEx.getLoginame())){
|
||||
String loginName=userEx.getLoginame();
|
||||
list=this.getUserListByloginName(loginName);
|
||||
if(list!=null&&list.size()>0){
|
||||
if(list.size()>1){
|
||||
//超过一条数据存在,该登录名已存在
|
||||
logger.error("异常码[{}],异常提示[{}],参数,loginName:[{}]",
|
||||
ExceptionConstants.USER_LOGIN_NAME_ALREADY_EXISTS_CODE,ExceptionConstants.USER_LOGIN_NAME_ALREADY_EXISTS_MSG,loginName);
|
||||
throw new BusinessRunTimeException(ExceptionConstants.USER_LOGIN_NAME_ALREADY_EXISTS_CODE,
|
||||
ExceptionConstants.USER_LOGIN_NAME_ALREADY_EXISTS_MSG);
|
||||
}
|
||||
//一条数据,新增时抛出异常,修改时和当前的id不同时抛出异常
|
||||
if(list.size()==1){
|
||||
if(userId==null||(userId!=null&&!userId.equals(list.get(0).getId()))){
|
||||
logger.error("异常码[{}],异常提示[{}],参数,loginName:[{}]",
|
||||
ExceptionConstants.USER_LOGIN_NAME_ALREADY_EXISTS_CODE,ExceptionConstants.USER_LOGIN_NAME_ALREADY_EXISTS_MSG,loginName);
|
||||
throw new BusinessRunTimeException(ExceptionConstants.USER_LOGIN_NAME_ALREADY_EXISTS_CODE,
|
||||
ExceptionConstants.USER_LOGIN_NAME_ALREADY_EXISTS_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//检查用户名
|
||||
if(!StringUtils.isEmpty(userEx.getUsername())){
|
||||
String userName=userEx.getUsername();
|
||||
list=this.getUserListByUserName(userName);
|
||||
if(list!=null&&list.size()>0){
|
||||
if(list.size()>1){
|
||||
//超过一条数据存在,该用户名已存在
|
||||
logger.error("异常码[{}],异常提示[{}],参数,userName:[{}]",
|
||||
ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_CODE,ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_MSG,userName);
|
||||
throw new BusinessRunTimeException(ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_CODE,
|
||||
ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_MSG);
|
||||
}
|
||||
//一条数据,新增时抛出异常,修改时和当前的id不同时抛出异常
|
||||
if(list.size()==1){
|
||||
if(userId==null||(userId!=null&&!userId.equals(list.get(0).getId()))){
|
||||
logger.error("异常码[{}],异常提示[{}],参数,userName:[{}]",
|
||||
ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_CODE,ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_MSG,userName);
|
||||
throw new BusinessRunTimeException(ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_CODE,
|
||||
ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 通过用户名获取用户列表
|
||||
* */
|
||||
public List<User> getUserListByUserName(String userName){
|
||||
return userMapperEx.getUserListByUserNameOrLoginName(userName,null);
|
||||
}
|
||||
/**
|
||||
* 通过登录名获取用户列表
|
||||
* */
|
||||
public List<User> getUserListByloginName(String loginName){
|
||||
return userMapperEx.getUserListByUserNameOrLoginName(null,loginName);
|
||||
}
|
||||
/**
|
||||
* 批量删除用户
|
||||
* */
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public void batDeleteUser(String ids) {
|
||||
String idsArray[]=ids.split(",");
|
||||
int i= userMapperEx.batDeleteOrUpdateUser(idsArray,BusinessConstants.USER_STATUS_DELETE);
|
||||
if(i<1){
|
||||
logger.error("异常码[{}],异常提示[{}],参数,ids:[{}]",
|
||||
ExceptionConstants.USER_DELETE_FAILED_CODE,ExceptionConstants.USER_DELETE_FAILED_MSG,ids);
|
||||
throw new BusinessRunTimeException(ExceptionConstants.USER_DELETE_FAILED_CODE,
|
||||
ExceptionConstants.USER_DELETE_FAILED_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user