Browse Source

用户设置绑定手机号和邮箱之后,如果用户信息表没存联系方式则自动添加到信息表。

zzy.zhiyuan.foxmail 8 years ago
parent
commit
7201b70ca7

+ 8 - 0
src/main/java/com/ekexiu/portal/dao/ProfessorDao.java

40
	@Update
40
	@Update
41
	public abstract int update(Connection con, Professor professor) throws SQLException;
41
	public abstract int update(Connection con, Professor professor) throws SQLException;
42
	
42
	
43
	@UpdateWith
44
	@From(Professor.class)
45
	public abstract int updatePhone(Connection con, String id, @Set String phone) throws SQLException;
46
	
47
	@UpdateWith
48
	@From(Professor.class)
49
	public abstract int updateEmail(Connection con, String id, @Set String email) throws SQLException;
50
	
43
	@UpdateWith
51
	@UpdateWith
44
	@From(Professor.class)
52
	@From(Professor.class)
45
	public abstract int updateSortFirst(Connection con, String id, @Set Integer sortFirst) throws SQLException;
53
	public abstract int updateSortFirst(Connection con, String id, @Set Integer sortFirst) throws SQLException;

+ 38 - 2
src/main/java/com/ekexiu/portal/service/InitUserService.java

14
import org.jfw.apt.web.annotation.param.PathVar;
14
import org.jfw.apt.web.annotation.param.PathVar;
15
import org.jfw.apt.web.annotation.param.RequestBody;
15
import org.jfw.apt.web.annotation.param.RequestBody;
16
16
17
import com.ekexiu.portal.dao.ProfessorDao;
17
import com.ekexiu.portal.dao.UserDao;
18
import com.ekexiu.portal.dao.UserDao;
19
import com.ekexiu.portal.po.Professor;
18
import com.ekexiu.portal.po.User;
20
import com.ekexiu.portal.po.User;
19
21
20
@Path("/init")
22
@Path("/init")
21
public class InitUserService {
23
public class InitUserService {
22
	@Autowrie
24
	@Autowrie
23
	private UserDao userDao;
25
	private UserDao userDao;
26
	@Autowrie
27
	private ProfessorDao professorDao;
24
	
28
	
25
	
29
	
26
	public UserDao getUserDao() {
30
	public UserDao getUserDao() {
27
		return userDao;
31
		return userDao;
28
	}
32
	}
29
33
30
31
	public void setUserDao(UserDao userDao) {
34
	public void setUserDao(UserDao userDao) {
32
		this.userDao = userDao;
35
		this.userDao = userDao;
33
	}
36
	}
34
37
38
	public ProfessorDao getProfessorDao() {
39
		return professorDao;
40
	}
41
42
	public void setProfessorDao(ProfessorDao professorDao) {
43
		this.professorDao = professorDao;
44
	}
35
45
36
	@Get
46
	@Get
37
	@Path("/user/{id}")
47
	@Path("/user/{id}")
42
	@Path("/user")
52
	@Path("/user")
43
	public void modifyMobilePhone(@JdbcConn(true) Connection con,String id,@Nullable String mobilePhone,
53
	public void modifyMobilePhone(@JdbcConn(true) Connection con,String id,@Nullable String mobilePhone,
44
			@Nullable String email)throws SQLException{
54
			@Nullable String email)throws SQLException{
55
		if(mobilePhone.isEmpty()){
56
			mobilePhone = null;
57
		}
58
		if(email.isEmpty()){
59
			email = null;
60
		}
45
		Random rd = new Random();
61
		Random rd = new Random();
46
		int code = rd.nextInt(1000000);
62
		int code = rd.nextInt(1000000);
47
		String inviteCode = String.format("%06d", code);
63
		String inviteCode = String.format("%06d", code);
52
		user.setPasswd(SysService.DEFAULT_PASS_WORD);
68
		user.setPasswd(SysService.DEFAULT_PASS_WORD);
53
		user.setUserType("0");
69
		user.setUserType("0");
54
		user.setInviteCode(inviteCode);
70
		user.setInviteCode(inviteCode);
55
		this.userDao.insert(con, user);		
71
		this.userDao.insert(con, user);
72
		Professor professor = this.professorDao.queryOne(con, id);
73
		if(mobilePhone != null && (professor.getPhone() == null || professor.getPhone().isEmpty())){
74
			this.professorDao.updatePhone(con, id, mobilePhone);
75
		}
76
		if(email != null && (professor.getEmail() == null || professor.getEmail().isEmpty())){
77
			this.professorDao.updateEmail(con, id, email);
78
		}
56
	}
79
	}
57
	@Put
80
	@Put
58
	@Path("/user")
81
	@Path("/user")
59
	public void modifyMobilePhone(@JdbcConn(true) Connection con ,@RequestBody User user)throws SQLException{
82
	public void modifyMobilePhone(@JdbcConn(true) Connection con ,@RequestBody User user)throws SQLException{
83
		if(user.getMobilePhone().isEmpty()){
84
			user.setMobilePhone(null);
85
		}
86
		if(user.getEmail().isEmpty()){
87
			user.setEmail(null);
88
		}
60
		this.userDao.updateMobilePhone(con, user.getMobilePhone(), user.getId());
89
		this.userDao.updateMobilePhone(con, user.getMobilePhone(), user.getId());
61
		this.userDao.updateEmail(con, user.getEmail(), user.getId());
90
		this.userDao.updateEmail(con, user.getEmail(), user.getId());
91
		Professor professor = this.professorDao.queryOne(con, user.getId());
92
		if(user.getMobilePhone() != null && (professor.getPhone() == null || professor.getPhone().isEmpty())){
93
			this.professorDao.updatePhone(con, user.getId(), user.getMobilePhone());
94
		}
95
		if(user.getEmail() != null && (professor.getEmail() == null || professor.getEmail().isEmpty())){
96
			this.professorDao.updateEmail(con, user.getId(), user.getEmail());
97
		}
62
		Random rd = new Random();
98
		Random rd = new Random();
63
		int code = rd.nextInt(1000000);
99
		int code = rd.nextInt(1000000);
64
		String inviteCode = String.format("%06d", code);
100
		String inviteCode = String.format("%06d", code);

+ 9 - 1
src/main/java/com/ekexiu/portal/service/SysService.java

627
		if (sc.getExpiredTime() < System.currentTimeMillis())
627
		if (sc.getExpiredTime() < System.currentTimeMillis())
628
			return false;
628
			return false;
629
		try {
629
		try {
630
			Professor professor = this.professorDao.queryOne(con, sc.getKey());
631
			if(professor.getPhone() == null || professor.getPhone().isEmpty()){
632
				this.professorDao.updateEmail(con, sc.getKey(), sc.getValue());
633
			}
630
			return this.userDao.updateEmail(con, sc.getValue(), sc.getKey()) > 0;
634
			return this.userDao.updateEmail(con, sc.getValue(), sc.getKey()) > 0;
631
		} finally {
635
		} finally {
632
			JfwAppContext.removeCachedObject(key);
636
			JfwAppContext.removeCachedObject(key);
748
			if (!sc.getKey().equals(mobilePhone)
752
			if (!sc.getKey().equals(mobilePhone)
749
					|| !sc.getValue().equals(validateCode))
753
					|| !sc.getValue().equals(validateCode))
750
				return false;
754
				return false;
755
			Professor professor = this.professorDao.queryOne(con, userid);
756
			if(professor.getPhone() == null || professor.getPhone().isEmpty()){
757
				this.professorDao.updatePhone(con, userid, mobilePhone);
758
			}
751
			return this.userDao.updateMobilePhone(con, mobilePhone, userid) > 0;
759
			return this.userDao.updateMobilePhone(con, mobilePhone, userid) > 0;
752
		} finally {
760
		} finally {
753
			JfwAppContext.removeCachedObject(state);
761
			JfwAppContext.removeCachedObject(state);
909
			JfwAppContext.removeCachedObject(state);
917
			JfwAppContext.removeCachedObject(state);
910
		}
918
		}
911
	}
919
	}
912
920
	
913
	public static void main(String[] args) {
921
	public static void main(String[] args) {
914
		System.out.println(String.format("%04d", new Random().nextInt(10000)));
922
		System.out.println(String.format("%04d", new Random().nextInt(10000)));
915
	}
923
	}

+ 2 - 1
src/main/webapp/page/professor.html

687
			}
687
			}
688
688
689
			var addJob = function($data) {
689
			var addJob = function($data) {
690
				gtbody($data, $("#job_tbody"), [ "startMonth", "stopMonth:--",
690
				gtbody($data, $("#job_tbody"), [ "startMonth", "stopMonth",
691
						"company", "department", "title", "descp" ], "job");
691
						"company", "department", "title", "descp" ], "job");
692
			};
692
			};
693
			var addHonor = function($data) {
693
			var addHonor = function($data) {
930
										$("#job_startMonth").val($info.startMonth);
930
										$("#job_startMonth").val($info.startMonth);
931
										$("#job_stopMonth").val($info.stopMonth ? $info.stopMonth: "");
931
										$("#job_stopMonth").val($info.stopMonth ? $info.stopMonth: "");
932
										$("#job_company").val($info.company ? $info.company: "");
932
										$("#job_company").val($info.company ? $info.company: "");
933
										$("#job_department").val($info.department ? $info.department: "");
933
										$("#job_title").val($info.title ? $info.title: "");
934
										$("#job_title").val($info.title ? $info.title: "");
934
										$("#job_descp").val($info.descp ? $info.descp: "");
935
										$("#job_descp").val($info.descp ? $info.descp: "");
935
										$("#jobModal").modal();
936
										$("#jobModal").modal();