templates.service.LoginServiceImpl.ftl Maven / Gradle / Ivy
package ${afterEndBo.packageName}.service.${folderName}.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import ${afterEndBo.packageName}.common.entity.${folderName}.SystemAccountEntity;
import ${afterEndBo.packageName}.common.entity.${folderName}.SystemMenuEntity;
import ${afterEndBo.packageName}.common.utils.JwtTokenUtil;
import ${afterEndBo.packageName}.common.utils.MenuTreeUtils;
import ${afterEndBo.packageName}.common.vo.LoginUserVo;
import ${afterEndBo.packageName}.common.vo.${folderName}.SystemAccountVo;
import ${afterEndBo.packageName}.common.vo.${folderName}.SystemMenuVo;
import ${afterEndBo.packageName}.service.${folderName}.service.LoginService;
import ${afterEndBo.packageName}.service.${folderName}.service.SystemAccountService;
import ${afterEndBo.packageName}.service.${folderName}.service.SystemMenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.yes.tools.core.exception.YesBaseException;
import org.yes.tools.core.vo.MetaInfo;
import org.yes.tools.utils.BeanCopyUtils;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* @author Co.
* @name LoginServiceImpl
* @date 2023/4/10 15:09
*/
@Slf4j
@Service(value = "${folderName}LoginServiceImpl")
public class LoginServiceImpl implements LoginService {
@Autowired
private SystemAccountService systemAccountService;
@Autowired
private JwtTokenUtil jwtTokenUtil;
@Autowired
private SystemMenuService systemMenuService;
@Override
public String login(String account, String pwd) {
SystemAccountEntity systemAccount = systemAccountService.getOne(new LambdaQueryWrapper().eq(SystemAccountEntity::getAccount, account));
if (Objects.isNull(systemAccount)) {
throw new YesBaseException("用户不存在");
}
if (systemAccount.getStatus().equals(2)) {
throw new YesBaseException("用户已禁用");
}
if (!systemAccount.getPwd().equals(pwd)) {
throw new YesBaseException("账号密码错误");
}
String token = jwtTokenUtil.generateToken(systemAccount.getId().toString());
return token;
}
@Override
public SystemAccountVo getAccountInfo() {
LoginUserVo loginUserVo = JwtTokenUtil.getSecurityAuthentication();
SystemAccountVo systemAccountVo = BeanCopyUtils.copyAs(loginUserVo.getUser(), SystemAccountVo.class);
return systemAccountVo;
}
@Override
public List getMenuTree() {
List menuEntities = systemMenuService.list();
List systemMenuVos = BeanCopyUtils.copyListAs(menuEntities, SystemMenuVo.class);
List collect = systemMenuVos.stream().map(e -> {
SystemMenuVo menuInfo = BeanCopyUtils.copyAs(e,SystemMenuVo.class);
MetaInfo metaInfo = new MetaInfo();
metaInfo.setTitle(e.getName());
metaInfo.setIsLink(null);
metaInfo.setIsHide(false);
metaInfo.setIsKeepAlive(false);
metaInfo.setIsAffix(false);
metaInfo.setIsIframe(false);
metaInfo.setAuth("admin");
metaInfo.setIcon(e.getIcon());
menuInfo.setMeta(metaInfo);
return menuInfo;
}).collect(Collectors.toList());
MenuTreeUtils menuTreeUtils = new MenuTreeUtils(collect);
return menuTreeUtils.buildTree();
}
}