package net.chenlin.dp.modules.sys.controller; import com.google.code.kaptcha.Constants; import com.taobao.api.ApiException; import net.chenlin.dp.common.annotation.SysLog; import net.chenlin.dp.common.openapi4j.exception.OpenAPIException; import net.chenlin.dp.common.openapi4j.service.AcceptService; import net.chenlin.dp.common.support.orm.db.DynamicDataSource; import net.chenlin.dp.common.support.properties.GlobalProperties; import net.chenlin.dp.common.utils.MD5Utils; import net.chenlin.dp.common.utils.ShiroUtils; import net.chenlin.dp.modules.api.controller.*; import net.chenlin.dp.modules.api.dao.AcceptOrderMapper; import net.chenlin.dp.modules.api.dao.CustomerMapper; import net.chenlin.dp.modules.api.dao.SaleOrderMapper; import net.chenlin.dp.modules.api.service.CustomerService; import net.chenlin.dp.modules.api.service.PayrequestService; import net.chenlin.dp.modules.api.service.PurchaseOrderService; import net.chenlin.dp.modules.api.service.SaleOrderService; import net.chenlin.dp.modules.api.vo.*; import net.chenlin.dp.modules.sys.service.SysUserService; import net.chenlin.dp.modules.sys.service.impl.SysUserServiceImpl; import org.apache.commons.lang.StringUtils; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 用户controller * @author zcl */ @Controller public class SysLoginController extends AbstractController { @Autowired private SysUserService sysUserService; @Autowired private GlobalProperties globalProperties; /** * 跳转登录页面 * @return */ @RequestMapping(value = "/login", method = RequestMethod.GET) public String toLogin() { if (ShiroUtils.isLogin() || ShiroUtils.getUserEntity() != null) { return redirect("/"); } return html("/login"); } /** * 登录 */ @SysLog("登录") @RequestMapping(value = "/login", method = RequestMethod.POST) public String login(Model model) throws OpenAPIException, ApiException { String username = getParam("username").trim(); String password = getParam("password").trim(); Mapmap=new HashMap<>(); SaleOrderService service=new SaleOrderService(); service.getToaccount(); service.IKSDDKOrder(); //saleOrderController.SaleOrderBJ(); // try { // // 开启验证码 // if (globalProperties.isKaptchaEnable()) { // String code = getParam("code").trim(); // if (StringUtils.isBlank(code)) { // model.addAttribute("errorMsg", "验证码不能为空"); // return html("/login"); // } // String kaptcha = ShiroUtils.getKaptcha(Constants.KAPTCHA_SESSION_KEY); // if (!code.equalsIgnoreCase(kaptcha)) { // model.addAttribute("errorMsg", "验证码错误"); // return html("/login"); // } // } // // 用户名验证 // if (StringUtils.isBlank(username)) { // model.addAttribute("errorMsg", "用户名不能为空"); // return html("/login"); // } // // 密码验证 // if (StringUtils.isBlank(password)) { // model.addAttribute("errorMsg", "密码不能为空"); // return html("/login"); // } // UsernamePasswordToken token = new UsernamePasswordToken(username, MD5Utils.encrypt(username, password)); // ShiroUtils.getSubject().login(token); // SecurityUtils.getSubject().getSession().setAttribute("sessionFlag", true); // return redirect("/"); // } catch (UnknownAccountException | IncorrectCredentialsException | LockedAccountException e) { // model.addAttribute("errorMsg", e.getMessage()); // } catch (AuthenticationException e) { // model.addAttribute("errorMsg", "登录服务异常"); // } return html("/login"); } /** * 跳转后台控制台 * @return */ @RequestMapping(value = "/", method = RequestMethod.GET) public String index() { return html("/index"); } /** * 退出 */ @SysLog("退出系统") @RequestMapping(value = "/logout", method = RequestMethod.GET) public String logout() { ShiroUtils.logout(); return html("/login"); } }