| | |
| | | import com.google.gson.TypeAdapter; |
| | | import com.google.gson.stream.JsonReader; |
| | | import com.google.gson.stream.JsonWriter; |
| | | import com.sun.org.apache.bcel.internal.generic.BREAKPOINT; |
| | | import com.taoke.autopay.dao.KeyOrderMapper; |
| | | import com.taoke.autopay.dto.admin.OrderExcelDataDto; |
| | | import com.taoke.autopay.entity.*; |
| | | import com.taoke.autopay.entity.ClientInfo; |
| | | import com.taoke.autopay.entity.KeyOrder; |
| | | import com.taoke.autopay.entity.OrderChannelEnum; |
| | | import com.taoke.autopay.entity.agent.ChannelAgent; |
| | | import com.taoke.autopay.factory.OrderFactory; |
| | | import com.taoke.autopay.service.ClientInfoService; |
| | | import com.taoke.autopay.service.KeyOrderService; |
| | | import com.taoke.autopay.service.agent.ChannelAgentService; |
| | | import com.taoke.autopay.utils.Constant; |
| | | import com.taoke.autopay.utils.TimeUtil; |
| | | import com.taoke.autopay.vo.admin.AdminOrderVO; |
| | |
| | | private KeyOrderService keyOrderService; |
| | | @Resource |
| | | private ClientInfoService clientInfoService; |
| | | @Resource |
| | | private ChannelAgentService channelAgentService; |
| | | |
| | | private KeyOrderMapper.DaoQuery createOrderQuery(OrderSearchVO vo) throws Exception { |
| | | // <option value="0">按老铁ID</option> |
| | | // <option value="1">按代理ID</option> |
| | | // <option value="2">按订单号</option> |
| | | KeyOrderMapper.DaoQuery query = new KeyOrderMapper.DaoQuery(); |
| | | if (!StringUtil.isNullOrEmpty(vo.getKey())) { |
| | | switch (vo.getKeyType()) { |
| | | case 0: |
| | | // 老铁ID |
| | | if (!NumberUtil.isNumeric(vo.getKey().trim())) { |
| | | throw new Exception("老铁ID必须为数字"); |
| | | } |
| | | query.uid = Long.parseLong(vo.getKey()); |
| | | break; |
| | | case 1: |
| | | // 代理ID |
| | | if (!NumberUtil.isNumeric(vo.getKey().trim())) { |
| | | throw new Exception("代理ID必须为数字"); |
| | | } |
| | | query.agentId = Long.parseLong(vo.getKey().trim()); |
| | | break; |
| | | case 2: |
| | | // 订单号 |
| | | query.orderNo = vo.getKey().trim(); |
| | | break; |
| | | case 3: |
| | | // 支付设备ID |
| | | if (!NumberUtil.isNumeric(vo.getKey().trim())) { |
| | | throw new Exception("支付设备ID必须为数字"); |
| | | } |
| | | query.distributeClientUid = Long.parseLong(vo.getKey().trim()); |
| | | break; |
| | | } |
| | | |
| | | } |
| | | |
| | | if (!StringUtil.isNullOrEmpty(vo.getState())) { |
| | | query.state = Integer.parseInt(vo.getState()); |
| | | } |
| | | |
| | | if (!StringUtil.isNullOrEmpty(vo.getOrderChannel())) { |
| | | |
| | | query.orderChannel = OrderChannelEnum.valueOf(vo.getOrderChannel()).getKey(); |
| | | |
| | | } |
| | | |
| | | if (!StringUtil.isNullOrEmpty(vo.getStartDate())) { |
| | | query.minCreateTime = new Date(TimeUtil.convertToTimeTemp(vo.getStartDate(), "yyyy-MM-dd")); |
| | | } |
| | | if (!StringUtil.isNullOrEmpty(vo.getEndDate())) { |
| | | query.maxCreateTime = TimeUtil.getNextDay(1, new Date(TimeUtil.convertToTimeTemp(vo.getEndDate(), "yyyy-MM-dd")).getTime()); |
| | | } |
| | | |
| | | return query; |
| | | |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("list") |
| | | 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(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()); |
| | | } |
| | | |
| | | List<KeyOrder> orderList = keyOrderService.list(query); |
| | | long count = keyOrderService.count(query); |
| | | Map<Long, ClientInfo> clientMap = new HashMap<>(); |
| | | if (orderList.size() > 0) { |
| | | List<Long> cids = new ArrayList<>(); |
| | | for (KeyOrder u : orderList) { |
| | | if (u.getDistributeClientUid() != null) { |
| | | cids.add(u.getDistributeClientUid()); |
| | | try { |
| | | KeyOrderMapper.DaoQuery query = createOrderQuery(search); |
| | | query.sortList = Arrays.asList(new String[]{"create_time desc"}); |
| | | query.start = (page - 1) * limit; |
| | | query.count = limit; |
| | | List<KeyOrder> orderList = keyOrderService.list(query); |
| | | long count = keyOrderService.count(query); |
| | | // 统计设备 |
| | | Map<Long, ClientInfo> clientMap = new HashMap<>(); |
| | | if (orderList.size() > 0) { |
| | | List<Long> cids = new ArrayList<>(); |
| | | for (KeyOrder u : orderList) { |
| | | if (u.getDistributeClientUid() != null) { |
| | | cids.add(u.getDistributeClientUid()); |
| | | } |
| | | } |
| | | List<ClientInfo> clients = clientInfoService.listByIds(cids); |
| | | for (ClientInfo client : clients) { |
| | | clientMap.put(client.getId(), client); |
| | | } |
| | | } |
| | | List<ClientInfo> clients = clientInfoService.listByIds(cids); |
| | | for (ClientInfo client : clients) { |
| | | clientMap.put(client.getId(), client); |
| | | // 统计代理信息 |
| | | Map<Long, ChannelAgent> agentMap = new HashMap<>(); |
| | | List<Long> agengIds = new ArrayList<>(); |
| | | for (KeyOrder u : orderList) { |
| | | if (u.getAgentId() != null) { |
| | | agengIds.add(u.getAgentId()); |
| | | } |
| | | } |
| | | } |
| | | List<ChannelAgent> agents = channelAgentService.listByIds(agengIds); |
| | | for (ChannelAgent agent : agents) { |
| | | agentMap.put(agent.getId(), agent); |
| | | } |
| | | |
| | | // 转vo |
| | | List<AdminOrderVO> voList = new ArrayList<>(); |
| | | for (KeyOrder order : orderList) { |
| | | voList.add(OrderFactory.createAdminVO(order, clientMap.get(order.getDistributeClientUid()))); |
| | | |
| | | // 转vo |
| | | List<AdminOrderVO> voList = new ArrayList<>(); |
| | | for (KeyOrder order : orderList) { |
| | | voList.add(OrderFactory.createAdminVO(order, clientMap.get(order.getDistributeClientUid()), agentMap.get(order.getAgentId()))); |
| | | } |
| | | JSONObject data = new JSONObject(); |
| | | data.put("count", count); |
| | | data.put("list", gson.toJson(voList)); |
| | | return JsonUtil.loadTrueResult(data); |
| | | }catch(Exception e){ |
| | | return JsonUtil.loadFalseResult(e.getMessage()); |
| | | } |
| | | JSONObject data = new JSONObject(); |
| | | data.put("count", count); |
| | | data.put("list", gson.toJson(voList)); |
| | | 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"}); |
| | | try { |
| | | KeyOrderMapper.DaoQuery query = createOrderQuery(search); |
| | | query.sortList = Arrays.asList(new String[]{"create_time desc"}); |
| | | long count = keyOrderService.count(query); |
| | | |
| | | 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); |
| | | 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<>(); |
| | | // 统计代理信息 |
| | | Map<Long, ChannelAgent> agentMap = new HashMap<>(); |
| | | List<Long> agengIds = new ArrayList<>(); |
| | | for (KeyOrder u : orderList) { |
| | | if (u.getAgentId() != null) { |
| | | agengIds.add(u.getAgentId()); |
| | | } |
| | | } |
| | | List<ChannelAgent> agents = channelAgentService.listByIds(agengIds); |
| | | for (ChannelAgent agent : agents) { |
| | | agentMap.put(agent.getId(), agent); |
| | | } |
| | | |
| | | 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.setAgent(agentMap.get(order.getAgentId()) == null ? "" : agentMap.get(order.getAgentId()).getName()); |
| | | 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(""); |
| | | } |
| | | dto.setPayMerchant(order.getPayMerchant()); |
| | | 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); |
| | | }catch(Exception e){ |
| | | response.sendError(402,e.getMessage()); |
| | | } |
| | | 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); |
| | | } |
| | | |
| | | |
| | | |
| | | } |