dcs 5 months ago
parent
commit
749b494f92

+ 2 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/dao/PaymentInvoiceDao.java

@@ -26,4 +26,6 @@ public interface PaymentInvoiceDao {
     PaymentInvoice get(long id);
 
     List<PaymentInvoice> getPaymentOrdinaryId(long id);
+
+    List<PaymentInvoice> getPaymentOrdinaryIds(List<Long> ids);
 }

+ 2 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/dao/PaymentRecordDao.java

@@ -22,4 +22,6 @@ public interface PaymentRecordDao {
 
     List<PaymentRecord> getPaymentOrdinaryId(long paymentOrdinaryId);
 
+    List<PaymentRecord> getPaymentOrdinaryIds(List<Long> ids);
+
 }

+ 6 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/model/PaymentRecord.java

@@ -1,5 +1,7 @@
 package com.bosshand.virgo.api.model;
 
+import com.fasterxml.jackson.annotation.JsonFormat;
+
 /**
  * 付款记录
  */
@@ -25,6 +27,10 @@ public class PaymentRecord {
     /**
      * 时间
      */
+    /**
+     * 时间
+     */
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     private String date;
 
     /**

+ 18 - 5
virgo.api/src/main/java/com/bosshand/virgo/api/service/PaymentService.java

@@ -11,10 +11,8 @@ import org.springframework.stereotype.Service;
 import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.time.temporal.ChronoUnit;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.stream.Collectors;
 
 @Service
 public class PaymentService {
@@ -246,7 +244,22 @@ public class PaymentService {
 
     public List<PaymentOrdinary> getLimit(PaymentOrdinary paymentOrdinary, int currPage, int pageSize) {
         int currIndex = (currPage - 1) * pageSize;
-        return paymentOrdinaryDao.getLimit(paymentOrdinary, currIndex, pageSize);
+        List<PaymentOrdinary> list = paymentOrdinaryDao.getLimit(paymentOrdinary, currIndex, pageSize);
+        if (list.size() > 0) {
+            List<Long> ids = new ArrayList<>();
+            list.forEach(ls -> ids.add(ls.getId()));
+
+            List<PaymentInvoice> paymentInvoiceList = paymentInvoiceDao.getPaymentOrdinaryIds(ids);
+            Map<Long, List<PaymentInvoice>> groupedByPaymentInvoice = paymentInvoiceList.stream().collect(Collectors.groupingBy(PaymentInvoice::getPaymentOrdinaryId));
+            List<PaymentRecord> paymentRecordList = paymentRecordDao.getPaymentOrdinaryIds(ids);
+            Map<Long, List<PaymentRecord>> groupedByPaymentRecord = paymentRecordList.stream().collect(Collectors.groupingBy(PaymentRecord::getPaymentOrdinaryId));
+
+            for (PaymentOrdinary po : list) {
+                po.setPaymentInvoiceList(groupedByPaymentInvoice.get(po.getId()));
+                po.setPaymentRecordList(groupedByPaymentRecord.get(po.getId()));
+            }
+        }
+        return list;
     }
 
     public PaymentOrdinary getPaymentOrdinary(long id) {

+ 8 - 0
virgo.api/src/main/resources/mapper/PaymentInvoiceMapper.xml

@@ -201,6 +201,14 @@
         SELECT * FROM  payment_invoice where paymentOrdinaryId = #{paymentOrdinaryId}
     </select>
 
+    <select id="getPaymentOrdinaryIds" resultMap="result">
+        SELECT * FROM payment_invoice where paymentOrdinaryId in (
+        <foreach collection="list" item="item" index="index" separator=",">
+            #{item}
+        </foreach>
+        )
+    </select>
+
     <select id="get" resultMap="result">
         <include refid="query"/>
         where a.id = #{id}

+ 9 - 2
virgo.api/src/main/resources/mapper/PaymentRecordMapper.xml

@@ -16,7 +16,7 @@
 
     <insert id="insert" parameterType="com.bosshand.virgo.api.model.PaymentRecord" useGeneratedKeys="true" keyProperty="id">
         INSERT INTO  payment_record (`paymentOrdinaryId`, `paymentId`, `name`, `date`, `attachment`, `data`)
-        VALUES (#{paymentOrdinaryId}, #{paymentId}, #{name}, #{date}, #{attachment}, #{data})
+        VALUES (#{paymentOrdinaryId}, #{paymentId}, #{name}, now(), #{attachment}, #{data})
     </insert>
 
     <delete id="delete">
@@ -30,7 +30,6 @@
             <if test="paymentOrdinaryId!=0">paymentOrdinaryId=#{paymentOrdinaryId},</if>
             <if test="paymentId!=0">paymentId=#{paymentId},</if>
             <if test="name!=null">name=#{name},</if>
-            <if test="date!=null">date=#{date},</if>
             <if test="attachment!=null">attachment=#{attachment},</if>
             <if test="data!=null">data=#{data},</if>
         </trim>
@@ -57,6 +56,14 @@
         SELECT * FROM  payment_record where paymentOrdinaryId = #{paymentOrdinaryId}
     </select>
 
+    <select id="getPaymentOrdinaryIds" resultMap="result">
+        SELECT * FROM  payment_record where paymentOrdinaryId in (
+        <foreach collection="list" item="item" index="index" separator=",">
+            #{item}
+        </foreach>
+        )
+    </select>
+
     <select id="get" resultMap="result">
         SELECT * FROM  payment_record where id = #{id}
     </select>