|
@@ -1,10 +1,8 @@
|
|
|
package thyyxxk.webserver.controller.singlepage;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.poi.ss.usermodel.*;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
import thyyxxk.webserver.config.auth.PassToken;
|
|
|
import thyyxxk.webserver.config.exception.ExceptionEnum;
|
|
|
import thyyxxk.webserver.dao.his.singlepage.LotteryDao;
|
|
@@ -14,9 +12,6 @@ import thyyxxk.webserver.entity.singlepage.lottery.LotteryUser;
|
|
|
import thyyxxk.webserver.entity.singlepage.lottery.StartLotteryRequest;
|
|
|
import thyyxxk.webserver.utils.ResultVoUtil;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
-import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Slf4j
|
|
@@ -30,49 +25,6 @@ public class LotteryController {
|
|
|
this.dao = dao;
|
|
|
}
|
|
|
|
|
|
- @PassToken
|
|
|
- @PostMapping("/uploadLotteryUsers")
|
|
|
- public ResultVo<List<LotteryUser>> uploadLotteryUsers(@RequestBody MultipartFile file) throws IOException {
|
|
|
- List<LotteryUser> userList = new ArrayList<>();
|
|
|
- dao.truncateTable();
|
|
|
- Workbook workbook;
|
|
|
- InputStream is = file.getInputStream();
|
|
|
- workbook = WorkbookFactory.create(is);
|
|
|
- // 获取第一个活页数据
|
|
|
- Sheet sheet = workbook.getSheetAt(0);
|
|
|
- // 第几行开始解析
|
|
|
- for (int i = 1; i <= sheet.getLastRowNum(); i++) {
|
|
|
- Row row = sheet.getRow(i);
|
|
|
- if(null == row.getCell(0)){
|
|
|
- continue;
|
|
|
- }
|
|
|
- // 获取行所有单元格数据
|
|
|
- LotteryUser user = new LotteryUser();
|
|
|
- user.setCodeRs(getCellValue(row.getCell(0)));
|
|
|
- user.setName(getCellValue(row.getCell(1)));
|
|
|
- userList.add(user);
|
|
|
- if (userList.size() == 100) {
|
|
|
- dao.insertUsers(userList);
|
|
|
- userList.clear();
|
|
|
- }
|
|
|
- }
|
|
|
- workbook.close();
|
|
|
- is.close();
|
|
|
-
|
|
|
- if (!userList.isEmpty()) {
|
|
|
- dao.insertUsers(userList);
|
|
|
- }
|
|
|
-
|
|
|
- return selectLotteryUsers();
|
|
|
- }
|
|
|
-
|
|
|
- private String getCellValue(Cell cell) {
|
|
|
- if (cell.getCellType() == CellType.NUMERIC) {
|
|
|
- return String.valueOf((int) cell.getNumericCellValue());
|
|
|
- }
|
|
|
- return cell.getRichStringCellValue().getString();
|
|
|
- }
|
|
|
-
|
|
|
@PassToken
|
|
|
@GetMapping("/selectLotteryUsers")
|
|
|
public ResultVo<List<LotteryUser>> selectLotteryUsers() {
|
|
@@ -103,9 +55,6 @@ public class LotteryController {
|
|
|
@GetMapping("/selectWonUsers")
|
|
|
public ResultVo<List<LotteryUser>> selectWonUsers() {
|
|
|
List<LotteryUser> wonUsers = dao.selectWonUsers();
|
|
|
- if (wonUsers.isEmpty()) {
|
|
|
- return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "尚未有人中奖。");
|
|
|
- }
|
|
|
return ResultVoUtil.success(wonUsers);
|
|
|
}
|
|
|
}
|