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