Commit 381e307a authored by 曲欣红's avatar 曲欣红

1

parent 16ed0cd0
package com.egolm.film.api.service;
import java.util.Map;
public interface FilmReportService {
Map<String, Object> uploadReport(String start_date, String end_date);
Map<String, Object> applyTypeReport();
}
package com.egolm.film.api.service.impl;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.egolm.common.DateUtil;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.film.api.service.FilmReportService;
@Service
public class FilmReportServiceImpl implements FilmReportService {
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public Map<String, Object> uploadReport(String start_date, String end_date) {
String createDateSql = "select count(id) count, DATE_FORMAT((select from_unixtime(create_time)),'%Y-%m-%d') date from fc_member_film where create_time >= ? and create_time <= ? group by date";
String uploadDateSql = "select count(id) count, DATE_FORMAT(upload_time,'%Y-%m-%d') date from fc_member_film where upload_state = 1 and upload_time >= ? and upload_time <= ? group by date";
String totalCountSql = "select count(id) from fc_member_film where upload_state = 1 and upload_time >= ? and upload_time <= ?";
Date start = DateUtil.parse(start_date, DateUtil.FMT_DATE);
Date end = DateUtil.parse(end_date, DateUtil.FMT_DATE);
List<Map<String, Object>> createCountDataLsit = jdbcTemplate.queryForList(createDateSql, start.getTime()/1000, end.getTime()/1000);
List<Map<String, Object>> uploadCountDataLsit = jdbcTemplate.queryForList(uploadDateSql, start, end);
Calendar c = Calendar.getInstance();
Map<String, Object> res = new HashMap<>();
Long totalCount = jdbcTemplate.queryForLong(totalCountSql, start, end);
res.put("total_count", totalCount);
Map<String, Object> data = new HashMap<>();
while (!start.equals(end)) {
Map<String, Object> item = new HashMap<>();
Long createCount = 0L;
for(Map<String, Object> map : createCountDataLsit) {
if(map.get("date").equals(DateUtil.format(start, DateUtil.FMT_DATE))) {
createCount = (Long) map.get("count");
}
}
Long uploadCount = 0L;
for(Map<String, Object> map : uploadCountDataLsit) {
if(map.get("date").equals(DateUtil.format(start, DateUtil.FMT_DATE))) {
uploadCount = (Long) map.get("count");
}
}
item.put("apply_count", createCount);
item.put("upload_count", uploadCount);
item.put("total_count", totalCount);
item.put("date", DateUtil.format(start, DateUtil.FMT_DATE));
data.put(DateUtil.format(start, DateUtil.FMT_DATE), item);
c.setTime(start);
c.add(Calendar.DATE, 1); // 日期加1天
start = c.getTime();
}
Map<String, Object> item = new HashMap<>();
Integer createCount = 0;
for(Map<String, Object> map : createCountDataLsit) {
if(map.get("date").equals(DateUtil.format(start, DateUtil.FMT_DATE))) {
createCount = (Integer) map.get("count");
}
}
Integer uploadCount = 0;
for(Map<String, Object> map : uploadCountDataLsit) {
if(map.get("date").equals(DateUtil.format(start, DateUtil.FMT_DATE))) {
uploadCount = (Integer) map.get("count");
}
}
item.put("apply_count", createCount);
item.put("upload_count", uploadCount);
item.put("total_count", totalCount);
item.put("date", DateUtil.format(start, DateUtil.FMT_DATE));
data.put(DateUtil.format(start, DateUtil.FMT_DATE), item);
List<Object> dataLsit = new ArrayList<>();
for(Entry<String, Object> entry : data.entrySet()) {
dataLsit.add(entry.getValue());
}
res.put("list", dataLsit);
return res;
}
/**
* select ee.enroll_type enroll_type_id, ee.enroll_type_name enroll_type_name, fmfe.film_id film_id, fmf.cn_name cn_name from fc_member_film fmf, fc_member_film_enroll fmfe, enum_enroll ee where fmf.id = fmfe.film_id and fmfe.enroll_type_id = ee.enroll_type
*/
@Override
public Map<String, Object> applyTypeReport() {
Map<String, Object> res = new HashMap<>();
String applyTypeSql = "ee.enroll_type enroll_type_id, "
+ "ee.enroll_type_name enroll_type_name "
+ "from enum_enroll ee, "
+ "fc_member_film fmf, "
+ "fc_member_film_enroll fmfe "
+ "where fmf.id = fmfe.film_id "
+ "and fmfe.enroll_type_id = ee.enroll_type ";
Long applyTypeTotalCount = jdbcTemplate.queryForLong("select count(1) from (select "+applyTypeSql+") t");
List<Map<String, Object>> applyTypeGroup = jdbcTemplate.queryForList("select count(1) count, "+applyTypeSql+" group by ee.enroll_type");
String filmTypeSql = "ef.film_type, ef.film_type_name from enum_filmtype ef, fc_member_film fmf where ef.film_type = fmf.film_type_name";
Long filmTypeTotalCount = jdbcTemplate.queryForLong("select count(1) from (select "+filmTypeSql+") t");
List<Map<String, Object>> filmTypeGroup = jdbcTemplate.queryForList("select count(1) count, "+filmTypeSql+" group by ef.film_type");
String showTypeSql = "play_shanghai from fc_member_film";
Long showTypeTotalCount = jdbcTemplate.queryForLong("select count(1) from (select "+showTypeSql+") t");
List<Map<String, Object>> showTypeGroup = jdbcTemplate.queryForList("select count(1) count, "+showTypeSql+" group by play_shanghai");
for(Map<String, Object> map : applyTypeGroup) {
Long itemCount = (Long) map.get("count");
Double proportion = itemCount.doubleValue()/applyTypeTotalCount;
map.put("proportion", proportion);
}
for(Map<String, Object> map : filmTypeGroup) {
Long itemCount = (Long) map.get("count");
Double proportion = itemCount.doubleValue()/filmTypeTotalCount;
map.put("proportion", proportion);
}
for(Map<String, Object> map : showTypeGroup) {
Long itemCount = (Long) map.get("count");
Double proportion = itemCount.doubleValue()/showTypeTotalCount;
map.put("proportion", proportion);
}
res.put("apply_type_group_list", applyTypeGroup);
res.put("film_type_group_list", filmTypeGroup);
res.put("show_type_group_list", showTypeGroup);
return res;
}
public static void main(String[] args) {
System.out.println(1D/99L);
}
}
package com.egolm.film.api.web.report;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.egolm.common.bean.Rjx;
import com.egolm.film.api.service.FilmReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
@Api
@RestController
@RequestMapping({"/report"})
public class FilmReportController {
@Autowired
FilmReportService filmReportService;
@ResponseBody
@PostMapping("update_report")
@ApiOperation("上传影片统计")
@ApiImplicitParams({
@ApiImplicitParam(paramType="header", dataType="string", name="i18n_language"),
@ApiImplicitParam(paramType="query", dataType="string", required=true, name="start_date", value="开始时间"),
@ApiImplicitParam(paramType="query", dataType="string", required=true, name="end_date", value="结束时间")
})
public Object getUploadReport(String start_date, String end_date) {
return Rjx.jsonOk()
.setData(filmReportService.uploadReport(start_date, end_date));
}
@ResponseBody
@PostMapping("apply_type_report")
@ApiOperation("上传影片统计")
@ApiImplicitParams({
@ApiImplicitParam(paramType="header", dataType="string", name="i18n_language"),
})
public Object getApplyTypeReport() {
return Rjx.jsonOk()
.setData(filmReportService.applyTypeReport());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment