|
@@ -9,6 +9,7 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.google.common.collect.Lists;
|
|
@@ -18,18 +19,17 @@ import com.jeeplus.common.constant.CacheNames;
|
|
|
import com.jeeplus.common.constant.CommonConstants;
|
|
|
import com.jeeplus.common.redis.RedisUtils;
|
|
|
import com.jeeplus.common.utils.RequestUtils;
|
|
|
-import com.jeeplus.sys.domain.Cert;
|
|
|
-import com.jeeplus.sys.domain.Office;
|
|
|
-import com.jeeplus.sys.domain.SysConfig;
|
|
|
-import com.jeeplus.sys.domain.User;
|
|
|
+import com.jeeplus.sys.domain.*;
|
|
|
import com.jeeplus.sys.feign.IUserApi;
|
|
|
import com.jeeplus.sys.mapper.OfficeMapper;
|
|
|
import com.jeeplus.sys.mapper.UserMapper;
|
|
|
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.SnowFlake2;
|
|
|
import com.jeeplus.sys.utils.UserUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -37,10 +37,10 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.validation.constraints.NotNull;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Calendar;
|
|
|
-import java.util.List;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.lang.reflect.Type;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -78,6 +78,15 @@ public class UserService extends ServiceImpl <UserMapper, User> {
|
|
|
|
|
|
@Autowired
|
|
|
private RedisUtils redisUtils;
|
|
|
+ @Autowired
|
|
|
+ private RosterCertificateService rosterCertificateService;
|
|
|
+ @Autowired
|
|
|
+ private RosterContractService rosterContractService;
|
|
|
+ @Autowired
|
|
|
+ private OtherUserInfoService otherUserInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RosterBankCardsService rosterBankCardsService;
|
|
|
|
|
|
public void insertWorkAttachment (WorkAttachmentInfo2 workAttachment, UserDTO userDto){
|
|
|
userMapper.insertWorkAttachment(workAttachment, userDto);
|
|
@@ -352,6 +361,9 @@ public class UserService extends ServiceImpl <UserMapper, User> {
|
|
|
* @param userDTO
|
|
|
*/
|
|
|
public void saveOrUpdate(UserDTO userDTO) {
|
|
|
+
|
|
|
+ UserDTO info = SpringUtil.getBean ( IUserApi.class ).getByToken ( TokenProvider.getCurrentToken() );
|
|
|
+
|
|
|
User user = userWrapper.toEntity ( userDTO );
|
|
|
if(StringUtils.isNotBlank(userDTO.getManageOfficeIds())){
|
|
|
user.setManageOfficeIds(userDTO.getManageOfficeIds());
|
|
@@ -392,9 +404,225 @@ public class UserService extends ServiceImpl <UserMapper, User> {
|
|
|
redisUtils.set(CacheNames.USER_CACHE_USER_ALL_INFO,"user:cache:user:all:info",allUserInfo);
|
|
|
}
|
|
|
|
|
|
+ //保存合同信息
|
|
|
+ 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()));
|
|
|
+ }
|
|
|
+ //批量导入人员信息处理
|
|
|
+ UserOtherInfoDto temporaryOtherInfo = new UserOtherInfoDto();
|
|
|
+ //身份证处理
|
|
|
+ if(StringUtils.isNotBlank(userDTO.getIdCard())){
|
|
|
+ temporaryOtherInfo.setIdCard(userDTO.getIdCard());
|
|
|
+ temporaryOtherInfo.setCertificatesType("1");//类型调整为身份证
|
|
|
+ }
|
|
|
+ temporaryOtherInfo.setWorkerType("1");//员工类型默认正式
|
|
|
+
|
|
|
+ if(null != userDTO.getOnboardingDate()) {
|
|
|
+ SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ temporaryOtherInfo.setOnboardingDate(sf.format(userDTO.getOnboardingDate()));//员工入职时间
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(temporaryOtherInfo.getIdCard()) || StringUtils.isNotBlank(temporaryOtherInfo.getWorkerType()) || StringUtils.isNotBlank(temporaryOtherInfo.getOnboardingDate())) {
|
|
|
+ userDTO.setOtherInfoDto(temporaryOtherInfo);
|
|
|
+ }
|
|
|
+ //保存 银行卡信息、人员资质、员工证书 及 其他个人信息
|
|
|
+ //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 thisUser = this.getOne(new QueryWrapper<User>().lambda().eq(User::getRosterId, userDTO.getId()));
|
|
|
+ if (ObjectUtil.isNotEmpty(thisUser)) {
|
|
|
+ // 保存花名册关联用户的资质信息
|
|
|
+// 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()); // 修改用户的管理部门 (用户表)
|
|
|
+ }
|
|
|
+ String id = SnowFlake2.getId();
|
|
|
+ //5、保存附件信息
|
|
|
+ if (CollectionUtils.isNotEmpty(userDTO.getFiles())) {
|
|
|
+ saveFiles(userDTO.getFiles(), userDTO, id);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
+ 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);
|
|
|
+ this.insertWorkAttachment(i, userDTO);
|
|
|
+ j++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void deleteUser(UserDTO userDTO) {
|
|
|
baseMapper.deleteUserRole ( userDTO.getId ( ) );
|
|
|
baseMapper.deleteUserPost ( userDTO.getId ( ) );
|