员工部门增加
parent
01cd05faec
commit
95b336ef50
@ -0,0 +1,51 @@
|
|||||||
|
package com.kiisoo.ic.config;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import lombok.val;
|
||||||
|
import me.chanjar.weixin.common.api.WxConsts;
|
||||||
|
import me.chanjar.weixin.cp.api.WxCpService;
|
||||||
|
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
|
||||||
|
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
|
||||||
|
import me.chanjar.weixin.cp.constant.WxCpConsts;
|
||||||
|
import me.chanjar.weixin.cp.message.WxCpMessageRouter;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Binary Wang(https://github.com/binarywang)
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@EnableConfigurationProperties(WxCpProperties.class)
|
||||||
|
public class WxCpConfiguration {
|
||||||
|
private WxCpProperties properties;
|
||||||
|
|
||||||
|
private static Map<Integer, WxCpMessageRouter> routers = Maps.newHashMap();
|
||||||
|
private static Map<Integer, WxCpService> cpServices = Maps.newHashMap();
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public WxCpConfiguration(WxCpProperties properties) {
|
||||||
|
this.properties = properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WxCpService getCpService(Integer agentId) {
|
||||||
|
return cpServices.get(agentId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void initServices() {
|
||||||
|
cpServices = this.properties.getAppConfigs().stream().map(a -> {
|
||||||
|
val configStorage = new WxCpDefaultConfigImpl();
|
||||||
|
configStorage.setCorpId(this.properties.getCorpId());
|
||||||
|
configStorage.setAgentId(a.getAgentId());
|
||||||
|
configStorage.setCorpSecret(a.getSecret());
|
||||||
|
val service = new WxCpServiceImpl();
|
||||||
|
service.setWxCpConfigStorage(configStorage);
|
||||||
|
return service;
|
||||||
|
}).collect(Collectors.toMap(service -> service.getWxCpConfigStorage().getAgentId(), a -> a));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
package com.kiisoo.ic.config;
|
||||||
|
|
||||||
|
import com.kiisoo.ic.utils.JsonUtils;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Binary Wang(https://github.com/binarywang)
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ConfigurationProperties(prefix = "wechat.cp")
|
||||||
|
public class WxCpProperties {
|
||||||
|
/**
|
||||||
|
* 设置微信企业号的corpId
|
||||||
|
*/
|
||||||
|
private String corpId;
|
||||||
|
|
||||||
|
private List<AppConfig> appConfigs;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public static class AppConfig {
|
||||||
|
/**
|
||||||
|
* 设置微信企业应用的AgentId
|
||||||
|
*/
|
||||||
|
private Integer agentId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置微信企业应用的Secret
|
||||||
|
*/
|
||||||
|
private String secret;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置微信企业号的token
|
||||||
|
*/
|
||||||
|
private String token;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置微信企业号的EncodingAESKey
|
||||||
|
*/
|
||||||
|
private String aesKey;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return JsonUtils.toJson(this);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.kiisoo.ic.department.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 DepartmentConreoller 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,21 @@
|
|||||||
|
package com.kiisoo.ic.department.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import me.chanjar.weixin.cp.bean.Gender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 员工对象
|
||||||
|
* @Auther: yechenhao
|
||||||
|
* @Date: 2020/4/7 0002 10:06
|
||||||
|
* @Version: v1
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class DepartmentDO {
|
||||||
|
/**
|
||||||
|
* 数据库实体id和企业微信部门id
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
private Long parentId;
|
||||||
|
private Long order;
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package com.kiisoo.ic.department.service;
|
||||||
|
|
||||||
|
import com.kiisoo.ic.employee.entity.EmployeeDO;
|
||||||
|
import com.kiisoo.ic.wx.service.QWMailListManageService;
|
||||||
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 用户管理service
|
||||||
|
* @Auther: yechenhao
|
||||||
|
* @Date: 2020/4/7 0002 10:06
|
||||||
|
* @Version: v1
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class EmployeeService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private QWMailListManageService qwMailListManageService;
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public Boolean addUser(EmployeeDO employee) throws WxErrorException {
|
||||||
|
//数据库创建用户
|
||||||
|
|
||||||
|
//数据库创建登录account
|
||||||
|
|
||||||
|
//成功则添加用户到企业微信
|
||||||
|
qwMailListManageService.addUser(employee);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
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,33 @@
|
|||||||
|
package com.kiisoo.ic.employee.service;
|
||||||
|
|
||||||
|
import com.kiisoo.ic.employee.entity.EmployeeDO;
|
||||||
|
import com.kiisoo.ic.wx.service.QWMailListManageService;
|
||||||
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 用户管理service
|
||||||
|
* @Auther: yechenhao
|
||||||
|
* @Date: 2020/4/7 0002 10:06
|
||||||
|
* @Version: v1
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class EmployeeService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private QWMailListManageService qwMailListManageService;
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public Boolean addUser(EmployeeDO employee) throws WxErrorException {
|
||||||
|
//数据库创建用户
|
||||||
|
|
||||||
|
//数据库创建登录account
|
||||||
|
|
||||||
|
//成功则添加用户到企业微信
|
||||||
|
qwMailListManageService.addUser(employee);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.kiisoo.ic.utils;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Binary Wang(https://github.com/binarywang)
|
||||||
|
*/
|
||||||
|
public class JsonUtils {
|
||||||
|
private static final ObjectMapper JSON = new ObjectMapper();
|
||||||
|
|
||||||
|
static {
|
||||||
|
JSON.setSerializationInclusion(Include.NON_NULL);
|
||||||
|
JSON.configure(SerializationFeature.INDENT_OUTPUT, Boolean.TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String toJson(Object obj) {
|
||||||
|
try {
|
||||||
|
return JSON.writeValueAsString(obj);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
package com.kiisoo.ic.wx.service;
|
||||||
|
|
||||||
|
import com.kiisoo.ic.config.WxCpConfiguration;
|
||||||
|
import com.kiisoo.ic.department.entity.DepartmentDO;
|
||||||
|
import com.kiisoo.ic.employee.entity.EmployeeDO;
|
||||||
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
|
import me.chanjar.weixin.cp.api.WxCpDepartmentService;
|
||||||
|
import me.chanjar.weixin.cp.api.WxCpService;
|
||||||
|
import me.chanjar.weixin.cp.api.WxCpUserService;
|
||||||
|
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
|
||||||
|
import me.chanjar.weixin.cp.bean.WxCpDepart;
|
||||||
|
import me.chanjar.weixin.cp.bean.WxCpUser;
|
||||||
|
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 企业微信用户管理service
|
||||||
|
* @Auther: yechenhao
|
||||||
|
* @Date: 2020/4/7 0002 10:06
|
||||||
|
* @Version: v1
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class QWMailListManageService {
|
||||||
|
|
||||||
|
@Value("${qywx.applicationid}")
|
||||||
|
private Integer applicationid;
|
||||||
|
|
||||||
|
private WxCpService wxCpService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增加企业微信用户
|
||||||
|
*/
|
||||||
|
public void addUser(EmployeeDO employeeDO) throws WxErrorException {
|
||||||
|
wxCpService = WxCpConfiguration.getCpService(applicationid);
|
||||||
|
WxCpUserService userService = wxCpService.getUserService();
|
||||||
|
WxCpUser wxCpUser = new WxCpUser();
|
||||||
|
BeanUtils.copyProperties(employeeDO,wxCpUser);
|
||||||
|
userService.create(wxCpUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增加企业微信用户
|
||||||
|
*/
|
||||||
|
public void addDepartment(DepartmentDO departmentDO) throws WxErrorException {
|
||||||
|
wxCpService = WxCpConfiguration.getCpService(applicationid);
|
||||||
|
WxCpDepartmentService departmentService = wxCpService.getDepartmentService();
|
||||||
|
WxCpDepart wxCpDepart = new WxCpDepart();
|
||||||
|
BeanUtils.copyProperties(departmentDO,wxCpDepart);
|
||||||
|
departmentService.create(wxCpDepart);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue