用户登记信息工具类提取

beta-enc
kane 2 years ago
parent 2fe1ae9308
commit 71f9584fcf
  1. 46
      jianshui-platform/src/main/java/com/jianshui/platform/service/impl/InvoiceDeliveryServiceImpl.java
  2. 60
      jianshui-platform/src/main/java/com/jianshui/platform/utils/InvoiceAllYhdjUtils.java

@ -11,6 +11,7 @@ import com.jianshui.common.core.domain.entity.Companyservice;
import com.jianshui.common.core.domain.entity.SysUser;
import com.jianshui.common.core.redis.RedisCache;
import com.jianshui.common.utils.BeanToMapUtils;
import com.jianshui.common.utils.InvoiceUtils;
import com.jianshui.common.utils.SecurityUtils;
import com.jianshui.common.utils.ValidateUtils;
import com.jianshui.common.utils.jcsk.ApiHttp;
@ -21,6 +22,7 @@ import com.jianshui.platform.dto.InvoiceDeliveryDTO;
import com.jianshui.platform.dto.InvoiceDeliveryJsonDataDTO;
import com.jianshui.platform.mapper.InvoiceDeliveryMapper;
import com.jianshui.platform.service.InvoiceDeliveryService;
import com.jianshui.platform.utils.InvoiceAllYhdjUtils;
import com.jianshui.system.domain.InvoiceAllApiLog;
import com.jianshui.system.domain.InvoiceAllYhdj;
import com.jianshui.system.mapper.CompanyserviceMapper;
@ -31,9 +33,11 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.Date;
import java.util.List;
import java.util.UUID;
/**
* @Author: xingze
@ -48,8 +52,7 @@ public class InvoiceDeliveryServiceImpl implements InvoiceDeliveryService {
private SysUserMapper sysUserMapper;
@Autowired
private CompanyserviceMapper companyServiceMapper;
@Autowired
private InvoiceAllYhdjMapper yhdjMapper;
@Autowired
private InvoiceDeliveryMapper invoiceDeliveryMapper;
@ -63,10 +66,6 @@ public class InvoiceDeliveryServiceImpl implements InvoiceDeliveryService {
*/
@Override
public HXResponse invoiceDelivery(List<InvoiceDeliveryJsonDataDTO> dtos) {
//判空
if (dtos.isEmpty()){
return new HXResponse("传入信息为空,请检查信息!");
}
//获取用户id
Long userId = SecurityUtils.getUserId();
//根据用户id获取用户信息
@ -74,7 +73,8 @@ public class InvoiceDeliveryServiceImpl implements InvoiceDeliveryService {
//根据企业id获取企业信息
Companyservice companyservice = companyServiceMapper.selectCompanyserviceByCompanyid(sysUser.getCompanyId());
//获取登记用户信息
InvoiceAllYhdj userInfo = getUserInfo(companyservice);
InvoiceAllYhdjUtils invoiceAllYhdjUtils = new InvoiceAllYhdjUtils();
InvoiceAllYhdj userInfo = invoiceAllYhdjUtils.getUserInfo(companyservice);
if (BeanUtil.isEmpty(userInfo)) {
return new HXResponse("未查询到登记信息!");
}
@ -107,6 +107,7 @@ public class InvoiceDeliveryServiceImpl implements InvoiceDeliveryService {
allApiLog.setCompany(companyservice.getSellertax());
allApiLog.setIdentityId(companyservice.getIdentity());
allApiLog.setCreateTime(new Date());
allApiLog.setRequestId(UUID.randomUUID().toString());
//封装实体类
BeanUtils.copyProperties(invoiceDeliveryDTO, invoiceDelivery);
invoiceDelivery.setJflx(dto.getJflx());
@ -139,35 +140,4 @@ public class InvoiceDeliveryServiceImpl implements InvoiceDeliveryService {
return new HXResponse("0000", "处理成功");
}
/**
* 获取登记用户信息
*/
public InvoiceAllYhdj getUserInfo(Companyservice companyservice) {
String identity = companyservice.getIdentity();
String sellertax = companyservice.getSellertax();
String key = WebServiceConstant.TOKEN_KEY + sellertax + "_"+ identity;
RedisCache redisCache = SpringUtils.getBean(RedisCache.class);
cn.hutool.json.JSONObject yhdjObj = redisCache.getCacheObject(key);
if(JSONUtil.isNull(yhdjObj)){
// 查询用户登记参数
QueryWrapper<InvoiceAllYhdj> yhdjQueryWrapper = new QueryWrapper<>();
yhdjQueryWrapper.eq("nsrsbh", sellertax);
yhdjQueryWrapper.eq("identity", identity);
InvoiceAllYhdj invoiceAllYhdj = yhdjMapper.selectOne(yhdjQueryWrapper);
cn.hutool.json.JSONObject obj = JSONUtil.parseObj(invoiceAllYhdj);
Long exprieTime = System.currentTimeMillis(); // 过期时间
obj.put("exprieTime", exprieTime);
redisCache.setCacheObject(key, obj);
yhdjObj = obj;
}
return BeanUtil.copyProperties(yhdjObj,InvoiceAllYhdj.class);
}
}

@ -0,0 +1,60 @@
package com.jianshui.platform.utils;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jianshui.common.constant.WebServiceConstant;
import com.jianshui.common.core.domain.entity.Companyservice;
import com.jianshui.common.core.redis.RedisCache;
import com.jianshui.common.utils.spring.SpringUtils;
import com.jianshui.system.domain.InvoiceAllYhdj;
import com.jianshui.system.mapper.InvoiceAllYhdjMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @Author: kane
* @Description: 获取用户登记信息工具类
* @CreateTime: 2023-06-07 09:08
* @Version: 1.0
**/
@Component
public class InvoiceAllYhdjUtils {
@Autowired
private InvoiceAllYhdjMapper invoiceAllYhdjMapper;
public InvoiceAllYhdjUtils() {
}
/**
* 获取登记用户信息
*/
public InvoiceAllYhdj getUserInfo(Companyservice companyservice) {
String identity = companyservice.getIdentity();
String sellertax = companyservice.getSellertax();
String key = WebServiceConstant.TOKEN_KEY + sellertax + "_"+ identity;
RedisCache redisCache = SpringUtils.getBean(RedisCache.class);
cn.hutool.json.JSONObject yhdjObj = redisCache.getCacheObject(key);
if(JSONUtil.isNull(yhdjObj)){
// 查询用户登记参数
QueryWrapper<InvoiceAllYhdj> yhdjQueryWrapper = new QueryWrapper<>();
yhdjQueryWrapper.eq("nsrsbh", sellertax);
yhdjQueryWrapper.eq("identity", identity);
InvoiceAllYhdj invoiceAllYhdj = invoiceAllYhdjMapper.selectOne(yhdjQueryWrapper);
cn.hutool.json.JSONObject obj = JSONUtil.parseObj(invoiceAllYhdj);
Long exprieTime = System.currentTimeMillis(); // 过期时间
obj.put("exprieTime", exprieTime);
redisCache.setCacheObject(key, obj);
yhdjObj = obj;
}
return BeanUtil.copyProperties(yhdjObj,InvoiceAllYhdj.class);
}
}
Loading…
Cancel
Save