浏览代码

Merge branch 'test' of http://git.tjyourong.com.cn/ctop/adsp-cloud into test

zhaoxian 3 年之前
父节点
当前提交
30bfe19728

+ 9 - 5
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/service/impl/CreateSheetServiceImpl.java

@@ -117,6 +117,8 @@ public class CreateSheetServiceImpl implements ICreateSheetService {
         cell.setCellStyle(style);
         sheet.autoSizeColumn(0, true);
         List<SheetBytedanceVo> resultList = new ArrayList<>(accountIdList.size());
+        //获取当前年月的 第一天 和 最后一天
+        Map<String,String> timeMap = SettlementUtil.getFirstAndLastDayOfMonth(uploadYears);
         //查看账户数据
         List<Map<String,Object>> list = reportSettlementMapper.getAccountTransactionDayBytedanceSheet(accountIdList,uploadYears);
         for (Map<String,Object> map : list) {
@@ -130,7 +132,7 @@ public class CreateSheetServiceImpl implements ICreateSheetService {
             List<String> policyDaysList = new ArrayList<>();
             if (!Check.isNull(map.get("productName"))){
                 //查询 头条利润表  返点类型和比列
-                List<Map<String,Object>> rateMap = reportSettlementMapper.getProfitBytedance(map.get("advertiserName")+"",map.get("productName")+"",null,"1",uploadYears+"-01",uploadYears+"-31");
+                List<Map<String,Object>> rateMap = reportSettlementMapper.getProfitBytedance(map.get("advertiserName")+"",map.get("productName")+"",null,"1",timeMap.get("startTime"),timeMap.get("endTime"));
                 List listPolicyTIme = new ArrayList();
                 for (Map<String, Object> rate : rateMap) {
                     listPolicyTIme.add(rate.get("policyStartDate"));
@@ -187,7 +189,7 @@ public class CreateSheetServiceImpl implements ICreateSheetService {
 
             //不使用政策 的时间段
             // 获取两个日期之间 所有的 时间 年-月-日
-            List<String> betweenDaysList = SettlementUtil.getAllDatesOfTwoTimes(uploadYears+"-01",uploadYears+"-31");
+            List<String> betweenDaysList = SettlementUtil.getAllDatesOfTwoTimes(timeMap.get("startTime"),timeMap.get("endTime"));
             // 时间差集(所有时间段 - 使用政策的时间段)
             List<String>  reduceList = betweenDaysList.stream().filter(item -> !policyDaysList.contains(item)).collect(Collectors.toList());
             //差集拼接  开始 和 结束时间
@@ -332,7 +334,9 @@ public class CreateSheetServiceImpl implements ICreateSheetService {
 
         List<SheetKuaiShouVo> resultList = new ArrayList<>(accountIdList.size());
         //查询该时段 快手 数据
-        List<Map<String,Object>> accountList = reportSettlementMapper.getProfitKuaiShouAccountCostSheet(accountIdList,uploadYears+"-01",uploadYears+"-31");
+        //获取当前年月的 第一天 和 最后一天
+        Map<String,String> timeMap = SettlementUtil.getFirstAndLastDayOfMonth(uploadYears);
+        List<Map<String,Object>> accountList = reportSettlementMapper.getProfitKuaiShouAccountCostSheet(accountIdList,timeMap.get("startTime"),timeMap.get("endTime"));
         for (Map<String,Object> map : accountList) {
             SheetKuaiShouVo voSource = new SheetKuaiShouVo();
             voSource.setAccountId(map.get("accountId")+"");
@@ -343,7 +347,7 @@ public class CreateSheetServiceImpl implements ICreateSheetService {
             List<String> policyDaysList = new ArrayList<>();
             if (!Check.isNull(map.get("productName"))) {
                 //查询 快手利润表  返点类型和比列
-                List<Map<String, Object>> rateMap = reportSettlementMapper.getProfitBytedance(map.get("advertiserName")+"",map.get("productName") + "", null,"2", uploadYears+"-01",uploadYears+"-31");
+                List<Map<String, Object>> rateMap = reportSettlementMapper.getProfitBytedance(map.get("advertiserName")+"",map.get("productName") + "", null,"2", timeMap.get("startTime"),timeMap.get("endTime"));
                 List listPolicyTIme = new ArrayList();
                 for (Map<String, Object> rate : rateMap) {
                     listPolicyTIme.add(rate.get("policyStartDate"));
@@ -406,7 +410,7 @@ public class CreateSheetServiceImpl implements ICreateSheetService {
 
             //不使用政策 的时间段
             // 获取两个日期之间 所有的 时间 年-月-日
-            List<String> betweenDaysList = SettlementUtil.getAllDatesOfTwoTimes(uploadYears+"-01",uploadYears+"-31");
+            List<String> betweenDaysList = SettlementUtil.getAllDatesOfTwoTimes(timeMap.get("startTime"),timeMap.get("endTime"));
             // 时间差集(所有时间段 - 使用政策的时间段)
             List<String> reduceList = betweenDaysList.stream().filter(item -> !policyDaysList.contains(item)).collect(Collectors.toList());
             //差集拼接  开始 和 结束时间

+ 7 - 2
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/service/serviceImpl/ReportSettlementServiceImpl.java

@@ -252,8 +252,10 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
                         BufferedImage bufferImg = createExcelByTemplate.toBufferedImage(imageTookittitle);
                         ImageIO.write(bufferImg, imagePath.substring(imagePath.lastIndexOf(".") + 1), byteArrayOut);
                         int startIndex = settlementList.size() +6;
+                        int hight = (int)Math.round(bufferImg.getHeight() / 28.35 / (sheet.getDefaultRowHeightInPoints() / 28.35));
+                        int width = (int)Math.round(bufferImg.getWidth() / (96/2.54) / ((sheet.getColumnWidthInPixels(settlementList.size()) / (96 / 2.54))));
                         //anchor主要用于设置图片的属性
-                        HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 255, 255, (short) 0, startIndex+(5*j)+50*j, (short) 25, startIndex+(5*j)+50*(j+1));
+                        HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 255, 255, (short) 0, startIndex+(5*j)+hight*j, (short) width, startIndex+(5*j)+hight*(j+1));
                         //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);
                         //插入图片
@@ -496,7 +498,10 @@ public class ReportSettlementServiceImpl implements IReportSettlementService {
                         ImageIO.write(bufferImg, imagePath.substring(imagePath.lastIndexOf(".") + 1), byteArrayOut);
                         //anchor主要用于设置图片的属性
                         int startIndex = settlementList.size()+7;
-                        HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 255, 255, (short) 0, startIndex+(5*j)+50*j, (short) 25, startIndex+(5*j)+50*(j+1));
+                        int hight = (int)Math.round(bufferImg.getHeight() / 28.35 / (sheet.getDefaultRowHeightInPoints() / 28.35));
+                        int width = (int)Math.round(bufferImg.getWidth() / (96/2.54) / ((sheet.getColumnWidthInPixels(settlementList.size()) / (96 / 2.54))));
+                        HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 255, 255, (short) 0, startIndex+(5*j)+hight*j, (short) width, startIndex+(5*j)+hight*(j+1));
+
                         //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);
                         //插入图片

+ 70 - 0
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/utils/SettlementUtil.java

@@ -294,4 +294,74 @@ public class SettlementUtil {
         return dayAfter;
     }
 
+
+    /**
+     * 获取当前日期 年-月 的 第一天和最后一天
+     */
+    public static Map<String,String> getFirstAndLastDayOfMonth(String yearMonth){
+        Map<String,String> map = new HashMap<>();
+        String[] year = yearMonth.split("-");
+        Integer y = Integer.valueOf(year[0]);
+        Integer m = Integer.valueOf(year[1]);
+        String firstDay = getFirstDayOfMonth(y,m);
+        String lastDay = getLastDayOfMonth(y,m);
+        map.put("startTime",firstDay);
+        map.put("endTime",lastDay);
+        return map;
+    }
+
+
+
+
+
+    /**
+     * 获取指定年月的第一天
+     * @param year
+     * @param month
+     * @return
+     */
+    public static String getFirstDayOfMonth(int year, int month) {
+        Calendar cal = Calendar.getInstance();
+        //设置年份
+        cal.set(Calendar.YEAR, year);
+        //设置月份
+        cal.set(Calendar.MONTH, month-1);
+        //获取某月最小天数
+        int firstDay = cal.getMinimum(Calendar.DATE);
+        //设置日历中月份的最小天数
+        cal.set(Calendar.DAY_OF_MONTH,firstDay);
+        //格式化日期
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        return sdf.format(cal.getTime());
+    }
+
+
+    /**
+     * 获取指定年月的最后一天
+     * @param year
+     * @param month
+     * @return
+     */
+    public static String getLastDayOfMonth(int year, int month) {
+        Calendar cal = Calendar.getInstance();
+        //设置年份
+        cal.set(Calendar.YEAR, year);
+        //设置月份
+        cal.set(Calendar.MONTH, month-1);
+        //获取某月最大天数
+        int lastDay = cal.getActualMaximum(Calendar.DATE);
+        //设置日历中月份的最大天数
+        cal.set(Calendar.DAY_OF_MONTH, lastDay);
+        //格式化日期
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        return sdf.format(cal.getTime());
+    }
+
+
+    public static void main(String[] args) {
+        System.out.println(getFirstAndLastDayOfMonth("2021-02").get("startTime"));;
+        System.out.println(getFirstAndLastDayOfMonth("2021-02").get("endTime"));;
+    }
+
+
 }