| | |
| | | package com.taoke.autopay.controller.admin; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.GsonBuilder; |
| | | import com.google.gson.TypeAdapter; |
| | | import com.google.gson.stream.JsonReader; |
| | | import com.google.gson.stream.JsonWriter; |
| | | import com.taoke.autopay.dao.KeyOrderMapper; |
| | | import com.taoke.autopay.dao.WxUserInfoMapper; |
| | | import com.taoke.autopay.entity.*; |
| | | import com.taoke.autopay.dto.admin.OrderExcelDataDto; |
| | | import com.taoke.autopay.entity.ClientInfo; |
| | | import com.taoke.autopay.entity.KeyOrder; |
| | | import com.taoke.autopay.factory.OrderFactory; |
| | | import com.taoke.autopay.factory.WxUserFactory; |
| | | import com.taoke.autopay.service.AdminUserService; |
| | | import com.taoke.autopay.service.ClientInfoService; |
| | | import com.taoke.autopay.service.KeyOrderService; |
| | | import com.taoke.autopay.utils.Constant; |
| | | import com.taoke.autopay.utils.TimeUtil; |
| | | import com.taoke.autopay.vo.AdminOrderVO; |
| | | import com.taoke.autopay.vo.WxUserVO; |
| | | import com.taoke.autopay.vo.admin.AdminOrderVO; |
| | | import com.taoke.autopay.vo.admin.OrderSearchVO; |
| | | import net.sf.json.JSONObject; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.validation.BindingResult; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.yeshi.utils.JsonUtil; |
| | |
| | | import org.yeshi.utils.StringUtil; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpSession; |
| | | import javax.validation.constraints.NotEmpty; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.net.URLEncoder; |
| | | import java.util.*; |
| | | |
| | | @Controller |
| | |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("list") |
| | | public String listOrder(String key, int page, int limit) { |
| | | public String listOrder(OrderSearchVO search, int page, int limit) { |
| | | //先查询所有的数据 |
| | | KeyOrderMapper.DaoQuery query = new KeyOrderMapper.DaoQuery(); |
| | | query.sortList=Arrays.asList(new String[]{"create_time desc"}); |
| | | query.start = (page - 1) * limit; |
| | | query.count = limit; |
| | | if (!StringUtil.isNullOrEmpty(key)) { |
| | | if (key.length() > 10 || !NumberUtil.isNumeric(key.trim())) { |
| | | if (!StringUtil.isNullOrEmpty(search.getKey())) { |
| | | if (search.getKey().length() > 10 || !NumberUtil.isNumeric(search.getKey().trim())) { |
| | | // 订单号 |
| | | query.orderNo = key.trim(); |
| | | query.orderNo = search.getKey().trim(); |
| | | } else { |
| | | // 用户ID |
| | | query.uid = Long.parseLong(key.trim()); |
| | | query.uid = Long.parseLong(search.getKey().trim()); |
| | | } |
| | | } |
| | | |
| | | if (!StringUtil.isNullOrEmpty(search.getStartDate())) { |
| | | query.minCreateTime =new Date(TimeUtil.convertToTimeTemp(search.getStartDate(),"yyyy-MM-dd")); |
| | | } |
| | | if (!StringUtil.isNullOrEmpty(search.getEndDate())) { |
| | | query.maxCreateTime =TimeUtil.getNextDay(1,new Date(TimeUtil.convertToTimeTemp(search.getEndDate(),"yyyy-MM-dd")).getTime()); |
| | | } |
| | | |
| | | List<KeyOrder> orderList = keyOrderService.list(query); |
| | |
| | | return JsonUtil.loadTrueResult(data); |
| | | } |
| | | |
| | | |
| | | |
| | | @RequestMapping("downLoadOrder") |
| | | public void downLoadOrder(OrderSearchVO search, HttpServletResponse response) throws IOException { |
| | | KeyOrderMapper.DaoQuery query = new KeyOrderMapper.DaoQuery(); |
| | | if (!StringUtil.isNullOrEmpty(search.getKey())) { |
| | | if (search.getKey().length() > 10 || !NumberUtil.isNumeric(search.getKey().trim())) { |
| | | // 订单号 |
| | | query.orderNo = search.getKey().trim(); |
| | | } else { |
| | | // 用户ID |
| | | query.uid = Long.parseLong(search.getKey().trim()); |
| | | } |
| | | } |
| | | if (!StringUtil.isNullOrEmpty(search.getStartDate())) { |
| | | query.minCreateTime =new Date(TimeUtil.convertToTimeTemp(search.getStartDate(),"yyyy-MM-dd")); |
| | | } |
| | | if (!StringUtil.isNullOrEmpty(search.getEndDate())) { |
| | | query.maxCreateTime =TimeUtil.getNextDay(1,new Date(TimeUtil.convertToTimeTemp(search.getEndDate(),"yyyy-MM-dd")).getTime()); |
| | | } |
| | | query.sortList=Arrays.asList(new String[]{"create_time desc"}); |
| | | |
| | | long count = keyOrderService.count(query); |
| | | |
| | | query.start=0; |
| | | query.count = (int)count; |
| | | List<KeyOrder> orderList = keyOrderService.list(query); |
| | | // 统计订单与金额 |
| | | Map<Long,Integer> userOrderCountMap=new HashMap<>(); |
| | | Map<Long, BigDecimal> userOrderMoneyMap=new HashMap<>(); |
| | | Map<Long, ClientInfo> payDeviceMap=new HashMap<>(); |
| | | |
| | | List<OrderExcelDataDto> dataList=new ArrayList<>(); |
| | | for(KeyOrder order:orderList){ |
| | | if(!userOrderCountMap.containsKey(order.getUid())){ |
| | | userOrderCountMap.put(order.getUid(),1); |
| | | }else{ |
| | | userOrderCountMap.put(order.getUid(), userOrderCountMap.get(order.getUid())+1); |
| | | } |
| | | if(!userOrderMoneyMap.containsKey(order.getUid())){ |
| | | userOrderMoneyMap.put(order.getUid(),new BigDecimal(0)); |
| | | } |
| | | if(order.getOrderMoney()!=null) { |
| | | userOrderMoneyMap.put(order.getUid(), userOrderMoneyMap.get(order.getUid()).add(order.getOrderMoney())); |
| | | } |
| | | if(!payDeviceMap.containsKey(order.getDistributeClientUid())&&order.getDistributeClientUid()!=null) { |
| | | ClientInfo clientInfo = clientInfoService.selectByPrimaryKey(order.getDistributeClientUid()); |
| | | if(clientInfo!=null) { |
| | | payDeviceMap.put(clientInfo.getId(), clientInfo); |
| | | } |
| | | } |
| | | |
| | | } |
| | | for(KeyOrder order:orderList){ |
| | | OrderExcelDataDto dto=new OrderExcelDataDto(); |
| | | dto.setId(order.getId()); |
| | | dto.setCreateTime(TimeUtil.getGernalTime(order.getCreateTime())); |
| | | dto.setOrderMoney(order.getOrderMoney()==null?"":order.getOrderMoney().toString()); |
| | | if(order.getOrderChannel()!=null) { |
| | | switch (order.getOrderChannel()) { |
| | | case Constant |
| | | .ORDER_CHANNEL_CYX: |
| | | dto.setOrderChannel("超佣享"); |
| | | break; |
| | | case Constant |
| | | .ORDER_CHANNEL_BPS: |
| | | dto.setOrderChannel("爆品社"); |
| | | break; |
| | | default: |
| | | dto.setOrderChannel(""); |
| | | } |
| | | }else{ |
| | | dto.setOrderChannel(""); |
| | | } |
| | | dto.setOrderNo(order.getOrderNo()); |
| | | if(order.getOrderType()!=null) { |
| | | switch (order.getOrderType()) { |
| | | case Constant.ORDER_TYPE_DY: |
| | | dto.setPlatform("抖音"); |
| | | break; |
| | | case Constant.ORDER_TYPE_KS: |
| | | dto.setPlatform("快手"); |
| | | break; |
| | | default: |
| | | dto.setPlatform(""); |
| | | } |
| | | }else{ |
| | | dto.setPlatform(""); |
| | | } |
| | | |
| | | if(order.getPayType()!=null) { |
| | | switch (order.getPayType()) { |
| | | case Constant.PAY_TYPE_WITH_ORDER_NO: |
| | | dto.setPayType("按订单"); |
| | | break; |
| | | case Constant.PAY_TYPE_WITH_MONEY: |
| | | dto.setPayType("按金额"); |
| | | break; |
| | | default: |
| | | dto.setPayType(""); |
| | | } |
| | | }else{ |
| | | dto.setPayType(""); |
| | | } |
| | | |
| | | dto.setUid(order.getUid()); |
| | | if(order.getState()==KeyOrder.STATE_PAY){ |
| | | dto.setPaySuccess("是"); |
| | | }else { |
| | | dto.setPaySuccess("否"); |
| | | } |
| | | dto.setStateDesc(order.getStateDesc()); |
| | | dto.setTotalCount(userOrderCountMap.get(order.getUid())); |
| | | dto.setTotalMoney(userOrderMoneyMap.get(order.getUid()).toString()); |
| | | dto.setKey(order.getKey()); |
| | | if(order.getPayTime()!=null){ |
| | | dto.setPayTime(TimeUtil.getGernalTime(order.getPayTime().getTime(),"yyyy-MM-dd HH:mm:ss")); |
| | | } |
| | | ClientInfo device = payDeviceMap.get(order.getDistributeClientUid()); |
| | | if(device!=null){ |
| | | dto.setPayDevice(device.getAccount()); |
| | | }else{ |
| | | dto.setPayDevice(""); |
| | | } |
| | | dataList.add(dto); |
| | | } |
| | | |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 |
| | | String fileName= URLEncoder.encode(TimeUtil.getGernalTime(System.currentTimeMillis(),"yyyyMMdd_HHmmss"),"UTF-8"); |
| | | response.setHeader("Content-disposition","attachment;filename*=utf-8''"+fileName+".xlsx"); |
| | | EasyExcel.write(response.getOutputStream(),OrderExcelDataDto.class).sheet("订单").doWrite(dataList); |
| | | } |
| | | |
| | | |
| | | |
| | | } |