Explorar o código

Merge branch 'fix/钉钉同步员工编码的问题' into 'develop'

Merge of fix/[人员组织]钉钉同步员工编码的问题 to develop

See merge request o2oa/o2oa!817
o2null %!s(int64=5) %!d(string=hai) anos
pai
achega
48e7e54e38

+ 21 - 2
o2server/x_program_center/src/main/java/com/x/program/center/dingding/SyncOrganization.java

@@ -263,6 +263,13 @@ public class SyncOrganization {
 			person.setName(user.getName());
 			person.setName(user.getName());
 			person.setMobile(user.getMobile());
 			person.setMobile(user.getMobile());
 			person.setUnique(user.getUserid());
 			person.setUnique(user.getUserid());
+			String employee = user.getJobnumber();
+			if(StringUtils.isNotEmpty(employee)){
+				if(business.person().employeeExists(employee, person.getUnique())){
+					employee = "";
+				}
+			}
+			person.setEmployee(employee);
 			person.setMail(user.getEmail());
 			person.setMail(user.getEmail());
 			person.setOfficePhone(user.getMobile());
 			person.setOfficePhone(user.getMobile());
 			person.setGenderType(GenderType.d);
 			person.setGenderType(GenderType.d);
@@ -275,7 +282,13 @@ public class SyncOrganization {
 			person.setName(user.getName());
 			person.setName(user.getName());
 			person.setMobile(user.getMobile());
 			person.setMobile(user.getMobile());
 			person.setUnique(user.getUserid());
 			person.setUnique(user.getUserid());
-			// person.setEmployee(user.getJobNumber());
+			String employee = user.getJobnumber();
+			if(StringUtils.isNotEmpty(employee)){
+				if(business.person().employeeExists(employee, person.getUnique())){
+					employee = "";
+				}
+			}
+			person.setEmployee(employee);
 			person.setMail(user.getEmail());
 			person.setMail(user.getEmail());
 			person.setOfficePhone(user.getMobile());
 			person.setOfficePhone(user.getMobile());
 			person.setGenderType(GenderType.d);
 			person.setGenderType(GenderType.d);
@@ -308,7 +321,13 @@ public class SyncOrganization {
 		EntityManagerContainer emc = business.entityManagerContainer();
 		EntityManagerContainer emc = business.entityManagerContainer();
 		emc.beginTransaction(Person.class);
 		emc.beginTransaction(Person.class);
 		person.setDingdingHash(DigestUtils.sha256Hex(XGsonBuilder.toJson(user)));
 		person.setDingdingHash(DigestUtils.sha256Hex(XGsonBuilder.toJson(user)));
-		// person.setEmployee(user.getJobNumber());
+		String employee = user.getJobnumber();
+		if(StringUtils.isNotEmpty(employee)){
+			if(business.person().employeeExists(employee, person.getUnique())){
+				employee = "";
+			}
+		}
+		person.setEmployee(employee);
 		person.setName(user.getName());
 		person.setName(user.getName());
 		person.setMobile(user.getMobile());
 		person.setMobile(user.getMobile());
 		person.setMail(user.getEmail());
 		person.setMail(user.getEmail());

+ 18 - 2
o2server/x_program_center/src/main/java/com/x/program/center/factory/PersonFactory.java

@@ -54,12 +54,12 @@ public class PersonFactory extends AbstractFactory {
 		}
 		}
 	}
 	}
 
 
-	public Person getWithQiyeweixinIdObject(String dingdingId) throws Exception {
+	public Person getWithQiyeweixinIdObject(String qiyeweixinId) throws Exception {
 		EntityManager em = this.entityManagerContainer().get(Person.class);
 		EntityManager em = this.entityManagerContainer().get(Person.class);
 		CriteriaBuilder cb = em.getCriteriaBuilder();
 		CriteriaBuilder cb = em.getCriteriaBuilder();
 		CriteriaQuery<Person> cq = cb.createQuery(Person.class);
 		CriteriaQuery<Person> cq = cb.createQuery(Person.class);
 		Root<Person> root = cq.from(Person.class);
 		Root<Person> root = cq.from(Person.class);
-		Predicate p = cb.equal(root.get(Person_.qiyeweixinId), dingdingId);
+		Predicate p = cb.equal(root.get(Person_.qiyeweixinId), qiyeweixinId);
 		List<Person> os = em.createQuery(cq.select(root).where(p)).setMaxResults(1).getResultList();
 		List<Person> os = em.createQuery(cq.select(root).where(p)).setMaxResults(1).getResultList();
 		if (os.isEmpty()) {
 		if (os.isEmpty()) {
 			return null;
 			return null;
@@ -81,4 +81,20 @@ public class PersonFactory extends AbstractFactory {
 		}
 		}
 	}
 	}
 
 
+	public boolean employeeExists(String employee, String excludeUnique) throws Exception {
+		EntityManager em = this.entityManagerContainer().get(Person.class);
+		CriteriaBuilder cb = em.getCriteriaBuilder();
+		CriteriaQuery<Person> cq = cb.createQuery(Person.class);
+		Root<Person> root = cq.from(Person.class);
+		Predicate p = cb.equal(root.get(Person_.employee), employee);
+		if(StringUtils.isNotEmpty(excludeUnique)){
+			p = cb.and(p, cb.notEqual(root.get(Person_.unique), excludeUnique));
+		}
+		List<Person> os = em.createQuery(cq.select(root).where(p)).setMaxResults(1).getResultList();
+		if (os.isEmpty()) {
+			return false;
+		}
+		return true;
+	}
+
 }
 }