package com.ks.daylucky.controller.admin; import com.ks.lucky.exception.LuckySponsorException; import com.ks.lucky.pojo.DO.LuckySponsors; import com.ks.lucky.remote.service.LuckySponsorService; import org.apache.dubbo.config.annotation.Reference; import org.springframework.stereotype.Controller; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.yeshi.utils.JsonUtil; import javax.servlet.http.HttpSession; import javax.validation.constraints.NotEmpty; import java.util.Date; @Controller @RequestMapping("/admin/api/user") public class AdminUserController { @Reference(version = "1.0.0") private LuckySponsorService luckySponsorService; @ResponseBody @RequestMapping("login") public String login(@NotEmpty(message = "账号不能为空") String account, @NotEmpty(message = "密码不能为空") String pwd, BindingResult bindingResult, HttpSession session) { if (bindingResult.hasErrors()) { String msg = bindingResult.getFieldError().getDefaultMessage(); return JsonUtil.loadFalseResult(msg); } LuckySponsors sponsors = luckySponsorService.getSponsorByAccount(account); if (sponsors == null) { return JsonUtil.loadFalseResult("赞助商不存在"); } if (!sponsors.getPwd().equalsIgnoreCase(pwd)) { return JsonUtil.loadFalseResult("用户名账号或密码错误"); } LuckySponsors update = new LuckySponsors(); update.setId(sponsors.getId()); update.setLatestLoginTime(new Date()); try { luckySponsorService.updateSponsor(update); } catch (LuckySponsorException e) { e.printStackTrace(); } session.setAttribute("SPONSOR_LOGIN", sponsors); return JsonUtil.loadTrueResult("登录成功"); } }