No Description

ProfessorService.java 9.8KB

    package com.ekexiu.console.system.service; import com.ekexiu.console.system.dao.LuserDao; import com.ekexiu.console.system.dao.OrgDao; import com.ekexiu.console.system.dao.ProfessorDao; import com.ekexiu.console.system.po.Luser; import com.ekexiu.console.system.po.Professor; import com.ekexiu.console.system.pojo.ProfessorInfo; import com.ekexiu.console.system.pojo.UserDetail; import com.ekexiu.console.system.vo.ConsoleAuthUser; import org.jfw.apt.annotation.Autowrie; import org.jfw.apt.annotation.DefaultValue; import org.jfw.apt.annotation.Nullable; import org.jfw.apt.web.annotation.LoginUser; 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.DateUtil; import org.jfw.util.PageQueryResult; import org.jfw.util.StringUtil; import org.jfw.util.exception.JfwBaseException; import java.io.IOException; import java.sql.Connection; import java.sql.SQLException; import java.util.Objects; import java.util.Random; /** * Created by TT on 2017/5/25. */ @Path("/sys/professor") public class ProfessorService { public static final String DEFAULT_PASS_WORD = "11111111111111111111111111111111"; @Autowrie private ProfessorDao professorDao; @Autowrie private OrgDao orgDao; @Autowrie private OrgService orgService; @Autowrie private LuserDao luserDao; public OrgService getOrgService() { return orgService; } public void setOrgService(OrgService orgService) { this.orgService = orgService; } public OrgDao getOrgDao() { return orgDao; } public void setOrgDao(OrgDao orgDao) { this.orgDao = orgDao; } public ProfessorDao getProfessorDao() { return professorDao; } public void setProfessorDao(ProfessorDao professorDao) { this.professorDao = professorDao; } public LuserDao getLuserDao() { return luserDao; } public void setLuserDao(LuserDao luserDao) { this.luserDao = luserDao; } @Post @Path public String insert(@JdbcConn(true) Connection con, Professor professor, @Nullable String orgName) throws SQLException, IOException { if (professor.getId() == null) { professor.setId(StringUtil.buildUUID()); } if (professor.getOrgId() == null && orgName != null) { if (null != this.orgDao.queryByName(con, orgName)) { professor.setOrgId(this.orgDao.queryByName(con, orgName)); } else { professor.setOrgId(this.orgService.createOrganization(con, orgName)); } } if (professor.getOrgAuth() == null) { professor.setOrgAuth("0"); } this.professorDao.insert(con, professor); return professor.getId(); } @Put @Path public void update(@JdbcConn(true) Connection con, @RequestBody Professor professor) throws SQLException, IOException { this.professorDao.update(con, professor); } @Get @Path("/pq") public PageQueryResult<ProfessorInfo> pageQuery(@JdbcConn Connection con, @Nullable String enter,@Nullable String orgName, @Nullable String name, @Nullable Integer professorState, @Nullable String bt, @Nullable String et, @DefaultValue("10") int pageSize, @DefaultValue("1") int pageNo) throws SQLException { String oName = null; if (orgName != null) { oName = "%" + orgName + "%"; } String pname = null; if (name != null) { pname = "%" + name + "%"; } if (et!=null) { et = et + "235959"; } return this.professorDao.pageQuery(con,enter, oName, pname, professorState, bt, et, pageSize, pageNo); } @Get @Path("/id/{id}") public ProfessorInfo query(@JdbcConn Connection con,@PathVar String id) throws SQLException { return this.professorDao.query(con, id); } @Post @Path("/sortFirst") public void updateSortFirst(@JdbcConn(true) Connection con,String id,Integer sortFirst)throws SQLException { this.professorDao.updateSortFirst(con, id, sortFirst); } @Get @Path("/pqperson") public PageQueryResult<ProfessorInfo> pageQueryPerson(@JdbcConn Connection con, @LoginUser ConsoleAuthUser cau,@Nullable String orgName, @Nullable String name, @Nullable Integer professorState,@Nullable String bt, @Nullable String et, @DefaultValue("10") int pageSize, @DefaultValue("1") int pageNo) throws SQLException { String oName = null; if (orgName != null) { oName = "%" + orgName + "%"; } String pname = null; if (name != null) { pname = "%" + name + "%"; } if (bt != null) bt = bt + "000000"; if (et != null) et = et + "235959"; return this.professorDao.pageQueryPerson(con,cau.getId(),oName, pname, professorState, bt, et, pageSize, pageNo); } @Post @Path("/check") public void check(@JdbcConn(true) Connection con, String[] ids, Integer professorState, Integer authType, Integer authStatusExpert)throws SQLException { this.professorDao.updateProfessorState(con, ids, professorState); this.professorDao.updateAuthType(con, ids, authType); this.professorDao.updateAuthStatusExpert(con, ids, authStatusExpert); } @Get @Path("/getName/{id}") public String getName(@JdbcConn Connection con,@PathVar String id) throws SQLException { return this.professorDao.queryById(con, id); } @Get @Path("/pqUserDetail") public PageQueryResult<UserDetail> userDetailPageQueryResult(@JdbcConn Connection con, @Nullable String name, @Nullable String bt, @Nullable String et, @DefaultValue("10") int pageSize, @DefaultValue("1") int pageNo)throws SQLException { return this.professorDao.pageQueryUserDetail(con, name == null ? null : "%" + name + "%", bt, et, pageSize, pageNo); } @Post @Path("/updateBusinessData") public void updateBusinessData(@JdbcConn(true) Connection con,String id,@Nullable int authentication,@Nullable int authStatus,@Nullable int authStatusExpert,int sortFirst)throws SQLException{ this.professorDao.updateBusinessData(con, id, authentication, authStatus, authStatusExpert, sortFirst); } @Path("/createCheck") @Get public boolean entryCheck(@JdbcConn Connection con, @Nullable String mobile, @Nullable String email) throws SQLException { Luser luser1 = this.luserDao.check(con, mobile); Luser luser2 = this.luserDao.check(con, email); return luser1 == null && luser2 == null; } @Path("/updateCheck") @Get public int editCheck(@JdbcConn Connection con,@Nullable String mobile, @Nullable String email,String id) throws SQLException { String luserId = this.luserDao.queryByEmail(con, email); if ((luserId != null)&&(!Objects.equals(luserId, id))) { return 2;//该邮箱已被注册 } String luserId1 = this.luserDao.queryByPhone(con, mobile); if ((luserId1 != null) && (!Objects.equals(luserId1, id))) { return 3;//该手机已被注册 } return 1; } @Post @Path("/createAccount") public void insert(@JdbcConn(true) Connection con,String name, @Nullable String mobile,@Nullable String email)throws SQLException,JfwBaseException { String luserId = this.luserDao.queryByEmail(con, email); if (luserId != null) { throw new JfwBaseException(40001, "邮箱已被注册"); } String luserId1 = this.luserDao.queryByPhone(con, mobile); if (luserId1 != null) { throw new JfwBaseException(40002, "该电话已被注册"); } String id = StringUtil.buildUUID(); Luser luser = new Luser(); luser.setId(id); Random rd = new Random(); int code = rd.nextInt(1000000); String inviteCode = String.format("%06d", code); luser.setInviteCode(inviteCode); luser.setEmail(email); luser.setMobilePhone(mobile); luser.setPasswd(DEFAULT_PASS_WORD); luser.setUserType("0"); luser.setCreateTime(DateUtil.formatDateTime(System.currentTimeMillis())); this.luserDao.insert(con, luser); Professor professor = new Professor(); professor.setId(id); professor.setName(name); professor.setEmail(email); professor.setPhone(mobile); professor.setAuthType(1); professor.setAuthStatus(0); professor.setAuthStatusExpert(0); professor.setSortFirst(0); professor.setProfessorState(0); professor.setAuthentication(0); professor.setOrgAuth("0"); this.professorDao.insert(con, professor); } @Post @Path("/updateAccount") public void updateAccount(@JdbcConn(true) Connection con,@Nullable String mobile, @Nullable String email,String id) throws SQLException, JfwBaseException { String luserId = this.luserDao.queryByEmail(con, email); if ((luserId != null)&&(!Objects.equals(luserId, id))) { throw new JfwBaseException(40001, "该邮箱已被注册"); } String luserId1 = this.luserDao.queryByPhone(con, mobile); if ((luserId1 != null) && (!Objects.equals(luserId1, id))) { throw new JfwBaseException(40002, "该电话已被注册"); } this.luserDao.updateAccount(con, id, mobile, email); } @Get @Path("/luserId/{id}") public Luser queryAccount(@JdbcConn Connection con, @PathVar String id)throws SQLException { Luser luser = this.luserDao.query(con, id); if (luser != null) { luser.setPasswd(null); } return luser; } }