package com.ekexiu.portal.service; import java.sql.Connection; import java.sql.SQLException; import java.util.Random; import org.jfw.apt.annotation.Autowrie; import org.jfw.apt.annotation.DefaultValue; import org.jfw.apt.annotation.Nullable; import org.jfw.apt.web.annotation.Path; import org.jfw.apt.web.annotation.operate.Get; import org.jfw.apt.web.annotation.operate.Post; import org.jfw.apt.web.annotation.operate.Put; import org.jfw.apt.web.annotation.param.JdbcConn; import org.jfw.apt.web.annotation.param.PathVar; import org.jfw.apt.web.annotation.param.RequestBody; import org.jfw.util.PageQueryResult; import com.ekexiu.portal.dao.ProfessorDao; import com.ekexiu.portal.dao.UserDao; import com.ekexiu.portal.po.Professor; import com.ekexiu.portal.po.User; @Path("/init") public class InitUserService { @Autowrie private UserDao userDao; @Autowrie private ProfessorDao professorDao; @Autowrie private GrowthLogService growthLogService; public UserDao getUserDao() { return userDao; } public void setUserDao(UserDao userDao) { this.userDao = userDao; } public ProfessorDao getProfessorDao() { return professorDao; } public void setProfessorDao(ProfessorDao professorDao) { this.professorDao = professorDao; } public GrowthLogService getGrowthLogService() { return growthLogService; } public void setGrowthLogService(GrowthLogService growthLogService) { this.growthLogService = growthLogService; } @Get @Path("/user/{id}") public User getUser(@JdbcConn Connection con,@PathVar String id) throws SQLException{ return this.userDao.query(con, id); } @Post @Path("/sendMailStatus") public void updateSendMailStatus(@JdbcConn(true) Connection con,String id,Integer sendMailStatus) throws SQLException{ this.userDao.updateSendMailStatus(con, sendMailStatus, id); } @Post @Path("/user") public void modifyMobilePhone(@JdbcConn(true) Connection con,String id,@Nullable String mobilePhone, @Nullable String email)throws SQLException{ Random rd = new Random(); int code = rd.nextInt(1000000); String inviteCode = String.format("%06d", code); User user = new User(); user.setId(id); user.setMobilePhone(mobilePhone); user.setEmail(email); user.setPasswd(SysService.DEFAULT_PASS_WORD); user.setUserType("0"); user.setInviteCode(inviteCode); this.userDao.insert(con, user); if(mobilePhone != null && mobilePhone.trim().length() == 11){ this.growthLogService.bindMobile(con, id); } if(email != null && !"".equals(email)){ this.growthLogService.bindEmail(con, id); } Professor professor = this.professorDao.queryOne(con, id); if(mobilePhone != null && (professor.getPhone() == null || professor.getPhone().isEmpty())){ this.professorDao.updatePhone(con, id, mobilePhone); } if(email != null && (professor.getEmail() == null || professor.getEmail().isEmpty())){ this.professorDao.updateEmail(con, id, email); } } @Put @Path("/user") public void modifyMobilePhone(@JdbcConn(true) Connection con ,@RequestBody User user)throws SQLException{ this.userDao.updateMobilePhone(con, user.getMobilePhone(), user.getId()); this.userDao.updateEmail(con, user.getEmail(), user.getId()); if(user.getMobilePhone() != null && user.getMobilePhone().trim().length() == 11){ this.growthLogService.bindMobile(con, user.getId()); } if(user.getEmail() != null && !"".equals(user.getEmail())){ this.growthLogService.bindEmail(con, user.getId()); } Professor professor = this.professorDao.queryOne(con, user.getId()); if(user.getMobilePhone() != null && (professor.getPhone() == null || professor.getPhone().isEmpty())){ this.professorDao.updatePhone(con, user.getId(), user.getMobilePhone()); } if(user.getEmail() != null && (professor.getEmail() == null || professor.getEmail().isEmpty())){ this.professorDao.updateEmail(con, user.getId(), user.getEmail()); } } @Get @Path("/pq") public PageQueryResult pageQuery(@JdbcConn Connection con,@DefaultValue("50") int pageSize,@DefaultValue("1") int pageNo)throws SQLException{ return this.userDao.pageQuery(con, pageSize, pageNo); } }