Simon 1 年之前
父节点
当前提交
f086f6be78

+ 52 - 38
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TDataDisplayController.java

@@ -25,13 +25,14 @@ import java.util.stream.Collectors;
 
 /**
  * 数据大屏Controller
- *
+ * 
  * @author zhengjie
  * @date 2023-09-08
  */
 @RestController
 @RequestMapping("/system/display")
-public class TDataDisplayController extends BaseController {
+public class TDataDisplayController extends BaseController
+{
     @Autowired
     private ITShouhuanAlarmListService tShouhuanAlarmListService;
 
@@ -51,11 +52,12 @@ public class TDataDisplayController extends BaseController {
      * 查询SOS预警处理列表
      */
     @GetMapping("/list")
-    public TableDataInfo list(DataAlarmListDto dataAlarmListDto) {
+    public TableDataInfo list(DataAlarmListDto dataAlarmListDto)
+    {
         startPage();
         List<DataAlarmListDto> list = tShouhuanAlarmListService.selectTShouhuanAlarmList(dataAlarmListDto);
         List<AlarmListDto> alarmListDtoList = new ArrayList<>();
-        for (DataAlarmListDto dto : list) {
+        for (DataAlarmListDto dto : list){
             AlarmListDto alarmListDto = new AlarmListDto();
             alarmListDto.setName(dto.getName());
             alarmListDto.setTelno(dto.getTel_one());
@@ -64,16 +66,18 @@ public class TDataDisplayController extends BaseController {
             alarmListDto.setCreatetime(dto.getCreatetime());
             alarmListDtoList.add(alarmListDto);
         }
-        return getDataTable1(alarmListDtoList, tShouhuanAlarmListService.selectTShouhuanAlarmListCount());
+        return getDataTable1(alarmListDtoList,tShouhuanAlarmListService.selectTShouhuanAlarmListCount());
     }
 
     @GetMapping("/count")
-    public AjaxResult count() {
+    public AjaxResult count()
+    {
         return success(tShouhuanAlarmListService.selectTShouhuanAlarmListCount());
     }
 
     @GetMapping("/alarm")
-    public AjaxResult alarm() {
+    public AjaxResult alarm()
+    {
         AlarmStatusDto dto = new AlarmStatusDto();
         dto.setAlarmSOSSolve(tShouhuanAlarmListService.selectTShouhuanAlarmSOSSolve());
         dto.setUn_alarmSOSSolve(tShouhuanAlarmListService.selectTShouhuanAlarmSOS() - tShouhuanAlarmListService.selectTShouhuanAlarmSOSSolve());
@@ -91,20 +95,22 @@ public class TDataDisplayController extends BaseController {
     }
 
     @GetMapping("/percent")
-    public AjaxResult percent() {
+    public AjaxResult percent()
+    {
         AlarmPercentDto dto = new AlarmPercentDto();
-        dto.setAlarmSOS(checkPercent(tShouhuanAlarmListService.selectTShouhuanAlarmSOSSolve(), tShouhuanAlarmListService.selectTShouhuanAlarmSOS()));
-        dto.setAlarmRail(checkPercent(tShouhuanAlarmListService.selectTShouhuanAlarmRailSolve(), tShouhuanAlarmListService.selectTShouhuanAlarmRail()));
-        dto.setAlarmFall(checkPercent(tShouhuanAlarmListService.selectTShouhuanAlarmFallSolve(), tShouhuanAlarmListService.selectTShouhuanAlarmFall()));
+        dto.setAlarmSOS(checkPercent(tShouhuanAlarmListService.selectTShouhuanAlarmSOSSolve(),tShouhuanAlarmListService.selectTShouhuanAlarmSOS()));
+        dto.setAlarmRail(checkPercent(tShouhuanAlarmListService.selectTShouhuanAlarmRailSolve(),tShouhuanAlarmListService.selectTShouhuanAlarmRail()));
+        dto.setAlarmFall(checkPercent(tShouhuanAlarmListService.selectTShouhuanAlarmFallSolve(),tShouhuanAlarmListService.selectTShouhuanAlarmFall()));
         int statusSum = tShouhuanAlarmListService.selectTShouhuanAlarmStatus() + tShouhuanAlarmListService.selectTShouhuanAlarmStatusSolve();
-        dto.setAlarmStauts(checkPercent(tShouhuanAlarmListService.selectTShouhuanAlarmStatus(), statusSum));
+        dto.setAlarmStauts(checkPercent(tShouhuanAlarmListService.selectTShouhuanAlarmStatus(),statusSum));
         int alarmAll = tShouhuanAlarmListService.selectTShouhuanAlarmSOSSolve() + tShouhuanAlarmListService.selectTShouhuanAlarmRailSolve() + tShouhuanAlarmListService.selectTShouhuanAlarmRailSolve() + tShouhuanAlarmListService.selectTShouhuanAlarmFallSolve() + tShouhuanAlarmListService.selectTShouhuanAlarmOtherSolve();
-        dto.setAlarmAll(checkPercent(alarmAll, tShouhuanAlarmListService.selectTShouhuanAlarmListCount()));
+        dto.setAlarmAll(checkPercent(alarmAll,tShouhuanAlarmListService.selectTShouhuanAlarmListCount()));
         return success(dto);
     }
 
     @GetMapping("/deviceView")
-    public AjaxResult deviceView() {
+    public AjaxResult deviceView()
+    {
         DeviceViewDto dto = new DeviceViewDto();
         dto.setDeviceCount(tShouhuanAlarmListService.selectTShouhuanAlarmStatus() + tShouhuanAlarmListService.selectTShouhuanAlarmStatusSolve());
         dto.setDeviceOnline(tShouhuanAlarmListService.selectTShouhuanAlarmStatus());
@@ -114,37 +120,40 @@ public class TDataDisplayController extends BaseController {
     }
 
     @GetMapping("/deviceType")
-    public AjaxResult deviceType() {
+    public AjaxResult deviceType()
+    {
         Integer total = tDeviceListService.selectDeviceListCount();
         List<DeviceTypeDto> deviceListDto = tDeviceListService.selectDeviceListDto();
-        for (DeviceTypeDto listDto : deviceListDto) {
+        for (DeviceTypeDto listDto : deviceListDto){
             listDto.setDeviceStr(checkDeviceType(listDto.getDevice_model()));
-            listDto.setDevicePercent(checkPercent(listDto.getCount(), total));
+            listDto.setDevicePercent(checkPercent(listDto.getCount(),total));
         }
         AjaxResult ajax = new AjaxResult();
-        ajax.put("list", deviceListDto);
+        ajax.put("list",deviceListDto);
         ajax.put("total", total);
-        return AjaxResult.success("操作成功", ajax);
+        return AjaxResult.success("操作成功",ajax);
     }
 
     @GetMapping("/userAgeAll")
-    public AjaxResult userAgeAll() {
+    public AjaxResult userAgeAll()
+    {
         Integer total = userProfileService.selectuserAgeCount();
         List<UserAgeDto> dtoList = userProfileService.selectuserAgeDto();
         AjaxResult ajax = new AjaxResult();
-        ajax.put("list", dtoList);
+        ajax.put("list",dtoList);
         ajax.put("total", total);
-        return AjaxResult.success("操作成功", ajax);
+        return AjaxResult.success("操作成功",ajax);
     }
 
     @GetMapping("/mapGpsView")
-    public AjaxResult mapGpsView() {
+    public AjaxResult mapGpsView()
+    {
         List<MapGpsDto> dtoList = itShouhuanInfoService.selectMapGpsView();
         AjaxResult ajax = new AjaxResult();
         ajax.put("lnglat", dtoList);
         AjaxResult ajax1 = new AjaxResult();
-        ajax1.put("pointList", ajax);
-        return AjaxResult.success("操作成功", ajax1);
+        ajax1.put("pointList",ajax);
+        return AjaxResult.success("操作成功",ajax1);
     }
 
     @GetMapping("/mapGpsViewV2")
@@ -175,7 +184,8 @@ public class TDataDisplayController extends BaseController {
      * 用户新增
      */
     @GetMapping("/addUser")
-    public AjaxResult addUser() {
+    public AjaxResult addUser()
+    {
         List<AddUserDto> dtoList = userProfileService.selectAddUser();
         return success(dtoList);
     }
@@ -184,15 +194,17 @@ public class TDataDisplayController extends BaseController {
      * 设备新增
      */
     @GetMapping("/addDevice")
-    public AjaxResult addDevice() {
+    public AjaxResult addDevice()
+    {
         List<AddDeviceDto> dtoList = tDeviceListService.selectAddDevice();
         return success(dtoList);
     }
 
     @GetMapping("/alarmStatusList")
-    public AjaxResult alarmStatusList() {
+    public AjaxResult alarmStatusList()
+    {
         List<AlarmStatusListDto> dtoList = tShouhuanAlarmListService.selectAlarmStatusListDto();
-        for (AlarmStatusListDto dto : dtoList) {
+        for (AlarmStatusListDto dto : dtoList){
             dto.setAlarm_msg(tDeviceListService.checkMessage(dto.getAlarm_type()));
         }
         return success(dtoList);
@@ -202,7 +214,8 @@ public class TDataDisplayController extends BaseController {
      * 设备总览
      */
     @GetMapping("/deviceOver")
-    public AjaxResult deviceOver() {
+    public AjaxResult deviceOver()
+    {
         DeviceOverDto dto = new DeviceOverDto();
         dto.setBindDevice(tDeviceListService.selectDeviceListCount());
         dto.setBindUser(tDeviceListService.selectTDeviceListBandUser());
@@ -214,10 +227,11 @@ public class TDataDisplayController extends BaseController {
      * 查询SOS预警处理列表
      */
     @GetMapping("/alarmList")
-    public AjaxResult alarmList(DataAlarmListDto dataAlarmListDto) {
+    public AjaxResult alarmList(DataAlarmListDto dataAlarmListDto)
+    {
         List<DataAlarmListDto> list = tShouhuanAlarmListService.selectTShouhuanAlarmList(dataAlarmListDto);
         List<MessageAlarmListDto> messageAlarmListDtoList = new ArrayList<>();
-        for (DataAlarmListDto dto : list) {
+        for (DataAlarmListDto dto : list){
             MessageAlarmListDto alarmListDto = new MessageAlarmListDto();
             alarmListDto.setName(dto.getName());
             alarmListDto.setAlarm_msg(tDeviceListService.checkMessage(dto.getAlarm_type()));
@@ -233,13 +247,13 @@ public class TDataDisplayController extends BaseController {
     }
 
 
+
     /**
      * 逆地理编码
-     *
      * @param location
      * @return
      */
-    public String getCounterLocation(String location) {
+    public String getCounterLocation(String location){
 
         Map<String, String> params = new HashMap<>();
         params.put("location", location);
@@ -253,15 +267,15 @@ public class TDataDisplayController extends BaseController {
     /**
      * 计算百分比
      */
-    public String checkPercent(int num1, int num2) {
+    public String checkPercent(int num1, int num2){
         NumberFormat numberFormat = NumberFormat.getInstance();
         numberFormat.setMaximumFractionDigits(2);
-        String result = numberFormat.format((float) num1 / (float) num2 * 100);
+        String result = numberFormat.format((float)num1/(float)num2*100);
         return result;
     }
 
-    public String checkDeviceType(Integer device_model) {
-        switch (device_model) {
+    public String checkDeviceType(Integer device_model){
+        switch (device_model){
             case 0:
                 return "S8";
             case 1:

+ 6 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TFallSolveController.java

@@ -1,6 +1,10 @@
 package com.ruoyi.web.controller.system;
 
+import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
+import java.util.TreeSet;
+import java.util.stream.Collectors;
 import javax.servlet.http.HttpServletResponse;
 
 import com.ruoyi.common.utils.DateUtils;
@@ -53,7 +57,8 @@ public class TFallSolveController extends BaseController
             }
             salve.setAlarmMsg("跌倒告警求助:" + salve.getName() + "于" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,salve.getCreatetime()) + "发起跌倒告警求助");
         }
-        return getDataTable(list);
+        List<TFallSolve> collect=list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<TFallSolve>(Comparator.comparing(TFallSolve::getAid))), ArrayList::new));
+        return getDataTable(collect);
     }
 
     /**

+ 7 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/THealthSolveController.java

@@ -1,11 +1,16 @@
 package com.ruoyi.web.controller.system;
 
+import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
+import java.util.TreeSet;
+import java.util.stream.Collectors;
 import javax.servlet.http.HttpServletResponse;
 
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.system.domain.TRailSolve;
+import com.ruoyi.system.domain.TSosSolve;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -53,7 +58,8 @@ public class THealthSolveController extends BaseController
             }
             salve.setAlarmMsg("健康告警求助:" + salve.getName() + "于" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,salve.getCreatetime()) + "发起健康告警求助");
         }
-        return getDataTable(list);
+        List<THealthSolve> collect=list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<THealthSolve>(Comparator.comparing(THealthSolve::getAid))), ArrayList::new));
+        return getDataTable(collect);
     }
 
     /**

+ 6 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TOtherSolveController.java

@@ -1,6 +1,10 @@
 package com.ruoyi.web.controller.system;
 
+import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
+import java.util.TreeSet;
+import java.util.stream.Collectors;
 import javax.servlet.http.HttpServletResponse;
 
 import com.ruoyi.common.utils.DateUtils;
@@ -53,7 +57,8 @@ public class TOtherSolveController extends BaseController
             }
             salve.setAlarmMsg("其他告警求助:" + salve.getName() + "于" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,salve.getCreatetime()) + "发起其他告警求助");
         }
-        return getDataTable(list);
+        List<TOtherSolve> collect=list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<TOtherSolve>(Comparator.comparing(TOtherSolve::getAid))), ArrayList::new));
+        return getDataTable(collect);
     }
 
     /**

+ 7 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TRailSolveController.java

@@ -1,11 +1,16 @@
 package com.ruoyi.web.controller.system;
 
+import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
+import java.util.TreeSet;
+import java.util.stream.Collectors;
 import javax.servlet.http.HttpServletResponse;
 
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.system.domain.TFallSolve;
+import com.ruoyi.system.domain.TOtherSolve;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -53,7 +58,8 @@ public class TRailSolveController extends BaseController
             }
             salve.setAlarmMsg("围栏告警求助:" + salve.getName() + "于" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,salve.getCreatetime()) + "发起围栏告警求助");
         }
-        return getDataTable(list);
+        List<TRailSolve> collect=list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<TRailSolve>(Comparator.comparing(TRailSolve::getAid))), ArrayList::new));
+        return getDataTable(collect);
     }
 
     /**

+ 4 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TSosSolveController.java

@@ -1,6 +1,7 @@
 package com.ruoyi.web.controller.system;
 
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 import javax.servlet.http.HttpServletResponse;
 
 import com.ruoyi.common.utils.DateUtils;
@@ -52,7 +53,8 @@ public class TSosSolveController extends BaseController
             }
             salve.setAlarmMsg("SOS紧急求助:" + salve.getName() + "于" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,salve.getCreatetime()) + "发起SOS紧急求助");
         }
-        return getDataTable(list);
+        List<TSosSolve> collect=list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<TSosSolve>(Comparator.comparing(TSosSolve::getAid))), ArrayList::new));
+        return getDataTable(collect);
     }
 
     /**

+ 2 - 2
ruoyi-admin/src/main/resources/application.yml

@@ -56,9 +56,9 @@ spring:
     # 测试环境
     #    active: test
     # 开发环境
-    active: dev
+#    active: dev
     # 生产环境
-#    active: druid
+    active: druid
 
   # 文件上传
   servlet:

+ 7 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/TDeviceListMapper.java

@@ -29,6 +29,13 @@ public interface TDeviceListMapper
      */
     public List<TDeviceList> selectTDeviceListList(TDeviceList tDeviceList);
 
+    /**
+     * 查询设备列列表
+     *
+     * @return 设备列集合
+     */
+    public TDeviceList selectTDeviceListListByDeviceId(String device_id_code);
+
     /**
      * 查询心率列表
      *

+ 3 - 10
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDeviceListServiceImpl.java

@@ -167,10 +167,10 @@ public class TDeviceListServiceImpl implements ITDeviceListService
         {
             try
             {
-
-                if (checkManageData(tDeviceList))
+                TUserProfile user = tUserProfileMapper.selectTUserProfileBySfzId(tDeviceList.getSfzid());
+                TDeviceList device = tDeviceListMapper.selectTDeviceListListByDeviceId(tDeviceList.getDeviceId());
+                if (StringUtils.isNotNull(user) && StringUtils.isNull(device))
                 {
-                    TUserProfile user = tUserProfileMapper.selectTUserProfileBySfzId(tDeviceList.getSfzid());
                     tDeviceList.setUserid(user.getId());
                     tDeviceList.setSfzid(user.getSfzid());
                     tDeviceList.setTelno(user.getTelOne());
@@ -204,13 +204,6 @@ public class TDeviceListServiceImpl implements ITDeviceListService
 
     }
 
-    public boolean checkManageData(TDeviceList tDeviceList){
-        return StringUtils.isNotNull(tDeviceList.getName()) && StringUtils.isNotNull(tDeviceList.getSfzid()) &&
-                StringUtils.isNotNull(tDeviceList.getTelno()) && StringUtils.isNotNull(tDeviceList.getDeviceId()) &&
-                StringUtils.isNotNull(tDeviceList.getGrantType());
-    }
-
-
     /**
      * 判断报警信息
      *

+ 3 - 7
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TUserProfileServiceImpl.java

@@ -146,7 +146,9 @@ public class TUserProfileServiceImpl implements ITUserProfileService
         {
             try
             {
-                if (checkManageData(tUserProfile))
+                // 验证是否存在这个人
+                TUserProfile u = tUserProfileMapper.selectTUserProfileBySfzId(tUserProfile.getSfzid() );
+                if (StringUtils.isNull(u))
                 {
                     this.insertTUserProfile(tUserProfile);
                     successNum++;
@@ -192,12 +194,6 @@ public class TUserProfileServiceImpl implements ITUserProfileService
         return tUserProfileMapper.selectAddUser();
     }
 
-    public boolean checkManageData(TUserProfile tUserProfile){
-        return StringUtils.isNotNull(tUserProfile.getName()) && StringUtils.isNotNull(tUserProfile.getGender()) &&
-                StringUtils.isNotNull(tUserProfile.getSfzid()) && StringUtils.isNotNull(tUserProfile.getTelOne()) &&
-                StringUtils.isNotNull(tUserProfile.getBirthday());
-    }
-
     /**
      * 新增紧急联系人信息
      * 

+ 7 - 0
ruoyi-system/src/main/resources/mapper/system/TDeviceListMapper.xml

@@ -114,6 +114,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="selectTDeviceListBandUser" resultType="java.lang.Integer">
         select count(distinct userid) from t_device_list
     </select>
+    <select id="selectTDeviceListListByDeviceId" resultMap="TDeviceListResult">
+        select a.id, a.device_proper, a.userid, a.factory, a.device_model, a.device_id, a.sim_code, a.serial_number, a.grant_type, a.price, a.cost, a.payment, a.createtime, b.status, b.id as fid, c.name,c.sfzid,c.tel_one,d.online_statis,d.electric_quantity,d.offlinetime from t_device_list a
+        left join t_facility b on a.device_id=b.code
+        left join t_user_profile c on a.userid=c.id
+        left join t_shouhuan_info d on a.device_id=d.device_id_code
+        where a.device_id = #{deviceId}
+    </select>
 
 
     <insert id="insertTDeviceList" parameterType="TDeviceList" useGeneratedKeys="true" keyProperty="id">

+ 1 - 1
ruoyi-system/src/main/resources/mapper/system/TUserProfileMapper.xml

@@ -140,7 +140,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </where>
     </select>
     <select id="selectTUserProfileBySfzId" resultType="com.ruoyi.system.domain.TUserProfile">
-        select id, name, gender, sfzid, tel_one, age, family_address from t_user_profile
+        select * from t_user_profile
         where sfzid = #{sfzid}
     </select>
     <select id="selectuserAgeDto" resultType="com.ruoyi.system.domain.dto.UserAgeDto">

+ 79 - 1
ruoyi-ui/src/views/system/device/index.vue

@@ -144,6 +144,16 @@
           v-hasPermi="['system:device:remove']"
         >删除</el-button>
       </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="info"
+          plain
+          icon="el-icon-upload2"
+          size="mini"
+          @click="handleImport"
+          v-hasPermi="['system:user:import']"
+        >导入</el-button>
+      </el-col>
       <el-col :span="1.5">
         <el-button
           type="warning"
@@ -197,7 +207,7 @@
         </template>
       </el-table-column>
     </el-table>
-    
+
     <pagination
       v-show="total>0"
       :total="total"
@@ -251,11 +261,38 @@
         <el-button @click="cancel">取 消</el-button>
       </div>
     </el-dialog>
+    <!-- 用户导入对话框 -->
+    <el-dialog :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 + '?updateSupport=' + upload.updateSupport"
+        :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">
+          <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 { listDevice, getDevice, delDevice, addDevice, updateDevice } from "@/api/system/device";
+import {getToken} from "@/utils/auth";
 
 export default {
   name: "Device",
@@ -279,6 +316,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 + "/system/device/importData"
+      },
       // 查询参数
       queryParams: {
         pageNum: 1,
@@ -354,6 +406,11 @@ export default {
       this.resetForm("queryForm");
       this.handleQuery();
     },
+    /** 导入按钮操作 */
+    handleImport() {
+      this.upload.title = "用户导入";
+      this.upload.open = true;
+    },
     // 多选框选中数据
     handleSelectionChange(selection) {
       this.ids = selection.map(item => item.id)
@@ -366,6 +423,11 @@ export default {
       this.open = true;
       this.title = "添加设备列";
     },
+    /** 下载模板操作 */
+    importTemplate() {
+      this.download('system/device/importTemplate', {
+      }, `user_template_${new Date().getTime()}.xlsx`)
+    },
     /** 修改按钮操作 */
     handleUpdate(row) {
       this.reset();
@@ -411,6 +473,22 @@ export default {
       this.download('system/device/export', {
         ...this.queryParams
       }, `device_${new Date().getTime()}.xlsx`)
+    },
+    // 提交上传文件
+    submitFileForm() {
+      this.$refs.upload.submit();
+    },
+    // 文件上传中处理
+    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();
     }
   }
 };