|
|
|
@ -4,6 +4,7 @@ import com.alibaba.excel.EasyExcel; |
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.bweb.config.SysConst; |
|
|
|
|
import com.bweb.excelListener.ImportCouponListener; |
|
|
|
|
import com.bweb.model.ImportCouponModel; |
|
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
@ -37,6 +38,7 @@ import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
import java.io.File; |
|
|
|
|
import java.util.*; |
|
|
|
|
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) |
|
|
|
|
@ResponseBody |
|
|
|
|
@ApiOperation(value = "填写卡卷库存(内部劵)") |
|
|
|
|