Explorar o código

支部年度工作计划模板下载、导入

Wang Zi Wen %!s(int64=2) %!d(string=hai) anos
pai
achega
a199b46c72

+ 172 - 8
ruoyi-admin/src/main/java/com/ruoyi/web/controller/branch/TBranchPlanController.java

@@ -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);
+    }
+
     /**
      * 查询支部年度工作计划列表
      */

+ 4 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java

@@ -169,6 +169,10 @@ public class CommonController {
                 downloadname = "发展对象名册导入模板.xlsx";
                 url = "static/template/jjfz&fzdxmc.xlsx";
                 break;
+            case "gzjh":
+                downloadname = "支部年度工作计划导入模板.xlsx";
+                url = "static/template/gzjh.xlsx";
+                break;
         }
         InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(url);
 

BIN=BIN
ruoyi-admin/src/main/resources/static/template/gzjh.xlsx


+ 2 - 2
ruoyi-system/src/main/resources/mapper/branch/TBranchPlanMapper.xml

@@ -31,7 +31,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </where>
         <!-- 数据范围过滤 -->
         ${params.dataScope}
-        order by u.create_time asc
+        order by u.create_time asc, plan_id asc
     </select>
     
     <select id="selectTBranchPlanByPlanId" parameterType="Long" resultMap="TBranchPlanResult">
@@ -40,7 +40,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         and u.del_flag = 0
     </select>
         
-    <insert id="insertTBranchPlan" parameterType="TBranchPlan">
+    <insert id="insertTBranchPlan" parameterType="TBranchPlan" useGeneratedKeys="true" keyProperty="planId">
         <selectKey keyProperty="planId" resultType="long" order="BEFORE">
             SELECT seq_t_branch_plan.NEXTVAL as planId FROM DUAL
         </selectKey>

+ 34 - 19
ruoyi-ui/src/views/branch/zbjs/plan/index.vue

@@ -53,6 +53,16 @@
           v-hasPermi="['branch:plan:add']"
         >新增标题</el-button>
       </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="info"
+          plain
+          icon="el-icon-upload2"
+          size="mini"
+          @click="handleImport"
+          v-hasPermi="['branch:plan:edit']"
+        >导入</el-button>
+      </el-col>
       <el-col :span="1.5">
         <el-button
           type="warning"
@@ -233,9 +243,12 @@
                 <em>点击上传</em>
             </div>
             <div class="el-upload__tip" slot="tip">
-                <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据
+                <!--<el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据-->
                 <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
             </div>
+            <form ref="downloadFileForm" :action="upload.downloadAction" target="FORMSUBMIT">
+              <input name="type" :value="upload.type" hidden/>
+            </form>
             <div class="el-upload__tip" style="color:red" slot="tip">提示:仅允许导入“xls”或“xlsx”格式文件!</div>
         </el-upload>
         <div slot="footer" class="dialog-footer">
@@ -290,6 +303,9 @@ export default {
       userList: [],
       // 用户导入参数
       upload: {
+          downloadAction: process.env.VUE_APP_BASE_API + '/common/template',
+          //下载模板类型
+          type: "gzjh",
           // 是否显示弹出层(用户导入)
           open: false,
           // 弹出层标题(用户导入)
@@ -301,7 +317,7 @@ export default {
           // 设置上传的请求头部
           headers: { Authorization: "Bearer " + getToken() },
           // 上传的地址
-          url: process.env.VUE_APP_BASE_API + "/branch/planitem/importData"
+          url: process.env.VUE_APP_BASE_API + "/branch/plan/importData"
       },
       // 查询参数
       queryParams: {
@@ -366,23 +382,24 @@ export default {
   methods: {
     // 单元格样式
     tableCellStyle( {row, column, rowIndex, columnIndex} ) {
-      console.log(row.planTime)
-      if (columnIndex === 0 ||columnIndex === 7) {
-        return;
-      }
-      let today = new Date(); // 当前时间
-      let planTime = new Date(row.planTime);
-      if (today.getTime() < planTime.getTime()) {
-        let difference = planTime.getTime() - today.getTime(); // 时间差
-        if (row.planTime != null && row.planTime != '' && row.itemStatus != '1') {
-          if (difference < 16 * 24 * 60 * 60 * 1000) {  // 到期时间 - 当前时间 < 16
-            return "background-color: rgba(203, 0, 0, 1); color: rgb(255, 255, 255);";
-          } else if (difference >= 16 * 24 * 60 * 60 * 1000
-            && difference <= 30 * 24 * 60 * 60 * 1000) {  // 16 <= 到期时间 - 当前时间 <= 30
-            return "background-color: rgba(255, 255, 0, 1);";
+      if (columnIndex === 0 || columnIndex === 1 || columnIndex === 7 || columnIndex === 8) {
+        return "background-color: transparent;";
+      } else {
+        let today = new Date(); // 当前时间
+        let planTime = new Date(row.planTime);
+        if (today.getTime() < planTime.getTime()) {
+          let difference = planTime.getTime() - today.getTime(); // 时间差
+          if (row.planTime != null && row.planTime != '' && row.itemStatus != '1') {
+            if (difference < 16 * 24 * 60 * 60 * 1000) {  // 到期时间 - 当前时间 < 16
+              return "background-color: rgba(203, 0, 0, 1); color: rgb(255, 255, 255);";
+            } else if (difference >= 16 * 24 * 60 * 60 * 1000
+              && difference <= 30 * 24 * 60 * 60 * 1000) {  // 16 <= 到期时间 - 当前时间 <= 30
+              return "background-color: rgba(255, 255, 0, 1);";
+            }
           }
         }
       }
+
     },
     /** 设置搜索条件年份 */
     setYear() {
@@ -672,9 +689,7 @@ export default {
       },
       /** 下载模板操作 */
       importTemplate() {
-          importTemplate().then(response => {
-              this.download(response.msg);
-          });
+        this.$refs['downloadFileForm'].submit();
       },
       // 文件上传中处理
       handleFileUploadProgress(event, file, fileList) {