Commit 5867e527 authored by maliang's avatar maliang

权限控制

parent c5cf7c11
...@@ -148,6 +148,18 @@ ...@@ -148,6 +148,18 @@
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>4.12</version> <version>4.12</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
</dependencies> </dependencies>
......
...@@ -39,7 +39,6 @@ public class AdvertiserController { ...@@ -39,7 +39,6 @@ public class AdvertiserController {
@ApiOperation(value = "获取广告数据汇总") @ApiOperation(value = "获取广告数据汇总")
@ResponseBody @ResponseBody
public String getAdvertiserDataCount(@RequestBody PageTableRequest request) { public String getAdvertiserDataCount(@RequestBody PageTableRequest request) {
System.out.println(request.getStartTime()+":"+request.getEndTime());
List<AdvertiserData> advertDataList = advertDao.getAdvertData(request.getStartTime(), request.getEndTime()); List<AdvertiserData> advertDataList = advertDao.getAdvertData(request.getStartTime(), request.getEndTime());
Integer count = advertDao.getAdvertDataCount(request.getStartTime(), request.getEndTime()); Integer count = advertDao.getAdvertDataCount(request.getStartTime(), request.getEndTime());
return PageTableHandler.getJSONObject(advertDataList,count); return PageTableHandler.getJSONObject(advertDataList,count);
......
package com.boot.security.server.controller; package com.boot.security.server.controller;
import java.io.IOException; import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.boot.security.server.model.AdvertiserData;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
...@@ -45,6 +53,16 @@ public class FileController { ...@@ -45,6 +53,16 @@ public class FileController {
return fileService.save(file); return fileService.save(file);
} }
@PostMapping("/excel")
@ApiOperation(value = "excel上传")
public String uploadExcel(MultipartFile file) throws IOException {
JSONObject jsonObject = new JSONObject();
jsonObject.put("code",0);
fileService.saveExel(file);
return jsonObject.toJSONString();
}
/** /**
* layui富文本文件自定义上传 * layui富文本文件自定义上传
* *
......
...@@ -39,6 +39,9 @@ public interface AdvertDao { ...@@ -39,6 +39,9 @@ public interface AdvertDao {
@Select("SELECT count(*) FROM(SELECT advertiser_id FROM advertiser_user_map WHERE user_id=#{userId}) a LEFT JOIN advertiser_data_count b ON a.advertiser_id=b.advertiser_id") @Select("SELECT count(*) FROM(SELECT advertiser_id FROM advertiser_user_map WHERE user_id=#{userId}) a LEFT JOIN advertiser_data_count b ON a.advertiser_id=b.advertiser_id")
int getAdvertiserDataByUserIdCount(@Param("userId") Long userId); int getAdvertiserDataByUserIdCount(@Param("userId") Long userId);
@Select("select report_date reportDate,code_id codeId,sum(exposure) exposure,sum(click) click from advertiser_data_minutes t where code_id=#{advertiserData.codeId} and report_date<=#{advertiserData.reportDate} and report_date<=#{advertiserData.reportDate} group by report_date,code_id")
AdvertiserData getCliExExcel(@Param("advertiserData") AdvertiserData advertiserData);
@Update("update advertiser_data_count set balance=#{balance},exposure_view=#{exposureView},click_view=#{clickView} where advertiser_id=#{advertiserId} ") @Update("update advertiser_data_count set balance=#{balance},exposure_view=#{exposureView},click_view=#{clickView} where advertiser_id=#{advertiserId} ")
int updateAdvertiserData(@Param("advertiserId") Integer advertiserId,@Param("balance") Double balance,@Param("exposureView") Integer exposureView,@Param("clickView") Integer clickView); int updateAdvertiserData(@Param("advertiserId") Integer advertiserId,@Param("balance") Double balance,@Param("exposureView") Integer exposureView,@Param("clickView") Integer clickView);
} }
...@@ -12,4 +12,6 @@ public interface FileService { ...@@ -12,4 +12,6 @@ public interface FileService {
void delete(String id); void delete(String id);
void saveExel(MultipartFile file) throws IOException;
} }
package com.boot.security.server.service.impl; package com.boot.security.server.service.impl;
import java.io.IOException; import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import com.boot.security.server.dao.AdvertDao;
import com.boot.security.server.model.AdvertiserData;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -23,6 +30,8 @@ public class FileServiceImpl implements FileService { ...@@ -23,6 +30,8 @@ public class FileServiceImpl implements FileService {
private String filesPath; private String filesPath;
@Autowired @Autowired
private FileInfoDao fileInfoDao; private FileInfoDao fileInfoDao;
@Autowired
private AdvertDao advertDao;
@Override @Override
public FileInfo save(MultipartFile file) throws IOException { public FileInfo save(MultipartFile file) throws IOException {
...@@ -74,4 +83,51 @@ public class FileServiceImpl implements FileService { ...@@ -74,4 +83,51 @@ public class FileServiceImpl implements FileService {
} }
} }
@Override
public void saveExel(MultipartFile file) throws IOException {
Workbook wb = null;
wb = new XSSFWorkbook(file.getInputStream());
Sheet sheet = null;
Row row = null;
List<AdvertiserData> list = null;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
if(wb != null){
//用来存放表中数据
list = new ArrayList<AdvertiserData>();
//获取第一个sheet
sheet = wb.getSheetAt(0);
//获取最大行数
int rownum = sheet.getPhysicalNumberOfRows();
//获取第一行
row = sheet.getRow(0);
//获取最大列数
//int colnum = row.getPhysicalNumberOfCells();
for (int i = 0; i<rownum; i++) {
row = sheet.getRow(i);
if(row !=null){
Cell cell = row.getCell(0);
AdvertiserData advertiserData = new AdvertiserData();
advertiserData.setReportDate(simpleDateFormat.format(cell.getDateCellValue()));
cell = row.getCell(1);
if(cell.getCellType().equals(CellType.STRING)){
advertiserData.setCodeId(cell.getStringCellValue());
}else {
advertiserData.setCodeId(String.valueOf((int) cell.getNumericCellValue()));
}
cell = row.getCell(2);
advertiserData.setIncome(cell.getNumericCellValue());
list.add(advertiserData);
}else{
break;
}
}
}
for (AdvertiserData advertiserData : list) {
AdvertiserData cliExExcel = advertDao.getCliExExcel(advertiserData);
System.out.println(cliExExcel.getExposure());
System.out.println(cliExExcel.getClick());
}
}
} }
...@@ -9,8 +9,13 @@ ...@@ -9,8 +9,13 @@
<link rel="stylesheet" type="text/css" media="screen" href="../../layui/css/layui.css"> <link rel="stylesheet" type="text/css" media="screen" href="../../layui/css/layui.css">
<body> <body>
<div class="layui-inline"> <div class="layui-inline" style="width: 100%">
<div class="" style="width: 180px;float: left">
<input type="text" class="layui-input" id="date1"> <input type="text" class="layui-input" id="date1">
</div>
<button type="button" class="layui-btn" id="upload" style="float: right">
<i class="layui-icon">&#xe67c;</i>上传excel
</button>
</div> </div>
<table id="demo" lay-filter="adveriserDataCount"></table> <table id="demo" lay-filter="adveriserDataCount"></table>
...@@ -95,22 +100,34 @@ ...@@ -95,22 +100,34 @@
,{field: 'income', title: '收入'} ,{field: 'income', title: '收入'}
,{field: 'advertiserName', title: '广告主名称'} ,{field: 'advertiserName', title: '广告主名称'}
]] ]]
,defaultToolbar: ['filter', 'exports',{ ,defaultToolbar: ['filter', 'exports']
title: '上传' //标题 // ,{
,layEvent: 'upload' //事件名,用于 toolbar 事件中使用 // title: '上传' //标题
,icon: 'layui-icon-addition' //图标类名 // ,layEvent: 'upload' //事件名,用于 toolbar 事件中使用
}] // ,icon: 'layui-icon-addition' //图标类名
// }
}); });
table.on('toolbar(adveriserDataCount)', function(obj){ // table.on('toolbar(adveriserDataCount)', function(obj){
var layEvent = obj.event; // var layEvent = obj.event;
var checkStatus = table.checkStatus('idTest'); // var checkStatus = table.checkStatus('idTest');
if(layEvent === 'upload'){ //上传 // if(layEvent === 'upload'){ //上传
layer.msg('upload'); // }
} // });
});
});
layui.use('upload', function(){
var upload = layui.upload;
upload.render({
elem:'#upload'
,accept: 'file' //允许上传的文件类型
,url: '/files/excel' //上传接口
,done: function(res, index, upload){
layer.msg("上传成功");
}
});
}); });
......
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