|
@@ -22,11 +22,6 @@ import me.chanjar.weixin.cp.bean.WxCpDepart;
|
|
|
*/
|
|
|
public class WXCpDepartUtil {
|
|
|
|
|
|
- public static void main(String[] args) throws WxErrorException {
|
|
|
-// {"id":228,"name":"财务计划与分析","parentid":223}
|
|
|
- createOrUpdate(228L, 223L, "财务计划与分析");
|
|
|
- }
|
|
|
-
|
|
|
public static List<WxCpDepart> getChildDeparts(Long id) throws WxErrorException {
|
|
|
List<WxCpDepart> departs = Lists.newArrayList();
|
|
|
for (WxCpDepart depart : departService.list(id)) {
|
|
@@ -98,35 +93,19 @@ public class WXCpDepartUtil {
|
|
|
return depatmentId;
|
|
|
}
|
|
|
|
|
|
- public static Long createOrUpdate(Long id, Long parentId, String name) throws WxErrorException {
|
|
|
- if(id == null) {
|
|
|
- Map<String, Long> map = getChildDepartMap(parentId);
|
|
|
- Long depatmentId = map.get(name);
|
|
|
- if (depatmentId == null) {
|
|
|
- WxCpDepart depart = new WxCpDepart();
|
|
|
- depart.setName(name);
|
|
|
- depart.setParentId(parentId);
|
|
|
- depatmentId = departService.create(depart);
|
|
|
- }
|
|
|
- return depatmentId;
|
|
|
- } else {
|
|
|
- Map<String, Long> map = getChildDepartMap(parentId);
|
|
|
- LoggerUtil.info("createOrUpdate->" + JSON.toJSONString(map));
|
|
|
- Long depatmentId = map.get(name);
|
|
|
- if(!id.equals(depatmentId)) {
|
|
|
- WxCpDepart depart = new WxCpDepart();
|
|
|
- depart.setId(id);
|
|
|
- depart.setName(name);
|
|
|
- depart.setParentId(parentId);
|
|
|
- try {
|
|
|
- // 部门删除情况下,更新报错,变成创建
|
|
|
- departService.update(depart);
|
|
|
- } catch (WxErrorException e) {
|
|
|
- id = departService.create(depart);
|
|
|
- }
|
|
|
- }
|
|
|
- return id;
|
|
|
+ public static Long createOrUpdate(Long parentId, String name) throws WxErrorException {
|
|
|
+ Map<String, Long> map = getChildDepartMap(parentId);
|
|
|
+ LoggerUtil.info("createOrUpdate->" + JSON.toJSONString(map));
|
|
|
+ Long wxDepartId = map.get(name);
|
|
|
+ // 1.判断parentId对应子部门是否存在对应部门,存在返回对应
|
|
|
+ // 2.不存在创建对应子部门
|
|
|
+ if(wxDepartId == null) {
|
|
|
+ WxCpDepart depart = new WxCpDepart();
|
|
|
+ depart.setName(name);
|
|
|
+ depart.setParentId(parentId);
|
|
|
+ wxDepartId = departService.create(depart);
|
|
|
}
|
|
|
+ return wxDepartId;
|
|
|
}
|
|
|
|
|
|
public static List<WxCpDepart> getAllChildDeparts(Long id) throws WxErrorException {
|