| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.domain.entity.Custom; |
| | | import com.ruoyi.common.core.domain.entity.User; |
| | | import com.ruoyi.common.core.dto.PersonDto; |
| | | import com.ruoyi.common.utils.QueryWrappers; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.system.mapper.UserMapper; |
| | | import com.ruoyi.system.service.CustomService; |
| | | import com.ruoyi.system.service.UserService; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.DigestUtils; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 用户信息表 |
| | |
| | | @Service |
| | | public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService { |
| | | |
| | | @Autowired |
| | | private CustomService customService; |
| | | |
| | | /** |
| | | * 根据条件获取用户列表 |
| | | * @param user |
| | | * @param type |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<User> selectUserCondition(User user, String type) { |
| | | return baseMapper.selectUserCondition(QueryWrappers.queryWrappers(user), type); |
| | | } |
| | | |
| | | /** |
| | | * 获取当前登录的客户信息 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public User getUserNow() { |
| | | return baseMapper.getUserNow(SecurityUtils.getUserId().intValue()); |
| | | } |
| | | |
| | | /** |
| | | * 获取当前登录用户部门 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public String selectUserDepartmentLimsName() { |
| | | return baseMapper.selectUserDepartmentLimsName(SecurityUtils.getUserId().intValue()); |
| | | } |
| | | |
| | | @Override |
| | | public int upUserDepardLimsId(String ids, String id) { |
| | | List<Integer> userIds = JSON.parseArray(ids, Integer.class); |
| | | return baseMapper.update(null, Wrappers.<User>lambdaUpdate().in(User::getId, userIds).set(User::getDepartLimsId, id).set(User::getUpdateTime, LocalDateTime.now()).set(User::getUpdateBy,SecurityUtils.getLoginUser().getUsername())); |
| | | } |
| | | |
| | | @Override |
| | | public int delUserDepardLimsId(Integer id) { |
| | | return baseMapper.update(null, Wrappers.<User>lambdaUpdate().eq(User::getId, id).set(User::getDepartLimsId, null).set(User::getUpdateTime, LocalDateTime.now()).set(User::getUpdateBy, SecurityUtils.getUsername())); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int addPersonUser(PersonDto personDto) { |
| | | personDto.getPerson().forEach(person -> { |
| | | User user = baseMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getAccount, person.getEmployeeID())); |
| | | String companyName = personDto.getCompany().stream().filter(a -> a.getCompanyId().equals(person.getCompanyId())).findFirst().get().getCompanyName(); |
| | | Custom custom = customService.getCustomId(companyName); |
| | | if (BeanUtil.isEmpty(user)) { |
| | | user = new User(); |
| | | user.setName(person.getName()); |
| | | user.setNameEn("not write"); |
| | | user.setAccount(person.getEmployeeID()); |
| | | user.setPhone(person.getPhoneNumber()); |
| | | user.setEmail(person.getCompanyEmail()); |
| | | user.setIsCustom(person.getCompanyId().equals("SC2463") ? 0 : 1); |
| | | // user.setPassword(DigestUtils.md5DigestAsHex(headerToken.getPassword(person.getEmployeeID()).getBytes())); |
| | | user.setPassword(SecurityUtils.encryptPassword("zttZTT123!")); |
| | | user.setCompany(BeanUtil.isNotEmpty(custom) ? (custom.getId() + "") : companyName); |
| | | // user.setAddress("未填写"); |
| | | // user.setRoleId(personDto.getRoleId() > 10000 ? 0 : personDto.getRoleId()); |
| | | user.setCompanyId(person.getCompanyId()); |
| | | baseMapper.insert(user); |
| | | } else { |
| | | user.setName(person.getName()); |
| | | user.setPhone(person.getPhoneNumber()); |
| | | user.setEmail(person.getCompanyEmail()); |
| | | user.setIsCustom(0); |
| | | user.setCompany(BeanUtil.isNotEmpty(custom) ? (custom.getId() + "") : companyName); |
| | | // user.setCreateUser(null); |
| | | // user.setCreateTime(null); |
| | | // user.setUpdateUser(null); |
| | | // user.setUpdateTime(null); |
| | | user.setCompanyId(person.getCompanyId()); |
| | | baseMapper.updateById(user); |
| | | } |
| | | }); |
| | | return 1; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, List<Map<String, Object>>> getLaboratoryPersonList() { |
| | | //查询通信和电力下的人员信息 |
| | | //查询当前登录人员的架构 |
| | | //判断全部,个人,组织的权限 |
| | | User user = baseMapper.selectById(SecurityUtils.getUserId());//当前登录的人 |
| | | //获取当前人所属实验室id |
| | | String laboratory = ""; |
| | | String departLimsId = user.getDepartLimsId(); |
| | | if (ObjectUtils.isNotEmpty(departLimsId)) { |
| | | String[] split = departLimsId.split(","); |
| | | //查询对应架构名称(通信实验室,电力实验室,检测办) |
| | | String departLims = baseMapper.seldepLimsId(Integer.parseInt(split[split.length - 1])); |
| | | if (departLims.contains("实验室")) { |
| | | laboratory = departLims; |
| | | } |
| | | } |
| | | return baseMapper.getLaboratoryPersonList(laboratory).stream().collect(Collectors.groupingBy(m->m.get("depName").toString())); |
| | | } |
| | | } |
| | | |