Commit 7b18d7a9 authored by ZWT's avatar ZWT

feat(零碳): 长庆演示系统新增功能

1.修改第三方日累计数据推送表表结构,增加日累计储能放电量字段,同时修改代码对应实体及mapper文件,修改相关接口增加储能日累计放电量接收逻辑;
2.修改首页井场收益分析模块接口,修改获取储能累计放电量逻辑;
3.设计并创建井口日用电趋势表,生成对应实体类及mapper文件;
4.统计分析模块,新增本月累计节电经济效益查询接口,添加线上接口文档并完成接口冒烟测试;
5.统计分析模块,新增本月累计减碳量查询接口,添加线上接口文档并完成接口冒烟测试;
6.统计分析模块,新增光伏发电趋势查询接口,添加线上接口文档并完成接口冒烟测试;
7.统计分析模块,新增月度总览查询接口,添加线上接口文档并完成接口冒烟测试;

BREAKING CHANGE: 无

Closes 无

[skip ci]
parent 4c7e084f
......@@ -3,25 +3,25 @@ package pps.core.system.service;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import pps.core.common.session.PpsUserSession;
import pps.core.common.utils.PatternUtil;
import pps.core.common.utils.RSAUtil;
import pps.core.common.utils.VerificationCode;
import pps.core.system.cache.FineReportThirdTokenCache;
import pps.core.system.cache.LoginSmsCodeCache;
import pps.core.system.cache.LoginVerCodeCache;
import pps.core.system.config.LoginConfig;
import pps.core.system.entity.*;
import pps.core.system.entity.SysUserEnt;
import pps.core.system.entity.SysUserForgetLogEnt;
import pps.core.system.entity.SysUserLoginLogEnt;
import pps.core.system.entity.SysUserOrganizationRelEnt;
import pps.core.system.error.LoginError;
import pps.core.system.mapper.*;
import pps.core.system.service.data.FineReport.GetFineReport;
import pps.core.system.service.data.iam.GetIamInput;
import pps.core.system.mapper.SysUserForgetLogMapper;
import pps.core.system.mapper.SysUserLoginLogMapper;
import pps.core.system.mapper.SysUserMapper;
import pps.core.system.mapper.SysUserOrganizationRelMapper;
import pps.core.system.service.data.sys_login.*;
import pps.core.system.utils.UserInfoUtil;
import xstartup.annotation.XService;
......@@ -31,101 +31,38 @@ import xstartup.base.XSsoAuth;
import xstartup.base.XUser;
import xstartup.base.conf.XConfManager;
import xstartup.base.exception.XServiceException;
import xstartup.base.util.*;
import xstartup.base.util.XDateUtils;
import xstartup.base.util.XStringUtils;
import xstartup.base.util.XUuidUtils;
import xstartup.core.base.provider.data.XToken;
import xstartup.data.XFileResult;
import xstartup.data.XRedirectResult;
import xstartup.data.XServiceResult;
import xstartup.data.XSingleResult;
import xstartup.error.XError;
import xstartup.feature.api.annotation.XApiAnonymous;
import xstartup.feature.api.annotation.XApiGet;
import xstartup.feature.api.annotation.XApiPost;
import xstartup.feature.api.conf.XApiCookieConf;
import xstartup.helper.XTokenHelper;
import java.awt.image.BufferedImage;
import java.util.*;
import java.util.stream.Collectors;
import java.util.Date;
import java.util.Map;
import java.util.UUID;
import static pps.core.common.constant.LoginConstant.LOGIN_FLAG_SIMULATE;
import static pps.core.common.constant.LoginConstant.LOGIN_FLAG_TRADE;
import static pps.core.system.error.LoginError.NotExistUserName;
import static pps.core.system.error.LoginError.Trade_IpWhiteError;
@XService
public class LoginService {
/**
* 生成third_token需要的key
*/
private static final String KEY = "pppppppppppsssssssssssssssssssssssss";
private static final String SPLIT = "_&_";
/**
* 多久过期
*/
private static final int EXPIRE_TIME = 6000000;
@XText("获取最后一次登录信息")
@XApiGet(anonymous = true)
public XSingleResult<GetLastLoginInfoOutput> getLastLoginInfo(XContext context, GetLastLoginInfoInput input) {
context.log().info("input:{}", input);
GetLastLoginInfoOutput output = new GetLastLoginInfoOutput();
output.setIp(XDeviceUtils.getDefaultIp());
return XSingleResult.success(output);
}
@XText("登陆发送短信")
@XApiGet(anonymous = true)
public XServiceResult sendCode(XContext context, SendCodeInput input) {
if (!checkIsSendSmsCode(context)) {
return XServiceResult.OK;
}
checkCode(context, input.getCode(), input.getCodeIden());
XSingleResult<SysUserEnt> sysUserResult = checkAccount(context, input.getLoginName(), input.getPassword());
SysUserEnt sysUserEnt = sysUserResult.getResult();
String phone = sysUserEnt.getPhone();
phone = UserInfoUtil.decrypt(phone);
if (StringUtils.isBlank(phone)) {
return XServiceResult.error(context, LoginError.NotExistPhone);
}
if (!PatternUtil.checkPhone(phone)) {
return XServiceResult.error(context, LoginError.NotExistPhone);
}
Integer sendSmsCodeInterval = LoginConfig.sendSmsCodeInterval.findValue(context);
if (sendSmsCodeInterval == null) {
sendSmsCodeInterval = 1;
}
LoginSmsCodeCache smsCodeCache = LoginSmsCodeCache.exist(context, input.getLoginName());
if (smsCodeCache != null) {
Date currentDate = smsCodeCache.getCurrentDate();
if (currentDate != null) {
Date date = XDateUtils.addMunites(currentDate, sendSmsCodeInterval);
if (XDateUtils.compare(date, new Date()) > 0) {
return XServiceResult.error(context, LoginError.ISValidateSmsCode);
}
}
}
String smsContent = LoginConfig.smsContent.findValue(context);
if (StringUtils.isBlank(smsContent)) {
smsContent = "您正在登陆生产运行管理系统,验证码为:{smsCode},{valiteMinite}分钟有效!";
}
return XServiceResult.OK;
}
@XText("账号密码登录")
@XApiPost(anonymous = true)
public XSingleResult<LoginByAccountOutput> loginByAccount(XContext context, LoginByAccountInput input) {
long startTime = System.currentTimeMillis();
Long count = getErrorTimes(context, input.getLoginName(), null);
if (count >= 5) {
return XSingleResult.error(context, LoginError.ISLOCKED);
}
System.out.println("登录开始:----------------------------" + startTime);
checkCode(context, input.getCode(), input.getCodeIden());
// checkSmsCode(context, input.getLoginName(), input.getSmsCode());
XSingleResult<SysUserEnt> sysUserResult = checkAccount(context, input.getLoginName(), input.getPassword());
SysUserEnt sysUserEnt = sysUserResult.getResult();
if (sysUserEnt.getStatus() != null && sysUserEnt.getStatus() == 1)
......@@ -169,23 +106,11 @@ public class LoginService {
new XSsoAuth(uniqueId, ssoToken, ssoRefreshToken));
XSingleResult<XToken> saveUserResult = XTokenHelper.saveUser(context, user, expiresIn);
saveUserResult.throwIfFail();
/*//todo:设置对应角色的权限缓存
List list = new ArrayList();
RolePermissionCache insertCache = new RolePermissionCache("insert","插入");
RolePermissionCache updateCache = new RolePermissionCache("update","修改");
list.add(insertCache);
list.add(updateCache);
for(Long roleId : user.getRoles()){
RolePermissionCache.set(context, roleId, list);
}*/
LoginByAccountOutput output = new LoginByAccountOutput();
output.setExpiresIn(expiresIn);
output.setToken(saveUserResult.getResult().getToken());
PpsUserSession session = context.getSession(PpsUserSession.class);
output.setSession(session);
long endTime = System.currentTimeMillis();
long cost = endTime - startTime;
long costOrg = endTime - getOrgTime;
//登录成功后,删除失败记录
deleteError(context, sysUserEnt);
return XSingleResult.success(output);
......@@ -275,31 +200,6 @@ public class LoginService {
return XServiceResult.OK;
}
@XText("测试token是否有效")
@XApiPost
public XSingleResult<TestTokenOutput> testToken(XContext context) {
PpsUserSession session;
try {
session = context.getSession(PpsUserSession.class);
context.log().info("session:{}", session);
} catch (XServiceException e) {
return XSingleResult.error(context, XError.NotAuth);
}
TestTokenOutput output = new TestTokenOutput();
output.setUserId(session.getUserCode());
output.setUserName(session.getUserName());
return XSingleResult.success(output);
}
@XText("Iam重定向")
@XApiAnonymous
@XApiGet
public XRedirectResult iamToLogin(XContext context, GetIamInput input) {
// XWebRequest request = context.getWebRequest();
// request.getHeader("host")
return XRedirectResult.success(LoginConfig.iamToLoginUrl.getValue(context) + "?code=" + input.getCode() + "&client_secret=" + input.getClient_secret());
}
@XText("验证码")
@XApiGet(anonymous = true)
public XFileResult getVerificationCode(XContext context, VerificationCodeInput input) {
......@@ -312,226 +212,8 @@ public class LoginService {
return XFileResult.createWithPng(input.getCodeIden() + ".png", (BufferedImage) codeMap.get("codePic"));
}
/**
* 部门参数规则(department):
* 部门ID长度构建部门树:
* 默认通过部门ID长度构建部分树,会根据department和id字段长度来自动构建部门树结构
* 例如:id 0 对应中国, 02 对应北京,021 对应朝阳区,根据id长度匹配父子部门
* 特殊根部门ID:
* 例如:id 00 对应中国, 02 对应北京,021 对应朝阳区,这时候就需要填入 00 来标记特殊根部门
* @return
*/
/**
* 帆软获取third_token
*
* @param context
* @param input
* @return
*/
@XText("帆软获取third_token")
@XApiPost
public XSingleResult<GetFineReport> getThirdToken(XContext context, TestThirdToken input) {
PpsUserSession session = context.getSession(PpsUserSession.class);
GetFineReport report = new GetFineReport();
boolean exist = FineReportThirdTokenCache.exist(context, session.getLoginName(), session.getLoginName());
if (exist) {
List<FineReportThirdTokenCache> list = FineReportThirdTokenCache.list(context, session.getLoginName());
if (ObjectUtils.isNotEmpty(list)) {
FineReportThirdTokenCache cache = list.get(0);
report.setThirdToken(cache.getCacheCode());
}
} else {
String string = getString(context);
System.out.println(string);
/*String key = "";
QueryWrapper<SysDictionaryEnt> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SysDictionaryEnt::getAlias,"FINE_REPORT_KEY")
.gt(SysDictionaryEnt::getEndTime,new Date());
List<SysDictionaryEnt> sysDictionaryEnts = dictionaryMapper.selectList(queryWrapper);
if(ObjectUtils.isNotEmpty(sysDictionaryEnts)){
SysDictionaryEnt dictionaryEnt = sysDictionaryEnts.get(0);
if(ObjectUtils.isNotEmpty(dictionaryEnt)){
QueryWrapper<SysDictionaryEnt> query = new QueryWrapper<>();
query.lambda().eq(SysDictionaryEnt::getPid,dictionaryEnt.getId())
.gt(SysDictionaryEnt::getEndTime,new Date());
List<SysDictionaryEnt> dicList = dictionaryMapper.selectList(query);
if(ObjectUtils.isNotEmpty(dicList)){
SysDictionaryEnt sysDictionaryEnt = dicList.get(0);
if(ObjectUtils.isNotEmpty(sysDictionaryEnt) && StringUtils.isNotBlank(sysDictionaryEnt.getDicKey())){
key = sysDictionaryEnt.getDicKey();
}
}
}
}*/
Date expireTime = new Date(System.currentTimeMillis() + EXPIRE_TIME);
String third_token = "";
try {
third_token = io.jsonwebtoken.Jwts.builder()
.setExpiration(expireTime)
.signWith(io.jsonwebtoken.SignatureAlgorithm.HS256, Base64.getEncoder().encodeToString(KEY.getBytes("UTF-8")))
.setSubject(string)
.compact();
} catch (Exception e) {
e.printStackTrace();
}
List<FineReportThirdTokenCache> list = new ArrayList<>();
FineReportThirdTokenCache cache = new FineReportThirdTokenCache();
cache.setCacheKey(session.getLoginName());
cache.setCacheCode(third_token);
list.add(cache);
FineReportThirdTokenCache.set(context, session.getLoginName(), list);
// third_token 返回前端.
// url?tenant=租户id&third_token=third_token 跳转到指定报表
// cookie中生成 fine_auth_token和tenantId, 可以正常打开地址
// tenant=test1&third_token=third_token
System.out.println(third_token);
report.setThirdToken(third_token);
}
return XSingleResult.success(report);
}
@XText("交易平台登录")
@XApiAnonymous
@XApiPost
public XSingleResult<TradeLoginOutput> loginByTrade(XContext context, TradeLoginInput input) {
String env = context.getEnv().getText();
if ("prod".equals(env)) {
String clientIp = context.getWebRequest().getClientIp();
String ipWhiteValue = LoginConfig.ipWhite.findValue(context);
if (StringUtils.isNotBlank(ipWhiteValue) && !ipWhiteValue.contains(clientIp)) {
return XSingleResult.error(context, Trade_IpWhiteError);
}
}
String loginParam = input.getLoginParam();
if (StringUtils.isBlank(loginParam)) {
return XSingleResult.error(context, LoginError.Trade_ParamIsNull);
}
String loginInfo;
try {
String privateKey = LoginConfig.rsaPrivateKey.findValue(context);
privateKey = XEncryptUtils.decrypt(privateKey);
loginInfo = RSAUtil.RsaDecrypt(loginParam, privateKey);
} catch (Exception e) {
context.getLogger().error("参数解密失败", e);
return XSingleResult.error(context, LoginError.Trade_ParamRSAError);
}
TradeLoginInfo tradeLoginInfo;
try {
tradeLoginInfo = XJsonUtils.toObject(loginInfo, TradeLoginInfo.class);
if (!(tradeLoginInfo != null && StringUtils.isNotBlank(tradeLoginInfo.getLoginName()))) {
return XSingleResult.error(context, LoginError.Trade_ParamFormatError);
}
} catch (Exception e) {
context.getLogger().error("参数格式有误", e);
return XSingleResult.error(context, LoginError.Trade_ParamFormatError);
}
SysUserMapper mapper = context.getBean(SysUserMapper.class);
QueryWrapper<SysUserEnt> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(SysUserEnt::getLoginName, tradeLoginInfo.getLoginName())
.eq(SysUserEnt::getIsTrade, 1)
.last("limit 1");
SysUserEnt sysUserEnt = mapper.selectOne(queryWrapper);
if (sysUserEnt == null)
return XSingleResult.error(context, LoginError.Trade_LoginError);
XApiCookieConf apiCookieConf = XConfManager.getConf(XApiCookieConf.class);
Integer expiresIn = apiCookieConf.getExpires();
String userName = sysUserEnt.getUserName(); //姓名
Long orgId = LOGIN_FLAG_TRADE; //组织机构id - 交易平台登陆专用值
Long roleId0 = 1L; //角色id1
Long roleId1 = 1L; //角色id2
Long userId = IdWorker.getId(); //用户id
String userCode = sysUserEnt.getId();//这个是用户字符串类型的唯一标志
String ssoToken = null; //sso系统授权的token
String ssoRefreshToken = null; //sso系统授权的刷新token
String uniqueId = XUuidUtils.randomUUID();
XUser user = XUser.createUser(XUser.ENTRY_API,
orgId,
new Long[]{roleId0, roleId1},
userId,
userCode,
sysUserEnt.getLoginName(),
userName,
new XSsoAuth(uniqueId, ssoToken, ssoRefreshToken));
XSingleResult<XToken> saveUserResult = XTokenHelper.saveUser(context, user, expiresIn);
saveUserResult.throwIfFail();
TradeLoginOutput output = new TradeLoginOutput();
output.setExpiresIn(expiresIn);
output.setToken(saveUserResult.getResult().getToken());
return XSingleResult.success(output);
}
/*------------------------------- private -------------------------------*/
/**
* 平台用户类型(platformType):
* 1 PC端
* 2 BI查看 (仅BI)
* 4 移动端
* 5 BI数据分析(只可创建excel和自助数据集) (仅BI)
* 6 BI数据处理(可创建sql/db/excel/自助数据集)(仅BI)
*
* @return
*/
private String getString(XContext context) {
PpsUserSession session = context.getSession(PpsUserSession.class);
HashMap<String, Object> map = new HashMap<>();
HashMap<String, Object> department = new HashMap<>();
String ouName = getDepartment(session.getOuId(), context);
department.put("name", ouName != null ? ouName : session.getOuName());
department.put("id", session.getOuId());
map.put("username", session.getLoginName());
map.put("department", department);
/* ArrayList<String> list1 = new ArrayList<>();
ArrayList<Integer> list2 = new ArrayList<>();
list1.add("职员");
list2.add(1);
map.put("roles", list1);
map.put("platformType", list2);*/
String jsonString = JSONUtil.toJsonStr(map);
return jsonString;
}
private String getDepartment(String ouId, XContext context) {
try {
SysOrganizationRelMapper bean = context.getBean(SysOrganizationRelMapper.class);
QueryWrapper<SysOrganizationRelEnt> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("ou_id", ouId);
queryWrapper.lambda().lt(SysOrganizationRelEnt::getEffectTime, new Date());
queryWrapper.lambda().gt(SysOrganizationRelEnt::getEndTime, new Date());
SysOrganizationRelEnt sysOrganizationRelEnt = bean.selectOne(queryWrapper);
String ouIdPath = sysOrganizationRelEnt.getOuIdPath();
if (StringUtils.isEmpty(ouIdPath)) {
return null;
}
String[] split = ouIdPath.split("/");
SysOrganizationMapper mapper = context.getBean(SysOrganizationMapper.class);
QueryWrapper<SysOrganizationEnt> wrapper = new QueryWrapper<>();
wrapper.in("id", split);
wrapper.eq("is_deleted", "1");
List<SysOrganizationEnt> sysOrganizationEnts = mapper.selectList(wrapper);
Map<String, SysOrganizationEnt> personMap = sysOrganizationEnts.stream().collect(Collectors.toMap(
ent -> ent.getId(),
ent -> ent,
(p, n) -> p
));
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < split.length; i++) {
String ouName = personMap.get(split[i]).getOuName();
if (i == split.length - 1) {
buffer.append(ouName);
} else {
buffer.append(ouName).append(SPLIT);
}
}
return buffer.toString();
} catch (Exception e) {
context.log().info("获取机构path错误");
return null;
}
}
private boolean checkIsSendSmsCode(XContext context) {
Integer sendSmsCodeSwitch = new LoginConfig().sendSmsCodeSwitch.findValue(context);
if (sendSmsCodeSwitch != null && sendSmsCodeSwitch == 1) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment