wangming hai 2 días
pai
achega
4162de9305

+ 10 - 2
yami-shop-bean/src/main/java/com/yami/shop/bean/vo/PointsRecordVo.java

@@ -1,6 +1,7 @@
 
 package com.yami.shop.bean.vo;
 
+import com.alibaba.excel.annotation.ExcelProperty;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.AllArgsConstructor;
@@ -15,27 +16,34 @@ import java.time.LocalDateTime;
 @AllArgsConstructor
 public class PointsRecordVo {
 
-    @ApiModelProperty("流水号")
-    private String code;
+    @ApiModelProperty("订单编号")
+    @ExcelProperty("订单编号")
+    private String orderNumber;
 
     @ApiModelProperty("姓名")
+    @ExcelProperty("姓名")
     private String realName;
 
     @ApiModelProperty("手机号")
+    @ExcelProperty("手机号")
     private String mobile;
 
     @ApiModelProperty("变动积分")
+    @ExcelProperty("变动积分")
     private String variablePoints;
 
     @ApiModelProperty("变动后积分")
+    @ExcelProperty("变动后积分")
     private String currentlyAvailablePoints;
 
     @ApiModelProperty("创建时间")
+    @ExcelProperty("创建时间")
     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private LocalDateTime creationDate;
 
     @ApiModelProperty("业务类型 CZ-充值 XD-下单 TK-退款 GQ-过期")
+    @ExcelProperty("业务类型")
     private String businessType;
 
 }

+ 9 - 0
yami-shop-platform/src/main/java/com/yami/shop/platform/controller/PointsRecordController.java

@@ -14,6 +14,7 @@ import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
 import java.util.Arrays;
 
@@ -82,4 +83,12 @@ public class PointsRecordController {
         return R.SUCCESS(pointsRecordService.backendPointsRecordList(po));
     }
 
+    @GetMapping("/backendPointsRecordListExport")
+    @ApiOperation("后台-积分使用记录-导出")
+    public R<?> backendPointsRecordListExport(HttpServletResponse response, PointsRecordPo po) {
+        pointsRecordService.backendPointsRecordListExport(response,po);
+        return R.SUCCESS();
+    }
+
+
 }

+ 2 - 2
yami-shop-service/pom.xml

@@ -13,8 +13,8 @@
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <configuration>
-                    <source>9</source>
-                    <target>9</target>
+                    <source>10</source>
+                    <target>10</target>
                 </configuration>
             </plugin>
         </plugins>

+ 1 - 0
yami-shop-service/src/main/java/com/yami/shop/dao/PointsRecordMapper.java

@@ -31,4 +31,5 @@ public interface PointsRecordMapper extends BaseMapper<PointsRecord> {
     List<PointsRecord> findByExpiredPoints(@Param("today")Date today,@Param("yesterday") Date yesterday);
 
     IPage<PointsRecordVo> backendPointsRecordList(@Param("page") Page<PointsRecordVo> page, @Param("po") PointsRecordPo po);
+    List<PointsRecordVo> backendPointsRecordList2(@Param("po") PointsRecordPo po);
 }

+ 4 - 0
yami-shop-service/src/main/java/com/yami/shop/service/PointsRecordService.java

@@ -7,6 +7,8 @@ import com.yami.shop.bean.model.PointsRecord;
 import com.yami.shop.bean.po.PointsRecordPo;
 import com.yami.shop.bean.vo.PointsRecordVo;
 
+import javax.servlet.http.HttpServletResponse;
+
 /**
  * 积分记录详细 Service接口
  *
@@ -18,4 +20,6 @@ public interface PointsRecordService extends IService<PointsRecord> {
     void expiredPoints(String todayStr,String yesterdayStr);
 
     IPage<PointsRecordVo> backendPointsRecordList(PointsRecordPo po);
+
+    void backendPointsRecordListExport(HttpServletResponse response, PointsRecordPo po);
 }

+ 22 - 0
yami-shop-service/src/main/java/com/yami/shop/service/impl/PointsRecordServiceImpl.java

@@ -1,18 +1,25 @@
 package com.yami.shop.service.impl;
 
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.yami.shop.bean.model.PointsRecord;
 import com.yami.shop.bean.po.PointsRecordPo;
 import com.yami.shop.bean.vo.PointsRecordVo;
+import com.yami.shop.common.exception.GlobalException;
 import com.yami.shop.dao.PointsRecordMapper;
 import com.yami.shop.service.PointsRecordService;
 import lombok.AllArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.math.BigDecimal;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
@@ -69,6 +76,21 @@ public class PointsRecordServiceImpl extends ServiceImpl<PointsRecordMapper, Poi
         return baseMapper.backendPointsRecordList(new Page<>(po.getCurrent(), po.getSize()), po);
     }
 
+    @Override
+    public void backendPointsRecordListExport(HttpServletResponse response, PointsRecordPo po) {
+        try {
+            List<PointsRecordVo> list = baseMapper.backendPointsRecordList2(po);
+            response.setCharacterEncoding("utf-8");
+            String fileName = URLEncoder.encode("积分使用记录表", StandardCharsets.UTF_8).replaceAll("\\+", "%20");
+            response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
+            EasyExcel.write(response.getOutputStream(), PointsRecordVo.class)
+                    .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
+                    .sheet("列表").doWrite(list);
+        } catch (IOException e) {
+            throw new GlobalException("文件下载异常");
+        }
+    }
+
     /**
      * @param dateStr string类型的时间
      * @param type    标识是否为当天

+ 42 - 1
yami-shop-service/src/main/resources/mapper/PointsRecordMapper.xml

@@ -112,7 +112,7 @@
                          ) a where a.points>0
     </select>
     <select id="backendPointsRecordList" resultType="com.yami.shop.bean.vo.PointsRecordVo">
-        SELECT a.`code`, b.real_name,b.user_mobile mobile ,IF(a.points_type in(1,3),CONCAT('+',a.variable_points),CONCAT('-',a.variable_points)) variable_points,a.currently_available_points,a.creation_date,
+        SELECT c.order_number, b.real_name,b.user_mobile mobile ,IF(a.points_type in(1,3),CONCAT('+',a.variable_points),CONCAT('-',a.variable_points)) variable_points,a.currently_available_points,a.creation_date,
                CASE
                    WHEN a.points_type = 1 THEN '充值'
                    WHEN a.points_type = 2 THEN '下单'
@@ -122,6 +122,47 @@
                    END AS business_type
         FROM `tz_points_record` a
                  LEFT JOIN tz_user b on a.user_id=b.user_id
+                 LEFT JOIN tz_order c on a.order_number=c.order_number
+        <where>
+            <if test="po.mobile != null and po.mobile != ''">
+                AND b.user_mobile LIKE CONCAT("%",#{po.mobile},"%")
+            </if>
+            <if test="po.startTime != null and po.startTime != ''">
+                and a.creation_date&gt;= #{po.startTime}
+            </if>
+            <if test="po.endTime != null and po.endTime != ''">
+                and a.creation_date&lt;= #{po.endTime}
+            </if>
+            <if test="po.businessType != null and po.businessType != ''">
+                <if test="po.businessType == 'CZ'">
+                    AND a.points_type = 1
+                </if>
+                <if test="po.businessType == 'XD'">
+                    AND a.points_type = 2
+                </if>
+                <if test="po.businessType == 'TK'">
+                    AND a.points_type = 3
+                </if>
+                <if test="po.businessType == 'GQ'">
+                    AND a.points_type = 4
+                </if>
+            </if>
+        </where>
+        order by a.creation_date desc
+    </select>
+
+    <select id="backendPointsRecordList2" resultType="com.yami.shop.bean.vo.PointsRecordVo">
+        SELECT c.order_number, b.real_name,b.user_mobile mobile ,IF(a.points_type in(1,3),CONCAT('+',a.variable_points),CONCAT('-',a.variable_points)) variable_points,a.currently_available_points,a.creation_date,
+        CASE
+        WHEN a.points_type = 1 THEN '充值'
+        WHEN a.points_type = 2 THEN '下单'
+        WHEN a.points_type = 3 THEN '退款'
+        WHEN a.points_type = 4 THEN '过期'
+        ELSE '其他'
+        END AS business_type
+        FROM `tz_points_record` a
+        LEFT JOIN tz_user b on a.user_id=b.user_id
+        LEFT JOIN tz_order c on a.order_number=c.order_number
         <where>
             <if test="po.mobile != null and po.mobile != ''">
                 AND b.user_mobile LIKE CONCAT("%",#{po.mobile},"%")