|
|
@ -1,21 +1,29 @@ |
|
|
package cn.chjyj.szwh.controller.admin; |
|
|
package cn.chjyj.szwh.controller.admin; |
|
|
|
|
|
|
|
|
|
|
|
import cn.chjyj.szwh.bean.Order; |
|
|
import cn.chjyj.szwh.bean.OrderGoodsDetail; |
|
|
import cn.chjyj.szwh.bean.OrderGoodsDetail; |
|
|
import cn.chjyj.szwh.controller.BaseController; |
|
|
import cn.chjyj.szwh.controller.BaseController; |
|
|
import cn.chjyj.szwh.service.OrderGoodsDetailService; |
|
|
import cn.chjyj.szwh.service.OrderGoodsDetailService; |
|
|
import cn.chjyj.szwh.service.OrderService; |
|
|
import cn.chjyj.szwh.service.OrderService; |
|
|
|
|
|
import cn.chjyj.szwh.utils.AjaxResult; |
|
|
|
|
|
import cn.chjyj.szwh.utils.SzReqUtils; |
|
|
|
|
|
import cn.chjyj.szwh.vo.AdOrderVO; |
|
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
import com.alibaba.fastjson2.JSON; |
|
|
import com.alibaba.fastjson2.JSON; |
|
|
import com.alibaba.fastjson2.JSONArray; |
|
|
import com.alibaba.fastjson2.JSONArray; |
|
|
import com.alibaba.fastjson2.JSONObject; |
|
|
import com.alibaba.fastjson2.JSONObject; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
import java.util.HashMap; |
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import java.util.List; |
|
|
import java.io.IOException; |
|
|
import java.util.Map; |
|
|
import java.math.BigDecimal; |
|
|
|
|
|
import java.net.URLEncoder; |
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 订单管理 |
|
|
* 订单管理 |
|
|
@ -37,70 +45,23 @@ public class AdminOrderController extends BaseController { |
|
|
public JSONObject odlist(@RequestBody(required = false) String jsonStr){ |
|
|
public JSONObject odlist(@RequestBody(required = false) String jsonStr){ |
|
|
JSONObject request = JSON.parseObject(jsonStr); |
|
|
JSONObject request = JSON.parseObject(jsonStr); |
|
|
Map rqmap = new HashMap(); |
|
|
Map rqmap = new HashMap(); |
|
|
if(StringUtils.isBlank(jsonStr)){ |
|
|
if(StringUtils.isNotBlank(jsonStr)){ |
|
|
rqmap=null; |
|
|
rqmap = queryMap(request); |
|
|
} |
|
|
|
|
|
// 订单编号
|
|
|
|
|
|
String batchcode= request.getString("batchcode"); |
|
|
|
|
|
if(StringUtils.isNotBlank(batchcode)){ |
|
|
|
|
|
rqmap.put("o.batchcode",batchcode); |
|
|
|
|
|
} |
|
|
|
|
|
//委托方
|
|
|
|
|
|
String entrustName=request.getString("entrust_name").trim(); |
|
|
|
|
|
//购买方
|
|
|
|
|
|
String buyName=request.getString("buy_name"); |
|
|
|
|
|
|
|
|
|
|
|
//商品名称
|
|
|
|
|
|
String goodsName=request.getString("goods_name"); |
|
|
|
|
|
if(StringUtils.isNotBlank(goodsName)){ |
|
|
|
|
|
rqmap.put("og.goods_name",goodsName); |
|
|
|
|
|
} |
|
|
|
|
|
// 订单类型
|
|
|
|
|
|
String orderType= request.getString("order_type"); |
|
|
|
|
|
if(StringUtils.isNotBlank(orderType)){ |
|
|
|
|
|
rqmap.put("order_type",orderType); |
|
|
|
|
|
} |
|
|
|
|
|
//充值类型
|
|
|
|
|
|
String chargesType= request.getString("charges_type"); |
|
|
|
|
|
if(StringUtils.isNotBlank(chargesType)){ |
|
|
|
|
|
rqmap.put("og.charges_type",chargesType); |
|
|
|
|
|
} |
|
|
|
|
|
//订单状态
|
|
|
|
|
|
String transaction_status=request.getString("transaction_status"); |
|
|
|
|
|
if(StringUtils.isNotBlank(transaction_status)){ |
|
|
|
|
|
rqmap.put("o.status",transaction_status); |
|
|
|
|
|
} |
|
|
} |
|
|
// 交易类型
|
|
|
|
|
|
String entrustType=request.getString("entrust_type"); |
|
|
|
|
|
if(StringUtils.isNotBlank(entrustType)){ |
|
|
|
|
|
rqmap.put("og.goods_entrust",entrustType); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 创建时间
|
|
|
|
|
|
String createtime=request.getString("createtime"); |
|
|
|
|
|
if(StringUtils.isNotBlank(createtime)){ |
|
|
|
|
|
JSONArray jarr = JSONArray.parseArray(createtime); |
|
|
|
|
|
if(jarr.size()>0){ |
|
|
|
|
|
// 拆分
|
|
|
|
|
|
rqmap.put("o.createtime"," og.createtime between '"+jarr.get(0)+" 00:00:00' and '"+jarr.get(1)+" 23:59:59'"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//商品编号
|
|
|
|
|
|
String gdsid = request.getString("goods_isli"); |
|
|
|
|
|
if(StringUtils.isNotEmpty(gdsid)){ |
|
|
|
|
|
rqmap.put("og.goods_islicode",gdsid); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
//
|
|
|
String spage=request.getString("page"); |
|
|
String spage=request.getString("page"); |
|
|
int page= StringUtils.isNotBlank(spage)?Integer.valueOf(spage):1; |
|
|
int page= StringUtils.isNotBlank(spage)?Integer.valueOf(spage):1; |
|
|
//
|
|
|
//
|
|
|
String slimit=request.getString("limit"); |
|
|
String slimit=request.getString("limit"); |
|
|
int limit = StringUtils.isNotBlank(slimit)?Integer.valueOf(slimit):10; |
|
|
int limit = StringUtils.isNotBlank(slimit)?Integer.valueOf(slimit):10; |
|
|
|
|
|
//委托方
|
|
|
|
|
|
String entrustName=request.getString("entrust_name").trim(); |
|
|
|
|
|
//购买方
|
|
|
|
|
|
String buyName=request.getString("buy_name"); |
|
|
|
|
|
// 查询条件
|
|
|
Map map = orderService.getOrderList(rqmap,buyName,entrustName,page,limit); |
|
|
Map map = orderService.getOrderList(rqmap,buyName,entrustName,page,limit); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jsonObject.put("code",200); |
|
|
jsonObject.put("code",200); |
|
|
jsonObject.put("msg","操作成功"); |
|
|
jsonObject.put("msg","操作成功"); |
|
|
jsonObject.put("data",map); |
|
|
jsonObject.put("data",map); |
|
|
@ -169,4 +130,117 @@ public class AdminOrderController extends BaseController { |
|
|
return jsonObject; |
|
|
return jsonObject; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 从json 字符串中抽取得到相应的map进行查询 |
|
|
|
|
|
* @param request |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
private Map queryMap(JSONObject request){ |
|
|
|
|
|
Map rqmap = new HashMap(); |
|
|
|
|
|
|
|
|
|
|
|
// 订单编号
|
|
|
|
|
|
String batchcode= request.getString("batchcode"); |
|
|
|
|
|
if(StringUtils.isNotBlank(batchcode)){ |
|
|
|
|
|
rqmap.put("o.batchcode",batchcode); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//商品名称
|
|
|
|
|
|
String goodsName=request.getString("goods_name"); |
|
|
|
|
|
if(StringUtils.isNotBlank(goodsName)){ |
|
|
|
|
|
rqmap.put("og.goods_name",goodsName); |
|
|
|
|
|
} |
|
|
|
|
|
// 订单类型
|
|
|
|
|
|
String orderType= request.getString("order_type"); |
|
|
|
|
|
if(StringUtils.isNotBlank(orderType)){ |
|
|
|
|
|
rqmap.put("order_type",orderType); |
|
|
|
|
|
} |
|
|
|
|
|
//充值类型
|
|
|
|
|
|
String chargesType= request.getString("charges_type"); |
|
|
|
|
|
if(StringUtils.isNotBlank(chargesType)){ |
|
|
|
|
|
rqmap.put("og.charges_type",chargesType); |
|
|
|
|
|
} |
|
|
|
|
|
//订单状态
|
|
|
|
|
|
String transaction_status=request.getString("transaction_status"); |
|
|
|
|
|
if(StringUtils.isNotBlank(transaction_status)){ |
|
|
|
|
|
rqmap.put("o.status",transaction_status); |
|
|
|
|
|
} |
|
|
|
|
|
// 交易类型
|
|
|
|
|
|
String entrustType=request.getString("entrust_type"); |
|
|
|
|
|
if(StringUtils.isNotBlank(entrustType)){ |
|
|
|
|
|
rqmap.put("og.goods_entrust",entrustType); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 创建时间
|
|
|
|
|
|
String createtime=request.getString("createtime"); |
|
|
|
|
|
if(StringUtils.isNotBlank(createtime)){ |
|
|
|
|
|
JSONArray jarr = JSONArray.parseArray(createtime); |
|
|
|
|
|
if(jarr.size()>0){ |
|
|
|
|
|
// 拆分
|
|
|
|
|
|
rqmap.put("o.createtime"," og.createtime between '"+jarr.get(0)+" 00:00:00' and '"+jarr.get(1)+" 23:59:59'"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//商品编号
|
|
|
|
|
|
String gdsid = request.getString("goods_isli"); |
|
|
|
|
|
if(StringUtils.isNotEmpty(gdsid)){ |
|
|
|
|
|
rqmap.put("og.goods_islicode",gdsid); |
|
|
|
|
|
} |
|
|
|
|
|
return rqmap; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 导出excel,出现错误时候反馈给json |
|
|
|
|
|
* @param response |
|
|
|
|
|
* @param request |
|
|
|
|
|
* @throws IOException |
|
|
|
|
|
*/ |
|
|
|
|
|
@PostMapping(value = "/export",produces = "application/octet-stream") |
|
|
|
|
|
public void export(HttpServletResponse response, HttpServletRequest request) throws IOException { |
|
|
|
|
|
// 获取查询条件,得到对应的数据
|
|
|
|
|
|
JSONObject rejson = SzReqUtils.getJson(request); |
|
|
|
|
|
String spage=rejson.getString("page"); |
|
|
|
|
|
int page= StringUtils.isNotBlank(spage)?Integer.valueOf(spage):1; |
|
|
|
|
|
//
|
|
|
|
|
|
String slimit=rejson.getString("limit"); |
|
|
|
|
|
int limit = StringUtils.isNotBlank(slimit)?Integer.valueOf(slimit):10; |
|
|
|
|
|
// 从json 抽取出相应的查询条件
|
|
|
|
|
|
Map rmap = queryMap(rejson); |
|
|
|
|
|
List<AdOrderVO> adordlist = orderService.getAdOrdlist(rmap,page,limit); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
String dateStr = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")); |
|
|
|
|
|
String name = "WHYOTS"+dateStr; |
|
|
|
|
|
//防止下载时中文乱码
|
|
|
|
|
|
name = new String(name.getBytes("UTF-8"), "ISO-8859-1"); |
|
|
|
|
|
response.setContentType("application/vnd.ms-excel"); |
|
|
|
|
|
response.setCharacterEncoding("utf-8"); |
|
|
|
|
|
//添加这个是防止前端拿不到Content-disposition
|
|
|
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=" + name+".xlsx"); |
|
|
|
|
|
response.setHeader("Access-Control-Expose-Headers","Content-disposition"); |
|
|
|
|
|
|
|
|
|
|
|
// response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
|
|
|
// response.setCharacterEncoding("utf-8");
|
|
|
|
|
|
// // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
|
|
|
|
|
|
// //String fileName = URLEncoder.encode("测试", "UTF-8").replaceAll("\\+", "%20");
|
|
|
|
|
|
// String fileName =UUID.randomUUID().toString();
|
|
|
|
|
|
// response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
|
|
|
|
|
// 这里需要设置不关闭流
|
|
|
|
|
|
EasyExcel.write(response.getOutputStream(), AdOrderVO.class) |
|
|
|
|
|
.autoCloseStream(Boolean.FALSE) |
|
|
|
|
|
.sheet("数据1") |
|
|
|
|
|
.doWrite(adordlist); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
// 重置response
|
|
|
|
|
|
response.reset(); |
|
|
|
|
|
response.setContentType("application/json"); |
|
|
|
|
|
response.setCharacterEncoding("utf-8"); |
|
|
|
|
|
JSONObject otjson = AjaxResult.error("下载文件失败" + e.getMessage()); |
|
|
|
|
|
response.getWriter().println(otjson); |
|
|
|
|
|
// Map<String, String> otmap = new HashMap<>();
|
|
|
|
|
|
// otmap.put("status", "failure");
|
|
|
|
|
|
// otmap.put("message", "下载文件失败" + e.getMessage());
|
|
|
|
|
|
//response.getWriter().println(JSON.toJSONString(otmap));
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|