zhangxin 3 недель назад
Родитель
Сommit
493e7c9a37

+ 10 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/model/PointsRecharge.java

@@ -1,5 +1,6 @@
 package com.yami.shop.bean.model;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
@@ -9,6 +10,7 @@ import java.io.Serializable;
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.util.Date;
+import java.util.List;
 
 /**
  * 积分充值实体类
@@ -103,4 +105,12 @@ public class PointsRecharge implements Serializable {
      * 备注
      */
     private String remark;
+
+    /**
+     * 额外字段 用于查询条件
+     * 企业ID列表
+     */
+    @TableField(exist = false)
+    private List<Long> channelIdList;
+
 }

+ 13 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/po/EnterpriseUserPo.java

@@ -5,6 +5,8 @@ import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
+import java.util.List;
+
 @Data
 @NoArgsConstructor
 @AllArgsConstructor
@@ -16,4 +18,15 @@ public class EnterpriseUserPo {
 
     private String userMobile;
 
+    /**
+     * 企业ID列表
+     */
+    private List<Long> channelIdList;
+
+
+    public EnterpriseUserPo(Long channelId, String realName, String userMobile) {
+        this.channelId = channelId;
+        this.realName = realName;
+        this.userMobile = userMobile;
+    }
 }

+ 3 - 3
yami-shop-platform/src/main/java/com/yami/shop/platform/controller/OrderRefundController.java

@@ -140,9 +140,9 @@ public class OrderRefundController {
     @GetMapping("/export")
     @ApiOperation("后管端-快递订单列表导出")
     public void export(OrderRefundStaisticsParam orderRefund, HttpServletResponse response) {
-//        if (orderRefund.getChannelIdList()==null||orderRefund.getChannelIdList().isEmpty()){
-//            throw new GlobalException("请求参数-所属企业不允许为空");
-//        }
+        if (orderRefund.getChannelIdList()==null||orderRefund.getChannelIdList().isEmpty()){
+            throw new GlobalException("请求参数-所属企业不允许为空");
+        }
         orderRefundService.export(orderRefund,response);
     }
 

+ 20 - 1
yami-shop-platform/src/main/java/com/yami/shop/platform/controller/PointsRechargeController.java

@@ -6,7 +6,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.yami.shop.bean.model.PointsRecharge;
+import com.yami.shop.bean.po.EnterpriseUserPo;
 import com.yami.shop.bean.vo.PointsRechargeVO;
+import com.yami.shop.common.exception.GlobalException;
 import com.yami.shop.common.util.PageParam;
 import com.yami.shop.common.util.R;
 import com.yami.shop.security.platform.model.YamiSysUser;
@@ -44,8 +46,11 @@ public class PointsRechargeController {
      */
     @GetMapping("/page")
     public R<IPage<PointsRecharge>> page(PageParam<PointsRecharge> pageParam, PointsRecharge pointsRecharge) {
+        if (pointsRecharge==null||pointsRecharge.getChannelIdList()==null||pointsRecharge.getChannelIdList().isEmpty()){
+            return R.FAIL("请求参数-所属企业不允许为空");
+        }
         IPage<PointsRecharge> page = pointsRechargeService.page(pageParam,new LambdaQueryWrapper<PointsRecharge>()
-                .eq(ObjectUtils.isNotEmpty(pointsRecharge.getChannelId()),PointsRecharge::getChannelId,pointsRecharge.getChannelId())
+                .in(PointsRecharge::getChannelId,pointsRecharge.getChannelIdList())
                 .eq(ObjectUtils.isNotEmpty(pointsRecharge.getUserPhone()),PointsRecharge::getUserPhone,pointsRecharge.getUserPhone())
                 .orderByDesc(PointsRecharge::getCreateTime)
         );
@@ -129,5 +134,19 @@ public class PointsRechargeController {
             return R.FAIL("导入失败:" + e.getMessage());
         }
     }
+    /**
+     * 导出积分
+     * @param pointsRecharge
+     * @param response
+     */
+    @GetMapping("/export")
+    @ApiOperation("后管端-用户列表导出")
+    public void export(PointsRecharge pointsRecharge, HttpServletResponse response) {
+        if (pointsRecharge.getChannelIdList()==null||pointsRecharge.getChannelIdList().isEmpty()){
+            throw new GlobalException("请求参数-所属企业不允许为空");
+        }
+        pointsRechargeService.export(pointsRecharge,response);
+    }
+
 
 }

+ 20 - 0
yami-shop-platform/src/main/java/com/yami/shop/platform/controller/UserEnterpriseController.java

@@ -2,9 +2,11 @@ package com.yami.shop.platform.controller;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.yami.shop.bean.model.User;
+import com.yami.shop.bean.param.OrderRefundStaisticsParam;
 import com.yami.shop.bean.po.EnterpriseUserLogPo;
 import com.yami.shop.bean.po.EnterpriseUserPo;
 import com.yami.shop.bean.vo.EnterpriseUserVo;
+import com.yami.shop.common.exception.GlobalException;
 import com.yami.shop.common.util.PageParam;
 import com.yami.shop.common.util.R;
 import com.yami.shop.security.platform.util.SecurityUtils;
@@ -58,6 +60,9 @@ public class UserEnterpriseController {
     @ApiOperation("员工列表")
     @GetMapping("/enterpriseUserList")
     public R<IPage<EnterpriseUserVo>> enterpriseUserList(EnterpriseUserPo po, PageParam<EnterpriseUserPo> page) {
+        if (po.getChannelIdList()==null||po.getChannelIdList().isEmpty()){
+            throw new GlobalException("请求参数-所属企业不允许为空");
+        }
         IPage<EnterpriseUserVo> userPage =  userService.enterpriseUserList(page,po);
         return R.SUCCESS(userPage);
     }
@@ -101,4 +106,19 @@ public class UserEnterpriseController {
         userService.updateById(updateUser);
         return R.SUCCESS();
     }
+
+
+    /**
+     * 导出
+     * @param po
+     * @param response
+     */
+    @GetMapping("/export")
+    @ApiOperation("后管端-用户列表导出")
+    public void export(EnterpriseUserPo po, HttpServletResponse response) {
+        if (po.getChannelIdList()==null||po.getChannelIdList().isEmpty()){
+            throw new GlobalException("请求参数-所属企业不允许为空");
+        }
+        userService.export(po,response);
+    }
 }

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

@@ -50,4 +50,5 @@ public interface UserMapper extends BaseMapper<User> {
 
     List<EnterpriseUserLogPo> enterpriseUserLogErrList(String batchNo);
 
+    List<EnterpriseUserVo> exportList( @Param("po")EnterpriseUserPo po);
 }

+ 2 - 0
yami-shop-service/src/main/java/com/yami/shop/service/PointsRechargeService.java

@@ -42,4 +42,6 @@ public interface PointsRechargeService extends IService<PointsRecharge> {
      * @return 积分充值统计列表
      */
     IPage<PointsRechargeVO> statisticsList(PointsRecharge pointsRecharge);
+
+    void export(PointsRecharge pointsRecharge, HttpServletResponse response);
 }

+ 2 - 0
yami-shop-service/src/main/java/com/yami/shop/service/UserService.java

@@ -62,4 +62,6 @@ public interface UserService extends IService<User> {
     IPage<User> userList(PageParam<User> page, User user);
 
     void downloadErrorExcel(HttpServletResponse response, String batchNo);
+
+    void export(EnterpriseUserPo po, HttpServletResponse response);
 }

+ 131 - 0
yami-shop-service/src/main/java/com/yami/shop/service/impl/PointsRechargeServiceImpl.java

@@ -7,6 +7,8 @@ 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.*;
+import com.yami.shop.bean.po.EnterpriseUserPo;
+import com.yami.shop.bean.vo.EnterpriseUserVo;
 import com.yami.shop.bean.vo.PointsRechargeVO;
 import com.yami.shop.common.exception.GlobalException;
 import com.yami.shop.common.util.CommonUtils;
@@ -15,8 +17,15 @@ import com.yami.shop.dao.*;
 import com.yami.shop.service.PointsFailureRecordService;
 import com.yami.shop.service.PointsRechargeService;
 import com.yami.shop.service.PointsRecordService;
+import com.yami.shop.utils.ExportUtils;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -212,4 +221,126 @@ public class PointsRechargeServiceImpl extends ServiceImpl<PointsRechargeMapper,
 
         return  page;
     }
+
+    /**
+     * 导出积分
+     * @param pointsRecharge
+     * @param response
+     */
+    @Override
+    public void export(PointsRecharge pointsRecharge, HttpServletResponse response) {
+        List<PointsRecharge> enterpriseUserVos= pointsRechargeMapper.selectList(new LambdaQueryWrapper<PointsRecharge>()
+                .in(PointsRecharge::getChannelId,pointsRecharge.getChannelIdList())
+                .eq(ObjectUtils.isNotEmpty(pointsRecharge.getUserPhone()),PointsRecharge::getUserPhone,pointsRecharge.getUserPhone())
+                .orderByDesc(PointsRecharge::getCreateTime));
+        if (enterpriseUserVos.isEmpty()){
+            throw new GlobalException("该次导出未查询到数据,不允许导出");
+        }
+        exportNormalOrders(enterpriseUserVos,response,"积分列表");
+    }
+    /**
+     * 导出正常订单数据到Excel(直接输出到HttpServletResponse)
+     */
+    public void exportNormalOrders(List<PointsRecharge> orderList,
+                                   HttpServletResponse response,
+                                   String fileName) {
+        // 设置响应头
+        ExportUtils.setupResponse(response, fileName);
+
+        try (Workbook workbook = new XSSFWorkbook()) {
+            // 创建Sheet
+            Sheet sheet = workbook.createSheet("积分列表");
+
+            // 设置列宽
+            setupColumnWidth(sheet);
+
+            // 创建表头样式
+            CellStyle headerStyle = ExportUtils.createHeaderStyle(workbook);
+
+            // 创建数据样式
+            CellStyle dataStyle = ExportUtils.createDataStyle(workbook);
+            CellStyle numberStyle = ExportUtils.createNumberStyle(workbook);
+            CellStyle dateStyle = ExportUtils.createDateStyle(workbook);
+
+
+            String[] headers = {
+                    "序号","所属企业", "员工姓名", "员工手机号", "充值积分", "过期时间",
+                    "创建时间"
+            };
+            // 创建合并单元格的表头
+            ExportUtils.createMergedHeader(sheet, headerStyle,"积分列表");
+
+            // 创建列标题行
+            ExportUtils.createColumnHeaders(sheet, headerStyle,headers);
+
+            // 填充数据
+            fillOrderData(sheet, orderList, dataStyle, numberStyle, dateStyle);
+
+            // 写入响应流
+            workbook.write(response.getOutputStream());
+            response.getOutputStream().flush();
+
+            log.info("订单导出成功,文件:{},记录数:{}", fileName, orderList.size());
+
+        } catch (Exception e) {
+            log.error("订单导出失败", e);
+            throw new RuntimeException("导出失败:" + e.getMessage());
+        }
+    }
+
+    /**
+     * 设置列宽
+     */
+    private void setupColumnWidth(Sheet sheet) {
+        // 根据模板设置列宽(单位:1/256字符宽度)
+        sheet.setColumnWidth(0, 12 * 256);   // 序号
+        sheet.setColumnWidth(1, 12 * 256);   // 所属企业
+        sheet.setColumnWidth(2, 18 * 256);   // 员工姓名
+        sheet.setColumnWidth(3, 18 * 256);   // 员工手机号
+        sheet.setColumnWidth(4, 10 * 256);   // 充值积分
+        sheet.setColumnWidth(5, 8 * 256);    // 过期时间
+        sheet.setColumnWidth(6, 25 * 256);   // 创建时间
+    }
+
+    /**
+     * 填充订单数据
+     */
+    private void fillOrderData(Sheet sheet, List<PointsRecharge> orderList,
+                               CellStyle dataStyle, CellStyle numberStyle, CellStyle dateStyle) {
+        int rowNum = 2; // 从第3行开始(0-based索引)
+        int indexNum= 1; //序号
+        for (PointsRecharge enterpriseUserVo : orderList) {
+            Row row = sheet.createRow(rowNum++);
+            row.setHeightInPoints(18);
+            // 序号
+            ExportUtils.createCell(sheet,row, 0,0,0, indexNum, dataStyle);
+            fillOrderRowData(sheet,row, enterpriseUserVo, dataStyle, numberStyle, dateStyle);
+            indexNum++;
+        }
+
+    }
+
+    /**
+     * 填充单行订单数据
+     */
+    private void fillOrderRowData(Sheet sheet,Row row, PointsRecharge orderRefundVo,
+                                  CellStyle dataStyle, CellStyle numberStyle, CellStyle dateStyle) {
+        // 所属企业
+        ExportUtils.createCell(sheet,row, 1,0,0, orderRefundVo.getChannelName(), dataStyle);
+
+        // 员工姓名
+        ExportUtils.createCell(sheet,row, 2,0,0,  orderRefundVo.getUserName(), dateStyle);
+
+        // 员工手机号
+        ExportUtils.createCell(sheet,row, 3,0,0, orderRefundVo.getUserPhone(), dateStyle);
+
+        // 充值积分
+        ExportUtils.createCell(sheet,row, 4,0,0,orderRefundVo.getPoints(), numberStyle);
+
+        // 过期时间
+        ExportUtils.createCell(sheet,row, 5,0,0, ExportUtils.formatDate(orderRefundVo.getCreateTime()), dateStyle);
+        // 创建时间
+        ExportUtils.createCell(sheet,row, 6,0,0, ExportUtils.formatDate(orderRefundVo.getExpiryDate()), dateStyle);
+
+    }
 }

+ 53 - 3
yami-shop-service/src/main/resources/mapper/UserMapper.xml

@@ -136,9 +136,12 @@
         SUM(CASE WHEN points_type = 3 THEN points ELSE 0 END))  from tz_points_record 	where user_id =  a.user_id  and channel_id = a.channel_id),0) used -- 已消耗积分
         FROM tz_user a
         <where>
-            a.channel_id in(SELECT id FROM tz_channel)
-            <if test="po.channelId != null">
-                AND a.channel_id = #{po.channelId}
+            a.channel_id in (SELECT id FROM tz_channel)
+            <if test="po.channelIdList != null and po.channelIdList != ''">
+                and a.channel_id  in
+                <foreach collection="po.channelIdList" item="channelId" open="(" close=")" separator=",">
+                    #{channelId}
+                </foreach>
             </if>
             <if test="po.realName != null and po.realName != ''">
                 AND a.real_name LIKE CONCAT("%",#{po.realName},"%")
@@ -193,6 +196,53 @@
           and `status` = 0
         ORDER BY create_time
     </select>
+    <select id="exportList" resultType="com.yami.shop.bean.vo.EnterpriseUserVo">
+        SELECT a.user_id,a.`status`,a.real_name,a.user_mobile,a.channel_id,
+               (SELECT channel_name FROM tz_channel WHERE id= a.channel_id) channelName,
+               IFNULL((SELECT SUM(points) FROM tz_points_recharge WHERE user_id=a.user_id),0) total, -- 总积分
+
+               IFNULL(( select (
+                                       SUM(CASE WHEN points_type = 1 OR points_type = 3 THEN points ELSE 0 END) -- 充值和退款的总积分
+                                       -
+                                       GREATEST(
+                                               SUM( CASE WHEN expiry_date &lt;= NOW() THEN
+                                                             CASE WHEN points_type = 1 OR points_type = 3 THEN points
+                                                                  WHEN points_type = 2 THEN -variable_points
+                                                                  ELSE 0 END
+                                                         ELSE 0 END ), 0) -- 所以情况的过期积分
+                                       -
+                                       SUM(CASE WHEN points_type = 2 THEN variable_points ELSE 0 END) -- 下单的所有积分  未使用 -过期的 = 可用的
+                                   )  from tz_points_record where user_id =  a.user_id  and channel_id = a.channel_id ),0) available, -- 当前可用积分
+
+               IFNULL(( select  GREATEST(
+                                        SUM(
+                                                CASE WHEN expiry_date &lt;= NOW() THEN
+                                                         CASE  WHEN points_type = 1 OR points_type = 3 THEN points
+                                                               WHEN points_type = 2 THEN -variable_points
+                                                               ELSE 0 END
+                                                     ELSE 0 END ), 0 ) from tz_points_record where user_id =  a.user_id  and channel_id = a.channel_id),0) expired, -- 已过期积分
+
+               IFNULL((select  (
+                                       SUM(CASE WHEN points_type = 2 THEN variable_points ELSE 0 END)
+                                       -
+                                       SUM(CASE WHEN points_type = 3 THEN points ELSE 0 END))  from tz_points_record 	where user_id =  a.user_id  and channel_id = a.channel_id),0) used -- 已消耗积分
+        FROM tz_user a
+        <where>
+            a.channel_id in (SELECT id FROM tz_channel)
+            <if test="po.channelIdList != null and po.channelIdList != ''">
+                and a.channel_id  in
+                <foreach collection="po.channelIdList" item="channelId" open="(" close=")" separator=",">
+                    #{channelId}
+                </foreach>
+            </if>
+            <if test="po.realName != null and po.realName != ''">
+                AND a.real_name LIKE CONCAT("%",#{po.realName},"%")
+            </if>
+            <if test="po.userMobile != null and po.userMobile != ''">
+                AND a.user_mobile LIKE CONCAT("%",#{po.userMobile},"%")
+            </if>
+        </where>
+    </select>
 
 
 </mapper>