Browse Source

0820_添加登录日志

master
zy_Java 5 years ago
parent
commit
c0334bd2fe
  1. 10
      cloudutil/src/main/java/com/ccsens/cloudutil/aspect/MustLoginAspect.java
  2. 10
      pims/src/main/java/com/ccsens/pims/bean/dto/CompanyDto.java
  3. 2
      pims/src/main/java/com/ccsens/pims/persist/dao/ProductDao.java
  4. 3
      pims/src/main/java/com/ccsens/pims/service/ReportService.java
  5. 6
      pims/src/main/resources/mapper_dao/ProducrDao.xml
  6. 18
      tall/src/main/java/com/ccsens/tall/service/UserService.java
  7. 10
      tall/src/main/java/com/ccsens/tall/web/UserController.java
  8. 9
      util/src/test/java/com/ccsens/util/Base64Test.java

10
cloudutil/src/main/java/com/ccsens/cloudutil/aspect/MustLoginAspect.java

@ -1,5 +1,6 @@
package com.ccsens.cloudutil.aspect; package com.ccsens.cloudutil.aspect;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.ccsens.cloudutil.annotation.MustLogin; import com.ccsens.cloudutil.annotation.MustLogin;
@ -52,7 +53,10 @@ public class MustLoginAspect {
QueryDto dto = args == null || args.length < 1 ? null : (QueryDto) args[0]; QueryDto dto = args == null || args.length < 1 ? null : (QueryDto) args[0];
//获取userId //获取userId
JsonResponse response = tallFeignClient.getUserIdByToken(authHeader); JsonResponse response = null;
if(StrUtil.isNotEmpty(authHeader)){
response = tallFeignClient.getUserIdByToken(authHeader);
}
log.info("{}获取userId:{}", authHeader, response); log.info("{}获取userId:{}", authHeader, response);
Signature signature = pjp.getSignature(); Signature signature = pjp.getSignature();
@ -62,7 +66,7 @@ public class MustLoginAspect {
if (mustLoginAnnotation == null) { if (mustLoginAnnotation == null) {
log.info("不是必须登录,有token,则添加userId,没有则不添加"); log.info("不是必须登录,有token,则添加userId,没有则不添加");
if (response.getCode().intValue() == CodeEnum.SUCCESS.getCode().intValue() && response.getData() != null) { if (response != null && response.getCode().intValue() == CodeEnum.SUCCESS.getCode().intValue() && response.getData() != null) {
JSONObject json = JSONObject.parseObject(JSON.toJSONString(response.getData())); JSONObject json = JSONObject.parseObject(JSON.toJSONString(response.getData()));
Long userId = json.getLong("id"); Long userId = json.getLong("id");
if (dto != null) { if (dto != null) {
@ -73,7 +77,7 @@ public class MustLoginAspect {
return result; return result;
} }
//必须登录,未登录直接返回未登录相关信息 //必须登录,未登录直接返回未登录相关信息
if (response.getCode().intValue() != CodeEnum.SUCCESS.getCode().intValue()) { if (response == null || response.getCode().intValue() != CodeEnum.SUCCESS.getCode().intValue()) {
return response; return response;
} }
if (response.getData() == null) { if (response.getData() == null) {

10
pims/src/main/java/com/ccsens/pims/bean/dto/CompanyDto.java

@ -1,10 +1,12 @@
package com.ccsens.pims.bean.dto; package com.ccsens.pims.bean.dto;
import cn.hutool.core.date.DateUtil;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.Date;
/** /**
* @author * @author
@ -18,8 +20,12 @@ public class CompanyDto {
@NotNull @NotNull
@ApiModelProperty("项目id") @ApiModelProperty("项目id")
private Long projectId; private Long projectId;
@ApiModelProperty("任务id") @ApiModelProperty("年份 默认当前年份")
private int year; private int year = DateUtil.year(new Date());
@ApiModelProperty("开始月 默认1月")
private int startMonth = 1;
@ApiModelProperty("结束月 默认12月")
private int endMonth = 12;
} }
@Data @Data

2
pims/src/main/java/com/ccsens/pims/persist/dao/ProductDao.java

@ -25,7 +25,7 @@ public interface ProductDao extends ProductMapper {
* @param projectId 产品id * @param projectId 产品id
* @return 返回产品的收入信息 * @return 返回产品的收入信息
*/ */
List<CompanyVo.ProductIncomeType> queryProductIncome(@Param("projectId")Long projectId); List<CompanyVo.ProductIncomeType> queryProductIncome(@Param("projectId")Long projectId,@Param("year")int year,@Param("sMonth")int sMonth,@Param("eMonth")int eMonth);
/** /**
* 查看现金流变动 * 查看现金流变动

3
pims/src/main/java/com/ccsens/pims/service/ReportService.java

@ -86,7 +86,8 @@ public class ReportService implements IReportService {
return wpsPath; return wpsPath;
} }
//从数据库查找产品收入信息 //从数据库查找产品收入信息
List<CompanyVo.ProductIncomeType> productIncomeTypeList = productDao.queryProductIncome(project.getProjectId()); List<CompanyVo.ProductIncomeType> productIncomeTypeList =
productDao.queryProductIncome(project.getProjectId(),project.getYear(),project.getStartMonth(),project.getEndMonth());
//生成excel写入的数据 //生成excel写入的数据
List<List<PoiUtil.PoiUtilCell>> product = generateProduction(productIncomeTypeList); List<List<PoiUtil.PoiUtilCell>> product = generateProduction(productIncomeTypeList);
//写入WBS //写入WBS

6
pims/src/main/resources/mapper_dao/ProducrDao.xml

@ -305,6 +305,12 @@
p.rec_status = 0 p.rec_status = 0
and and
pt.project_id = #{projectId} pt.project_id = #{projectId}
and
pi.year_income = #{year}
and
pi.month_time &gt;= #{sMonth}
and
pi.month_time &lt;= #{eMonth}
</select> </select>
<select id="getTotalIncome" parameterType="java.util.Map" resultType="com.ccsens.pims.bean.vo.CompanyVo$TotalIncome"> <select id="getTotalIncome" parameterType="java.util.Map" resultType="com.ccsens.pims.bean.vo.CompanyVo$TotalIncome">

18
tall/src/main/java/com/ccsens/tall/service/UserService.java

@ -385,7 +385,10 @@ public class UserService implements IUserService {
*/ */
private UserVo.UserSign wxmplogin(String code, String gameType) throws Exception { private UserVo.UserSign wxmplogin(String code, String gameType) throws Exception {
//0.获取openid //0.获取openid
Long start = System.currentTimeMillis();
WxXcxUtil.WechatUser wechatUser = WxXcxUtil.getUserInfo(code, gameType); WxXcxUtil.WechatUser wechatUser = WxXcxUtil.getUserInfo(code, gameType);
Long end = System.currentTimeMillis();
log.info("调用微信查询openId耗时:{}",end - start);
String openId = wechatUser.openid; String openId = wechatUser.openid;
String unionId = wechatUser.unionid; String unionId = wechatUser.unionid;
log.info("小程序登录,openid:{} ,unionId:{}", openId, unionId); log.info("小程序登录,openid:{} ,unionId:{}", openId, unionId);
@ -408,6 +411,7 @@ public class UserService implements IUserService {
*/ */
private UserVo.UserSign getUserSign(String openId, String unionId, private UserVo.UserSign getUserSign(String openId, String unionId,
byte identifyType, String redirect) { byte identifyType, String redirect) {
long start = System.currentTimeMillis();
UserVo.UserSign userSignVo; UserVo.UserSign userSignVo;
List<SysAuth> authList; List<SysAuth> authList;
SysAuth theAuth; SysAuth theAuth;
@ -423,13 +427,17 @@ public class UserService implements IUserService {
SysAuthExample authExample = new SysAuthExample(); SysAuthExample authExample = new SysAuthExample();
authExample.createCriteria().andIdentifierEqualTo(openId).andIdentifyTypeEqualTo(identifyType); authExample.createCriteria().andIdentifierEqualTo(openId).andIdentifyTypeEqualTo(identifyType);
authList = authDao.selectByExample(authExample); authList = authDao.selectByExample(authExample);
long end1 = System.currentTimeMillis();
log.info("查auth表耗时:{}",end1 - start);
if (CollectionUtil.isEmpty(authList)) { if (CollectionUtil.isEmpty(authList)) {
List<SysAuth> sysAuthList = null; List<SysAuth> sysAuthList = null;
long end2 = 0;
if (ObjectUtil.isNotNull(unionId) && identifyType == WebConstant.IDENTIFY_TYPE.Wxmp.value) { if (ObjectUtil.isNotNull(unionId) && identifyType == WebConstant.IDENTIFY_TYPE.Wxmp.value) {
SysAuthExample sysAuthExample = new SysAuthExample(); SysAuthExample sysAuthExample = new SysAuthExample();
sysAuthExample.createCriteria().andCredentialEqualTo(unionId); sysAuthExample.createCriteria().andCredentialEqualTo(unionId);
sysAuthList = authDao.selectByExample(sysAuthExample); sysAuthList = authDao.selectByExample(sysAuthExample);
end2 = System.currentTimeMillis();
log.info("查找同平台其他登录方式耗时:{}",end2 - end1);
} }
if (CollectionUtil.isNotEmpty(sysAuthList)) { if (CollectionUtil.isNotEmpty(sysAuthList)) {
//添加认证方式 //添加认证方式
@ -440,7 +448,8 @@ public class UserService implements IUserService {
theAuth.setIdentifier(openId); theAuth.setIdentifier(openId);
theAuth.setCredential(unionId); theAuth.setCredential(unionId);
authDao.insertSelective(theAuth); authDao.insertSelective(theAuth);
long end3 = System.currentTimeMillis();
log.info("同平台有其他登录方式,添加小程序auth耗时:{}",end3 - (end2 == 0 ? end1 : end2));
} else { } else {
//新建用户并保存微信信息 //新建用户并保存微信信息
SysUser user = new SysUser(); SysUser user = new SysUser();
@ -456,6 +465,8 @@ public class UserService implements IUserService {
theAuth.setIdentifier(openId); theAuth.setIdentifier(openId);
theAuth.setCredential(unionId); theAuth.setCredential(unionId);
authDao.insertSelective(theAuth); authDao.insertSelective(theAuth);
long end4 = System.currentTimeMillis();
log.info("同平台没有其他登录方式,添加user和小程序auth耗时:{}",end4 - (end2 == 0 ? end1 : end2));
// //自动添加账号密码 // //自动添加账号密码
// String accountName = RandomStringUtils.random(8, WebConstant.RANDOM_STR); // String accountName = RandomStringUtils.random(8, WebConstant.RANDOM_STR);
// SysAuth accountAuth = new SysAuth(); // SysAuth accountAuth = new SysAuth();
@ -476,8 +487,11 @@ public class UserService implements IUserService {
userSignVo = new UserVo.UserSign(); userSignVo = new UserVo.UserSign();
userSignVo.setUserId(theAuth.getUserId()); userSignVo.setUserId(theAuth.getUserId());
userSignVo.setAuthId(theAuth.getId()); userSignVo.setAuthId(theAuth.getId());
//存入redis //存入redis
redisUtil.set(key,userSignVo,TallConstant.LOGIN_TIME); redisUtil.set(key,userSignVo,TallConstant.LOGIN_TIME);
long end2 = System.currentTimeMillis();
log.info("方法结束总耗时:{}",end2 - end1);
return userSignVo; return userSignVo;
} }

10
tall/src/main/java/com/ccsens/tall/web/UserController.java

@ -47,6 +47,8 @@ public class UserController {
@RequestMapping(value = "/signin", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) @RequestMapping(value = "/signin", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<UserVo.TokenBean> userSignin(HttpServletRequest request, public JsonResponse<UserVo.TokenBean> userSignin(HttpServletRequest request,
@ApiParam @Validated @RequestBody(required = true) UserDto.UserSginin dto) throws Exception { @ApiParam @Validated @RequestBody(required = true) UserDto.UserSginin dto) throws Exception {
log.info("开始登陆:{}",dto);
Long start = System.currentTimeMillis();
WebConstant.CLIENT_TYPE clientType = WebConstant.CLIENT_TYPE.valueOf(dto.getClient()); WebConstant.CLIENT_TYPE clientType = WebConstant.CLIENT_TYPE.valueOf(dto.getClient());
WebConstant.IDENTIFY_TYPE identify_type = WebConstant.IDENTIFY_TYPE.valueOf(dto.getType()); WebConstant.IDENTIFY_TYPE identify_type = WebConstant.IDENTIFY_TYPE.valueOf(dto.getType());
String identifier = dto.getData().getIdentifier(); String identifier = dto.getData().getIdentifier();
@ -99,6 +101,9 @@ public class UserController {
theMap.put("authId", String.valueOf(userSignVo.getAuthId())); theMap.put("authId", String.valueOf(userSignVo.getAuthId()));
UserVo.TokenBean tokenBean = userService.getUserInfoAndToken(clientType, identify_type,userSignVo, theMap); UserVo.TokenBean tokenBean = userService.getUserInfoAndToken(clientType, identify_type,userSignVo, theMap);
Long end = System.currentTimeMillis();
log.info("本次登录使用了{}毫秒",end - start);
log.info("登录返回:{}",tokenBean);
return JsonResponse.newInstance().ok(tokenBean); return JsonResponse.newInstance().ok(tokenBean);
} else { } else {
return JsonResponse.newInstance().fail("登陆信息不正确."); return JsonResponse.newInstance().fail("登陆信息不正确.");
@ -384,7 +389,7 @@ public class UserController {
}) })
@RequestMapping(value = "token",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"}) @RequestMapping(value = "token",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"})
public JsonResponse<UserVo.TokenToUserId> getUserByToken(@RequestParam(required = true) String token) throws Exception { public JsonResponse<UserVo.TokenToUserId> getUserByToken(@RequestParam(required = true) String token) throws Exception {
long start = System.currentTimeMillis();
UserVo.TokenToUserId tokenToUserId = new UserVo.TokenToUserId(); UserVo.TokenToUserId tokenToUserId = new UserVo.TokenToUserId();
// 验证token是否存在 // 验证token是否存在
@ -412,7 +417,8 @@ public class UserController {
// } // }
tokenToUserId.setId(Long.valueOf(claims.getSubject())); tokenToUserId.setId(Long.valueOf(claims.getSubject()));
long end = System.currentTimeMillis();
log.info("根据token查找userId用时:{}",end - start);
return JsonResponse.newInstance().ok(tokenToUserId); return JsonResponse.newInstance().ok(tokenToUserId);
} }

9
util/src/test/java/com/ccsens/util/Base64Test.java

@ -1,11 +1,13 @@
package com.ccsens.util; package com.ccsens.util;
import cn.hutool.core.codec.Base64; import cn.hutool.core.codec.Base64;
import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Test; import org.junit.Test;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.util.Date;
/** /**
* @description: * @description:
@ -33,9 +35,10 @@ public class Base64Test {
@Test @Test
public void test02() throws Exception { public void test02() throws Exception {
String s = "https://wwo.wps.cn/office/s/1291660455860899840?_w_appid=09d77d2eb919438e8ae4f2a9ec6ec8dd&_w_signature=oFhIjXT7MHYm58jfcbTAO%2Fo9quA%3D&_w_token=eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1OTY3ODY0NjksInN1YiI6IjEyMTc2NDc2ODY1OTgxMzU4MDgiLCJhdXRoSWQiOiIxMTc3MTU4ODQ4ODg1MTY2MDgwIiwiZXhwIjoxNTk2ODcyODY5fQ.-pNqWTas-5Efu1855QzuObqE9y2N9HI-K3MZCKmI6SA&_w_url=https://test.tall.wiki/gateway/pims/read/income"; // String s = "https://wwo.wps.cn/office/s/1291660455860899840?_w_appid=09d77d2eb919438e8ae4f2a9ec6ec8dd&_w_signature=oFhIjXT7MHYm58jfcbTAO%2Fo9quA%3D&_w_token=eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1OTY3ODY0NjksInN1YiI6IjEyMTc2NDc2ODY1OTgxMzU4MDgiLCJhdXRoSWQiOiIxMTc3MTU4ODQ4ODg1MTY2MDgwIiwiZXhwIjoxNTk2ODcyODY5fQ.-pNqWTas-5Efu1855QzuObqE9y2N9HI-K3MZCKmI6SA&_w_url=https://test.tall.wiki/gateway/pims/read/income";
//
System.out.println(s); // System.out.println(s);
System.out.println(DateUtil.year(new Date()));
} }

Loading…
Cancel
Save