|
|
|
@ -1,11 +1,14 @@
|
|
|
|
|
package com.kiisoo.ic.employee.service;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.kiisoo.ic.department.entity.PrivilageCpUserDepartmentDO;
|
|
|
|
|
import com.kiisoo.ic.department.mapper.PrivilageCpUserDepartmentDOMapper;
|
|
|
|
|
import com.kiisoo.ic.employee.entity.EmployeeDO;
|
|
|
|
|
import com.kiisoo.ic.employee.entity.PrivilageCpUserDO;
|
|
|
|
|
import com.kiisoo.ic.employee.mapper.PrivilageCpUserDOMapper;
|
|
|
|
|
import com.kiisoo.ic.wx.service.QWMailListManageService;
|
|
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
|
|
import me.chanjar.weixin.cp.bean.WxCpUser;
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
@ -31,16 +34,19 @@ public class EmployeeService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private PrivilageCpUserDOMapper privilageCpUserDOMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private PrivilageCpUserDepartmentDOMapper privilageCpUserDepartmentDOMapper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增成员
|
|
|
|
|
* 查询成员
|
|
|
|
|
* @param employee 成员实体
|
|
|
|
|
* @return
|
|
|
|
|
* @throws WxErrorException
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public List<PrivilageCpUserDO> listUser() {
|
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
|
|
List<PrivilageCpUserDO> privilageCpUserDOS = privilageCpUserDOMapper.selectByMap(params);
|
|
|
|
|
QueryWrapper<PrivilageCpUserDO> params = new QueryWrapper<>();
|
|
|
|
|
List<PrivilageCpUserDO> privilageCpUserDOS = privilageCpUserDOMapper.selectList(params);
|
|
|
|
|
return privilageCpUserDOS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -53,13 +59,13 @@ public class EmployeeService {
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Boolean addUser(EmployeeDO employee) throws Exception {
|
|
|
|
|
//排重
|
|
|
|
|
Map<String, Object> mobileParams = new HashMap<>();
|
|
|
|
|
mobileParams.put("mobile",employee.getMobile());
|
|
|
|
|
List<PrivilageCpUserDO> mobileCpUser = privilageCpUserDOMapper.selectByMap(mobileParams);
|
|
|
|
|
QueryWrapper<PrivilageCpUserDO> mobileParams = new QueryWrapper<>();
|
|
|
|
|
mobileParams.eq("mobile",employee.getMobile());
|
|
|
|
|
List<PrivilageCpUserDO> mobileCpUser = privilageCpUserDOMapper.selectList(mobileParams);
|
|
|
|
|
|
|
|
|
|
Map<String, Object> cuUserIdParams = new HashMap<>();
|
|
|
|
|
mobileParams.put("cpUserId",employee.getUserId());
|
|
|
|
|
List<PrivilageCpUserDO> cuUserIdUser = privilageCpUserDOMapper.selectByMap(cuUserIdParams);
|
|
|
|
|
QueryWrapper<PrivilageCpUserDO> cuUserIdParams = new QueryWrapper<>();
|
|
|
|
|
mobileParams.eq("cp_user_id",employee.getUserId());
|
|
|
|
|
List<PrivilageCpUserDO> cuUserIdUser = privilageCpUserDOMapper.selectList(cuUserIdParams);
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(mobileCpUser) && CollectionUtils.isEmpty(cuUserIdUser)){
|
|
|
|
|
PrivilageCpUserDO privilageCpUserDO = new PrivilageCpUserDO();
|
|
|
|
@ -78,6 +84,55 @@ public class EmployeeService {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 同步成员
|
|
|
|
|
* @param employee 成员实体
|
|
|
|
|
* @return
|
|
|
|
|
* @throws WxErrorException
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void syncUser() throws Exception {
|
|
|
|
|
List<WxCpUser> wxCpUsers = qwMailListManageService.syncUser();
|
|
|
|
|
if (CollectionUtils.isNotEmpty(wxCpUsers)){
|
|
|
|
|
wxCpUsers.forEach(wxCpUser -> {
|
|
|
|
|
//排重
|
|
|
|
|
QueryWrapper<PrivilageCpUserDO> mobileParams = new QueryWrapper<>();
|
|
|
|
|
mobileParams.eq("mobile",wxCpUser.getMobile());
|
|
|
|
|
List<PrivilageCpUserDO> mobileCpUser = privilageCpUserDOMapper.selectList(mobileParams);
|
|
|
|
|
|
|
|
|
|
QueryWrapper<PrivilageCpUserDO> cuUserIdParams = new QueryWrapper<>();
|
|
|
|
|
mobileParams.eq("cp_user_id",wxCpUser.getUserId());
|
|
|
|
|
List<PrivilageCpUserDO> cuUserIdUser = privilageCpUserDOMapper.selectList(cuUserIdParams);
|
|
|
|
|
|
|
|
|
|
PrivilageCpUserDO privilageCpUserDO = new PrivilageCpUserDO();
|
|
|
|
|
BeanUtils.copyProperties(wxCpUser,privilageCpUserDO);
|
|
|
|
|
privilageCpUserDO.setCpUserId(wxCpUser.getUserId());
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(mobileCpUser) && CollectionUtils.isEmpty(cuUserIdUser)){
|
|
|
|
|
//添加用户
|
|
|
|
|
int insert = privilageCpUserDOMapper.insert(privilageCpUserDO);
|
|
|
|
|
}else{
|
|
|
|
|
privilageCpUserDO.setId(cuUserIdUser.get(0).getId());
|
|
|
|
|
//修改用户
|
|
|
|
|
int update = privilageCpUserDOMapper.updateById(privilageCpUserDO);
|
|
|
|
|
//维护部门关系——删除原有部门关系
|
|
|
|
|
QueryWrapper<PrivilageCpUserDepartmentDO> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
queryWrapper.eq("cp_user_id",cuUserIdUser.get(0).getId());
|
|
|
|
|
privilageCpUserDepartmentDOMapper.delete(queryWrapper);
|
|
|
|
|
}
|
|
|
|
|
Long[] departIds = wxCpUser.getDepartIds();
|
|
|
|
|
Integer[] orders = wxCpUser.getOrders();
|
|
|
|
|
Integer[] isLeaderInDept = wxCpUser.getIsLeaderInDept();
|
|
|
|
|
|
|
|
|
|
for (int i = 0;i<departIds.length; i++){
|
|
|
|
|
PrivilageCpUserDepartmentDO relation = new PrivilageCpUserDepartmentDO(privilageCpUserDO.getId(),departIds[i],orders[i],isLeaderInDept[i]);
|
|
|
|
|
privilageCpUserDepartmentDOMapper.insert(relation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改成员
|
|
|
|
|
* @param employee 成员实体
|
|
|
|
|