部门、成员修改

master
LegnaYet 6 years ago
parent b4f98d3d47
commit 4a14b6679a

@ -0,0 +1,47 @@
package com.kiisoo.ic.department.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
/**
* @Description: -
* @Auther: yechenhao
* @Date: 2020/4/7 0002 10:06
* @Version: v1
*/
@Data
@TableName("privilage_cp_user_department")
public class PrivilageCpUserDepartmentDO {
/**
* id
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* privilage_cp_user id userId
*/
private Long cpUserId;
/**
* id
*/
private Long departmentId;
/**
*
*/
private Integer order;
/**
*
*/
private Integer isLeader;
public PrivilageCpUserDepartmentDO() {}
public PrivilageCpUserDepartmentDO(Long cpUserId, Long departmentId, Integer order, Integer isLeader) {
this.cpUserId = cpUserId;
this.departmentId = departmentId;
this.order = order;
this.isLeader = isLeader;
}
}

@ -0,0 +1,10 @@
package com.kiisoo.ic.department.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kiisoo.ic.department.entity.PrivilageCpUserDepartmentDO;
import org.springframework.stereotype.Repository;
@Repository
public interface PrivilageCpUserDepartmentDOMapper extends BaseMapper<PrivilageCpUserDepartmentDO> {
}

@ -1,7 +1,9 @@
package com.kiisoo.ic.department.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kiisoo.ic.department.entity.DepartmentDO;
import com.kiisoo.ic.department.mapper.PrivilageDepartmentDOMapper;
import com.kiisoo.ic.employee.entity.PrivilageCpUserDO;
import com.kiisoo.ic.wx.service.QWMailListManageService;
import lombok.Synchronized;
import me.chanjar.weixin.common.error.WxErrorException;
@ -43,8 +45,8 @@ public class DepartmentService {
@Transactional(rollbackFor = Exception.class)
@Synchronized
public List<DepartmentDO> listDepartment() throws Exception {
Map<String,Object> params = new HashMap<>();
List<DepartmentDO> departmentDOS = departmentDOMapper.selectByMap(params);
QueryWrapper<DepartmentDO> params = new QueryWrapper<>();
List<DepartmentDO> departmentDOS = departmentDOMapper.selectList(params);
//转换为微信部门以使用递归分组
List<WxCpDepart> wxCpDeparts = new ArrayList<>();
if (CollectionUtils.isNotEmpty(departmentDOS)){

@ -45,6 +45,24 @@ public class EmployeeController extends BaseController {
}
}
/**
*
* @param employee
* @return
* @throws WxErrorException
*/
@RequestMapping(value = "sync",method = RequestMethod.GET)
@ResponseBody
public Map<String,Object> syncUser(){
try {
employeeService.syncUser();
return data(null);
}catch (Exception e){
log.error("添加用户失败",e);
return fail();
}
}
/**
*
* @param employee

@ -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

@ -9,12 +9,16 @@ import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.WxCpUserService;
import me.chanjar.weixin.cp.bean.WxCpDepart;
import me.chanjar.weixin.cp.bean.WxCpUser;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import static com.kiisoo.ic.department.constant.Constants.MAIN_DEPARTMENT_ID;
/**
* @Description: service
* @Auther: yechenhao
@ -39,6 +43,14 @@ public class QWMailListManageService {
BeanUtils.copyProperties(employeeDO,wxCpUser);
userService.create(wxCpUser);
}
/**
*
*/
public List<WxCpUser> syncUser() throws WxErrorException {
wxCpService = WxCpConfiguration.getCpService(applicationid);
WxCpUserService userService = wxCpService.getUserService();
return userService.listByDepartment(MAIN_DEPARTMENT_ID,true,0);
}
/**
*
*/

Loading…
Cancel
Save