Browse Source

[储值卡][新增]:消费记录添加导出及批量更新支付状态功能

release_toaliyun_real
Stormeye Wu 7 years ago
parent
commit
94036f2d16
6 changed files with 262 additions and 21 deletions
  1. +49
    -4
      mallinkAdmin/src/main/java/com/iformall/controller/WxCardPayController.java
  2. +8
    -2
      mallinkService/src/main/java/com/iformall/domain/po/WxCardSpend.java
  3. +39
    -0
      mallinkService/src/main/java/com/iformall/enums/EnumCardSpendStatus.java
  4. +23
    -12
      mallinkService/src/main/java/com/iformall/service/WxCardSpendService.java
  5. +137
    -3
      mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java
  6. +6
    -0
      mallinkService/src/main/resources/mapper/WxCardSpendMapper.xml

+ 49
- 4
mallinkAdmin/src/main/java/com/iformall/controller/WxCardPayController.java View File

@@ -2,6 +2,7 @@ package com.iformall.controller;


import com.github.pagehelper.PageInfo;
import com.iformall.common.Result;
import com.iformall.common.ResultData;
import com.iformall.domain.po.MallUserInfo;
import com.iformall.domain.po.WxCardInfo;
@@ -9,6 +10,7 @@ import com.iformall.domain.po.WxCardSpend;
import com.iformall.domain.po.WxCouponOrder;
import com.iformall.domain.vo.WxCardSpendVo;
import com.iformall.domain.vo.WxCardVo;
import com.iformall.enums.EnumCardSpendStatus;
import com.iformall.service.WxCardInfoService;
import com.iformall.service.WxCardSpendService;
import com.iformall.service.WxMerchantService;
@@ -21,12 +23,12 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
@@ -86,7 +88,50 @@ public class WxCardPayController extends BaseController {
if (wxCardSpendVo == null) wxCardSpendVo = new WxCardSpendVo();
MallUserInfo user = getUser();
wxCardSpendVo.setTenantId(user.getTenantId());
if(StringUtils.isNotBlank(wxCardSpendVo.getPayStatusStr())) {
String [] statusAttr = wxCardSpendVo.getPayStatusStr().split(",");
List<Integer> tmpList = new ArrayList<Integer>();
for(String status: statusAttr) {
tmpList.add(Integer.valueOf(status));
}
if(!tmpList.isEmpty()) {
wxCardSpendVo.setPayStatusS(tmpList);
}
}
final PageInfo<WxCardSpendVo> page = wxCardSpendService.listAsPage(wxCardSpendVo, pageNum, pageSize);
return new ResultData(page);
}

@ApiOperation("交易流水导出")
@RequestMapping("/exportData")
public void exportData(@ModelAttribute WxCardSpendVo wxCardSpendVo, HttpServletRequest request, HttpServletResponse response) {
logger.info("[" + getIpAddr() + "] WxCardPayController::exportData");
wxCardSpendVo.setTenantId(getTenantId());
if(StringUtils.isNotBlank(wxCardSpendVo.getPayStatusStr())) {
String [] statusAttr = wxCardSpendVo.getPayStatusStr().split(",");
List<Integer> tmpList = new ArrayList<Integer>();
for(String status: statusAttr) {
tmpList.add(Integer.valueOf(status));
}
if(!tmpList.isEmpty()) {
wxCardSpendVo.setPayStatusS(tmpList);
}
}
wxCardSpendService.exportData(wxCardSpendVo, request, response);
}

@ApiOperation("更新补贴记录")
@PostMapping("update")
public ResultData update(@RequestBody WxCardSpendVo wxCardSpendVo) {
String ipStr = getIpAddr();
logger.info("subsidy/update: " + ipStr + " :" + wxCardSpendVo.toString());
if (wxCardSpendVo == null)
return new ResultData(Result.SUCCESS, "无更新条件");
MallUserInfo user = getUser();
wxCardSpendVo.setTenantId(user.getTenantId());
wxCardSpendVo.setStatus(EnumCardSpendStatus.MANUAL_PAY.getCode());
wxCardSpendVo.setUpdateDate(new Date());
int num = wxCardSpendService.update(wxCardSpendVo);
return new ResultData(num);
}
}

+ 8
- 2
mallinkService/src/main/java/com/iformall/domain/po/WxCardSpend.java View File

@@ -67,10 +67,16 @@ public class WxCardSpend implements Serializable {
@io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate")
private Date updateDate;

/**状态*/
@io.swagger.annotations.ApiModelProperty(value="状态(0:未分帐,1:已分账)",name="payStatus")
/**支付状态*/
@io.swagger.annotations.ApiModelProperty(value="支付状态(0:未分帐, 1:已分账, 2:已人工分账)",name="payStatus")
private Integer payStatus;

@Transient
protected List<Integer> payStatusS;

@Transient
protected String payStatusStr;

public static enum Field
{
Id_ASC("`id` ASC"),Id_DESC("`id` DESC")


+ 39
- 0
mallinkService/src/main/java/com/iformall/enums/EnumCardSpendStatus.java View File

@@ -0,0 +1,39 @@
package com.iformall.enums;

/**
* Created by Stormeye on 2018/08/09.
*/
public enum EnumCardSpendStatus {

// 0-未支付;1-已分账;2:已人工分账;

NOT_PAY(0, "未支付"),
PS_SHARED(1, "已分账"),
MANUAL_PAY(2, "已人工分账")
;

public static EnumCardSpendStatus getEnum(Integer code) {
for (EnumCardSpendStatus value : values()) {
if (value.getCode().equals(code)) {
return value;
}
}
return null;
}

private Integer code;
private String message;

EnumCardSpendStatus(Integer code, String message) {
this.code = code;
this.message = message;
}

public Integer getCode() {
return code;
}

public String getMessage() {
return message;
}
}

+ 23
- 12
mallinkService/src/main/java/com/iformall/service/WxCardSpendService.java View File

@@ -5,6 +5,8 @@ import com.iformall.common.ResultData;
import com.iformall.domain.po.*;
import com.iformall.domain.vo.WxCardSpendVo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

public interface WxCardSpendService {
@@ -13,8 +15,10 @@ public interface WxCardSpendService {
*
*/
WxCouponMerchant checkMerchantInCoupon(WxCardInfo cardInfo, Long merchantId);

/**
* 创建卡花费
*
* @param record
* @param order
* @param user
@@ -30,7 +34,7 @@ public interface WxCardSpendService {
* @param pageSize
* @return
*/
PageInfo<WxCardSpendVo> listAsPage(WxCardSpendVo record, Integer pageIndex, Integer pageSize);
PageInfo<WxCardSpendVo> listAsPage(WxCardSpendVo record, Integer pageIndex, Integer pageSize);

/**
* 根据实体SUM
@@ -39,22 +43,29 @@ public interface WxCardSpendService {
* @return
*/
Map<String, Object> sumCardSpend(WxCardSpendVo record);
/**
/**
* 根据Id获得实体
*
* @param id
* @return
*/
WxCardSpend getById(Long id);
/**
/**
* 保存或更新实体
*
* @param record
*/
void saveOrUpdate(WxCardSpend record);

/**
* 更新实体
*
* @param record
*/
int update(WxCardSpendVo record);

/**
* 根据Id删除实体
*
@@ -64,16 +75,16 @@ public interface WxCardSpendService {

/**
* cardPay分账
*
* @param orderId
* @param cardSpendId
*/
void shareForCardPay(String tenantId, Long cardId, Long orderId, Long cardSpendId);

/**
* cardPay交易流水导出
*/
void exportData(WxCardSpendVo wxCardSpendVo, HttpServletRequest request, HttpServletResponse response);


}

+ 137
- 3
mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java View File

@@ -1,5 +1,6 @@
package com.iformall.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iformall.common.ErrorCode;
@@ -13,6 +14,13 @@ import com.iformall.exception.MallinkException;
import com.iformall.mapper.*;
import com.iformall.service.WxCardSpendService;
import com.iformall.service.WxProfitSharingOrderService;
import com.iformall.utils.Constant;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -21,8 +29,11 @@ import com.iformall.common.IdWorker;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class WxCardSpendServiceImpl implements WxCardSpendService {
@@ -178,7 +189,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
merchantSubsidy.setRealSubsidy(realSubsidyFee);
if (coupon.getSubsidyType().equals(EnumCouponSubsidyType.WECHAT_COUPON.getCode())) {
// 立减领券
merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.SUBSIDIED.getCode());
merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.AUTO_SUBSIDIED.getCode());
} else if (coupon.getSubsidyType().equals(EnumCouponSubsidyType.WECHAT_MCHPAY.getCode())) {
// 转账倒现金
} else {
@@ -257,6 +268,11 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
}
}

@Override
public int update(WxCardSpendVo record) {
return wxCardSpendMapper.updateByCond(record);
}

@Override
public void deleteById(Long id) {
wxCardSpendMapper.deleteByPrimaryKey(id);
@@ -376,5 +392,123 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
profitSharingOrderService.finishSharingOrder(shareOrder);
}

@Override
public void exportData(WxCardSpendVo wxCardSpendVo, HttpServletRequest request, HttpServletResponse response) {
List<WxCardSpendVo> cardSpendVoList = wxCardSpendMapper.findCardSpendVoList(wxCardSpendVo);

XSSFWorkbook workbook;
String filepath = Constant.fileDirectory;
File savefile = new File(filepath);
if (!savefile.exists()) {
savefile.mkdirs();
}
String filename = UUID.randomUUID() + ".xlsx";
filepath = filepath + filename;

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

try {
File file = new File(filepath);
workbook = new XSSFWorkbook();
XSSFSheet sheetTwo = workbook.createSheet("消费记录");
Row rowtwo = sheetTwo.createRow(0);
Cell idCellTwo = rowtwo.createCell(0);
Cell ownerCellTwo = rowtwo.createCell(1);
Cell phoneCellTwo = rowtwo.createCell(2);
Cell cardNameCellTwo = rowtwo.createCell(3);
Cell merchantNameCellTwo = rowtwo.createCell(4);
Cell costCellTwo = rowtwo.createCell(5);
Cell costTimeCellTwo = rowtwo.createCell(6);
Cell receivePayCellTwo = rowtwo.createCell(7);
Cell realReceivePayCellTwo = rowtwo.createCell(8);
Cell payStatusCellTwo = rowtwo.createCell(9);

idCellTwo.setCellValue("ID");
ownerCellTwo.setCellValue("消费者");
phoneCellTwo.setCellValue("手机号");
cardNameCellTwo.setCellValue("卡名");
merchantNameCellTwo.setCellValue("商户");
costCellTwo.setCellValue("消费金额");
costTimeCellTwo.setCellValue("地址");
receivePayCellTwo.setCellValue("收款金额");
realReceivePayCellTwo.setCellValue("收款实际金额");
payStatusCellTwo.setCellValue("收款状态");

for (int i = 0; i < cardSpendVoList.size(); i++) {
rowtwo = sheetTwo.createRow(i + 1);
idCellTwo = rowtwo.createCell(0);
ownerCellTwo = rowtwo.createCell(1);
phoneCellTwo = rowtwo.createCell(2);
cardNameCellTwo = rowtwo.createCell(3);
merchantNameCellTwo = rowtwo.createCell(4);
costCellTwo = rowtwo.createCell(5);
costTimeCellTwo = rowtwo.createCell(6);
receivePayCellTwo = rowtwo.createCell(7);
realReceivePayCellTwo = rowtwo.createCell(8);
payStatusCellTwo = rowtwo.createCell(9);

WxCardSpendVo entity = cardSpendVoList.get(i);

idCellTwo.setCellValue(entity.getId());
ownerCellTwo.setCellValue(entity.getOnickName());
phoneCellTwo.setCellValue(entity.getOuPhone());
cardNameCellTwo.setCellValue(entity.getTitle());
merchantNameCellTwo.setCellValue(entity.getMerchantName());
costCellTwo.setCellValue(entity.getDeductionAmount());
if (entity.getCreateDate() != null)
costTimeCellTwo.setCellValue(sdf.format(entity.getCreateDate()));
receivePayCellTwo.setCellValue(entity.getPayment());
realReceivePayCellTwo.setCellValue(entity.getRealPayment());
String statusStr = "未支付";
if (entity.getPayStatus().equals(EnumCardSpendStatus.NOT_PAY.getCode()))
statusStr = "未支付";
else if (entity.getPayStatus().equals(EnumCardSpendStatus.PS_SHARED.getCode()))
statusStr = "已分账";
else if (entity.getPayStatus().equals(EnumCardSpendStatus.MANUAL_PAY.getCode()))
statusStr = "已手工分账";
payStatusCellTwo.setCellValue(statusStr);
}


FileOutputStream fileOut = new FileOutputStream(file);
workbook.write(fileOut);
fileOut.close();
workbook.close();
downFile(filepath, filename,"消费记录.xlsx",response, request);
FileUtils.forceDelete(file);
} catch (Exception e) {
e.printStackTrace();
}
}

public void downFile(String filePath, String filename, String exportFileName,
HttpServletResponse response, HttpServletRequest req) throws IOException {
try {
response.reset();
response.setContentType("bin");
String agent = req.getHeader("user-agent");
if (agent.contains("Firefox")) {
response.setHeader("Content-disposition",
"attachment; filename="
+ new String(exportFileName.getBytes("GB2312"),
"ISO-8859-1"));
} else {
response
.setHeader("Content-disposition",
"attachment; filename="
+ java.net.URLEncoder.encode(exportFileName,
"UTF-8"));
}
// 循环取出流中的数据
byte[] b = new byte[1024];
int len;
InputStream inStream = new FileInputStream(filePath);
while ((len = inStream.read(b)) > 0)
response.getOutputStream().write(b, 0, len);
inStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}

}

+ 6
- 0
mallinkService/src/main/resources/mapper/WxCardSpendMapper.xml View File

@@ -198,6 +198,12 @@
<if test=" null != startdate and null!=enddate">
and cs.`create_date` between #{startdate} and #{enddate}
</if>
<if test=" null != payStatusS ">
and cs.`pay_status` in
<foreach collection="payStatusS" index="index" item="sItem" open="(" separator="," close=")">
#{sItem}
</foreach>
</if>
<if test=" null != ids ">
and cs.id in
<foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">


Loading…
Cancel
Save