jiapeng 7 年之前
父节点
当前提交
c44c6dc970
共有 1 个文件被更改,包括 175 次插入13 次删除
  1. 175 13
      src/main/java/com/ekexiu/portal/service/SysService.java

+ 175 - 13
src/main/java/com/ekexiu/portal/service/SysService.java

29
29
30
import com.ekexiu.portal.dao.OrgDao;
30
import com.ekexiu.portal.dao.OrgDao;
31
import com.ekexiu.portal.dao.OrgUserDao;
31
import com.ekexiu.portal.dao.OrgUserDao;
32
import com.ekexiu.portal.dao.PaperAuthorDao;
33
import com.ekexiu.portal.dao.PatentAuthorDao;
32
import com.ekexiu.portal.dao.ProfessorDao;
34
import com.ekexiu.portal.dao.ProfessorDao;
33
import com.ekexiu.portal.dao.UserDao;
35
import com.ekexiu.portal.dao.UserDao;
34
import com.ekexiu.portal.dao.UserOpenIdDao;
36
import com.ekexiu.portal.dao.UserOpenIdDao;
74
	@Autowrie
76
	@Autowrie
75
	private UserOpenIdDao userOpenIdDao;
77
	private UserOpenIdDao userOpenIdDao;
76
78
79
	@Autowrie
80
	private PatentAuthorDao patentAuthorDao;
81
	@Autowrie
82
	private PaperAuthorDao paperAuthorDao;
83
77
	private String bindMailSubject;
84
	private String bindMailSubject;
78
85
79
	private String bindMailReplaceKey;
86
	private String bindMailReplaceKey;
143
	private String retrieveOrgFailTempalte;
150
	private String retrieveOrgFailTempalte;
144
	private String retrieveOrgFailSubject;
151
	private String retrieveOrgFailSubject;
145
152
153
	public PatentAuthorDao getPatentAuthorDao() {
154
		return patentAuthorDao;
155
	}
156
157
	public void setPatentAuthorDao(PatentAuthorDao patentAuthorDao) {
158
		this.patentAuthorDao = patentAuthorDao;
159
	}
160
161
	public PaperAuthorDao getPaperAuthorDao() {
162
		return paperAuthorDao;
163
	}
164
165
	public void setPaperAuthorDao(PaperAuthorDao paperAuthorDao) {
166
		this.paperAuthorDao = paperAuthorDao;
167
	}
168
146
	public String getRegMailReplaceKey() {
169
	public String getRegMailReplaceKey() {
147
		return regMailReplaceKey;
170
		return regMailReplaceKey;
148
	}
171
	}
753
	 */
776
	 */
754
	@Post
777
	@Post
755
	@Path("/regmobile")
778
	@Path("/regmobile")
756
	public String regMobile(@JdbcConn(true) Connection con, String state, String mobilePhone, String validateCode, String password, @Nullable String inviterId) throws SQLException, JfwBaseException {
779
	public String regMobile(@JdbcConn(true) Connection con, String state, String mobilePhone, String validateCode, String password, @Nullable String inviterId)
780
			throws SQLException, JfwBaseException {
757
		@SuppressWarnings("unchecked")
781
		@SuppressWarnings("unchecked")
758
		StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
782
		StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
759
		if (sc == null || sc.getExpiredTime() < System.currentTimeMillis())
783
		if (sc == null || sc.getExpiredTime() < System.currentTimeMillis())
833
	@Post
857
	@Post
834
	@Path("/mobileReg")
858
	@Path("/mobileReg")
835
	public String mobileReg(@JdbcConn(true) Connection con, String state, String mobilePhone, String validateCode, String password, @Nullable String inviterId,
859
	public String mobileReg(@JdbcConn(true) Connection con, String state, String mobilePhone, String validateCode, String password, @Nullable String inviterId,
836
			String name,	@Nullable String oauthType, @Nullable String openid, @Nullable String authCode) throws SQLException, JfwBaseException, IOException {
860
			String name, @Nullable String oauthType, @Nullable String openid, @Nullable String authCode) throws SQLException, JfwBaseException, IOException {
837
		@SuppressWarnings("unchecked")
861
		@SuppressWarnings("unchecked")
838
		StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
862
		StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
839
		if (sc == null || sc.getExpiredTime() < System.currentTimeMillis())
863
		if (sc == null || sc.getExpiredTime() < System.currentTimeMillis())
868
		}
892
		}
869
	}
893
	}
870
894
895
	@Post
896
	@Path("/regAndAssPatent")
897
	public boolean assPatent(@JdbcConn(true) Connection con, String state, String phone, String vc, @Nullable String inviterId, String name, String patent)
898
			throws SQLException, JfwBaseException, IOException {
899
		@SuppressWarnings("unchecked")
900
		 StateCode<String, String> sc = (StateCode<String, String>)
901
		 JfwAppContext.getCachedObject(state);
902
		 if (sc == null || sc.getExpiredTime() < System.currentTimeMillis())
903
		 throw new JfwBaseException(-1, "验证超时");
904
		 if (!sc.getKey().equals(phone)) {
905
		 throw new JfwBaseException(-2, "手机号与验证手机不匹配");
906
		 }
907
		 if (!sc.getValue().equals(vc)) {
908
		 throw new JfwBaseException(-3, "验证码错误");
909
		 }
910
		User user = null;
911
		boolean exists = false;
912
		String uid = StringUtil.buildUUID();
913
		try {
914
			try {
915
				user = new User();
916
				user.setId(uid);
917
				String passwd = StringUtil.md5("123456");
918
				user.setMobilePhone(phone);
919
				user.setPasswd(passwd);
920
				user.setUserType("0");
921
				user.setInviterId(inviterId);
922
				user.setActiveTime(DATE.format(new Date()));
923
				this.userDao.insert(con, user);
924
			} catch (SQLException e) {
925
				if ("23505".equals(e.getSQLState())) {
926
					con.rollback();
927
					user = userDao.queryByEmailOrMobilePhone(con, phone);
928
					if (user == null)
929
						throw new RuntimeException("not fonud  with query user by phone");
930
					exists = true;
931
					uid = user.getId();
932
				} else {
933
					throw e;
934
				}
935
			}
936
			if (exists) {
937
				Professor professor = this.professorDao.query(con, uid);
938
				if (professor == null) {
939
					professor = new Professor();
940
					professor.setId(uid);
941
					professor.setName(name);
942
					professor.setPhone(phone);
943
					this.professorService.insert(con, professor, null);
944
				} else {
945
					name = professor.getName();
946
				}
947
			} else {
948
				Professor professor = new Professor();
949
				professor.setId(uid);
950
				professor.setName(name);
951
				professor.setPhone(phone);
952
				this.professorService.insert(con, professor, null);
953
				if (inviterId != null) {
954
					this.growthLogService.invite(con, inviterId, uid);
955
				}
956
			}
957
			return this.patentAuthorDao.update(con, patent, uid, name) > 0;
958
959
		} finally {
960
			JfwAppContext.removeCachedObject(state);
961
		}
962
	}
963
964
	@Post
965
	@Path("/regAndAssPaper")
966
	public boolean assPaper(@JdbcConn(true) Connection con, String state, String phone, String vc, @Nullable String inviterId, String name, String paper)
967
			throws SQLException, JfwBaseException, IOException {
968
		@SuppressWarnings("unchecked")
969
		 StateCode<String, String> sc = (StateCode<String, String>)
970
		 JfwAppContext.getCachedObject(state);
971
		 if (sc == null || sc.getExpiredTime() < System.currentTimeMillis())
972
		 throw new JfwBaseException(-1, "验证超时");
973
		 if (!sc.getKey().equals(phone)) {
974
		 throw new JfwBaseException(-2, "手机号与验证手机不匹配");
975
		 }
976
		 if (!sc.getValue().equals(vc)) {
977
		 throw new JfwBaseException(-3, "验证码错误");
978
		 }
979
		User user = null;
980
		boolean exists = false;
981
		String uid = StringUtil.buildUUID();
982
		try {
983
			try {
984
				user = new User();
985
				user.setId(uid);
986
				String passwd = StringUtil.md5("123456");
987
				user.setMobilePhone(phone);
988
				user.setPasswd(passwd);
989
				user.setUserType("0");
990
				user.setInviterId(inviterId);
991
				user.setActiveTime(DATE.format(new Date()));
992
				this.userDao.insert(con, user);
993
			} catch (SQLException e) {
994
				if ("23505".equals(e.getSQLState())) {
995
					con.rollback();
996
					user = userDao.queryByEmailOrMobilePhone(con, phone);
997
					if (user == null)
998
						throw new RuntimeException("not fonud  with query user by phone");
999
					exists = true;
1000
					uid = user.getId();
1001
				} else {
1002
					throw e;
1003
				}
1004
			}
1005
			if (exists) {
1006
				Professor professor = this.professorDao.query(con, uid);
1007
				if (professor == null) {
1008
					professor = new Professor();
1009
					professor.setId(uid);
1010
					professor.setName(name);
1011
					professor.setPhone(phone);
1012
					this.professorService.insert(con, professor, null);
1013
				} else {
1014
					name = professor.getName();
1015
				}
1016
			} else {
1017
				Professor professor = new Professor();
1018
				professor.setId(uid);
1019
				professor.setName(name);
1020
				professor.setPhone(phone);
1021
				this.professorService.insert(con, professor, null);
1022
				if (inviterId != null) {
1023
					this.growthLogService.invite(con, inviterId, uid);
1024
				}
1025
			}
1026
			return this.paperAuthorDao.update(con, paper, uid, name) > 0;
1027
1028
		} finally {
1029
			JfwAppContext.removeCachedObject(state);
1030
		}
1031
	}
1032
871
	/**
1033
	/**
872
	 * 邮箱验证并注册
1034
	 * 邮箱验证并注册
873
	 * 
1035
	 * 
1288
	}
1450
	}
1289
1451
1290
	@SetCookie(checkResultNull = true, path = "/", value = { "userid=result.getId()", "userMobilePhone=result.getMobilePhone()", "userType=result.getType()",
1452
	@SetCookie(checkResultNull = true, path = "/", value = { "userid=result.getId()", "userMobilePhone=result.getMobilePhone()", "userType=result.getType()",
1291
			"userEmail=result.getEmail()==null?\"\":result.getEmail()","authentication=result.getAuthentication()==null?\"\":result.getAuthentication()",
1453
			"userEmail=result.getEmail()==null?\"\":result.getEmail()", "authentication=result.getAuthentication()==null?\"\":result.getAuthentication()",
1292
			"userAuth=String.valueOf(result.isAuth())", "userName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
1454
			"userAuth=String.valueOf(result.isAuth())", "userName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
1293
	@Post
1455
	@Post
1294
	@Path("/invitelogin")
1456
	@Path("/invitelogin")
1308
		ret.setEmail(user.getEmail());
1470
		ret.setEmail(user.getEmail());
1309
		if (professor != null) {
1471
		if (professor != null) {
1310
			ret.setName(professor.getName());
1472
			ret.setName(professor.getName());
1311
			ret.setAuthentication(professor.getAuthentication()+"");
1473
			ret.setAuthentication(professor.getAuthentication() + "");
1312
		}
1474
		}
1313
		ret.setAuth(!DEFAULT_PASS_WORD.equals(user.getPasswd()));
1475
		ret.setAuth(!DEFAULT_PASS_WORD.equals(user.getPasswd()));
1314
		return ret;
1476
		return ret;
1315
	}
1477
	}
1316
1478
1317
	@SetCookie(checkResultNull = true, path = "/", value = { "userid=result.getId()", "userMobilePhone=result.getMobilePhone()", "userType=result.getType()",
1479
	@SetCookie(checkResultNull = true, path = "/", value = { "userid=result.getId()", "userMobilePhone=result.getMobilePhone()", "userType=result.getType()",
1318
			"userEmail=result.getEmail()==null?\"\":result.getEmail()","authentication=result.getAuthentication()==null?\"\":result.getAuthentication()",
1480
			"userEmail=result.getEmail()==null?\"\":result.getEmail()", "authentication=result.getAuthentication()==null?\"\":result.getAuthentication()",
1319
			"userAuth=String.valueOf(result.isAuth())", "userName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
1481
			"userAuth=String.valueOf(result.isAuth())", "userName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
1320
	@Post
1482
	@Post
1321
	@Path("/slogin")
1483
	@Path("/slogin")
1331
		ret.setMobilePhone(mobile);
1493
		ret.setMobilePhone(mobile);
1332
		ret.setType(user.getUserType());
1494
		ret.setType(user.getUserType());
1333
		ret.setEmail(user.getEmail());
1495
		ret.setEmail(user.getEmail());
1334
		if(professor != null){
1496
		if (professor != null) {
1335
			ret.setName(professor.getName());
1497
			ret.setName(professor.getName());
1336
			ret.setAuthentication(professor.getAuthentication()+"");
1498
			ret.setAuthentication(professor.getAuthentication() + "");
1337
		}
1499
		}
1338
		ret.setAuth(!DEFAULT_PASS_WORD.equals(user.getPasswd()));
1500
		ret.setAuth(!DEFAULT_PASS_WORD.equals(user.getPasswd()));
1339
		return ret;
1501
		return ret;
1340
	}
1502
	}
1341
1503
1342
	@SetCookie(checkResultNull = true, path = "/", value = { "userid=result.getId()", "userMobilePhone=result.getMobilePhone()", "userType=result.getType()",
1504
	@SetCookie(checkResultNull = true, path = "/", value = { "userid=result.getId()", "userMobilePhone=result.getMobilePhone()", "userType=result.getType()",
1343
			"userEmail=result.getEmail()==null?\"\":result.getEmail()","authentication=result.getAuthentication()==null?\"\":result.getAuthentication()",
1505
			"userEmail=result.getEmail()==null?\"\":result.getEmail()", "authentication=result.getAuthentication()==null?\"\":result.getAuthentication()",
1344
			"userAuth=String.valueOf(result.isAuth())", "userName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
1506
			"userAuth=String.valueOf(result.isAuth())", "userName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
1345
	@Post
1507
	@Post
1346
	@Path("/login")
1508
	@Path("/login")
1358
		Professor pf = this.professorDao.query(con, user.getId());
1520
		Professor pf = this.professorDao.query(con, user.getId());
1359
		if (null != pf) {
1521
		if (null != pf) {
1360
			ret.setName(pf.getName());
1522
			ret.setName(pf.getName());
1361
			ret.setAuthentication(pf.getAuthentication()+"");
1523
			ret.setAuthentication(pf.getAuthentication() + "");
1362
		}
1524
		}
1363
		ret.setMobilePhone(user.getMobilePhone());
1525
		ret.setMobilePhone(user.getMobilePhone());
1364
		ret.setType(user.getUserType());
1526
		ret.setType(user.getUserType());
1368
	}
1530
	}
1369
1531
1370
	@SetCookie(checkResultNull = true, path = "/", value = { "userid=result.getId()", "userMobilePhone=result.getMobilePhone()", "userType=result.getType()",
1532
	@SetCookie(checkResultNull = true, path = "/", value = { "userid=result.getId()", "userMobilePhone=result.getMobilePhone()", "userType=result.getType()",
1371
			"userEmail=result.getEmail()==null?\"\":result.getEmail()","authentication=result.getAuthentication()==null?\"\":result.getAuthentication()",
1533
			"userEmail=result.getEmail()==null?\"\":result.getEmail()", "authentication=result.getAuthentication()==null?\"\":result.getAuthentication()",
1372
			"userAuth=String.valueOf(result.isAuth())", "userName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
1534
			"userAuth=String.valueOf(result.isAuth())", "userName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
1373
	@Post
1535
	@Post
1374
	@Path("/mobileLogin")
1536
	@Path("/mobileLogin")
1394
			Professor professor = this.professorDao.query(con, user.getId());
1556
			Professor professor = this.professorDao.query(con, user.getId());
1395
			if (null != professor) {
1557
			if (null != professor) {
1396
				ret.setName(professor.getName());
1558
				ret.setName(professor.getName());
1397
				ret.setAuthentication(professor.getAuthentication()+"");
1559
				ret.setAuthentication(professor.getAuthentication() + "");
1398
			}
1560
			}
1399
			ret.setMobilePhone(user.getMobilePhone());
1561
			ret.setMobilePhone(user.getMobilePhone());
1400
			ret.setType(user.getUserType());
1562
			ret.setType(user.getUserType());
1406
		}
1568
		}
1407
	}
1569
	}
1408
1570
1409
	@SetCookie(checkResultNull = true, path = "/", value = { "orgId=result.getId()", "orgType=result.getType()",
1410
			"orgAuth=String.valueOf(result.isAuth())","orgEmail=result.getEmail()==null?\"\":result.getEmail()",
1571
	@SetCookie(checkResultNull = true, path = "/", value = { "orgId=result.getId()", "orgType=result.getType()", "orgAuth=String.valueOf(result.isAuth())",
1572
			"orgEmail=result.getEmail()==null?\"\":result.getEmail()",
1411
			"orgName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
1573
			"orgName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
1412
	@Post
1574
	@Post
1413
	@Path("/orgLogin")
1575
	@Path("/orgLogin")