Loki
3 years ago
54 changed files with 1177 additions and 85 deletions
@ -0,0 +1,33 @@
|
||||
package cn.iocoder.yudao.config; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
import me.chanjar.weixin.cp.api.WxCpService; |
||||
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl; |
||||
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
|
||||
@Configuration |
||||
@Slf4j |
||||
public class WxCpConfigure { |
||||
|
||||
|
||||
@Bean |
||||
public WxCpService wxCpService(){ |
||||
|
||||
WxCpDefaultConfigImpl config = new WxCpDefaultConfigImpl(); |
||||
|
||||
config.setCorpId("wwb9f9734e8e124761"); |
||||
config.setAgentId(1000033); |
||||
config.setCorpSecret("UDSKsn0_LAPYqSwjH9E-AfY_X40lq0sormfe1yV_6Gc"); |
||||
|
||||
WxCpServiceImpl wxCpService = new WxCpServiceImpl(); |
||||
wxCpService.setWxCpConfigStorage(config); |
||||
|
||||
log.info("企业微信初始化:{}",wxCpService); |
||||
|
||||
return wxCpService; |
||||
|
||||
} |
||||
|
||||
} |
@ -0,0 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ |
||||
cn.iocoder.yudao.config.WxCpConfigure |
@ -0,0 +1,100 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.CpUser; |
||||
|
||||
import org.springframework.web.bind.annotation.*; |
||||
import javax.annotation.Resource; |
||||
import org.springframework.validation.annotation.Validated; |
||||
import org.springframework.security.access.prepost.PreAuthorize; |
||||
import io.swagger.annotations.*; |
||||
|
||||
import javax.validation.constraints.*; |
||||
import javax.validation.*; |
||||
import javax.servlet.http.*; |
||||
import java.util.*; |
||||
import java.io.IOException; |
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
||||
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; |
||||
|
||||
import cn.iocoder.yudao.module.system.controller.admin.CpUser.vo.*; |
||||
import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO; |
||||
import cn.iocoder.yudao.module.system.convert.CpUser.CpUserConvert; |
||||
import cn.iocoder.yudao.module.system.service.CpUser.CpUserService; |
||||
|
||||
@Api(tags = "管理后台 - 企业微信成员") |
||||
@RestController |
||||
@RequestMapping("/system/cp-user") |
||||
@Validated |
||||
public class CpUserController { |
||||
|
||||
@Resource |
||||
private CpUserService cpUserService; |
||||
|
||||
@PostMapping("/create") |
||||
@ApiOperation("创建企业微信成员") |
||||
@PreAuthorize("@ss.hasPermission('system:cp-user:create')") |
||||
public CommonResult<Long> createCpUser(@Valid @RequestBody CpUserCreateReqVO createReqVO) { |
||||
return success(cpUserService.createCpUser(createReqVO)); |
||||
} |
||||
|
||||
@PutMapping("/update") |
||||
@ApiOperation("更新企业微信成员") |
||||
@PreAuthorize("@ss.hasPermission('system:cp-user:update')") |
||||
public CommonResult<Boolean> updateCpUser(@Valid @RequestBody CpUserUpdateReqVO updateReqVO) { |
||||
cpUserService.updateCpUser(updateReqVO); |
||||
return success(true); |
||||
} |
||||
|
||||
@DeleteMapping("/delete") |
||||
@ApiOperation("删除企业微信成员") |
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) |
||||
@PreAuthorize("@ss.hasPermission('system:cp-user:delete')") |
||||
public CommonResult<Boolean> deleteCpUser(@RequestParam("id") Long id) { |
||||
cpUserService.deleteCpUser(id); |
||||
return success(true); |
||||
} |
||||
|
||||
@GetMapping("/get") |
||||
@ApiOperation("获得企业微信成员") |
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) |
||||
@PreAuthorize("@ss.hasPermission('system:cp-user:query')") |
||||
public CommonResult<CpUserRespVO> getCpUser(@RequestParam("id") Long id) { |
||||
CpUserDO cpUser = cpUserService.getCpUser(id); |
||||
return success(CpUserConvert.INSTANCE.convert(cpUser)); |
||||
} |
||||
|
||||
@GetMapping("/list") |
||||
@ApiOperation("获得企业微信成员列表") |
||||
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) |
||||
@PreAuthorize("@ss.hasPermission('system:cp-user:query')") |
||||
public CommonResult<List<CpUserRespVO>> getCpUserList(@RequestParam("ids") Collection<Long> ids) { |
||||
List<CpUserDO> list = cpUserService.getCpUserList(ids); |
||||
return success(CpUserConvert.INSTANCE.convertList(list)); |
||||
} |
||||
|
||||
@GetMapping("/page") |
||||
@ApiOperation("获得企业微信成员分页") |
||||
@PreAuthorize("@ss.hasPermission('system:cp-user:query')") |
||||
public CommonResult<PageResult<CpUserRespVO>> getCpUserPage(@Valid CpUserPageReqVO pageVO) { |
||||
PageResult<CpUserDO> pageResult = cpUserService.getCpUserPage(pageVO); |
||||
return success(CpUserConvert.INSTANCE.convertPage(pageResult)); |
||||
} |
||||
|
||||
@GetMapping("/export-excel") |
||||
@ApiOperation("导出企业微信成员 Excel") |
||||
@PreAuthorize("@ss.hasPermission('system:cp-user:export')") |
||||
@OperateLog(type = EXPORT) |
||||
public void exportCpUserExcel(@Valid CpUserExportReqVO exportReqVO, |
||||
HttpServletResponse response) throws IOException { |
||||
List<CpUserDO> list = cpUserService.getCpUserList(exportReqVO); |
||||
// 导出 Excel
|
||||
List<CpUserExcelVO> datas = CpUserConvert.INSTANCE.convertList02(list); |
||||
ExcelUtils.write(response, "企业微信成员.xls", "数据", CpUserExcelVO.class, datas); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,46 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.CpUser.vo; |
||||
|
||||
import lombok.*; |
||||
import java.util.*; |
||||
import io.swagger.annotations.*; |
||||
import javax.validation.constraints.*; |
||||
|
||||
/** |
||||
* 企业微信成员 Base VO,提供给添加、修改、详细的子 VO 使用 |
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 |
||||
*/ |
||||
@Data |
||||
public class CpUserBaseVO { |
||||
|
||||
@ApiModelProperty(value = "用户昵称", required = true) |
||||
@NotNull(message = "用户昵称不能为空") |
||||
private String userid; |
||||
|
||||
@ApiModelProperty(value = "头像", required = true) |
||||
@NotNull(message = "头像不能为空") |
||||
private String avatar; |
||||
|
||||
@ApiModelProperty(value = "状态", required = true) |
||||
@NotNull(message = "状态不能为空") |
||||
private Integer status; |
||||
|
||||
@ApiModelProperty(value = "手机号", required = true) |
||||
@NotNull(message = "手机号不能为空") |
||||
private String mobile; |
||||
|
||||
@ApiModelProperty(value = "姓名") |
||||
private String name; |
||||
|
||||
@ApiModelProperty(value = "部门") |
||||
private Object department; |
||||
|
||||
@ApiModelProperty(value = "职位") |
||||
private String position; |
||||
|
||||
@ApiModelProperty(value = "邮件") |
||||
private String email; |
||||
|
||||
@ApiModelProperty(value = "企业邮件") |
||||
private String bizMail; |
||||
|
||||
} |
@ -0,0 +1,14 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.CpUser.vo; |
||||
|
||||
import lombok.*; |
||||
import java.util.*; |
||||
import io.swagger.annotations.*; |
||||
import javax.validation.constraints.*; |
||||
|
||||
@ApiModel("管理后台 - 企业微信成员创建 Request VO") |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@ToString(callSuper = true) |
||||
public class CpUserCreateReqVO extends CpUserBaseVO { |
||||
|
||||
} |
@ -0,0 +1,50 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.CpUser.vo; |
||||
|
||||
import lombok.*; |
||||
import java.util.*; |
||||
import io.swagger.annotations.*; |
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty; |
||||
|
||||
/** |
||||
* 企业微信成员 Excel VO |
||||
* |
||||
* @author 系统管理员 |
||||
*/ |
||||
@Data |
||||
public class CpUserExcelVO { |
||||
|
||||
@ExcelProperty("编号") |
||||
private Long id; |
||||
|
||||
@ExcelProperty("用户昵称") |
||||
private String userid; |
||||
|
||||
@ExcelProperty("头像") |
||||
private String avatar; |
||||
|
||||
@ExcelProperty("状态") |
||||
private Integer status; |
||||
|
||||
@ExcelProperty("手机号") |
||||
private String mobile; |
||||
|
||||
@ExcelProperty("创建时间") |
||||
private Date createTime; |
||||
|
||||
@ExcelProperty("姓名") |
||||
private String name; |
||||
|
||||
@ExcelProperty("部门") |
||||
private Object department; |
||||
|
||||
@ExcelProperty("职位") |
||||
private String position; |
||||
|
||||
@ExcelProperty("邮件") |
||||
private String email; |
||||
|
||||
@ExcelProperty("企业邮件") |
||||
private String bizMail; |
||||
|
||||
} |
@ -0,0 +1,50 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.CpUser.vo; |
||||
|
||||
import lombok.*; |
||||
import java.util.*; |
||||
import io.swagger.annotations.*; |
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam; |
||||
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; |
||||
|
||||
@ApiModel(value = "管理后台 - 企业微信成员 Excel 导出 Request VO", description = "参数和 CpUserPageReqVO 是一致的") |
||||
@Data |
||||
public class CpUserExportReqVO { |
||||
|
||||
@ApiModelProperty(value = "用户昵称") |
||||
private String userid; |
||||
|
||||
@ApiModelProperty(value = "头像") |
||||
private String avatar; |
||||
|
||||
@ApiModelProperty(value = "状态") |
||||
private Integer status; |
||||
|
||||
@ApiModelProperty(value = "手机号") |
||||
private String mobile; |
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) |
||||
@ApiModelProperty(value = "开始创建时间") |
||||
private Date beginCreateTime; |
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) |
||||
@ApiModelProperty(value = "结束创建时间") |
||||
private Date endCreateTime; |
||||
|
||||
@ApiModelProperty(value = "姓名") |
||||
private String name; |
||||
|
||||
@ApiModelProperty(value = "部门") |
||||
private Object department; |
||||
|
||||
@ApiModelProperty(value = "职位") |
||||
private String position; |
||||
|
||||
@ApiModelProperty(value = "邮件") |
||||
private String email; |
||||
|
||||
@ApiModelProperty(value = "企业邮件") |
||||
private String bizMail; |
||||
|
||||
} |
@ -0,0 +1,52 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.CpUser.vo; |
||||
|
||||
import lombok.*; |
||||
import java.util.*; |
||||
import io.swagger.annotations.*; |
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam; |
||||
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; |
||||
|
||||
@ApiModel("管理后台 - 企业微信成员分页 Request VO") |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@ToString(callSuper = true) |
||||
public class CpUserPageReqVO extends PageParam { |
||||
|
||||
@ApiModelProperty(value = "用户昵称") |
||||
private String userid; |
||||
|
||||
@ApiModelProperty(value = "头像") |
||||
private String avatar; |
||||
|
||||
@ApiModelProperty(value = "状态") |
||||
private Integer status; |
||||
|
||||
@ApiModelProperty(value = "手机号") |
||||
private String mobile; |
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) |
||||
@ApiModelProperty(value = "开始创建时间") |
||||
private Date beginCreateTime; |
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) |
||||
@ApiModelProperty(value = "结束创建时间") |
||||
private Date endCreateTime; |
||||
|
||||
@ApiModelProperty(value = "姓名") |
||||
private String name; |
||||
|
||||
@ApiModelProperty(value = "部门") |
||||
private Object department; |
||||
|
||||
@ApiModelProperty(value = "职位") |
||||
private String position; |
||||
|
||||
@ApiModelProperty(value = "邮件") |
||||
private String email; |
||||
|
||||
@ApiModelProperty(value = "企业邮件") |
||||
private String bizMail; |
||||
|
||||
} |
@ -0,0 +1,19 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.CpUser.vo; |
||||
|
||||
import lombok.*; |
||||
import java.util.*; |
||||
import io.swagger.annotations.*; |
||||
|
||||
@ApiModel("管理后台 - 企业微信成员 Response VO") |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@ToString(callSuper = true) |
||||
public class CpUserRespVO extends CpUserBaseVO { |
||||
|
||||
@ApiModelProperty(value = "编号", required = true) |
||||
private Long id; |
||||
|
||||
@ApiModelProperty(value = "创建时间", required = true) |
||||
private Date createTime; |
||||
|
||||
} |
@ -0,0 +1,18 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.CpUser.vo; |
||||
|
||||
import lombok.*; |
||||
import java.util.*; |
||||
import io.swagger.annotations.*; |
||||
import javax.validation.constraints.*; |
||||
|
||||
@ApiModel("管理后台 - 企业微信成员更新 Request VO") |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@ToString(callSuper = true) |
||||
public class CpUserUpdateReqVO extends CpUserBaseVO { |
||||
|
||||
@ApiModelProperty(value = "编号", required = true) |
||||
@NotNull(message = "编号不能为空") |
||||
private Long id; |
||||
|
||||
} |
@ -0,0 +1,37 @@
|
||||
package cn.iocoder.yudao.module.system.convert.CpUser; |
||||
|
||||
import java.util.*; |
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
||||
import me.chanjar.weixin.cp.bean.WxCpUser; |
||||
import org.mapstruct.Mapper; |
||||
import org.mapstruct.factory.Mappers; |
||||
import cn.iocoder.yudao.module.system.controller.admin.CpUser.vo.*; |
||||
import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO; |
||||
|
||||
/** |
||||
* 企业微信成员 Convert |
||||
* |
||||
* @author 系统管理员 |
||||
*/ |
||||
@Mapper |
||||
public interface CpUserConvert { |
||||
|
||||
CpUserConvert INSTANCE = Mappers.getMapper(CpUserConvert.class); |
||||
|
||||
CpUserDO convert(CpUserCreateReqVO bean); |
||||
|
||||
CpUserDO convert(CpUserUpdateReqVO bean); |
||||
|
||||
CpUserRespVO convert(CpUserDO bean); |
||||
|
||||
List<CpUserRespVO> convertList(List<CpUserDO> list); |
||||
|
||||
PageResult<CpUserRespVO> convertPage(PageResult<CpUserDO> page); |
||||
|
||||
List<CpUserExcelVO> convertList02(List<CpUserDO> list); |
||||
|
||||
List<CpUserDO> convertListFromWxApi(List<WxCpUser> list); |
||||
|
||||
} |
@ -0,0 +1,65 @@
|
||||
package cn.iocoder.yudao.module.system.dal.dataobject.CpUser; |
||||
|
||||
import lombok.*; |
||||
import java.util.*; |
||||
import com.baomidou.mybatisplus.annotation.*; |
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
||||
|
||||
/** |
||||
* 企业微信成员 DO |
||||
* |
||||
* @author 系统管理员 |
||||
*/ |
||||
@TableName("wxcp_users") |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@ToString(callSuper = true) |
||||
@Builder |
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
public class CpUserDO extends BaseDO { |
||||
|
||||
/** |
||||
* 编号 |
||||
*/ |
||||
@TableId |
||||
private Long id; |
||||
/** |
||||
* 用户昵称 |
||||
*/ |
||||
@TableField(value = "user_id") |
||||
private String userId; |
||||
/** |
||||
* 头像 |
||||
*/ |
||||
private String avatar; |
||||
/** |
||||
* 状态 |
||||
*/ |
||||
private Integer status; |
||||
/** |
||||
* 手机号 |
||||
*/ |
||||
private String mobile; |
||||
/** |
||||
* 姓名 |
||||
*/ |
||||
private String name; |
||||
/** |
||||
* 部门 |
||||
*/ |
||||
private Object department; |
||||
/** |
||||
* 职位 |
||||
*/ |
||||
private String position; |
||||
/** |
||||
* 邮件 |
||||
*/ |
||||
private String email; |
||||
/** |
||||
* 企业邮件 |
||||
*/ |
||||
private String bizMail; |
||||
|
||||
} |
@ -0,0 +1,50 @@
|
||||
package cn.iocoder.yudao.module.system.dal.mysql.CpUser; |
||||
|
||||
import java.util.*; |
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
||||
import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
import cn.iocoder.yudao.module.system.controller.admin.CpUser.vo.*; |
||||
|
||||
/** |
||||
* 企业微信成员 Mapper |
||||
* |
||||
* @author 系统管理员 |
||||
*/ |
||||
@Mapper |
||||
public interface CpUserMapper extends BaseMapperX<CpUserDO> { |
||||
|
||||
default PageResult<CpUserDO> selectPage(CpUserPageReqVO reqVO) { |
||||
return selectPage(reqVO, new LambdaQueryWrapperX<CpUserDO>() |
||||
.eqIfPresent(CpUserDO::getUserId, reqVO.getUserid()) |
||||
.eqIfPresent(CpUserDO::getAvatar, reqVO.getAvatar()) |
||||
.eqIfPresent(CpUserDO::getStatus, reqVO.getStatus()) |
||||
.eqIfPresent(CpUserDO::getMobile, reqVO.getMobile()) |
||||
.betweenIfPresent(CpUserDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) |
||||
.likeIfPresent(CpUserDO::getName, reqVO.getName()) |
||||
.eqIfPresent(CpUserDO::getDepartment, reqVO.getDepartment()) |
||||
.eqIfPresent(CpUserDO::getPosition, reqVO.getPosition()) |
||||
.eqIfPresent(CpUserDO::getEmail, reqVO.getEmail()) |
||||
.eqIfPresent(CpUserDO::getBizMail, reqVO.getBizMail()) |
||||
.orderByDesc(CpUserDO::getId)); |
||||
} |
||||
|
||||
default List<CpUserDO> selectList(CpUserExportReqVO reqVO) { |
||||
return selectList(new LambdaQueryWrapperX<CpUserDO>() |
||||
.eqIfPresent(CpUserDO::getUserId, reqVO.getUserid()) |
||||
.eqIfPresent(CpUserDO::getAvatar, reqVO.getAvatar()) |
||||
.eqIfPresent(CpUserDO::getStatus, reqVO.getStatus()) |
||||
.eqIfPresent(CpUserDO::getMobile, reqVO.getMobile()) |
||||
.betweenIfPresent(CpUserDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) |
||||
.likeIfPresent(CpUserDO::getName, reqVO.getName()) |
||||
.eqIfPresent(CpUserDO::getDepartment, reqVO.getDepartment()) |
||||
.eqIfPresent(CpUserDO::getPosition, reqVO.getPosition()) |
||||
.eqIfPresent(CpUserDO::getEmail, reqVO.getEmail()) |
||||
.eqIfPresent(CpUserDO::getBizMail, reqVO.getBizMail()) |
||||
.orderByDesc(CpUserDO::getId)); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,24 @@
|
||||
package cn.iocoder.yudao.module.system.job.cpuser; |
||||
|
||||
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; |
||||
import cn.iocoder.yudao.framework.tenant.core.job.TenantJob; |
||||
import cn.iocoder.yudao.module.system.service.CpUser.CpUserService; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.annotation.Resource; |
||||
|
||||
@Component |
||||
@TenantJob |
||||
@Slf4j |
||||
public class CpWeixinUserSyncJob implements JobHandler { |
||||
|
||||
@Resource |
||||
private CpUserService cpUserService; |
||||
|
||||
@Override |
||||
public String execute(String param) throws Exception { |
||||
cpUserService.cpUserSync(); |
||||
return "企业微信同步完成..."; |
||||
} |
||||
} |
@ -0,0 +1,76 @@
|
||||
package cn.iocoder.yudao.module.system.service.CpUser; |
||||
|
||||
import java.util.*; |
||||
import javax.validation.*; |
||||
import cn.iocoder.yudao.module.system.controller.admin.CpUser.vo.*; |
||||
import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO; |
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import me.chanjar.weixin.common.error.WxErrorException; |
||||
|
||||
/** |
||||
* 企业微信成员 Service 接口 |
||||
* |
||||
* @author 系统管理员 |
||||
*/ |
||||
public interface CpUserService extends IService<CpUserDO> { |
||||
|
||||
/** |
||||
* 创建企业微信成员 |
||||
* |
||||
* @param createReqVO 创建信息 |
||||
* @return 编号 |
||||
*/ |
||||
Long createCpUser(@Valid CpUserCreateReqVO createReqVO); |
||||
|
||||
/** |
||||
* 更新企业微信成员 |
||||
* |
||||
* @param updateReqVO 更新信息 |
||||
*/ |
||||
void updateCpUser(@Valid CpUserUpdateReqVO updateReqVO); |
||||
|
||||
/** |
||||
* 删除企业微信成员 |
||||
* |
||||
* @param id 编号 |
||||
*/ |
||||
void deleteCpUser(Long id); |
||||
|
||||
/** |
||||
* 获得企业微信成员 |
||||
* |
||||
* @param id 编号 |
||||
* @return 企业微信成员 |
||||
*/ |
||||
CpUserDO getCpUser(Long id); |
||||
|
||||
CpUserDO getByUserId(String userId); |
||||
|
||||
/** |
||||
* 获得企业微信成员列表 |
||||
* |
||||
* @param ids 编号 |
||||
* @return 企业微信成员列表 |
||||
*/ |
||||
List<CpUserDO> getCpUserList(Collection<Long> ids); |
||||
|
||||
/** |
||||
* 获得企业微信成员分页 |
||||
* |
||||
* @param pageReqVO 分页查询 |
||||
* @return 企业微信成员分页 |
||||
*/ |
||||
PageResult<CpUserDO> getCpUserPage(CpUserPageReqVO pageReqVO); |
||||
|
||||
/** |
||||
* 获得企业微信成员列表, 用于 Excel 导出 |
||||
* |
||||
* @param exportReqVO 查询条件 |
||||
* @return 企业微信成员列表 |
||||
*/ |
||||
List<CpUserDO> getCpUserList(CpUserExportReqVO exportReqVO); |
||||
|
||||
void cpUserSync() throws WxErrorException; |
||||
|
||||
} |
@ -0,0 +1,127 @@
|
||||
package cn.iocoder.yudao.module.system.service.CpUser; |
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import me.chanjar.weixin.common.error.WxErrorException; |
||||
import me.chanjar.weixin.cp.api.WxCpService; |
||||
import me.chanjar.weixin.cp.bean.WxCpUser; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import javax.annotation.Resource; |
||||
import org.springframework.validation.annotation.Validated; |
||||
|
||||
import java.util.*; |
||||
import java.util.stream.Collectors; |
||||
|
||||
import cn.iocoder.yudao.module.system.controller.admin.CpUser.vo.*; |
||||
import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO; |
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
||||
import cn.iocoder.yudao.module.system.convert.CpUser.CpUserConvert; |
||||
import cn.iocoder.yudao.module.system.dal.mysql.CpUser.CpUserMapper; |
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; |
||||
|
||||
/** |
||||
* 企业微信成员 Service 实现类 |
||||
* |
||||
* @author 系统管理员 |
||||
*/ |
||||
@Service |
||||
@Validated |
||||
@Slf4j |
||||
public class CpUserServiceImpl extends ServiceImpl<CpUserMapper,CpUserDO> implements CpUserService { |
||||
|
||||
@Resource |
||||
private CpUserMapper cpUserMapper; |
||||
|
||||
@Autowired |
||||
private WxCpService wxCpService; |
||||
|
||||
|
||||
@Override |
||||
public Long createCpUser(CpUserCreateReqVO createReqVO) { |
||||
// 插入
|
||||
CpUserDO cpUser = CpUserConvert.INSTANCE.convert(createReqVO); |
||||
cpUserMapper.insert(cpUser); |
||||
// 返回
|
||||
return cpUser.getId(); |
||||
} |
||||
|
||||
@Override |
||||
public void updateCpUser(CpUserUpdateReqVO updateReqVO) { |
||||
// 校验存在
|
||||
this.validateCpUserExists(updateReqVO.getId()); |
||||
// 更新
|
||||
CpUserDO updateObj = CpUserConvert.INSTANCE.convert(updateReqVO); |
||||
cpUserMapper.updateById(updateObj); |
||||
} |
||||
|
||||
@Override |
||||
public void deleteCpUser(Long id) { |
||||
// 校验存在
|
||||
this.validateCpUserExists(id); |
||||
// 删除
|
||||
cpUserMapper.deleteById(id); |
||||
} |
||||
|
||||
private void validateCpUserExists(Long id) { |
||||
if (cpUserMapper.selectById(id) == null) { |
||||
throw exception(CP_USER_NOT_EXISTS); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public CpUserDO getCpUser(Long id) { |
||||
return cpUserMapper.selectById(id); |
||||
} |
||||
|
||||
@Override |
||||
public CpUserDO getByUserId(String userId) { |
||||
return this.getOne(Wrappers.<CpUserDO>lambdaQuery().eq(CpUserDO::getUserId,userId),false); |
||||
} |
||||
|
||||
@Override |
||||
public List<CpUserDO> getCpUserList(Collection<Long> ids) { |
||||
return cpUserMapper.selectBatchIds(ids); |
||||
} |
||||
|
||||
@Override |
||||
public PageResult<CpUserDO> getCpUserPage(CpUserPageReqVO pageReqVO) { |
||||
return cpUserMapper.selectPage(pageReqVO); |
||||
} |
||||
|
||||
@Override |
||||
public List<CpUserDO> getCpUserList(CpUserExportReqVO exportReqVO) { |
||||
return cpUserMapper.selectList(exportReqVO); |
||||
} |
||||
|
||||
public void cpUserSync() throws WxErrorException { |
||||
List<WxCpUser> userList = wxCpService.getUserService().listByDepartment(1L, true, 0); |
||||
|
||||
List<CpUserDO> rs = CpUserConvert.INSTANCE.convertListFromWxApi(userList); |
||||
|
||||
List<CpUserDO> nowUsers = this.cpUserMapper.selectList(); |
||||
|
||||
// 已经存在的员工
|
||||
List<String> nowUsersIds = nowUsers.stream().map(CpUserDO::getUserId).collect(Collectors.toList()); |
||||
|
||||
rs.removeIf(cpUserDO -> nowUsersIds.contains(cpUserDO.getUserId())); |
||||
|
||||
this.saveBatch(rs); |
||||
|
||||
// 已经离职的员工 设置删除
|
||||
List<String> leaveUserIds = userList.stream().filter(wxCpUser -> wxCpUser.getStatus() == 0) |
||||
.map(WxCpUser::getUserId).collect(Collectors.toList()); |
||||
|
||||
List<CpUserDO> leaveUsers = this.list(Wrappers.<CpUserDO>lambdaQuery() |
||||
.in(CpUserDO::getUserId, leaveUserIds)); |
||||
leaveUsers.forEach(cpUserDO -> cpUserDO.setDeleted(true)); |
||||
this.updateBatchById(leaveUsers); |
||||
|
||||
} |
||||
|
||||
} |
@ -0,0 +1,12 @@
|
||||
<?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="cn.iocoder.yudao.module.system.dal.mysql.CpUser.CpUserMapper"> |
||||
|
||||
<!-- |
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。 |
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。 |
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 |
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ |
||||
--> |
||||
|
||||
</mapper> |
@ -0,0 +1,218 @@
|
||||
package cn.iocoder.yudao.module.system.service.CpUser; |
||||
|
||||
import org.junit.jupiter.api.Disabled; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import javax.annotation.Resource; |
||||
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; |
||||
|
||||
import cn.iocoder.yudao.module.system.controller.admin.CpUser.vo.*; |
||||
import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO; |
||||
import cn.iocoder.yudao.module.system.dal.mysql.CpUser.CpUserMapper; |
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
||||
import org.springframework.context.annotation.Import; |
||||
import java.util.*; |
||||
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; |
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; |
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; |
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; |
||||
import static org.junit.jupiter.api.Assertions.*; |
||||
|
||||
/** |
||||
* {@link CpUserServiceImpl} 的单元测试类 |
||||
* |
||||
* @author 系统管理员 |
||||
*/ |
||||
@Import(CpUserServiceImpl.class) |
||||
public class CpUserServiceImplTest extends BaseDbUnitTest { |
||||
|
||||
@Resource |
||||
private CpUserServiceImpl cpUserService; |
||||
|
||||
@Resource |
||||
private CpUserMapper cpUserMapper; |
||||
|
||||
@Test |
||||
public void testCreateCpUser_success() { |
||||
// 准备参数
|
||||
CpUserCreateReqVO reqVO = randomPojo(CpUserCreateReqVO.class); |
||||
|
||||
// 调用
|
||||
Long cpUserId = cpUserService.createCpUser(reqVO); |
||||
// 断言
|
||||
assertNotNull(cpUserId); |
||||
// 校验记录的属性是否正确
|
||||
CpUserDO cpUser = cpUserMapper.selectById(cpUserId); |
||||
assertPojoEquals(reqVO, cpUser); |
||||
} |
||||
|
||||
@Test |
||||
public void testUpdateCpUser_success() { |
||||
// mock 数据
|
||||
CpUserDO dbCpUser = randomPojo(CpUserDO.class); |
||||
cpUserMapper.insert(dbCpUser);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
CpUserUpdateReqVO reqVO = randomPojo(CpUserUpdateReqVO.class, o -> { |
||||
o.setId(dbCpUser.getId()); // 设置更新的 ID
|
||||
}); |
||||
|
||||
// 调用
|
||||
cpUserService.updateCpUser(reqVO); |
||||
// 校验是否更新正确
|
||||
CpUserDO cpUser = cpUserMapper.selectById(reqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(reqVO, cpUser); |
||||
} |
||||
|
||||
@Test |
||||
public void testUpdateCpUser_notExists() { |
||||
// 准备参数
|
||||
CpUserUpdateReqVO reqVO = randomPojo(CpUserUpdateReqVO.class); |
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> cpUserService.updateCpUser(reqVO), CP_USER_NOT_EXISTS); |
||||
} |
||||
|
||||
@Test |
||||
public void testDeleteCpUser_success() { |
||||
// mock 数据
|
||||
CpUserDO dbCpUser = randomPojo(CpUserDO.class); |
||||
cpUserMapper.insert(dbCpUser);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbCpUser.getId(); |
||||
|
||||
// 调用
|
||||
cpUserService.deleteCpUser(id); |
||||
// 校验数据不存在了
|
||||
assertNull(cpUserMapper.selectById(id)); |
||||
} |
||||
|
||||
@Test |
||||
public void testDeleteCpUser_notExists() { |
||||
// 准备参数
|
||||
Long id = randomLongId(); |
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> cpUserService.deleteCpUser(id), CP_USER_NOT_EXISTS); |
||||
} |
||||
|
||||
@Test |
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetCpUserPage() { |
||||
// mock 数据
|
||||
CpUserDO dbCpUser = randomPojo(CpUserDO.class, o -> { // 等会查询到
|
||||
o.setUserId(null); |
||||
o.setAvatar(null); |
||||
o.setStatus(null); |
||||
o.setMobile(null); |
||||
o.setCreateTime(null); |
||||
o.setName(null); |
||||
o.setDepartment(null); |
||||
o.setPosition(null); |
||||
o.setEmail(null); |
||||
o.setBizMail(null); |
||||
}); |
||||
cpUserMapper.insert(dbCpUser); |
||||
// 测试 userid 不匹配
|
||||
cpUserMapper.insert(cloneIgnoreId(dbCpUser, o -> o.setUserId(null))); |
||||
// 测试 avatar 不匹配
|
||||
cpUserMapper.insert(cloneIgnoreId(dbCpUser, o -> o.setAvatar(null))); |
||||
// 测试 status 不匹配
|
||||
cpUserMapper.insert(cloneIgnoreId(dbCpUser, o -> o.setStatus(null))); |
||||
// 测试 mobile 不匹配
|
||||
cpUserMapper.insert(cloneIgnoreId(dbCpUser, o -> o.setMobile(null))); |
||||
// 测试 createTime 不匹配
|
||||
cpUserMapper.insert(cloneIgnoreId(dbCpUser, o -> o.setCreateTime(null))); |
||||
// 测试 name 不匹配
|
||||
cpUserMapper.insert(cloneIgnoreId(dbCpUser, o -> o.setName(null))); |
||||
// 测试 department 不匹配
|
||||
cpUserMapper.insert(cloneIgnoreId(dbCpUser, o -> o.setDepartment(null))); |
||||
// 测试 position 不匹配
|
||||
cpUserMapper.insert(cloneIgnoreId(dbCpUser, o -> o.setPosition(null))); |
||||
// 测试 email 不匹配
|
||||
cpUserMapper.insert(cloneIgnoreId(dbCpUser, o -> o.setEmail(null))); |
||||
// 测试 bizMail 不匹配
|
||||
cpUserMapper.insert(cloneIgnoreId(dbCpUser, o -> o.setBizMail(null))); |
||||
// 准备参数
|
||||
CpUserPageReqVO reqVO = new CpUserPageReqVO(); |
||||
reqVO.setUserid(null); |
||||
reqVO.setAvatar(null); |
||||
reqVO.setStatus(null); |
||||
reqVO.setMobile(null); |
||||
reqVO.setBeginCreateTime(null); |
||||
reqVO.setEndCreateTime(null); |
||||
reqVO.setName(null); |
||||
reqVO.setDepartment(null); |
||||
reqVO.setPosition(null); |
||||
reqVO.setEmail(null); |
||||
reqVO.setBizMail(null); |
||||
|
||||
// 调用
|
||||
PageResult<CpUserDO> pageResult = cpUserService.getCpUserPage(reqVO); |
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal()); |
||||
assertEquals(1, pageResult.getList().size()); |
||||
assertPojoEquals(dbCpUser, pageResult.getList().get(0)); |
||||
} |
||||
|
||||
@Test |
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetCpUserList() { |
||||
// mock 数据
|
||||
CpUserDO dbCpUser = randomPojo(CpUserDO.class, o -> { // 等会查询到
|
||||
o.setUserId(null); |
||||
o.setAvatar(null); |
||||
o.setStatus(null); |
||||
o.setMobile(null); |
||||
o.setCreateTime(null); |
||||
o.setName(null); |
||||
o.setDepartment(null); |
||||
o.setPosition(null); |
||||
o.setEmail(null); |
||||
o.setBizMail(null); |
||||
}); |
||||
cpUserMapper.insert(dbCpUser); |
||||
// 测试 userid 不匹配
|
||||
cpUserMapper.insert(cloneIgnoreId(dbCpUser, o -> o.setUserId(null))); |
||||
// 测试 avatar 不匹配
|
||||
cpUserMapper.insert(cloneIgnoreId(dbCpUser, o -> o.setAvatar(null))); |
||||
// 测试 status 不匹配
|
||||
cpUserMapper.insert(cloneIgnoreId(dbCpUser, o -> o.setStatus(null))); |
||||
// 测试 mobile 不匹配
|
||||
cpUserMapper.insert(cloneIgnoreId(dbCpUser, o -> o.setMobile(null))); |
||||
// 测试 createTime 不匹配
|
||||
cpUserMapper.insert(cloneIgnoreId(dbCpUser, o -> o.setCreateTime(null))); |
||||
// 测试 name 不匹配
|
||||
cpUserMapper.insert(cloneIgnoreId(dbCpUser, o -> o.setName(null))); |
||||
// 测试 department 不匹配
|
||||
cpUserMapper.insert(cloneIgnoreId(dbCpUser, o -> o.setDepartment(null))); |
||||
// 测试 position 不匹配
|
||||
cpUserMapper.insert(cloneIgnoreId(dbCpUser, o -> o.setPosition(null))); |
||||
// 测试 email 不匹配
|
||||
cpUserMapper.insert(cloneIgnoreId(dbCpUser, o -> o.setEmail(null))); |
||||
// 测试 bizMail 不匹配
|
||||
cpUserMapper.insert(cloneIgnoreId(dbCpUser, o -> o.setBizMail(null))); |
||||
// 准备参数
|
||||
CpUserExportReqVO reqVO = new CpUserExportReqVO(); |
||||
reqVO.setUserid(null); |
||||
reqVO.setAvatar(null); |
||||
reqVO.setStatus(null); |
||||
reqVO.setMobile(null); |
||||
reqVO.setBeginCreateTime(null); |
||||
reqVO.setEndCreateTime(null); |
||||
reqVO.setName(null); |
||||
reqVO.setDepartment(null); |
||||
reqVO.setPosition(null); |
||||
reqVO.setEmail(null); |
||||
reqVO.setBizMail(null); |
||||
|
||||
// 调用
|
||||
List<CpUserDO> list = cpUserService.getCpUserList(reqVO); |
||||
// 断言
|
||||
assertEquals(1, list.size()); |
||||
assertPojoEquals(dbCpUser, list.get(0)); |
||||
} |
||||
|
||||
} |
@ -1 +1 @@
|
||||
Subproject commit 05fdb1d9e71965bbb19e9e35b8732c861d7eab94 |
||||
Subproject commit 8db432a76334b37b1a9c20fb16287fd0c9e57fe0 |
Loading…
Reference in new issue