/selectInvoicedOrders 完成查询可开票订单接口

This commit is contained in:
wen 2021-12-27 11:07:02 +08:00
parent 14ce1fc2b2
commit 1efa9aa95b
11 changed files with 389 additions and 6 deletions

View File

@ -2,13 +2,12 @@ package com.xhpc.invoice.api;
import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.invoice.domain.InvoiceOrdersResponse;
import com.xhpc.invoice.domain.InvoiceTitleResponse;
import com.xhpc.invoice.domain.InvoicedOrdersRequest;
import com.xhpc.invoice.domain.TitleResponse;
import com.xhpc.invoice.service.XhpcInvoiceService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@ -26,6 +25,29 @@ public class XhpcInvoiceApiController extends BaseController {
@Resource
XhpcInvoiceService xhpcInvoiceService;
@PostMapping(value = "/selectInvoiceHistoryRecords")
public AjaxResult selectInvoiceHistoryRecords(@RequestBody InvoicedOrdersRequest invoicedOrdersRequest) {
return AjaxResult.success(null);
}
/**
* 根据用户id用户类型要查询的当前时间的年月日查询该用户3个月内可以开发票的订单
*
* @author WH
* @date 2021/12/24 14:10
* @since version-1.0
*/
@PostMapping(value = "/selectInvoicedOrders")
public AjaxResult selectInvoicedOrders(@RequestBody InvoicedOrdersRequest invoicedOrdersRequest) {
if (invoicedOrdersRequest.getCurrentPage() == null || invoicedOrdersRequest.getItems() == null) {
return AjaxResult.error("分页参数不能为空:当前页数参数或当页要显示的条数为空");
}
InvoiceOrdersResponse invoiceOrdersResponse = xhpcInvoiceService.selectInvoicedOrders(invoicedOrdersRequest);
return AjaxResult.success(invoiceOrdersResponse);
}
/**
* 查询发票抬头信息
*

View File

@ -0,0 +1,59 @@
package com.xhpc.invoice.domain;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.util.List;
/**
* /invoiceOrders接口的返回参数封装类
*
* @author WH
* @date 2021/12/24 10:25
* @since version-1.0
*/
@NoArgsConstructor
@Data
public class InvoiceOrdersResponse {
/**
* 符合条件的总记录条数
*/
@JsonProperty("totalItems")
private Long totalItems;
/**
* 存放当前页要的数据的集合
*/
@JsonProperty("items")
private List<ItemsDTO> items;
@NoArgsConstructor
@Data
public static class ItemsDTO {
/**
* 历史订单id
*/
@JsonProperty("orderId")
private Long orderId;
/**
* 历史订单号
*/
@JsonProperty("orderNumber")
private String orderNumber;
/**
* 订单金额
*/
@JsonProperty("orderMoney")
private BigDecimal orderMoney;
/**
* 历史订单时间
*/
@JsonProperty("orderTime")
private String orderTime;
}
}

View File

@ -0,0 +1,44 @@
package com.xhpc.invoice.domain;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* /selectInvoicedOrders接口的请求参数封装类
*
* @author WH
* @date 2021/12/24 10:19
* @since version-1.0
*/
@NoArgsConstructor
@Data
public class InvoicedOrdersRequest {
/**
* 用户id
*/
@JsonProperty("userId")
private Long userId;
/**
* 用户类型0 C端用户 1 流量方用户 2社区用户 3B端用户
*/
@JsonProperty("userType")
private Integer userType;
/**
* 当前时间
*/
@JsonProperty("currentTime")
private String currentTime;
/**
* 当前页数
*/
@JsonProperty("currentPage")
private Integer currentPage;
/**
* 每页显示几条数据
*/
@JsonProperty("items")
private Integer items;
}

View File

@ -0,0 +1,42 @@
package com.xhpc.invoice.mapper;
import com.xhpc.invoice.domain.InvoicedOrdersRequest;
import com.xhpc.order.domain.XhpcHistoryOrder;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 专门用于发票服务的XhpcHistoryOrderMapper
*
* @author WH
* @date 2021/12/24 14:20
* @since version-1.0
*/
public interface XhpcHistoryOrderMapper {
/**
* 根据用户id用户类型要查询的当前时间的年月日查询该用户3个月内可以开发票的历史订单
*
* @param invoicedOrdersRequest 查询条件
* @param lockOrderNumberList 过滤条件
* @return 历史订单记录集合
* @author WH
* @date 2021/12/24 14:41
* @since version-1.0
*/
List<XhpcHistoryOrder> findByCondition(@Param("invoicedOrdersRequest") InvoicedOrdersRequest invoicedOrdersRequest, @Param("lockOrderNumberList") List<Integer> lockOrderNumberList);
/**
* 查询用户指定时间所有可以开发票的历史订单数量
*
* @param invoicedOrdersRequest 查询条件
* @param lockOrderNumberList 过滤条件
* @return 历史订单数量
* @author WH
* @date 2021/12/24 16:40
* @since version-1.0
*/
Long findAllOrdersByCondition(@Param("invoicedOrdersRequest") InvoicedOrdersRequest invoicedOrdersRequest, @Param("lockOrderNumberList") List<Integer> lockOrderNumberList);
}

View File

@ -1,5 +1,7 @@
package com.xhpc.invoice.mapper;
import com.xhpc.invoice.domain.InvoiceToUserRequest;
import com.xhpc.invoice.domain.InvoicedOrdersRequest;
import com.xhpc.invoice.pojo.XhpcInvoiceMapHistoryOrder;
import java.util.List;
@ -39,4 +41,25 @@ public interface XhpcInvoiceMapHistoryOrderMapper {
*/
List<String> getHistoryOrderScopeByInvoiceId(Long invoiceId);
/**
* 更新发票所关联的历史订单的状态
*
* @param requestData 存储与历史订单相关联的发票id
* @author WH
* @date 2021/12/24 13:59
* @since version-1.0
*/
void updateStatus(InvoiceToUserRequest requestData);
/**
* 查询被用户锁定了的订单的id
*
* @param invoicedOrdersRequest 用户id和用户类型
* @return 被用户锁定的历史订单id集合
* @author WH
* @date 2021/12/24 16:01
* @since version-1.0
*/
List<Integer> findLockOrdersByUserIdAndUserType(InvoicedOrdersRequest invoicedOrdersRequest);
}

View File

@ -144,6 +144,11 @@ public class XhpcInvoice implements Serializable {
*/
private Date updateTime;
/**
* 是否已经阅读
*/
private Integer isRead;
/**
* 逻辑删除字段
*/

View File

@ -30,7 +30,7 @@ public class XhpcInvoiceMapHistoryOrder implements Serializable {
private Long historyUserId;
/**
* 该发票所选中的历史订单的用户类型0为C端用户 1流量用户
* 该发票所选中的历史订单的用户类型0 C端用户 1 流量方用户 2社区用户 3B端用户
*/
private Long historyUserType;
@ -79,6 +79,11 @@ public class XhpcInvoiceMapHistoryOrder implements Serializable {
*/
private Long terminalId;
/**
* 该发票所选中的历史订单是否被锁定
*/
private Integer delLock;
/**
* 逻辑删除字段
*/

View File

@ -77,4 +77,15 @@ public interface XhpcInvoiceService {
*/
TitleResponse selectUserInputInvoiceInfo(Long creatorId, Integer creatorType);
/**
* 根据用户id用户类型要查询的当前时间的年月日查询该用户3个月内可以开发票的订单
*
* @param invoicedOrdersRequest 查询条件
* @return 要返回的数据的封装类
* @author WH
* @date 2021/12/24 10:42
* @since version-1.0
*/
InvoiceOrdersResponse selectInvoicedOrders(InvoicedOrdersRequest invoicedOrdersRequest);
}

View File

@ -9,6 +9,7 @@ import com.xhpc.invoice.mapper.*;
import com.xhpc.invoice.pojo.XhpcInvoice;
import com.xhpc.invoice.pojo.XhpcInvoiceMapHistoryOrder;
import com.xhpc.invoice.service.XhpcInvoiceService;
import com.xhpc.order.domain.XhpcHistoryOrder;
import com.xhpc.system.api.domain.SysUser;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -40,6 +41,8 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService {
XhpcChargingStationMapper xhpcChargingStationMapper;
@Resource
SysUserMapper sysUserMapper;
@Resource
XhpcHistoryOrderMapper xhpcHistoryOrderMapper;
/**
* 通过requestData中的申请人申请人类型发票状态发票起始时间发票申请终止时间开票起始时间开票终点时间当前所在页数当前页所要显示几行来查询发票列表信息
@ -53,7 +56,7 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService {
@Override
public AllInvoiceOrdersResponse selectAllInvoiceOrders(AllInvoiceOrdersRequest requestData) {
//计算分页索引
requestData.setCurrentPage(requestData.getCurrentPage() - 1);
requestData.setCurrentPage((requestData.getCurrentPage() - 1) * requestData.getItems());
//获取每个历史订单信息
List<XhpcInvoice> xhpcInvoiceList = xhpcInvoiceMapper.selectAllInvoiceOrdersByCondition(requestData);
//对拷放置到itemsDTO中,然后将itemsDTO存放到itemsDTOList中
@ -165,6 +168,42 @@ public class XhpcInvoiceServiceImpl implements XhpcInvoiceService {
TitleResponse titleResponse = new TitleResponse();
BeanUtils.copyProperties(xhpcInvoice, titleResponse);
return titleResponse;
}
/**
* 根据用户id用户类型要查询的当前时间的年月日查询该用户3个月内可以开发票的历史订单
*
* @param invoicedOrdersRequest 查询条件
* @return 要返回的数据的封装类
* @author WH
* @date 2021/12/24 10:42
* @since version-1.0
*/
@Override
public InvoiceOrdersResponse selectInvoicedOrders(InvoicedOrdersRequest invoicedOrdersRequest) {
//计算分页索引,放置到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;
}
/**

View File

@ -0,0 +1,112 @@
<?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">
<mapper namespace="com.xhpc.invoice.mapper.XhpcHistoryOrderMapper">
<resultMap type="com.xhpc.order.domain.XhpcHistoryOrder" id="XhpcHistoryOrderResult">
<id column="history_order_id" jdbcType="BIGINT" property="historyOrderId"/>
<result column="charging_station_id" jdbcType="BIGINT" property="chargingStationId"/>
<result column="charge_order_id" jdbcType="BIGINT" property="chargeOrderId"/>
<result column="user_id" jdbcType="BIGINT" property="userId"/>
<result column="terminal_id" jdbcType="BIGINT" property="terminalId"/>
<result column="serial_number" jdbcType="VARCHAR" property="serialNumber"/>
<result column="internet_serial_number" jdbcType="VARCHAR" property="internetSerialNumber"/>
<result column="power_price_total" jdbcType="DECIMAL" property="powerPriceTotal"/>
<result column="service_price_total" jdbcType="DECIMAL" property="servicePriceTotal"/>
<result column="total_price" jdbcType="DECIMAL" property="totalPrice"/>
<result column="promotion_discount" jdbcType="DECIMAL" property="promotionDiscount"/>
<result column="act_price" jdbcType="DECIMAL" property="actPrice"/>
<result column="act_power_price" jdbcType="DECIMAL" property="actPowerPrice"/>
<result column="act_service_price" jdbcType="DECIMAL" property="actServicePrice"/>
<result column="internet_commission" jdbcType="DECIMAL" property="internetCommission"/>
<result column="internet_svc_commission" jdbcType="DECIMAL" property="internetSvcCommission"/>
<result column="platform_commission" jdbcType="DECIMAL" property="platformCommission"/>
<result column="platform_svc_commisssion" jdbcType="DECIMAL" property="platformSvcCommisssion"/>
<result column="operation_commission" jdbcType="DECIMAL" property="operationCommission"/>
<result column="operation_svc_commission" jdbcType="DECIMAL" property="operationSvcCommission"/>
<result column="start_soc" jdbcType="VARCHAR" property="startSoc"/>
<result column="end_soc" jdbcType="VARCHAR" property="endSoc"/>
<result column="reconciliation_status" jdbcType="INTEGER" property="reconciliationStatus"/>
<result column="sorting_status" jdbcType="INTEGER" property="sortingStatus"/>
<result column="type" jdbcType="TINYINT" property="type"/>
<result column="status" jdbcType="INTEGER" property="status"/>
<result column="del_flag" jdbcType="INTEGER" property="delFlag"/>
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
<result column="create_by" jdbcType="VARCHAR" property="createBy"/>
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
<result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
<result column="remark" jdbcType="VARCHAR" property="remark"/>
<result column="state" jdbcType="INTEGER" property="state"/>
<result column="vin_normal" jdbcType="VARCHAR" property="vinNormal"/>
<result column="search_value" jdbcType="VARCHAR" property="searchValue"/>
<result column="operator_id_evcs" jdbcType="VARCHAR" property="operatorIdEvcs"/>
<result column="charge_model_evcs" jdbcType="INTEGER" property="chargeModelEvcs"/>
<result column="connector_power_evcs" jdbcType="DOUBLE" property="connectorPowerEvcs"/>
<result column="meter_value_end_evcs" jdbcType="DOUBLE" property="meterValueEndEvcs"/>
<result column="meter_value_start_evcs" jdbcType="DOUBLE" property="meterValueStartEvcs"/>
<result column="operator_id3rdpty_evcs" jdbcType="VARCHAR" property="operatorId3rdptyEvcs"/>
<result column="start_time" jdbcType="TIMESTAMP" property="startTime"/>
<result column="end_time" jdbcType="TIMESTAMP" property="endTime"/>
<result column="stop_reason_evcs" jdbcType="INTEGER" property="stopReasonEvcs"/>
<result column="rate_model_id" jdbcType="BIGINT" property="rateModelId"/>
<result column="total_power" jdbcType="DOUBLE" property="totalPower"/>
<result column="user_name_evcs" jdbcType="VARCHAR" property="userNameEvcs"/>
<result column="phone" jdbcType="VARCHAR" property="phone"/>
<result column="internet_degree_commission" jdbcType="DECIMAL" property="internetDegreeCommission"/>
<result column="source" jdbcType="INTEGER" property="source"/>
</resultMap>
<sql id="Base_Column_List">
history_order_id
, charging_station_id, charge_order_id, user_id, terminal_id, serial_number,
internet_serial_number, power_price_total, service_price_total, total_price, promotion_discount,
act_price, act_power_price, act_service_price, internet_commission, internet_svc_commission,
platform_commission, platform_svc_commisssion, operation_commission, operation_svc_commission,
start_soc, end_soc, reconciliation_status, sorting_status, `type`, `status`, del_flag,
create_time, create_by, update_time, update_by, remark, `state`, vin_normal, search_value,
operator_id_evcs, charge_model_evcs, connector_power_evcs, meter_value_end_evcs,
meter_value_start_evcs, operator_id3rdpty_evcs, start_time, stop_reason_evcs, total_power,
user_name_evcs, phone, rate_model_id
</sql>
<select id="findByCondition" resultMap="XhpcHistoryOrderResult">
SELECT
history_order_id,
serial_number,
act_price,
create_time
FROM
xhpc_history_order
WHERE
user_id = #{invoicedOrdersRequest.userId}
AND source = #{invoicedOrdersRequest.userType}
AND create_time &lt;= #{invoicedOrdersRequest.currentTime}
<if test="lockOrderNumberList!=null">
AND history_order_id
<foreach collection="lockOrderNumberList" item="historyOrderId" open="not in (" close=")" separator=",">
#{historyOrderId}
</foreach>
</if>
ORDER BY
create_time DESC
LIMIT #{invoicedOrdersRequest.currentPage},#{invoicedOrdersRequest.items}
</select>
<select id="findAllOrdersByCondition" resultType="java.lang.Long">
SELECT
count(history_order_id)
FROM
xhpc_history_order
WHERE
user_id = #{invoicedOrdersRequest.userId}
AND source = #{invoicedOrdersRequest.userType}
AND create_time &lt;= #{invoicedOrdersRequest.currentTime}
<if test="lockOrderNumberList!=null">
AND history_order_id
<foreach collection="lockOrderNumberList" item="historyOrderId" open="not in (" close=")" separator=",">
#{historyOrderId}
</foreach>
</if>
</select>
</mapper>

View File

@ -15,8 +15,10 @@
<result column="charging_mode" jdbcType="VARCHAR" property="chargingMode"/>
<result column="charging_station_id" jdbcType="BIGINT" property="chargingStationId"/>
<result column="terminal_id" jdbcType="BIGINT" property="terminalId"/>
<result column="del_lock" jdbcType="TINYINT" property="delLock"/> <!--他自己生成的方法没加这个字段,用到了的时候在加-->
<result column="del_flag" jdbcType="INTEGER" property="delFlag"/>
</resultMap>
<insert id="insert" parameterType="com.xhpc.invoice.pojo.XhpcInvoiceMapHistoryOrder">
insert into xhpc_invoice_map_history_order (invoice_id, history_order_id, history_user_id,
history_user_type, hisotry_serial_number, power_price_total,
@ -123,6 +125,17 @@
</if>
</trim>
</insert>
<update id="updateStatus">
update xhpc_invoice_map_history_order
set lock_flag = 0
where history_order_id in (
(SELECT middle.history_order_id
from (select history_order_id
from xhpc_invoice_map_history_order
where invoice_id = #{invoiceId}) as middle
)
)
</update>
<select id="findOrdersByInvoiceId" resultMap="BaseResultMap">
SELECT *
FROM `xhpc_invoice_map_history_order`
@ -140,4 +153,12 @@
WHERE invoice_id = #{invoiceId}
AND del_flag IS NULL
</select>
<select id="findLockOrdersByUserIdAndUserType" resultType="java.lang.Integer">
SELECT history_order_id
FROM xhpc_invoice_map_history_order
WHERE lock_flag = 0
AND del_flag IS NULL
AND history_user_id = #{userId}
AND history_user_type = #{userType};
</select>
</mapper>