123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- package com.miniframe.bisiness.system;
- import com.miniframe.constant.XIConstant;
- import com.miniframe.generate.business.system.model.A00002BaseModel;
- import com.miniframe.service.LoginService;
- import com.miniframe.core.ExecProcessFlow;
- import com.miniframe.core.exception.BusinessException;
- import com.miniframe.core.ext.UtilTools;
- import com.miniframe.generate.appcode.*;
- import com.miniframe.generate.comm.system.D_A00002_FUNCLIST_RECODE;
- import com.miniframe.generate.comm.system.D_A00002_MENULIST_RECODE;
- import com.miniframe.generate.comm.system.D_A00002_ROLELIST_RECODE;
- import com.miniframe.model.XIFuncRecode;
- import com.miniframe.model.XIMenuRecode;
- import com.miniframe.model.XIRoleRecode;
- import com.miniframe.model.system.*;
- import com.miniframe.model.system.dao.SysDepartmentMapper;
- import com.miniframe.model.system.dao.SysUserMapper;
- import com.miniframe.model.system.dao.UserLoginMapper;
- import com.miniframe.spring.properties.MFMiniCoreProperties;
- import com.miniframe.tools.encode.XIDESedeCoderUtils;
- import com.miniframe.tools.XIDateTimeUtils;
- import com.miniframe.tools.XIUtils;
- import com.miniframe.tools.jwt.JwtManageUtil;
- import org.springframework.util.CollectionUtils;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.UUID;
- import java.util.stream.Collectors;
- /**
- * 基础系统,“登录”逻辑处理(重新生成不覆盖)。
- */
- public class A00002Service extends A00002BaseModel implements ExecProcessFlow {
- private static final long serialVersionUID = -7051358269847459502L;
- /**
- * 基础系统,“登录”业务核心处理
- */
- public void transExecute() throws Exception {
- String loginMedia = UtilTools.isNullOrBlank(this.getA_a00002().getLoginMedia()) ? LoginMedia.APP.getIndex() : this.getA_a00002().getLoginMedia();
- if (LoginMedia.getLoginMedia(loginMedia) == null) {
- throw new BusinessException("EB8000015");
- }
- String loginType = UtilTools.isNullOrBlank(this.getA_a00002().getType()) ? LoginType.PASSWD.getIndex() : this.getA_a00002().getType();
- if (LoginType.getLoginType(loginType) == null) {
- throw new BusinessException("EB8000015");
- }
- //0手动登录 1-自动登录
- String loginWay = UtilTools.isNullOrBlank(this.getA_a00002().getLoginWay()) ? LoginWay.MANUAL.getIndex() : this.getA_a00002().getLoginWay();
- if (LoginWay.getLoginWay(loginWay) == null) {
- throw new BusinessException("EB8000015");
- }
- SysUser sysUser;
- SysUserMapper sysUserDAO = UtilTools.getBean(SysUserMapper.class);
- if (loginWay.equals(LoginWay.MANUAL.getIndex())) { //手动登录
- if (UtilTools.isNotNullAndBlank(this.getA_a00002().getAuthCode())) {
- //验证图片
- LoginService.validateGraph(this.getA_a00002().getAuthCode(), this.getA_systemhead().getClientToken());
- }
- //本地是否存在
- SysUserSQLBuilder sysUserSQLBuilder = new SysUserSQLBuilder();
- String loginName = this.getA_a00002().getLoginName().trim();
- //先使用loginName查询用户,再用手机号查询
- sysUserSQLBuilder.createCriteria().andUserstateNotEqualTo(UserState.delete.getIndex()).andUsernameEqualTo(loginName);
- List<SysUser> userInfoList = sysUserDAO.selectByExample(sysUserSQLBuilder);
- if (CollectionUtils.isEmpty(userInfoList)) {
- //再用手机号查询
- sysUserSQLBuilder = new SysUserSQLBuilder();
- sysUserSQLBuilder.createCriteria().andUsermobnubEqualTo(loginName);
- userInfoList = sysUserDAO.selectByExample(sysUserSQLBuilder);
- if (CollectionUtils.isEmpty(userInfoList)) {
- // 不存在就报错
- throw new BusinessException("EB8000015");
- }
- }
- sysUser = userInfoList.get(0);
- } else {
- sysUser = sysUserDAO.selectByPrimaryKey(this.getA_systemhead().getUserId());
- if (sysUser == null) {
- throw new BusinessException("EB8000015");
- }
- }
- UserLoginMapper userLoginDAO = UtilTools.getBean(UserLoginMapper.class);
- UserLogin userLogin = new UserLogin();
- userLogin.setId(UtilTools.getUUid());
- userLogin.setUid(sysUser.getId());
- userLogin.setLoginName(this.getA_a00002().getLoginName());
- userLogin.setLoginTime(XIDateTimeUtils.getNowDate());
- userLogin.setLoginIp(XIUtils.getClientIp());
- userLogin.setWrongTimes(0);
- userLogin.setLoginType(LoginType.getLoginType(loginType).getDesc());
- userLogin.setLoginWay(LoginWay.getLoginWay(loginWay).getDesc()); //0手动登录 1-自动登录
- userLogin.setLoginMedia(LoginMedia.getLoginMedia(loginMedia).getDesc());
- userLogin.setCreateTime(XIDateTimeUtils.getNowDate());
- userLogin.setUpdateTime(userLogin.getCreateTime());
- userLogin.setStatus(Loginflag.sucess.getIndex()); //默认登录成功
- userLogin.setLoginCode(XIUtils.getNormalReturnCode());
- userLogin.setLoginMsg(Loginflag.sucess.getDesc());
- if (loginWay.equals(LoginWay.MANUAL.getIndex())) { //手动登录
- if (LoginType.PASSWD.getIndex().equals(loginType)) {// 密码登录
- String password_ = XIDESedeCoderUtils.dec(this.getA_a00002().getPassword(), this.getA_systemhead().getClientToken());//3DES解密
- if (!LoginService.encodePassword(sysUser.getId(), password_).equals(sysUser.getUserpwd())) {//比较密码是否相同
- userLogin.setStatus(Loginflag.fail.getIndex());
- userLogin.setLoginCode("EB8000015");
- userLogin.setLoginMsg(UtilTools.getText(userLogin.getLoginCode()));
- userLoginDAO.insertSelective(userLogin);
- throw new BusinessException(userLogin.getLoginCode());
- }
- } else if (LoginType.VERIFYCODE.getIndex().equals(loginType)) {// 验证码登录
- // if (!IdentifyingCodeUtil.verification(this.getA_a00002().getPhoneNo(), this.getA_a00002().getAuthCode())) {
- // // 验证码校验失败!
- // throw new BusinessException("EB8000021");
- // }
- }
- } else { //自动登录,验证clientToken
- boolean isCheckJwtToken=false;
- try {
- isCheckJwtToken=LoginService.checkJwtTokenForUser(this.getA_systemhead().getUserId(), this.getA_systemhead().getClientToken());
- }catch (Exception e){}
- if (!isCheckJwtToken) {
- userLogin.setStatus("1");
- userLogin.setLoginCode("EB8000015");
- userLogin.setLoginMsg(UtilTools.getText(userLogin.getLoginCode()));
- userLoginDAO.insertSelective(userLogin);
- throw new BusinessException(userLogin.getLoginCode());
- }
- }
- if (sysUser.getUserstate().equals(UserState.delete.getIndex())) {
- userLogin.setStatus(Loginflag.fail.getIndex());
- userLogin.setLoginCode("EB8000015");
- userLogin.setLoginMsg(UtilTools.getText(userLogin.getLoginCode()));
- userLoginDAO.insertSelective(userLogin);
- throw new BusinessException(userLogin.getLoginCode());
- }
- if (sysUser.getUserstate().equals(UserState.black.getIndex())) {
- userLogin.setStatus(Loginflag.fail.getIndex());
- userLogin.setLoginCode("EB8000104");
- userLogin.setLoginMsg(UtilTools.getText(userLogin.getLoginCode()));
- userLoginDAO.insertSelective(userLogin);
- throw new BusinessException(userLogin.getLoginCode());
- }
- // //用户是否可用此登录渠道进行登录权限判断
- // if (!XIUtils.getListFromStrDelEmpty(sysUser.getFuncids()).stream()
- // .anyMatch(func -> func.equals(LoginMedia.getLoginMedia(loginMedia).getDesc()))) {
- // userLogin.setStatus(Loginflag.fail.getIndex());
- // userLogin.setLoginCode("EB8000012");
- // userLogin.setLoginMsg(UtilTools.getText(userLogin.getLoginCode()));
- // userLoginDAO.insertSelective(userLogin);
- //
- // throw new BusinessException(userLogin.getLoginCode());
- // }
- ///////////////////////////////
- userLoginDAO.insertSelective(userLogin);
- String userId = sysUser.getId();
- String tocken = this.getA_systemhead().getClientToken();
- if (loginWay.equals(LoginWay.MANUAL.getIndex())) { //手动登录
- if (UtilTools.isNotNullAndBlank(this.getA_a00002().getIsLoginAuto()) && this.getA_a00002().getIsLoginAuto().equals("1")) {
- tocken = JwtManageUtil.getClientLoginAutoJWT(MFMiniCoreProperties.getInstance().getUniqueid(), userId, userId);
- } else {
- tocken = UUID.randomUUID().toString().replace("-", "").trim();
- }
- }
- //部门自定义的用户权限
- Map deptFuncMap = new HashMap();
- SysDepartment sysDepartment = UtilTools.getBean(SysDepartmentMapper.class).selectByPrimaryKey(sysUser.getOrgDeptCode());
- if (sysDepartment != null) {
- XIUtils.getListFromStrDelEmpty(sysDepartment.getDeptfunc()).stream()
- .forEach(func->deptFuncMap.put(func,""));
- }
- //用户cache
- UtilTools.putUserCache(XIConstant.UserKeyPre + sysUser.getId().trim(), tocken);
- UtilTools.putUserCache(XIConstant.TokenKeyPre + tocken, sysUser.getId());
- LoginService.initUserAccess(sysUser.getId());
- this.getD_systemhead().setClientToken(tocken);
- this.getD_systemhead().setUserId(userId);
- this.getD_a00002().setNickName(sysUser.getNickname() == null ? sysUser.getUsername() : sysUser.getNickname());
- this.getD_a00002().setUserName(sysUser.getUsername());
- this.getD_a00002().setOrgCode(sysUser.getOrgcode());
- this.getD_a00002().setOrgDeptCode(sysUser.getOrgDeptCode());
- this.getD_a00002().setRegTime(XIDateTimeUtils.getStrFromDate(sysUser.getCreateTime()));
- this.getD_a00002().setMobileNo(sysUser.getUsermobnub());
- this.getD_a00002().setHeadProfile(sysUser.getHeadPortait());
- this.getD_a00002().setUserType(sysUser.getUserType());
- if(sysUser.getUserType().equals(UserType.son.getIndex())){
- }else {
- SysUserSQLBuilder sonUserSQLBuilder=new SysUserSQLBuilder();
- sonUserSQLBuilder.createCriteria().andSuperiorUserIdEqualTo(sysUser.getId());
- List<SysUser> sonUserList = UtilTools.getBean(SysUserMapper.class).selectByExample(sonUserSQLBuilder);
- List<String> userIdList = null;
- if(sonUserList!=null && sonUserList.size()>0) {
- userIdList=sonUserList.stream().map(data->data.getId()).distinct()
- .collect(Collectors.toList());
- }
- if(userIdList == null){
- userIdList=new ArrayList<>();
- }
- userIdList.add(sysUser.getId());
- }
- List<XIRoleRecode> roleList = LoginService.getAccessRole(sysUser.getId());
- if (roleList != null && roleList.size() > 0) {
- this.getD_a00002().setRoleList(roleList.stream().map(role -> {
- D_A00002_ROLELIST_RECODE recode = new D_A00002_ROLELIST_RECODE();
- recode.setRoleId(role.getRoleId());
- recode.setRoleName(role.getRoleName());
- recode.setRoleDesc(role.getRoleDesc());
- return recode;
- }).collect(Collectors.toList()));
- }
- List<XIFuncRecode> funcList = LoginService.getAccessFunction(sysUser.getId(),deptFuncMap);
- if (funcList != null && funcList.size() > 0) {
- this.getD_a00002().setFuncList(funcList.stream().map(func -> {
- D_A00002_FUNCLIST_RECODE recode = new D_A00002_FUNCLIST_RECODE();
- recode.setFuncId(func.getFuncId());
- recode.setFuncClass(func.getFuncClass());
- recode.setFuncDesc(func.getFuncDesc());
- recode.setFuncName(func.getFuncName());
- return recode;
- }).collect(Collectors.toList()));
- }
- List<XIMenuRecode> menuList = LoginService.getAccessMenu(sysUser.getId());
- if (menuList != null && menuList.size() > 0) {
- List<D_A00002_MENULIST_RECODE> menulistRecodes = menuList.stream().map(menu -> {
- D_A00002_MENULIST_RECODE recode = new D_A00002_MENULIST_RECODE();
- recode.setMenuId(menu.getMenuId());
- recode.setMenuDesc(menu.getMenuDesc());
- recode.setMenuFlag(menu.getMenuFlag());
- recode.setMenuImage(menu.getMenuImage());
- recode.setMenuName(menu.getMenuName());
- recode.setMenuParentId(menu.getMenuParentId());
- recode.setMenuUrl(menu.getMenuUrl());
- return recode;
- }).collect(Collectors.toList());
- this.getD_a00002().setMenuList(menulistRecodes);
- }
- // VExtUserSQLBuilder VExtUserSQLBuilder = new VExtUserSQLBuilder();
- // VExtUserSQLBuilder.createCriteria().andIdEqualTo(sysUser.getId());
- // List<VExtUser> VExtUserList = UtilTools.getBean(VExtUserMapper.class).selectByExample(VExtUserSQLBuilder);
- // if (VExtUserList != null && VExtUserList.size() > 0) {
- // VExtUser VExtUser = VExtUserList.get(0);
- //
- // String certState = VExtUser.getCertState();
- // if (certState == null) {
- // certState = CertificationState.noCertificate.getIndex();
- // }
- // this.getD_a00002().setAuthenticationState(certState);
- // this.getD_a00002().setCertType(VExtUser.getCertType());
- // this.getD_a00002().setCertName(VExtUser.getCertName());
- // this.getD_a00002().setCertNo(VExtUser.getCertNumber());
- // this.getD_a00002().setCertFile(VExtUser.getCertFile());
- // this.getD_a00002().setCertTime(XIDateTimeUtils.getStrFromDate(VExtUser.getCertAuthTime()));
- // }
- }
- /**
- * 基础系统,“登录”业务前处理
- */
- public void preTransFlow() throws Exception {
- this.validater();
- }
- /**
- * 基础系统,“登录”业务后处理
- */
- public void afterTransFlow() throws Exception {
- }
- /**
- * 基础系统,“登录”逻辑入口处理方法
- */
- @SuppressWarnings("rawtypes")
- @Override
- public Map execute(Map vars) throws Exception {
- this.setTransMap(vars);
- preTransFlow();// 执行业务开始的规则检查和校验
- transExecute();// 执行核心业务段
- afterTransFlow();// 执行核心逻辑完成后的收尾逻辑
- return this.getTransMap();
- }
- }
|