From 94036f2d166ed2314677e64f1c46f146b4d6dc4a Mon Sep 17 00:00:00 2001 From: Stormeye Wu Date: Wed, 26 Dec 2018 14:26:41 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=82=A8=E5=80=BC=E5=8D=A1][=E6=96=B0?= =?UTF-8?q?=E5=A2=9E]:=E6=B6=88=E8=B4=B9=E8=AE=B0=E5=BD=95=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=AF=BC=E5=87=BA=E5=8F=8A=E6=89=B9=E9=87=8F=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=94=AF=E4=BB=98=E7=8A=B6=E6=80=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WxCardPayController.java | 53 ++++++- .../com/iformall/domain/po/WxCardSpend.java | 10 +- .../iformall/enums/EnumCardSpendStatus.java | 39 +++++ .../iformall/service/WxCardSpendService.java | 35 +++-- .../service/impl/WxCardSpendServiceImpl.java | 140 +++++++++++++++++- .../resources/mapper/WxCardSpendMapper.xml | 6 + 6 files changed, 262 insertions(+), 21 deletions(-) create mode 100644 mallinkService/src/main/java/com/iformall/enums/EnumCardSpendStatus.java diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/WxCardPayController.java b/mallinkAdmin/src/main/java/com/iformall/controller/WxCardPayController.java index 523b8a99b..0a9a41fa7 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/WxCardPayController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/WxCardPayController.java @@ -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 tmpList = new ArrayList(); + for(String status: statusAttr) { + tmpList.add(Integer.valueOf(status)); + } + if(!tmpList.isEmpty()) { + wxCardSpendVo.setPayStatusS(tmpList); + } + } final PageInfo 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 tmpList = new ArrayList(); + 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); + } } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCardSpend.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCardSpend.java index 9fd781e53..3df6bc13e 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxCardSpend.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCardSpend.java @@ -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 payStatusS; + + @Transient + protected String payStatusStr; + public static enum Field { Id_ASC("`id` ASC"),Id_DESC("`id` DESC") diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumCardSpendStatus.java b/mallinkService/src/main/java/com/iformall/enums/EnumCardSpendStatus.java new file mode 100644 index 000000000..8b112b9f6 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/enums/EnumCardSpendStatus.java @@ -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; + } +} diff --git a/mallinkService/src/main/java/com/iformall/service/WxCardSpendService.java b/mallinkService/src/main/java/com/iformall/service/WxCardSpendService.java index 77f641114..d4ae3d7de 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxCardSpendService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxCardSpendService.java @@ -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 listAsPage(WxCardSpendVo record, Integer pageIndex, Integer pageSize); + PageInfo listAsPage(WxCardSpendVo record, Integer pageIndex, Integer pageSize); /** * 根据实体SUM @@ -39,22 +43,29 @@ public interface WxCardSpendService { * @return */ Map 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); + + } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java index 87cfa7716..ab5d57c1e 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java @@ -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 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(); + } + } } diff --git a/mallinkService/src/main/resources/mapper/WxCardSpendMapper.xml b/mallinkService/src/main/resources/mapper/WxCardSpendMapper.xml index 9a8be88b6..9e6ee3521 100644 --- a/mallinkService/src/main/resources/mapper/WxCardSpendMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCardSpendMapper.xml @@ -198,6 +198,12 @@ and cs.`create_date` between #{startdate} and #{enddate} + + and cs.`pay_status` in + + #{sItem} + + and cs.id in