package com.kiisoo.ic.department.service; import com.kiisoo.ic.department.entity.DepartmentDO; import com.kiisoo.ic.department.mapper.PrivilageDepartmentDOMapper; import com.kiisoo.ic.wx.service.QWMailListManageService; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.bean.WxCpDepart; import org.apache.commons.collections.CollectionUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; /** * @Description: 部门管理service * @Auther: yechenhao * @Date: 2020/4/7 0002 10:06 * @Version: v1 */ @Service public class DepartmentService { @Autowired private QWMailListManageService qwMailListManageService; @Autowired private PrivilageDepartmentDOMapper departmentDOMapper; @Transactional(rollbackFor = Exception.class) public Boolean addDepartment(DepartmentDO departmentDO) throws WxErrorException { //数据库创建部门(需要返回部门id) //成功则添加用户到企业微信 qwMailListManageService.addDepartment(departmentDO); return true; } @Transactional(rollbackFor = Exception.class) public Boolean syncDepartment() throws WxErrorException { //获取企业微信部门架构 List wxCpDeparts = qwMailListManageService.syncDepartment(); if (CollectionUtils.isNotEmpty(wxCpDeparts)){ wxCpDeparts.forEach(wxDept -> { DepartmentDO departmentDO = new DepartmentDO(); BeanUtils.copyProperties(wxDept,departmentDO); }); } // departmentDOMapper.insert(departmentDO); return true; } }