Showing
12 changed files
with
289 additions
and
14 deletions
@@ -2,6 +2,7 @@ package com.yohoufo.dal.order; | @@ -2,6 +2,7 @@ package com.yohoufo.dal.order; | ||
2 | 2 | ||
3 | 3 | ||
4 | import com.yohoufo.dal.order.model.InviteSettlementItem; | 4 | import com.yohoufo.dal.order.model.InviteSettlementItem; |
5 | +import com.yohoufo.dal.order.model.InviteSettlementItemStats; | ||
5 | import org.apache.ibatis.annotations.Param; | 6 | import org.apache.ibatis.annotations.Param; |
6 | 7 | ||
7 | import java.util.List; | 8 | import java.util.List; |
@@ -32,4 +33,17 @@ public interface InviteSettlementItemMapper { | @@ -32,4 +33,17 @@ public interface InviteSettlementItemMapper { | ||
32 | @Param("type") Integer type, | 33 | @Param("type") Integer type, |
33 | @Param("inviteSettlementId") Integer inviteSettlementId); | 34 | @Param("inviteSettlementId") Integer inviteSettlementId); |
34 | 35 | ||
36 | + | ||
37 | + InviteSettlementItemStats selectStats(@Param("uid") Integer uid, | ||
38 | + @Param("type") Integer type, | ||
39 | + @Param("startTime") Integer startTime, | ||
40 | + @Param("endTime") Integer endTime); | ||
41 | + | ||
42 | + List<InviteSettlementItem> select(@Param("uid") Integer uid, | ||
43 | + @Param("type") Integer type, | ||
44 | + @Param("startTime") Integer startTime, | ||
45 | + @Param("endTime") Integer endTime, | ||
46 | + @Param("start") Integer start, | ||
47 | + @Param("limit") Integer limit); | ||
48 | + | ||
35 | } | 49 | } |
@@ -17,4 +17,6 @@ public interface InviteSettlementMapper { | @@ -17,4 +17,6 @@ public interface InviteSettlementMapper { | ||
17 | @Param("uid") Integer uid, @Param("status") Integer status, | 17 | @Param("uid") Integer uid, @Param("status") Integer status, |
18 | @Param("start") Integer start, @Param("limit") Integer limit); | 18 | @Param("start") Integer start, @Param("limit") Integer limit); |
19 | 19 | ||
20 | + List<InviteSettlement> selectByUidAndIds(@Param("uid") Integer uid, @Param("ids") List<Integer> ids); | ||
21 | + | ||
20 | } | 22 | } |
@@ -38,6 +38,8 @@ public class InviteSettlementItem { | @@ -38,6 +38,8 @@ public class InviteSettlementItem { | ||
38 | 38 | ||
39 | private Integer type; | 39 | private Integer type; |
40 | 40 | ||
41 | + private BigDecimal settleAmount; | ||
42 | + | ||
41 | private Integer inviteSettlementId; | 43 | private Integer inviteSettlementId; |
42 | 44 | ||
43 | private Integer status; | 45 | private Integer status; |
1 | +package com.yohoufo.dal.order.model; | ||
2 | + | ||
3 | +import lombok.Data; | ||
4 | + | ||
5 | +import java.math.BigDecimal; | ||
6 | + | ||
7 | +/** | ||
8 | + * @author LUOXC | ||
9 | + * @date 2019/4/11 9:41 | ||
10 | + */ | ||
11 | +@Data | ||
12 | +public class InviteSettlementItemStats { | ||
13 | + | ||
14 | + Integer totalElements; | ||
15 | + | ||
16 | + BigDecimal totalOrderAmount; | ||
17 | + | ||
18 | + BigDecimal totalSettleAmount; | ||
19 | + | ||
20 | +} |
@@ -10,6 +10,7 @@ | @@ -10,6 +10,7 @@ | ||
10 | <result column="order_amount" property="orderAmount" jdbcType="DECIMAL" /> | 10 | <result column="order_amount" property="orderAmount" jdbcType="DECIMAL" /> |
11 | <result column="order_create_time" property="orderCreateTime" jdbcType="INTEGER" /> | 11 | <result column="order_create_time" property="orderCreateTime" jdbcType="INTEGER" /> |
12 | <result column="type" property="type" jdbcType="INTEGER" /> | 12 | <result column="type" property="type" jdbcType="INTEGER" /> |
13 | + <result column="settle_amount" property="settleAmount" jdbcType="DECIMAL" /> | ||
13 | <result column="invite_settlement_id" property="inviteSettlementId" jdbcType="INTEGER" /> | 14 | <result column="invite_settlement_id" property="inviteSettlementId" jdbcType="INTEGER" /> |
14 | <result column="status" property="status" jdbcType="INTEGER" /> | 15 | <result column="status" property="status" jdbcType="INTEGER" /> |
15 | <result column="status_desc" property="statusDesc" jdbcType="VARCHAR" /> | 16 | <result column="status_desc" property="statusDesc" jdbcType="VARCHAR" /> |
@@ -17,17 +18,35 @@ | @@ -17,17 +18,35 @@ | ||
17 | <result column="order_num" property="orderNum" jdbcType="INTEGER" /> | 18 | <result column="order_num" property="orderNum" jdbcType="INTEGER" /> |
18 | </resultMap> | 19 | </resultMap> |
19 | <sql id="Base_Column_List" > | 20 | <sql id="Base_Column_List" > |
20 | - id, uid, buyer_uid, buyer_order_code, seller_uid, order_amount,order_create_time,type, invite_settlement_id, | 21 | + id, uid, buyer_uid, buyer_order_code, seller_uid, order_amount,order_create_time,type,settle_amount, invite_settlement_id, |
21 | status, status_desc, create_time | 22 | status, status_desc, create_time |
22 | </sql> | 23 | </sql> |
23 | <insert id="insert" parameterType="com.yohoufo.dal.order.model.InviteSettlementItem" > | 24 | <insert id="insert" parameterType="com.yohoufo.dal.order.model.InviteSettlementItem" > |
24 | - insert into invite_settlement_item (id, uid, buyer_uid, | ||
25 | - buyer_order_code, seller_uid, order_amount,order_create_time,type, | ||
26 | - invite_settlement_id, status, status_desc, | 25 | + insert into invite_settlement_item (id, |
26 | + uid, | ||
27 | + buyer_uid, | ||
28 | + buyer_order_code, | ||
29 | + seller_uid, | ||
30 | + order_amount, | ||
31 | + order_create_time, | ||
32 | + type, | ||
33 | + settle_amount, | ||
34 | + invite_settlement_id, | ||
35 | + status, | ||
36 | + status_desc, | ||
27 | create_time) | 37 | create_time) |
28 | - values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{buyerUid,jdbcType=INTEGER}, | ||
29 | - #{buyerOrderCode,jdbcType=BIGINT}, #{sellerUid,jdbcType=INTEGER}, #{orderAmount,jdbcType=DECIMAL}, #{orderCreateTime,jdbcType=INTEGER}, #{type,jdbcType=INTEGER}, | ||
30 | - #{inviteSettlementId,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}, #{statusDesc,jdbcType=VARCHAR}, | 38 | + values (#{id,jdbcType=INTEGER}, |
39 | + #{uid,jdbcType=INTEGER}, | ||
40 | + #{buyerUid,jdbcType=INTEGER}, | ||
41 | + #{buyerOrderCode,jdbcType=BIGINT}, | ||
42 | + #{sellerUid,jdbcType=INTEGER}, | ||
43 | + #{orderAmount,jdbcType=DECIMAL}, | ||
44 | + #{orderCreateTime,jdbcType=INTEGER}, | ||
45 | + #{type,jdbcType=INTEGER}, | ||
46 | + #{settleAmount,jdbcType=DECIMAL}, | ||
47 | + #{inviteSettlementId,jdbcType=INTEGER}, | ||
48 | + #{status,jdbcType=INTEGER}, | ||
49 | + #{statusDesc,jdbcType=VARCHAR}, | ||
31 | #{createTime,jdbcType=INTEGER}) | 50 | #{createTime,jdbcType=INTEGER}) |
32 | </insert> | 51 | </insert> |
33 | 52 | ||
@@ -74,4 +93,28 @@ | @@ -74,4 +93,28 @@ | ||
74 | from invite_settlement_item | 93 | from invite_settlement_item |
75 | where uid = #{uid,jdbcType=INTEGER} and type = #{type,jdbcType=INTEGER} and invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER} | 94 | where uid = #{uid,jdbcType=INTEGER} and type = #{type,jdbcType=INTEGER} and invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER} |
76 | </select> | 95 | </select> |
96 | + | ||
97 | + <select id="selectStats" resultType="com.yohoufo.dal.order.model.InviteSettlementItemStats" > | ||
98 | + select | ||
99 | + count(1) as 'totalElements', | ||
100 | + sum(order_amount) as 'totalOrderAmount' | ||
101 | + from invite_settlement_item | ||
102 | + where uid = #{uid,jdbcType=INTEGER} | ||
103 | + and type = #{type,jdbcType=INTEGER} | ||
104 | + and status in (1,3) | ||
105 | + and order_create_time between #{startTime,jdbcType=INTEGER} and #{endTime,jdbcType=INTEGER} | ||
106 | + </select> | ||
107 | + | ||
108 | + <select id="select" resultMap="BaseResultMap" > | ||
109 | + select | ||
110 | + <include refid="Base_Column_List" /> | ||
111 | + from invite_settlement_item | ||
112 | + where uid = #{uid,jdbcType=INTEGER} | ||
113 | + and type = #{type,jdbcType=INTEGER} | ||
114 | + and status in (1,3) | ||
115 | + and order_create_time between #{startTime,jdbcType=INTEGER} and #{endTime,jdbcType=INTEGER} | ||
116 | + order by order_create_time desc | ||
117 | + limit #{start,jdbcType=INTEGER},#{limit,jdbcType=INTEGER} | ||
118 | + </select> | ||
119 | + | ||
77 | </mapper> | 120 | </mapper> |
@@ -49,4 +49,15 @@ | @@ -49,4 +49,15 @@ | ||
49 | limit #{start,jdbcType=INTEGER}, #{limit,jdbcType=INTEGER} | 49 | limit #{start,jdbcType=INTEGER}, #{limit,jdbcType=INTEGER} |
50 | </select> | 50 | </select> |
51 | 51 | ||
52 | + <select id="selectByUidAndIds" resultMap="BaseResultMap" > | ||
53 | + select | ||
54 | + <include refid="Base_Column_List" /> | ||
55 | + from invite_settlement | ||
56 | + where uid = #{uid,jdbcType=INTEGER} | ||
57 | + and id in | ||
58 | + <foreach collection="ids" item="id" open="(" separator="," close=")"> | ||
59 | + #{id} | ||
60 | + </foreach> | ||
61 | + </select> | ||
62 | + | ||
52 | </mapper> | 63 | </mapper> |
1 | package com.yohoufo.order.controller; | 1 | package com.yohoufo.order.controller; |
2 | 2 | ||
3 | import com.yohoufo.common.ApiResponse; | 3 | import com.yohoufo.common.ApiResponse; |
4 | +import com.yohoufo.order.model.InviteSettlementItemListVO; | ||
4 | import com.yohoufo.order.model.InviteSettlementListVO; | 5 | import com.yohoufo.order.model.InviteSettlementListVO; |
5 | import com.yohoufo.order.service.IInviteSettlementService; | 6 | import com.yohoufo.order.service.IInviteSettlementService; |
6 | import lombok.extern.slf4j.Slf4j; | 7 | import lombok.extern.slf4j.Slf4j; |
@@ -18,7 +19,7 @@ import org.springframework.web.bind.annotation.RestController; | @@ -18,7 +19,7 @@ import org.springframework.web.bind.annotation.RestController; | ||
18 | public class InviteSettlementController { | 19 | public class InviteSettlementController { |
19 | 20 | ||
20 | @Autowired | 21 | @Autowired |
21 | - private IInviteSettlementService inviterService; | 22 | + private IInviteSettlementService inviteSettlementService; |
22 | 23 | ||
23 | /** | 24 | /** |
24 | * 我的收款记录 | 25 | * 我的收款记录 |
@@ -29,13 +30,29 @@ public class InviteSettlementController { | @@ -29,13 +30,29 @@ public class InviteSettlementController { | ||
29 | @RequestMapping(params = "method=ufo.invite.getInviteSettlementList") | 30 | @RequestMapping(params = "method=ufo.invite.getInviteSettlementList") |
30 | public ApiResponse getInviteSettlementList(@RequestParam(value = "uid") int uid) { | 31 | public ApiResponse getInviteSettlementList(@RequestParam(value = "uid") int uid) { |
31 | log.info("get inviter settlement list, uid is {}", uid); | 32 | log.info("get inviter settlement list, uid is {}", uid); |
32 | - InviteSettlementListVO inviteSettlementListVO = inviterService.getInviteSettlementList(uid); | 33 | + InviteSettlementListVO inviteSettlementListVO = inviteSettlementService.getInviteSettlementList(uid); |
33 | return new ApiResponse.ApiResponseBuilder().code(200).data(inviteSettlementListVO).message("ok").build(); | 34 | return new ApiResponse.ApiResponseBuilder().code(200).data(inviteSettlementListVO).message("ok").build(); |
34 | } | 35 | } |
35 | 36 | ||
37 | + /** | ||
38 | + * 我的收款记录明细 | ||
39 | + * | ||
40 | + * @param uid | ||
41 | + * @return | ||
42 | + */ | ||
43 | + @RequestMapping(params = "method=ufo.invite.getInviteSettlementItemList") | ||
44 | + public ApiResponse getInviteSettlementItemList(@RequestParam(value = "uid") Integer uid, | ||
45 | + @RequestParam(value = "month") String month, | ||
46 | + @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, | ||
47 | + @RequestParam(value = "limit", required = false, defaultValue = "10") Integer limit) { | ||
48 | + log.info("get inviter settlement item list, uid is {}", uid); | ||
49 | + InviteSettlementItemListVO resp = inviteSettlementService.getInviteSettlementItemList(uid, month, page, limit); | ||
50 | + return new ApiResponse.ApiResponseBuilder().code(200).data(resp).message("ok").build(); | ||
51 | + } | ||
52 | + | ||
36 | @RequestMapping(value = "/erp/invite/settlement/help/settle") | 53 | @RequestMapping(value = "/erp/invite/settlement/help/settle") |
37 | public ApiResponse settle() { | 54 | public ApiResponse settle() { |
38 | - inviterService.settle(); | 55 | + inviteSettlementService.settle(); |
39 | return new ApiResponse.ApiResponseBuilder().code(200).message("ok").build(); | 56 | return new ApiResponse.ApiResponseBuilder().code(200).message("ok").build(); |
40 | } | 57 | } |
41 | 58 |
1 | +package com.yohoufo.order.model; | ||
2 | + | ||
3 | +import lombok.Data; | ||
4 | +import lombok.experimental.Builder; | ||
5 | + | ||
6 | +import java.util.List; | ||
7 | + | ||
8 | +/** | ||
9 | + * @author LUOXC | ||
10 | + * @date 2019/4/2 15:00 | ||
11 | + */ | ||
12 | +@Builder | ||
13 | +@Data | ||
14 | +public class InviteSettlementItemListVO { | ||
15 | + | ||
16 | + | ||
17 | + int page; | ||
18 | + int pageTotal; | ||
19 | + int pageSize; | ||
20 | + int totalElements; | ||
21 | + String totalOrderAmount; | ||
22 | + String totalSettleAmount; | ||
23 | + List<InviteSettlementItemVO> list; | ||
24 | + | ||
25 | + @Data | ||
26 | + public static class InviteSettlementItemVO { | ||
27 | + String buyerOrderCode; | ||
28 | + String sellerName; | ||
29 | + String orderAmount; | ||
30 | + String orderCreateTime; | ||
31 | + String settleAmount; | ||
32 | + String statusDesc; | ||
33 | + } | ||
34 | + | ||
35 | +} |
1 | package com.yohoufo.order.service; | 1 | package com.yohoufo.order.service; |
2 | 2 | ||
3 | +import com.yohoufo.order.model.InviteSettlementItemListVO; | ||
3 | import com.yohoufo.order.model.InviteSettlementListVO; | 4 | import com.yohoufo.order.model.InviteSettlementListVO; |
4 | 5 | ||
5 | public interface IInviteSettlementService { | 6 | public interface IInviteSettlementService { |
@@ -12,6 +13,8 @@ public interface IInviteSettlementService { | @@ -12,6 +13,8 @@ public interface IInviteSettlementService { | ||
12 | */ | 13 | */ |
13 | InviteSettlementListVO getInviteSettlementList(Integer uid); | 14 | InviteSettlementListVO getInviteSettlementList(Integer uid); |
14 | 15 | ||
16 | + InviteSettlementItemListVO getInviteSettlementItemList(Integer uid, String month, Integer page, Integer limit); | ||
17 | + | ||
15 | /** | 18 | /** |
16 | * 结算 | 19 | * 结算 |
17 | */ | 20 | */ |
1 | package com.yohoufo.order.service.impl; | 1 | package com.yohoufo.order.service.impl; |
2 | 2 | ||
3 | +import com.google.common.annotations.VisibleForTesting; | ||
4 | +import com.google.common.collect.Lists; | ||
3 | import com.yohoufo.common.utils.DateUtil; | 5 | import com.yohoufo.common.utils.DateUtil; |
6 | +import com.yohoufo.dal.order.InviteSettlementItemMapper; | ||
4 | import com.yohoufo.dal.order.InviteSettlementMapper; | 7 | import com.yohoufo.dal.order.InviteSettlementMapper; |
5 | import com.yohoufo.dal.order.InviterMapper; | 8 | import com.yohoufo.dal.order.InviterMapper; |
6 | import com.yohoufo.dal.order.model.InviteSettlement; | 9 | import com.yohoufo.dal.order.model.InviteSettlement; |
10 | +import com.yohoufo.dal.order.model.InviteSettlementItem; | ||
11 | +import com.yohoufo.dal.order.model.InviteSettlementItemStats; | ||
7 | import com.yohoufo.dal.order.model.Inviter; | 12 | import com.yohoufo.dal.order.model.Inviter; |
13 | +import com.yohoufo.order.model.InviteSettlementItemListVO; | ||
8 | import com.yohoufo.order.model.InviteSettlementListVO; | 14 | import com.yohoufo.order.model.InviteSettlementListVO; |
9 | import com.yohoufo.order.service.IInviteSettlementService; | 15 | import com.yohoufo.order.service.IInviteSettlementService; |
10 | -import com.yohoufo.order.utils.IdUtils; | 16 | +import com.yohoufo.order.utils.InviteSettlementUtils; |
11 | import lombok.extern.slf4j.Slf4j; | 17 | import lombok.extern.slf4j.Slf4j; |
18 | +import lombok.val; | ||
19 | +import org.apache.commons.collections.CollectionUtils; | ||
20 | +import org.apache.commons.lang3.tuple.Pair; | ||
12 | import org.springframework.beans.factory.annotation.Autowired; | 21 | import org.springframework.beans.factory.annotation.Autowired; |
13 | import org.springframework.stereotype.Service; | 22 | import org.springframework.stereotype.Service; |
14 | 23 | ||
15 | -import java.math.RoundingMode; | 24 | +import java.math.BigDecimal; |
16 | import java.time.LocalDateTime; | 25 | import java.time.LocalDateTime; |
17 | import java.time.ZoneOffset; | 26 | import java.time.ZoneOffset; |
18 | import java.time.format.DateTimeFormatter; | 27 | import java.time.format.DateTimeFormatter; |
28 | +import java.util.Collections; | ||
19 | import java.util.List; | 29 | import java.util.List; |
30 | +import java.util.Map; | ||
31 | +import java.util.Objects; | ||
20 | import java.util.stream.Collectors; | 32 | import java.util.stream.Collectors; |
21 | 33 | ||
34 | +import static com.yohoufo.order.utils.ServiceExceptions.throwServiceException; | ||
35 | + | ||
22 | /** | 36 | /** |
23 | * @author LUOXC | 37 | * @author LUOXC |
24 | * @date 2019/4/2 15:27 | 38 | * @date 2019/4/2 15:27 |
@@ -37,6 +51,9 @@ public class InviteSettlementServiceImpl implements IInviteSettlementService { | @@ -37,6 +51,9 @@ public class InviteSettlementServiceImpl implements IInviteSettlementService { | ||
37 | private InviteSettlementMapper inviteSettlementMapper; | 51 | private InviteSettlementMapper inviteSettlementMapper; |
38 | 52 | ||
39 | @Autowired | 53 | @Autowired |
54 | + private InviteSettlementItemMapper inviteSettlementItemMapper; | ||
55 | + | ||
56 | + @Autowired | ||
40 | private InviteSettlementItemCreator inviteSettlementItemCreator; | 57 | private InviteSettlementItemCreator inviteSettlementItemCreator; |
41 | 58 | ||
42 | @Override | 59 | @Override |
@@ -46,12 +63,12 @@ public class InviteSettlementServiceImpl implements IInviteSettlementService { | @@ -46,12 +63,12 @@ public class InviteSettlementServiceImpl implements IInviteSettlementService { | ||
46 | List<InviteSettlement> inviteSettlementList = inviteSettlementMapper.selectByUidAndStatusWithLimit(uid, InviteSettlement.STATUS_PAID, 0, 100); | 63 | List<InviteSettlement> inviteSettlementList = inviteSettlementMapper.selectByUidAndStatusWithLimit(uid, InviteSettlement.STATUS_PAID, 0, 100); |
47 | 64 | ||
48 | // build vo | 65 | // build vo |
49 | - ZoneOffset zoneOffset = ZoneOffset.of("+8"); | 66 | + |
50 | List<InviteSettlementListVO.InviteSettlementVO> items = inviteSettlementList.stream() | 67 | List<InviteSettlementListVO.InviteSettlementVO> items = inviteSettlementList.stream() |
51 | .map(inviteSettlement -> { | 68 | .map(inviteSettlement -> { |
52 | InviteSettlementListVO.InviteSettlementVO item = new InviteSettlementListVO.InviteSettlementVO(); | 69 | InviteSettlementListVO.InviteSettlementVO item = new InviteSettlementListVO.InviteSettlementVO(); |
53 | item.setSettleCode(String.format("%010d", inviteSettlement.getSettleCode())); | 70 | item.setSettleCode(String.format("%010d", inviteSettlement.getSettleCode())); |
54 | - item.setSettleAmount("+" + inviteSettlement.getSettleAmount().setScale(1, RoundingMode.FLOOR)); | 71 | + item.setSettleAmount(InviteSettlementUtils.format("+%s", inviteSettlement.getSettleAmount())); |
55 | item.setSettleTime(DateUtil.formatYYMMddHHmmssPoint(inviteSettlement.getSettleTime())); | 72 | item.setSettleTime(DateUtil.formatYYMMddHHmmssPoint(inviteSettlement.getSettleTime())); |
56 | item.setPaidTime(DateUtil.formatYYMMddHHmmssPoint(inviteSettlement.getPaidTime())); | 73 | item.setPaidTime(DateUtil.formatYYMMddHHmmssPoint(inviteSettlement.getPaidTime())); |
57 | return item; | 74 | return item; |
@@ -63,6 +80,73 @@ public class InviteSettlementServiceImpl implements IInviteSettlementService { | @@ -63,6 +80,73 @@ public class InviteSettlementServiceImpl implements IInviteSettlementService { | ||
63 | } | 80 | } |
64 | 81 | ||
65 | @Override | 82 | @Override |
83 | + public InviteSettlementItemListVO getInviteSettlementItemList(Integer uid, String month, Integer page, Integer limit) { | ||
84 | + Pair<Integer, Integer> time = getTimeRangeOfMonth(month); | ||
85 | + // 只查询结算规则1的记录 | ||
86 | + int settlementType = 1; | ||
87 | + InviteSettlementItemStats stats = inviteSettlementItemMapper.selectStats(uid, settlementType, time.getLeft(), time.getRight()); | ||
88 | + int totalElements = Objects.isNull(stats.getTotalElements()) ? 0 : stats.getTotalElements(); | ||
89 | + BigDecimal totalOrderAmount = Objects.isNull(stats.getTotalOrderAmount()) ? BigDecimal.ZERO : stats.getTotalOrderAmount(); | ||
90 | + BigDecimal totalSettleAmount = Objects.isNull(stats.getTotalSettleAmount()) ? BigDecimal.ZERO : stats.getTotalSettleAmount(); | ||
91 | + InviteSettlementItemListVO.InviteSettlementItemListVOBuilder builder = InviteSettlementItemListVO.builder(); | ||
92 | + builder.page(page) | ||
93 | + .pageSize(limit) | ||
94 | + .pageTotal((totalElements % limit == 0) ? (totalElements / limit) : (totalElements / limit + 1)) | ||
95 | + .totalElements(totalElements) | ||
96 | + .totalOrderAmount(InviteSettlementUtils.format(totalOrderAmount)) | ||
97 | + .totalSettleAmount(InviteSettlementUtils.format(totalSettleAmount)); | ||
98 | + if (totalElements == 0) { | ||
99 | + return builder.list(Lists.newArrayList()).build(); | ||
100 | + } | ||
101 | + int start = (page - 1) * limit; | ||
102 | + List<InviteSettlementItem> list = inviteSettlementItemMapper.select(uid, settlementType, time.getLeft(), time.getRight(), start, limit); | ||
103 | + Map<Integer, Integer> settlementStatusMap = buildInviteSettlementIdStatusMap(uid, list); | ||
104 | + return builder | ||
105 | + .list(list.stream().map(item -> { | ||
106 | + Integer settlementStatus = settlementStatusMap.getOrDefault(item.getInviteSettlementId(), InviteSettlement.STATUS_WAIT_SETTLE); | ||
107 | + InviteSettlementItemListVO.InviteSettlementItemVO vo = new InviteSettlementItemListVO.InviteSettlementItemVO(); | ||
108 | + vo.setBuyerOrderCode(item.getBuyerOrderCode().toString()); | ||
109 | + vo.setSellerName(item.getSellerUid().toString()); | ||
110 | + vo.setOrderAmount(InviteSettlementUtils.format(item.getOrderAmount())); | ||
111 | + vo.setOrderCreateTime(DateUtil.formatYYMMddHHmmssPoint(item.getOrderCreateTime())); | ||
112 | + vo.setSettleAmount(InviteSettlementUtils.format(item.getSettleAmount())); | ||
113 | + vo.setStatusDesc(settlementStatus.equals(InviteSettlement.STATUS_PAID) ? "已付款" : "待付款"); | ||
114 | + return vo; | ||
115 | + }).collect(Collectors.toList())) | ||
116 | + .build(); | ||
117 | + } | ||
118 | + | ||
119 | + private Map<Integer, Integer> buildInviteSettlementIdStatusMap(Integer uid, List<InviteSettlementItem> list) { | ||
120 | + val inviteSettlementIds = list.stream() | ||
121 | + .map(InviteSettlementItem::getInviteSettlementId) | ||
122 | + .filter(Objects::nonNull) | ||
123 | + .distinct() | ||
124 | + .collect(Collectors.toList()); | ||
125 | + if (CollectionUtils.isEmpty(inviteSettlementIds)) { | ||
126 | + return Collections.emptyMap(); | ||
127 | + } else { | ||
128 | + return inviteSettlementMapper.selectByUidAndIds(uid, inviteSettlementIds).stream() | ||
129 | + .collect(Collectors.toMap(InviteSettlement::getId, InviteSettlement::getStatus)); | ||
130 | + } | ||
131 | + } | ||
132 | + | ||
133 | + @VisibleForTesting | ||
134 | + Pair<Integer, Integer> getTimeRangeOfMonth(String month) { | ||
135 | + LocalDateTime requestMonth = null; | ||
136 | + try { | ||
137 | + requestMonth = LocalDateTime.parse(month, DateTimeFormatter.ofPattern("yyyyMM")); | ||
138 | + } catch (Exception e) { | ||
139 | + throwServiceException("日期格式不正确"); | ||
140 | + } | ||
141 | + ZoneOffset zoneOffset = ZoneOffset.of("+8"); | ||
142 | + int startTime = (int) LocalDateTime.of(requestMonth.getYear(), requestMonth.getMonthValue(), 1, 0, 0, 0) | ||
143 | + .toEpochSecond(zoneOffset); | ||
144 | + int endTime = (int) LocalDateTime.of(requestMonth.getYear(), requestMonth.getMonthValue() + 1, 1, 0, 0, 0) | ||
145 | + .toEpochSecond(zoneOffset) - 1; | ||
146 | + return Pair.of(startTime, endTime); | ||
147 | + } | ||
148 | + | ||
149 | + @Override | ||
66 | public void settle() { | 150 | public void settle() { |
67 | inviterMapper.selectAll().stream() | 151 | inviterMapper.selectAll().stream() |
68 | .map(Inviter::getUid) | 152 | .map(Inviter::getUid) |
1 | +package com.yohoufo.order.utils; | ||
2 | + | ||
3 | +import java.math.BigDecimal; | ||
4 | +import java.math.RoundingMode; | ||
5 | +import java.util.Objects; | ||
6 | + | ||
7 | +/** | ||
8 | + * @author LUOXC | ||
9 | + * @date 2019/4/11 11:04 | ||
10 | + */ | ||
11 | +public class InviteSettlementUtils { | ||
12 | + | ||
13 | + public static String format(BigDecimal src) { | ||
14 | + return format("%s", src); | ||
15 | + } | ||
16 | + | ||
17 | + public static String format(String format, BigDecimal src) { | ||
18 | + if (Objects.isNull(src)) { | ||
19 | + return null; | ||
20 | + } else { | ||
21 | + return String.format(format, src.setScale(1, RoundingMode.FLOOR)); | ||
22 | + } | ||
23 | + } | ||
24 | + | ||
25 | +} |
1 | +package com.yohoufo.order.service.impl; | ||
2 | + | ||
3 | +import org.apache.commons.lang3.tuple.Pair; | ||
4 | +import org.junit.Assert; | ||
5 | +import org.junit.Test; | ||
6 | + | ||
7 | +import static org.junit.Assert.*; | ||
8 | + | ||
9 | +public class InviteSettlementServiceImplTest { | ||
10 | + | ||
11 | + @Test | ||
12 | + public void getTimeRangeOfMonth() { | ||
13 | + | ||
14 | + Pair<Integer, Integer> integerIntegerPair = new InviteSettlementServiceImpl().getTimeRangeOfMonth("201903"); | ||
15 | + Assert.assertEquals(integerIntegerPair.getLeft().intValue(),1551369600); | ||
16 | + Assert.assertEquals(integerIntegerPair.getRight().intValue(),1554047999); | ||
17 | + } | ||
18 | + | ||
19 | +} |
-
Please register or login to post a comment