|
@@ -4,6 +4,7 @@
|
|
|
package com.jeeplus.sys.controller;
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
@@ -11,6 +12,7 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.gson.Gson;
|
|
@@ -25,23 +27,20 @@ import com.jeeplus.common.redis.RedisUtils;
|
|
|
import com.jeeplus.common.utils.ResponseUtil;
|
|
|
import com.jeeplus.core.query.QueryWrapperGenerator;
|
|
|
import com.jeeplus.logging.annotation.ApiLog;
|
|
|
-import com.jeeplus.sys.domain.Office;
|
|
|
-import com.jeeplus.sys.domain.User;
|
|
|
+import com.jeeplus.sys.domain.*;
|
|
|
import com.jeeplus.sys.domain.vo.UserVO;
|
|
|
import com.jeeplus.sys.feign.IUserApi;
|
|
|
-import com.jeeplus.sys.service.OfficeService;
|
|
|
-import com.jeeplus.sys.service.UserService;
|
|
|
-import com.jeeplus.sys.service.dto.OfficeDTO;
|
|
|
-import com.jeeplus.sys.service.dto.UserDTO;
|
|
|
+import com.jeeplus.sys.mapper.UserMapper;
|
|
|
+import com.jeeplus.sys.service.*;
|
|
|
+import com.jeeplus.sys.service.dto.*;
|
|
|
+import com.jeeplus.sys.service.mapstruct.CertWrapper;
|
|
|
import com.jeeplus.sys.service.mapstruct.UserWrapper;
|
|
|
-import com.jeeplus.sys.utils.DictUtils;
|
|
|
-import com.jeeplus.sys.utils.MenuUtils;
|
|
|
-import com.jeeplus.sys.utils.TenantUtils;
|
|
|
-import com.jeeplus.sys.utils.UserUtils;
|
|
|
+import com.jeeplus.sys.utils.*;
|
|
|
import com.jeeplus.sys.utils.excel.UserEasyExcel;
|
|
|
import com.jeeplus.utils.StringUtils;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
@@ -53,6 +52,8 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.Valid;
|
|
|
import javax.validation.constraints.NotNull;
|
|
|
import java.io.IOException;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.lang.reflect.Type;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -73,6 +74,20 @@ public class UserController {
|
|
|
private UserService userService;
|
|
|
|
|
|
@Autowired
|
|
|
+ private OtherUserInfoService otherUserInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RosterBankCardsService rosterBankCardsService;
|
|
|
+ @Autowired
|
|
|
+ private RosterCertificateService rosterCertificateService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CertService certService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RosterContractService rosterContractService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private OfficeService officeService;
|
|
|
|
|
|
@Autowired
|
|
@@ -124,6 +139,64 @@ public class UserController {
|
|
|
@ApiOperation(value = "查询用户")
|
|
|
public ResponseEntity queryById(@RequestParam("id") String id) {
|
|
|
UserDTO userDTO = userService.get ( id );
|
|
|
+ UserOtherInfo otherInfo = otherUserInfoService.getOne(new QueryWrapper<UserOtherInfo>().lambda().eq(UserOtherInfo::getUserInfoId, id));
|
|
|
+ UserOtherInfoDto otherInfoDto = new UserOtherInfoDto();
|
|
|
+ if (null != otherInfo) {
|
|
|
+ BeanUtils.copyProperties(otherInfo, otherInfoDto);
|
|
|
+ userDTO.setOtherInfoDto(otherInfoDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询合同信息
|
|
|
+ RosterContract contract = rosterContractService.getOne(new QueryWrapper<RosterContract>().lambda().eq(RosterContract::getBaseId, id));
|
|
|
+ RosterContractDTO contractDto = new RosterContractDTO();
|
|
|
+ if (null != contract) {
|
|
|
+ BeanUtils.copyProperties(contract, contractDto);
|
|
|
+ userDTO.setRosterContractDTO(contractDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null != contract) {
|
|
|
+ BeanUtils.copyProperties(contract, contractDto);
|
|
|
+ userDTO.setRosterContractDTO(contractDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ //查银行卡信息
|
|
|
+ List<RosterBankCards> bankCards = rosterBankCardsService.list(new QueryWrapper<RosterBankCards>().lambda().eq(RosterBankCards::getBaseId, id));
|
|
|
+ List<RosterBankCardsDTO> bankCardsDTO = new ArrayList<>();
|
|
|
+ bankCards.forEach(ba->{
|
|
|
+ RosterBankCardsDTO cardsDTO = new RosterBankCardsDTO();
|
|
|
+ BeanUtils.copyProperties(ba, cardsDTO);
|
|
|
+ bankCardsDTO.add(cardsDTO);
|
|
|
+ });
|
|
|
+ userDTO.setRosterBankCardsDTOList(bankCardsDTO);
|
|
|
+
|
|
|
+ //员工证书
|
|
|
+ List<RosterCertificate> certificates = rosterCertificateService.list(new QueryWrapper<RosterCertificate>().lambda().eq(RosterCertificate::getBaseId, id));
|
|
|
+ List<RosterCertificateDTO> certificateDTOS = new ArrayList<>();
|
|
|
+ certificates.forEach(ba->{
|
|
|
+ RosterCertificateDTO cardsDTO = new RosterCertificateDTO();
|
|
|
+ BeanUtils.copyProperties(ba, cardsDTO);
|
|
|
+ certificateDTOS.add(cardsDTO);
|
|
|
+ });
|
|
|
+ userDTO.setRosterCertificateDTOList(certificateDTOS);
|
|
|
+
|
|
|
+ //查询人员资质
|
|
|
+ List<Cert> certs = certService.list(new QueryWrapper<Cert>().lambda().eq(Cert::getUserId, id));
|
|
|
+ List<CertDTO> certDTOS = new ArrayList<>();
|
|
|
+ certs.forEach(ba->{
|
|
|
+ CertDTO cardsDTO = new CertDTO();
|
|
|
+ BeanUtils.copyProperties(ba, cardsDTO);
|
|
|
+ certDTOS.add(cardsDTO);
|
|
|
+ });
|
|
|
+ userDTO.setCertDTOList(certDTOS);
|
|
|
+
|
|
|
+ // 附件信息
|
|
|
+ List<WorkAttachmentDto2> files = userService.getByAttachmentId(id);
|
|
|
+ if (CollectionUtils.isNotEmpty(files)) {
|
|
|
+ for (WorkAttachmentDto2 i : files) {
|
|
|
+ i.setCreateBy(SpringUtil.getBean ( IUserApi.class ).getById(i.getBy()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ userDTO.setFiles(files);
|
|
|
return ResponseEntity.ok ( userDTO );
|
|
|
}
|
|
|
|
|
@@ -678,6 +751,9 @@ public class UserController {
|
|
|
@ApiOperation(value = "保存用户")
|
|
|
@PostMapping("save")
|
|
|
public ResponseEntity save(@Valid @RequestBody UserDTO userDTO) {
|
|
|
+
|
|
|
+ UserDTO info = SpringUtil.getBean ( IUserApi.class ).getByToken ( TokenProvider.getCurrentToken() );
|
|
|
+
|
|
|
// 如果新密码为空,则不更换密码
|
|
|
if ( StrUtil.isNotBlank ( userDTO.getNewPassword ( ) ) ) {
|
|
|
userDTO.setPassword ( SecurityUtils.encryptPassword ( userDTO.getNewPassword ( ) ) );
|
|
@@ -685,8 +761,152 @@ public class UserController {
|
|
|
if ( !UserUtils.isCheckLoginName ( userDTO.getOldLoginName ( ), userDTO.getLoginName ( ), userDTO.getTenantDTO ( ).getId ( ) ) ) {
|
|
|
return ResponseEntity.badRequest ( ).body ( "保存用户'" + userDTO.getLoginName ( ) + "'失败,登录名已存在!" );
|
|
|
}
|
|
|
+ String id = SnowFlake2.getId();
|
|
|
+ if (StringUtils.isBlank(userDTO.getId())) {
|
|
|
+ userDTO.setId(id);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
// 保存用户信息
|
|
|
userService.saveOrUpdate ( userDTO );
|
|
|
+
|
|
|
+ //保存合同信息
|
|
|
+ if(ObjectUtil.isNotEmpty(userDTO.getRosterContractDTO())){
|
|
|
+ RosterContractDTO rosterContractDTO = userDTO.getRosterContractDTO();
|
|
|
+
|
|
|
+ RosterContract rosterContract = new RosterContract();
|
|
|
+ BeanUtils.copyProperties(rosterContractDTO, rosterContract);
|
|
|
+
|
|
|
+ rosterContract.setCreateById(info.getId());
|
|
|
+ rosterContract.setCreateTime(new Date());
|
|
|
+ rosterContract.setUpdateById(info.getId());
|
|
|
+ rosterContract.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ rosterContract.setBaseId(userDTO.getId());
|
|
|
+ rosterContractService.remove(new QueryWrapper<RosterContract>().eq("base_id",userDTO.getId()));
|
|
|
+ rosterContractService.saveOrUpdate(rosterContract);
|
|
|
+ } else {
|
|
|
+ rosterContractService.remove(new QueryWrapper<RosterContract>().eq("base_id",userDTO.getId()));
|
|
|
+ }
|
|
|
+ //保存 银行卡信息、人员资质、员工证书 及 其他个人信息
|
|
|
+ //1、保存其他个人信息
|
|
|
+ if (null != userDTO.getOtherInfoDto()) {
|
|
|
+ UserOtherInfoDto otherInfoDto = userDTO.getOtherInfoDto();
|
|
|
+ UserOtherInfo otherInfo = new UserOtherInfo();
|
|
|
+ BeanUtils.copyProperties(otherInfoDto, otherInfo);
|
|
|
+
|
|
|
+ otherInfo.setCreateById(info.getId());
|
|
|
+ otherInfo.setCreateTime(new Date());
|
|
|
+ otherInfo.setUpdateById(info.getId());
|
|
|
+ otherInfo.setUpdateTime(new Date());
|
|
|
+ otherInfo.setUserInfoId(userDTO.getId());
|
|
|
+ otherUserInfoService.saveOrUpdate(otherInfo);
|
|
|
+ }
|
|
|
+ //2、保存银行卡信息
|
|
|
+ if(CollectionUtil.isNotEmpty(userDTO.getRosterBankCardsDTOList())){
|
|
|
+ List<String> collect = userDTO.getRosterBankCardsDTOList().stream().map(RosterBankCardsDTO::getId).collect(Collectors.toList());
|
|
|
+ rosterBankCardsService.remove(new QueryWrapper<RosterBankCards>().eq("base_id",userDTO.getId()).notIn(CollectionUtil.isNotEmpty(collect),"id",collect));
|
|
|
+ userDTO.getRosterBankCardsDTOList().stream().forEach(item->{
|
|
|
+ if(ObjectUtil.isNotEmpty(item)&& objectCheckIsNull(item)){
|
|
|
+ RosterBankCards rosterBankCards = new RosterBankCards();
|
|
|
+ BeanUtils.copyProperties(item, rosterBankCards);
|
|
|
+ rosterBankCards.setCreateById(info.getId());
|
|
|
+ rosterBankCards.setCreateTime(new Date());
|
|
|
+ rosterBankCards.setUpdateById(info.getId());
|
|
|
+ rosterBankCards.setUpdateTime(new Date());
|
|
|
+ rosterBankCards.setBaseId(userDTO.getId());
|
|
|
+ rosterBankCardsService.saveOrUpdate(rosterBankCards);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ rosterBankCardsService.remove(new QueryWrapper<RosterBankCards>().eq("base_id",userDTO.getId()));
|
|
|
+ }
|
|
|
+ //3、保存员工证书
|
|
|
+ //保存员工证书
|
|
|
+ if(CollectionUtil.isNotEmpty(userDTO.getRosterCertificateDTOList())){
|
|
|
+ List<String> collect = userDTO.getRosterCertificateDTOList().stream().map(RosterCertificateDTO::getId).collect(Collectors.toList());
|
|
|
+ rosterCertificateService.remove(new QueryWrapper<RosterCertificate>().eq("base_id",userDTO.getId()).notIn(CollectionUtil.isNotEmpty(collect),"id",collect));
|
|
|
+ userDTO.getRosterCertificateDTOList().stream().forEach(item->{
|
|
|
+ if(ObjectUtil.isNotEmpty(item)&& objectCheckIsNull(item)){
|
|
|
+ RosterCertificate rosterCertificate = new RosterCertificate();
|
|
|
+ BeanUtils.copyProperties(item, rosterCertificate);
|
|
|
+ rosterCertificate.setCreateById(info.getId());
|
|
|
+ rosterCertificate.setCreateTime(new Date());
|
|
|
+ rosterCertificate.setUpdateById(info.getId());
|
|
|
+ rosterCertificate.setUpdateTime(new Date());
|
|
|
+ rosterCertificate.setBaseId(userDTO.getId());
|
|
|
+ rosterCertificate.setBaseId(userDTO.getId());
|
|
|
+ rosterCertificateService.saveOrUpdate(rosterCertificate);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ rosterCertificateService.remove(new QueryWrapper<RosterCertificate>().eq("base_id",userDTO.getId()));
|
|
|
+ }
|
|
|
+ //4、保存人员资质
|
|
|
+ // 保存花名册关联用户的资质信息
|
|
|
+ certService.remove(new QueryWrapper<Cert>().lambda().eq(Cert::getUserId,userDTO.getId()));
|
|
|
+ if(ObjectUtil.isNotEmpty(userDTO.getCertDTOList())){
|
|
|
+ List<Cert> certList = new ArrayList<>();
|
|
|
+ userDTO.getCertDTOList().stream().forEach(i -> {
|
|
|
+ Cert cert = CertWrapper.INSTANCE.toEntity(i);
|
|
|
+ cert.setUserId(userDTO.getId());
|
|
|
+ cert.setId("");
|
|
|
+ certList.add(cert);
|
|
|
+ });
|
|
|
+ if (CollectionUtil.isNotEmpty(certList)) {
|
|
|
+ certService.saveBatch(certList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ User user = userService.getOne(new QueryWrapper<User>().lambda().eq(User::getRosterId, userDTO.getId()));
|
|
|
+ if (ObjectUtil.isNotEmpty(user)) {
|
|
|
+ // 保存花名册关联用户的资质信息
|
|
|
+// certService.remove(new QueryWrapper<Cert>().lambda().eq(Cert::getUserId,user.getId()));
|
|
|
+// if(ObjectUtil.isNotEmpty(userDTO.getCertDTOList())){
|
|
|
+// List<Cert> certList = new ArrayList<>();
|
|
|
+// userDTO.getCertDTOList().stream().forEach(i -> {
|
|
|
+// Cert cert = CertWrapper.INSTANCE.toEntity(i);
|
|
|
+// cert.setUserId(user.getId());
|
|
|
+// cert.setId("");
|
|
|
+// certList.add(cert);
|
|
|
+// });
|
|
|
+// if (CollectionUtil.isNotEmpty(certList)) {
|
|
|
+// certService.saveBatch(certList);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// // 保存花名册关联用户的角色
|
|
|
+// userMapper.deleteUserRole(user.getId()); // 删除用户的角色
|
|
|
+// if (CollectionUtil.isNotEmpty(userDTO.getRoleIdList())) {
|
|
|
+// userDTO.getRoleIdList().stream().forEach(i -> {
|
|
|
+// userMapper.insertUserRole(user.getId(), i); // 插入用户的角色
|
|
|
+// });
|
|
|
+// }
|
|
|
+// // 保存花名册关联用户的岗位
|
|
|
+// userMapper.deleteUserPost(user.getId()); // 删除用户的岗位
|
|
|
+// if (CollectionUtil.isNotEmpty(userDTO.getPostIdList())) {
|
|
|
+// userDTO.getPostIdList().stream().forEach(i -> {
|
|
|
+// userMapper.insertUserPost(user.getId(), i); // 插入用户的岗位
|
|
|
+// });
|
|
|
+// }
|
|
|
+// // 保存花名册关联用户的管理部门
|
|
|
+// UserDTO u = new UserDTO();
|
|
|
+// u.setId(user.getId());
|
|
|
+// userMapper.deleteUserManageOffice(u); // 删除用户的管理部门 (用户、管理部门关联表)
|
|
|
+// String oIds = "";
|
|
|
+// if (StringUtils.isNotBlank(userDTO.getManageOfficeIds())) {
|
|
|
+// List<String> officeIds= Arrays.asList(userDTO.getManageOfficeIds().split(","));
|
|
|
+// officeIds.stream().forEach(officeId -> {
|
|
|
+// userMapper.insertUserManageOffice(officeId,user.getId()); // 插入用户的管理部门 (用户、管理部门关联表)
|
|
|
+// });
|
|
|
+// oIds = userDTO.getManageOfficeIds();
|
|
|
+// }
|
|
|
+// userMapper.updateUserManageOffice(oIds, user.getId()); // 修改用户的管理部门 (用户表)
|
|
|
+ }
|
|
|
+ //5、保存附件信息
|
|
|
+ if (CollectionUtils.isNotEmpty(userDTO.getFiles())) {
|
|
|
+ saveFiles(userDTO.getFiles(), userDTO, id);
|
|
|
+ }
|
|
|
+
|
|
|
return ResponseEntity.ok ( "保存用户'" + userDTO.getLoginName ( ) + "'成功!" );
|
|
|
}
|
|
|
|
|
@@ -1385,7 +1605,64 @@ public class UserController {
|
|
|
|
|
|
|
|
|
|
|
|
+ public static boolean objectCheckIsNull(Object object) {
|
|
|
+ boolean flag = false; //定义返回结果,默认为true
|
|
|
|
|
|
+ if (Objects.isNull(object)) {
|
|
|
+ flag = false;
|
|
|
+ } else {
|
|
|
+ Class clazz = (Class) object.getClass(); // 得到类对象
|
|
|
+ Field fields[] = clazz.getDeclaredFields(); // 得到所有属性
|
|
|
+ for (Field field : fields) {
|
|
|
+ if("serialVersionUID".equals(field.getName()) || "BIZ_CODE".equalsIgnoreCase(field.getName())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ field.setAccessible(true);
|
|
|
+ Object fieldValue = null;
|
|
|
+ try {
|
|
|
+ fieldValue = field.get(object); //得到属性值
|
|
|
+ Type fieldType = field.getGenericType();//得到属性类型
|
|
|
+ String fieldName = field.getName(); // 得到属性名
|
|
|
+ System.out.println(("属性类型:" + fieldType + ",属性名:" + fieldName + ",属性值:" + fieldValue));
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (fieldValue != null && fieldValue != "") { //只要有一个属性值不为null 就返回false 表示对象不为null
|
|
|
+ flag = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
|
|
|
+ public void saveFiles(List<WorkAttachmentDto2> list, UserDTO userDTO, String id) {
|
|
|
+ int j = 1;
|
|
|
+ for (WorkAttachmentDto2 dto : list) {
|
|
|
+ WorkAttachmentInfo2 i = new WorkAttachmentInfo2();
|
|
|
+ //包含了url、size、name
|
|
|
+ i.setId(UUID.randomUUID().toString().replace("-", ""));
|
|
|
+// i.getCreateBy().setId(userDTO.getId());
|
|
|
+ i.setCreateTime(new Date());
|
|
|
+// i.getUpdateBy().setId(userDTO.getId());
|
|
|
+ i.setUpdateTime(new Date());
|
|
|
+ i.setDelFlag(0);
|
|
|
+ i.setUrl(dto.getUrl());
|
|
|
+ //文件类型处理
|
|
|
+ List<String> strings = Arrays.asList(dto.getName().split("\\."));
|
|
|
+ if (org.flowable.editor.language.json.converter.util.CollectionUtils.isNotEmpty(strings)) {
|
|
|
+ i.setType(strings.get(1));
|
|
|
+ }
|
|
|
+ i.setAttachmentId(id);
|
|
|
+ i.setAttachmentName(dto.getName());
|
|
|
+ i.setAttachmentFlag("userFilesInfo");
|
|
|
+ i.setFileSize(dto.getSize());
|
|
|
+ i.setSort(j);
|
|
|
+ userService.insertWorkAttachment(i, userDTO);
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|