|  |  |  | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | import com.core.common.R; | 
|---|
|  |  |  | import com.core.exception.CoolException; | 
|---|
|  |  |  | import com.zy.crm.manager.service.SmsCodeService; | 
|---|
|  |  |  | import com.zy.crm.manager.utils.SmsUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | 
|---|
|  |  |  | private RolePermissionService rolePermissionService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private HostService hostService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SmsCodeService smsCodeService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping("/login.action") | 
|---|
|  |  |  | @ManagerAuth(value = ManagerAuth.Auth.NONE, memo = "登录") | 
|---|
|  |  |  | @ManagerAuth(value = ManagerAuth.Auth.NONE, memo = "密码登录") | 
|---|
|  |  |  | public R loginAction(String username, String password){ | 
|---|
|  |  |  | if (username.equals("super") && password.equals(Cools.md5(superPwd))) { | 
|---|
|  |  |  | Map<String, Object> res = new HashMap<>(); | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok(res); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping("/smsLogin.action") | 
|---|
|  |  |  | @ManagerAuth(value = ManagerAuth.Auth.NONE, memo = "短信登录") | 
|---|
|  |  |  | public R smsLoginAction(String phone, String code){ | 
|---|
|  |  |  | EntityWrapper<User> userWrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | userWrapper.eq("mobile", phone); | 
|---|
|  |  |  | User user = userService.selectOne(userWrapper); | 
|---|
|  |  |  | if (Cools.isEmpty(user)){ | 
|---|
|  |  |  | return R.parse(CodeRes.USER_10001); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (user.getStatus()!=1){ | 
|---|
|  |  |  | return R.parse(CodeRes.USER_10002); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | boolean verify = smsCodeService.verifySmsCode(phone, code); | 
|---|
|  |  |  | if (!verify) { | 
|---|
|  |  |  | return R.parse(CodeRes.USER_10005); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String token = Cools.enToken(System.currentTimeMillis() + phone, code); | 
|---|
|  |  |  | userLoginService.delete(new EntityWrapper<UserLogin>().eq("user_id", user.getId())); | 
|---|
|  |  |  | UserLogin userLogin = new UserLogin(); | 
|---|
|  |  |  | userLogin.setUserId(user.getId()); | 
|---|
|  |  |  | userLogin.setToken(token); | 
|---|
|  |  |  | userLogin.setCreateTime(new Date()); | 
|---|
|  |  |  | if (user.getRoleId() == 1) { | 
|---|
|  |  |  | userLogin.setHostId(hostService.getTop1().getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | userLoginService.insert(userLogin); | 
|---|
|  |  |  | Map<String, Object> res = new HashMap<>(); | 
|---|
|  |  |  | res.put("username", user.getUsername()); | 
|---|
|  |  |  | res.put("nickname", user.getNickname()); | 
|---|
|  |  |  | res.put("token", token); | 
|---|
|  |  |  | return R.ok(res); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping("/show/host.action") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R showHosts() { | 
|---|