diff --git a/hai-bweb/src/test/common/ExcelModel.java b/hai-bweb/src/test/common/ExcelModel.java index ed6f11db..363a7913 100644 --- a/hai-bweb/src/test/common/ExcelModel.java +++ b/hai-bweb/src/test/common/ExcelModel.java @@ -9,25 +9,14 @@ import com.alibaba.excel.annotation.ExcelProperty; */ public class ExcelModel { - @ExcelProperty("卡券编码") - private String key; + @ExcelProperty("二维码地址") + private String codeUrl; - @ExcelProperty("商品编码") - private String name; - - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - - public String getName() { - return name; + public String getCodeUrl() { + return codeUrl; } - public void setName(String name) { - this.name = name; + public void setCodeUrl(String codeUrl) { + this.codeUrl = codeUrl; } } diff --git a/hai-bweb/src/test/common/RegionTest.java b/hai-bweb/src/test/common/RegionTest.java index b1aacb56..0d5da036 100644 --- a/hai-bweb/src/test/common/RegionTest.java +++ b/hai-bweb/src/test/common/RegionTest.java @@ -1,10 +1,15 @@ package common; import com.BWebApplication; +import com.alibaba.excel.EasyExcel; import com.alibaba.fastjson.JSON; +import com.hai.common.Base64Util; +import com.hai.common.security.AESEncodeUtil; +import com.hai.entity.HighDiscountAgentCode; import com.hai.entity.SecRegion; import com.hai.service.CommonService; +import com.hai.service.HighDiscountAgentCodeService; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; @@ -33,6 +38,9 @@ public class RegionTest { @Resource private CommonService commonService; + @Resource + private HighDiscountAgentCodeService highDiscountAgentCodeService; + @Test public void addLogs(){ try { @@ -67,4 +75,32 @@ public class RegionTest { e.printStackTrace(); } } + + @Test + public void simpleWrite() throws Exception { + // 写法1 + String fileName = "D:\\simpleWrite.xlsx"; + + + Map paramMap = new HashMap<>(); + paramMap.put("discountAgentId", ""); + List codeList = highDiscountAgentCodeService.getDiscountCode(paramMap); + + List list = new ArrayList<>(); + ExcelModel excelModel; + + Map map = new HashMap<>(); + map.put("type", "DISCOUNT"); + + for (HighDiscountAgentCode code : codeList) { + excelModel = new ExcelModel(); + map.put("id", code.getId()); + String param = "https://hsg.dctpay.com/wx/?action=gogogo&id=" + Base64Util.encode(AESEncodeUtil.aesEncrypt(JSON.toJSONString(map))); + excelModel.setCodeUrl(param); + list.add(excelModel); + } + // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭 + // 如果这里想使用03 则 传入excelType参数即可 + EasyExcel.write(fileName, ExcelModel.class).sheet("模板").doWrite(list); + } } diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java b/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java index 2690ccf0..a6af5a78 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java @@ -11,6 +11,7 @@ import com.hai.common.utils.ResponseMsgUtil; import com.hai.entity.BsCompany; import com.hai.entity.HighCoupon; import com.hai.entity.HighUserCoupon; +import com.hai.entity.SecRegion; import com.hai.model.HighUserCouponModel; import com.hai.model.HighUserModel; import com.hai.model.ResponseData; @@ -61,6 +62,9 @@ public class HighCouponController { @Resource private HighMerchantStoreService highMerchantStoreService; + @Resource + private CommonService commonService; + @RequestMapping(value = "/getCouponList", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "卡卷列表") @@ -73,20 +77,22 @@ public class HighCouponController { @RequestParam(name = "pageSize", required = true) Integer pageSize) { try { - BsCompany bsCompany = bsCompanyService.selectCompanyByRegion(regionId); - if (bsCompany != null) { - Map map = new HashMap<>(); - map.put("companyId", bsCompany.getId()); - map.put("merchantId", merchantId); - map.put("couponName", couponName); - map.put("couponType", couponType); - map.put("displayArea", displayArea); - map.put("notCouponSource", 2); - map.put("status", 2); - PageHelper.startPage(pageNum, pageSize); - return ResponseMsgUtil.success(new PageInfo<>(highCouponService.getCouponList(map))); + SecRegion region = commonService.getRegionsById(Long.parseLong(regionId)); + if (region != null && region.getParentId() != null) { + BsCompany bsCompany = bsCompanyService.selectCompanyByRegion(region.getParentId().toString()); + if (bsCompany != null) { + Map map = new HashMap<>(); + map.put("companyId", bsCompany.getId()); + map.put("merchantId", merchantId); + map.put("couponName", couponName); + map.put("couponType", couponType); + map.put("displayArea", displayArea); + map.put("notCouponSource", 2); + map.put("status", 2); + PageHelper.startPage(pageNum, pageSize); + return ResponseMsgUtil.success(new PageInfo<>(highCouponService.getCouponList(map))); + } } - return ResponseMsgUtil.success(new PageInfo<>()); } catch (Exception e) { diff --git a/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java b/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java index 09b07f90..1bfd4138 100644 --- a/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java +++ b/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java @@ -3,6 +3,7 @@ package com.hai.service; import com.hai.entity.HighDiscountAgentCode; import java.util.List; +import java.util.Map; /** * @Auther: 胡锐 @@ -32,6 +33,13 @@ public interface HighDiscountAgentCodeService { **/ void updateCode(HighDiscountAgentCode highDiscountAgentCode); + /** + * @Author 胡锐 + * @Description 查询 + * @Date 2021/4/16 22:20 + **/ + List getDiscountCode(Map map); + /** * @Author 胡锐 * @Description 根据id 查询二维码 diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentCodeServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentCodeServiceImpl.java index 0bb4c17a..aa1dd8ee 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentCodeServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentCodeServiceImpl.java @@ -2,11 +2,14 @@ package com.hai.service.impl; import com.hai.dao.HighDiscountAgentCodeMapper; import com.hai.entity.HighDiscountAgentCode; +import com.hai.entity.HighDiscountAgentCodeExample; import com.hai.service.HighDiscountAgentCodeService; +import org.apache.commons.collections4.MapUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.List; +import java.util.Map; /** * @Auther: 胡锐 @@ -34,6 +37,17 @@ public class HighDiscountAgentCodeServiceImpl implements HighDiscountAgentCodeSe highDiscountAgentCodeMapper.updateByPrimaryKey(highDiscountAgentCode); } + @Override + public List getDiscountCode(Map map) { + HighDiscountAgentCodeExample example = new HighDiscountAgentCodeExample(); + HighDiscountAgentCodeExample.Criteria criteria = example.createCriteria(); + + if (MapUtils.getLong(map, "discountAgentId") != null) { + criteria.andDiscountAgentIdEqualTo(MapUtils.getLong(map, "discountAgentId")); + } + return highDiscountAgentCodeMapper.selectByExample(example); + } + @Override public HighDiscountAgentCode getCodeById(Long id) { return highDiscountAgentCodeMapper.selectByPrimaryKey(id); diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentRelServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentRelServiceImpl.java index 8e679446..edae51de 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentRelServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentRelServiceImpl.java @@ -66,6 +66,7 @@ public class HighDiscountAgentRelServiceImpl implements HighDiscountAgentRelServ String param = "https://hsg.dctpay.com/wx/?action=gogogo&id=" + Base64Util.encode(AESEncodeUtil.aesEncrypt(JSON.toJSONString(map))); QRCodeGenerator.generateQRCodeImage(param, 350, 350, path + folder + qrCodeImg); code.setQrCode(qrCodeImg); + code.setExt1(param); highDiscountAgentCodeService.updateCode(code); } }