部门、成员修改

master
LegnaYet 6 years ago
parent cd1e0baa2d
commit c53750465c

@ -1,50 +0,0 @@
package com.kiisoo.ic.department.controller;
import com.kiisoo.ic.common.BaseController;
import com.kiisoo.ic.department.entity.DepartmentDO;
import com.kiisoo.ic.department.service.DepartmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.util.Map;
/**
* @Description: controller
* @Auther: yechenhao
* @Date: 2020/4/7 0002 10:06
* @Version: v1
*/
@Controller
@RequestMapping("/department")
@Slf4j
public class DepartmentConreoller extends BaseController {
@Autowired
private DepartmentService departmentService;
@RequestMapping(value = "add",method = RequestMethod.POST)
public Map<String,Object> addDepartment(@RequestBody DepartmentDO departmentDO){
try {
Boolean hasAdd = departmentService.addDepartment(departmentDO);
return data(hasAdd);
}catch (Exception e){
log.error("添加部门失败",e);
return fail();
}
}
@RequestMapping(value = "sync",method = RequestMethod.GET)
public Map<String,Object> syncDepartment(){
try {
Boolean hasAdd = departmentService.syncDepartment();
return data(hasAdd);
}catch (Exception e){
log.error("添加部门失败",e);
return fail();
}
}
}

@ -0,0 +1,110 @@
package com.kiisoo.ic.department.controller;
import com.kiisoo.ic.common.BaseController;
import com.kiisoo.ic.department.entity.DepartmentDO;
import com.kiisoo.ic.department.service.DepartmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* @Description: controller
* @Auther: yechenhao
* @Date: 2020/4/7 0002 10:06
* @Version: v1
*/
@Controller
@RequestMapping("/department")
@Slf4j
public class DepartmentController extends BaseController {
@Autowired
private DepartmentService departmentService;
/**
*
* @param
* @return
* @throws Exception
*/
@RequestMapping(value = "list",method = RequestMethod.POST)
@ResponseBody
public Map<String,Object> listDepartment(){
try {
Boolean hasAdd = departmentService.listDepartment();
return data(hasAdd);
}catch (Exception e){
log.error("添加部门失败",e);
return fail();
}
}
/**
*
* @param departmentDO
* @return
* @throws Exception
*/
@RequestMapping(value = "add",method = RequestMethod.POST)
@ResponseBody
public Map<String,Object> addDepartment(@RequestBody DepartmentDO departmentDO){
try {
Boolean hasAdd = departmentService.addDepartment(departmentDO);
return data(hasAdd);
}catch (Exception e){
log.error("添加部门失败",e);
return fail();
}
}
/**
*
* @param departmentDO
* @return
* @throws Exception
*/
@RequestMapping(value = "update",method = RequestMethod.POST)
@ResponseBody
public Map<String,Object> updateDepartment(@RequestBody DepartmentDO departmentDO){
try {
Boolean hasUpdate = departmentService.updateDepartment(departmentDO);
return data(hasUpdate);
}catch (Exception e){
log.error("修改部门失败",e);
return fail();
}
}
/**
*
* @param departmentId id
* @return
* @throws Exception
*/
@RequestMapping(value = "delete",method = RequestMethod.POST)
@ResponseBody
public Map<String,Object> deleteDepartment(@RequestParam("departmentId") Long departmentId){
try {
Boolean hasDel = departmentService.deleteDepartment(departmentId);
return data(hasDel);
}catch (Exception e){
log.error("删除部门失败",e);
return fail();
}
}
@RequestMapping(value = "sync",method = RequestMethod.GET)
@ResponseBody
public Map<String,Object> syncDepartment(){
try {
Boolean hasSync = departmentService.syncDepartment();
return data(hasSync);
}catch (Exception e){
log.error("添加部门失败",e);
return fail();
}
}
}

@ -6,4 +6,9 @@ import org.springframework.stereotype.Repository;
@Repository
public interface PrivilageDepartmentDOMapper extends BaseMapper<DepartmentDO> {
/**
* id
* @return
*/
Long selectMaxDepartmentId();
}

@ -3,6 +3,7 @@ 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 lombok.Synchronized;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpDepart;
import org.apache.commons.collections.CollectionUtils;
@ -12,7 +13,9 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.kiisoo.ic.department.constant.Constants.*;
@ -31,16 +34,97 @@ public class DepartmentService {
@Autowired
private PrivilageDepartmentDOMapper departmentDOMapper;
/**
*
* @param departmentDO
* @return
* @throws Exception
*/
@Transactional(rollbackFor = Exception.class)
public Boolean addDepartment(DepartmentDO departmentDO) throws WxErrorException {
//数据库创建部门需要返回部门id
@Synchronized
public List<DepartmentDO> listDepartment() throws Exception {
Map<String,Object> params = new HashMap<>();
List<DepartmentDO> departmentDOS = departmentDOMapper.selectByMap(params);
//转换为微信部门以使用递归分组
List<WxCpDepart> wxCpDeparts = new ArrayList<>();
if (CollectionUtils.isNotEmpty(departmentDOS)){
departmentDOS.forEach(department -> {
WxCpDepart wxCpDepart = new WxCpDepart();
BeanUtils.copyProperties(department,wxCpDepart);
wxCpDepart.setOrder(department.getOrderNum());
wxCpDeparts.add(wxCpDepart);
});
}
List<DepartmentDO> results = new ArrayList<>();
groupByDepartments(wxCpDeparts,results);
return results;
}
/**
*
* @param departmentDO
* @return
* @throws Exception
*/
@Transactional(rollbackFor = Exception.class)
@Synchronized
public Boolean addDepartment(DepartmentDO departmentDO) throws Exception {
//数据库创建部门需要返回部门id
DepartmentDO parentDep = departmentDOMapper.selectById(departmentDO.getParentId());
Long maxId = departmentDOMapper.selectMaxDepartmentId();
departmentDO.setLevel(parentDep.getLevel()+1);
departmentDO.setId(maxId+1);
int insert = departmentDOMapper.insert(departmentDO);
if (insert == 0){
throw new Exception("创建部门service失败");
}
//成功则添加用户到企业微信
qwMailListManageService.addDepartment(departmentDO);
return true;
}
/**
*
* @param departmentDO
* @return
* @throws Exception
*/
@Transactional(rollbackFor = Exception.class)
public Boolean updateDepartment(DepartmentDO departmentDO) throws Exception {
//数据库创建部门需要返回部门id
DepartmentDO parentDep = departmentDOMapper.selectById(departmentDO.getParentId());
departmentDO.setLevel(parentDep.getLevel()+1);
int update = departmentDOMapper.updateById(departmentDO);
if (update == 0){
throw new Exception("修改部门service失败");
}
//成功则添加用户到企业微信
qwMailListManageService.updateDepartment(departmentDO);
return true;
}
/**
*
* @param departmentId id
* @return
* @throws Exception
*/
@Transactional(rollbackFor = Exception.class)
public Boolean deleteDepartment(Long departmentId) throws Exception {
//数据库创建部门需要返回部门id
int delete = departmentDOMapper.deleteById(departmentId);
if (delete == 0){
throw new Exception("删除部门service失败");
}
//todo 删除部门后操作员工
//成功则添加用户到企业微信
qwMailListManageService.deleteDepartment(departmentId);
return true;
}
//-----------------------------同步部门------------------------start-----------------------------
@Transactional(rollbackFor = Exception.class)
public Boolean syncDepartment() throws WxErrorException {
//获取企业微信部门架构
@ -112,10 +196,10 @@ public class DepartmentService {
/**
*
* @param level
* @param hasParents
* @param departmentDO
* @param wxDept
* @param level
* @param hasParents
* @param departmentDO
* @param wxDept
*/
private Boolean recursionLevel(int level,Boolean hasParents,DepartmentDO departmentDO,WxCpDepart wxDept){
int nowLevel = ++level;
@ -149,7 +233,7 @@ public class DepartmentService {
/**
*
* @param departmentDO
* @param departmentDO
*/
private void recursionInsertDepartment(List<DepartmentDO> departmentDO){
if (CollectionUtils.isNotEmpty(departmentDO)){
@ -167,4 +251,7 @@ public class DepartmentService {
});
}
}
//-----------------------------同步部门------------------------end-----------------------------
}

@ -1,39 +0,0 @@
package com.kiisoo.ic.employee.controller;
import com.kiisoo.ic.common.BaseController;
import com.kiisoo.ic.employee.entity.EmployeeDO;
import com.kiisoo.ic.employee.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.util.Map;
/**
* @Description: controller
* @Auther: yechenhao
* @Date: 2020/4/7 0002 10:06
* @Version: v1
*/
@Controller
@RequestMapping("/user")
@Slf4j
public class EmployeeConreoller extends BaseController {
@Autowired
private EmployeeService employeeService;
@RequestMapping(value = "add",method = RequestMethod.POST)
public Map<String,Object> addUser(@RequestBody EmployeeDO employee){
try {
Boolean hasAdd = employeeService.addUser(employee);
return data(hasAdd);
}catch (Exception e){
log.error("添加用户失败",e);
return fail();
}
}
}

@ -0,0 +1,101 @@
package com.kiisoo.ic.employee.controller;
import com.kiisoo.ic.common.BaseController;
import com.kiisoo.ic.employee.entity.EmployeeDO;
import com.kiisoo.ic.employee.entity.PrivilageCpUserDO;
import com.kiisoo.ic.employee.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* @Description: controller
* @Auther: yechenhao
* @Date: 2020/4/7 0002 10:06
* @Version: v1
*/
@Controller
@RequestMapping("/user")
@Slf4j
public class EmployeeController extends BaseController {
@Autowired
private EmployeeService employeeService;
/**
*
* @param employee
* @return
* @throws WxErrorException
*/
@RequestMapping(value = "list",method = RequestMethod.POST)
@ResponseBody
public Map<String,Object> listUser(){
try {
List<PrivilageCpUserDO> privilageCpUserDOS = employeeService.listUser();
return data(privilageCpUserDOS);
}catch (Exception e){
log.error("添加用户失败",e);
return fail();
}
}
/**
*
* @param employee
* @return
* @throws WxErrorException
*/
@RequestMapping(value = "add",method = RequestMethod.POST)
@ResponseBody
public Map<String,Object> addUser(@RequestBody EmployeeDO employee){
try {
Boolean hasAdd = employeeService.addUser(employee);
return data(hasAdd);
}catch (Exception e){
log.error("添加用户失败",e);
return fail();
}
}
/**
*
* @param employee
* @return
* @throws WxErrorException
*/
@RequestMapping(value = "update",method = RequestMethod.POST)
@ResponseBody
public Map<String,Object> updateUser(@RequestBody EmployeeDO employee){
try {
Boolean hasAdd = employeeService.updateUser(employee);
return data(hasAdd);
}catch (Exception e){
log.error("修改用户失败",e);
return fail();
}
}
/**
*
* @param employee
* @return
* @throws WxErrorException
*/
@RequestMapping(value = "add",method = RequestMethod.POST)
@ResponseBody
public Map<String,Object> deleteUser(@RequestParam("cpUserId") Long cpUserId){
try {
Boolean hasAdd = employeeService.deleteUser(cpUserId);
return data(hasAdd);
}catch (Exception e){
log.error("删除用户失败",e);
return fail();
}
}
}

@ -115,4 +115,19 @@ public class PrivilageCpUserDO {
this.mobile = mobile;
}
public Integer getGender() {
return gender;
}
public void setGender(Integer gender) {
this.gender = gender;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
}

@ -6,10 +6,16 @@ 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 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.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Description: service
* @Auther: yechenhao
@ -25,14 +31,95 @@ public class EmployeeService {
@Autowired
private PrivilageCpUserDOMapper privilageCpUserDOMapper;
/**
*
* @param employee
* @return
* @throws WxErrorException
*/
@Transactional(rollbackFor = Exception.class)
public Boolean addUser(EmployeeDO employee) throws WxErrorException {
public List<PrivilageCpUserDO> listUser() {
Map<String, Object> params = new HashMap<>();
List<PrivilageCpUserDO> privilageCpUserDOS = privilageCpUserDOMapper.selectByMap(params);
return privilageCpUserDOS;
}
/**
*
* @param employee
* @return
* @throws WxErrorException
*/
@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);
Map<String, Object> cuUserIdParams = new HashMap<>();
mobileParams.put("cpUserId",employee.getUserId());
List<PrivilageCpUserDO> cuUserIdUser = privilageCpUserDOMapper.selectByMap(cuUserIdParams);
if (CollectionUtils.isEmpty(mobileCpUser) && CollectionUtils.isEmpty(cuUserIdUser)){
PrivilageCpUserDO privilageCpUserDO = new PrivilageCpUserDO();
BeanUtils.copyProperties(employee,privilageCpUserDO);
privilageCpUserDO.setCpUserId(employee.getUserId());
int insert = privilageCpUserDOMapper.insert(privilageCpUserDO);
if (insert == 0){
throw new Exception("创建成员失败");
}
//成功则添加用户到企业微信
qwMailListManageService.addUser(employee);
return true;
}
return false;
}
/**
*
* @param employee
* @return
* @throws WxErrorException
*/
@Transactional(rollbackFor = Exception.class)
public Boolean updateUser(EmployeeDO employee) throws Exception {
PrivilageCpUserDO privilageCpUserDO = new PrivilageCpUserDO();
BeanUtils.copyProperties(employee,privilageCpUserDO);
privilageCpUserDO.setCpUserId(employee.getUserId());
int update = privilageCpUserDOMapper.updateById(privilageCpUserDO);
if (update == 0){
throw new Exception("修改成员失败");
}
//成功则添加用户到企业微信
qwMailListManageService.addUser(employee);
qwMailListManageService.updateUser(employee);
return true;
}
/**
*
* @param employee
* @return
* @throws WxErrorException
*/
@Transactional(rollbackFor = Exception.class)
public Boolean deleteUser(Long cpUserId) throws Exception {
PrivilageCpUserDO privilageCpUserDO = privilageCpUserDOMapper.selectById(cpUserId);
if (privilageCpUserDO == null){
return false;
}
int delete = privilageCpUserDOMapper.deleteById(cpUserId);
if (delete == 0){
throw new Exception("删除成员失败");
}
//成功则添加用户到企业微信
qwMailListManageService.deleteUser(privilageCpUserDO.getCpUserId());
return true;
}

@ -33,12 +33,30 @@ public class QWMailListManageService {
*
*/
public void addUser(EmployeeDO employeeDO) throws WxErrorException {
wxCpService = WxCpConfiguration.getCpService(1);
wxCpService = WxCpConfiguration.getCpService(applicationid);
WxCpUserService userService = wxCpService.getUserService();
WxCpUser wxCpUser = new WxCpUser();
BeanUtils.copyProperties(employeeDO,wxCpUser);
userService.create(wxCpUser);
}
/**
*
*/
public void updateUser(EmployeeDO employeeDO) throws WxErrorException {
wxCpService = WxCpConfiguration.getCpService(applicationid);
WxCpUserService userService = wxCpService.getUserService();
WxCpUser wxCpUser = new WxCpUser();
BeanUtils.copyProperties(employeeDO,wxCpUser);
userService.update(wxCpUser);
}
/**
*
*/
public void deleteUser(String userId) throws WxErrorException {
wxCpService = WxCpConfiguration.getCpService(applicationid);
WxCpUserService userService = wxCpService.getUserService();
userService.delete(userId);
}
/**
*
@ -51,11 +69,32 @@ public class QWMailListManageService {
departmentService.create(wxCpDepart);
}
/**
*
*/
public void updateDepartment(DepartmentDO departmentDO) throws WxErrorException {
wxCpService = WxCpConfiguration.getCpService(applicationid);
WxCpDepartmentService departmentService = wxCpService.getDepartmentService();
WxCpDepart wxCpDepart = new WxCpDepart();
BeanUtils.copyProperties(departmentDO,wxCpDepart);
departmentService.update(wxCpDepart);
}
/**
*
*/
public void deleteDepartment(Long departmentId) throws WxErrorException {
wxCpService = WxCpConfiguration.getCpService(applicationid);
WxCpDepartmentService departmentService = wxCpService.getDepartmentService();
departmentService.delete(departmentId);
//todo 删除部门后操作员工
}
/**
*
*/
public List<WxCpDepart> syncDepartment() throws WxErrorException {
wxCpService = WxCpConfiguration.getCpService(1);
wxCpService = WxCpConfiguration.getCpService(applicationid);
WxCpDepartmentService departmentService = wxCpService.getDepartmentService();
return departmentService.list(null);
}

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.kiisoo.ic.department.mapper.PrivilageDepartmentDOMapper">
<select id="selectMaxDepartmentId" resultType="java.lang.Long">
select max(id) from privilage_department
</select>
</mapper>
Loading…
Cancel
Save