|
@@ -1,24 +1,49 @@
|
|
|
package org.fouram.service;
|
|
|
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import org.fouram.core.base.service.BaseService;
|
|
|
import org.fouram.core.plugin.weixin.cp.util.WXCpUserUtil;
|
|
|
+import org.fouram.entity.WxDepart;
|
|
|
import org.fouram.entity.WxUser;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import com.google.common.collect.Maps;
|
|
|
+
|
|
|
import me.chanjar.weixin.cp.bean.WxCpUser;
|
|
|
|
|
|
@Service
|
|
|
public class WxUserService extends BaseService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WxDepartService wxDepartService;
|
|
|
+
|
|
|
+ private Map<Long, List<WxDepart>> userDepartMap = Maps.newHashMap();
|
|
|
|
|
|
public void saveUsers() throws Exception {
|
|
|
List<WxCpUser> users = WXCpUserUtil.listAllUser();
|
|
|
+ List<WxDepart> departs = null;
|
|
|
WxUser wxUser = null;
|
|
|
for (WxCpUser user : users) {
|
|
|
wxUser = WxUser.builder().userId(user.getUserId()).name(user.getName()).departId(user.getDepartIds()[0])
|
|
|
.build();
|
|
|
+ departs = getUserDepart(wxUser.getDepartId());
|
|
|
+ if(departs.size() > 0) {
|
|
|
+ wxUser.setFirstDepartName(departs.get(0).getName());
|
|
|
+ }
|
|
|
+ if(departs.size() > 1) {
|
|
|
+ wxUser.setSecondDepartName(departs.get(1).getName());
|
|
|
+ }
|
|
|
save("WxUserMapper.save", wxUser);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private List<WxDepart> getUserDepart(Long departId) throws Exception {
|
|
|
+ if(!userDepartMap.containsKey(departId)) {
|
|
|
+ userDepartMap.put(departId, wxDepartService.findParentList(departId));
|
|
|
+ }
|
|
|
+ return userDepartMap.get(departId);
|
|
|
+ }
|
|
|
}
|