| @@ -4,6 +4,7 @@ import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.MallUserInfo; | import com.iformall.domain.po.MallUserInfo; | ||||
| import com.iformall.domain.po.WxMerchantSubsidy; | import com.iformall.domain.po.WxMerchantSubsidy; | ||||
| import com.iformall.domain.vo.WxCardSpendVo; | |||||
| import com.iformall.domain.vo.WxMerchantSubsidyVo; | import com.iformall.domain.vo.WxMerchantSubsidyVo; | ||||
| import com.iformall.enums.EnumMerchantSubsidyStatus; | import com.iformall.enums.EnumMerchantSubsidyStatus; | ||||
| import com.iformall.service.WxMerchantSubsidyService; | import com.iformall.service.WxMerchantSubsidyService; | ||||
| @@ -11,12 +12,17 @@ import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.web.bind.annotation.*; | 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.Date; | ||||
| import java.util.List; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| @RestController | @RestController | ||||
| @@ -36,6 +42,16 @@ public class WxMerchantSubsidyController extends BaseController { | |||||
| if (wxMerchantSubsidy == null) wxMerchantSubsidy = new WxMerchantSubsidy(); | if (wxMerchantSubsidy == null) wxMerchantSubsidy = new WxMerchantSubsidy(); | ||||
| MallUserInfo user = getUser(); | MallUserInfo user = getUser(); | ||||
| wxMerchantSubsidy.setTenantId(user.getTenantId()); | wxMerchantSubsidy.setTenantId(user.getTenantId()); | ||||
| if(StringUtils.isNotBlank(wxMerchantSubsidy.getStatusStr())) { | |||||
| String [] statusAttr = wxMerchantSubsidy.getStatusStr().split(","); | |||||
| List<Integer> tmpList = new ArrayList<Integer>(); | |||||
| for(String status: statusAttr) { | |||||
| tmpList.add(Integer.valueOf(status)); | |||||
| } | |||||
| if(!tmpList.isEmpty()) { | |||||
| wxMerchantSubsidy.setStatusS(tmpList); | |||||
| } | |||||
| } | |||||
| Map retMap = wxMerchantSubsidyService.sumForSubsidy(wxMerchantSubsidy); | Map retMap = wxMerchantSubsidyService.sumForSubsidy(wxMerchantSubsidy); | ||||
| return new ResultData(retMap); | return new ResultData(retMap); | ||||
| } | } | ||||
| @@ -51,6 +67,16 @@ public class WxMerchantSubsidyController extends BaseController { | |||||
| if (wxMerchantSubsidy == null) wxMerchantSubsidy = new WxMerchantSubsidy(); | if (wxMerchantSubsidy == null) wxMerchantSubsidy = new WxMerchantSubsidy(); | ||||
| MallUserInfo user = getUser(); | MallUserInfo user = getUser(); | ||||
| wxMerchantSubsidy.setTenantId(user.getTenantId()); | wxMerchantSubsidy.setTenantId(user.getTenantId()); | ||||
| if(StringUtils.isNotBlank(wxMerchantSubsidy.getStatusStr())) { | |||||
| String [] statusAttr = wxMerchantSubsidy.getStatusStr().split(","); | |||||
| List<Integer> tmpList = new ArrayList<Integer>(); | |||||
| for(String status: statusAttr) { | |||||
| tmpList.add(Integer.valueOf(status)); | |||||
| } | |||||
| if(!tmpList.isEmpty()) { | |||||
| wxMerchantSubsidy.setStatusS(tmpList); | |||||
| } | |||||
| } | |||||
| final PageInfo<WxMerchantSubsidyVo> page = wxMerchantSubsidyService.listAsPage(wxMerchantSubsidy, pageNum, pageSize); | final PageInfo<WxMerchantSubsidyVo> page = wxMerchantSubsidyService.listAsPage(wxMerchantSubsidy, pageNum, pageSize); | ||||
| return new ResultData(page); | return new ResultData(page); | ||||
| } | } | ||||
| @@ -63,9 +89,28 @@ public class WxMerchantSubsidyController extends BaseController { | |||||
| if (wxMerchantSubsidy == null) wxMerchantSubsidy = new WxMerchantSubsidy(); | if (wxMerchantSubsidy == null) wxMerchantSubsidy = new WxMerchantSubsidy(); | ||||
| MallUserInfo user = getUser(); | MallUserInfo user = getUser(); | ||||
| wxMerchantSubsidy.setTenantId(user.getTenantId()); | wxMerchantSubsidy.setTenantId(user.getTenantId()); | ||||
| wxMerchantSubsidy.setStatus(EnumMerchantSubsidyStatus.SUBSIDIED.getCode()); | |||||
| wxMerchantSubsidy.setStatus(EnumMerchantSubsidyStatus.MANUAL_SUBSIDIED.getCode()); | |||||
| wxMerchantSubsidy.setUpdateDate(new Date()); | wxMerchantSubsidy.setUpdateDate(new Date()); | ||||
| return wxMerchantSubsidyService.saveOrUpdate(wxMerchantSubsidy); | |||||
| int num = wxMerchantSubsidyService.update(wxMerchantSubsidy); | |||||
| return new ResultData(num); | |||||
| } | |||||
| @ApiOperation("补贴记录导出") | |||||
| @RequestMapping("/exportData") | |||||
| public void exportData(@ModelAttribute WxMerchantSubsidy wxMerchantSubsidy, HttpServletRequest request, HttpServletResponse response) { | |||||
| logger.info("[" + getIpAddr() + "] subsidy/exportData"); | |||||
| wxMerchantSubsidy.setTenantId(getTenantId()); | |||||
| if(StringUtils.isNotBlank(wxMerchantSubsidy.getStatusStr())) { | |||||
| String [] statusAttr = wxMerchantSubsidy.getStatusStr().split(","); | |||||
| List<Integer> tmpList = new ArrayList<Integer>(); | |||||
| for(String status: statusAttr) { | |||||
| tmpList.add(Integer.valueOf(status)); | |||||
| } | |||||
| if(!tmpList.isEmpty()) { | |||||
| wxMerchantSubsidy.setStatusS(tmpList); | |||||
| } | |||||
| } | |||||
| wxMerchantSubsidyService.exportData(wxMerchantSubsidy, request, response); | |||||
| } | } | ||||
| } | } | ||||
| @@ -54,8 +54,8 @@ public class WxMerchantSubsidy implements Serializable { | |||||
| /**线上补贴额/实收补贴额(通道费扣除)*/ | /**线上补贴额/实收补贴额(通道费扣除)*/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="线上补贴额/实收补贴额(通道费扣除)",name="realSubsidy") | @io.swagger.annotations.ApiModelProperty(value="线上补贴额/实收补贴额(通道费扣除)",name="realSubsidy") | ||||
| private Integer realSubsidy; | private Integer realSubsidy; | ||||
| /**状态(0:未补贴, 1:已补贴)*/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="状态(0:未补贴, 1:已补贴)",name="status") | |||||
| /**状态(0:未补贴, 1:已自动补贴, 2:已手工补贴)*/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="状态(0:未补贴, 1:已补贴, 2:已手工补贴)",name="status") | |||||
| private Integer status; | private Integer status; | ||||
| /**创建时间*/ | /**创建时间*/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | ||||
| @@ -70,6 +70,12 @@ public class WxMerchantSubsidy implements Serializable { | |||||
| @Transient | @Transient | ||||
| private Date enddate; | private Date enddate; | ||||
| @Transient | |||||
| protected List<Integer> statusS; | |||||
| @Transient | |||||
| protected String statusStr; | |||||
| public static enum Field | public static enum Field | ||||
| { | { | ||||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | ||||
| @@ -6,7 +6,8 @@ package com.iformall.enums; | |||||
| public enum EnumMerchantSubsidyStatus { | public enum EnumMerchantSubsidyStatus { | ||||
| NOT_SUBSIDY(0, "未补贴"), | NOT_SUBSIDY(0, "未补贴"), | ||||
| SUBSIDIED(1, "已补贴"), | |||||
| AUTO_SUBSIDIED(1, "已自动补贴"), | |||||
| MANUAL_SUBSIDIED(1, "已手工补贴"), | |||||
| ; | ; | ||||
| public static EnumMerchantSubsidyStatus getEnum(Integer code) { | public static EnumMerchantSubsidyStatus getEnum(Integer code) { | ||||
| @@ -5,6 +5,8 @@ import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.WxMerchantSubsidy; | import com.iformall.domain.po.WxMerchantSubsidy; | ||||
| import com.iformall.domain.vo.WxMerchantSubsidyVo; | import com.iformall.domain.vo.WxMerchantSubsidyVo; | ||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| public interface WxMerchantSubsidyService { | public interface WxMerchantSubsidyService { | ||||
| @@ -46,7 +48,7 @@ public interface WxMerchantSubsidyService { | |||||
| * | * | ||||
| * @param record | * @param record | ||||
| */ | */ | ||||
| ResultData update(WxMerchantSubsidy record); | |||||
| int update(WxMerchantSubsidy record); | |||||
| /** | /** | ||||
| * 根据Id删除实体 | * 根据Id删除实体 | ||||
| @@ -54,12 +56,10 @@ public interface WxMerchantSubsidyService { | |||||
| * @param id | * @param id | ||||
| */ | */ | ||||
| void deleteById(Long id); | void deleteById(Long id); | ||||
| /** | |||||
| * 补贴流水导出 | |||||
| */ | |||||
| void exportData(WxMerchantSubsidy wxMerchantSubsidy, HttpServletRequest request, HttpServletResponse response); | |||||
| } | } | ||||
| @@ -5,13 +5,27 @@ import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxMerchantSubsidy; | import com.iformall.domain.po.WxMerchantSubsidy; | ||||
| import com.iformall.domain.vo.WxMerchantSubsidyVo; | import com.iformall.domain.vo.WxMerchantSubsidyVo; | ||||
| import com.iformall.enums.EnumMerchantSubsidyStatus; | |||||
| import com.iformall.enums.EnumOrderType; | |||||
| import com.iformall.mapper.WxMerchantSubsidyMapper; | import com.iformall.mapper.WxMerchantSubsidyMapper; | ||||
| import com.iformall.service.WxMerchantSubsidyService; | import com.iformall.service.WxMerchantSubsidyService; | ||||
| import com.iformall.utils.Constant; | |||||
| import org.apache.commons.io.FileUtils; | |||||
| 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.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import com.iformall.common.IdWorker; | import com.iformall.common.IdWorker; | ||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import java.io.*; | |||||
| import java.text.SimpleDateFormat; | |||||
| import java.util.List; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| import java.util.UUID; | |||||
| @Service | @Service | ||||
| public class WxMerchantSubsidyServiceImpl implements WxMerchantSubsidyService { | public class WxMerchantSubsidyServiceImpl implements WxMerchantSubsidyService { | ||||
| @@ -50,21 +64,154 @@ public class WxMerchantSubsidyServiceImpl implements WxMerchantSubsidyService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public ResultData update(WxMerchantSubsidy record) { | |||||
| int num = wxMerchantSubsidyMapper.updateByCond(record); | |||||
| return new ResultData(num); | |||||
| public int update(WxMerchantSubsidy record) { | |||||
| return wxMerchantSubsidyMapper.updateByCond(record); | |||||
| } | } | ||||
| @Override | @Override | ||||
| public void deleteById(Long id) { | public void deleteById(Long id) { | ||||
| wxMerchantSubsidyMapper.deleteByPrimaryKey(id); | wxMerchantSubsidyMapper.deleteByPrimaryKey(id); | ||||
| } | } | ||||
| @Override | |||||
| public void exportData(WxMerchantSubsidy wxMerchantSubsidy, HttpServletRequest request, HttpServletResponse response) { | |||||
| List<WxMerchantSubsidyVo> subsidyVoList = wxMerchantSubsidyMapper.findVoList(wxMerchantSubsidy); | |||||
| 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 merchantNameCellTwo = rowtwo.createCell(1); | |||||
| Cell cardNameCellTwo = rowtwo.createCell(2); | |||||
| Cell orderIdCellTwo = rowtwo.createCell(3); | |||||
| Cell orderTypeCellTwo = rowtwo.createCell(4); | |||||
| Cell orderPaymentCellTwo = rowtwo.createCell(5); | |||||
| Cell receiverPaymentCellTwo = rowtwo.createCell(6); | |||||
| Cell realPaymentCellTwo = rowtwo.createCell(7); | |||||
| Cell realReceivePayCellTwo = rowtwo.createCell(8); | |||||
| Cell subsidyCellTwo = rowtwo.createCell(9); | |||||
| Cell realSubsidyCellTwo = rowtwo.createCell(10); | |||||
| Cell createDateCellTwo = rowtwo.createCell(11); | |||||
| Cell statusCellTwo = rowtwo.createCell(12); | |||||
| idCellTwo.setCellValue("ID"); | |||||
| merchantNameCellTwo.setCellValue("商户"); | |||||
| cardNameCellTwo.setCellValue("卡券名"); | |||||
| orderIdCellTwo.setCellValue("订单号"); | |||||
| orderTypeCellTwo.setCellValue("支付类型"); | |||||
| orderPaymentCellTwo.setCellValue("订单金额"); | |||||
| receiverPaymentCellTwo.setCellValue("接收金额"); | |||||
| realPaymentCellTwo.setCellValue("实收金额"); | |||||
| realReceivePayCellTwo.setCellValue("实收金额"); | |||||
| subsidyCellTwo.setCellValue("补贴金额(包含通道费)"); | |||||
| realSubsidyCellTwo.setCellValue("补贴金额(不包含通道费)"); | |||||
| createDateCellTwo.setCellValue("创建时间"); | |||||
| statusCellTwo.setCellValue("状态"); | |||||
| for (int i = 0; i < subsidyVoList.size(); i++) { | |||||
| rowtwo = sheetTwo.createRow(i + 1); | |||||
| idCellTwo = rowtwo.createCell(0); | |||||
| merchantNameCellTwo = rowtwo.createCell(1); | |||||
| cardNameCellTwo = rowtwo.createCell(2); | |||||
| orderIdCellTwo = rowtwo.createCell(3); | |||||
| orderTypeCellTwo = rowtwo.createCell(4); | |||||
| orderPaymentCellTwo = rowtwo.createCell(5); | |||||
| receiverPaymentCellTwo = rowtwo.createCell(6); | |||||
| realPaymentCellTwo = rowtwo.createCell(7); | |||||
| subsidyCellTwo = rowtwo.createCell(8); | |||||
| realSubsidyCellTwo = rowtwo.createCell(9); | |||||
| createDateCellTwo = rowtwo.createCell(10); | |||||
| statusCellTwo = rowtwo.createCell(11); | |||||
| WxMerchantSubsidyVo entity = subsidyVoList.get(i); | |||||
| idCellTwo.setCellValue(entity.getId()); | |||||
| merchantNameCellTwo.setCellValue(entity.getMerchantName()); | |||||
| cardNameCellTwo.setCellValue(entity.getTitle()); | |||||
| orderIdCellTwo.setCellValue(entity.getOrderId()); | |||||
| String str = "券"; // 0:券1:付款码支付,2:C扫码支付,3,储值卡 | |||||
| if (entity.getOrderType().equals(EnumOrderType.COUPON.getCode())) { | |||||
| str = "券"; | |||||
| } else if (entity.getOrderType().equals(EnumOrderType.MICROPAY.getCode())) { | |||||
| str = "付款码支付"; | |||||
| } else if (entity.getOrderType().equals(EnumOrderType.NATIVEPAY.getCode())) { | |||||
| str = "C扫码支付"; | |||||
| } else if (entity.getOrderType().equals(EnumOrderType.PREPAIDCARD.getCode())) { | |||||
| str = "储值卡"; | |||||
| } | |||||
| orderTypeCellTwo.setCellValue(str); | |||||
| orderPaymentCellTwo.setCellValue(entity.getOrderPayment()/ 100); | |||||
| receiverPaymentCellTwo.setCellValue(entity.getReceiverPayment() / 100); | |||||
| realPaymentCellTwo.setCellValue(entity.getRealPayment() / 100); | |||||
| subsidyCellTwo.setCellValue(entity.getSubsidy() / 100); | |||||
| realSubsidyCellTwo.setCellValue(entity.getRealSubsidy()); | |||||
| if (entity.getCreateDate() != null) | |||||
| createDateCellTwo.setCellValue(sdf.format(entity.getCreateDate())); | |||||
| String statusStr = "未补贴"; | |||||
| if (entity.getStatus().equals(EnumMerchantSubsidyStatus.NOT_SUBSIDY.getCode())) { | |||||
| statusStr = "未补贴"; | |||||
| } else if (entity.getStatus().equals(EnumMerchantSubsidyStatus.AUTO_SUBSIDIED.getCode())) { | |||||
| statusStr = "已自动补贴"; | |||||
| } else if (entity.getStatus().equals(EnumMerchantSubsidyStatus.MANUAL_SUBSIDIED.getCode())) { | |||||
| statusStr = "已手工补贴"; | |||||
| } | |||||
| statusCellTwo.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(); | |||||
| } | |||||
| } | |||||
| } | } | ||||