package com.matrix.system.common.actions;
|
|
import com.matrix.component.tools.WxTempLateMsgUtil;
|
import com.matrix.core.constance.MatrixConstance;
|
import com.matrix.core.constance.SystemErrorCode;
|
import com.matrix.core.exception.GlobleException;
|
import com.matrix.core.pojo.AjaxResult;
|
import com.matrix.core.tools.*;
|
import com.matrix.core.web.BaseAction;
|
import com.matrix.system.common.authority.DefaultAuthorityManager;
|
import com.matrix.system.common.authority.strategy.AccountPasswordLogin;
|
import com.matrix.system.common.authority.strategy.LoginStrategy;
|
import com.matrix.system.common.authority.strategy.ScanQrCodeLogin;
|
import com.matrix.system.common.bean.SysCompany;
|
import com.matrix.system.common.bean.SysUsers;
|
import com.matrix.system.common.constance.AppConstance;
|
import com.matrix.system.common.dao.ProjExceptionDao;
|
import com.matrix.system.common.dao.SysCompanyDao;
|
import com.matrix.system.common.dto.WebLoginDto;
|
import com.matrix.system.common.interceptor.HostInterceptor;
|
import com.matrix.system.common.service.SysUsersService;
|
import com.matrix.system.hive.dao.SysShopInfoDao;
|
import com.matrix.system.hive.statistics.StatisticsBusinessDataJob;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.security.Key;
|
import java.util.Map;
|
import java.util.Objects;
|
|
/**
|
* @description 通用控制器,本action未经session过验证器
|
* @author 姜友瑶
|
* @email 935090232@qq.com
|
* @date 2016-06-26
|
*/
|
@RequestMapping(value = "/common")
|
@Controller
|
@CrossOrigin(origins = "*", maxAge = 3600)
|
public class CommonAction extends BaseAction {
|
|
@Autowired
|
public ProjExceptionDao projExceptionDao;
|
|
|
/**
|
* 管理员主页
|
*/
|
private static final String ADMIN_REDIRECT_INDEX = "admin/redirect/index";
|
|
private static final String HIVE_MOBILE_REDIRECT_INDEX = "admin/redirect/hive/mobile/CRM?foot=3";
|
|
@Autowired
|
StatisticsBusinessDataJob sjobp;
|
@RequestMapping(value = "/job")
|
public @ResponseBody String job() {
|
//sjobp.executeExt2();
|
return "1";
|
}
|
|
@Autowired
|
SysUsersService sysUsersService;
|
|
@Autowired
|
DefaultAuthorityManager authorityManager;
|
|
@Autowired
|
SysShopInfoDao sysShopInfoDao;
|
|
@Autowired
|
SysCompanyDao sysCompanyDao;
|
|
/**
|
* 页面定向方法,每个权限模块公用一个,每个模块共享一个一级路径,已便于进行权限过滤
|
* @date 2016年8月30日
|
*/
|
@RequestMapping(value = "/redirect/{page1}/{page2}")
|
public String redirect(@PathVariable("page1") String page1, @PathVariable("page2") String page2) {
|
return "common/" + page1 + "/" + page2;
|
}
|
|
|
|
@RequestMapping(value = "/msg")
|
public void sendOrderDeliveryNotice(String openId, String page, String formId) {
|
WxTempLateMsgUtil.sendOrderDeliveryNotice("123","舒肤佳","湖南省长沙市岳麓区五矿科技产业园","顺丰","20120391203",openId,page,formId);
|
}
|
|
/**
|
*
|
* 页面定向方法,每个权限模块公用一个,每个模块共享一个一级路径,已便于进行权限过滤
|
* @date 2016年8月30日
|
*/
|
@RequestMapping(value = "/redirect/{page1}")
|
public String redirect(@PathVariable("page1") String page1) {
|
return "common/" + page1;
|
}
|
|
/**
|
*
|
* 登录验证
|
* @author:姜友瑶
|
* @return 返回类型 AjaxResult
|
* @date 2016年8月30日
|
*/
|
@RequestMapping(value = "/dologin")
|
public @ResponseBody AjaxResult dologin(WebLoginDto webLoginDto) {
|
|
long sqlStart = System.currentTimeMillis();
|
SysUsers user=null;
|
if(WebLoginDto.ACCOUNT_LOGIN.equals(webLoginDto.getLoginType())){
|
user= decryptAccountAndPassword(webLoginDto);
|
LoginStrategy apLogin = new AccountPasswordLogin(user, sysUsersService);
|
user = authorityManager.login(apLogin);
|
}else {
|
ScanQrCodeLogin apLogin = new ScanQrCodeLogin( sysUsersService,webLoginDto.getLoginQrCodeKey());
|
user = authorityManager.login(apLogin);
|
}
|
|
|
if(user.getShopId()!=null){
|
user.setShopName(sysShopInfoDao.selectById(user.getShopId()).getShopName());
|
}
|
AjaxResult result = new AjaxResult();
|
authorityManager.initUserPower(result);
|
|
SysCompany sysCompany = sysCompanyDao.selectById(user.getCompanyId());
|
WebUtil.setSessionAttribute(HostInterceptor.ATTR_COMPANY, sysCompany);
|
|
result.putInMap("user",user);
|
result.setStatus(AjaxResult.STATUS_SUCCESS);
|
LogUtil.info("#用户登录成功 账号={}#", user.getSuAccount());
|
switch (user.getSuUserType()) {
|
// 开发人员
|
case AppConstance.USER_TYPE_DEVELOPER:
|
result.setPage("developer/redirect/index");
|
break;
|
// 超级管理员
|
case AppConstance.USER_TYPE_SUPER:
|
result.setPage("super/redirect/index");
|
break;
|
// 企业管理员
|
case AppConstance.USER_TYPE_ADMIN:
|
result.setPage(ADMIN_REDIRECT_INDEX);
|
break;
|
// 企业用户
|
case AppConstance.USER_TYPE_EMPLOYEE:
|
result.setPage(ADMIN_REDIRECT_INDEX);
|
break;
|
// 普通用户
|
case AppConstance.USER_TYPE_CUSTIMER:
|
result.setPage(ADMIN_REDIRECT_INDEX);
|
break;
|
default:// 不能识别的用户
|
result.setPage("common/redirect/404");
|
}
|
long endStart = System.currentTimeMillis();
|
LogUtil.info("本次登录耗时#{}毫秒", (endStart-sqlStart)+"");
|
return result;
|
}
|
|
/**
|
* 对用户账号密码进行解密
|
*
|
* @author JIANGYOUYAO
|
* @email 935090232@qq.com
|
* @date 2017年12月11日
|
*/
|
private SysUsers decryptAccountAndPassword(WebLoginDto webLoginDto) {
|
|
String privateKey = WebUtil.getSessionAttribute(MatrixConstance.PRIVATE_KEY);
|
if (StringUtils.isBlank(privateKey)) {
|
throw new GlobleException(SystemErrorCode.REQUEST_INVALID);
|
}
|
SysUsers user=new SysUsers();
|
try {
|
// 账号解密
|
byte[] acccountData = RSAUtils.decryptByPrivateKey(webLoginDto.getSuAccount(), privateKey);
|
user.setSuAccount(new String(acccountData));
|
// 密码解密
|
byte[] passWordData = RSAUtils.decryptByPrivateKey(webLoginDto.getSuPassword(), privateKey);
|
user.setSuPassword(new String(passWordData));
|
|
} catch (Exception e) {
|
LogUtil.error("用户账号密码解密失败", e);
|
throw new GlobleException(SystemErrorCode.LOGIN_FAIL);
|
}
|
return user;
|
}
|
|
|
/**
|
*
|
* 用户退出系统
|
* @author:姜友瑶
|
* @return
|
* @throws Exception
|
* 返回类型 String
|
* @date 2016年11月15日
|
*/
|
@GetMapping(value = "/loginOut")
|
public String loginOut() {
|
authorityManager.getLoginOut();
|
return "redirect:/common/toLogin";
|
}
|
|
/**
|
* 进入登录界面
|
*
|
* @author JIANGYOUYAO
|
* @email 935090232@qq.com
|
* @date 2017年12月11日
|
* @return
|
* @throws Exception
|
*/
|
@GetMapping(value = "/toLogin")
|
public String toLogin() {
|
if(WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY)!=null){
|
return "redirect:/"+ADMIN_REDIRECT_INDEX;
|
}else {
|
// 初始化登录密钥
|
Map<String, Key> keyMap;
|
try {
|
keyMap = RSAUtils.initKey();
|
String publicKey = RSAUtils.getPublicKey(keyMap);
|
String privateKey = RSAUtils.getPrivateKey(keyMap);
|
WebUtil.setSessionAttribute(MatrixConstance.PUPBLIC_KEY, publicKey);
|
WebUtil.setSessionAttribute(MatrixConstance.PRIVATE_KEY, privateKey);
|
} catch (Exception e) {
|
LogUtil.error("#初始化登录加密秘钥错误#", e);
|
throw new GlobleException(SystemErrorCode.SYSTEM_RUNNING_ERROR);
|
}
|
return "common/login";
|
}
|
}
|
|
|
@GetMapping(value = "/hmlogin")
|
public String toMobileLogin() {
|
if(WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY)!=null){
|
return "redirect:/"+HIVE_MOBILE_REDIRECT_INDEX;
|
}else{
|
// 初始化登录密钥
|
Map<String, Key> keyMap;
|
try {
|
keyMap = RSAUtils.initKey();
|
String publicKey = RSAUtils.getPublicKey(keyMap);
|
String privateKey = RSAUtils.getPrivateKey(keyMap);
|
WebUtil.setSessionAttribute(MatrixConstance.PUPBLIC_KEY, publicKey);
|
WebUtil.setSessionAttribute(MatrixConstance.PRIVATE_KEY, privateKey);
|
} catch (Exception e) {
|
LogUtil.error("#初始化登录加密秘钥错误#", e);
|
throw new GlobleException(SystemErrorCode.SYSTEM_RUNNING_ERROR);
|
}
|
return "admin/hive/mobile/mobileLogin";
|
}
|
|
}
|
|
@GetMapping(value = "/hiveMobileLoginOut")
|
public String hiveMobileLoginOut() {
|
authorityManager.getLoginOut();
|
return "redirect:/common/hmlogin";
|
}
|
|
|
|
|
|
/**
|
* 官网联系我们通知
|
*/
|
@RequestMapping(value = "/gwLinkUs")
|
public @ResponseBody
|
AjaxResult gwLinkUs(@RequestBody Map<String , Object> param) {
|
|
String title = "hive新客户在官网提交联系请求";
|
if(Objects.nonNull(param.get("name"))){
|
String content = "hive=>name:" + param.get("name") + " tel:" + param.get("tel") ;
|
DingDingRobotUtil.sendLink("https://oapi.dingtalk.com/robot/send?access_token=62bb902f0e3945f0ece31306b99abae043fc69a66da0ef04d89fd20bf58d88d8", content, title, "", "www.baidu.com");
|
|
}
|
|
return AjaxResult.buildSuccessInstance("提交成功");
|
}
|
|
|
|
}
|