Commit 18bc39ab authored by licc's avatar licc

测试方案上传

parent d48cb15c
...@@ -24,21 +24,27 @@ public interface VolunteerService extends IService<Volunteer> { ...@@ -24,21 +24,27 @@ public interface VolunteerService extends IService<Volunteer> {
/** /**
* Excel批量添加方案志愿 * Excel批量添加方案志愿
*
* @param file 志愿文件 * @param file 志愿文件
* @param type 方案类型 * @param type 方案类型
* @param schemeName 方案名称 * @param schemeName 方案名称
* @param fileUrl 方案url
* @param response 相应数据 * @param response 相应数据
* @throws IOException 异常 * @throws IOException 异常
*/ */
void excelAdd(MultipartFile file, Integer type, String schemeName, String fileUrl, HttpServletResponse response) throws IOException; void excelAdd(MultipartFile file, Integer type, String schemeName, String fileUrl,HttpServletResponse response) throws IOException;
/** /**
* 批量添加方案Excel模板 * Excel批量添加方案志愿
* * @param response 相应数据
* @param response 结果 * @throws IOException 异常
*/ */
void excelTemplate(HttpServletResponse response) throws IOException; void excelTemplate(HttpServletResponse response) throws IOException;
/**
* Excel批量添加方案志愿
* @param file 志愿文件
* @param response 相应数据
* @throws IOException 异常
*/
void ceshi(MultipartFile file, HttpServletResponse response) throws IOException;
} }
...@@ -79,11 +79,31 @@ public class VolunteerServiceImpl extends ServiceImpl<VolunteerMapper, Volunteer ...@@ -79,11 +79,31 @@ public class VolunteerServiceImpl extends ServiceImpl<VolunteerMapper, Volunteer
} }
@Override @Override
public void excelTemplate(HttpServletResponse response) throws IOException { public void ceshi(MultipartFile file, HttpServletResponse response) throws IOException {
//构造假数据 if (file == null || file.isEmpty()) {
List<Volunteer> residents = this.mockData(); throw new BaseException("操作错误");
//excel导出 }
this.download(response, Volunteer.class, residents, "居民管理模板", "居民管理");
VolunteerListener excelListener = new VolunteerListener();
//判断文件类型=
boolean valid = this.validContentType(file.getOriginalFilename());
if (!valid) {
throw new BaseException("请传入Excel文件");
}
//2.读取数据进行入库操作
EasyExcel.read(file.getInputStream(), Volunteer.class, excelListener).sheet().doRead();
List<Volunteer> list = excelListener.getList();
//3、保存方案和志愿信息
SchemeInfo schemeInfo = new SchemeInfo();
schemeInfo.setSchemeName("专科文学编导一批");
schemeInfo.setType(7);
schemeInfo.setUploadTime(new Date());
schemeInfo.setIsDelete(0);
volunteerManager.saveSchemeAndVolunteer(schemeInfo, list);
log.info("导入方案数据成功!");
} }
/** /**
......
...@@ -66,6 +66,20 @@ public class SchemeController { ...@@ -66,6 +66,20 @@ public class SchemeController {
return R.ok("添加成功"); return R.ok("添加成功");
} }
@ApiOperation(value = "测试Excel", notes = "测试Excel")
@ApiImplicitParam(name = "file", value = "志愿查询参数", dataType = "MultipartFile")
@PostMapping("/excel/add/ceshi")
public R ceshi(@RequestBody MultipartFile file, HttpServletResponse response) throws IOException {
log.info("");
if (file == null || file.isEmpty()) {
throw new BaseException("操作错误");
}
volunteerService.ceshi(file, response);
return R.ok("添加成功");
}
@ApiOperation(value = "方案上传Excel模板", notes = "方案上传Excel模板") @ApiOperation(value = "方案上传Excel模板", notes = "方案上传Excel模板")
@PostMapping("/excel/template") @PostMapping("/excel/template")
public R excelTemplate(HttpServletResponse response) throws IOException { public R excelTemplate(HttpServletResponse response) throws IOException {
......
...@@ -21,6 +21,7 @@ import java.util.List; ...@@ -21,6 +21,7 @@ import java.util.List;
* @ Description: PC-我的方案 * @ Description: PC-我的方案
* @ Author : 86187 * @ Author : 86187
* @ Date : 2021/1/14 10:48 * @ Date : 2021/1/14 10:48
* @author 86187
*/ */
@RestController @RestController
@Api(tags = "PC-我的方案") @Api(tags = "PC-我的方案")
......
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