优化invoice后台返回给前端的错误语句

给用户开发票接口,默认后台生成当前时间
修复多个接口的没有数据报404问题,没有数据让其返回null值
修改bootrap.yml中的发票下载附件存放路径,让其为本地,合并是需要更改为服务器存放地址
This commit is contained in:
wen 2022-01-13 18:03:24 +08:00
parent e2ab06708b
commit fad1e6f7cc
7 changed files with 43 additions and 31 deletions

View File

@ -25,7 +25,7 @@ public class LoginUser implements Serializable
private Long userid; private Long userid;
/** /**
* 用户 * 用户账号手机号账号
*/ */
private String username; private String username;

View File

@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Map;
/** /**
* @author yuyang * @author yuyang
@ -18,11 +19,12 @@ public interface UserTypeService {
/** /**
* 根据手机号账号用户id和类型 获取用户信息 * 根据手机号账号用户id和类型 获取用户信息
*
* @param * @param
* @return * @return
*/ */
@GetMapping("/common/getUser") @GetMapping("/common/getUser")
R getUser(@RequestParam(value = "phone")String phone,@RequestParam(value = "userId")Long userId,@RequestParam(value = "userType")Integer userType,@RequestParam(value = "serialNumber")String serialNumber,@RequestParam(value = "tenantId")String tenantId); R<Map<String, Object>> getUser(@RequestParam(value = "phone") String phone, @RequestParam(value = "userId") Long userId, @RequestParam(value = "userType") Integer userType, @RequestParam(value = "serialNumber") String serialNumber, @RequestParam(value = "tenantId") String tenantId);

View File

@ -1,4 +1,4 @@
package com.xhpc.invoice; package com.xhpc;
import com.xhpc.common.security.annotation.EnableCustomConfig; import com.xhpc.common.security.annotation.EnableCustomConfig;
import com.xhpc.common.security.annotation.EnableRyFeignClients; import com.xhpc.common.security.annotation.EnableRyFeignClients;

View File

@ -95,7 +95,7 @@ public class XhpcInvoiceController extends BaseController {
public AjaxResult invoiceToUser(@RequestBody InvoiceToUserRequest requestData) { public AjaxResult invoiceToUser(@RequestBody InvoiceToUserRequest requestData) {
//前置条件 //前置条件
if (requestData.getInvoiceId() == null) { if (requestData.getInvoiceId() == null) {
return AjaxResult.error("必须递未开发票id"); return AjaxResult.error("必须传发票id");
} }
if (requestData.getStatus() == null || requestData.getStatus().equals(InvoiceStatusConst.INVOICING)) { if (requestData.getStatus() == null || requestData.getStatus().equals(InvoiceStatusConst.INVOICING)) {
return AjaxResult.error("必须传递发票状态或发票状态不能为0"); return AjaxResult.error("必须传递发票状态或发票状态不能为0");

View File

@ -128,6 +128,8 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Boolean invoiceToUser(InvoiceToUserRequest requestData) { public Boolean invoiceToUser(InvoiceToUserRequest requestData) {
//获取当前时间
requestData.setInvoicingTime(DateUtil.getYyyyMmDdHhMmSs());
//根据操作人的id查询操作人的名字 //根据操作人的id查询操作人的名字
SysUser sysUser = sysUserMapper.selectUserById(Long.valueOf(requestData.getDrawer())); SysUser sysUser = sysUserMapper.selectUserById(Long.valueOf(requestData.getDrawer()));
requestData.setDrawer(sysUser.getNickName()); requestData.setDrawer(sysUser.getNickName());
@ -137,7 +139,14 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService {
//从阿里云上下载下来电子发票 //从阿里云上下载下来电子发票
String fileUrl = requestData.getEletricInvoiceUrl(); String fileUrl = requestData.getEletricInvoiceUrl();
File electricInvoiceFile = new File(environment.getProperty("file.serverStoreDisposableFileLocation") + "ElectricInvoice.pdf"); File electricInvoiceFile = new File(environment.getProperty("file.serverStoreDisposableFileLocation") + "ElectricInvoice.pdf");
HttpUtil.downloadFile(fileUrl, electricInvoiceFile); try {
//参数1 文件下载路径
//参数2 文件存放位置
//服务器响应404 表示服务器找不到客户端所请求的资源
HttpUtil.downloadFile(fileUrl, electricInvoiceFile);
} catch (Exception e) {
throw new RuntimeException("在阿里云上无法找到该文件,请检查上传的图片路径是否完整或有误");
}
try { try {
MailUtil.send(receiveEmail, "【小华充电】电子发票", "邮件来自小华充电", false, electricInvoiceFile); MailUtil.send(receiveEmail, "【小华充电】电子发票", "邮件来自小华充电", false, electricInvoiceFile);
} catch (Exception e) { } catch (Exception e) {
@ -161,6 +170,8 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void failInvoiceToUser(InvoiceToUserRequest requestData) { public void failInvoiceToUser(InvoiceToUserRequest requestData) {
//获取当前时间
requestData.setInvoicingTime(DateUtil.getYyyyMmDdHhMmSs());
//根据操作人的id查询操作人的名字 //根据操作人的id查询操作人的名字
SysUser sysUser = sysUserMapper.selectUserById(Long.valueOf(requestData.getDrawer())); SysUser sysUser = sysUserMapper.selectUserById(Long.valueOf(requestData.getDrawer()));
requestData.setDrawer(sysUser.getNickName()); requestData.setDrawer(sysUser.getNickName());
@ -196,6 +207,11 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService {
public InvoiceTitleResponse findTitleInfo(String firmName) { public InvoiceTitleResponse findTitleInfo(String firmName) {
List<XhpcInvoice> xhpcInvoiceList = xhpcInvoiceMapper.selectInvoiceTitleInfo(firmName); List<XhpcInvoice> xhpcInvoiceList = xhpcInvoiceMapper.selectInvoiceTitleInfo(firmName);
InvoiceTitleResponse invoiceTitleResponse = new InvoiceTitleResponse();
//如果没有记录则返回空包装类
if (xhpcInvoiceList.size() == 0) {
return invoiceTitleResponse;
}
ArrayList<InvoiceTitleResponse.DataDTO> dataDTOList = new ArrayList<>(); ArrayList<InvoiceTitleResponse.DataDTO> dataDTOList = new ArrayList<>();
for (XhpcInvoice xhpcInvoice : xhpcInvoiceList) { for (XhpcInvoice xhpcInvoice : xhpcInvoiceList) {
InvoiceTitleResponse.DataDTO dataDTO = new InvoiceTitleResponse.DataDTO(); InvoiceTitleResponse.DataDTO dataDTO = new InvoiceTitleResponse.DataDTO();
@ -203,7 +219,6 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService {
dataDTO.setDutyNumber(xhpcInvoice.getDutyNumber()); dataDTO.setDutyNumber(xhpcInvoice.getDutyNumber());
dataDTOList.add(dataDTO); dataDTOList.add(dataDTO);
} }
InvoiceTitleResponse invoiceTitleResponse = new InvoiceTitleResponse();
invoiceTitleResponse.setData(dataDTOList); invoiceTitleResponse.setData(dataDTOList);
return invoiceTitleResponse; return invoiceTitleResponse;
} }
@ -223,6 +238,10 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService {
XhpcInvoice xhpcInvoice = xhpcInvoiceMapper.selectUserLastInputInvoiceInfo(creatorId, creatorType); XhpcInvoice xhpcInvoice = xhpcInvoiceMapper.selectUserLastInputInvoiceInfo(creatorId, creatorType);
TitleResponse titleResponse = new TitleResponse(); TitleResponse titleResponse = new TitleResponse();
//如果数据库本身就没有数据那么就返回空实体类对象
if (xhpcInvoice == null) {
return titleResponse;
}
BeanUtils.copyProperties(xhpcInvoice, titleResponse); BeanUtils.copyProperties(xhpcInvoice, titleResponse);
return titleResponse; return titleResponse;
@ -251,6 +270,10 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService {
//查询该用户3个月内可以开发票的历史订单 //查询该用户3个月内可以开发票的历史订单
List<Map<String, Object>> xhpcHistoryOrderList = xhpcHistoryOrderMapper.findByCondition(invoicedOrdersRequest, lockOrderNumberList); List<Map<String, Object>> xhpcHistoryOrderList = xhpcHistoryOrderMapper.findByCondition(invoicedOrdersRequest, lockOrderNumberList);
InvoicedOrderResponse invoicedOrderResponse = new InvoicedOrderResponse(); InvoicedOrderResponse invoicedOrderResponse = new InvoicedOrderResponse();
//没有则直接返回空对象出去
if (xhpcHistoryOrderList.size() == 0) {
return invoicedOrderResponse;
}
//设置该用户3个月内可以开发票的历史订单数量 //设置该用户3个月内可以开发票的历史订单数量
invoicedOrderResponse.setTotalItems(xhpcHistoryOrderList.size()); invoicedOrderResponse.setTotalItems(xhpcHistoryOrderList.size());
//查询该用户所有可以开的发票的历史订单数量 //查询该用户所有可以开的发票的历史订单数量
@ -312,29 +335,6 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService {
invoicedOrderResponse.setItems(itemsDTOS); invoicedOrderResponse.setItems(itemsDTOS);
return invoicedOrderResponse; return invoicedOrderResponse;
// //计算分页索引,放置到currentPage属性中
// int startIndex = (invoicedOrdersRequest.getCurrentPage() - 1) * invoicedOrdersRequest.getItems();
// invoicedOrdersRequest.setCurrentPage(startIndex);
// //先查询该用户被锁定了的订单过滤掉它
// List<Integer> lockOrderNumberList = xhpcInvoiceMapHistoryOrderMapper.findLockOrdersByUserIdAndUserType(invoicedOrdersRequest);
// //查询该用户3个月内可以开发票的历史订单
// List<XhpcHistoryOrder> xhpcHistoryOrderList = xhpcHistoryOrderMapper.findByCondition(invoicedOrdersRequest, lockOrderNumberList);
// ArrayList<InvoiceOrdersResponse.ItemsDTO> itemsDTOList = new ArrayList<>();
// for (XhpcHistoryOrder xhpcHistoryOrder : xhpcHistoryOrderList) {
// InvoiceOrdersResponse.ItemsDTO itemsDTO = new InvoiceOrdersResponse.ItemsDTO();
// itemsDTO.setOrderId(xhpcHistoryOrder.getHistoryOrderId());
// itemsDTO.setOrderNumber(xhpcHistoryOrder.getSerialNumber());
// itemsDTO.setOrderMoney(xhpcHistoryOrder.getActPrice());
// itemsDTO.setOrderTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, xhpcHistoryOrder.getCreateTime()));
// itemsDTOList.add(itemsDTO);
// }
// InvoiceOrdersResponse invoiceOrdersResponse = new InvoiceOrdersResponse();
// invoiceOrdersResponse.setItems(itemsDTOList);
// //查询该用户所有可以开发票的历史订单的数量
// Long allOrdersCount = xhpcHistoryOrderMapper.findAllOrdersByCondition(invoicedOrdersRequest, lockOrderNumberList);
// invoiceOrdersResponse.setTotalItems(allOrdersCount);
// return invoiceOrdersResponse;
} }
/** /**
@ -353,6 +353,10 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService {
//对拷发票部分数据 //对拷发票部分数据
XhpcInvoice xhpcInvoice = xhpcInvoiceMapper.selectByPrimaryKey(invoiceId); XhpcInvoice xhpcInvoice = xhpcInvoiceMapper.selectByPrimaryKey(invoiceId);
SpecificInvoicedResponse specificInvoicedResponse = new SpecificInvoicedResponse(); SpecificInvoicedResponse specificInvoicedResponse = new SpecificInvoicedResponse();
//查不出来返回空包装类
if (xhpcInvoice == null) {
return specificInvoicedResponse;
}
specificInvoicedResponse.setCreatorTime(DateUtils.parseDateToStr(xhpcInvoice.getCreateTime())); specificInvoicedResponse.setCreatorTime(DateUtils.parseDateToStr(xhpcInvoice.getCreateTime()));
specificInvoicedResponse.setReceiveEmail(xhpcInvoice.getReceiveEmail()); specificInvoicedResponse.setReceiveEmail(xhpcInvoice.getReceiveEmail());
specificInvoicedResponse.setTitleType(xhpcInvoice.getTitleType()); specificInvoicedResponse.setTitleType(xhpcInvoice.getTitleType());
@ -462,6 +466,11 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService {
invoiceHistoryRecordsRequest.setCurrentPage(startIndex); invoiceHistoryRecordsRequest.setCurrentPage(startIndex);
//获取该用户所提交的每个发票信息 //获取该用户所提交的每个发票信息
List<XhpcInvoice> invoicesList = xhpcInvoiceMapper.findInvoicesByCreatorIdAndCreatorType(invoiceHistoryRecordsRequest); List<XhpcInvoice> invoicesList = xhpcInvoiceMapper.findInvoicesByCreatorIdAndCreatorType(invoiceHistoryRecordsRequest);
//如果为0那么则返回空的实体类出去
InvoiceHistoryRecordsResponse invoiceHistoryRecordsResponse = new InvoiceHistoryRecordsResponse();
if (invoicesList.size() == 0) {
return invoiceHistoryRecordsResponse;
}
//实体类对拷 //实体类对拷
ArrayList<InvoiceHistoryRecordsResponse.ItemsDTO> itemsDTOS = new ArrayList<>(); ArrayList<InvoiceHistoryRecordsResponse.ItemsDTO> itemsDTOS = new ArrayList<>();
for (XhpcInvoice xhpcInvoice : invoicesList) { for (XhpcInvoice xhpcInvoice : invoicesList) {
@ -473,7 +482,6 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService {
itemsDTO.setIsRead(xhpcInvoice.getIsRead()); itemsDTO.setIsRead(xhpcInvoice.getIsRead());
itemsDTOS.add(itemsDTO); itemsDTOS.add(itemsDTO);
} }
InvoiceHistoryRecordsResponse invoiceHistoryRecordsResponse = new InvoiceHistoryRecordsResponse();
invoiceHistoryRecordsResponse.setItems(itemsDTOS); invoiceHistoryRecordsResponse.setItems(itemsDTOS);
Long userInvoiceItems = xhpcInvoiceMapper.getUserInvoiceItemsByCreatorIdAndCreatorType(invoiceHistoryRecordsRequest.getCreatorId(), invoiceHistoryRecordsRequest.getCreatorType()); Long userInvoiceItems = xhpcInvoiceMapper.getUserInvoiceItemsByCreatorIdAndCreatorType(invoiceHistoryRecordsRequest.getCreatorId(), invoiceHistoryRecordsRequest.getCreatorType());
invoiceHistoryRecordsResponse.setTotalItems(userInvoiceItems); invoiceHistoryRecordsResponse.setTotalItems(userInvoiceItems);

View File

@ -37,4 +37,5 @@ oss:
#文件路径 #文件路径
file: file:
aliyunPath: invoicePdf/ aliyunPath: invoicePdf/
serverStoreDisposableFileLocation: /www/wwwroot/xhpc.scxhua.com/disposableFiles/ # serverStoreDisposableFileLocation: /www/wwwroot/xhpc.scxhua.com/disposableFiles/
serverStoreDisposableFileLocation: C:\\www\\wwwroot\\xhpc.scxhua.com\\disposableFiles\\

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--suppress ALL -->
<mapper namespace="com.xhpc.invoice.mapper.XhpcInvoiceMapHistoryOrderMapper"> <mapper namespace="com.xhpc.invoice.mapper.XhpcInvoiceMapHistoryOrderMapper">
<resultMap id="BaseResultMap" type="com.xhpc.invoice.pojo.XhpcInvoiceMapHistoryOrder"> <resultMap id="BaseResultMap" type="com.xhpc.invoice.pojo.XhpcInvoiceMapHistoryOrder">
<result column="invoice_id" jdbcType="BIGINT" property="invoiceId"/> <result column="invoice_id" jdbcType="BIGINT" property="invoiceId"/>