|
@@ -2,7 +2,12 @@ package org.jeecg.ctop.finance.settlement.service.serviceImpl;
|
|
|
|
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
|
|
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.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.ImageUtils;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -16,6 +21,9 @@ import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
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;
|
|
@@ -29,6 +37,7 @@ import org.jeecg.ctop.finance.settlement.mapper.SettlementInfoMapper;
|
|
|
import org.jeecg.ctop.finance.settlement.service.IReportSettlementService;
|
|
|
import org.jeecg.ctop.finance.utils.SettlementUtil;
|
|
|
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;
|
|
@@ -43,6 +52,7 @@ import java.io.*;
|
|
|
import java.net.URL;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.text.MessageFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -51,29 +61,31 @@ import java.util.stream.Collectors;
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
|
-
|
|
|
@Resource
|
|
|
private ReportSettlementMapper reportSettlementMapper;
|
|
|
-
|
|
|
@Resource
|
|
|
private CorpWexinUtils corpWexinUtils;
|
|
|
@Resource
|
|
|
private MailLogMapper mailLogMapper;
|
|
|
-
|
|
|
@Resource
|
|
|
private CwjsProfitMapper cwjsProfitMapper;
|
|
|
+ @Resource
|
|
|
+ private UserAllocationMapper userAllocationMapper;
|
|
|
+ @Resource
|
|
|
+ private SysRoleMapper roleMapper;
|
|
|
+ @Autowired
|
|
|
+ private IMaterialReportOverViewService materialReportOverViewService;
|
|
|
+ @Resource
|
|
|
+ private SysLogMapper sysLogMapper;
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public List<SettlementReportBytedanceVo> getAccountTransactionDayBytedance() {
|
|
|
return reportSettlementMapper.getAccountTransactionDayBytedance(null);
|
|
|
}
|
|
|
-
|
|
|
@Override
|
|
|
- public Result settlementReportBytedance(SettlementFileParamsVo paramsVo, HttpServletResponse response) {
|
|
|
-
|
|
|
+ public Result settlementReportBytedance(SettlementFileParamsVo paramsVo, HttpServletResponse response, SysUser user) {
|
|
|
try {
|
|
|
-
|
|
|
//第一步创建workbook
|
|
|
HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
|
|
@@ -88,7 +100,7 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
|
style.setFont(font);
|
|
|
|
|
|
//查询 账户id
|
|
|
- List<String> accountIdList = reportSettlementMapper.getAccountIdBytedance(paramsVo);
|
|
|
+ List<String> accountIdList = this.getAccountId(paramsVo,user);
|
|
|
|
|
|
if (Check.isNull(accountIdList)){
|
|
|
return Result.errorMsg("该广告主和产品下无法查询到绑定的账户信息");
|
|
@@ -97,7 +109,6 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
|
int num = 0;
|
|
|
|
|
|
for (int k = 0; k < accountIdList.size(); k++) {
|
|
|
-
|
|
|
String accountId = accountIdList.get(k);
|
|
|
paramsVo.setAccountId(accountId);
|
|
|
|
|
@@ -128,23 +139,23 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
|
|
|
|
//5:创建第2行的单元格
|
|
|
HSSFCell cell = row.createCell(0); //第一个单元格
|
|
|
- cell.setCellValue(" 日期 "); //设定值
|
|
|
+ cell.setCellValue("日期"); //设定值
|
|
|
cell.setCellStyle(style); //内容居中
|
|
|
|
|
|
cell = row.createCell(1);
|
|
|
- cell.setCellValue(" 账户名称 ");
|
|
|
+ cell.setCellValue("账户名称");
|
|
|
cell.setCellStyle(style);
|
|
|
|
|
|
cell = row.createCell(2);
|
|
|
- cell.setCellValue(" 账户ID ");
|
|
|
+ cell.setCellValue("账户ID");
|
|
|
cell.setCellStyle(style);
|
|
|
|
|
|
cell = row.createCell(3);
|
|
|
- cell.setCellValue(" 所属代理商名称 ");
|
|
|
+ cell.setCellValue("所属代理商名称");
|
|
|
cell.setCellStyle(style);
|
|
|
|
|
|
cell = row.createCell(4);
|
|
|
- cell.setCellValue(" 所属代理商ID ");
|
|
|
+ cell.setCellValue("所属代理商ID");
|
|
|
cell.setCellStyle(style);
|
|
|
|
|
|
cell = row.createCell(5);
|
|
@@ -179,9 +190,6 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
|
cell.setCellValue("冻结(¥)");
|
|
|
cell.setCellStyle(style);
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
for (int i = 0; i < settlementList.size(); i++) {
|
|
|
SettlementReportBytedanceVo vo = settlementList.get(i);
|
|
|
//创建行 (表头占0-1行 所以 从 2开始)
|
|
@@ -204,8 +212,6 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
|
row.createCell(12).setCellValue(vo.getFrozen());
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
//查询 图片 url
|
|
|
List<String> imageUrlList = reportSettlementMapper.getAccountImagesBytedance(accountId,paramsVo.getUploadYears());
|
|
|
|
|
@@ -252,19 +258,64 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
|
output.close();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- log.error("====>>>>", e.getMessage());
|
|
|
return Result.errorMsg(e.getMessage());
|
|
|
}
|
|
|
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();
|
|
|
+ List<String> settlementAccountList = reportSettlementMapper.getAccountIdBytedance(paramsVo);
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ allocations = userAllocationMapper.getAccountInfoBySalesId(sales,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
|
|
|
- public Result settlementReportKuaiShou(SettlementFileParamsVo paramsVo, HttpServletResponse response) {
|
|
|
-
|
|
|
+ public Result settlementReportKuaiShou(SettlementFileParamsVo paramsVo, HttpServletResponse response, SysUser user) {
|
|
|
try {
|
|
|
-
|
|
|
//第一步创建workbook
|
|
|
HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
|
|
@@ -279,16 +330,14 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
|
style.setFont(font);
|
|
|
|
|
|
//查询 需要导出的数据的账户id
|
|
|
- List<String> accountIdList = reportSettlementMapper.getAccountIdBytedance(paramsVo);
|
|
|
+ List<String> accountIdList = this.getAccountId(paramsVo,user);
|
|
|
|
|
|
if (Check.isNull(accountIdList)){
|
|
|
return Result.errorMsg("该广告主和产品下无法查询到绑定的快手账户信息");
|
|
|
}
|
|
|
|
|
|
int num = 0;
|
|
|
-
|
|
|
for (int k = 0; k < accountIdList.size(); k++) {
|
|
|
-
|
|
|
String accountId = accountIdList.get(k);
|
|
|
paramsVo.setAccountId(accountId);
|
|
|
|
|
@@ -449,16 +498,11 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
|
output.close();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- log.error("====>>>>", e.getMessage());
|
|
|
return Result.errorMsg(e.getMessage());
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- @Resource
|
|
|
- private SettlementInfoMapper settlementInfoMapper;
|
|
|
/**
|
|
|
*
|
|
|
* @description: 财务结算 利润表导出 头条
|
|
@@ -469,89 +513,105 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
|
*/
|
|
|
@Override
|
|
|
public Result porfitReportBytedance(SettlementFileParamsVo paramsVo, HttpServletResponse response) {
|
|
|
-
|
|
|
try {
|
|
|
//查询 头条利润表 时间段内 所有 账户
|
|
|
- List<Map<String,Object>> list = reportSettlementMapper.getProfitBytedanceAccountCost(null,paramsVo.getStartTime(),paramsVo.getEndTime());
|
|
|
+ List<Map<String,Object>> list = reportSettlementMapper.getProfitBytedanceAccount(paramsVo.getStartTime(),paramsVo.getEndTime());
|
|
|
if (Check.isNull(list)){
|
|
|
return Result.errorMsg("暂无数据");
|
|
|
}
|
|
|
List<ProfitReportBytedanceVo> resultList = new ArrayList<>(list.size());
|
|
|
- for (Map<String, Object> map : list) {
|
|
|
- /* //查看该账户 状态信息
|
|
|
- QueryWrapper<CtopCwjsSettlementInfo> settlementAccountQw = new QueryWrapper<>();
|
|
|
- settlementAccountQw.eq("account_id",map.get("accountId"));
|
|
|
- //账户状态 0-开 1-关
|
|
|
- settlementAccountQw.eq("status",0);
|
|
|
- //(0,正常,1已删除)
|
|
|
- settlementAccountQw.eq("del_flag",0);
|
|
|
- List<CtopCwjsSettlementInfo> settlementAccountList = settlementInfoMapper.selectList(settlementAccountQw);
|
|
|
- if (Check.isNull(settlementAccountList)){
|
|
|
- continue;
|
|
|
+ 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();
|
|
|
- //查询销售
|
|
|
- Map<String,Object> slaeMap = reportSettlementMapper.getProfitBytedanceSale(map.get("accountId")+"");
|
|
|
- voSource.setSaleName(Check.isNull(slaeMap) ? "" : slaeMap.getOrDefault("saleName","")+"");//销售
|
|
|
+ voSource.setAccountId(map.get("accountId")+"");
|
|
|
|
|
|
+ voSource.setAdvertiserName(!Check.isNull(map.get("advertiserName")) ? map.getOrDefault("advertiserName","")+"" : "" );//广告主名称
|
|
|
//产品名称
|
|
|
- voSource.setProductName(map.getOrDefault("productName","")+"");
|
|
|
+ voSource.setProductName(!Check.isNull(map.get("productName")) ? map.getOrDefault("productName","")+"" : "" );
|
|
|
+
|
|
|
|
|
|
- Map<String,Object> operateMap = reportSettlementMapper.getProfitBytedanceOperate(map.get("accountId")+"");
|
|
|
+ //查询销售
|
|
|
+ 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.setAdvertiserName(operateMap.getOrDefault("advertiserName","")+"");//广告主名称
|
|
|
voSource.setOperateName(operateMap.getOrDefault("operateName","")+"");//运营
|
|
|
voSource.setOperateArea(operateMap.getOrDefault("operateArea","")+"");//运营所属区域
|
|
|
}
|
|
|
-
|
|
|
- //查询 头条利润表 返点类型和比列
|
|
|
- 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.get(i+1).toString());
|
|
|
- i += 1;
|
|
|
- arrayList.add(mapTime);
|
|
|
- }
|
|
|
-
|
|
|
//政策所有时间点
|
|
|
List<String> policyDaysList = new ArrayList<>();
|
|
|
- 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("返现+返货");
|
|
|
+ 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("");
|
|
|
}
|
|
|
- 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")));
|
|
|
}
|
|
|
- // 时间段内 账户流水 信息
|
|
|
- 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.setCashCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("cashCost","")+"");//现金消耗
|
|
|
- vo.setRewardCost(Check.isNull(listAccount) ? "0" : listAccount.get(0).getOrDefault("rewardCost","")+"");//赠款消耗
|
|
|
- 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")));
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//不使用政策 的时间段
|
|
@@ -573,10 +633,13 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
|
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"));
|
|
|
+ vo.setTime((!Check.isNull(vo.getRebateType()) ? stringMap.get("startDate")+"----"+stringMap.get("endDate") : ""));
|
|
|
resultList.add(vo);
|
|
|
}
|
|
|
}
|
|
@@ -592,14 +655,11 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- log.error("====>>>>", e.getMessage());
|
|
|
return Result.errorMsg(e.getMessage());
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
*
|
|
|
* @description: 财务结算 利润表导出 快手
|
|
@@ -613,96 +673,109 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
|
|
|
|
try {
|
|
|
//查询 快手利润表 时间段内的 所有账户
|
|
|
- List<Map<String,Object>> list = reportSettlementMapper.getProfitKuaiShouAccountCost(null,paramsVo.getStartTime(),paramsVo.getEndTime());
|
|
|
+ List<Map<String,Object>> list = reportSettlementMapper.getProfitKuaiShouAgentAccount(paramsVo.getStartTime(),paramsVo.getEndTime());
|
|
|
if (Check.isNull(list)){
|
|
|
return Result.errorMsg("暂无数据");
|
|
|
}
|
|
|
List<ProfitReportKuaiShouVo> resultList = new ArrayList<>(list.size());
|
|
|
- for (Map<String, Object> map : list) {
|
|
|
- /* //查看该账户 状态信息
|
|
|
- QueryWrapper<CtopCwjsSettlementInfo> settlementAccountQw = new QueryWrapper<>();
|
|
|
- settlementAccountQw.eq("account_id",map.get("accountId"));
|
|
|
- //账户状态 0-开 1-关
|
|
|
- settlementAccountQw.eq("status",0);
|
|
|
- //(0,正常,1已删除)
|
|
|
- settlementAccountQw.eq("del_flag",0);
|
|
|
- List<CtopCwjsSettlementInfo> settlementAccountList = settlementInfoMapper.selectList(settlementAccountQw);
|
|
|
- if (Check.isNull(settlementAccountList)){
|
|
|
- continue;
|
|
|
- }
|
|
|
-*/
|
|
|
- ProfitReportKuaiShouVo voSource = new ProfitReportKuaiShouVo();
|
|
|
-
|
|
|
- voSource.setAccountId(map.getOrDefault("accountId","")+"");//账户id
|
|
|
- voSource.setProductName(map.getOrDefault("productName","")+"");//产品名称
|
|
|
- voSource.setKsId(map.getOrDefault("ksId","")+"");//快手id
|
|
|
- voSource.setAdvertiserName(map.getOrDefault("advertiserName","")+"");//广告主名称
|
|
|
-
|
|
|
- //查询销售
|
|
|
- Map<String,Object> slaeMap = reportSettlementMapper.getProfitBytedanceSale(map.get("accountId")+"");
|
|
|
- voSource.setSaleName(Check.isNull(slaeMap) ? "" : slaeMap.getOrDefault("saleName","")+"");//销售
|
|
|
-
|
|
|
- Map<String,Object> operateMap = reportSettlementMapper.getProfitKuaiShouOperate(map.get("accountId")+"");
|
|
|
- if (!Check.isNull(operateMap)){
|
|
|
- voSource.setOperateName(operateMap.getOrDefault("operateName","")+"");//运营
|
|
|
- voSource.setOperateArea(operateMap.getOrDefault("operateArea","")+"");//运营所属区域
|
|
|
- }
|
|
|
+ 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;
|
|
|
|
|
|
- //查询 快手利润表 返点类型和比列
|
|
|
- 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<>();
|
|
|
- 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.get(i+1).toString());
|
|
|
- i += 1;
|
|
|
- arrayList.add(mapTime);
|
|
|
+ //查询账户数据信息
|
|
|
+ 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<>();
|
|
|
- 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("返现+返货");
|
|
|
+ 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);
|
|
|
}
|
|
|
- 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")));
|
|
|
+ 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")));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//不使用政策 的时间段
|
|
|
// 获取两个日期之间 所有的 时间 年-月-日
|
|
|
- List<String> betweenDaysList = SettlementUtil.getAllDatesOfTwoTimes(paramsVo.getStartTime(),paramsVo.getEndTime());
|
|
|
+ List<String> betweenDaysList = SettlementUtil.getAllDatesOfTwoTimes(paramsVo.getStartTime(), paramsVo.getEndTime());
|
|
|
// 时间差集(所有时间段 - 使用政策的时间段)
|
|
|
- List<String> reduceList = betweenDaysList.stream().filter(item -> !policyDaysList.contains(item)).collect(Collectors.toList());
|
|
|
+ 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) {
|
|
@@ -714,12 +787,12 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
|
vo.setRebateType("");//返点类型
|
|
|
vo.setRebateRate("");//返点比列
|
|
|
//账户流水 信息
|
|
|
- List<Map<String,Object>> listAccount = reportSettlementMapper.getProfitKuaiShouCost(map.get("accountId")+"",stringMap.get("startDate"),stringMap.get("endDate"));
|
|
|
+ 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"));
|
|
|
+ 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);
|
|
|
}
|
|
|
|
|
@@ -738,7 +811,6 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- log.error("====>>>>", e.getMessage());
|
|
|
return Result.errorMsg(e.getMessage());
|
|
|
}
|
|
|
return null;
|
|
@@ -847,5 +919,4 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|