|
@@ -2,9 +2,16 @@ package org.jeecg.ctop.finance.settlement.service.serviceImpl;
|
|
|
|
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
|
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|
|
|
+import cn.com.ctop.common.module.entity.SysLog;
|
|
|
|
+import cn.com.ctop.common.module.entity.UserAllocation;
|
|
import cn.com.ctop.common.module.mapper.MailLogMapper;
|
|
import cn.com.ctop.common.module.mapper.MailLogMapper;
|
|
|
|
+import cn.com.ctop.common.module.mapper.SysLogMapper;
|
|
|
|
+import cn.com.ctop.common.module.mapper.SysRoleMapper;
|
|
|
|
+import cn.com.ctop.common.module.mapper.UserAllocationMapper;
|
|
import cn.com.ctop.common.module.utils.CorpWexinUtils;
|
|
import cn.com.ctop.common.module.utils.CorpWexinUtils;
|
|
|
|
+import cn.com.ctop.common.module.utils.ImageUtils;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.google.gson.JsonObject;
|
|
import com.google.gson.JsonObject;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -14,51 +21,71 @@ import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
import org.jeecg.common.api.vo.Result;
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
|
+import org.jeecg.common.system.entity.SysUser;
|
|
|
|
+import org.jeecg.common.system.vo.LoginUser;
|
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
|
+import org.jeecg.ctop.finance.policy.entity.CwjsPolicyInfo;
|
|
|
|
+import org.jeecg.ctop.finance.policy.entity.CwjsPolicyProduct;
|
|
|
|
+import org.jeecg.ctop.finance.policy.mapper.CwjsPolicyProductMapper;
|
|
import org.jeecg.ctop.finance.policy.utils.Check;
|
|
import org.jeecg.ctop.finance.policy.utils.Check;
|
|
|
|
+import org.jeecg.ctop.finance.settlement.entity.pojo.CtopCwjsSettlementInfo;
|
|
|
|
+import org.jeecg.ctop.finance.settlement.entity.pojo.CtopCwjsSlettementReport;
|
|
import org.jeecg.ctop.finance.settlement.entity.vo.*;
|
|
import org.jeecg.ctop.finance.settlement.entity.vo.*;
|
|
|
|
+import org.jeecg.ctop.finance.settlement.mapper.CwjsProfitMapper;
|
|
import org.jeecg.ctop.finance.settlement.mapper.ReportSettlementMapper;
|
|
import org.jeecg.ctop.finance.settlement.mapper.ReportSettlementMapper;
|
|
|
|
+import org.jeecg.ctop.finance.settlement.mapper.SettlementInfoMapper;
|
|
import org.jeecg.ctop.finance.settlement.service.IReportSettlementService;
|
|
import org.jeecg.ctop.finance.settlement.service.IReportSettlementService;
|
|
import org.jeecg.ctop.finance.utils.SettlementUtil;
|
|
import org.jeecg.ctop.finance.utils.SettlementUtil;
|
|
import org.jeecg.ctop.finance.utils.createExcelByTemplate;
|
|
import org.jeecg.ctop.finance.utils.createExcelByTemplate;
|
|
|
|
+import org.jeecg.modules.ctop.service.IMaterialReportOverViewService;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import javax.imageio.ImageIO;
|
|
import javax.imageio.ImageIO;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import javax.swing.*;
|
|
|
|
+import java.awt.*;
|
|
import java.awt.image.BufferedImage;
|
|
import java.awt.image.BufferedImage;
|
|
import java.io.*;
|
|
import java.io.*;
|
|
|
|
+import java.net.URL;
|
|
import java.net.URLEncoder;
|
|
import java.net.URLEncoder;
|
|
import java.text.MessageFormat;
|
|
import java.text.MessageFormat;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Calendar;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.*;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
-import java.util.Map;
|
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@Service
|
|
@Service
|
|
public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
-
|
|
|
|
@Resource
|
|
@Resource
|
|
private ReportSettlementMapper reportSettlementMapper;
|
|
private ReportSettlementMapper reportSettlementMapper;
|
|
-
|
|
|
|
@Resource
|
|
@Resource
|
|
private CorpWexinUtils corpWexinUtils;
|
|
private CorpWexinUtils corpWexinUtils;
|
|
@Resource
|
|
@Resource
|
|
private MailLogMapper mailLogMapper;
|
|
private MailLogMapper mailLogMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private CwjsProfitMapper cwjsProfitMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private UserAllocationMapper userAllocationMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private SysRoleMapper roleMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IMaterialReportOverViewService materialReportOverViewService;
|
|
|
|
+ @Resource
|
|
|
|
+ private SysLogMapper sysLogMapper;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public List<SettlementReportBytedanceVo> getAccountTransactionDayBytedance() {
|
|
public List<SettlementReportBytedanceVo> getAccountTransactionDayBytedance() {
|
|
return reportSettlementMapper.getAccountTransactionDayBytedance(null);
|
|
return reportSettlementMapper.getAccountTransactionDayBytedance(null);
|
|
}
|
|
}
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
- public Result settlementReportBytedance(SettlementFileParamsVo paramsVo, HttpServletResponse response) {
|
|
|
|
-
|
|
|
|
|
|
+ public Result settlementReportBytedance(SettlementFileParamsVo paramsVo, HttpServletResponse response, SysUser user) {
|
|
try {
|
|
try {
|
|
-
|
|
|
|
//第一步创建workbook
|
|
//第一步创建workbook
|
|
HSSFWorkbook wb = new HSSFWorkbook();
|
|
HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
|
|
|
@@ -73,16 +100,15 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
style.setFont(font);
|
|
style.setFont(font);
|
|
|
|
|
|
//查询 账户id
|
|
//查询 账户id
|
|
- List<String> accountIdList = reportSettlementMapper.getAccountIdBytedance(paramsVo);
|
|
|
|
|
|
+ List<String> accountIdList = this.getAccountId(paramsVo,user);
|
|
|
|
|
|
if (Check.isNull(accountIdList)){
|
|
if (Check.isNull(accountIdList)){
|
|
- return Result.errorMsg("该广告主和产品下无法查询到绑定的账户信息。");
|
|
|
|
|
|
+ return Result.errorMsg("该广告主和产品下无法查询到绑定的账户信息");
|
|
}
|
|
}
|
|
|
|
|
|
int num = 0;
|
|
int num = 0;
|
|
|
|
|
|
for (int k = 0; k < accountIdList.size(); k++) {
|
|
for (int k = 0; k < accountIdList.size(); k++) {
|
|
-
|
|
|
|
String accountId = accountIdList.get(k);
|
|
String accountId = accountIdList.get(k);
|
|
paramsVo.setAccountId(accountId);
|
|
paramsVo.setAccountId(accountId);
|
|
|
|
|
|
@@ -113,23 +139,23 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
|
|
|
|
//5:创建第2行的单元格
|
|
//5:创建第2行的单元格
|
|
HSSFCell cell = row.createCell(0); //第一个单元格
|
|
HSSFCell cell = row.createCell(0); //第一个单元格
|
|
- cell.setCellValue(" 日期 "); //设定值
|
|
|
|
|
|
+ cell.setCellValue("日期"); //设定值
|
|
cell.setCellStyle(style); //内容居中
|
|
cell.setCellStyle(style); //内容居中
|
|
|
|
|
|
cell = row.createCell(1);
|
|
cell = row.createCell(1);
|
|
- cell.setCellValue(" 账户名称 ");
|
|
|
|
|
|
+ cell.setCellValue("账户名称");
|
|
cell.setCellStyle(style);
|
|
cell.setCellStyle(style);
|
|
|
|
|
|
cell = row.createCell(2);
|
|
cell = row.createCell(2);
|
|
- cell.setCellValue(" 账户ID ");
|
|
|
|
|
|
+ cell.setCellValue("账户ID");
|
|
cell.setCellStyle(style);
|
|
cell.setCellStyle(style);
|
|
|
|
|
|
cell = row.createCell(3);
|
|
cell = row.createCell(3);
|
|
- cell.setCellValue(" 所属代理商名称 ");
|
|
|
|
|
|
+ cell.setCellValue("所属代理商名称");
|
|
cell.setCellStyle(style);
|
|
cell.setCellStyle(style);
|
|
|
|
|
|
cell = row.createCell(4);
|
|
cell = row.createCell(4);
|
|
- cell.setCellValue(" 所属代理商ID ");
|
|
|
|
|
|
+ cell.setCellValue("所属代理商ID");
|
|
cell.setCellStyle(style);
|
|
cell.setCellStyle(style);
|
|
|
|
|
|
cell = row.createCell(5);
|
|
cell = row.createCell(5);
|
|
@@ -164,9 +190,6 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
cell.setCellValue("冻结(¥)");
|
|
cell.setCellValue("冻结(¥)");
|
|
cell.setCellStyle(style);
|
|
cell.setCellStyle(style);
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
for (int i = 0; i < settlementList.size(); i++) {
|
|
for (int i = 0; i < settlementList.size(); i++) {
|
|
SettlementReportBytedanceVo vo = settlementList.get(i);
|
|
SettlementReportBytedanceVo vo = settlementList.get(i);
|
|
//创建行 (表头占0-1行 所以 从 2开始)
|
|
//创建行 (表头占0-1行 所以 从 2开始)
|
|
@@ -189,21 +212,25 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
row.createCell(12).setCellValue(vo.getFrozen());
|
|
row.createCell(12).setCellValue(vo.getFrozen());
|
|
}
|
|
}
|
|
|
|
|
|
- //先把读进来的图片放到一个ByteArrayOutputStream中,以便产生ByteArray
|
|
|
|
- ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
|
|
|
|
-
|
|
|
|
//查询 图片 url
|
|
//查询 图片 url
|
|
- List<String> imageUrlList = reportSettlementMapper.getAccountImagesBytedance(accountId);
|
|
|
|
|
|
+ List<String> imageUrlList = reportSettlementMapper.getAccountImagesBytedance(accountId,paramsVo.getUploadYears());
|
|
|
|
|
|
if (!Check.isNull(imageUrlList)){
|
|
if (!Check.isNull(imageUrlList)){
|
|
for (int j = 0; j < imageUrlList.size(); j++) {
|
|
for (int j = 0; j < imageUrlList.size(); j++) {
|
|
|
|
+ //先把读进来的图片放到一个ByteArrayOutputStream中,以便产生ByteArray
|
|
|
|
+ ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
|
|
String imagePath = imageUrlList.get(j);
|
|
String imagePath = imageUrlList.get(j);
|
|
//通过图片网络地址 获取输入流
|
|
//通过图片网络地址 获取输入流
|
|
- InputStream is = createExcelByTemplate.getInputStreamByUrl(imagePath);
|
|
|
|
|
|
+ /* InputStream is = createExcelByTemplate.getInputStreamByUrl(imagePath);
|
|
BufferedImage bufferImg = ImageIO.read(is);
|
|
BufferedImage bufferImg = ImageIO.read(is);
|
|
|
|
+*/
|
|
|
|
+ URL url = new URL(imagePath);
|
|
|
|
+ Image imageTookittitle = Toolkit.getDefaultToolkit().createImage(url);
|
|
|
|
+ BufferedImage bufferImg = createExcelByTemplate.toBufferedImage(imageTookittitle);
|
|
ImageIO.write(bufferImg, imagePath.substring(imagePath.lastIndexOf(".") + 1), byteArrayOut);
|
|
ImageIO.write(bufferImg, imagePath.substring(imagePath.lastIndexOf(".") + 1), byteArrayOut);
|
|
|
|
+ int startIndex = settlementList.size() +6;
|
|
//anchor主要用于设置图片的属性
|
|
//anchor主要用于设置图片的属性
|
|
- HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 255, 255, (short) 2, settlementList.size() + 6 +(j*40), (short) 10, 90*(j+1));
|
|
|
|
|
|
+ HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 255, 255, (short) 0, startIndex+(5*j)+50*j, (short) 25, startIndex+(5*j)+50*(j+1));
|
|
//HSSFClientAnchor anchor2 = new HSSFClientAnchor(0, 0, 255, 255, (short) 5, settlementList.size() + 40, (short) 10, 40 * 2);
|
|
//HSSFClientAnchor anchor2 = new HSSFClientAnchor(0, 0, 255, 255, (short) 5, settlementList.size() + 40, (short) 10, 40 * 2);
|
|
anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE);
|
|
anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE);
|
|
//插入图片
|
|
//插入图片
|
|
@@ -214,7 +241,7 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
}
|
|
}
|
|
|
|
|
|
if(accountIdList.size() == num){
|
|
if(accountIdList.size() == num){
|
|
- return Result.errorMsg("暂无数据。");
|
|
|
|
|
|
+ return Result.errorMsg("暂无账户流水数据");
|
|
}
|
|
}
|
|
|
|
|
|
response.setCharacterEncoding("UTF-8");
|
|
response.setCharacterEncoding("UTF-8");
|
|
@@ -222,7 +249,7 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
response.setHeader("Pragma", "no-cache");
|
|
response.setHeader("Pragma", "no-cache");
|
|
response.setHeader("Cache-Control", "no-cache");
|
|
response.setHeader("Cache-Control", "no-cache");
|
|
response.setDateHeader("Expires", 0);
|
|
response.setDateHeader("Expires", 0);
|
|
- response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(paramsVo.getUploadYears()+"头条结算单.xlsx", "UTF-8"));
|
|
|
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(paramsVo.getUploadYears()+"-头条结算单.xlsx", "UTF-8"));
|
|
OutputStream output = response.getOutputStream();
|
|
OutputStream output = response.getOutputStream();
|
|
BufferedOutputStream bufferedOutPut = new BufferedOutputStream(output);
|
|
BufferedOutputStream bufferedOutPut = new BufferedOutputStream(output);
|
|
wb.write(bufferedOutPut);
|
|
wb.write(bufferedOutPut);
|
|
@@ -231,19 +258,65 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
output.close();
|
|
output.close();
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
- log.error("====>>>>", e.getMessage());
|
|
|
|
return Result.errorMsg(e.getMessage());
|
|
return Result.errorMsg(e.getMessage());
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
+ /**
|
|
|
|
+ * @param paramsVo
|
|
|
|
+ * @param user
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public List<String> getAccountId(SettlementFileParamsVo paramsVo,SysUser user) {
|
|
|
|
+ String uploadYears = paramsVo.getUploadYears();
|
|
|
|
+ //1:区分媒体(头条:1 快手:2)
|
|
|
|
+ Integer mediaId = paramsVo.getMediaId();
|
|
|
|
+
|
|
|
|
+ String roleCode = roleMapper.getRoleCodeByUserId(user.getId());
|
|
|
|
+ Set<String>sales = new HashSet<>();
|
|
|
|
+ List<UserAllocation>allocations ;
|
|
|
|
+ if("admin".equals(roleCode)|| "finance".equals(roleCode)){
|
|
|
|
+ //查询所有可用的账户
|
|
|
|
+ }else if("saleDirector".equals(roleCode)){
|
|
|
|
+ //查询自己下辖的所有销售绑定的账户
|
|
|
|
+ sales = materialReportOverViewService.recursiveQuerySubordinate(paramsVo.getCreateUserId());
|
|
|
|
+ }else if("saleAssistant".equals(roleCode)|| "sale".equals(roleCode)|| "saleAm".equals(roleCode)){
|
|
|
|
+ //查询自己名绑定下的账户
|
|
|
|
+ sales.add(user.getId());
|
|
|
|
+ }
|
|
|
|
+ if(sales.isEmpty()){
|
|
|
|
+ sales = null;
|
|
|
|
+ }
|
|
|
|
+ List<String> settlementAccountList = reportSettlementMapper.getAccountIdBytedance(sales,String.valueOf(mediaId),paramsVo.getAdvertiserId(),paramsVo.getProductId());
|
|
|
|
+ allocations = userAllocationMapper.getAccountInfoBySalesId(sales,String.valueOf(mediaId),paramsVo.getAdvertiserId(),paramsVo.getProductId());
|
|
|
|
+ return mergeAccountId(settlementAccountList,allocations,uploadYears);
|
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
|
|
|
+ private List<String> mergeAccountId(List<String> settlementAccountList, List<UserAllocation> allocations,String uploadYears) {
|
|
|
|
+ List<String>salesAccount = new ArrayList<>();
|
|
|
|
+ for(UserAllocation allocation:allocations){
|
|
|
|
+ if(allocation.getAccountStatus() == 0){
|
|
|
|
+ salesAccount.add(allocation.getAccountId()+"");
|
|
|
|
+ }
|
|
|
|
+ if(allocation.getAccountStatus() == 1){
|
|
|
|
+ //被关停的账户
|
|
|
|
+ Long updateDateNum = Long.parseLong(DateUtils.formatDate(allocation.getUpdateTime(),"yyyymm"));
|
|
|
|
+ uploadYears = uploadYears.replace("-","");
|
|
|
|
+ Long uploadYearNum = Long.parseLong(uploadYears);
|
|
|
|
+ if(updateDateNum>=uploadYearNum){
|
|
|
|
+ salesAccount.add(allocation.getAccountId()+"");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ settlementAccountList.removeAll(salesAccount);
|
|
|
|
+ settlementAccountList.addAll(salesAccount);
|
|
|
|
+ return settlementAccountList;
|
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public Result settlementReportKuaiShou(SettlementFileParamsVo paramsVo, HttpServletResponse response) {
|
|
|
|
-
|
|
|
|
|
|
+ public Result settlementReportKuaiShou(SettlementFileParamsVo paramsVo, HttpServletResponse response, SysUser user) {
|
|
try {
|
|
try {
|
|
-
|
|
|
|
//第一步创建workbook
|
|
//第一步创建workbook
|
|
HSSFWorkbook wb = new HSSFWorkbook();
|
|
HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
|
|
|
@@ -257,22 +330,28 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
font.setFontHeightInPoints((short) 12);//设置字体大小
|
|
font.setFontHeightInPoints((short) 12);//设置字体大小
|
|
style.setFont(font);
|
|
style.setFont(font);
|
|
|
|
|
|
- //查询 账户id
|
|
|
|
- List<String> accountIdList = reportSettlementMapper.getAccountIdBytedance(paramsVo);
|
|
|
|
|
|
+ //查询 需要导出的数据的账户id
|
|
|
|
+ List<String> accountIdList = this.getAccountId(paramsVo,user);
|
|
|
|
|
|
if (Check.isNull(accountIdList)){
|
|
if (Check.isNull(accountIdList)){
|
|
- return Result.errorMsg("该广告主和产品下无法查询到绑定的快手账户信息。");
|
|
|
|
|
|
+ return Result.errorMsg("该广告主和产品下无法查询到绑定的快手账户信息");
|
|
}
|
|
}
|
|
|
|
|
|
int num = 0;
|
|
int num = 0;
|
|
-
|
|
|
|
for (int k = 0; k < accountIdList.size(); k++) {
|
|
for (int k = 0; k < accountIdList.size(); k++) {
|
|
-
|
|
|
|
String accountId = accountIdList.get(k);
|
|
String accountId = accountIdList.get(k);
|
|
paramsVo.setAccountId(accountId);
|
|
paramsVo.setAccountId(accountId);
|
|
|
|
|
|
//获取账户 日流水数据 根据账户id 和 年月 查询数据
|
|
//获取账户 日流水数据 根据账户id 和 年月 查询数据
|
|
- List<SettlementReportKuaiShouVo> settlementList = reportSettlementMapper.getAccountTransactionDayKuaiShou(paramsVo);
|
|
|
|
|
|
+ /* List<SettlementReportKuaiShouVo> settlementList = new ArrayList<>();
|
|
|
|
+ //查询账户维度
|
|
|
|
+ settlementList = reportSettlementMapper.getAccountTransactionDayKuaiShou(paramsVo);
|
|
|
|
+ if (Check.isNull(settlementList)){
|
|
|
|
+ //查询代理商维度
|
|
|
|
+ settlementList = reportSettlementMapper.getAccountTransactionDayKuaiShouAgent(paramsVo);
|
|
|
|
+ }
|
|
|
|
+*/
|
|
|
|
+ List<SettlementReportKuaiShouVo> settlementList = reportSettlementMapper.getTransactionDayKuaiShouAgentAndAccount(paramsVo);
|
|
if (Check.isNull(settlementList)){
|
|
if (Check.isNull(settlementList)){
|
|
num++;
|
|
num++;
|
|
continue;
|
|
continue;
|
|
@@ -298,23 +377,23 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
|
|
|
|
//5:创建第2行的单元格
|
|
//5:创建第2行的单元格
|
|
HSSFCell cell = row.createCell(0); //第一个单元格
|
|
HSSFCell cell = row.createCell(0); //第一个单元格
|
|
- cell.setCellValue(" 日期 "); //设定值
|
|
|
|
|
|
+ cell.setCellValue("日期"); //设定值
|
|
cell.setCellStyle(style); //内容居中
|
|
cell.setCellStyle(style); //内容居中
|
|
|
|
|
|
cell = row.createCell(1);
|
|
cell = row.createCell(1);
|
|
- cell.setCellValue(" 账户快手ID ");
|
|
|
|
|
|
+ cell.setCellValue("账户快手ID");
|
|
cell.setCellStyle(style);
|
|
cell.setCellStyle(style);
|
|
|
|
|
|
cell = row.createCell(2);
|
|
cell = row.createCell(2);
|
|
- cell.setCellValue(" 广告主账户ID ");
|
|
|
|
|
|
+ cell.setCellValue("广告主账户ID");
|
|
cell.setCellStyle(style);
|
|
cell.setCellStyle(style);
|
|
|
|
|
|
cell = row.createCell(3);
|
|
cell = row.createCell(3);
|
|
- cell.setCellValue(" 日总花费 ");
|
|
|
|
|
|
+ cell.setCellValue("日总花费");
|
|
cell.setCellStyle(style);
|
|
cell.setCellStyle(style);
|
|
|
|
|
|
cell = row.createCell(4);
|
|
cell = row.createCell(4);
|
|
- cell.setCellValue(" 充值花费 ");
|
|
|
|
|
|
+ cell.setCellValue("充值花费");
|
|
cell.setCellStyle(style);
|
|
cell.setCellStyle(style);
|
|
|
|
|
|
cell = row.createCell(5);
|
|
cell = row.createCell(5);
|
|
@@ -350,8 +429,6 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
cell.setCellStyle(style);
|
|
cell.setCellStyle(style);
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
for (int i = 0; i < settlementList.size(); i++) {
|
|
for (int i = 0; i < settlementList.size(); i++) {
|
|
SettlementReportKuaiShouVo vo = settlementList.get(i);
|
|
SettlementReportKuaiShouVo vo = settlementList.get(i);
|
|
//创建行 (表头占0-1行 所以 从 2开始)
|
|
//创建行 (表头占0-1行 所以 从 2开始)
|
|
@@ -374,23 +451,27 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
row.createCell(12).setCellValue(vo.getBalance());
|
|
row.createCell(12).setCellValue(vo.getBalance());
|
|
}
|
|
}
|
|
|
|
|
|
- //先把读进来的图片放到一个ByteArrayOutputStream中,以便产生ByteArray
|
|
|
|
- ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
|
|
|
|
|
|
+
|
|
|
|
|
|
//查询 图片 url
|
|
//查询 图片 url
|
|
- List<String> imageUrlList = reportSettlementMapper.getAccountImagesBytedance(accountId);
|
|
|
|
|
|
+ List<String> imageUrlList = reportSettlementMapper.getAccountImagesBytedance(accountId,paramsVo.getUploadYears());
|
|
|
|
|
|
if (!Check.isNull(imageUrlList)){
|
|
if (!Check.isNull(imageUrlList)){
|
|
for (int j = 0; j < imageUrlList.size(); j++) {
|
|
for (int j = 0; j < imageUrlList.size(); j++) {
|
|
|
|
+ //先把读进来的图片放到一个ByteArrayOutputStream中,以便产生ByteArray
|
|
|
|
+ ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
|
|
String imagePath = imageUrlList.get(j);
|
|
String imagePath = imageUrlList.get(j);
|
|
//通过图片网络地址 获取输入流
|
|
//通过图片网络地址 获取输入流
|
|
- InputStream is = createExcelByTemplate.getInputStreamByUrl(imagePath);
|
|
|
|
|
|
+ /* InputStream is = createExcelByTemplate.getInputStreamByUrl(imagePath);
|
|
BufferedImage bufferImg = ImageIO.read(is);
|
|
BufferedImage bufferImg = ImageIO.read(is);
|
|
|
|
+ */
|
|
|
|
+ URL url = new URL(imagePath);
|
|
|
|
+ Image imageTookittitle = Toolkit.getDefaultToolkit().createImage(url);
|
|
|
|
+ BufferedImage bufferImg = createExcelByTemplate.toBufferedImage(imageTookittitle);
|
|
ImageIO.write(bufferImg, imagePath.substring(imagePath.lastIndexOf(".") + 1), byteArrayOut);
|
|
ImageIO.write(bufferImg, imagePath.substring(imagePath.lastIndexOf(".") + 1), byteArrayOut);
|
|
//anchor主要用于设置图片的属性
|
|
//anchor主要用于设置图片的属性
|
|
int startIndex = settlementList.size()+7;
|
|
int startIndex = settlementList.size()+7;
|
|
-
|
|
|
|
- HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 255, 255, (short) 2, startIndex+(5*j)+50*j, (short) 10, startIndex+(5*j)+50*(j+1));
|
|
|
|
|
|
+ HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 255, 255, (short) 0, startIndex+(5*j)+50*j, (short) 25, startIndex+(5*j)+50*(j+1));
|
|
//HSSFClientAnchor anchor2 = new HSSFClientAnchor(0, 0, 255, 255, (short) 5, settlementList.size() + 40, (short) 10, 40 * 2);
|
|
//HSSFClientAnchor anchor2 = new HSSFClientAnchor(0, 0, 255, 255, (short) 5, settlementList.size() + 40, (short) 10, 40 * 2);
|
|
anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE);
|
|
anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE);
|
|
//插入图片
|
|
//插入图片
|
|
@@ -401,7 +482,7 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
}
|
|
}
|
|
|
|
|
|
if(accountIdList.size() == num){
|
|
if(accountIdList.size() == num){
|
|
- return Result.errorMsg("暂无数据。");
|
|
|
|
|
|
+ return Result.errorMsg("暂无数据");
|
|
}
|
|
}
|
|
|
|
|
|
response.setCharacterEncoding("UTF-8");
|
|
response.setCharacterEncoding("UTF-8");
|
|
@@ -409,7 +490,7 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
response.setHeader("Pragma", "no-cache");
|
|
response.setHeader("Pragma", "no-cache");
|
|
response.setHeader("Cache-Control", "no-cache");
|
|
response.setHeader("Cache-Control", "no-cache");
|
|
response.setDateHeader("Expires", 0);
|
|
response.setDateHeader("Expires", 0);
|
|
- response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(paramsVo.getUploadYears()+"快手结算单.xlsx", "UTF-8"));
|
|
|
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(paramsVo.getUploadYears()+"-快手结算单.xlsx", "UTF-8"));
|
|
OutputStream output = response.getOutputStream();
|
|
OutputStream output = response.getOutputStream();
|
|
BufferedOutputStream bufferedOutPut = new BufferedOutputStream(output);
|
|
BufferedOutputStream bufferedOutPut = new BufferedOutputStream(output);
|
|
wb.write(bufferedOutPut);
|
|
wb.write(bufferedOutPut);
|
|
@@ -418,15 +499,11 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
output.close();
|
|
output.close();
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
- log.error("====>>>>", e.getMessage());
|
|
|
|
return Result.errorMsg(e.getMessage());
|
|
return Result.errorMsg(e.getMessage());
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
* @description: 财务结算 利润表导出 头条
|
|
* @description: 财务结算 利润表导出 头条
|
|
@@ -437,49 +514,141 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public Result porfitReportBytedance(SettlementFileParamsVo paramsVo, HttpServletResponse response) {
|
|
public Result porfitReportBytedance(SettlementFileParamsVo paramsVo, HttpServletResponse response) {
|
|
-
|
|
|
|
try {
|
|
try {
|
|
- //查询 头条利润表 总花费
|
|
|
|
- List<Map<String,Object>> list = reportSettlementMapper.getProfitBytedanceCost(paramsVo.getUploadYears());
|
|
|
|
|
|
+ //查询 头条利润表 时间段内 所有 账户
|
|
|
|
+ List<Map<String,Object>> list = reportSettlementMapper.getProfitBytedanceAccount(paramsVo.getStartTime(),paramsVo.getEndTime());
|
|
if (Check.isNull(list)){
|
|
if (Check.isNull(list)){
|
|
- return Result.errorMsg("暂无数据。");
|
|
|
|
|
|
+ return Result.errorMsg("暂无数据");
|
|
}
|
|
}
|
|
List<ProfitReportBytedanceVo> resultList = new ArrayList<>(list.size());
|
|
List<ProfitReportBytedanceVo> resultList = new ArrayList<>(list.size());
|
|
- for (Map<String, Object> map : list) {
|
|
|
|
- ProfitReportBytedanceVo vo = new ProfitReportBytedanceVo();
|
|
|
|
- vo.setCost(map.getOrDefault("cost","")+"");//总消耗
|
|
|
|
- vo.setCashCost(map.getOrDefault("cashCost","")+"");//现金消耗
|
|
|
|
- vo.setRewardCost(map.getOrDefault("rewardCost","")+"");//赠款消耗
|
|
|
|
- vo.setProductName(map.getOrDefault("productName","")+"");//产品名称
|
|
|
|
- //查询 头条利润表 销售人员姓名 以及 返点类型和比列
|
|
|
|
- Map<String,Object> slaeMap = reportSettlementMapper.getProfitBytedanceSale(map.get("productId")+"");
|
|
|
|
- if (!Check.isNull(slaeMap)){
|
|
|
|
- vo.setSaleName(slaeMap.getOrDefault("saleName","")+"");//销售
|
|
|
|
- // 当前查询时间 与 销售政策 开始 截至时间 是否匹配
|
|
|
|
- if (SettlementUtil.isEffectiveDate(paramsVo.getUploadYears(),slaeMap.get("policyStart")+"",slaeMap.get("policyEnd")+"")){
|
|
|
|
- //销售政策状态 为 通过 显示 返点类型 和 返点比列
|
|
|
|
- if (StringUtils.equals(slaeMap.getOrDefault("approvedStatus","")+"","3")){
|
|
|
|
- vo.setRebateType(slaeMap.getOrDefault("rebateType","")+"");//返点类型
|
|
|
|
- vo.setRebateRate(slaeMap.getOrDefault("rebateRate","")+"");//返点比列
|
|
|
|
|
|
+ for (Map<String, Object> mapList : list) {
|
|
|
|
+ //查看该账户 状态信息
|
|
|
|
+ /*QueryWrapper<SysLog> sysLogQw = new QueryWrapper<>();
|
|
|
|
+ sysLogQw.eq("log_type", 2);
|
|
|
|
+ //操作类型
|
|
|
|
+ sysLogQw.eq("operate_type", 10001);
|
|
|
|
+ sysLogQw.eq("log_content", "0");//0开 1关
|
|
|
|
+ sysLogQw.eq("request_param", mapList.get("accountId").toString());
|
|
|
|
+ sysLogQw.orderByDesc("create_time");
|
|
|
|
+ sysLogQw.last("limit 1");
|
|
|
|
+ SysLog sysLog = sysLogMapper.selectOne(sysLogQw);
|
|
|
|
+ if (!Check.isNull(sysLog)) {
|
|
|
|
+ SimpleDateFormat m = new SimpleDateFormat("MM");
|
|
|
|
+ String createMonth = m.format(sysLog.getCreateTime());
|
|
|
|
+ int crate = Integer.valueOf(createMonth);
|
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
|
+ int month = cal.get(Calendar.MONTH) + 1;
|
|
|
|
+ }*/
|
|
|
|
+ //查看账户数据
|
|
|
|
+ Map<String,Object> map = reportSettlementMapper.getProfitBytedanceAccountCost(mapList.get("accountId").toString(),paramsVo.getStartTime(),paramsVo.getEndTime());
|
|
|
|
+
|
|
|
|
+ ProfitReportBytedanceVo voSource = new ProfitReportBytedanceVo();
|
|
|
|
+ voSource.setAccountId(map.get("accountId")+"");
|
|
|
|
+
|
|
|
|
+ voSource.setAdvertiserName(!Check.isNull(map.get("advertiserName")) ? map.getOrDefault("advertiserName","")+"" : "" );//广告主名称
|
|
|
|
+ //产品名称
|
|
|
|
+ voSource.setProductName(!Check.isNull(map.get("productName")) ? map.getOrDefault("productName","")+"" : "" );
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //查询销售
|
|
|
|
+ Map<String,Object> slaeMap = reportSettlementMapper.getProfitReportSale(map.get("accountId")+"");
|
|
|
|
+ voSource.setSaleName(Check.isNull(slaeMap) ? "" : slaeMap.getOrDefault("saleName","")+"");//销售
|
|
|
|
+ //查询运营
|
|
|
|
+ Map<String,Object> operateMap = reportSettlementMapper.getProfitReportOperateAndArea(map.get("accountId")+"");
|
|
|
|
+ if (!Check.isNull(operateMap)){
|
|
|
|
+ voSource.setOperateName(operateMap.getOrDefault("operateName","")+"");//运营
|
|
|
|
+ voSource.setOperateArea(operateMap.getOrDefault("operateArea","")+"");//运营所属区域
|
|
|
|
+ }
|
|
|
|
+ //政策所有时间点
|
|
|
|
+ List<String> policyDaysList = new ArrayList<>();
|
|
|
|
+ if (!Check.isNull(map.get("productName"))){
|
|
|
|
+ //查询 头条利润表 返点类型和比列
|
|
|
|
+ List<Map<String,Object>> rateMap = reportSettlementMapper.getProfitBytedance(map.get("productName")+"","1",paramsVo.getStartTime(),paramsVo.getEndTime());
|
|
|
|
+ List listPolicyTIme = new ArrayList();
|
|
|
|
+ for (Map<String, Object> rate : rateMap) {
|
|
|
|
+ listPolicyTIme.add(rate.get("policyStartDate"));
|
|
|
|
+ listPolicyTIme.add(rate.get("policyEndDate"));
|
|
|
|
+ }
|
|
|
|
+ //政策时间 去重 排序
|
|
|
|
+ List<Object> times = SettlementUtil.sortlistTest(listPolicyTIme);
|
|
|
|
+ // 使用政策的时间段 拼接 开始 和 截至 时间
|
|
|
|
+ List<Map<String, String>> arrayList = new ArrayList<>();
|
|
|
|
+ for ( int i = 0; i < times.size(); i++) {
|
|
|
|
+ HashMap<String, String> mapTime = new HashMap<>();
|
|
|
|
+ mapTime.put("startDate", times.get(i).toString());
|
|
|
|
+ mapTime.put("endDate", times.size() < 2 ? times.get(i).toString() : times.get(i + 1).toString());
|
|
|
|
+ i += 1;
|
|
|
|
+ arrayList.add(mapTime);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ for (Map<String, String> stringMap : arrayList) {
|
|
|
|
+ ProfitReportBytedanceVo vo = new ProfitReportBytedanceVo();
|
|
|
|
+ //使用政策 返点类型和比例
|
|
|
|
+ Map<String,Object> policyRateMap = reportSettlementMapper.getProfitRebate(map.get("productName")+"",stringMap.get("startDate"),stringMap.get("endDate"));
|
|
|
|
+ if (!Check.isNull(policyRateMap)){
|
|
|
|
+ if(Integer.valueOf(policyRateMap.get("rebateType").toString())== 0){
|
|
|
|
+ vo.setRebateType("返现");//返点类型
|
|
|
|
+ }else if (Integer.valueOf(policyRateMap.get("rebateType").toString())== 1){
|
|
|
|
+ vo.setRebateType("返货");
|
|
|
|
+ }else if (Integer.valueOf(policyRateMap.get("rebateType").toString())== 2){
|
|
|
|
+ vo.setRebateType("返现+返货");
|
|
|
|
+ }
|
|
|
|
+ vo.setRebateRate(policyRateMap.getOrDefault("rebateRate","")+"%");//返点比列
|
|
|
|
+ }else {
|
|
|
|
+ vo.setRebateType("");
|
|
}
|
|
}
|
|
|
|
+ // 时间段内 账户流水 信息
|
|
|
|
+ List<Map<String,Object>> listAccount = reportSettlementMapper.getProfitBytedanceCost(map.get("accountId")+"",stringMap.get("startDate"),stringMap.get("endDate"));
|
|
|
|
+ listAccount.removeAll(Collections.singleton(null));
|
|
|
|
+ vo.setCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("cost","")+"");//总消耗
|
|
|
|
+ vo.setCost(String.format("%.3f",new Double(vo.getCost())));
|
|
|
|
+ vo.setCashCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("cashCost","")+"");//现金消耗
|
|
|
|
+ vo.setCashCost(String.format("%.3f",new Double(vo.getCashCost())));
|
|
|
|
+ vo.setRewardCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("rewardCost","")+"");//赠款消耗
|
|
|
|
+ vo.setRewardCost(String.format("%.3f",new Double(vo.getRewardCost())));
|
|
|
|
+ BeanUtils.copyProperties(voSource,vo,SettlementUtil.getNullPropertyNames(voSource));
|
|
|
|
+ vo.setTime(stringMap.get("startDate")+"----"+stringMap.get("endDate"));
|
|
|
|
+ resultList.add(vo);
|
|
|
|
+ policyDaysList.addAll(SettlementUtil.getAllDatesOfTwoTimes(stringMap.get("startDate"),stringMap.get("endDate")));
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
- Map<String,Object> operateMap = reportSettlementMapper.getProfitBytedanceOperate(map.get("accountId")+"");
|
|
|
|
- if (!Check.isNull(operateMap)){
|
|
|
|
- vo.setAdvertiserName(operateMap.getOrDefault("advertiserName","")+"");//广告主名称
|
|
|
|
- vo.setOperateName(operateMap.getOrDefault("operateName","")+"");//运营
|
|
|
|
- vo.setOperateArea(operateMap.getOrDefault("operateArea","")+"");//运营所属区域
|
|
|
|
|
|
+ //不使用政策 的时间段
|
|
|
|
+ // 获取两个日期之间 所有的 时间 年-月-日
|
|
|
|
+ List<String> betweenDaysList = SettlementUtil.getAllDatesOfTwoTimes(paramsVo.getStartTime(),paramsVo.getEndTime());
|
|
|
|
+ // 时间差集(所有时间段 - 使用政策的时间段)
|
|
|
|
+ List<String> reduceList = betweenDaysList.stream().filter(item -> !policyDaysList.contains(item)).collect(Collectors.toList());
|
|
|
|
+ //差集拼接 开始 和 结束时间
|
|
|
|
+ List<Map<String, String>> stringList = SettlementUtil.getTime(reduceList);
|
|
|
|
+ for (Map<String, String> stringMap : stringList) {
|
|
|
|
+ ProfitReportBytedanceVo vo = new ProfitReportBytedanceVo();
|
|
|
|
+ // 不使用 政策 则 返点为空
|
|
|
|
+ //政策 返点类型和比例
|
|
|
|
+ /* Map<String,Object> policyRateMap = reportSettlementMapper.getProfitRebate(map.get("productName")+"",stringMap.get("startDate"),stringMap.get("endDate"));
|
|
|
|
+ */
|
|
|
|
+ vo.setRebateType("");//返点类型
|
|
|
|
+ vo.setRebateRate("");//返点比列
|
|
|
|
+ //账户流水 信息
|
|
|
|
+ List<Map<String,Object>> listAccount = reportSettlementMapper.getProfitBytedanceCost(map.get("accountId")+"",stringMap.get("startDate"),stringMap.get("endDate"));
|
|
|
|
+ listAccount.removeAll(Collections.singleton(null));
|
|
|
|
+ vo.setCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("cost","")+"");//总消耗
|
|
|
|
+ vo.setCost(String.format("%.3f",new Double(vo.getCost())));
|
|
|
|
+ vo.setCashCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("cashCost","")+"");//现金消耗
|
|
|
|
+ vo.setCashCost(String.format("%.3f",new Double(vo.getCashCost())));
|
|
|
|
+ vo.setRewardCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("rewardCost","")+"");//赠款消耗
|
|
|
|
+ vo.setRewardCost(String.format("%.3f",new Double(vo.getRewardCost())));
|
|
|
|
+ BeanUtils.copyProperties(voSource,vo,SettlementUtil.getNullPropertyNames(voSource));
|
|
|
|
+ vo.setTime((!Check.isNull(vo.getRebateType()) ? stringMap.get("startDate")+"----"+stringMap.get("endDate") : ""));
|
|
|
|
+ resultList.add(vo);
|
|
}
|
|
}
|
|
- resultList.add(vo);
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("头条利润单", "头条利润单"), ProfitReportBytedanceVo.class, resultList);
|
|
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("头条利润单", "头条利润单"), ProfitReportBytedanceVo.class, resultList);
|
|
-
|
|
|
|
try {
|
|
try {
|
|
response.setCharacterEncoding("UTF-8");
|
|
response.setCharacterEncoding("UTF-8");
|
|
response.setHeader("content-Type", "application/vnd.ms-excel");
|
|
response.setHeader("content-Type", "application/vnd.ms-excel");
|
|
- response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("头条利润单.xls", "UTF-8"));
|
|
|
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("头条利润单.xlsx", "UTF-8"));
|
|
workbook.write(response.getOutputStream());
|
|
workbook.write(response.getOutputStream());
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
throw new RuntimeException(e);
|
|
throw new RuntimeException(e);
|
|
@@ -487,14 +656,11 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
- log.error("====>>>>", e.getMessage());
|
|
|
|
return Result.errorMsg(e.getMessage());
|
|
return Result.errorMsg(e.getMessage());
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
* @description: 财务结算 利润表导出 快手
|
|
* @description: 财务结算 利润表导出 快手
|
|
@@ -507,40 +673,130 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
public Result porfitReportKuaiShou(SettlementFileParamsVo paramsVo, HttpServletResponse response) {
|
|
public Result porfitReportKuaiShou(SettlementFileParamsVo paramsVo, HttpServletResponse response) {
|
|
|
|
|
|
try {
|
|
try {
|
|
- //查询 快手利润表 总花费
|
|
|
|
- List<Map<String,Object>> list = reportSettlementMapper.getProfitKuaiShou(paramsVo.getUploadYears());
|
|
|
|
|
|
+ //查询 快手利润表 时间段内的 所有账户
|
|
|
|
+ List<Map<String,Object>> list = reportSettlementMapper.getProfitKuaiShouAgentAccount(paramsVo.getStartTime(),paramsVo.getEndTime());
|
|
if (Check.isNull(list)){
|
|
if (Check.isNull(list)){
|
|
- return Result.errorMsg("暂无数据。");
|
|
|
|
|
|
+ return Result.errorMsg("暂无数据");
|
|
}
|
|
}
|
|
List<ProfitReportKuaiShouVo> resultList = new ArrayList<>(list.size());
|
|
List<ProfitReportKuaiShouVo> resultList = new ArrayList<>(list.size());
|
|
- for (Map<String, Object> map : list) {
|
|
|
|
- ProfitReportKuaiShouVo vo = new ProfitReportKuaiShouVo();
|
|
|
|
- vo.setAccountId(map.getOrDefault("accountId","")+"");//账户id
|
|
|
|
- vo.setCost(map.getOrDefault("cost","")+"");//总消耗
|
|
|
|
- vo.setCashCost(map.getOrDefault("cashCost","")+"");//现金消耗
|
|
|
|
- vo.setProductName(map.getOrDefault("productName","")+"");//产品名称
|
|
|
|
- //查询 销售人员姓名 以及 返点类型和比列
|
|
|
|
- Map<String,Object> slaeMap = reportSettlementMapper.getProfitBytedanceSale(map.get("productId")+"");
|
|
|
|
- if (!Check.isNull(slaeMap)){
|
|
|
|
- vo.setSaleName(slaeMap.getOrDefault("saleName","")+"");//销售
|
|
|
|
- // 当前查询时间 与 销售政策 开始 截至时间 是否匹配
|
|
|
|
- if (SettlementUtil.isEffectiveDate(paramsVo.getUploadYears(),slaeMap.get("policyStart")+"",slaeMap.get("policyEnd")+"")){
|
|
|
|
- //销售政策状态 为 通过 显示 返点类型 和 返点比列
|
|
|
|
- if (StringUtils.equals(slaeMap.getOrDefault("approvedStatus","")+"","3")){
|
|
|
|
- vo.setRebateType(slaeMap.getOrDefault("rebateType","")+"");//返点类型
|
|
|
|
- vo.setRebateRate(slaeMap.getOrDefault("rebateRate","")+"");//返点比列
|
|
|
|
|
|
+ for (Map<String, Object> mapList : list) {
|
|
|
|
+ //查看该账户 状态信息
|
|
|
|
+ /* QueryWrapper<SysLog> sysLogQw = new QueryWrapper<>();
|
|
|
|
+ sysLogQw.eq("log_type", 2);
|
|
|
|
+ //操作类型
|
|
|
|
+ sysLogQw.eq("operate_type", 10001);
|
|
|
|
+ sysLogQw.eq("log_content", "0");//0开 1关
|
|
|
|
+ sysLogQw.eq("request_param", mapList.get("account_id").toString());
|
|
|
|
+ sysLogQw.orderByDesc("create_time");
|
|
|
|
+ sysLogQw.last("limit 1");
|
|
|
|
+ SysLog sysLog = sysLogMapper.selectOne(sysLogQw);
|
|
|
|
+ if (!Check.isNull(sysLog)) {
|
|
|
|
+ SimpleDateFormat m = new SimpleDateFormat("MM");
|
|
|
|
+ String createMonth = m.format(sysLog.getCreateTime());
|
|
|
|
+ int crate = Integer.parseInt(createMonth);
|
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
|
+ int month = cal.get(Calendar.MONTH) + 1;
|
|
|
|
+
|
|
|
|
+ }*/
|
|
|
|
+
|
|
|
|
+ //查询账户数据信息
|
|
|
|
+ Map<String,Object> map = reportSettlementMapper.getProfitKuaiShouAccountCost(mapList.get("account_id").toString(),paramsVo.getStartTime(),paramsVo.getEndTime());
|
|
|
|
+ ProfitReportKuaiShouVo voSource = new ProfitReportKuaiShouVo();
|
|
|
|
+ voSource.setAccountId(map.getOrDefault("accountId", "") + "");//账户id
|
|
|
|
+ voSource.setProductName( !Check.isNull(map.get("productName")) ? map.getOrDefault("productName", "") + "" : "");//产品名称
|
|
|
|
+ voSource.setKsId(map.getOrDefault("ksId", "") + "");//快手id
|
|
|
|
+ voSource.setAdvertiserName(!Check.isNull(map.get("advertiserName")) ? map.getOrDefault("advertiserName", "") + "" : "");//广告主名称
|
|
|
|
+
|
|
|
|
+ //销售
|
|
|
|
+ Map<String, Object> slaeMap = reportSettlementMapper.getProfitReportSale(map.get("accountId") + "");
|
|
|
|
+ voSource.setSaleName(Check.isNull(slaeMap) ? "" : slaeMap.getOrDefault("saleName", "") + "");//销售
|
|
|
|
+ //运营
|
|
|
|
+ Map<String, Object> operateMap = reportSettlementMapper.getProfitReportOperateAndArea(map.get("accountId") + "");
|
|
|
|
+ if (!Check.isNull(operateMap)) {
|
|
|
|
+ voSource.setOperateName(operateMap.getOrDefault("operateName", "") + "");//运营
|
|
|
|
+ voSource.setOperateArea(operateMap.getOrDefault("operateArea", "") + "");//运营所属区域
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //政策所有时间点
|
|
|
|
+ List<String> policyDaysList = new ArrayList<>();
|
|
|
|
+ if (!Check.isNull(map.get("productName"))) {
|
|
|
|
+ //查询 快手利润表 返点类型和比列
|
|
|
|
+ List<Map<String, Object>> rateMap = reportSettlementMapper.getProfitBytedance(map.get("productName") + "", "2", paramsVo.getStartTime(), paramsVo.getEndTime());
|
|
|
|
+ List listPolicyTIme = new ArrayList();
|
|
|
|
+ for (Map<String, Object> rate : rateMap) {
|
|
|
|
+ listPolicyTIme.add(rate.get("policyStartDate"));
|
|
|
|
+ listPolicyTIme.add(rate.get("policyEndDate"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //政策时间 去重 排序
|
|
|
|
+ List<Object> times = SettlementUtil.sortlistTest(listPolicyTIme);
|
|
|
|
+ // 使用政策的时间段 拼接 开始 和 截至 时间
|
|
|
|
+ List<Map<String, String>> arrayList = new ArrayList<>();
|
|
|
|
+ if (!Check.isNull(times)){
|
|
|
|
+ for (int i = 0; i < times.size(); i++) {
|
|
|
|
+ HashMap<String, String> mapTime = new HashMap<>();
|
|
|
|
+ mapTime.put("startDate", times.get(i).toString());
|
|
|
|
+ mapTime.put("endDate", times.size() < 2 ? times.get(i).toString() : times.get(i + 1).toString());
|
|
|
|
+ i += 1;
|
|
|
|
+ arrayList.add(mapTime);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (Map<String, String> stringMap : arrayList) {
|
|
|
|
+ ProfitReportKuaiShouVo vo = new ProfitReportKuaiShouVo();
|
|
|
|
+ //使用政策 返点类型和比例
|
|
|
|
+ Map<String, Object> policyRateMap = reportSettlementMapper.getProfitRebate(map.get("productName") + "", stringMap.get("startDate"), stringMap.get("endDate"));
|
|
|
|
+ if (!Check.isNull(policyRateMap)) {
|
|
|
|
+ if (Integer.valueOf(policyRateMap.get("rebateType").toString()) == 0) {
|
|
|
|
+ vo.setRebateType("返现");//返点类型
|
|
|
|
+ } else if (Integer.valueOf(policyRateMap.get("rebateType").toString()) == 1) {
|
|
|
|
+ vo.setRebateType("返货");
|
|
|
|
+ } else if (Integer.valueOf(policyRateMap.get("rebateType").toString()) == 2) {
|
|
|
|
+ vo.setRebateType("返现+返货");
|
|
|
|
+ }
|
|
|
|
+ vo.setRebateRate(policyRateMap.getOrDefault("rebateRate", "") + "%");//返点比列
|
|
|
|
+ } else {
|
|
|
|
+ vo.setRebateType("");
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // 时间段内 账户流水 信息
|
|
|
|
+ List<Map<String, Object>> listAccount = reportSettlementMapper.getProfitKuaiShouCost(map.get("accountId") + "", stringMap.get("startDate"), stringMap.get("endDate"));
|
|
|
|
+ listAccount.removeAll(Collections.singleton(null));
|
|
|
|
+ vo.setCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("cost", "") + "");//总消耗
|
|
|
|
+ vo.setCashCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("cashCost", "") + "");//现金消耗
|
|
|
|
+ BeanUtils.copyProperties(voSource, vo, SettlementUtil.getNullPropertyNames(voSource));
|
|
|
|
+ vo.setTime(stringMap.get("startDate") + "----" + stringMap.get("endDate"));
|
|
|
|
+ resultList.add(vo);
|
|
|
|
+ policyDaysList.addAll(SettlementUtil.getAllDatesOfTwoTimes(stringMap.get("startDate"), stringMap.get("endDate")));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- Map<String,Object> operateMap = reportSettlementMapper.getProfitKuaiShouOperate(map.get("accountId")+"");
|
|
|
|
- if (!Check.isNull(operateMap)){
|
|
|
|
- vo.setKsId(operateMap.getOrDefault("ksId","")+"");//快手id
|
|
|
|
- vo.setAdvertiserName(operateMap.getOrDefault("advertiserName","")+"");//广告主名称
|
|
|
|
- vo.setOperateName(operateMap.getOrDefault("operateName","")+"");//运营
|
|
|
|
- vo.setOperateArea(operateMap.getOrDefault("operateArea","")+"");//运营所属区域
|
|
|
|
|
|
+
|
|
|
|
+ //不使用政策 的时间段
|
|
|
|
+ // 获取两个日期之间 所有的 时间 年-月-日
|
|
|
|
+ List<String> betweenDaysList = SettlementUtil.getAllDatesOfTwoTimes(paramsVo.getStartTime(), paramsVo.getEndTime());
|
|
|
|
+ // 时间差集(所有时间段 - 使用政策的时间段)
|
|
|
|
+ List<String> reduceList = betweenDaysList.stream().filter(item -> !policyDaysList.contains(item)).collect(Collectors.toList());
|
|
|
|
+ //差集拼接 开始 和 结束时间
|
|
|
|
+ List<Map<String, String>> stringList = SettlementUtil.getTime(reduceList);
|
|
|
|
+ for (Map<String, String> stringMap : stringList) {
|
|
|
|
+ ProfitReportKuaiShouVo vo = new ProfitReportKuaiShouVo();
|
|
|
|
+ // 不使用 政策 则 返点为空
|
|
|
|
+ //政策 返点类型和比例
|
|
|
|
+ /* Map<String,Object> policyRateMap = reportSettlementMapper.getProfitRebate(map.get("productName")+"",stringMap.get("startDate"),stringMap.get("endDate"));
|
|
|
|
+ */
|
|
|
|
+ vo.setRebateType("");//返点类型
|
|
|
|
+ vo.setRebateRate("");//返点比列
|
|
|
|
+ //账户流水 信息
|
|
|
|
+ List<Map<String, Object>> listAccount = reportSettlementMapper.getProfitKuaiShouCost(map.get("accountId") + "", stringMap.get("startDate"), stringMap.get("endDate"));
|
|
|
|
+ listAccount.removeAll(Collections.singleton(null));
|
|
|
|
+ vo.setCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("cost", "") + "");//总消耗
|
|
|
|
+ vo.setCashCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("cashCost", "") + "");//现金消耗
|
|
|
|
+ BeanUtils.copyProperties(voSource, vo, SettlementUtil.getNullPropertyNames(voSource));
|
|
|
|
+ vo.setTime(!Check.isNull(vo.getRebateType()) ? stringMap.get("startDate") + "----" + stringMap.get("endDate") : "");
|
|
|
|
+ resultList.add(vo);
|
|
}
|
|
}
|
|
- resultList.add(vo);
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("快手利润单", "快手利润单"), ProfitReportKuaiShouVo.class, resultList);
|
|
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("快手利润单", "快手利润单"), ProfitReportKuaiShouVo.class, resultList);
|
|
@@ -556,7 +812,6 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
- log.error("====>>>>", e.getMessage());
|
|
|
|
return Result.errorMsg(e.getMessage());
|
|
return Result.errorMsg(e.getMessage());
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
@@ -567,22 +822,23 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
*
|
|
*
|
|
* @description: 给运营发送消息
|
|
* @description: 给运营发送消息
|
|
*
|
|
*
|
|
- * @param userId
|
|
|
|
|
|
+ * @param
|
|
* @return: org.jeecg.common.api.vo.Result
|
|
* @return: org.jeecg.common.api.vo.Result
|
|
* @author: zianY
|
|
* @author: zianY
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public Result sendMessageToOperate(String userId) {
|
|
|
|
- int month = Calendar.getInstance().get(Calendar.MONTH) + 1;
|
|
|
|
|
|
+ public Result sendMessageToOperate() {
|
|
|
|
+ //上个月份
|
|
|
|
+ int month = Calendar.getInstance().get(Calendar.MONTH);
|
|
int productNum = 0;
|
|
int productNum = 0;
|
|
int accountNum = 0;
|
|
int accountNum = 0;
|
|
String productInfo = null;
|
|
String productInfo = null;
|
|
- String message = "运营人{0},您好!您{1}月份有{2}个产品的账户需要进行媒体后台消耗截图上传,共计{3}个账户。产品分别为:{4}。请及时上传,多谢配合!";
|
|
|
|
|
|
+ String message = "{0},您好!您{1}月份有{2}个产品的账户需要进行媒体后台消耗截图上传,共计{3}个账户。产品分别为:{4}。请及时上传,多谢配合!";
|
|
|
|
|
|
//查询所有 运营绑定的账户
|
|
//查询所有 运营绑定的账户
|
|
List<Map<String,Object>> userList = reportSettlementMapper.getAccountOperateUserId();
|
|
List<Map<String,Object>> userList = reportSettlementMapper.getAccountOperateUserId();
|
|
for (Map<String, Object> userMap : userList) {
|
|
for (Map<String, Object> userMap : userList) {
|
|
- userId = userMap.get("userId").toString();
|
|
|
|
|
|
+ String userId = userMap.get("userId").toString();
|
|
//查询运营下的 账户 和 产品信息
|
|
//查询运营下的 账户 和 产品信息
|
|
List<Map<String,Object>> productList = reportSettlementMapper.getAccountAndProductByOperate(userId);
|
|
List<Map<String,Object>> productList = reportSettlementMapper.getAccountAndProductByOperate(userId);
|
|
if (Check.isNull(productList)){
|
|
if (Check.isNull(productList)){
|
|
@@ -595,19 +851,73 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
productInfo = StringUtils.join(product.toArray(),"、");
|
|
productInfo = StringUtils.join(product.toArray(),"、");
|
|
|
|
|
|
//发送微信通知
|
|
//发送微信通知
|
|
- JSONObject jsonObject = mailLogMapper.getWChatIdByUserId("f990f815ecef43fab9cbe1bb22bb6d63");
|
|
|
|
|
|
+ JSONObject jsonObject = mailLogMapper.getWChatIdByUserId(userId);
|
|
String msg = MessageFormat.format(message,userMap.get("userName").toString(),month,productNum,accountNum,productInfo);
|
|
String msg = MessageFormat.format(message,userMap.get("userName").toString(),month,productNum,accountNum,productInfo);
|
|
corpWexinUtils.sendMessageByWeChatId(jsonObject,msg);
|
|
corpWexinUtils.sendMessageByWeChatId(jsonObject,msg);
|
|
}
|
|
}
|
|
- return Result.successMsg("成功。",null);
|
|
|
|
|
|
+ return Result.successMsg("成功",null);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public Result sendMessageToOperateDemo(String userId) {
|
|
|
|
+ //上个月份
|
|
|
|
+ int month = Calendar.getInstance().get(Calendar.MONTH);
|
|
|
|
+ int productNum = 0;
|
|
|
|
+ int accountNum = 0;
|
|
|
|
+ String productInfo = null;
|
|
|
|
+ String message = "{0},您好!您{1}月份有{2}个产品的账户需要进行媒体后台消耗截图上传,共计{3}个账户。产品分别为:{4}。请及时上传,多谢配合!";
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
|
- String a = "woshiwoshi{1}woshi{2}111{3}===";
|
|
|
|
- String b = MessageFormat.format(a,"测试","我","你","结束");
|
|
|
|
- System.out.println(a);
|
|
|
|
- System.out.println(b);
|
|
|
|
|
|
+ //查询所有 运营绑定的账户
|
|
|
|
+ List<Map<String,Object>> userList = reportSettlementMapper.getAccountOperateUserId();
|
|
|
|
+ for (Map<String, Object> userMap : userList) {
|
|
|
|
+ String realUserId = userMap.get("userId").toString();
|
|
|
|
+ //查询运营下的 账户 和 产品信息
|
|
|
|
+ List<Map<String,Object>> productList = reportSettlementMapper.getAccountAndProductByOperate(realUserId);
|
|
|
|
+ if (Check.isNull(productList)){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ //产品名称
|
|
|
|
+ List product = productList.stream().map(map -> map.get("productName")).distinct().collect(Collectors.toList());
|
|
|
|
+ productNum = product.size();
|
|
|
|
+ accountNum = productList.size();
|
|
|
|
+ productInfo = StringUtils.join(product.toArray(),"、");
|
|
|
|
+
|
|
|
|
+ //发送微信通知
|
|
|
|
+ JSONObject jsonObject = mailLogMapper.getWChatIdByUserId(Check.isNull(userId) ? "f990f815ecef43fab9cbe1bb22bb6d63" : userId);
|
|
|
|
+ String msg = MessageFormat.format(message,userMap.get("userName").toString(),month,productNum,accountNum,productInfo);
|
|
|
|
+ corpWexinUtils.sendMessageByWeChatId(jsonObject,msg);
|
|
|
|
+ }
|
|
|
|
+ return Result.successMsg("发送微信通知成功-test",null);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private CwjsPolicyProductMapper cwjsPolicyProductMapper;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void cwjsPRofit(CwjsPolicyInfo cwjsPolicyInfo) {
|
|
|
|
+
|
|
|
|
+ // 获取两个日期之间 所有的 时间 年-月-日
|
|
|
|
+ List<String> betweenDaysList = SettlementUtil.getAllDatesOfTwoTimes(cwjsPolicyInfo.getPolicyStartDate(),cwjsPolicyInfo.getPolicyEndDate());
|
|
|
|
+ //查看 政策下的产品
|
|
|
|
+ List<CwjsPolicyProduct> productList = cwjsPolicyProductMapper.queryProductsByPolicyId(cwjsPolicyInfo.getId());
|
|
|
|
+ if (!Check.isNull(productList)){
|
|
|
|
+ if (!Check.isNull(betweenDaysList)){
|
|
|
|
+ List<CtopCwjsSlettementReport> reportList = new ArrayList<>();
|
|
|
|
+ for (CwjsPolicyProduct product : productList) {
|
|
|
|
+ for (String day : betweenDaysList) {
|
|
|
|
+ CtopCwjsSlettementReport report = new CtopCwjsSlettementReport();
|
|
|
|
+ report.setPolicyId(cwjsPolicyInfo.getId());
|
|
|
|
+ report.setAdvertiserName(cwjsPolicyInfo.getAdvertiserName());
|
|
|
|
+ report.setProductName(product.getPolicyProductName());
|
|
|
|
+ report.setMediaType(cwjsPolicyInfo.getMediaType());
|
|
|
|
+ report.setCreateUserId(cwjsPolicyInfo.getCreateUserId());
|
|
|
|
+ report.setPolicyDate(day);
|
|
|
|
+ reportList.add(report);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ cwjsProfitMapper.replaceCwjsSlettementProfit(reportList);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|