diff --git a/yshop-common/src/main/java/co/yixiang/annotation/Query.java b/yshop-common/src/main/java/co/yixiang/annotation/Query.java index 3d088a7b..3cce7ebf 100644 --- a/yshop-common/src/main/java/co/yixiang/annotation/Query.java +++ b/yshop-common/src/main/java/co/yixiang/annotation/Query.java @@ -56,6 +56,8 @@ public @interface Query { ,BETWEEN // 不为空 ,NOT_NULL + // 查询时间 + ,UNIX_TIMESTAMP } /** diff --git a/yshop-common/src/main/java/co/yixiang/utils/QueryHelp.java b/yshop-common/src/main/java/co/yixiang/utils/QueryHelp.java index a01da38f..27bc9a9f 100644 --- a/yshop-common/src/main/java/co/yixiang/utils/QueryHelp.java +++ b/yshop-common/src/main/java/co/yixiang/utils/QueryHelp.java @@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j; import co.yixiang.annotation.Query; import javax.persistence.criteria.*; import java.lang.reflect.Field; +import java.text.SimpleDateFormat; import java.util.*; /** @@ -118,6 +119,16 @@ public class QueryHelp { list.add(cb.between(getExpression(attributeName, join, root).as((Class) between.get(0).getClass()), (Comparable) between.get(0), (Comparable) between.get(1))); break; + case UNIX_TIMESTAMP: + List UNIX_TIMESTAMP = new ArrayList<>((List)val); + if(!UNIX_TIMESTAMP.isEmpty()){ + SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + long time1 = fm.parse(UNIX_TIMESTAMP.get(0).toString()).getTime()/1000; + long time2 = fm.parse(UNIX_TIMESTAMP.get(1).toString()).getTime()/1000; + list.add(cb.between(getExpression(attributeName, join, root), + time1, time2)); + } + break; default: break; } } diff --git a/yshop-shop/src/main/java/co/yixiang/modules/shop/rest/StoreOrderController.java b/yshop-shop/src/main/java/co/yixiang/modules/shop/rest/StoreOrderController.java index 12891525..671612b9 100644 --- a/yshop-shop/src/main/java/co/yixiang/modules/shop/rest/StoreOrderController.java +++ b/yshop-shop/src/main/java/co/yixiang/modules/shop/rest/StoreOrderController.java @@ -23,10 +23,12 @@ import co.yixiang.mp.service.YxTemplateService; import co.yixiang.mp.service.YxWechatTemplateService; import co.yixiang.utils.OrderUtil; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Pageable; import org.springframework.data.redis.core.RedisTemplate; @@ -37,7 +39,13 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.text.MessageFormat; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; /** @@ -370,4 +378,110 @@ public class StoreOrderController { return new ResponseEntity(expressInfo, HttpStatus.OK); } + @Log("导出数据") + @ApiOperation("导出数据") + @GetMapping(value = "/yxStoreOrder/download") + @PreAuthorize("@el.check('admin','cate:list')") + public void download(HttpServletResponse response, + YxStoreOrderQueryCriteria criteria, + Pageable pageable, + @RequestParam(name = "orderStatus") String orderStatus, + @RequestParam(name = "orderType") String orderType, + @RequestParam(name = "listContent") String listContent) throws IOException, ParseException { + List list = (List)getYxStoreList(criteria, pageable, orderStatus, orderType).get("content"); + List idList = JSONArray.parseArray(listContent).toJavaList(String.class); + List yxStoreOrderDTOS = new ArrayList<>(); + if(StringUtils.isEmpty(listContent)){ + yxStoreOrderService.download(list, response); + }else { + for(YxStoreOrderDTO yx : list){ + for(String ids : idList){ + if(yx.getOrderId().equals(ids)){ + yxStoreOrderDTOS.add(yx); + } + } + } + yxStoreOrderService.download(yxStoreOrderDTOS, response); + } + } + + public Map getYxStoreList(YxStoreOrderQueryCriteria criteria, + Pageable pageable, + String orderStatus, + String orderType){ + criteria.setShippingType(1);//默认查询所有快递订单 + //订单状态查询 + if (StrUtil.isNotEmpty(orderStatus)) { + switch (orderStatus) { + case "0": + criteria.setIsDel(0); + criteria.setPaid(0); + criteria.setStatus(0); + criteria.setRefundStatus(0); + break; + case "1": + criteria.setIsDel(0); + criteria.setPaid(1); + criteria.setStatus(0); + criteria.setRefundStatus(0); + break; + case "2": + criteria.setIsDel(0); + criteria.setPaid(1); + criteria.setStatus(1); + criteria.setRefundStatus(0); + break; + case "3": + criteria.setIsDel(0); + criteria.setPaid(1); + criteria.setStatus(2); + criteria.setRefundStatus(0); + break; + case "4": + criteria.setIsDel(0); + criteria.setPaid(1); + criteria.setStatus(3); + criteria.setRefundStatus(0); + break; + case "-1": + criteria.setIsDel(0); + criteria.setPaid(1); + criteria.setRefundStatus(1); + break; + case "-2": + criteria.setIsDel(0); + criteria.setPaid(1); + criteria.setRefundStatus(2); + break; + case "-4": + criteria.setIsDel(1); + break; + } + } + //订单类型查询 + if (StrUtil.isNotEmpty(orderType)) { + switch (orderType) { + case "1": + criteria.setBargainId(0); + criteria.setCombinationId(0); + criteria.setSeckillId(0); + break; + case "2": + criteria.setNewCombinationId(0); + break; + case "3": + criteria.setNewSeckillId(0); + break; + case "4": + criteria.setNewBargainId(0); + break; + case "5": + criteria.setShippingType(2); + break; + } + } + return yxStoreOrderService.queryAll(criteria, pageable); + } + + } \ No newline at end of file diff --git a/yshop-shop/src/main/java/co/yixiang/modules/shop/service/YxStoreOrderService.java b/yshop-shop/src/main/java/co/yixiang/modules/shop/service/YxStoreOrderService.java index 1262432a..a0c9d65d 100644 --- a/yshop-shop/src/main/java/co/yixiang/modules/shop/service/YxStoreOrderService.java +++ b/yshop-shop/src/main/java/co/yixiang/modules/shop/service/YxStoreOrderService.java @@ -6,7 +6,10 @@ import co.yixiang.modules.shop.service.dto.OrderTimeDataDTO; import co.yixiang.modules.shop.service.dto.YxStoreOrderDTO; import co.yixiang.modules.shop.service.dto.YxStoreOrderQueryCriteria; import org.springframework.data.domain.Pageable; +import java.text.ParseException; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.util.List; import java.util.Map; @@ -27,6 +30,9 @@ public interface YxStoreOrderService { void refund(YxStoreOrder resources); + void download(List queryAll, HttpServletResponse response) throws IOException, ParseException; + + /** * 查询数据分页 * @param criteria diff --git a/yshop-shop/src/main/java/co/yixiang/modules/shop/service/dto/YxStoreOrderQueryCriteria.java b/yshop-shop/src/main/java/co/yixiang/modules/shop/service/dto/YxStoreOrderQueryCriteria.java index 751087e1..00e02bf4 100644 --- a/yshop-shop/src/main/java/co/yixiang/modules/shop/service/dto/YxStoreOrderQueryCriteria.java +++ b/yshop-shop/src/main/java/co/yixiang/modules/shop/service/dto/YxStoreOrderQueryCriteria.java @@ -3,6 +3,8 @@ package co.yixiang.modules.shop.service.dto; import co.yixiang.annotation.Query; import lombok.Data; +import java.util.List; + /** * @author hupeng * @date 2019-10-14 @@ -10,6 +12,11 @@ import lombok.Data; @Data public class YxStoreOrderQueryCriteria{ + // 模糊 + @Query(type = Query.Type.UNIX_TIMESTAMP) + private List addTime; + + // 模糊 @Query(type = Query.Type.INNER_LIKE) private String orderId; diff --git a/yshop-shop/src/main/java/co/yixiang/modules/shop/service/impl/YxStoreOrderServiceImpl.java b/yshop-shop/src/main/java/co/yixiang/modules/shop/service/impl/YxStoreOrderServiceImpl.java index 382fe7d3..78999a8e 100644 --- a/yshop-shop/src/main/java/co/yixiang/modules/shop/service/impl/YxStoreOrderServiceImpl.java +++ b/yshop-shop/src/main/java/co/yixiang/modules/shop/service/impl/YxStoreOrderServiceImpl.java @@ -19,6 +19,7 @@ import co.yixiang.modules.shop.service.dto.*; import co.yixiang.modules.shop.service.mapper.YxStoreOrderMapper; import co.yixiang.mp.service.YxMiniPayService; import co.yixiang.mp.service.YxPayService; +import co.yixiang.utils.FileUtil; import co.yixiang.utils.OrderUtil; import co.yixiang.utils.QueryHelp; import co.yixiang.utils.ValidationUtil; @@ -31,7 +32,10 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.math.BigDecimal; +import java.text.ParseException; import java.util.*; /** @@ -356,4 +360,50 @@ public class YxStoreOrderServiceImpl implements YxStoreOrderService { public void delete(Integer id) { yxStoreOrderRepository.deleteById(id); } + + + @Override + public void download(List queryAll, HttpServletResponse response) throws IOException, ParseException { + List> list = new ArrayList<>(); + + for (YxStoreOrderDTO storeOrderDTO : queryAll) { + List storeList = new ArrayList(); + storeList = storeOrderDTO.getCartInfoList(); + if(storeList != null){ + for(StoreOrderCartInfoDTO storeOrderCartInfoDTO : storeList){ + Map map = new LinkedHashMap<>(); + map.put("订单号", storeOrderDTO.getOrderId()); + map.put("下单时间", OrderUtil.stampToDate(storeOrderDTO.getAddTime()+"")); + map.put("订单状态", storeOrderDTO.getStatusName()); + map.put("支付状态", storeOrderDTO.getPayTypeName()); + map.put("配送费用", storeOrderDTO.getFreightPrice()); + map.put("实际支付", storeOrderDTO.getPayPrice()); + + map.put("客户编号", storeOrderDTO.getUserDTO().getAccount()); + map.put("客户名称", storeOrderDTO.getUserDTO().getNickname()); + map.put("客户类型", storeOrderDTO.getUserDTO().getUserType()); + map.put("客户手机号码", storeOrderDTO.getUserDTO().getPhone()); + map.put("是否为推广员", storeOrderDTO.getUserDTO().getIsPromoter()); + + map.put("收货人", storeOrderDTO.getRealName()); + map.put("联系电话", storeOrderDTO.getUserPhone()); + map.put("收货地址", storeOrderDTO.getUserAddress()); + + Map proInfo = ((Map)storeOrderCartInfoDTO.getCartInfoMap().get("productInfo")); + map.put("商品编号", proInfo.get("id")); + map.put("商品名称", proInfo.get("store_name")); + map.put("商品规格", proInfo.get("unit_name")); + map.put("商品库存", proInfo.get("stock")); + map.put("单价", proInfo.get("price")); + map.put("订购数量", storeOrderDTO.getTotalNum()); + map.put("小计", storeOrderDTO.getTotalPrice()); + map.put("订单备注", storeOrderDTO.getMark()); + + list.add(map); + } + } + } + FileUtil.downloadExcel(list, response); + } + } \ No newline at end of file