renqianlong 1 年之前
父節點
當前提交
7a499af990

+ 221 - 46
zhongzheng-system/src/main/java/com/zhongzheng/modules/order/service/impl/OrderInputServiceImpl.java

@@ -1,10 +1,15 @@
 package com.zhongzheng.modules.order.service.impl;
 
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
+import cn.afterturn.easypoi.excel.entity.ExportParams;
+import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.lang.Validator;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.zhongzheng.common.config.RuoYiConfig;
+import com.zhongzheng.common.core.domain.AjaxResult;
 import com.zhongzheng.common.exception.CustomException;
 import com.zhongzheng.common.utils.DateUtils;
 import com.zhongzheng.common.utils.poi.ExcelUtil;
@@ -34,6 +39,7 @@ import com.zhongzheng.modules.user.domain.User;
 import com.zhongzheng.modules.user.domain.UserSubscribe;
 import com.zhongzheng.modules.user.service.IUserService;
 import com.zhongzheng.modules.user.service.IUserSubscribeService;
+import org.apache.poi.ss.usermodel.Workbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -41,6 +47,11 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.github.pagehelper.Page;
 
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -74,14 +85,14 @@ public class OrderInputServiceImpl extends ServiceImpl<OrderInputMapper, OrderIn
 
 
     @Override
-    public OrderInputVo queryById(Long id){
+    public OrderInputVo queryById(Long id) {
         OrderInput db = this.baseMapper.selectById(id);
         return BeanUtil.toBean(db, OrderInputVo.class);
     }
 
     @Override
     public OrderInput queryBySn(String inputOrderSn) {
-        return getOne(new LambdaQueryWrapper<OrderInput>().eq(OrderInput::getInputOrderSn,inputOrderSn));
+        return getOne(new LambdaQueryWrapper<OrderInput>().eq(OrderInput::getInputOrderSn, inputOrderSn));
     }
 
     @Override
@@ -108,19 +119,19 @@ public class OrderInputServiceImpl extends ServiceImpl<OrderInputMapper, OrderIn
     }
 
     /**
-    * 实体类转化成视图对象
-    *
-    * @param collection 实体类集合
-    * @return
-    */
+     * 实体类转化成视图对象
+     *
+     * @param collection 实体类集合
+     * @return
+     */
     private List<OrderInputVo> entity2Vo(Collection<OrderInput> collection) {
         List<OrderInputVo> voList = collection.stream()
                 .map(any -> BeanUtil.toBean(any, OrderInputVo.class))
                 .collect(Collectors.toList());
         if (collection instanceof Page) {
-            Page<OrderInput> page = (Page<OrderInput>)collection;
+            Page<OrderInput> page = (Page<OrderInput>) collection;
             Page<OrderInputVo> pageVo = new Page<>();
-            BeanUtil.copyProperties(page,pageVo);
+            BeanUtil.copyProperties(page, pageVo);
             pageVo.addAll(voList);
             voList = pageVo;
         }
@@ -134,7 +145,7 @@ public class OrderInputServiceImpl extends ServiceImpl<OrderInputMapper, OrderIn
         validEntityBeforeSave(add);
         add.setCreateTime(DateUtils.getNowTime());
         add.setUpdateTime(DateUtils.getNowTime());
-        if(Validator.isEmpty(add.getInputFrom())){
+        if (Validator.isEmpty(add.getInputFrom())) {
             add.setInputFrom(1);
         }
         this.save(add);
@@ -154,13 +165,13 @@ public class OrderInputServiceImpl extends ServiceImpl<OrderInputMapper, OrderIn
      *
      * @param entity 实体类数据
      */
-    private void validEntityBeforeSave(OrderInput entity){
+    private void validEntityBeforeSave(OrderInput entity) {
         //TODO 做一些数据校验,如唯一约束
     }
 
     @Override
     public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
-        if(isValid){
+        if (isValid) {
             //TODO 做一些业务上的校验,判断是否需要校验
         }
         return this.removeByIds(ids);
@@ -177,18 +188,18 @@ public class OrderInputServiceImpl extends ServiceImpl<OrderInputMapper, OrderIn
     }
 
     @Override
-    public void questionOrderOpen(String orderSn,Long tenantId) {
+    public void questionOrderOpen(String orderSn, Long tenantId) {
         OrderInput orderInput = getOne(new LambdaQueryWrapper<OrderInput>().eq(OrderInput::getInputOrderSn, orderSn));
-        if (ObjectUtils.isNull(orderInput)){
+        if (ObjectUtils.isNull(orderInput)) {
             throw new CustomException("订单信息获取有误");
         }
 
         //创建学员订单
         List<TopOldOrderGoods> orderGoodsList = topOldOrderGoodsService
                 .list(new LambdaQueryWrapper<TopOldOrderGoods>()
-                .eq(TopOldOrderGoods::getOrderSn, orderSn)
-                .eq(TopOldOrderGoods::getStatus, 1));
-        if (CollectionUtils.isEmpty(orderGoodsList)){
+                        .eq(TopOldOrderGoods::getOrderSn, orderSn)
+                        .eq(TopOldOrderGoods::getStatus, 1));
+        if (CollectionUtils.isEmpty(orderGoodsList)) {
             return;
         }
         SysOldOrg oldOrg = iSysOldOrgService.getOne(new LambdaQueryWrapper<SysOldOrg>()
@@ -204,8 +215,8 @@ public class OrderInputServiceImpl extends ServiceImpl<OrderInputMapper, OrderIn
             User user = iUserService.getOne(new LambdaQueryWrapper<User>()
                     .eq(User::getIdCard, orderGoods.getUserCard())
                     .eq(User::getTenantId, tenantId));
-            if (ObjectUtils.isNull(user)){
-                throw new CustomException("学员【"+user.getRealname()+"】信息不存在");
+            if (ObjectUtils.isNull(user)) {
+                throw new CustomException("学员【" + user.getRealname() + "】信息不存在");
             }
             //学员预约信息
             UserSubscribe userSubscribe = iUserSubscribeService.getById(orderGoods.getSignId());
@@ -251,7 +262,7 @@ public class OrderInputServiceImpl extends ServiceImpl<OrderInputMapper, OrderIn
             add.setGoodsReceived(order.getOrderPrice());
             add.setRefundStatus(0);
             add.setPayStatus(3);
-            add = setQuestionServiceTime(add,userSubscribe.getOrderGoodsId(),order);
+            add = setQuestionServiceTime(add, userSubscribe.getOrderGoodsId(), order);
             iOrderGoodsService.save(add);
 
             //题库关联
@@ -273,11 +284,11 @@ public class OrderInputServiceImpl extends ServiceImpl<OrderInputMapper, OrderIn
 
     @Override
     public Map<String, Object> excelImport(List<String> ids) {
-        Map<String,Object> map = new HashMap<>();
+        Map<String, Object> map = new HashMap<>();
         List<OrderInputVo> orderInputVos = new ArrayList<>();
         List<OrderInputImpotVo> orderInputImpotVos = new ArrayList<>();
         List<OrderListImportVo> orderListImportVos = new ArrayList<>();
-        if (ids.size()>50){
+        if (ids.size() > 50) {
             throw new CustomException("超出文档导出上限");
         }
         if (ObjectUtils.isNotEmpty(ids)) {
@@ -288,51 +299,215 @@ public class OrderInputServiceImpl extends ServiceImpl<OrderInputMapper, OrderIn
                 orderInputVos.add(orderInputVo);
                 orderInputVos.forEach(item -> {
                     OrderInputImpotVo bean = BeanUtil.toBean(item, OrderInputImpotVo.class);
+                    if (ObjectUtils.isEmpty(item.getGoodsRealPrice())) {
+                        bean.setGoodsRealPrice(BigDecimal.valueOf(0));
+                    }
+                    if (!ObjectUtils.isEmpty(item.getOrderFrom())){
+                        bean.setInputFrom(getGoodFromName(item.getOrderFrom()));
+                    }
+                    bean.setGoodBusiness(item.getEducationName() + item.getProjectName() + item.getBusinessName());
+                    bean.setGoodsNoReceived(item.getPayPrice().subtract(item.getGoodsReceived()));
                     orderInputImpotVos.add(bean);
                 });
                 OrderQueryBo orderQueryBo = new OrderQueryBo();
                 orderQueryBo.setInputOrderSn(String.valueOf(id));
                 orderQueryBo.setStatus(new Integer[]{1});
                 List<OrderListVo> orderListVo = iOrderService.selectList(orderQueryBo);
-                orderListVo.forEach(orderLIst->{
+                orderListVo.forEach(orderLIst -> {
                     OrderListImportVo bean = BeanUtil.toBean(orderLIst, OrderListImportVo.class);
+                    if (ObjectUtils.isEmpty(orderLIst.getGoodsRealPrice())) {
+                        bean.setGoodsRealPrice(BigDecimal.valueOf(0));
+                    }
+                    bean.setGoodsPayStatus(getGoodsPayStatus(orderLIst.getGoodsPayStatus()));
                     bean.setInputOrderSn(id);
+                    bean.setGoodsBusiness(orderLIst.getEducationName() + orderLIst.getProjectName() + orderLIst.getBusinessName());
+                    bean.setOrderStatus(getOrderStatus(orderLIst.getOrderStatus()));
+                    bean.setRefundStatus(getRefundStatus(orderLIst.getRefundStatus()));
+                    if (!ObjectUtils.isEmpty(orderLIst.getInvoiceStatus())){
+                        bean.setInvoiceStatus(getInvoiceStatus(orderLIst.getInvoiceStatus()));
+                    }
+                    if (!ObjectUtils.isEmpty(orderLIst.getRebuy())){
+                        bean.setRebuy(getRebuyStatus(orderLIst.getRebuy()));
+                    }
+                    bean.setGoodsNotReceived(orderLIst.getPayPrice().subtract(orderLIst.getGoodsReceived()));
                     orderListImportVos.add(bean);
                 });
             });
-        }
-        OrderInputQueryBo orderInputQueryBo = new OrderInputQueryBo();
-        orderInputQueryBo.setStatus(1);
-        List<OrderInputVo> orderInputVos1 = this.selectList(orderInputQueryBo);
-        orderInputVos1=orderInputVos1.stream().limit(50).collect(Collectors.toList());
-        orderInputVos1.forEach(item -> {
-            OrderInputImpotVo bean = BeanUtil.toBean(item, OrderInputImpotVo.class);
-            orderInputImpotVos.add(bean);
-            OrderQueryBo orderQueryBo = new OrderQueryBo();
-            orderQueryBo.setInputOrderSn(String.valueOf(item.getInputOrderSn()));
-            orderQueryBo.setStatus(new Integer[]{1});
-            List<OrderListVo> orderListVo = iOrderService.selectList(orderQueryBo);
-            orderListVo.forEach(orderLIst->{
-                OrderListImportVo importVo = BeanUtil.toBean(orderLIst, OrderListImportVo.class);
-                importVo.setInputOrderSn(item.getInputOrderSn());
-                orderListImportVos.add(importVo);
+        } else {
+            OrderInputQueryBo orderInputQueryBo = new OrderInputQueryBo();
+            orderInputQueryBo.setStatus(1);
+            List<OrderInputVo> orderInputVos1 = this.selectList(orderInputQueryBo);
+            orderInputVos1 = orderInputVos1.stream().limit(50).collect(Collectors.toList());
+            orderInputVos1.forEach(item -> {
+                OrderInputImpotVo bean = BeanUtil.toBean(item, OrderInputImpotVo.class);
+                bean.setInputOrderSn(item.getEducationName() + item.getProjectName() + item.getBusinessName());
+                if (ObjectUtils.isEmpty(item.getGoodsRealPrice())) {
+                    bean.setGoodsRealPrice(BigDecimal.valueOf(0));
+                }
+                if (!ObjectUtils.isEmpty(item.getOrderFrom())){
+                    bean.setInputFrom(getGoodFromName(item.getOrderFrom()));
+                }
+                bean.setGoodsNoReceived(item.getPayPrice().subtract(item.getGoodsReceived()));
+                orderInputImpotVos.add(bean);
+                OrderQueryBo orderQueryBo = new OrderQueryBo();
+                orderQueryBo.setInputOrderSn(String.valueOf(item.getInputOrderSn()));
+                orderQueryBo.setStatus(new Integer[]{1});
+                List<OrderListVo> orderListVo = iOrderService.selectList(orderQueryBo);
+                orderListVo.forEach(orderLIst -> {
+                    OrderListImportVo importVo = BeanUtil.toBean(orderLIst, OrderListImportVo.class);
+                    importVo.setInputOrderSn(item.getInputOrderSn());
+                    importVo.setGoodsPayStatus(getGoodsPayStatus(orderLIst.getGoodsPayStatus()));
+                    importVo.setOrderStatus(getOrderStatus(orderLIst.getOrderStatus()));
+                    importVo.setInputOrderSn(orderLIst.getEducationName() + orderLIst.getProjectName() + orderLIst.getBusinessName());
+                    importVo.setRefundStatus(getRefundStatus(orderLIst.getRefundStatus()));
+                    if (!ObjectUtils.isEmpty(orderLIst.getInvoiceStatus())){
+                        importVo.setInvoiceStatus(getInvoiceStatus(orderLIst.getInvoiceStatus()));
+                    }
+                    importVo.setGoodsNotReceived(orderLIst.getPayPrice().subtract(orderLIst.getGoodsReceived()));
+                    if (!ObjectUtils.isEmpty(orderLIst.getRebuy())){
+                        importVo.setRebuy(getInvoiceStatus(orderLIst.getRebuy()));
+                    }
+                    if (ObjectUtils.isEmpty(orderLIst.getGoodsRealPrice())) {
+                        importVo.setGoodsRealPrice(BigDecimal.valueOf(0));
+                    }
+                    orderListImportVos.add(importVo);
+                });
             });
-        });
-        ExcelUtil<OrderInputImpotVo> inputImpotVoExcelUtil = new ExcelUtil<>(OrderInputImpotVo.class);
-        ExcelUtil<OrderListImportVo> importVoExcelUtil = new ExcelUtil<>(OrderListImportVo.class);
-        map.put("excel",inputImpotVoExcelUtil.exportEasyExcel(inputImpotVoExcelUtil.exportEasyData2(orderInputImpotVos,orderInputImpotVos), "导出后台订单"));
+        }
+        List<Map<String, Object>> sheetsList = new ArrayList<>();
+        ExportParams deptExportParams = new ExportParams();
+        deptExportParams.setSheetName("后台订单");
+        Map<String, Object> deptExportMap = new HashMap<>();
+        deptExportMap.put("title", deptExportParams);
+        deptExportMap.put("entity", OrderInputImpotVo.class);
+        // sheet中要填充得数据
+        deptExportMap.put("data", orderInputImpotVos);
+
+        ExportParams deptExportParams1 = new ExportParams();
+        deptExportParams1.setSheetName("订单详情");
+        Map<String, Object> deptExportMap1 = new HashMap<>();
+        deptExportMap1.put("title", deptExportParams1);
+        deptExportMap1.put("entity", OrderListImportVo.class);
+        // sheet中要填充得数据
+        deptExportMap1.put("data", orderListImportVos);
+        sheetsList.add(deptExportMap);
+        sheetsList.add(deptExportMap1);
+        OutputStream out = null;
+        //     Workbook workbook = null;
+        try {
+            Workbook workbook = ExcelExportUtil.exportExcel(sheetsList, ExcelType.HSSF);
+            String filename = UUID.randomUUID().toString() + "_" + "导出后台订单" + ".xls";
+            String downloadPath = RuoYiConfig.getDownloadPath() + filename;
+            File desc = new File(downloadPath);
+            if (!desc.getParentFile().exists()) {
+                desc.getParentFile().mkdirs();
+            }
+            out = new FileOutputStream(downloadPath);
+            workbook.write(out);
+            workbook.close();
+            return AjaxResult.success(filename);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
         return map;
     }
 
+    private String getGoodFromName(String type) {
+        if (type.equals("1")) {
+            return "业务员普通单";
+        }
+        if (type.equals("2")) {
+            return "祥粤云学堂小程序";
+        }
+        if (type.equals("3")) {
+            return "祥粤云学堂网站";
+        }
+        if (type.equals("4")) {
+            return "祥粤e管证小程序";
+        }
+        if (type.equals("5")) {
+            return "业务员录单";
+        }
+        return null;
+    }
+    private String getGoodsPayStatus(Integer type) {
+        if (type==1) {
+            return "未收费";
+        }
+        if (type==2) {
+            return "部分收费";
+        }
+        if (type==3) {
+            return "完全收费";
+        }
+        if (type==4) {
+            return "免费";
+        }
+        return null;
+    }
+    private String getOrderStatus(Integer type) {
+        if (type==-2) {
+            return "超时关闭";
+        }
+        if (type==-1) {
+            return "手动关闭";
+        }
+        if (type==0) {
+            return "普通状态";
+        }
+        if (type==1) {
+            return "已付款";
+        }
+        if (type==3) {
+            return "成功";
+        }
+        return null;
+    }
+    private String getRefundStatus(Integer type) {
+        if (type==0) {
+            return "无";
+        }
+        if (type==1) {
+            return "退款中";
+        }
+        if (type==2) {
+            return "已退款";
+        }
+        if (type==3) {
+            return "拒绝退款";
+        }
+        return null;
+    }
+    private String getInvoiceStatus(Integer type) {
+        if (type==1) {
+            return "未开票";
+        }
+        if (type==2) {
+            return "已开票";
+        }
+        if (type==-1) {
+            return "已退票";
+        }
+        return null;
+    }
+    private String getRebuyStatus(Integer type) {
+        if (type==0) {
+            return "非复购";
+        }
+        if (type==1) {
+            return "复购";
+        }
+        return null;
+    }
 
-    private OrderGoods setQuestionServiceTime(OrderGoods add,Long orderGoodsId,Order order) {
+    private OrderGoods setQuestionServiceTime(OrderGoods add, Long orderGoodsId, Order order) {
         UserSubscribe subscribe = iUserSubscribeService.getOne(new LambdaQueryWrapper<UserSubscribe>()
                 .eq(UserSubscribe::getUserId, order.getUserId())
                 .eq(UserSubscribe::getOrderGoodsId, orderGoodsId)
                 .eq(UserSubscribe::getSubscribeStatus, 1)
-                .eq(UserSubscribe::getExamStatus,0)
+                .eq(UserSubscribe::getExamStatus, 0)
                 .last("limit 1"));
-        if (ObjectUtils.isNull(subscribe)){
+        if (ObjectUtils.isNull(subscribe)) {
             return add;
         }
         //考试日期

+ 2 - 2
zhongzheng-system/src/main/java/com/zhongzheng/modules/order/vo/OrderListImportVo.java

@@ -104,7 +104,7 @@ public class OrderListImportVo {
      */
     @Excel(name = "支付状态")
     @ApiModelProperty("支付状态")
-    private String payStatus;
+    private String goodsPayStatus;
     /**
      * 订单来源 1业务员录单
      */
@@ -122,7 +122,7 @@ public class OrderListImportVo {
      */
     @Excel(name = "订单状态")
     @ApiModelProperty("订单状态")
-    private String status;
+    private String orderStatus;
     /**
      * 商品名称
      */