|
|
|
@ -1,34 +1,49 @@ |
|
|
|
|
package com.jianshui.platform.service.impl; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.jianshui.common.core.domain.AjaxResult; |
|
|
|
|
import com.jianshui.common.core.domain.entity.Companyservice; |
|
|
|
|
import com.jianshui.common.enums.ErrorCode; |
|
|
|
|
import com.jianshui.common.exception.jianshui.JianshuiParamErrorException; |
|
|
|
|
import com.jianshui.common.exception.jianshui.JianshuiServiceException; |
|
|
|
|
import com.jianshui.common.utils.SecurityUtils; |
|
|
|
|
import com.jianshui.common.utils.ValidateUtils; |
|
|
|
|
import com.jianshui.invoice.domain.BillInfo; |
|
|
|
|
import com.jianshui.invoice.domain.dto.HXResponse; |
|
|
|
|
import com.jianshui.invoice.enums.ChannelSource; |
|
|
|
|
import com.jianshui.invoice.factory.IInvoiceServiceFactory; |
|
|
|
|
import com.jianshui.invoice.mapper.BillInfoMapper; |
|
|
|
|
import com.jianshui.invoice.service.IInvoiceApiService; |
|
|
|
|
import com.jianshui.invoice.service.IInvoiceRequestService; |
|
|
|
|
import com.jianshui.invoice.service.IInvoiceResponseService; |
|
|
|
|
import com.jianshui.platform.dto.InvoiceAdd.BillInfoPDTO; |
|
|
|
|
import com.jianshui.platform.service.InvoiceAddService; |
|
|
|
|
import com.jianshui.platform.utils.InvoiceAllYhdjUtils; |
|
|
|
|
import com.jianshui.system.domain.InvoiceAllYhdj; |
|
|
|
|
import com.jianshui.system.mapper.CompanyserviceMapper; |
|
|
|
|
import com.jianshui.system.service.IServiceManageService; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 发票录入 |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
@Service |
|
|
|
|
@Slf4j |
|
|
|
|
public class InvoiceAddServiceImpl implements InvoiceAddService { |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private static BillInfoMapper billInfoMapper; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private IServiceManageService serviceManageService; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private IInvoiceServiceFactory invoiceServiceFactory; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private CompanyserviceMapper companyServiceMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public int invoiceSave(BillInfoPDTO billInfoPDTO) { |
|
|
|
|
ValidateUtils.validate(billInfoPDTO); |
|
|
|
@ -41,16 +56,48 @@ public class InvoiceAddServiceImpl implements InvoiceAddService { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public AjaxResult invoiceIssuance(BillInfoPDTO billInfoPDTO) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public HXResponse invoiceIssuance(BillInfoPDTO billInfoPDTO) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BillInfo billInfo = BeanUtil.copyProperties(billInfoPDTO, BillInfo.class); |
|
|
|
|
|
|
|
|
|
billInfo.setSource(ChannelSource.PLATFORM.getCode()); |
|
|
|
|
|
|
|
|
|
// 获取用户信息
|
|
|
|
|
Long companyId = Optional.ofNullable(SecurityUtils.getLoginUser()) |
|
|
|
|
.map(loginUser -> loginUser.getCompanyId()) |
|
|
|
|
.orElse(0L); |
|
|
|
|
if (companyId == 0L) { |
|
|
|
|
return new HXResponse("未获取到用户服务信息,请联系管理员配置!"); |
|
|
|
|
} |
|
|
|
|
Companyservice companyservice = companyServiceMapper.selectCompanyserviceByCompanyid(companyId); |
|
|
|
|
if (BeanUtil.isEmpty(companyservice)) { |
|
|
|
|
return new HXResponse(("未获取到用户服务信息,请联系管理员配置!")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO: 2023/6/8 这里看看多通道的时候怎么处理
|
|
|
|
|
InvoiceAllYhdjUtils invoiceAllYhdjUtils = new InvoiceAllYhdjUtils(); |
|
|
|
|
InvoiceAllYhdj userInfo = invoiceAllYhdjUtils.getUserInfo(companyservice); |
|
|
|
|
|
|
|
|
|
if (BeanUtil.isEmpty(userInfo)) { |
|
|
|
|
return new HXResponse(("未查询到登记信息!")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 获得请求实例,并且进行扣费
|
|
|
|
|
String serviceKey = null; |
|
|
|
|
try { |
|
|
|
|
serviceKey = serviceManageService.getCompanyServiceSupplier("invoice", companyservice.getCompanyid()); |
|
|
|
|
|
|
|
|
|
serviceManageService.companyConsume("invoice", companyId); |
|
|
|
|
billInfo.setServiceSupplierKey(serviceKey); |
|
|
|
|
IInvoiceApiService invoiceService = invoiceServiceFactory.getService(serviceKey); |
|
|
|
|
|
|
|
|
|
return invoiceService.addInvoice(billInfo, companyservice); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("简税产品端,发票开具失败,请求报文={},企业税号={},servicekey={}",billInfoPDTO.toString(),companyservice.toString(),serviceKey); |
|
|
|
|
throw new JianshuiServiceException("发票开具系统异常!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -61,8 +108,4 @@ public class InvoiceAddServiceImpl implements InvoiceAddService { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|