完成优惠券导出功能

dev-discount
胡锐 3 years ago
parent 95c81728b3
commit 33f7057ceb
  1. BIN
      1
  2. 117
      hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java
  3. 8
      hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java

BIN
1

Binary file not shown.

@ -4,6 +4,7 @@ import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.bweb.config.SysConst;
import com.bweb.excelListener.ImportCouponListener; import com.bweb.excelListener.ImportCouponListener;
import com.bweb.model.ImportCouponModel; import com.bweb.model.ImportCouponModel;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
@ -37,6 +38,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -453,6 +455,121 @@ public class HighCouponController {
} }
} }
@RequestMapping(value="/exportStock",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "导出卡卷库存")
public ResponseData exportStock(@RequestBody JSONObject body, HttpServletRequest request) {
try {
SessionObject sessionObject = userCenter.getSessionObject(request);
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject();
if (body == null || body.getLong("couponId") == null) {
log.error("HighCouponController -> exportStock() error!","请求参数校验失败");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
// 查找卡卷
HighCoupon coupon = highCouponService.getCouponById(body.getLong("couponId"));
if (coupon == null) {
log.error("HighCouponController -> writeStock() error!","未找到卡卷信息");
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, "");
}
Map<String, Object> param = new HashMap<>();
param.put("couponId", body.getLong("couponId"));
param.put("status", body.getInteger("status"));
param.put("createTimeS", body.getLong("createTimeS"));
param.put("createTimeE", body.getLong("createTimeE"));
// 销售码
List<HighCouponCode> codeList = highCouponCodeService.getCouponCodeList(param);
List<String> headList = new ArrayList<>();;
headList.add("序号");
headList.add("消费码key");
headList.add("消费码");
headList.add("状态");
headList.add("使用门店");
headList.add("领取时间");
headList.add("消费时间");
headList.add("销售截止时间");
headList.add("使用截止时间");
headList.add("创建时间");
List<List<Object>> dataList = new ArrayList<>();
List<Object> data;
Integer i = 1;
for (HighCouponCode couponCode : codeList) {
data = new ArrayList<>();
data.add(i++);
data.add(couponCode.getCodeKey());
data.add(couponCode.getSalesCode());
if (couponCode.getStatus() == 1) {
data.add("待销售");
} else if (couponCode.getStatus() == 2) {
data.add("待使用");
} else if (couponCode.getStatus() == 3) {
data.add("已使用");
} else if (couponCode.getStatus() == 4) {
data.add("已过期");
} else if (couponCode.getStatus() == 99) {
data.add("预支付");
} else {
data.add("未知");
}
data.add(couponCode.getStoreName());
data.add(couponCode.getReceiveTime());
data.add(couponCode.getConsumeTime());
data.add(couponCode.getSalesEndTime());
data.add(couponCode.getUseEndTime());
data.add(couponCode.getCreateTime());
dataList.add(data);
}
String fileUrl = SysConst.getSysConfig().getFileUrl() + "/temporary/";
String pathName = "导出销售码"+System.currentTimeMillis()+".xlsx";
File file = new File(fileUrl);
if (!file.exists()) {
file.mkdirs();
}
EasyExcel.write(fileUrl+pathName).head(generationHead(headList)).sheet("消费码").doWrite(dataList);
return ResponseMsgUtil.success(pathName);
} catch (Exception e) {
log.error("HighCouponController -> importStock() error!",e);
return ResponseMsgUtil.exception(e);
}
}
/* private List<List<String>> generationHead(List<String> headList) {
List<List<String>> list = new ArrayList<>();
List<String> head0 = new ArrayList<>();
head0.add("字符串" + System.currentTimeMillis());
List<String> head1 = new ArrayList<>();
head1.add("数字" + System.currentTimeMillis());
List<String> head2 = new ArrayList<>();
head2.add("日期" + System.currentTimeMillis());
list.add(head0);
list.add(head1);
list.add(head2);
return list;
}*/
/**
* 生成头部
* @param headList
* @return
*/
private List<List<String>> generationHead(List<String> headList) {
List<List<String>> list = new ArrayList<>();
List<String> head;
for (String headStr : headList) {
head = new ArrayList<>();
head.add(headStr);
list.add(head);
}
return list;
}
@RequestMapping(value="/writeStock",method = RequestMethod.POST) @RequestMapping(value="/writeStock",method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "填写卡卷库存(内部劵)") @ApiOperation(value = "填写卡卷库存(内部劵)")

@ -266,6 +266,14 @@ public class HighCouponCodeServiceImpl implements HighCouponCodeService {
criteria.andSalesEndTimeGreaterThan(new Date(MapUtils.getLong(map, "salesEndTimeS"))); criteria.andSalesEndTimeGreaterThan(new Date(MapUtils.getLong(map, "salesEndTimeS")));
} }
if (MapUtils.getLong(map, "createTimeS") != null) {
criteria.andCreateTimeGreaterThanOrEqualTo(new Date(MapUtils.getLong(map, "createTimeS")));
}
if (MapUtils.getLong(map, "createTimeE") != null) {
criteria.andCreateTimeLessThanOrEqualTo(new Date(MapUtils.getLong(map, "createTimeE")));
}
if (MapUtils.getBoolean(map, "isAssignAgent") != null) { if (MapUtils.getBoolean(map, "isAssignAgent") != null) {
criteria.andIsAssignAgentEqualTo(MapUtils.getBoolean(map, "isAssignAgent")); criteria.andIsAssignAgentEqualTo(MapUtils.getBoolean(map, "isAssignAgent"));
} }

Loading…
Cancel
Save