vip明细统计、导出
This commit is contained in:
@@ -3,7 +3,15 @@ package com.peanut.modules.common.dao;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.peanut.modules.common.entity.UserVipLog;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface UserVipLogDao extends BaseMapper<UserVipLog> {
|
||||
|
||||
List<Map<String,Object>> getUserVipLogInfoList(@Param("date") String date);
|
||||
|
||||
Map<String,Object> getUserVipLogInfoTotal(@Param("date") String date);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.peanut.modules.common.entity.UserVip;
|
||||
import com.peanut.modules.common.entity.UserVipLog;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface UserVipLogService extends IService<UserVipLog> {
|
||||
@@ -15,4 +16,8 @@ public interface UserVipLogService extends IService<UserVipLog> {
|
||||
|
||||
BigDecimal countDayAmount(UserVipLog userVipLog);
|
||||
|
||||
List<Map<String,Object>> getUserVipLogInfoList(String date);
|
||||
|
||||
Map<String, Object> getUserVipLogInfoTotal(String date);
|
||||
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import com.peanut.modules.common.service.UserVipLogService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@@ -45,7 +45,18 @@ public class UserVipLogServiceImpl extends ServiceImpl<UserVipLogDao, UserVipLog
|
||||
return BigDecimal.ZERO;
|
||||
}else {
|
||||
BigDecimal days = new BigDecimal((userVipLog.getEndTime().getTime()-userVipLog.getStartTime().getTime())/24/60/60/1000);
|
||||
days = days.add(new BigDecimal(1));
|
||||
return userVipLog.getFee().divide(days, 2, BigDecimal.ROUND_HALF_UP);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getUserVipLogInfoList(String date) {
|
||||
return this.baseMapper.getUserVipLogInfoList(date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getUserVipLogInfoTotal(String date) {
|
||||
return this.baseMapper.getUserVipLogInfoTotal(date);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,14 +11,21 @@ import com.peanut.modules.common.service.JfTransactionDetailsService;
|
||||
import com.peanut.modules.common.service.UserVipLogService;
|
||||
import com.peanut.modules.master.service.MyUserService;
|
||||
import com.peanut.modules.master.service.UserVipService;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import jakarta.transaction.Transactional;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -40,6 +47,92 @@ public class UserVipController {
|
||||
@Autowired
|
||||
private JfTransactionDetailsService jfTransactionDetailsService;
|
||||
|
||||
@RequestMapping("/getUserVipLogInfoTotal")
|
||||
public R getUserVipLogInfoTotal(@RequestBody Map<String, Object> params) {
|
||||
Map<String,Object> map = userVipLogService.getUserVipLogInfoTotal(params.get("date").toString());
|
||||
return R.ok().put("total", map);
|
||||
}
|
||||
|
||||
@RequestMapping("/getUserVipLogInfoList")
|
||||
public R getUserVipLogInfoList(@RequestBody Map<String, Object> params) {
|
||||
List<Map<String,Object>> maps = userVipLogService.getUserVipLogInfoList(params.get("date").toString());
|
||||
return R.ok().put("list", maps);
|
||||
}
|
||||
|
||||
//导出vip记录明细
|
||||
@RequestMapping("/exportUserVipLogInfo")
|
||||
public void exportUserVipLogInfo(HttpServletResponse response, @RequestBody Map<String,Object> params){
|
||||
List<Map<String,Object>> maps = userVipLogService.getUserVipLogInfoList(params.get("date").toString());
|
||||
XSSFWorkbook wb = new XSSFWorkbook();
|
||||
//创建一张表
|
||||
Sheet sheet = wb.createSheet("vip记录明细");
|
||||
//创建第一行,起始为0
|
||||
Row titleRow = sheet.createRow(0);
|
||||
titleRow.createCell(0).setCellValue("姓名");
|
||||
titleRow.createCell(1).setCellValue("电话");
|
||||
titleRow.createCell(2).setCellValue("VIP类型");
|
||||
titleRow.createCell(3).setCellValue("开始时间");
|
||||
titleRow.createCell(4).setCellValue("结束时间");
|
||||
titleRow.createCell(5).setCellValue("订单号");
|
||||
titleRow.createCell(6).setCellValue("支付方式");
|
||||
titleRow.createCell(7).setCellValue("备注");
|
||||
titleRow.createCell(8).setCellValue("金额");
|
||||
titleRow.createCell(9).setCellValue("总天数");
|
||||
titleRow.createCell(10).setCellValue("每日摊销");
|
||||
titleRow.createCell(11).setCellValue("已摊销天数");
|
||||
titleRow.createCell(12).setCellValue("当月摊销天数");
|
||||
titleRow.createCell(13).setCellValue("未摊销天数");
|
||||
titleRow.createCell(14).setCellValue("已摊销金额");
|
||||
titleRow.createCell(15).setCellValue("当月摊销金额");
|
||||
titleRow.createCell(16).setCellValue("剩余摊销金额");
|
||||
//序号,默认为1
|
||||
int cell = 1;
|
||||
//遍历
|
||||
for (Map<String,Object> map : maps) {
|
||||
Row row = sheet.createRow(cell);
|
||||
row.createCell(0).setCellValue(map.get("name").toString());
|
||||
row.createCell(1).setCellValue(map.get("tel").toString());
|
||||
row.createCell(2).setCellValue(map.get("type").toString());
|
||||
row.createCell(3).setCellValue(map.get("startTime").toString());
|
||||
row.createCell(4).setCellValue(map.get("endTime").toString());
|
||||
row.createCell(5).setCellValue(map.get("orderSn").toString());
|
||||
row.createCell(6).setCellValue(map.get("payType").toString());
|
||||
row.createCell(7).setCellValue(map.get("remark").toString());
|
||||
row.createCell(8).setCellValue(map.get("fee").toString());
|
||||
row.createCell(9).setCellValue(map.get("totalDays").toString());
|
||||
row.createCell(10).setCellValue(map.get("dayAmount").toString());
|
||||
row.createCell(11).setCellValue(map.get("alreadyDays").toString());
|
||||
row.createCell(12).setCellValue(map.get("currentDays").toString());
|
||||
row.createCell(13).setCellValue(map.get("notyetDays").toString());
|
||||
row.createCell(14).setCellValue(map.get("alreadyTanxiao").toString());
|
||||
row.createCell(15).setCellValue(map.get("currentTanxiao").toString());
|
||||
row.createCell(16).setCellValue(map.get("notyetTanxiao").toString());
|
||||
//序号自增
|
||||
cell++;
|
||||
}
|
||||
String fileName = "vip记录明细.xlsx";
|
||||
OutputStream outputStream =null;
|
||||
try {
|
||||
//文件名编码格式
|
||||
fileName = URLEncoder.encode(fileName,"UTF-8");
|
||||
//设置ContentType请求信息格式
|
||||
response.setContentType("application/vnd.ms-excel");
|
||||
//设置标头
|
||||
response.setHeader("Content-disposition", "attachment;filename=" + fileName);
|
||||
outputStream = response.getOutputStream();
|
||||
wb.write(outputStream);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
try {
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("/getUserVipList")
|
||||
public R getUserVipList(@RequestBody Map<String, Object> params) {
|
||||
MPJLambdaWrapper<MyUserEntity> wrapper = new MPJLambdaWrapper();
|
||||
|
||||
42
src/main/resources/mapper/master/UserVipLogDao.xml
Normal file
42
src/main/resources/mapper/master/UserVipLogDao.xml
Normal file
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.peanut.modules.common.dao.UserVipLogDao">
|
||||
|
||||
<select id="getUserVipLogInfoList" resultType="map">
|
||||
select t.*,dayAmount*alreadyDays alreadyTanxiao, dayAmount*currentDays currentTanxiao, fee-(dayAmount*alreadyDays)-(dayAmount*currentDays) notyetTanxiao
|
||||
from (
|
||||
select u.name,if(u.tel is null,if(u.email is null,'',u.email),u.tel) tel,IF(uv.type=4,'中医学',IF(uv.type=5,'针灸学',IF(uv.type=6,'肿瘤学',IF(uv.type=7,'国学',IF(uv.type=8,'心理学','中西汇通学'))))) type,
|
||||
uvl.start_time startTime,uvl.end_time endTime,uvl.order_sn orderSn,uvl.pay_type payType,uvl.remark,uvl.fee,DATEDIFF(uvl.end_time,uvl.start_time)+1 totalDays,ROUND(uvl.fee/(DATEDIFF(uvl.end_time,uvl.start_time)+1),2) dayAmount,
|
||||
IF(DATE_FORMAT(uvl.end_time, '%Y-%m') < #{date},DATEDIFF(uvl.end_time,uvl.start_time)+1,IF(DATE_FORMAT(uvl.start_time, '%Y-%m') > #{date},0,IF(DATE_FORMAT(uvl.start_time, '%Y-%m') < #{date},DATEDIFF(concat(#{date},'-01'),uvl.start_time),0))) alreadyDays,
|
||||
IF(DATE_FORMAT(uvl.start_time, '%Y-%m') > #{date},0,IF(DATE_FORMAT(uvl.end_time, '%Y-%m') < #{date},0,IF(DATE_FORMAT(uvl.end_time, '%Y-%m') > #{date},DAY(LAST_DAY(concat(#{date},'-01'))),DATEDIFF(uvl.end_time,concat(#{date},'-01'))+1))) currentDays,
|
||||
IF(DATE_FORMAT(uvl.start_time, '%Y-%m') > #{date},DATEDIFF(uvl.end_time,uvl.start_time)+1,(IF(DATE_FORMAT(uvl.end_time, '%Y-%m') <= #{date},0,DATEDIFF(uvl.end_time,LAST_DAY(concat(#{date},'-01')))))) notyetDays
|
||||
from user_vip_log uvl
|
||||
left join user_vip uv on uv.id = uvl.user_vip_id
|
||||
left join user u on u.id = uvl.user_id
|
||||
where u.del_flag = 0 and uvl.del_flag = 0 and uv.del_flag = 0 and u.id not in (select id from user where tel in ('18812616272','13110039505','18526084267','12222222222','13333333333','14444444444','15555555555','16666666666','17777777777','18888888888','1774455','15533','165965','164964','54321','111','13662001490','15505153873','18834844847','17602219785','19999999999','12299','166933','16855','17602634511','16161616161','17171717171','112112112','21212121211','222222','666666','123123','789789','96','25252525','3434343434','123789','124789','789789','163963','5656','19966','1664455','15151515151','256366','986986','18834844846','18834844849','15611027864','18047689535','18834844848','456456456'))
|
||||
order by uvl.end_time asc
|
||||
) t order by currentDays desc
|
||||
</select>
|
||||
|
||||
<select id="getUserVipLogInfoTotal" resultType="map">
|
||||
select SUM(fee) fee,SUM(alreadyTanxiao) alreadyTanxiao,SUM(currentTanxiao) currentTanxiao,SUM(notyetTanxiao) notyetTanxiao
|
||||
from (
|
||||
select t.*,dayAmount*alreadyDays alreadyTanxiao, dayAmount*currentDays currentTanxiao, fee-(dayAmount*alreadyDays)-(dayAmount*currentDays) notyetTanxiao
|
||||
from (
|
||||
select u.name,if(u.tel is null,if(u.email is null,'',u.email),u.tel) tel,IF(uv.type=4,'中医学',IF(uv.type=5,'针灸学',IF(uv.type=6,'肿瘤学',IF(uv.type=7,'国学',IF(uv.type=8,'心理学','中西汇通学'))))) type,
|
||||
uvl.start_time startTime,uvl.end_time endTime,uvl.order_sn orderSn,uvl.pay_type payType,uvl.remark,uvl.fee,DATEDIFF(uvl.end_time,uvl.start_time)+1 totalDays,ROUND(uvl.fee/(DATEDIFF(uvl.end_time,uvl.start_time)+1),2) dayAmount,
|
||||
IF(DATE_FORMAT(uvl.end_time, '%Y-%m') < #{date},DATEDIFF(uvl.end_time,uvl.start_time)+1,IF(DATE_FORMAT(uvl.start_time, '%Y-%m') > #{date},0,IF(DATE_FORMAT(uvl.start_time, '%Y-%m') < #{date},DATEDIFF(concat(#{date},'-01'),uvl.start_time),0))) alreadyDays,
|
||||
IF(DATE_FORMAT(uvl.start_time, '%Y-%m') > #{date},0,IF(DATE_FORMAT(uvl.end_time, '%Y-%m') < #{date},0,IF(DATE_FORMAT(uvl.end_time, '%Y-%m') > #{date},DAY(LAST_DAY(concat(#{date},'-01'))),DATEDIFF(uvl.end_time,concat(#{date},'-01'))+1))) currentDays,
|
||||
IF(DATE_FORMAT(uvl.start_time, '%Y-%m') > #{date},DATEDIFF(uvl.end_time,uvl.start_time)+1,(IF(DATE_FORMAT(uvl.end_time, '%Y-%m') <= #{date},0,DATEDIFF(uvl.end_time,LAST_DAY(concat(#{date},'-01')))))) notyetDays
|
||||
from user_vip_log uvl
|
||||
left join user_vip uv on uv.id = uvl.user_vip_id
|
||||
left join user u on u.id = uvl.user_id
|
||||
where u.del_flag = 0 and uvl.del_flag = 0 and uv.del_flag = 0 and u.id not in (select id from user where tel in ('18812616272','13110039505','18526084267','12222222222','13333333333','14444444444','15555555555','16666666666','17777777777','18888888888','1774455','15533','165965','164964','54321','111','13662001490','15505153873','18834844847','17602219785','19999999999','12299','166933','16855','17602634511','16161616161','17171717171','112112112','21212121211','222222','666666','123123','789789','96','25252525','3434343434','123789','124789','789789','163963','5656','19966','1664455','15151515151','256366','986986','18834844846','18834844849','15611027864','18047689535','18834844848','456456456'))
|
||||
order by uvl.end_time asc
|
||||
) t order by currentDays desc
|
||||
) s
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user