|
|
@ -1,11 +1,14 @@ |
|
|
|
package com.storeroom.modules.archives.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.json.JSONArray; |
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
import com.storeroom.modules.archives.repository.ArchivesSummaryRepository; |
|
|
|
import com.storeroom.modules.archives.service.ArchivesService; |
|
|
|
import com.storeroom.modules.dictionary.domain.ArchivesDictionary; |
|
|
|
import com.storeroom.modules.dictionary.domain.ArchivesType; |
|
|
|
import com.storeroom.modules.dictionary.repository.ArchivesDictionaryRepository; |
|
|
|
import com.storeroom.modules.dictionary.repository.ArchivesTypeRepository; |
|
|
|
import com.storeroom.utils.StringUtils; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import org.springframework.data.domain.Pageable; |
|
|
|
import org.springframework.data.domain.Sort; |
|
|
@ -13,6 +16,7 @@ import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.persistence.EntityManager; |
|
|
|
import javax.persistence.PersistenceContext; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Optional; |
|
|
@ -50,10 +54,36 @@ public class ArchivesServiceImpl implements ArchivesService { |
|
|
|
quertOrder = " order by " + quertOrder.substring(0,quertOrder.length()-1); |
|
|
|
|
|
|
|
List<Object[]> list = entityManager.createNativeQuery("select "+queryField+" from "+queryTable+quertOrder).getResultList(); |
|
|
|
JSONArray jsons = new JSONArray(); |
|
|
|
jsons.put(queryFields); |
|
|
|
jsons.put(list); |
|
|
|
return jsons; |
|
|
|
JSONObject json = new JSONObject(); |
|
|
|
json.put("queryFields",queryFields); |
|
|
|
json.put("showlist",list); |
|
|
|
return json; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Object doedit(String categoryId,String archivesId) { |
|
|
|
JSONObject json = new JSONObject(); |
|
|
|
List<ArchivesDictionary> showFiled = archivesDictionaryRepository.findAllByCategoryIdAndIsInputOrderByIsSequenceAsc(categoryId,true); |
|
|
|
if(!StringUtils.isEmpty(archivesId)){ |
|
|
|
ArchivesType archivesType = archivesTypeRepository.findById(categoryId).get(); |
|
|
|
List<String> queryFields = new ArrayList<>(); |
|
|
|
for(ArchivesDictionary archivesDictionary:showFiled){ |
|
|
|
queryFields.add(archivesDictionary.getFieldName()); |
|
|
|
} |
|
|
|
String queryField = queryFields.stream().map(String::valueOf).collect(Collectors.joining(",")); |
|
|
|
String queryTable = archivesType.getEnName(); |
|
|
|
List<Object[]> list = entityManager.createNativeQuery("select "+queryField+" from "+queryTable + " where id = '"+archivesId+"'").getResultList(); |
|
|
|
Object[] doeditEntity = list.size() > 0 ? list.get(0) : null; |
|
|
|
if(null != doeditEntity){ |
|
|
|
JSONObject echo = new JSONObject(); |
|
|
|
for(int i = 0;i<queryFields.size();i++){ |
|
|
|
echo.put(queryFields.get(i),doeditEntity[i]); |
|
|
|
} |
|
|
|
json.put("echo",echo); |
|
|
|
} |
|
|
|
} |
|
|
|
json.put("showFiled",showFiled); |
|
|
|
return json; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|