Authored by mali

Merge branch 'master' into test6.9.1

Conflicts:
	order/src/main/java/com/yohoufo/order/controller/InviteSettlementController.java
	order/src/main/java/com/yohoufo/order/service/IInviteSettlementService.java
	order/src/main/java/com/yohoufo/order/service/impl/InviteSettlementServiceImpl.java
... ... @@ -17,6 +17,9 @@ public interface InviteSettlementItemMapper {
@Param("tagStatus") Integer tagStatus,
@Param("inviteSettlementId") Integer inviteSettlementId);
int updateStatusByUidAndInviteSettlementId(@Param("uid") Integer uid, @Param("inviteSettlementId") Integer inviteSettlementId,
@Param("status") Integer status);
InviteSettlementItem selectByUidAndBuyerOrderCode(@Param("uid") Integer uid, @Param("buyerOrderCode") Long buyerOrderCode);
InviteSettlementItem selectOneByUidAndStatus(@Param("uid") Integer uid,
... ... @@ -26,8 +29,6 @@ public interface InviteSettlementItemMapper {
@Param("type") Integer type,
@Param("inviteSettlementId") Integer inviteSettlementId);
List<InviteSettlementItem> selectOrderNumByInviterUid(@Param("inviterUid") Integer inviterUid);
int updateByPrimaryKeySelective(InviteSettlementItem record);
List<InviteSettlementItemStats> selectStatsByUidTypeAndInviteSettlementIdGroupBySellerUid(@Param("uid") Integer uid,
... ... @@ -40,12 +41,40 @@ public interface InviteSettlementItemMapper {
@Param("sellerUid") Integer sellerUid);
/**
* 查询type1 结算方式的待结算、已结算和已付款订单数
* @param inviterUid
* @return
*/
List<InviteSettlementItem> selectOrderNumByInviterUid(@Param("inviterUid") Integer inviterUid);
/**
* 根据条件查询,待结算、已结算和已付款的统计数据
* @param uid
* @param type
* @param startTime
* @param endTime
* @return
*/
InviteSettlementItemStats selectStats(@Param("uid") Integer uid,
@Param("statusList") List<Integer> statusList,
@Param("type") Integer type,
@Param("startTime") Integer startTime,
@Param("endTime") Integer endTime);
/**
* 根据条件查询,待结算、已结算和已付款的数据
* @param uid
* @param type
* @param startTime
* @param endTime
* @param start
* @param limit
* @return
*/
List<InviteSettlementItem> select(@Param("uid") Integer uid,
@Param("statusList") List<Integer> statusList,
@Param("type") Integer type,
@Param("startTime") Integer startTime,
@Param("endTime") Integer endTime,
... ...
... ... @@ -19,4 +19,6 @@ public interface InviteSettlementMapper {
List<InviteSettlement> selectByUidAndIds(@Param("uid") Integer uid, @Param("ids") List<Integer> ids);
List<InviteSettlement> selectByIds(@Param("ids") List<Integer> ids);
}
\ No newline at end of file
... ...
... ... @@ -22,6 +22,11 @@ public class InviteSettlementItem {
*/
public static final int STATUS_SETTLED = 3;
/**
* 结算项状态:已付款
*/
public static final int STATUS_PAID = 4;
private Integer id;
private Integer uid;
... ...
... ... @@ -19,4 +19,8 @@ public class InviteSettlementItemStats {
BigDecimal totalSettleAmount;
BigDecimal totalPaidAmount;
BigDecimal totalWaitPayAmount;
}
... ...
... ... @@ -59,6 +59,13 @@
and status = #{srcStatus,jdbcType=INTEGER}
</update>
<update id="updateStatusByUidAndInviteSettlementId">
update invite_settlement_item
set status = #{status,jdbcType=INTEGER}
where uid = #{uid,jdbcType=INTEGER}
and invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER}
</update>
<select id="selectByUidAndBuyerOrderCode" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
... ... @@ -75,14 +82,6 @@
limit 1
</select>
<select id="selectOrderNumByInviterUid" resultMap="BaseResultMap" >
select
seller_uid, count(buyer_order_code) order_num
from invite_settlement_item
where uid = #{inviterUid,jdbcType=INTEGER} and status in (1,3)
GROUP by seller_uid
</select>
<select id="selectCountByUidTypeAndInviteSettlementId" resultType="java.lang.Integer" >
select
count(1)
... ... @@ -97,7 +96,9 @@
sum(order_amount) as 'totalOrderAmount',
sum(settle_amount) as 'totalSettleAmount'
from invite_settlement_item
where uid = #{uid,jdbcType=INTEGER} and type = #{type,jdbcType=INTEGER} and invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER}
where uid = #{uid,jdbcType=INTEGER}
and type = #{type,jdbcType=INTEGER}
and invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER}
group by seller_uid
</select>
... ... @@ -107,19 +108,38 @@
select
<include refid="Base_Column_List" />
from invite_settlement_item
where uid = #{uid,jdbcType=INTEGER} and type = #{type,jdbcType=INTEGER} and invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER}
where uid = #{uid,jdbcType=INTEGER}
and type = #{type,jdbcType=INTEGER}
and invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER}
and seller_uid = #{sellerUid,jdbcType=INTEGER}
</select>
<select id="selectOrderNumByInviterUid" resultMap="BaseResultMap" >
select
seller_uid, count(buyer_order_code) order_num
from invite_settlement_item
where uid = #{inviterUid,jdbcType=INTEGER}
and type = 1
and status in (1,3,4)
GROUP by seller_uid
</select>
<select id="selectStats" resultType="com.yohoufo.dal.order.model.InviteSettlementItemStats" >
select
count(1) as 'totalElements',
sum(order_amount) as 'totalOrderAmount',
sum(settle_amount) as 'totalSettleAmount'
sum(settle_amount) as 'totalSettleAmount',
sum(if(status=4,settle_amount,0)) as 'totalPaidAmount',
sum(if(status!=4,settle_amount,0)) as 'totalWaitPayAmount'
from invite_settlement_item
where uid = #{uid,jdbcType=INTEGER}
and type = #{type,jdbcType=INTEGER}
and status in (1,3)
and status in
<foreach collection="statusList" item="status" open="(" separator="," close=")">
#{status}
</foreach>
and order_create_time between #{startTime,jdbcType=INTEGER} and #{endTime,jdbcType=INTEGER}
</select>
... ... @@ -129,7 +149,10 @@
from invite_settlement_item
where uid = #{uid,jdbcType=INTEGER}
and type = #{type,jdbcType=INTEGER}
and status in (1,3)
and status in
<foreach collection="statusList" item="status" open="(" separator="," close=")">
#{status}
</foreach>
and order_create_time between #{startTime,jdbcType=INTEGER} and #{endTime,jdbcType=INTEGER}
order by order_create_time desc
limit #{start,jdbcType=INTEGER},#{limit,jdbcType=INTEGER}
... ...
... ... @@ -70,4 +70,14 @@
</foreach>
</select>
<select id="selectByIds" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from invite_settlement
where id in
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -2,16 +2,16 @@ package com.yohoufo.order.controller;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.order.model.InviteSettlementItemListVO;
import com.yohoufo.order.model.InviteSettlementItemListVO;
import com.yohoufo.order.model.InviteSettlementListVO;
import com.yohoufo.order.service.IInviteSettlementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Objects;
import java.util.List;
/**
* @author LUOXC
... ... @@ -45,21 +45,24 @@ public class InviteSettlementController {
*/
@RequestMapping(params = "method=ufo.invite.getInviteSettlementItemList")
public ApiResponse getInviteSettlementItemList(@RequestParam(value = "uid") Integer uid,
@RequestParam(value = "tab") Integer tab,
@RequestParam(value = "month") String month,
@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
@RequestParam(value = "limit", required = false, defaultValue = "10") Integer limit) {
log.info("get inviter settlement item list, uid is {}", uid);
InviteSettlementItemListVO resp = inviteSettlementService.getInviteSettlementItemList(uid, month, page, limit);
InviteSettlementItemListVO resp = inviteSettlementService.getInviteSettlementItemList(uid, tab, month, page, limit);
return new ApiResponse.ApiResponseBuilder().code(200).data(resp).message("ok").build();
}
@RequestMapping(value = "/erp/invite/settlement/help/settle")
public ApiResponse settle(@RequestParam(value = "uid", required = false) Integer uid) {
if (Objects.nonNull(uid)) {
inviteSettlementService.settle(uid);
} else {
inviteSettlementService.settle();
}
public ApiResponse settle() {
inviteSettlementService.settle();
return new ApiResponse.ApiResponseBuilder().code(200).message("ok").build();
}
@RequestMapping(value = "/erp/invite/settlement/help/paid")
public ApiResponse paid(@RequestBody List<Integer> ids) {
inviteSettlementService.paid(ids);
return new ApiResponse.ApiResponseBuilder().code(200).message("ok").build();
}
... ...
package com.yohoufo.order.model;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.experimental.Builder;
import java.util.List;
... ... @@ -18,11 +19,13 @@ public class InviteSettlementItemListVO {
int pageTotal;
int pageSize;
int totalElements;
String totalOrderAmount;
String totalSettleAmount;
String totalPaidAmount;
String totalWaitPayAmount;
List<InviteSettlementItemVO> list;
@Data
@Accessors(chain = true)
public static class InviteSettlementItemVO {
String buyerOrderCode;
String sellerName;
... ...
... ... @@ -3,6 +3,8 @@ package com.yohoufo.order.service;
import com.yohoufo.order.model.InviteSettlementItemListVO;
import com.yohoufo.order.model.InviteSettlementListVO;
import java.util.List;
public interface IInviteSettlementService {
/**
... ... @@ -13,7 +15,7 @@ public interface IInviteSettlementService {
*/
InviteSettlementListVO getInviteSettlementList(Integer uid);
InviteSettlementItemListVO getInviteSettlementItemList(Integer uid, String month, Integer page, Integer limit);
InviteSettlementItemListVO getInviteSettlementItemList(Integer uid, Integer tab, String month, Integer page, Integer limit);
/**
* 结算
... ... @@ -21,9 +23,10 @@ public interface IInviteSettlementService {
void settle();
/**
* 结算
* 将结算单和结算项标志成已付款
* @param ids
*/
void settle(int uid);
void paid(List<Integer> ids);
/**
* 创建结算项
... ...
... ... @@ -2,7 +2,6 @@ package com.yohoufo.order.service.impl;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.InviteSettlementItemMapper;
import com.yohoufo.dal.order.InviteSettlementMapper;
import com.yohoufo.dal.order.InviterMapper;
... ... @@ -18,6 +17,7 @@ import com.yohoufo.order.utils.InviteSettlementUtils;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
... ... @@ -30,8 +30,13 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import static com.yohoufo.common.utils.DateUtil.formatYYMMddHHmmssPoint;
import static com.yohoufo.dal.order.model.InviteSettlement.STATUS_WAIT_SETTLE;
import static com.yohoufo.order.utils.InviteSettlementUtils.RMB_FLAG;
import static com.yohoufo.order.utils.InviteSettlementUtils.formatAmount;
import static com.yohoufo.order.utils.ServiceExceptions.throwServiceException;
/**
... ... @@ -72,9 +77,9 @@ public class InviteSettlementServiceImpl implements IInviteSettlementService {
.map(inviteSettlement -> {
InviteSettlementListVO.InviteSettlementVO item = new InviteSettlementListVO.InviteSettlementVO();
item.setSettleCode(String.format("%010d", inviteSettlement.getSettleCode()));
item.setSettleAmount(InviteSettlementUtils.format("+%s", inviteSettlement.getSettleAmount()));
item.setSettleTime(DateUtil.formatYYMMddHHmmssPoint(inviteSettlement.getSettleTime()));
item.setPaidTime(DateUtil.formatYYMMddHHmmssPoint(inviteSettlement.getPaidTime()));
item.setSettleAmount(formatAmount("+%s", inviteSettlement.getSettleAmount()));
item.setSettleTime(formatYYMMddHHmmssPoint(inviteSettlement.getSettleTime()));
item.setPaidTime(formatYYMMddHHmmssPoint(inviteSettlement.getPaidTime()));
return item;
})
.collect(Collectors.toList());
... ... @@ -84,47 +89,80 @@ public class InviteSettlementServiceImpl implements IInviteSettlementService {
}
@Override
public InviteSettlementItemListVO getInviteSettlementItemList(Integer uid, String month, Integer page, Integer limit) {
public InviteSettlementItemListVO getInviteSettlementItemList(Integer uid, Integer tab, String month, Integer page, Integer limit) {
if (!ObjectUtils.allNotNull(uid, tab, month, page, limit) || uid <= 0 || page <= 0 || limit <= 0) {
throwServiceException("参数不正确");
}
Pair<Integer, Integer> time = getTimeRangeOfMonth(month);
List<Integer> statusList = getStatusList(tab);
// 只查询结算规则1的记录
int settlementType = 1;
InviteSettlementItemStats stats = inviteSettlementItemMapper.selectStats(uid, settlementType, time.getLeft(), time.getRight());
InviteSettlementItemStats stats = inviteSettlementItemMapper.selectStats(uid, statusList, settlementType, time.getLeft(), time.getRight());
int totalElements = Objects.isNull(stats.getTotalElements()) ? 0 : stats.getTotalElements();
BigDecimal totalOrderAmount = Objects.isNull(stats.getTotalOrderAmount()) ? BigDecimal.ZERO : stats.getTotalOrderAmount();
BigDecimal totalSettleAmount = Objects.isNull(stats.getTotalSettleAmount()) ? BigDecimal.ZERO : stats.getTotalSettleAmount();
InviteSettlementItemStats statsAll;
if (tab != 0) {
statsAll = inviteSettlementItemMapper.selectStats(uid, getStatusList(0), settlementType, time.getLeft(), time.getRight());
} else {
statsAll = stats;
}
BigDecimal totalSettleAmount = Objects.isNull(statsAll.getTotalSettleAmount()) ? BigDecimal.ZERO : statsAll.getTotalSettleAmount();
BigDecimal totalPaidAmount = Objects.isNull(statsAll.getTotalPaidAmount()) ? BigDecimal.ZERO : statsAll.getTotalPaidAmount();
BigDecimal totalWaitPayAmount = Objects.isNull(statsAll.getTotalWaitPayAmount()) ? BigDecimal.ZERO : statsAll.getTotalWaitPayAmount();
InviteSettlementItemListVO.InviteSettlementItemListVOBuilder builder = InviteSettlementItemListVO.builder();
builder.page(page)
.pageSize(limit)
.pageTotal((totalElements % limit == 0) ? (totalElements / limit) : (totalElements / limit + 1))
.totalElements(totalElements)
.totalOrderAmount(InviteSettlementUtils.format(totalOrderAmount))
.totalSettleAmount(InviteSettlementUtils.format(totalSettleAmount));
.totalSettleAmount(formatAmount("%s%s", RMB_FLAG, totalSettleAmount))
.totalPaidAmount(formatAmount("%s%s", RMB_FLAG, totalPaidAmount))
.totalWaitPayAmount(formatAmount("%s%s", RMB_FLAG, totalWaitPayAmount));
if (totalElements == 0) {
return builder.list(Lists.newArrayList()).build();
return builder
.list(Lists.newArrayList())
.build();
}
int start = (page - 1) * limit;
List<InviteSettlementItem> list = inviteSettlementItemMapper.select(uid, settlementType, time.getLeft(), time.getRight(), start, limit);
List<InviteSettlementItem> list = inviteSettlementItemMapper.select(uid, statusList, settlementType, time.getLeft(), time.getRight(), start, limit);
Map<Integer, Integer> settlementStatusMap = buildInviteSettlementIdStatusMap(uid, list);
Map<Integer, String> sellerUidNickNameMap = userProxyService.getNickNameByUids(list.stream()
.map(InviteSettlementItem::getSellerUid)
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList()));
Predicate<InviteSettlementItem> itemHasPaid = item -> {
int status = settlementStatusMap.getOrDefault(item.getInviteSettlementId(), STATUS_WAIT_SETTLE).intValue();
return InviteSettlement.STATUS_PAID == status;
};
return builder
.list(list.stream().map(item -> {
Integer settlementStatus = settlementStatusMap.getOrDefault(item.getInviteSettlementId(), InviteSettlement.STATUS_WAIT_SETTLE);
InviteSettlementItemListVO.InviteSettlementItemVO vo = new InviteSettlementItemListVO.InviteSettlementItemVO();
vo.setBuyerOrderCode(item.getBuyerOrderCode().toString());
vo.setSellerName(sellerUidNickNameMap.get(item.getSellerUid()));
vo.setOrderAmount(InviteSettlementUtils.format(item.getOrderAmount()));
vo.setOrderCreateTime(DateUtil.formatYYMMddHHmmssPoint(item.getOrderCreateTime()));
vo.setSettleAmount(InviteSettlementUtils.format(item.getSettleAmount()));
vo.setStatusDesc(settlementStatus.equals(InviteSettlement.STATUS_PAID) ? "已付款" : "待付款");
return vo;
}).collect(Collectors.toList()))
.list(list.stream()
.map(item -> new InviteSettlementItemListVO.InviteSettlementItemVO()
.setBuyerOrderCode(item.getBuyerOrderCode().toString())
.setSellerName(sellerUidNickNameMap.get(item.getSellerUid()))
.setOrderAmount(formatAmount("%s%s", RMB_FLAG, item.getOrderAmount()))
.setOrderCreateTime(formatYYMMddHHmmssPoint(item.getOrderCreateTime()))
.setSettleAmount(formatAmount("%s%s", RMB_FLAG, item.getSettleAmount()))
.setStatusDesc(itemHasPaid.test(item) ? "已付款" : "待付款"))
.collect(Collectors.toList()))
.build();
}
private List<Integer> getStatusList(Integer tab) {
if (tab == 0) {
return Lists.newArrayList(InviteSettlementItem.STATUS_ENABLE, InviteSettlementItem.STATUS_SETTLED, InviteSettlementItem.STATUS_PAID);
}
if (tab == 1) {
return Lists.newArrayList(InviteSettlementItem.STATUS_ENABLE, InviteSettlementItem.STATUS_SETTLED);
}
if (tab == 2) {
return Lists.newArrayList(InviteSettlementItem.STATUS_PAID);
}
throwServiceException("参数不正确");
return Lists.newArrayList();
}
private Map<Integer, Integer> buildInviteSettlementIdStatusMap(Integer uid, List<InviteSettlementItem> list) {
val inviteSettlementIds = list.stream()
.map(InviteSettlementItem::getInviteSettlementId)
... ... @@ -141,18 +179,14 @@ public class InviteSettlementServiceImpl implements IInviteSettlementService {
@VisibleForTesting
Pair<Integer, Integer> getTimeRangeOfMonth(String month) {
LocalDateTime requestMonth = null;
LocalDateTime start = null;
ZoneOffset zoneOffset = InviteSettlementUtils.zoneOffset();
try {
requestMonth = LocalDateTime.parse(month, DateTimeFormatter.ofPattern("yyyyMM"));
start = LocalDateTime.parse(month + "01 00:00:00", DateTimeFormatter.ofPattern("yyyyMMdd HH:mm:ss"));
} catch (Exception e) {
throwServiceException("日期格式不正确");
}
ZoneOffset zoneOffset = ZoneOffset.of("+8");
int startTime = (int) LocalDateTime.of(requestMonth.getYear(), requestMonth.getMonthValue(), 1, 0, 0, 0)
.toEpochSecond(zoneOffset);
int endTime = (int) LocalDateTime.of(requestMonth.getYear(), requestMonth.getMonthValue() + 1, 1, 0, 0, 0)
.toEpochSecond(zoneOffset) - 1;
return Pair.of(startTime, endTime);
return Pair.of((int) start.toEpochSecond(zoneOffset), (int) start.plusMonths(1).toEpochSecond(zoneOffset) - 1);
}
@Override
... ... @@ -164,8 +198,18 @@ public class InviteSettlementServiceImpl implements IInviteSettlementService {
}
@Override
public void settle(int uid) {
inviterSettleService.settle(uid);
public void paid(List<Integer> ids) {
if (CollectionUtils.isEmpty(ids)) {
return;
}
List<InviteSettlement> settlements = inviteSettlementMapper.selectByIds(ids);
settlements.stream().forEach(settlement -> {
log.info("mark settlement to paid, settle id is {}", settlement.getId());
settlement.setStatus(InviteSettlement.STATUS_PAID);
inviteSettlementMapper.updateByUidAndId(settlement);
inviteSettlementItemMapper.updateStatusByUidAndInviteSettlementId(settlement.getUid(), settlement.getId(), InviteSettlementItem.STATUS_PAID);
});
}
@Override
... ...
... ... @@ -16,15 +16,26 @@ import java.util.function.BiPredicate;
*/
public class InviteSettlementUtils {
public static String format(BigDecimal src) {
return format("%s", src);
public static String RMB_FLAG = "¥";
public static String formatAmount(BigDecimal src) {
return formatAmount("%s", src);
}
public static String format(String format, BigDecimal src) {
if (Objects.isNull(src)) {
public static String formatAmount(String format, Object... args) {
if (Objects.isNull(args)) {
return null;
} else {
return String.format(format, src.setScale(1, RoundingMode.FLOOR));
Object[] tmp = new Object[args.length];
for (int i = 0; i < args.length; i++) {
Object arg = args[i];
if (arg instanceof BigDecimal) {
tmp[i] = ((BigDecimal) arg).setScale(1, RoundingMode.FLOOR);
} else {
tmp[i] = arg;
}
}
return String.format(format, tmp);
}
}
... ...