|
|
@ -5,10 +5,12 @@ import cn.hutool.json.JSONObject; |
|
|
|
import com.storeroom.modules.archives.repository.ArchivesSummaryRepository; |
|
|
|
import com.storeroom.modules.archives.service.ArchivesService; |
|
|
|
import com.storeroom.modules.archives.service.dto.ArchivesDTO; |
|
|
|
import com.storeroom.modules.common.ArchivesTypeEnum; |
|
|
|
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.NanoIdUtils; |
|
|
|
import com.storeroom.utils.StringUtils; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import org.springframework.data.domain.Pageable; |
|
|
@ -18,16 +20,15 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import javax.persistence.EntityManager; |
|
|
|
import javax.persistence.PersistenceContext; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Optional; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@Service |
|
|
|
@RequiredArgsConstructor |
|
|
|
public class ArchivesServiceImpl implements ArchivesService { |
|
|
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss.SSS"); |
|
|
|
private final ArchivesSummaryRepository archivesSummaryRepository; |
|
|
|
private final ArchivesTypeRepository archivesTypeRepository; |
|
|
|
private final ArchivesDictionaryRepository archivesDictionaryRepository; |
|
|
@ -36,7 +37,7 @@ public class ArchivesServiceImpl implements ArchivesService { |
|
|
|
EntityManager entityManager; |
|
|
|
|
|
|
|
@Override |
|
|
|
public Object initArchivesView(String categoryId, String query, Pageable page) { |
|
|
|
public Object initArchivesView(String categoryId, String query, boolean isdel,Pageable page) { |
|
|
|
categoryId = "FFAFBB1647D459C82080A"; |
|
|
|
Optional<ArchivesType> optional = archivesTypeRepository.findById(categoryId); |
|
|
|
if(!optional.isPresent()) |
|
|
@ -52,10 +53,11 @@ public class ArchivesServiceImpl implements ArchivesService { |
|
|
|
String[] splits = obj.toString().split(":"); |
|
|
|
quertOrder += splits[0].trim()+" "+splits[1].trim() +","; |
|
|
|
} |
|
|
|
String additional = isdel ? " where is_delete_time is not null " : " where is_delete_time is null "; |
|
|
|
if(objects.length > 0) |
|
|
|
quertOrder = " order by " + quertOrder.substring(0,quertOrder.length()-1); |
|
|
|
|
|
|
|
List<Object[]> list = entityManager.createNativeQuery("select "+queryField+" from "+queryTable+quertOrder).getResultList(); |
|
|
|
List<Object[]> list = entityManager.createNativeQuery("select "+queryField+" from "+queryTable+additional+quertOrder).getResultList(); |
|
|
|
JSONObject json = new JSONObject(); |
|
|
|
json.put("queryFields",queryFields); |
|
|
|
json.put("showlist",list); |
|
|
@ -91,6 +93,10 @@ public class ArchivesServiceImpl implements ArchivesService { |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Object edit(ArchivesDTO dto) { |
|
|
|
dto = new ArchivesDTO(); |
|
|
|
dto.setJsonString("{'category_name':'测试111','remarks':'这是一个备注2'}"); |
|
|
|
String dtoId = "42DA07A3174510955C5635"; |
|
|
|
// String dtoId = null; |
|
|
|
JSONObject json = new JSONObject(dto.getJsonString()); |
|
|
|
String categoryId = "FFAFBB1647D459C82080A"; |
|
|
|
ArchivesType archivesType = archivesTypeRepository.findById(categoryId).get(); |
|
|
@ -99,26 +105,55 @@ public class ArchivesServiceImpl implements ArchivesService { |
|
|
|
String insertValue = ""; |
|
|
|
String updateValue = ""; |
|
|
|
for(ArchivesDictionary archivesDictionary:showFiled){ |
|
|
|
insertFiled +="'"+archivesDictionary.getFieldName()+"',"; |
|
|
|
insertFiled +=archivesDictionary.getFieldName()+","; |
|
|
|
|
|
|
|
insertValue += archivesDictionary.getIsDataType() == 1 ? "'"+json.get(archivesDictionary.getFieldName())+"'," |
|
|
|
insertValue += archivesDictionary.getIsDataType() == 1 ? |
|
|
|
null == json.get(archivesDictionary.getFieldName()) ? null+"," : "'"+json.get(archivesDictionary.getFieldName())+"'," |
|
|
|
: json.get(archivesDictionary.getFieldName()) +","; |
|
|
|
updateValue += ""; |
|
|
|
String thisValue = |
|
|
|
archivesDictionary.getIsDataType() == 1 ? |
|
|
|
json.get(archivesDictionary.getFieldName()) == null ? null : "'"+json.get(archivesDictionary.getFieldName())+"'" |
|
|
|
:json.get(archivesDictionary.getFieldName())+""; |
|
|
|
updateValue += archivesDictionary.getFieldName() + "=" + thisValue +","; |
|
|
|
|
|
|
|
} |
|
|
|
insertFiled = insertFiled.length() != 0 ? insertFiled.substring(0,insertFiled.length()-1) : ""; |
|
|
|
insertValue = insertValue.length() != 0 ? insertValue.substring(0,insertValue.length()-1) : ""; |
|
|
|
String sql = StringUtils.isEmpty(dto.getId()) ? "insert into " + archivesType.getEnName() + "(" + insertFiled +") values ("+insertValue+")" |
|
|
|
: ""; |
|
|
|
updateValue = updateValue.length() != 0 ? updateValue.substring(0,updateValue.length()-1) : ""; |
|
|
|
insertFiled = "id,"+insertFiled; |
|
|
|
insertValue = "'"+NanoIdUtils.randomNanoId()+"',"+insertValue; |
|
|
|
String sql = StringUtils.isEmpty(dtoId) ? "insert into " + archivesType.getEnName() + "(" + insertFiled +") values ("+insertValue+")" |
|
|
|
: "update "+archivesType.getEnName() +" set "+updateValue+" where id = '"+dtoId+"'"; |
|
|
|
int result = entityManager.createNativeQuery(sql).executeUpdate(); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Object delete(ArchivesDTO dto) { |
|
|
|
dto.setId("42DA07A3174510955C5635"); |
|
|
|
dto.setCategoryId("FFAFBB1647D459C82080A"); |
|
|
|
ArchivesType archivesType = archivesTypeRepository.findById(dto.getCategoryId()).get(); |
|
|
|
String queryTable = archivesType.getEnName(); |
|
|
|
String sql = "update " + queryTable + " set is_delete_time = '" +sdf.format(new Date())+"',is_delete_man='"+dto.getDelMan()+"' where id = '"+dto.getId()+"'"; |
|
|
|
int result = entityManager.createNativeQuery(sql).executeUpdate(); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String test() { |
|
|
|
String testQuery = "dic_name,dic_code"; |
|
|
|
String testTable = "archives_dictionary_config"; |
|
|
|
List<Object[]> list = entityManager.createNativeQuery("select "+testQuery+" from "+testTable).getResultList(); |
|
|
|
return null; |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Object completelyDelete(ArchivesDTO dto) { |
|
|
|
dto.setId("42DA07A3174510955C5635"); |
|
|
|
dto.setCategoryId("FFAFBB1647D459C82080A"); |
|
|
|
ArchivesType archivesType = archivesTypeRepository.findById(dto.getCategoryId()).get(); |
|
|
|
String queryTable = archivesType.getEnName(); |
|
|
|
String sql = "delete from " +queryTable+" where id = '"+dto.getId()+"'"; |
|
|
|
int result = entityManager.createNativeQuery(sql).executeUpdate(); |
|
|
|
int result1 = 0; |
|
|
|
if(ArchivesTypeEnum.inChive.getCode() == archivesType.getIsType() || ArchivesTypeEnum.files.getCode() == archivesType.getIsType()){ |
|
|
|
String sql1 = "delete from file_" +queryTable+" where parents_id = '"+dto.getId()+"'"; |
|
|
|
result1 = entityManager.createNativeQuery(sql1).executeUpdate(); |
|
|
|
} |
|
|
|
return result+","+result1; |
|
|
|
} |
|
|
|
} |