Authored by Lixiaodi

增加保证金查询接口

package com.yoho.order.dal;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yoho.order.model.SellerWalletDetail;
public interface SellerWalletDetailMapper {
//查询用户违约的次数
int selectUserBreakRulesCount(@Param("uid") Integer uid);
List<SellerWalletDetail> selectMerchantInfo(@Param("uid") Integer uid,
@Param("startTime") Integer stratTime,
@Param("endTime") Integer endTime,
@Param("stateList") List<Integer> stateList,
@Param("start") int start,
@Param("rows") Integer rows);
int selectMerchantInfoCount(@Param("uid") Integer uid,
@Param("startTime") Integer stratTime,
@Param("endTime") Integer endTime,
@Param("stateList") List<Integer> stateList);
SellerWalletDetail selectById(Integer id);
}
\ No newline at end of file
... ...
package com.yoho.order.model;
import java.util.List;
import com.yoho.ufo.service.model.PageRequestBO;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Data
@ToString
@EqualsAndHashCode(callSuper=false)
public class MerchantReq extends PageRequestBO {
private static final long serialVersionUID = 1620427808531296022L;
private Integer id;
private Integer uid;
private String startTime;
private String endTime;
private List<Integer> stateList;
}
... ...
... ... @@ -28,4 +28,35 @@
where uid = #{uid,jdbcType=INTEGER} and is_batch = 0 and type in (32,33)
</select>
<select id="selectMerchantInfoCount" resultType="java.lang.Integer" >
select count(*) from seller_wallet_detail
where is_batch = 0 <include refid="condi" />
</select>
<select id="selectMerchantInfo" resultMap="BaseResultMap">
select * from seller_wallet_detail
where is_batch = 0 <include refid="condi" /> order by id desc limit #{start},#{rows}
</select>
<select id="selectById" resultMap="BaseResultMap">
select * from seller_wallet_detail
where id = #{id,jdbcType=INTEGER}
</select>
<sql id="condi">
<if test="uid != null and uid > 0">
and uid = #{uid,jdbcType=INTEGER}
</if>
<if test="startTime != null and startTime > 0">
and create_time &gt;= #{startTime,jdbcType=INTEGER}
</if>
<if test="endTime != null and endTime > 0">
and create_time &lt;= #{endTime,jdbcType=INTEGER}
</if>
<if test="stateList != null and stateList.size()>0">
and type in
<foreach collection="stateList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
</sql>
</mapper>
\ No newline at end of file
... ...
package com.yoho.ufo.order.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yoho.order.model.MerchantReq;
import com.yoho.ufo.order.service.impl.MerchantServiceImpl;
import com.yoho.ufo.service.model.ApiResponse;
import com.yoho.ufo.service.model.PageResponseBO;
import com.yohobuy.ufo.model.order.bo.MerchantOrderAttachInfo;
@RestController
@RequestMapping(value = "/merchant")
public class MerchantController {
private static final Logger LOGGER = LoggerFactory.getLogger(MerchantController.class);
@Autowired
private MerchantServiceImpl service;
@RequestMapping(value = "/earnestList")
public ApiResponse earnestList(MerchantReq req) {
LOGGER.info("earnestList in. req is {}", req);
PageResponseBO<MerchantOrderAttachInfo> result = service.earnestList(req);
return new ApiResponse.ApiResponseBuilder().code(200).message("查询成功").data(result).build();
}
@RequestMapping(value = "/earnestDetail")
public ApiResponse earnestDetail(MerchantReq req) {
if(req.getId()==null) {
return new ApiResponse(400, "参数有误", null);
}
MerchantOrderAttachInfo info = service.earnestDetail(req);
return new ApiResponse.ApiResponseBuilder().code(200).message("获取信息成功").data(info).build();
}
}
... ...
package com.yoho.ufo.order.service.impl;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.yoho.order.dal.SellerWalletDetailMapper;
import com.yoho.order.model.MerchantReq;
import com.yoho.order.model.SellerWalletDetail;
import com.yoho.ufo.service.model.PageResponseBO;
import com.yohobuy.ufo.model.order.bo.MerchantOrderAttachInfo;
@Service
public class MerchantServiceImpl {
private static final Logger LOGGER = LoggerFactory.getLogger(MerchantServiceImpl.class);
private ThreadLocal<SimpleDateFormat> sdf = ThreadLocal.withInitial(()-> new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"));
@Autowired
private SellerWalletDetailMapper mapper;
public MerchantOrderAttachInfo earnestDetail(MerchantReq req) {
return exchange(mapper.selectById(req.getId()));
}
public PageResponseBO<MerchantOrderAttachInfo> earnestList(MerchantReq req) {
Integer stratTime = parse(req.getStartTime());
Integer endTime = parse(req.getEndTime());
int total = mapper.selectMerchantInfoCount(req.getUid(), stratTime, endTime, req.getStateList());
if(total == 0) {
return new PageResponseBO<>();
}
List<SellerWalletDetail> beanList = mapper.selectMerchantInfo(req.getUid(), stratTime, endTime, req.getStateList(), req.getStart(), req.getRows());
List<MerchantOrderAttachInfo> boList = new ArrayList<>();
for(SellerWalletDetail detail : beanList) {
boList.add(exchange(detail));
}
PageResponseBO<MerchantOrderAttachInfo> result=new PageResponseBO<>();
result.setList(boList);
result.setPage(req.getPage());
result.setSize(req.getSize());
result.setTotal(total);
return result;
}
private MerchantOrderAttachInfo exchange(SellerWalletDetail detail) {
MerchantOrderAttachInfo info = new MerchantOrderAttachInfo();
if(StringUtils.isNotBlank(detail.getAttachValue())) {
info = JSON.parseObject(detail.getAttachValue(), MerchantOrderAttachInfo.class);
}
info.setId(detail.getId());
info.setUid(detail.getUid());
info.setType(detail.getType());
info.setUserName("");
info.setTime(sdf.get().format(new Date(detail.getCreateTime() * 1000L)));
if (info.getType() / 10 == 3 || info.getType()==61) {
info.setAccountAmount(detail.getAmount().toString());
info.setLockEarnestMoney(detail.getAmount().toString());
info.setAvailEarnestMoney("/");
} else {
info.setAccountAmount("/");
info.setLockEarnestMoney("/");
info.setAvailEarnestMoney(detail.getAmount().toString());
}
info.setAccountAllAmount(detail.getAvailAmount().add(detail.getLockAmount()).toString());
info.setLockAllEarnestMoney(detail.getLockAmount().toString());
info.setAvailAllEarnestMoney(detail.getAvailAmount().toString());
return info;
}
private Integer parse(String startTime) {
if(StringUtils.isBlank(startTime)) {
return null;
}
try {
return (int) (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(startTime).getTime()/1000);
} catch (ParseException e) {
return null;
}
}
}
... ...