Simon 1 year ago
parent
commit
bceb4772e3

+ 0 - 5
ruoyi-admin/pom.xml

@@ -67,11 +67,6 @@
             <artifactId>fastjson2</artifactId>
             <version>2.0.39</version>
         </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-        </dependency>
-
 
     </dependencies>
 

+ 16 - 4
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TDeviceListController.java

@@ -6,6 +6,7 @@ import javax.servlet.http.HttpServletResponse;
 
 import com.alibaba.fastjson2.JSONObject;
 import com.ruoyi.system.domain.TServiceManage;
+import com.ruoyi.system.domain.TUserProfile;
 import com.ruoyi.system.domain.dto.*;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -111,20 +112,31 @@ public class TDeviceListController extends BaseController
         util.importTemplateExcel(response, "设备列表模板");
     }
 
+//    /**
+//     * 导入
+//     */
+//    @Log(title = "设备列表", businessType = BusinessType.IMPORT)
+//    @PostMapping("/importData")
+//    @ResponseBody
+//    public AjaxResult importData(MultipartFile file) throws Exception
+//    {
+//        ExcelUtil<TDeviceList> util = new ExcelUtil<TDeviceList>(TDeviceList.class);
+//        List<TDeviceList> tDeviceLists = util.importExcel(file.getInputStream());
+//        String message = tDeviceListService.importTDeviceList(tDeviceLists);
+//        return AjaxResult.success(message);
+//    }
     /**
      * 导入
      */
     @Log(title = "设备列表", businessType = BusinessType.IMPORT)
     @PostMapping("/importData")
     @ResponseBody
-    public AjaxResult importData(MultipartFile file) throws Exception
-    {
+    public AjaxResult importDataV2(MultipartFile file) throws Exception {
         ExcelUtil<TDeviceList> util = new ExcelUtil<TDeviceList>(TDeviceList.class);
         List<TDeviceList> tDeviceLists = util.importExcel(file.getInputStream());
-        String message = tDeviceListService.importTDeviceList(tDeviceLists);
+        String message = tDeviceListService.importTDeviceListV2(tDeviceLists);
         return AjaxResult.success(message);
     }
-
     /**
      * 查询心率列表
      */

+ 8 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/ITDeviceListService.java

@@ -93,6 +93,14 @@ public interface ITDeviceListService
      */
     public String importTDeviceList(List<TDeviceList> tDeviceLists);
 
+    /**
+     * 导入设备列表数据
+     *
+     * @param tDeviceLists 设备列表列表
+     * @return 结果
+     */
+    public String importTDeviceListV2(List<TDeviceList> tDeviceLists);
+
     /**
      * 新增设备列
      * 

+ 124 - 53
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDeviceListServiceImpl.java

@@ -17,16 +17,16 @@ import org.springframework.stereotype.Service;
 import com.ruoyi.system.mapper.TDeviceListMapper;
 import com.ruoyi.system.domain.TDeviceList;
 import com.ruoyi.system.service.ITDeviceListService;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
  * 设备列Service业务层处理
- * 
+ *
  * @author zhengjie
  * @date 2023-08-30
  */
 @Service
-public class TDeviceListServiceImpl implements ITDeviceListService 
-{
+public class TDeviceListServiceImpl implements ITDeviceListService {
     @Autowired
     private TDeviceListMapper tDeviceListMapper;
     @Autowired
@@ -36,25 +36,23 @@ public class TDeviceListServiceImpl implements ITDeviceListService
 
     /**
      * 查询设备列
-     * 
+     *
      * @param id 设备列主键
      * @return 设备列
      */
     @Override
-    public TDeviceList selectTDeviceListById(Integer id)
-    {
+    public TDeviceList selectTDeviceListById(Integer id) {
         return tDeviceListMapper.selectTDeviceListById(id);
     }
 
     /**
      * 查询设备列列表
-     * 
+     *
      * @param tDeviceList 设备列
      * @return 设备列
      */
     @Override
-    public List<TDeviceList> selectTDeviceListList(TDeviceList tDeviceList)
-    {
+    public List<TDeviceList> selectTDeviceListList(TDeviceList tDeviceList) {
         return tDeviceListMapper.selectTDeviceListList(tDeviceList);
     }
 
@@ -95,19 +93,19 @@ public class TDeviceListServiceImpl implements ITDeviceListService
 
     /**
      * 新增设备列
-     * 
+     *
      * @param tDeviceList 设备列
      * @return 结果
      */
+    @Transactional
     @Override
-    public int insertTDeviceList(TDeviceList tDeviceList)
-    {
+    public int insertTDeviceList(TDeviceList tDeviceList) {
         TFacility tFacility = new TFacility();
-        if (StringUtils.isNotNull(tDeviceList.getDeviceId())){
+        if (StringUtils.isNotNull(tDeviceList.getDeviceId())) {
             tFacility.setCode(tDeviceList.getDeviceId());
-        }else if (StringUtils.isNotNull(tDeviceList.getSimCode())){
+        } else if (StringUtils.isNotNull(tDeviceList.getSimCode())) {
             tFacility.setTelno(tDeviceList.getSimCode());
-        }else if (StringUtils.isNotNull(tDeviceList.getSerialNumber())){
+        } else if (StringUtils.isNotNull(tDeviceList.getSerialNumber())) {
             tFacility.setIccid(tDeviceList.getSerialNumber());
         }
         tFacility.setCreateTime(DateUtils.getNowDate());
@@ -118,19 +116,18 @@ public class TDeviceListServiceImpl implements ITDeviceListService
 
     /**
      * 修改设备列
-     * 
+     *
      * @param tDeviceList 设备列
      * @return 结果
      */
     @Override
-    public int updateTDeviceList(TDeviceList tDeviceList)
-    {
+    public int updateTDeviceList(TDeviceList tDeviceList) {
         return tDeviceListMapper.updateTDeviceList(tDeviceList);
     }
 
     /**
      * 批量删除设备列
-     * 
+     *
      * @param ids 需要删除的设备列主键
      * @return 结果
      */
@@ -154,7 +151,7 @@ public class TDeviceListServiceImpl implements ITDeviceListService
 
     /**
      * 删除设备列信息
-     * 
+     *
      * @param id 设备列主键
      * @return 结果
      */
@@ -171,55 +168,129 @@ public class TDeviceListServiceImpl implements ITDeviceListService
     @Override
     public String importTDeviceList(List<TDeviceList> tDeviceLists) {
 
-        if (StringUtils.isNull(tDeviceLists) || tDeviceLists.size() == 0)
-        {
+        if (StringUtils.isNull(tDeviceLists) || tDeviceLists.size() == 0) {
             throw new ServiceException("导入设备列表信息数据不能为空!");
         }
         int successNum = 0;
         int failureNum = 0;
         StringBuilder successMsg = new StringBuilder();
         StringBuilder failureMsg = new StringBuilder();
-        for (TDeviceList tDeviceList : tDeviceLists)
-        {
-            try
-            {
+        for (TDeviceList tDeviceList : tDeviceLists) {
+            try {
                 TUserProfile user = tUserProfileMapper.selectTUserProfileBySfzId(tDeviceList.getSfzid());
                 TDeviceList device = tDeviceListMapper.selectTDeviceListListByDeviceId(tDeviceList.getDeviceId());
-                if (StringUtils.isNotNull(user) && StringUtils.isNull(device))
-                {
+                if (StringUtils.isNotNull(user) && StringUtils.isNull(device)) {
                     tDeviceList.setUserid(user.getId());
                     tDeviceList.setSfzid(user.getSfzid());
                     tDeviceList.setTelno(user.getTelOne());
                     this.insertTDeviceList(tDeviceList);
                     successNum++;
                     successMsg.append("<br/>" + successNum + "设备列表信息" + " 导入成功");
-                }
-                else
-                {
+                } else {
                     failureNum++;
                     failureMsg.append("<br/>" + failureNum + "设备列表信息" + " 信息不完整");
                 }
-            }
-            catch (Exception e)
-            {
+            } catch (Exception e) {
                 failureNum++;
                 String msg = "<br/>" + failureNum + "设备列表信息" + " 导入失败:";
                 failureMsg.append(msg + e.getMessage());
             }
         }
-        if (failureNum > 0)
-        {
+        if (failureNum > 0) {
             failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
             throw new ServiceException(failureMsg.toString());
-        }
-        else
-        {
+        } else {
             successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
         }
         return successMsg.toString();
 
     }
 
+    @Transactional
+    @Override
+    public String importTDeviceListV2(List<TDeviceList> tDeviceLists) {
+        if (tDeviceLists == null || tDeviceLists.isEmpty()) {
+            throw new ServiceException("导入设备列表信息数据不能为空!");
+        }
+        //批量导入设备数据
+        for (TDeviceList deviceListEntity : tDeviceLists) {
+            //判断提交数据格式是否正确
+            if (deviceListEntity.getSfzid() == null || deviceListEntity.getSfzid().isEmpty()) {
+                throw new ServiceException("导入设备数信息身份证号格式异常!");
+            }
+            //根据身份证号查询数据库中的用户信息
+            TUserProfile user = tUserProfileMapper.selectTUserProfileBySfzId(deviceListEntity.getSfzid());
+            if (user == null) {
+                //如果表中有该用户则提示
+                StringBuilder stringBuilder = new StringBuilder();
+                stringBuilder.append("导入设备数信息未匹配到用户");
+                //如果有设备标识ID,则提示
+                if (!StringUtils.isEmpty(deviceListEntity.getDeviceId())) {
+                    stringBuilder.append(", 设备标识ID:" + deviceListEntity.getDeviceId());
+                }
+                //如果有设备标识ID,则提示
+                if (!StringUtils.isEmpty(deviceListEntity.getName())) {
+                    stringBuilder.append(", 用户名:" + deviceListEntity.getName());
+                }
+                //如果有身份证号,则提示
+                if (!StringUtils.isEmpty(deviceListEntity.getSfzid())) {
+                    stringBuilder.append(", 身份证号:" + deviceListEntity.getSfzid());
+                }
+                stringBuilder.append("!");
+                throw new ServiceException(stringBuilder.toString());
+            }
+            //根据设备ID查询数据库中的设备信息
+            List<TFacility> facilityList = tFacilityMapper.selectTDeviceListListByDeviceId(deviceListEntity.getDeviceId());
+            if (facilityList != null && !facilityList.isEmpty()) {
+                //如果表中有该用户则提示
+                StringBuilder stringBuilder = new StringBuilder();
+                stringBuilder.append("导入设备信息已存在");
+                //如果有设备标识ID,则提示
+                if (!StringUtils.isEmpty(deviceListEntity.getDeviceId())) {
+                    stringBuilder.append(", 设备标识ID:" + deviceListEntity.getDeviceId());
+                }
+                //如果有设备标识ID,则提示
+                if (!StringUtils.isEmpty(deviceListEntity.getName())) {
+                    stringBuilder.append(", 用户名:" + deviceListEntity.getName());
+                }
+                //如果有身份证号,则提示
+                if (!StringUtils.isEmpty(deviceListEntity.getSfzid())) {
+                    stringBuilder.append(", 身份证号:" + deviceListEntity.getSfzid());
+                }
+                stringBuilder.append("!");
+                throw new ServiceException(stringBuilder.toString());
+            }
+            //根据设备ID查询数据库中的设备信息
+            TDeviceList device = tDeviceListMapper.selectTDeviceListListByDeviceId(deviceListEntity.getDeviceId());
+            if (device != null) {
+                //如果表中有该用户则提示
+                StringBuilder stringBuilder = new StringBuilder();
+                stringBuilder.append("导入设备信息已存在");
+                //如果有设备标识ID,则提示
+                if (!StringUtils.isEmpty(deviceListEntity.getDeviceId())) {
+                    stringBuilder.append(", 设备标识ID:" + deviceListEntity.getDeviceId());
+                }
+                //如果有设备标识ID,则提示
+                if (!StringUtils.isEmpty(deviceListEntity.getName())) {
+                    stringBuilder.append(", 用户名:" + deviceListEntity.getName());
+                }
+                //如果有身份证号,则提示
+                if (!StringUtils.isEmpty(deviceListEntity.getSfzid())) {
+                    stringBuilder.append(", 身份证号:" + deviceListEntity.getSfzid());
+                }
+                stringBuilder.append("!");
+                throw new ServiceException(stringBuilder.toString());
+            }
+            deviceListEntity.setUserid(user.getId());
+            deviceListEntity.setSfzid(user.getSfzid());
+            deviceListEntity.setTelno(user.getTelOne());
+            this.insertTDeviceList(deviceListEntity);
+        }
+        StringBuilder successMsg = new StringBuilder();
+        successMsg.append("恭喜您,数据已全部导入成功!共 " + tDeviceLists.size() + " 条,数据如下:");
+        return successMsg.toString();
+    }
+
     /**
      * 判断报警信息
      *
@@ -227,8 +298,8 @@ public class TDeviceListServiceImpl implements ITDeviceListService
      * @return 结果
      */
     @Override
-    public String checkMessage(Integer alarm_type){
-        switch (alarm_type){
+    public String checkMessage(Integer alarm_type) {
+        switch (alarm_type) {
             case 16:
                 return "SOS报警";
             case 17:
@@ -252,39 +323,39 @@ public class TDeviceListServiceImpl implements ITDeviceListService
 
     @Override
     public int deviceValue(CallPoliceDto callPoliceDto) {
-        if (StringUtils.isNotNull(callPoliceDto)){
-            if (StringUtils.isNotNull(callPoliceDto.getShouhuan_blood_high_max())){
+        if (StringUtils.isNotNull(callPoliceDto)) {
+            if (StringUtils.isNotNull(callPoliceDto.getShouhuan_blood_high_max())) {
                 tDeviceListMapper.updateTSettingshouhuan_blood_high_max(callPoliceDto.getShouhuan_blood_high_max());
             }
-            if (StringUtils.isNotNull(callPoliceDto.getShouhuan_blood_high_min())){
+            if (StringUtils.isNotNull(callPoliceDto.getShouhuan_blood_high_min())) {
                 tDeviceListMapper.updateTSettingshouhuan_blood_high_min(callPoliceDto.getShouhuan_blood_high_min());
             }
-            if (StringUtils.isNotNull(callPoliceDto.getShouhuan_blood_low_max())){
+            if (StringUtils.isNotNull(callPoliceDto.getShouhuan_blood_low_max())) {
                 tDeviceListMapper.updateTSettingshouhuan_blood_low_max(callPoliceDto.getShouhuan_blood_low_max());
             }
-            if (StringUtils.isNotNull(callPoliceDto.getShouhuan_blood_low_min())){
+            if (StringUtils.isNotNull(callPoliceDto.getShouhuan_blood_low_min())) {
                 tDeviceListMapper.updateTSettingshouhuan_blood_low_min(callPoliceDto.getShouhuan_blood_low_min());
             }
-            if (StringUtils.isNotNull(callPoliceDto.getShouhuan_body_max())){
+            if (StringUtils.isNotNull(callPoliceDto.getShouhuan_body_max())) {
                 tDeviceListMapper.updateTSettingshouhuan_body_max(callPoliceDto.getShouhuan_body_max());
             }
-            if (StringUtils.isNotNull(callPoliceDto.getShouhuan_body_min())){
+            if (StringUtils.isNotNull(callPoliceDto.getShouhuan_body_min())) {
                 tDeviceListMapper.updateTSettingshouhuan_body_min(callPoliceDto.getShouhuan_body_min());
             }
-            if (StringUtils.isNotNull(callPoliceDto.getShouhuan_oxygen_max())){
+            if (StringUtils.isNotNull(callPoliceDto.getShouhuan_oxygen_max())) {
                 tDeviceListMapper.updateTSettingshouhuan_oxygen_max(callPoliceDto.getShouhuan_oxygen_max());
             }
-            if (StringUtils.isNotNull(callPoliceDto.getShouhuan_oxygen_min())){
+            if (StringUtils.isNotNull(callPoliceDto.getShouhuan_oxygen_min())) {
                 tDeviceListMapper.updateTSettingshouhuan_oxygen_min(callPoliceDto.getShouhuan_oxygen_min());
             }
-            if (StringUtils.isNotNull(callPoliceDto.getShouhuan_heart_max())){
+            if (StringUtils.isNotNull(callPoliceDto.getShouhuan_heart_max())) {
                 tDeviceListMapper.updateTSettingshouhuan_heart_max(callPoliceDto.getShouhuan_heart_max());
             }
-            if (StringUtils.isNotNull(callPoliceDto.getShouhuan_heart_min())){
+            if (StringUtils.isNotNull(callPoliceDto.getShouhuan_heart_min())) {
                 tDeviceListMapper.updateTSettingshouhuan_heart_min(callPoliceDto.getShouhuan_heart_min());
             }
             return 1;
-        }else{
+        } else {
             return 0;
         }
     }

+ 0 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TRegionServiceImpl.java

@@ -5,7 +5,6 @@ import java.util.List;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.system.domain.TRegionVo;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.SpringApplication;
 import org.springframework.stereotype.Service;
 import com.ruoyi.system.mapper.TRegionMapper;
 import com.ruoyi.system.domain.TRegion;

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

@@ -38,7 +38,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <include refid="selectTFacilityVo"/>
         where id = #{id}
     </select>
-        
+ 	<select id="selectTFacilityByCode" resultMap="TFacilityResult">
+        <include refid="selectTFacilityVo"/>
+        where code = #{code}
+    </select>
+    <select id="selectTDeviceListListByDeviceId" parameterType="string" resultMap="TFacilityResult">
+        <include refid="selectTFacilityVo"/>
+        where code = #{code}
+    </select>
+
     <insert id="insertTFacility" parameterType="TFacility" useGeneratedKeys="true" keyProperty="id">
         insert into t_facility
         <trim prefix="(" suffix=")" suffixOverrides=",">