Jelajahi Sumber

修改 5天前被冲掉的 社区机构账号导入代码 与 前端增加社区机构账号导入功能

sigezuishuai 2 tahun lalu
induk
melakukan
dd7b372017

+ 3 - 4
ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/utils/OtherConstants.java

@@ -3,11 +3,10 @@ package com.ruoyi.system.utils;
 public class OtherConstants {
 
     public static final String DEPT_ID_JL = "5d4289205ffc6694f7e42082";
+    public static final String DEPT_ID_GJ = "479a446fce894740b373f9c4b356daac";
 
-    public static final String DEPT_ID_JL_GJ = "479a446fce894740b373f9c4b356daac";
-
-    public static final String DEPT_CODE_JL_GJ = "220000000000";
-
+    public static final String DEPT_CODE_GJ = "000000000000";
+    public static final String DEPT_CODE_JL = "220000000000";
 
 
     public static final long SYS_ROLE_YLJG_ID = 2;

+ 2 - 0
ruoyi-modules/mz-business/src/main/java/com/ruoyi/business/service/impl/YljgXfaqzcxxServiceImpl.java

@@ -144,6 +144,8 @@ public class YljgXfaqzcxxServiceImpl implements IYljgXfaqzcxxService
                 xfaq.setJgId(orginXfaqzcxx.getJgId());
                 xfaq.setZt(zt);
                 xfaq.setIsJc(orginXfaqzcxx.getIsJc());
+                // CH Problem - 2022-9-21
+//                xfaq.setCreateAreaCode(SecurityUtils.getAreaCode());
                 Integer resultSize = yljgXfaqzcxxMapper.selectYljgXfaqzcxxList(xfaq).size();
                 if(resultSize!=0){
                     throw new ServiceException("当前机构已存在暂存信息不允许进行新增操作!");

+ 2 - 0
ruoyi-modules/mz-business/src/main/resources/mapper/business/YljgXfaqzcxxMapper.xml

@@ -48,6 +48,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="txdz"    column="txdz"    />
         <result property="isJgxfaqdbgc"    column="is_jgxfaqdbgc"    />
         <result property="isJc"    column="is_jc"    />
+        <result property="isJc"    column="is_jc"    />
     </resultMap>
 
     <resultMap id="YljgXfaqzcxxYljgJcxmxxResult" type="YljgXfaqzcxx" extends="YljgXfaqzcxxResult">
@@ -202,6 +203,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="xfaqfzr != null  and xfaqfzr != ''"> and a.xfaqfzr = #{xfaqfzr}</if>
             <if test="jtqk != null  and jtqk != ''"> and a.jtqk = #{jtqk}</if>
             <if test="pbqk != null  and pbqk != ''"> and a.pbqk = #{pbqk}</if>
+            <if test="createAreaCode != null  and createAreaCode != ''"> and a.create_area_code = #{createAreaCode}</if>
             <if test="pbqkqt != null  and pbqkqt != ''"> and a.pbqkqt = #{pbqkqt}</if>
             <if test="zcsj != null  and zcsj != ''"> and a.zcsj = #{zcsj}</if>
             <if test="zt != null  and zt != ''"> and a.zt = #{zt}</if>

+ 4 - 0
ruoyi-modules/mz-organization-jg/src/main/java/com/ruoyi/organization/mapper/YljgsqJcxxMapper.java

@@ -121,4 +121,8 @@ public interface YljgsqJcxxMapper extends BaseMapperPlus<YljgsqJcxx>
 
     @InterceptorIgnore(tenantLine = "true")
     public Map<String, Object> selectPortalYljgsqMapJcxxById(String id);
+
+    public int batchSqYljgJcxx(List<YljgsqJcxx> yljgsqJcxxList);
+
+    public List<Map<String,Object>> selectJgxxByZh();
 }

+ 2 - 0
ruoyi-modules/mz-organization-jg/src/main/java/com/ruoyi/organization/service/IYljgsqJcxxService.java

@@ -79,4 +79,6 @@ public interface IYljgsqJcxxService
     public int insertYljgUserZhxx(YljgsqJcxx yljgsqJcxx,Integer type);
     public int updateYljgZhxx(YljgsqJcxx yljgsqJcxx);
     public int deleteYljgZhxxByIds(String[] ids);
+
+    public String importSqJcxx(List<YljgsqJcxx> sqJcxxList);
 }

+ 92 - 0
ruoyi-modules/mz-organization-jg/src/main/java/com/ruoyi/organization/service/impl/YljgsqJcxxServiceImpl.java

@@ -24,6 +24,8 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -507,4 +509,94 @@ public class YljgsqJcxxServiceImpl implements IYljgsqJcxxService
         YljgsqJcxx old = yljgsqJcxxMapper.selectYljgsqJcxxByIdZH(id);
         yljgsqJcxxMapper.insertYljgsqJcxxDeleteHi(old);
     }
+
+    public String importSqJcxx(List<YljgsqJcxx> sqJcxxList) {
+
+        Long userId = SecurityUtils.getUserId();
+        if( userId == 1 ){
+            throw new ServiceException("超级管理员用户无法导入信息,请您使用所对应的业务管理员账号!");
+        }else{
+            /**-----------------------------第一块 检查Excel信息 是否有问题 -----------------------------*/
+
+            if (StringUtils.isNull(sqJcxxList) || sqJcxxList.size() == 0)
+            {
+                throw new ServiceException("导入账号数据不能为空!");
+            }
+
+            List<Map<String,Object>> list = new ArrayList<>();
+            sqJcxxList.forEach( d->{
+                if(StringUtils.isNotBlank(d.getJgmc()) && StringUtils.isNotBlank(d.getTyshxydm()) && StringUtils.isNotBlank(d.getFrxm()) && StringUtils.isNotBlank(d.getFrlxfs())){
+                    Map<String,Object> map = new HashMap<>();
+                    map.put("社区养老服务机构和设施名称",d.getJgmc());
+                    map.put("统一社会信用代码",d.getTyshxydm());
+                    map.put("负责人",d.getFrxm());
+                    map.put("负责人联系电话",d.getFrlxfs());
+                    list.add(map);
+                } else{
+                    throw new ServiceException("社区养老服务机构和设施名称、社区养老服务机构和设施名称、负责人、负责人联系电话必须填写,请检查Excel信息!");
+                }
+            });
+
+            // 流特性去掉重复Map
+            long count = list.stream().distinct().count();
+            boolean isRepeat = count < list.size();
+            if (isRepeat)
+            {
+                throw new ServiceException("导入的Excel有重复信息,请检查。") ;
+            }
+
+            /**-----------------------------第二块 检查添加的账号是否存在 -----------------------------*/
+            int successNum = 0;
+            int failureNum = 0;
+            StringBuilder successMsg = new StringBuilder();
+            StringBuilder failureMsg = new StringBuilder();
+            List<Map<String,Object>> lists = yljgsqJcxxMapper.selectJgxxByZh();
+
+            int index = 0;
+            for (YljgsqJcxx sqJcxx : sqJcxxList)
+            {
+                index++;
+
+                // 不重复校验
+                Map<String,Object> map = new HashMap();
+                map.put("jgmc",sqJcxx.getJgmc());
+                map.put("tyshxydm",sqJcxx.getTyshxydm());
+                map.put("frxm",sqJcxx.getFrxm());
+                map.put("frlxfs",sqJcxx.getFrlxfs());
+                if(lists.contains(map)){
+                    failureNum++;
+                    failureMsg.append("<br/>" + failureNum + "<" + "机构名称:" + sqJcxx.getJgmc() + "> "+ "统一社会信用代码:" + sqJcxx.getTyshxydm() + " 已存在,请修改。");
+                }
+            }
+
+            /**-----------------------------第三块 导入账号 -----------------------------*/
+            List<YljgsqJcxx> sqInsertList = new ArrayList<YljgsqJcxx>();
+            for (int i = 0; i < sqJcxxList.size(); i++) {
+                // 导入账号
+                YljgsqJcxx sq = new YljgsqJcxx();
+                sq.setJgmc(sqJcxxList.get(i).getJgmc());
+                sq.setTyshxydm(sqJcxxList.get(i).getTyshxydm());
+                sq.setFrxm(sqJcxxList.get(i).getFrxm());
+                sq.setFrlxfs(sqJcxxList.get(i).getFrlxfs());
+                sq.setSsxzqh(SecurityUtils.getAreaCode());
+                sqInsertList.add(sq);
+                successNum++;
+                successMsg.append("<br/>" + successNum + "、社区养老机构: " + sqJcxxList.get(i).getJgmc() + " 账号导入成功");
+            }
+            if (failureNum > 0)
+            {
+                failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
+                throw new ServiceException(failureMsg.toString());
+            } else
+            {
+                successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
+            }
+            if (sqInsertList.size() > 0)
+            {
+                yljgsqJcxxMapper.batchSqYljgJcxx(sqInsertList);
+            }
+            return successMsg.toString();
+        }
+
+    }
 }

+ 16 - 0
ruoyi-modules/mz-organization-jg/src/main/resources/mapper/organization/YljgsqJcxxMapper.xml

@@ -693,4 +693,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         where id = #{id}
     </select>
 
+    <select id="selectJgxxByZh"  resultType="java.util.HashMap">
+        SELECT
+        a.jgmc, a.tyshxydm, a.frxm, a.frlxfs
+        FROM
+        yljgsq_jcxx a
+    </select>
+
+    <insert id="batchSqYljgJcxx">
+        insert into yljgsq_jcxx( id, jgmc, tyshxydm, frxm, frlxfs, ssxzqh, create_time_str, create_user_id,create_user_type,create_area_code, create_by, create_unit, create_unit_name) values
+        <foreach item="item" index="index" collection="list" separator=",">
+            ((REPLACE( UUID(),"-","")), #{item.jgmc}, #{item.tyshxydm}, #{item.frxm}, #{item.frlxfs}, #{item.ssxzqh},
+            #{item.createTimeStr}, #{item.createUserId},#{item.createUserType},
+            #{item.createAreaCode}, #{item.createBy}, #{item.createUnit}, #{item.createUnitName})
+        </foreach>
+    </insert>
+
 </mapper>

+ 13 - 5
ruoyi-modules/mz-organization/src/main/java/com/ruoyi/organization/controller/YljgsqJcxxController.java

@@ -1,20 +1,20 @@
 package com.ruoyi.organization.controller;
 
+import com.ruoyi.common.core.utils.poi.ExcelUtil;
 import com.ruoyi.common.core.web.controller.BaseController;
 import com.ruoyi.common.core.web.domain.AjaxResult;
 import com.ruoyi.common.core.web.page.TableDataInfo;
 import com.ruoyi.common.log.annotation.Log;
 import com.ruoyi.common.log.enums.BusinessType;
 import com.ruoyi.common.security.annotation.RequiresPermissions;
-import com.ruoyi.common.security.utils.SecurityUtils;
 import com.ruoyi.system.validate.group.AddGroup;
 import com.ruoyi.system.validate.group.AddZhGroup;
 import com.ruoyi.organization.domain.YljgsqJcxx;
-import com.ruoyi.organization.service.IYljgJcxxService;
 import com.ruoyi.organization.service.IYljgsqJcxxService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
 import java.util.Map;
@@ -32,9 +32,6 @@ public class YljgsqJcxxController extends BaseController
     @Autowired
     private IYljgsqJcxxService sqyljgJcxxService;
 
-    @Autowired
-    private IYljgJcxxService yljgJcxxService;
-
     /**
      * 查询社区养老机构_基础信息列表
      */
@@ -178,5 +175,16 @@ public class YljgsqJcxxController extends BaseController
         return toAjax(sqyljgJcxxService.deleteYljgZhxxByIds(ids));
     }
 
+     @Log(title = "社区机构账号管理", businessType = BusinessType.IMPORT)
+     @RequiresPermissions("organization:sqjgZhgl:importData")
+     @PostMapping("/importData")
+     public AjaxResult importData(MultipartFile file) throws Exception
+     {
+         ExcelUtil<YljgsqJcxx> util = new ExcelUtil<YljgsqJcxx>(YljgsqJcxx.class);
+         List<YljgsqJcxx> sqJcxxList = util.importExcel(file.getInputStream());
+         String message = sqyljgJcxxService.importSqJcxx(sqJcxxList);
+         return AjaxResult.success(message);
+     }
+
 
 }

+ 1 - 1
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysDeptJlController.java

@@ -75,7 +75,7 @@ public class SysDeptJlController extends BaseController
     public AjaxResult getList(SysDeptJl sysDeptJl)
     {
         if(StringUtils.isEmpty(sysDeptJl.getParentId()) && StringUtils.isEmpty(sysDeptJl.getId())){
-            sysDeptJl.setParentId(OtherConstants.DEPT_ID_JL_GJ);
+            sysDeptJl.setParentId(OtherConstants.DEPT_ID_GJ);
         }
         List<SysDeptJl> list = sysDeptJlService.selectSysDeptJlList(sysDeptJl);
         return AjaxResult.success(list);

+ 88 - 9
ruoyi-ui/src/views/system/zhgl/sqyljg/index.vue

@@ -52,6 +52,16 @@
           hasPermi="['organization:sqjgZhgl: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="['organization:sqjgZhgl:importData']"
+        >导入</el-button>
+      </el-col>
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
     </el-row>
 
@@ -86,14 +96,6 @@
             icon="el-icon-edit"
             @click="handleUpdate(scope.row,true)"
           >详情</el-button>
-<!--          v-hasPermi="['system:zhgl:edit']"-->
-          <!--<el-button-->
-            <!--size="mini"-->
-            <!--type="text"-->
-            <!--icon="el-icon-delete"-->
-            <!--@click="handleDelete(scope.row,scope.$index)"-->
-            <!--v-hasPermi="['system:zhgl:remove']"-->
-          <!--&gt;删除</el-button>-->
           <el-dropdown @command="changDate" trigger="click">
                 <span class="el-dropdown-link">
                   更多<i class="el-icon-arrow-down el-icon--right"></i>
@@ -181,12 +183,43 @@
         <el-button @click="cancel">取 消</el-button>
       </div>
     </el-dialog>
+
+    <!-- 用户导入对话框 -->
+    <el-dialog v-dialog-drag :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
+      <el-upload
+        ref="upload"
+        :limit="1"
+        accept=".xlsx, .xls"
+        :headers="upload.headers"
+        :action="upload.url"
+        :disabled="upload.isUploading"
+        :on-progress="handleFileUploadProgress"
+        :on-success="handleFileSuccess"
+        :auto-upload="false"
+        drag
+      >
+        <i class="el-icon-upload"></i>
+        <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
+        <div class="el-upload__tip text-center" slot="tip">
+<!--          <div class="el-upload__tip" slot="tip">-->
+<!--            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据-->
+<!--          </div>-->
+          <span>仅允许导入xls、xlsx格式文件。</span>
+          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
+        </div>
+      </el-upload>
+      <div slot="footer" class="dialog-footer">
+        <el-button type="primary" @click="submitFileForm">确 定</el-button>
+        <el-button @click="upload.open = false">取 消</el-button>
+      </div>
+    </el-dialog>
   </div>
 </template>
 
 <script>
 import {addZhgl, addUserZhxx, delZhgl, getZhgl, listZhgl, updateZhgl} from "@/api/system/yljgsqZhgl";
 import {chineseOne, Regular} from '@/utils/regular'
+import { getToken } from '@/utils/auth'
 
 export default {
   name: "Zhgl",
@@ -212,6 +245,21 @@ export default {
       title: "",
       // 是否显示弹出层
       open: false,
+      // 用户导入参数
+      upload: {
+        // 是否显示弹出层(用户导入)
+        open: false,
+        // 弹出层标题(用户导入)
+        title: "",
+        // 是否禁用上传
+        isUploading: false,
+        // 是否更新已经存在的用户数据
+        updateSupport: 0,
+        // 设置上传的请求头部
+        headers: { Authorization: "Bearer " + getToken() },
+        // 上传的地址
+        url: process.env.VUE_APP_BASE_API + "/organization/sqJcxx/importData"
+      },
       // 查询参数
       queryParams: {
         pageNum: 1,
@@ -364,6 +412,10 @@ export default {
       this.queryParams.pageNum = 1;
       this.getList();
     },
+    // /** 打开导入表弹窗 */
+    // openImportTable() {
+    //   this.$refs.import.show();
+    // },
     /** 重置按钮操作 */
     resetQuery() {
       this.resetForm("queryForm");
@@ -463,7 +515,34 @@ export default {
           this.getList();
         this.$modal.msgSuccess("删除成功");
       }).catch(() => {});
-    }
+    },
+    /** 导入按钮操作 */
+    handleImport() {
+      this.upload.title = "用户导入";
+      this.upload.open = true;
+    },
+    /** 下载模板操作 */
+    importTemplate() {
+      this.download('organization/sqJcxx/importTemplate', {
+      }, `jgzh_template_${new Date().getTime()}.xlsx`)
+    },
+    // 文件上传中处理
+    handleFileUploadProgress(event, file, fileList) {
+      this.upload.isUploading = true;
+    },
+    // 文件上传成功处理
+    handleFileSuccess(response, file, fileList) {
+      this.upload.open = false;
+      this.upload.isUploading = false;
+      this.$refs.upload.clearFiles();
+      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
+      this.getList();
+    },
+    // 提交上传文件
+    submitFileForm() {
+      this.$refs.upload.submit();
+    },
+
   }
 };
 </script>