瀏覽代碼

报表 自定义列

zhaoxian 2 年之前
父節點
當前提交
fda421b436

+ 19 - 0
ruixuan-live/src/main/java/com/ruixuan/report/controller/KuaishouLiveAccountReportController.java

@@ -118,6 +118,25 @@ public class KuaishouLiveAccountReportController extends BaseController {
         return getDataTable(list);
     }
 
+    @ApiOperation(value = "获取报表字段")
+    @GetMapping("/getReportFields")
+    public Result getReportFields() {
+        return KuaishouLiveAccountReportService.getReportFields();
+    }
+
+    @ApiOperation(value = "记录人员报表字段")
+    @PostMapping("/addKuaishouFields")
+    public Result addKuaishouFields(@RequestBody JSONObject request) {
+        return KuaishouLiveAccountReportService.addKuaishouFields(request);
+    }
+
+    @ApiOperation(value = "获取人员报表字段")
+    @GetMapping("/getKuaishouFieldsByUserId")
+    public Result addKuaishouFields(@ApiParam("userId") @RequestParam(value = "userId", required = true) Long userId,
+                                    @ApiParam("columnType") @RequestParam(value = "columnType", required = true) String columnType) {
+        return KuaishouLiveAccountReportService.getKuaishouFieldsByUserId(userId, columnType);
+    }
+
     @ApiOperation(value = "导出账户数据报表")
     @PostMapping("/exportAccountDataReport")
     public void exportAccountDataReport(@RequestBody JSONObject request, HttpServletResponse response) {

+ 5 - 0
ruixuan-live/src/main/java/com/ruixuan/report/mapper/KuaishouLiveAccountReportMapper.java

@@ -2,6 +2,7 @@ package com.ruixuan.report.mapper;
 
 
 import com.alibaba.fastjson.JSONObject;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 import java.util.Map;
@@ -70,4 +71,8 @@ public interface KuaishouLiveAccountReportMapper {
     List<JSONObject> getAccountDataReportByHourly(Map<String, Object> map);
 
     List<JSONObject> getAccountDataReportByDaily(Map<String, Object> map);
+
+    void replaceKuaishouFields(@Param("request") JSONObject request);
+
+    JSONObject getKuaishouFieldsByUserId(@Param("userId") Long userId, @Param("columnType") String columnType);
 }

+ 6 - 0
ruixuan-live/src/main/java/com/ruixuan/report/service/IKuaishouLiveAccountReportService.java

@@ -33,4 +33,10 @@ public interface IKuaishouLiveAccountReportService {
     List<JSONObject> getAccountDataReport(JSONObject request);
 
     List<JSONObject> exportAccountDataReport(JSONObject request);
+
+    Result getReportFields();
+
+    Result addKuaishouFields(JSONObject request);
+
+    Result getKuaishouFieldsByUserId(Long userId, String columnType);
 }

+ 18 - 21
ruixuan-live/src/main/java/com/ruixuan/report/service/impl/KuaishouLiveAccountReportServiceImpl.java

@@ -336,6 +336,24 @@ public class KuaishouLiveAccountReportServiceImpl implements IKuaishouLiveAccoun
         }
     }
 
+    @Override
+    public Result getReportFields() {
+        List<JSONObject> fieldsNames = JsonResourceUtil.getFieldsNames(AccountReportConstants.getKuaishouAccountReport());
+        return Result.success(fieldsNames);
+    }
+
+    @Override
+    public Result addKuaishouFields(JSONObject request) {
+        mapper.replaceKuaishouFields(request);
+        return Result.success();
+    }
+
+    @Override
+    public Result getKuaishouFieldsByUserId(Long userId, String columnType) {
+        JSONObject o = mapper.getKuaishouFieldsByUserId(userId, columnType);
+        return Result.success(o);
+    }
+
 
     /*补全数据,排序 */
     private void completeDate(List<JSONObject> list, List<String> allDates) {
@@ -357,27 +375,6 @@ public class KuaishouLiveAccountReportServiceImpl implements IKuaishouLiveAccoun
         });
     }
 
-
-    /*补全小时数据,排序 */
-    private void completeHour(List<JSONObject> list) {
-        List<Integer> newDayList = new ArrayList<>();
-        for (JSONObject data : list) {
-            newDayList.add(data.getInteger("time"));
-        }
-        List<Integer> dayList = new ArrayList<>();
-        for (int i = 0; i <= 23; i++) {
-            dayList.add(i);
-        }
-        for (Integer hour : dayList) {
-            if (!newDayList.contains(hour)) {
-                JSONObject obj = new JSONObject();
-                obj.put("time", hour);
-                obj.put("costTotal", 0);
-                list.add(obj);
-            }
-        }
-    }
-
     /*根据入参时间,整理上个时间周期,并判断查询日报OR时报*/
     private Map<String, Object> getDateTime(String startDate, String endDate) {
         Map<String, Object> map = new HashMap<>();

+ 20 - 5
ruixuan-live/src/main/java/com/ruixuan/report/utils/JsonResourceUtil.java

@@ -82,11 +82,11 @@ public class JsonResourceUtil {
     /**
      * 拼接字段
      */
-    public static String joinFiled(Map<String, Map<String,Object>> mapMap,JSONArray array) {
+    public static String joinFiled(Map<String, Map<String, Object>> mapMap, JSONArray array) {
         StringBuilder sb = new StringBuilder();
         array.forEach(it -> {
             String filedName = it.toString();
-            if (null== mapMap.get(filedName)||mapMap.get(filedName).isEmpty()) {
+            if (null == mapMap.get(filedName) || mapMap.get(filedName).isEmpty()) {
                 sb.append(it).append(",");
             } else {
                 sb.append(mapMap.get(filedName).get("filed")).append(",");
@@ -98,11 +98,11 @@ public class JsonResourceUtil {
     /**
      * 拼接title
      */
-    public static List<String> joinTitle(Map<String, Map<String,Object>> mapMap,JSONArray array) {
+    public static List<String> joinTitle(Map<String, Map<String, Object>> mapMap, JSONArray array) {
         List<String> titles = new ArrayList<>(20);
         array.forEach(it -> {
             String titleName = it.toString();
-            if (null== mapMap.get(titleName)||mapMap.get(titleName).isEmpty()) {
+            if (null == mapMap.get(titleName) || mapMap.get(titleName).isEmpty()) {
                 titles.add(it.toString());
             } else {
                 titles.add(mapMap.get(it.toString()).get("comment").toString());
@@ -114,9 +114,24 @@ public class JsonResourceUtil {
     /**
      * 拼接字段
      */
-    public static String joinAllFiled(Map<String, Map<String,Object>> mapMap) {
+    public static String joinAllFiled(Map<String, Map<String, Object>> mapMap) {
         StringBuilder sb = new StringBuilder();
         mapMap.forEach((k, v) -> sb.append(v.get("filed")).append(","));
         return sb.deleteCharAt(sb.length() - 1).toString();
     }
+
+    /**
+     * 获取字段名称JSON
+     */
+    public static List<JSONObject> getFieldsNames(Map<String, Map<String, Object>> mapMap) {
+        List<JSONObject> list = new ArrayList<>();
+        mapMap.forEach((k, v) -> {
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("code",k);
+            jsonObject.put("name", v.get("comment"));
+            list.add(jsonObject);
+        });
+        return list;
+    }
+
 }

+ 22 - 0
ruixuan-live/src/main/resources/mapper/report/KuaishouLiveAccountReportMapper.xml

@@ -681,4 +681,26 @@
         GROUP BY report_date
         ORDER BY report_date
     </select>
+
+
+    <insert id="replaceKuaishouFields">
+        replace
+        into kuaishou_Field_definition(
+        user_id,
+        json,
+        column_type
+        )values(
+        #{request.userId},
+        #{request.json},
+        #{request.columnType}
+        )
+    </insert>
+    <select id="getKuaishouFieldsByUserId" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT user_id as 'userId',
+               json,
+               column_type as 'columnType',
+        FROM kuaishou_Field_definition
+        WHERE user_id = #{userId}
+          AND column_type = #{columnType} Limit 1
+    </select>
 </mapper>