|
|
@ -0,0 +1,249 @@ |
|
|
|
package com.kms.web.controller.system; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.jianwei.common.core.domain.AjaxResult; |
|
|
|
import com.jianwei.common.core.domain.entity.SysDept; |
|
|
|
import com.jianwei.common.core.domain.entity.SysRole; |
|
|
|
import com.jianwei.common.core.domain.entity.SysUser; |
|
|
|
import com.jianwei.common.exception.CustomException; |
|
|
|
import com.jianwei.common.utils.password.MD5Util; |
|
|
|
import com.jianwei.common.utils.password.PasswordUtil; |
|
|
|
import com.jianwei.common.utils.uuid.IdUtils; |
|
|
|
import com.kms.config.CallBackRequest; |
|
|
|
import com.kms.config.CallType; |
|
|
|
import com.kms.config.WaterResult; |
|
|
|
import com.kms.config.scheduled.WaterScheduled; |
|
|
|
import com.kms.config.singleDomain.SingleOrg; |
|
|
|
import com.kms.config.singleDomain.SingleRole; |
|
|
|
import com.kms.config.singleDomain.SingleUser; |
|
|
|
import com.kms.system.domain.SysUserRole; |
|
|
|
import com.kms.system.service.SysDeptService; |
|
|
|
import com.kms.system.service.SysRoleService; |
|
|
|
import com.kms.system.service.SysUserRoleService; |
|
|
|
import com.kms.system.service.SysUserService; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Controller; |
|
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@RequestMapping("/callBack") |
|
|
|
@Controller |
|
|
|
public class CmsCallBackController { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
SysUserService userService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
SysDeptService deptService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
SysRoleService roleService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
SysUserRoleService userRoleService; |
|
|
|
|
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(CmsCallBackController.class); |
|
|
|
|
|
|
|
@PostMapping("/notify") |
|
|
|
public WaterResult callBack(@RequestBody CallBackRequest callBackRequest){ |
|
|
|
log.info("--------开启同步请求--------------,时间:{}",new Date()); |
|
|
|
log.info("发起同步请求的参数为:{}",callBackRequest); |
|
|
|
String type = callBackRequest.getType(); |
|
|
|
String content = callBackRequest.getContent(); |
|
|
|
if(type.equals(CallType.USER_ADD)){ |
|
|
|
SingleUser singleUser = JSONObject.parseObject(content, SingleUser.class); |
|
|
|
QueryWrapper<SysUser> query = Wrappers.query(); |
|
|
|
query.eq("single_user_id",singleUser.getId()); |
|
|
|
SysUser user = userService.getOne(query,false); |
|
|
|
if(user!=null){ |
|
|
|
throw new CustomException("该用户已存在,无法添加"); |
|
|
|
} |
|
|
|
user = new SysUser(); |
|
|
|
user.preInsert(); |
|
|
|
user.setCreateUid("1"); |
|
|
|
user.setUpdateUid("1"); |
|
|
|
user.setRemark("门户定时任务数据添加"); |
|
|
|
user.setId(IdUtils.fastSimpleUUID()); |
|
|
|
user.setIsPcUser("0"); |
|
|
|
user.setDelFlag("0"); |
|
|
|
user.setPhonenumber(singleUser.getPhone()); |
|
|
|
user.setNickName(singleUser.getName()); |
|
|
|
user.setUserName(singleUser.getUsername()); |
|
|
|
user.setSingleUserSource(singleUser.getSource()); |
|
|
|
user.setSingleUserType(singleUser.getType()); |
|
|
|
user.setSingleUserId(singleUser.getId()); |
|
|
|
user.setPassword(PasswordUtil.entryptPassword(singleUser.getUsername())); |
|
|
|
user.setIsFirst(singleUser.getFirstSignIn().toString()); |
|
|
|
if(singleUser.getStatus()==null||singleUser.getStatus().equals("1")){ |
|
|
|
user.setStatus("0"); |
|
|
|
}else { |
|
|
|
user.setStatus("1"); |
|
|
|
} |
|
|
|
List<String> collect = singleUser.getRoleList().stream().map(singleRole -> singleRole.getId()).collect(Collectors.toList()); |
|
|
|
user.setRoleIds(collect.toArray(new String[collect.size()])); |
|
|
|
userService.singleInsertUser(user); |
|
|
|
}else if(type.equals(CallType.USER_UPDATE)){ |
|
|
|
SingleUser singleUser = JSONObject.parseObject(content, SingleUser.class); |
|
|
|
QueryWrapper<SysUser> query = Wrappers.query(); |
|
|
|
query.eq("single_user_id",singleUser.getId()); |
|
|
|
SysUser user = userService.getOne(query,false); |
|
|
|
if(user==null){ |
|
|
|
throw new CustomException("该用户不存在,无法修改"); |
|
|
|
} |
|
|
|
SingleOrg org = singleUser.getOrg(); |
|
|
|
if(org!=null){ |
|
|
|
user.setDeptId(org.getId()); |
|
|
|
} |
|
|
|
user.setPhonenumber(singleUser.getPhone()); |
|
|
|
user.setNickName(singleUser.getName()); |
|
|
|
user.setUserName(singleUser.getUsername()); |
|
|
|
user.setSingleUserSource(singleUser.getSource()); |
|
|
|
user.setSingleUserType(singleUser.getType()); |
|
|
|
user.setSingleUserId(singleUser.getId()); |
|
|
|
user.setPassword(PasswordUtil.entryptPassword(singleUser.getUsername())); |
|
|
|
user.setIsFirst(singleUser.getFirstSignIn().toString()); |
|
|
|
if(singleUser.getStatus()==null||singleUser.getStatus().equals("1")){ |
|
|
|
user.setStatus("0"); |
|
|
|
}else { |
|
|
|
user.setStatus("1"); |
|
|
|
} |
|
|
|
List<String> collect = singleUser.getRoleList().stream().map(singleRole -> singleRole.getId()).collect(Collectors.toList()); |
|
|
|
user.setRoleIds(collect.toArray(new String[collect.size()])); |
|
|
|
userService.singleInsertUser(user); |
|
|
|
}else if(type.equals(CallType.USER_DELETE)){ |
|
|
|
SingleUser singleUser = JSONObject.parseObject(content, SingleUser.class); |
|
|
|
QueryWrapper<SysUser> query = Wrappers.query(); |
|
|
|
query.eq("single_user_id",singleUser.getId()); |
|
|
|
SysUser one = userService.getOne(query, false); |
|
|
|
if(one==null){ |
|
|
|
throw new CustomException("该用户不存在,无法删除"); |
|
|
|
} |
|
|
|
userService.deleteUserById(one.getId()); |
|
|
|
}else if(type.equals(CallType.ORG_ADD)){ |
|
|
|
SingleOrg singleOrg = JSONObject.parseObject(content, SingleOrg.class); |
|
|
|
SysDept dept = deptService.getById(singleOrg.getId()); |
|
|
|
if(dept==null) { |
|
|
|
dept = new SysDept(); |
|
|
|
dept.setIsDownload("0"); |
|
|
|
dept.setIsComment("0"); |
|
|
|
dept.setDelFlag("0"); |
|
|
|
dept.setCreateTime(new Date()); |
|
|
|
BeanUtils.copyProperties(singleOrg,dept); |
|
|
|
dept.setXzqhId(singleOrg.getArea()); |
|
|
|
dept.setXzqhName(singleOrg.getAreaText()); |
|
|
|
dept.setSingleCode(singleOrg.getCode()); |
|
|
|
dept.setSingleSeq(singleOrg.getSeq()); |
|
|
|
dept.setSingleType(singleOrg.getType()); |
|
|
|
dept.setDeptName(singleOrg.getName()); |
|
|
|
dept.setParentId(singleOrg.getParent()); |
|
|
|
dept.setLeader(singleOrg.getDutyPerson()); |
|
|
|
dept.setName(singleOrg.getName()); |
|
|
|
dept.setAdminName(singleOrg.getName()); |
|
|
|
dept.setUpdateTime(new Date()); |
|
|
|
if(singleOrg.getStatus()==null||singleOrg.getStatus().equals("1")){ |
|
|
|
dept.setStatus("0"); |
|
|
|
}else { |
|
|
|
dept.setStatus("1"); |
|
|
|
} |
|
|
|
deptService.save(dept); |
|
|
|
} |
|
|
|
}else if(type.equals(CallType.ORG_UPDATE)){ |
|
|
|
SingleOrg singleOrg = JSONObject.parseObject(content, SingleOrg.class); |
|
|
|
SysDept dept = deptService.getById(singleOrg.getId()); |
|
|
|
if(dept!=null) { |
|
|
|
BeanUtils.copyProperties(singleOrg, dept); |
|
|
|
dept.setXzqhId(singleOrg.getArea()); |
|
|
|
dept.setXzqhName(singleOrg.getAreaText()); |
|
|
|
dept.setSingleCode(singleOrg.getCode()); |
|
|
|
dept.setSingleSeq(singleOrg.getSeq()); |
|
|
|
dept.setSingleType(singleOrg.getType()); |
|
|
|
dept.setDeptName(singleOrg.getName()); |
|
|
|
dept.setParentId(singleOrg.getParent()); |
|
|
|
dept.setLeader(singleOrg.getDutyPerson()); |
|
|
|
dept.setName(singleOrg.getName()); |
|
|
|
dept.setAdminName(singleOrg.getName()); |
|
|
|
dept.setUpdateTime(new Date()); |
|
|
|
if(singleOrg.getStatus()==null||singleOrg.getStatus().equals("1")){ |
|
|
|
dept.setStatus("0"); |
|
|
|
}else { |
|
|
|
dept.setStatus("1"); |
|
|
|
} |
|
|
|
deptService.updateById(dept); |
|
|
|
} |
|
|
|
}else if(type.equals(CallType.ROLE_ADD)){ |
|
|
|
log.info("执行消息:角色添加,参数为:"+content); |
|
|
|
SingleRole singleRole = JSONObject.parseObject(content, SingleRole.class); |
|
|
|
SysRole sysRole = roleService.getById(singleRole.getId()); |
|
|
|
if(sysRole==null){ |
|
|
|
sysRole = new SysRole(); |
|
|
|
sysRole.setStatus("0"); |
|
|
|
if(sysRole.getStatus()==null||sysRole.getStatus()=="0"){ |
|
|
|
sysRole.setStatus("1"); |
|
|
|
} |
|
|
|
sysRole.setDelFlag("0"); |
|
|
|
sysRole.setRoleSort("0"); |
|
|
|
sysRole.setCreateTime(new Date()); |
|
|
|
BeanUtils.copyProperties(singleRole,sysRole); |
|
|
|
sysRole.setRoleName(singleRole.getName()); |
|
|
|
sysRole.setRoleKey(singleRole.getCode()); |
|
|
|
sysRole.setUpdateTime(new Date()); |
|
|
|
roleService.save(sysRole); |
|
|
|
} |
|
|
|
}else if(type.equals(CallType.ROLE_UPDATE)){ |
|
|
|
SingleRole singleRole = JSONObject.parseObject(content, SingleRole.class); |
|
|
|
SysRole sysRole = roleService.getById(singleRole.getId()); |
|
|
|
if(sysRole!=null){ |
|
|
|
if(sysRole.getStatus()==null||sysRole.getStatus()=="0"){ |
|
|
|
sysRole.setStatus("1"); |
|
|
|
}else{ |
|
|
|
sysRole.setStatus("0"); |
|
|
|
} |
|
|
|
BeanUtils.copyProperties(singleRole,sysRole); |
|
|
|
sysRole.setRoleName(singleRole.getName()); |
|
|
|
sysRole.setRoleKey(singleRole.getCode()); |
|
|
|
sysRole.setUpdateTime(new Date()); |
|
|
|
roleService.updateById(sysRole); |
|
|
|
} |
|
|
|
}else if(type.equals(CallType.ROLE_DELETE)){ |
|
|
|
SingleRole singleRole = JSONObject.parseObject(content, SingleRole.class); |
|
|
|
roleService.deleteRoleById(singleRole.getId()); |
|
|
|
}else if(type.equals(CallType.ROLE_USER_BIND)){ //绑定
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(content); |
|
|
|
String roleId = jsonObject.getString("roleId"); |
|
|
|
JSONArray userIds = jsonObject.getJSONArray("userIds"); |
|
|
|
List<String> list = userIds.toJavaList(String.class); |
|
|
|
for (String id : list) { |
|
|
|
SysUserRole sysUserRole = new SysUserRole(); |
|
|
|
sysUserRole.preInsert(); |
|
|
|
sysUserRole.setUserId(id); |
|
|
|
sysUserRole.setRoleId(roleId); |
|
|
|
userRoleService.save(sysUserRole); |
|
|
|
} |
|
|
|
}else if(type.equals(CallType.ROLE_USER_UNBIND)) { //解绑
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(content); |
|
|
|
String roleId = jsonObject.getString("roleId"); |
|
|
|
JSONArray userIds = jsonObject.getJSONArray("userIds"); |
|
|
|
List<String> list = userIds.toJavaList(String.class); |
|
|
|
QueryWrapper<SysUserRole> query = Wrappers.query(); |
|
|
|
query.eq("role_id",roleId).in("user_id",list); |
|
|
|
userRoleService.remove(query); |
|
|
|
} |
|
|
|
log.info("--------同步请求结束--------------,时间:{}",new Date()); |
|
|
|
return WaterResult.success(); |
|
|
|
} |
|
|
|
|
|
|
|
} |