|
|
|
@ -1,39 +1,16 @@ |
|
|
|
|
package com.dxhy.sign.service.fpqs.impl; |
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
|
import java.io.FileOutputStream; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.text.ParseException; |
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import javax.servlet.ServletOutputStream; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.codec.Base64Decoder; |
|
|
|
|
import cn.hutool.core.util.ArrayUtil; |
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
|
import com.alibaba.excel.ExcelWriter; |
|
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet; |
|
|
|
|
import com.dxhy.base.sms.utils.MessageSenderUtil; |
|
|
|
|
import com.dxhy.base.sms.vo.AttachmentVo; |
|
|
|
|
import com.dxhy.base.sms.vo.MailContentVo; |
|
|
|
|
import com.dxhy.base.sms.vo.SendMailVo; |
|
|
|
|
import com.dxhy.sign.config.BaseServiceConfig; |
|
|
|
|
import com.google.common.collect.Lists; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
import org.joda.time.DateTime; |
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
|
|
|
|
import com.dxhy.base.sms.utils.MessageSenderUtil; |
|
|
|
|
import com.dxhy.base.sms.vo.AttachmentVo; |
|
|
|
|
import com.dxhy.base.sms.vo.MailContentVo; |
|
|
|
|
import com.dxhy.base.sms.vo.SendMailVo; |
|
|
|
|
import com.dxhy.common.constant.DbConstant; |
|
|
|
|
import com.dxhy.common.constant.DictConstant; |
|
|
|
|
import com.dxhy.common.datasource.config.DynamicContextHolder; |
|
|
|
@ -53,6 +30,7 @@ import com.dxhy.common.vo.Business; |
|
|
|
|
import com.dxhy.common.vo.InvoiceLog; |
|
|
|
|
import com.dxhy.common.vo.Tax; |
|
|
|
|
import com.dxhy.common.vo.UserInfo; |
|
|
|
|
import com.dxhy.sign.config.BaseServiceConfig; |
|
|
|
|
import com.dxhy.sign.dao.SignInvoiceDao; |
|
|
|
|
import com.dxhy.sign.dao.SignInvoiceDelDao; |
|
|
|
|
import com.dxhy.sign.dao.SignRecordInvoiceDao; |
|
|
|
@ -68,9 +46,22 @@ import com.dxhy.sign.util.InvoiceQueryUtil; |
|
|
|
|
import com.dxhy.sign.util.PushIntefaceUtil; |
|
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
|
|
|
|
|
|
import com.google.common.collect.Lists; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import sun.security.krb5.internal.PAData; |
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
import org.joda.time.DateTime; |
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.text.ParseException; |
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 发票签收业务逻辑处理实现类 |
|
|
|
@ -87,6 +78,9 @@ public class SignFpqsServiceImpl extends MpBaseServiceImpl<SignRecordInvoiceDao, |
|
|
|
|
@Resource |
|
|
|
|
private SignInvoiceService signInvoiceSmService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private SignSaveInvoiceInfoService signSaveInvoiceInfoService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private InvoiceQueryUtil invoiceQueryUtil; |
|
|
|
|
|
|
|
|
@ -383,6 +377,166 @@ public class SignFpqsServiceImpl extends MpBaseServiceImpl<SignRecordInvoiceDao, |
|
|
|
|
return super.responseResult(json); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 根据查验结果进行发票签收 |
|
|
|
|
* |
|
|
|
|
* @param tDxInvoice |
|
|
|
|
* 抵账 |
|
|
|
|
* @param invoiceCode |
|
|
|
|
* 发票代码 |
|
|
|
|
* @param invoiceNo |
|
|
|
|
* 发票号码 |
|
|
|
|
* @param pramsMap |
|
|
|
|
* 入参 |
|
|
|
|
* @return 返回 |
|
|
|
|
*/ |
|
|
|
|
private TDxInvoice qsSinglefpByInvoiceQuery(TDxInvoice tDxInvoice, String invoiceCode, String invoiceNo, |
|
|
|
|
Map<String, String> pramsMap, String userName, Boolean isExits, String qsType) { |
|
|
|
|
Map<String, String> tax = getTax(); |
|
|
|
|
String invoiceDate = pramsMap.get("invoiceDate"); |
|
|
|
|
if (invoiceDate.length() == 8) { |
|
|
|
|
invoiceDate = |
|
|
|
|
invoiceDate.substring(0, 4) + "-" + invoiceDate.substring(4, 6) + "-" + invoiceDate.substring(6); |
|
|
|
|
} |
|
|
|
|
String invoiceAmount = pramsMap.getOrDefault("invoiceAmount", ""); |
|
|
|
|
String checkCode = pramsMap.getOrDefault("checkCode", ""); |
|
|
|
|
|
|
|
|
|
tDxInvoice.setQsDate(DateUtils.getSqlDateLong()); |
|
|
|
|
tDxInvoice.setQsType(qsType); |
|
|
|
|
tDxInvoice.setCreateDate(DateUtils.getSqlDateLong()); |
|
|
|
|
if (StringUtils.isNotBlank(invoiceAmount)) { |
|
|
|
|
tDxInvoice.setInvoiceAmount(new BigDecimal(invoiceAmount)); |
|
|
|
|
} |
|
|
|
|
tDxInvoice.setCheckCode(checkCode); |
|
|
|
|
tDxInvoice.setInvoiceDate(DateUtils.strToDate(invoiceDate)); |
|
|
|
|
tDxInvoice.setQsDate(DateUtils.getSqlDateLong()); |
|
|
|
|
tDxInvoice.setUuid(invoiceCode + invoiceNo); |
|
|
|
|
String gfsh = ""; |
|
|
|
|
|
|
|
|
|
if (pramsMap.containsKey("gfshAll") && StringUtils.isNotBlank(pramsMap.get("gfshAll"))) { |
|
|
|
|
String gfshAll = pramsMap.get("gfshAll"); |
|
|
|
|
String[] split = gfshAll.split(","); |
|
|
|
|
gfsh = split[1]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 调用查验接口查询发票信息
|
|
|
|
|
JSONObject queryInvoiceResult = |
|
|
|
|
invoiceQueryUtil.queryInvoice(invoiceCode, invoiceNo, invoiceDate, invoiceAmount, checkCode, gfsh,""); |
|
|
|
|
queryInvoiceResult.put("company", tDxInvoice.getCompany()); |
|
|
|
|
if (queryInvoiceResult.containsKey("returnCode")) { |
|
|
|
|
// 调用查验接口失败,进入查验失败处理流程
|
|
|
|
|
tDxInvoice.setNotes(queryInvoiceResult.getString("returnMessage")); |
|
|
|
|
tDxInvoice.setQsStatus(FpqsjgEnum.WQS.getQsjgDm()); |
|
|
|
|
} else { |
|
|
|
|
String resultCode = queryInvoiceResult.getString("resultCode"); |
|
|
|
|
tDxInvoice.setNotes(queryInvoiceResult.getString("resultTip")); |
|
|
|
|
// 查验成功且信息一致,直接保存到底账表并签收
|
|
|
|
|
if ("0001".equals(resultCode)) { |
|
|
|
|
// 查验返回的购方税号
|
|
|
|
|
String checkGfsh = queryInvoiceResult.getString("buyerTaxNo"); |
|
|
|
|
checkGfsh = checkGfsh == null ? "" : checkGfsh; |
|
|
|
|
// 查验返回的购方名称
|
|
|
|
|
String checkGfmc = queryInvoiceResult.getString("buyerName"); |
|
|
|
|
checkGfmc = checkGfmc == null ? "" : checkGfmc; |
|
|
|
|
|
|
|
|
|
String taxName = tax.get(checkGfsh); |
|
|
|
|
// 查验返回的作废标志
|
|
|
|
|
String zfbz = queryInvoiceResult.getString("isCancelled"); |
|
|
|
|
// 查验返回的税额
|
|
|
|
|
String taxAmount = queryInvoiceResult.getString("taxAmount"); |
|
|
|
|
if (StringUtils.isNotBlank(taxAmount)) { |
|
|
|
|
tDxInvoice.setTaxAmount(new BigDecimal(taxAmount)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (pramsMap.containsKey("gfshAll") && StringUtils.isNotBlank(pramsMap.get("gfshAll")) |
|
|
|
|
&& !pramsMap.get("gfshAll").contains(checkGfsh)) { |
|
|
|
|
// 查验成功但是信息不一致,直接在扫描表添加一条记录
|
|
|
|
|
tDxInvoice.setQsStatus(FpqsjgEnum.WQS.getQsjgDm()); |
|
|
|
|
tDxInvoice.setNotes("登录人的公司税号与发票购方税号不一致,查验返回的购方税号为:" + checkGfsh); |
|
|
|
|
} else if (StringUtils.isNotBlank(taxName) |
|
|
|
|
&& !CompareNameUtils.changeBrackets(taxName) |
|
|
|
|
.equals(CompareNameUtils.changeBrackets(checkGfmc.trim())) |
|
|
|
|
&& !CompareNameUtils.changeBrackets(oldOrgName) |
|
|
|
|
.contains(CompareNameUtils.changeBrackets(checkGfmc.trim()))) { |
|
|
|
|
// 查验成功但是信息不一致,直接在扫描表添加一条记录
|
|
|
|
|
tDxInvoice.setQsStatus(FpqsjgEnum.WQS.getQsjgDm()); |
|
|
|
|
tDxInvoice.setNotes("登录人的公司名称与发票购方名称不一致,查验返回的购方名称为:" + checkGfmc); |
|
|
|
|
} else if (!("N".equals(zfbz) || "0".equals(zfbz))) { |
|
|
|
|
// 作废发票无法签收,发票查验接口只返回了作废状态,未返回其它异常状态
|
|
|
|
|
tDxInvoice.setQsStatus(FpqsjgEnum.WQS.getQsjgDm()); |
|
|
|
|
tDxInvoice.setNotes("发票状态异常,签收失败!"); |
|
|
|
|
} else { |
|
|
|
|
if (tDxInvoice.getDeptId() != null) { |
|
|
|
|
// 部门存入底账
|
|
|
|
|
queryInvoiceResult.put("deptId", tDxInvoice.getDeptId()); |
|
|
|
|
queryInvoiceResult.put("deptName", tDxInvoice.getDeptName()); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
queryInvoiceResult.put("scanId", tDxInvoice.getScanId()); |
|
|
|
|
signSaveInvoiceInfoService.saveQueryInvoiceResult(queryInvoiceResult, userName, qsType, |
|
|
|
|
pramsMap.get("dbName")); |
|
|
|
|
tDxInvoice.setQsStatus(FpqsjgEnum.YQS.getQsjgDm()); |
|
|
|
|
|
|
|
|
|
// 增加发票签收日志
|
|
|
|
|
InvoiceLog log = new InvoiceLog(); |
|
|
|
|
log.setInputName(userName); |
|
|
|
|
log.setInputStatus("1"); |
|
|
|
|
log.setInvoiceCode(tDxInvoice.getInvoiceCode()); |
|
|
|
|
log.setInvoiceNo(tDxInvoice.getInvoiceNo()); |
|
|
|
|
log.setQsType(qsType); |
|
|
|
|
log.setType("3"); |
|
|
|
|
log.setCreateDate(new Date()); |
|
|
|
|
List<InvoiceLog> logs = new ArrayList<>(); |
|
|
|
|
logs.add(log); |
|
|
|
|
invoiceLogService.toInvoiceLog(logs); |
|
|
|
|
} |
|
|
|
|
tDxInvoice.setGfName(checkGfmc); |
|
|
|
|
tDxInvoice.setGfTaxNo(checkGfsh); |
|
|
|
|
tDxInvoice.setXfName(queryInvoiceResult.getString("salerName")); |
|
|
|
|
tDxInvoice.setXfTaxNo(queryInvoiceResult.getString("salerTaxNo")); |
|
|
|
|
tDxInvoice.setTotalAmount(queryInvoiceResult.getBigDecimal("totalAmount")); |
|
|
|
|
tDxInvoice.setInvoiceAmount(queryInvoiceResult.getBigDecimal("invoiceAmount")); |
|
|
|
|
tDxInvoice.setInvoiceRemark(queryInvoiceResult.getString("remark")); |
|
|
|
|
} else { |
|
|
|
|
// 查验成功但是信息不一致,直接在扫描表添加一条记录
|
|
|
|
|
tDxInvoice.setQsStatus(FpqsjgEnum.WQS.getQsjgDm()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_WRITE); |
|
|
|
|
if (!isExits) { |
|
|
|
|
if (tDxInvoice.getUpdateByScanId()) { |
|
|
|
|
// 已存在扫描记录
|
|
|
|
|
UpdateWrapper<TDxInvoice> updateWrapper = new UpdateWrapper<>(); |
|
|
|
|
updateWrapper.eq("scan_id", tDxInvoice.getScanId()); |
|
|
|
|
tDxInvoice.setUpdateDate(new Date()); |
|
|
|
|
tDxInvoice.setCreateDate(null); |
|
|
|
|
signInvoiceSmService.update(tDxInvoice, updateWrapper); |
|
|
|
|
} else { |
|
|
|
|
tDxInvoice.setInvoiceSerialNo(Long.valueOf(scanIdUtils.createSerialNum())); |
|
|
|
|
|
|
|
|
|
// 不存在扫描记录
|
|
|
|
|
signInvoiceSmService.save(tDxInvoice); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// 已存在扫描记录
|
|
|
|
|
// 已存在扫描记录,且存在的记录非当前扫描修改记录,先删再更新
|
|
|
|
|
if (!tDxInvoice.getUpdateByScanId()) { |
|
|
|
|
|
|
|
|
|
UpdateWrapper<TDxInvoice> delWrapper = new UpdateWrapper<>(); |
|
|
|
|
delWrapper.eq("scan_id", tDxInvoice.getScanId()); |
|
|
|
|
signInvoiceSmService.remove(delWrapper); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UpdateWrapper<TDxInvoice> updateWrapper = new UpdateWrapper<>(); |
|
|
|
|
updateWrapper.eq("uuid", tDxInvoice.getUuid()); |
|
|
|
|
tDxInvoice.setUpdateDate(new Date()); |
|
|
|
|
tDxInvoice.setCreateDate(null); |
|
|
|
|
signInvoiceSmService.update(tDxInvoice, updateWrapper); |
|
|
|
|
} |
|
|
|
|
return tDxInvoice; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 签收单张发票 |
|
|
|
|
* |
|
|
|
@ -1789,6 +1943,28 @@ public class SignFpqsServiceImpl extends MpBaseServiceImpl<SignRecordInvoiceDao, |
|
|
|
|
return signInvoiceSmService.requestValidate(pramsMap.get("uuid"), pramsMap.get("userId"), del); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public String getInvoiceInfo(Map<String, String> pramsMap) { |
|
|
|
|
|
|
|
|
|
JSONObject checkInfo; |
|
|
|
|
String invoiceCode = pramsMap.get("invoiceCode"); |
|
|
|
|
String invoiceNo = pramsMap.get("invoiceNo"); |
|
|
|
|
String uuid = invoiceCode + invoiceNo; |
|
|
|
|
|
|
|
|
|
DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ); |
|
|
|
|
QueryWrapper<TDxRecordInvoice> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
queryWrapper.eq("uuid", uuid); |
|
|
|
|
TDxRecordInvoice invoiceRecord = super.getOne(queryWrapper); |
|
|
|
|
|
|
|
|
|
if (invoiceRecord != null) { |
|
|
|
|
checkInfo = signSaveInvoiceInfoService.createInvoiceInfo(invoiceRecord, pramsMap.get("dbName")); |
|
|
|
|
return super.responseResult(checkInfo); |
|
|
|
|
} else { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public String yqsxxCancle(Map<String, String> pramsMap) { |
|
|
|
|
|
|
|
|
@ -3185,7 +3361,7 @@ public class SignFpqsServiceImpl extends MpBaseServiceImpl<SignRecordInvoiceDao, |
|
|
|
|
List<String> strings = Arrays.asList(ids); |
|
|
|
|
pramsMap.put("ids",strings); |
|
|
|
|
} |
|
|
|
|
List<TDxRecordInvoice> pageList = super.baseMapper.selectWqsfp(pramsMap); |
|
|
|
|
List<TDxRecordInvoice> pageList = super.baseMapper.selectWqsfpByQsyx(pramsMap); |
|
|
|
|
PageInfo<TDxRecordInvoice> pageInfo = new PageInfo<>(pageList); |
|
|
|
|
List<TDxRecordInvoice> resultList = pageInfo.getList(); |
|
|
|
|
List<QsExcelEntity> excelList = Lists.newArrayList(); |
|
|
|
|