Ver Fonte

优化用户信息导入功能(引起的数据错乱)

Simon há 1 ano atrás
pai
commit
0d047cfd07

+ 51 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TUserProfileServiceImpl.java

@@ -9,6 +9,8 @@ import java.sql.ResultSet;
 import java.util.Comparator;
 import java.util.List;
 
+import com.alibaba.fastjson.JSONObject;
+import com.ruoyi.common.core.domain.entity.SysDictData;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.system.domain.TDeviceList;
@@ -18,6 +20,7 @@ import com.ruoyi.system.domain.dto.TUserProfileDto;
 import com.ruoyi.system.domain.dto.UserAgeDto;
 import com.ruoyi.system.mapper.TDeviceListMapper;
 import com.ruoyi.system.mapper.TEmergentPeopleMapper;
+import com.ruoyi.system.service.ISysDictTypeService;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@@ -49,6 +52,8 @@ public class TUserProfileServiceImpl implements ITUserProfileService {
     private TEmergentPeopleMapper tEmergentPeopleMapper;
     @Autowired
     private TDeviceListMapper tDeviceListMapper;
+    @Autowired
+    private ISysDictTypeService dictTypeService;
 
     /**
      * 查询用户档案
@@ -122,6 +127,52 @@ public class TUserProfileServiceImpl implements ITUserProfileService {
             stringBuilder.append("!");
             throw new ServiceException(stringBuilder.toString());
         }
+        //TODO 关照之前逻辑
+        //特长
+        List<String> specialityList = new ArrayList<>();
+        if (tUserProfile.getSpeciality() != null && !tUserProfile.getSpeciality().isEmpty()) {
+            if (!tUserProfile.getSpeciality().startsWith("[") && !tUserProfile.getSpeciality().endsWith("]")) {
+                List<SysDictData> sysSpeciality = dictTypeService.selectDictDataByType("sys_speciality");
+                for (SysDictData data : sysSpeciality) {
+                    if (data.getDictLabel().contains(tUserProfile.getSpeciality())) {
+                        specialityList.add(data.getDictValue());
+                    }
+                }
+                tUserProfile.setSpeciality(JSONObject.toJSONString(specialityList));
+            }
+        } else {
+            tUserProfile.setSpeciality(JSONObject.toJSONString(specialityList));
+        }
+        //爱好
+        List<String> hobbyList = new ArrayList<>();
+        if (tUserProfile.getHobby() != null && !tUserProfile.getHobby().isEmpty()) {
+            if (!tUserProfile.getHobby().startsWith("[") && !tUserProfile.getHobby().endsWith("]")) {
+                List<SysDictData> sysHobby = dictTypeService.selectDictDataByType("sys_hobby");
+                for (SysDictData data : sysHobby) {
+                    if (data.getDictLabel().contains(tUserProfile.getHobby())) {
+                        hobbyList.add(data.getDictValue());
+                    }
+                }
+                tUserProfile.setHobby(JSONObject.toJSONString(hobbyList));
+            }
+        } else {
+            tUserProfile.setHobby(JSONObject.toJSONString(hobbyList));
+        }
+        //慢性疾病
+        List<String> slowIllnessList = new ArrayList<>();
+        if (tUserProfile.getSlowIllness() != null && !tUserProfile.getSlowIllness().isEmpty()) {
+            if (!tUserProfile.getSlowIllness().startsWith("[") && !tUserProfile.getSlowIllness().endsWith("]")) {
+                List<SysDictData> sysSlowIllness = dictTypeService.selectDictDataByType("sys_slow_illness");
+                for (SysDictData data : sysSlowIllness) {
+                    if (data.getDictLabel().contains(tUserProfile.getSlowIllness())) {
+                        slowIllnessList.add(data.getDictValue());
+                    }
+                }
+                tUserProfile.setSlowIllness(JSONObject.toJSONString(slowIllnessList));
+            }
+        } else {
+            tUserProfile.setSlowIllness(JSONObject.toJSONString(slowIllnessList));
+        }
         int rows = tUserProfileMapper.insertTUserProfile(tUserProfile);
         insertTEmergentPeople(tUserProfile);
         return rows;