|
@@ -1,29 +1,36 @@
|
|
|
package com.ruoyi.web.controller.branch;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
+import com.ruoyi.branch.domain.TBranchMember;
|
|
|
import com.ruoyi.branch.domain.TBranchPlanItem;
|
|
|
import com.ruoyi.branch.service.ITBranchPlanItemService;
|
|
|
+import com.ruoyi.common.core.domain.entity.SysDept;
|
|
|
import com.ruoyi.common.core.domain.entity.SysDictData;
|
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
+import com.ruoyi.common.utils.DateUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
+import com.ruoyi.common.utils.file.ExcelUtils;
|
|
|
import com.ruoyi.system.service.ISysDictTypeService;
|
|
|
import com.ruoyi.system.service.ISysUserService;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.PutMapping;
|
|
|
-import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
import com.ruoyi.common.annotation.Log;
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
@@ -32,6 +39,7 @@ import com.ruoyi.branch.domain.TBranchPlan;
|
|
|
import com.ruoyi.branch.service.ITBranchPlanService;
|
|
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
|
import com.ruoyi.common.core.page.TableDataInfo;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
/**
|
|
|
* 支部年度工作计划Controller
|
|
@@ -55,6 +63,162 @@ public class TBranchPlanController extends BaseController
|
|
|
@Autowired
|
|
|
private ISysUserService userService;
|
|
|
|
|
|
+ @PostMapping("/importData")
|
|
|
+ public AjaxResult importData(@RequestParam("file") MultipartFile file) throws IOException {
|
|
|
+ //报错行数统计
|
|
|
+ List<Integer> failRow = new ArrayList<>();
|
|
|
+ Workbook workbook = ExcelUtils.getWorkBook(file);
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ List<TBranchPlan> planList = new ArrayList<>();
|
|
|
+ List<TBranchPlanItem> itemList = new ArrayList<>();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ int rowNum = sheet.getPhysicalNumberOfRows();
|
|
|
+ int failNumber = 0;
|
|
|
+ List<SysDictData> PlanItemStatus = sysDictTypeService.selectDictDataByType("plan_item_status");
|
|
|
+ List<SysUser> sysUsers = userService.selectUserList(new SysUser());
|
|
|
+ Map<Long, String> userMap = sysUsers.stream().collect(Collectors.toMap(SysUser::getUserId, SysUser::getNickName));
|
|
|
+ for (int i = 1; i < rowNum; i++) {
|
|
|
+ try {
|
|
|
+ logger.info("读取行数:" + i);
|
|
|
+ Row row = sheet.getRow(i);
|
|
|
+ int cellNum = row.getLastCellNum();
|
|
|
+ TBranchPlanItem item = new TBranchPlanItem();
|
|
|
+ for (int j = 0; j < cellNum; j++) {
|
|
|
+ Cell cell = row.getCell(j);
|
|
|
+ if (cell == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String cellValue = ExcelUtils.getCellValue(cell);
|
|
|
+ logger.info("cellValue:" + cellValue);
|
|
|
+ if (j == 0) {//标题
|
|
|
+// if (StringUtils.isNotEmpty(cellValue)) {
|
|
|
+// TBranchPlan plan = new TBranchPlan();
|
|
|
+// plan.setPlanTitle(cellValue);
|
|
|
+// plan.setPlanYear(null);
|
|
|
+// planList.add(plan);
|
|
|
+// }
|
|
|
+ } else if (j == 1) {//内容
|
|
|
+ item.setItemContent(cellValue);
|
|
|
+ } else if (j == 2) {//计划实施时间
|
|
|
+ if (StringUtils.isNotEmpty(cellValue)) {
|
|
|
+ item.setPlanTime(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
|
|
|
+ }
|
|
|
+ } else if (j == 3) {//当前状态
|
|
|
+ for (SysDictData data : PlanItemStatus) {
|
|
|
+ if (data.getDictLabel().equals(cellValue)) {
|
|
|
+ item.setItemStatus(data.getDictValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (j == 4) {//实际完成日期
|
|
|
+ if (StringUtils.isNotEmpty(cellValue)) {
|
|
|
+ item.setActualTime(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
|
|
|
+ }
|
|
|
+ } else if (j == 5) {//负责人
|
|
|
+ String personInCharge = "";
|
|
|
+ String[] split = cellValue.split(",");
|
|
|
+ for (String s : split) {
|
|
|
+ for (Long key : userMap.keySet()) {
|
|
|
+ if (userMap.get(key).equals(s)) {
|
|
|
+ personInCharge += key + ",";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (personInCharge.length() != 0) {
|
|
|
+ item.setPersonInCharge(personInCharge.substring(0, personInCharge.length() - 1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(item.getItemContent())) {
|
|
|
+ itemList.add(item);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ failNumber++;
|
|
|
+ logger.info("e:" + JSON.toJSONString(e));
|
|
|
+ failRow.add(i + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ logger.info("==========>itemList:" + itemList);
|
|
|
+ logger.info("==========>planList:" + planList);
|
|
|
+
|
|
|
+ // 获取年
|
|
|
+ int year = 0;
|
|
|
+ Row row = sheet.getRow(1);
|
|
|
+ Cell cell = row.getCell(2);
|
|
|
+ String cellValue = ExcelUtils.getCellValue(cell);
|
|
|
+ if (StringUtils.isNotEmpty(cellValue)) {
|
|
|
+ try {
|
|
|
+ year = new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue).getYear() + 1900;
|
|
|
+ } catch (ParseException e) {
|
|
|
+ logger.info("e:" + JSON.toJSONString(e));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 初始化工作计划标题对象
|
|
|
+ TBranchPlan season1 = new TBranchPlan();
|
|
|
+ season1.setPlanYear(year + "");
|
|
|
+ season1.setPlanTitle("一季度工作计划(1月-3月)");
|
|
|
+ season1.setDeptId(getDeptId());
|
|
|
+ tBranchPlanService.insertTBranchPlan(season1);
|
|
|
+ TBranchPlan season2 = new TBranchPlan();
|
|
|
+ season2.setPlanYear(year + "");
|
|
|
+ season2.setPlanTitle("二季度工作计划(4月-6月)");
|
|
|
+ season2.setDeptId(getDeptId());
|
|
|
+ tBranchPlanService.insertTBranchPlan(season2);
|
|
|
+ TBranchPlan season3 = new TBranchPlan();
|
|
|
+ season3.setPlanYear(year + "");
|
|
|
+ season3.setPlanTitle("三季度工作计划(7月-9月)");
|
|
|
+ season3.setDeptId(getDeptId());
|
|
|
+ tBranchPlanService.insertTBranchPlan(season3);
|
|
|
+ TBranchPlan season4 = new TBranchPlan();
|
|
|
+ season4.setPlanYear(year + "");
|
|
|
+ season4.setPlanTitle("四季度工作计划(10月-12月)");
|
|
|
+ season4.setDeptId(getDeptId());
|
|
|
+ tBranchPlanService.insertTBranchPlan(season4);
|
|
|
+
|
|
|
+ int successNumber = 0;
|
|
|
+ int failNum = 0;
|
|
|
+ for (TBranchPlanItem item : itemList) {
|
|
|
+ failNum++;
|
|
|
+ try {
|
|
|
+ int month = item.getPlanTime().getMonth() + 1;
|
|
|
+ switch (month) {
|
|
|
+ case 1:
|
|
|
+ case 2:
|
|
|
+ case 3:
|
|
|
+ item.setPlanId(season1.getPlanId());
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ case 5:
|
|
|
+ case 6:
|
|
|
+ item.setPlanId(season2.getPlanId());
|
|
|
+ break;
|
|
|
+ case 7:
|
|
|
+ case 8:
|
|
|
+ case 9:
|
|
|
+ item.setPlanId(season3.getPlanId());
|
|
|
+ break;
|
|
|
+ case 10:
|
|
|
+ case 11:
|
|
|
+ case 12:
|
|
|
+ item.setPlanId(season4.getPlanId());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ item.setDeptId(getDeptId());
|
|
|
+ tBranchPlanItemService.insertTBranchPlanItem(item);
|
|
|
+ } catch (Exception e) {
|
|
|
+ failNumber++;
|
|
|
+ logger.info("e:" + e);
|
|
|
+ failRow.add(failNum + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ logger.info("list:" + JSON.toJSONString(itemList));
|
|
|
+ logger.info("successNumber:" + successNumber);
|
|
|
+ logger.info("failNumber:" + failNumber);
|
|
|
+ logger.info("failRow:" + failRow);
|
|
|
+ return AjaxResult.success(String.valueOf(successNumber), failRow);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 查询支部年度工作计划列表
|
|
|
*/
|