| | |
| | | package com.yuanchu.mom.service.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.yuanchu.mom.common.GetLook; |
| | | import com.yuanchu.mom.common.PrintChina; |
| | | import com.yuanchu.mom.dto.PersonDto; |
| | | import com.yuanchu.mom.dto.UserPageDto; |
| | | import com.yuanchu.mom.exception.ErrorException; |
| | | import com.yuanchu.mom.mapper.DepartmentsMapper; |
| | | import com.yuanchu.mom.mapper.UserMapper; |
| | | import com.yuanchu.mom.pojo.Departments; |
| | | import com.yuanchu.mom.pojo.User; |
| | | import com.yuanchu.mom.service.UserService; |
| | | import com.yuanchu.mom.utils.Jwt; |
| | | import com.yuanchu.mom.util.HeaderToken; |
| | | import com.yuanchu.mom.utils.QueryWrappers; |
| | | import com.yuanchu.mom.vo.Result; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.DigestUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | | |
| | | @Service |
| | | public class UserServiceImp implements UserService { |
| | |
| | | @Resource |
| | | UserMapper userMapper; |
| | | @Resource |
| | | Jwt jwt; |
| | | @Resource |
| | | private GetLook getLook; |
| | | |
| | | @Resource |
| | | private DepartmentsMapper departmentsMapper; |
| | | |
| | | @Resource |
| | | private HeaderToken headerToken; |
| | | |
| | | @Override |
| | | public User selectUserByPwd(String account, String password) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> selectPersonnelOverview(IPage<UserPageDto> page, UserPageDto user) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("head", PrintChina.printChina(UserPageDto.class)); |
| | | Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("selectUserList"); |
| | | if (map1.get("look") == 1) user.setCreateUser(map1.get("userId")); |
| | | map.put("body", userMapper.selectPersonnelOverview(page, QueryWrappers.queryWrappers(user))); |
| | | return map; |
| | | } |
| | | |
| | | @Override |
| | | public int updateUser(User user) { |
| | | user.setDepartId("1,"+user.getDepartId()); |
| | | user.setDepartId("1," + user.getDepartId()); |
| | | return userMapper.updateById(user); |
| | | } |
| | | |
| | | @Override |
| | | public int addUser(User user) { |
| | | user.setDepartId("1,"+user.getDepartId()); |
| | | user.setDepartId("1"); |
| | | return userMapper.insert(user); |
| | | } |
| | | |
| | |
| | | return userMapper.updateById(user); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int addPersonUser(PersonDto personDto) { |
| | | AtomicReference<String> departId = new AtomicReference<>(""); |
| | | AtomicReference<String> companyName = new AtomicReference<>(); |
| | | personDto.getCompany().forEach(company -> { |
| | | Departments department = departmentsMapper.selectOne(Wrappers.<Departments>lambdaQuery().eq(Departments::getCompanyId, company.getCompanyId())); |
| | | if (BeanUtil.isEmpty(department)) { |
| | | department = new Departments(); |
| | | department.setName(company.getCompanyName()); |
| | | department.setCompanyId(company.getCompanyId()); |
| | | Departments department2 = departmentsMapper.selectOne(Wrappers.<Departments>lambdaQuery().eq(Departments::getCompanyId, company.getParentCompanyId())); |
| | | if (BeanUtil.isEmpty(department2)) { |
| | | department.setFatherId(1); |
| | | } else { |
| | | department.setFatherId(department2.getId()); |
| | | } |
| | | departmentsMapper.insert(department); |
| | | } |
| | | departId.set(departId.get() + department.getId() + ","); |
| | | companyName.set(department.getName()); |
| | | }); |
| | | personDto.getPerson().forEach(person -> { |
| | | User user = userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getAccount, person.getEmployeeID())); |
| | | 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.setDepartId(departId.get()); |
| | | // user.setPassword(DigestUtils.md5DigestAsHex(headerToken.getPassword(person.getEmployeeID()).getBytes())); |
| | | user.setPassword(DigestUtils.md5DigestAsHex("123456".getBytes())); |
| | | user.setCompany(companyName.get()); |
| | | user.setAddress("未填写"); |
| | | userMapper.insert(user); |
| | | } else { |
| | | user.setName(person.getName()); |
| | | user.setPhone(person.getPhoneNumber()); |
| | | user.setEmail(person.getCompanyEmail()); |
| | | user.setIsCustom(person.getCompanyId().equals("SC2463") ? 0 : 1); |
| | | user.setDepartId(departId.get()); |
| | | user.setCompany(companyName.get()); |
| | | user.setCreateUser(null); |
| | | user.setCreateTime(null); |
| | | user.setUpdateUser(null); |
| | | user.setUpdateTime(null); |
| | | userMapper.updateById(user); |
| | | } |
| | | }); |
| | | return 1; |
| | | } |
| | | |
| | | @Override |
| | | public int upUserDepardLimsId(String ids, String id) { |
| | | List<Integer> userIds = JSON.parseArray(ids, Integer.class); |
| | | return userMapper.update(null, Wrappers.<User>lambdaUpdate().in(User::getId, userIds).set(User::getDepartLimsId, id).set(User::getUpdateTime, LocalDateTime.now()).set(User::getUpdateUser, getLook.selectPowerByMethodAndUserId(null).get("userId"))); |
| | | } |
| | | |
| | | @Override |
| | | public int delUserDepardLimsId(Integer id) { |
| | | return userMapper.update(null, Wrappers.<User>lambdaUpdate().eq(User::getId, id).set(User::getDepartLimsId, null).set(User::getUpdateTime, LocalDateTime.now()).set(User::getUpdateUser, getLook.selectPowerByMethodAndUserId(null).get("userId"))); |
| | | } |
| | | } |