批量新增时如果存在就更新,不存在就新增
This commit is contained in:
parent
e6729167aa
commit
6f906f8482
|
|
@ -21,110 +21,124 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* 成员同步
|
||||
*
|
||||
* @author zhujj
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/wx/cp/user")
|
||||
public class WxUserController {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
private final Logger logger = LoggerFactory.getLogger( this.getClass() );
|
||||
|
||||
@Autowired
|
||||
private WxCpProperties properties;
|
||||
|
||||
/**
|
||||
* 获取成员列表详情
|
||||
* @param departId 部门id
|
||||
* 获取成员列表详情
|
||||
*
|
||||
* @param departId 部门id
|
||||
* @param fetch_child 是否递归获取子部门下面的成员
|
||||
* @param state 成员状态 默认0-正常
|
||||
* @param state 成员状态 默认0-正常
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/userList")
|
||||
public AjaxResult userList(Long departId,boolean fetch_child,Integer state) {
|
||||
public AjaxResult userList(Long departId, boolean fetch_child, Integer state) {
|
||||
try {
|
||||
WxCpUserService userService = WxCpConfiguration.getCpService(999999).getUserService();
|
||||
WxCpUserService userService = WxCpConfiguration.getCpService( 999999 ).getUserService();
|
||||
|
||||
List<WxCpUser> wxCpUsers = userService.listByDepartment(departId, fetch_child, state);
|
||||
return AjaxResult.success(wxCpUsers,"获取成员成功");
|
||||
List<WxCpUser> wxCpUsers = userService.listByDepartment( departId, fetch_child, state );
|
||||
return AjaxResult.success( wxCpUsers, "获取成员成功" );
|
||||
} catch (WxErrorException e) {
|
||||
return AjaxResult.error("获取成员出错,错误码【"+ e.getError().getErrorCode()+"】,原因:"+ ErrorCodeText.errorMsg(e.getError().getErrorCode()));
|
||||
return AjaxResult.error( "获取成员出错,错误码【" + e.getError().getErrorCode() + "】,原因:" + ErrorCodeText.errorMsg( e.getError().getErrorCode() ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取成员列表(只返回成员简洁信息)
|
||||
* @param departId 部门id
|
||||
* 获取成员列表(只返回成员简洁信息)
|
||||
*
|
||||
* @param departId 部门id
|
||||
* @param fetch_child 是否递归获取子部门下面的成员
|
||||
* @param state 成员状态 默认0-正常
|
||||
* @param state 成员状态 默认0-正常
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/userSimpleList")
|
||||
public AjaxResult userSimpleList(Long departId,boolean fetch_child,Integer state) {
|
||||
public AjaxResult userSimpleList(Long departId, boolean fetch_child, Integer state) {
|
||||
try {
|
||||
WxCpUserService userService = WxCpConfiguration.getCpService(999999).getUserService();
|
||||
List<WxCpUser> wxCpUsers = userService.listSimpleByDepartment(departId, fetch_child, state);
|
||||
return AjaxResult.success(wxCpUsers,"获取成员成功");
|
||||
WxCpUserService userService = WxCpConfiguration.getCpService( 999999 ).getUserService();
|
||||
List<WxCpUser> wxCpUsers = userService.listSimpleByDepartment( departId, fetch_child, state );
|
||||
return AjaxResult.success( wxCpUsers, "获取成员成功" );
|
||||
} catch (WxErrorException e) {
|
||||
return AjaxResult.error("获取成员出错,错误码【"+ e.getError().getErrorCode()+"】,原因:"+ ErrorCodeText.errorMsg(e.getError().getErrorCode()));
|
||||
return AjaxResult.error( "获取成员出错,错误码【" + e.getError().getErrorCode() + "】,原因:" + ErrorCodeText.errorMsg( e.getError().getErrorCode() ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Log(title = "新增成员", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/insert")
|
||||
public AjaxResult insert(@RequestBody WxCpUser wxCpUuser) {
|
||||
try {
|
||||
|
||||
WxCpUserService userService = WxCpConfiguration.getCpService(999999).getUserService();
|
||||
userService.create(wxCpUuser);
|
||||
return AjaxResult.success("新增成员成功");
|
||||
WxCpUserService userService = WxCpConfiguration.getCpService( 999999 ).getUserService();
|
||||
userService.create( wxCpUuser );
|
||||
return AjaxResult.success( "新增成员成功" );
|
||||
} catch (WxErrorException e) {
|
||||
return AjaxResult.error("新增成员出错,错误码【"+ e.getError().getErrorCode()+"】,原因:"+ ErrorCodeText.errorMsg(e.getError().getErrorCode()));
|
||||
return AjaxResult.error( "新增成员出错,错误码【" + e.getError().getErrorCode() + "】,原因:" + ErrorCodeText.errorMsg( e.getError().getErrorCode() ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Log(title = "全量新增成员", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/insertList")
|
||||
public AjaxResult insertList(@RequestBody List<WxCpUser> wxCpUsers) {
|
||||
this.logger.info("全量新增成员");
|
||||
int i=0;
|
||||
this.logger.info( "全量新增成员" );
|
||||
int i = 0;
|
||||
try {
|
||||
WxCpUserService userService = WxCpConfiguration.getCpService(999999).getUserService();
|
||||
WxCpUserService userService = WxCpConfiguration.getCpService( 999999 ).getUserService();
|
||||
for (WxCpUser wxCpUser : wxCpUsers) {
|
||||
userService.create(wxCpUser);
|
||||
WxCpUser user = userService.getById( wxCpUser.getUserId() );
|
||||
if (user == null) {
|
||||
userService.create( wxCpUser );
|
||||
} else {
|
||||
userService.update( wxCpUser );
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return AjaxResult.success(i,"全量新增成员成功");
|
||||
return AjaxResult.success( i, "全量新增成员成功" );
|
||||
} catch (WxErrorException e) {
|
||||
return AjaxResult.error("全量新增成员成功【"+i+"】条,其余失败,错误码【"+ e.getError().getErrorCode()+"】,原因:"+ ErrorCodeText.errorMsg(e.getError().getErrorCode()));
|
||||
return AjaxResult.error( "全量新增成员成功【" + i + "】条,其余失败,错误码【" + e.getError().getErrorCode() + "】,原因:" + ErrorCodeText.errorMsg( e.getError().getErrorCode() ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Log(title = "更新成员", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/update")
|
||||
public AjaxResult update(@RequestBody WxCpUser wxCpUser) {
|
||||
try {
|
||||
WxCpUserService userService = WxCpConfiguration.getCpService(999999).getUserService();
|
||||
userService.update(wxCpUser);
|
||||
return AjaxResult.success("更新成员成功");
|
||||
WxCpUserService userService = WxCpConfiguration.getCpService( 999999 ).getUserService();
|
||||
userService.update( wxCpUser );
|
||||
return AjaxResult.success( "更新成员成功" );
|
||||
} catch (WxErrorException e) {
|
||||
return AjaxResult.error("更新成员失败,错误码【"+ e.getError().getErrorCode()+"】,原因:"+ ErrorCodeText.errorMsg(e.getError().getErrorCode()));
|
||||
return AjaxResult.error( "更新成员失败,错误码【" + e.getError().getErrorCode() + "】,原因:" + ErrorCodeText.errorMsg( e.getError().getErrorCode() ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Log(title = "删除成员", businessType = BusinessType.DELETE)
|
||||
@GetMapping("/delete")
|
||||
public AjaxResult delete(String id) {
|
||||
try {
|
||||
WxCpUserService userService = WxCpConfiguration.getCpService(999999).getUserService();
|
||||
userService.delete(id);
|
||||
return AjaxResult.success("删除成员成功");
|
||||
WxCpUserService userService = WxCpConfiguration.getCpService( 999999 ).getUserService();
|
||||
userService.delete( id );
|
||||
return AjaxResult.success( "删除成员成功" );
|
||||
} catch (WxErrorException e) {
|
||||
return AjaxResult.error("删除成员出错,错误码【"+ e.getError().getErrorCode()+"】,原因:"+ ErrorCodeText.errorMsg(e.getError().getErrorCode()));
|
||||
return AjaxResult.error( "删除成员出错,错误码【" + e.getError().getErrorCode() + "】,原因:" + ErrorCodeText.errorMsg( e.getError().getErrorCode() ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Log(title = "批量删除成员", businessType = BusinessType.DELETE)
|
||||
@GetMapping("/deleteByIds")
|
||||
public AjaxResult delete(@RequestBody String[] ids) {
|
||||
try {
|
||||
WxCpUserService userService = WxCpConfiguration.getCpService(999999).getUserService();
|
||||
userService.delete(ids);
|
||||
return AjaxResult.success("批量删除成员");
|
||||
WxCpUserService userService = WxCpConfiguration.getCpService( 999999 ).getUserService();
|
||||
userService.delete( ids );
|
||||
return AjaxResult.success( "批量删除成员" );
|
||||
} catch (WxErrorException e) {
|
||||
return AjaxResult.error("删除成员出错,错误码【"+ e.getError().getErrorCode()+"】,原因:"+ ErrorCodeText.errorMsg(e.getError().getErrorCode()));
|
||||
return AjaxResult.error( "删除成员出错,错误码【" + e.getError().getErrorCode() + "】,原因:" + ErrorCodeText.errorMsg( e.getError().getErrorCode() ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue