Browse Source

更新档案表

新增档案配置表字段类型
master
xia 3 years ago
parent
commit
25dd61549a
  1. 23
      archives/src/main/java/com/storeroom/modules/archives/controller/ArchivesController.java
  2. 8
      archives/src/main/java/com/storeroom/modules/archives/service/ArchivesService.java
  3. 4
      archives/src/main/java/com/storeroom/modules/archives/service/dto/ArchivesDTO.java
  4. 69
      archives/src/main/java/com/storeroom/modules/archives/service/impl/ArchivesServiceImpl.java
  5. 4
      archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesDictionary.java

23
archives/src/main/java/com/storeroom/modules/archives/controller/ArchivesController.java

@ -4,6 +4,7 @@ import com.storeroom.modules.archives.service.ArchivesService;
import com.storeroom.modules.archives.service.dto.ArchivesDTO; import com.storeroom.modules.archives.service.dto.ArchivesDTO;
import com.storeroom.modules.dictionary.service.dto.FieldDTO; import com.storeroom.modules.dictionary.service.dto.FieldDTO;
import com.storeroom.utils.ApiResponse; import com.storeroom.utils.ApiResponse;
import com.storeroom.utils.SecurityUtils;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -22,9 +23,9 @@ public class ArchivesController {
@ApiOperation("档案列表") @ApiOperation("档案列表")
@GetMapping("/initArchivesView") @GetMapping("/initArchivesView")
public ApiResponse<Object> initArchivesView( public ApiResponse<Object> initArchivesView(
String categoryId,String query,Pageable page
String categoryId,String query,boolean isdel,Pageable page
){ ){
return ApiResponse.success(archivesService.initArchivesView(categoryId,query,page));
return ApiResponse.success(archivesService.initArchivesView(categoryId,query,isdel,page));
} }
@ApiOperation("档案预编辑") @ApiOperation("档案预编辑")
@ -43,13 +44,21 @@ public class ArchivesController {
return ApiResponse.success(archivesService.edit(dto)); return ApiResponse.success(archivesService.edit(dto));
} }
@ApiOperation("档案删除")
@PostMapping("/delete")
public ApiResponse<Object> delete(
@Validated @RequestBody ArchivesDTO dto
){
dto.setDelMan(SecurityUtils.getCurrentUsername());
return ApiResponse.success(archivesService.delete(dto));
}
@ApiOperation("测试档案")
@GetMapping("/test")
public ApiResponse<Object> test(
@ApiOperation("档案回收站删除")
@PostMapping("/completelyDelete")
public ApiResponse<Object> completelyDelete(
@Validated @RequestBody ArchivesDTO dto
){ ){
archivesService.test();
return ApiResponse.success(null);
return ApiResponse.success(archivesService.completelyDelete(dto));
} }
} }

8
archives/src/main/java/com/storeroom/modules/archives/service/ArchivesService.java

@ -5,11 +5,13 @@ import org.springframework.data.domain.Pageable;
public interface ArchivesService { public interface ArchivesService {
//初始化档案列表 //初始化档案列表
Object initArchivesView(String categoryId, String query, Pageable page);
Object initArchivesView(String categoryId, String query, boolean isdel,Pageable page);
//预编辑档案 初始化信息 //预编辑档案 初始化信息
Object doedit(String categoryId,String archivesId); Object doedit(String categoryId,String archivesId);
//编辑档案 //编辑档案
Object edit(ArchivesDTO dto); Object edit(ArchivesDTO dto);
String test();
//档案删除进回收站
Object delete(ArchivesDTO dto);
//档案回收站删除
Object completelyDelete(ArchivesDTO dto);
} }

4
archives/src/main/java/com/storeroom/modules/archives/service/dto/ArchivesDTO.java

@ -17,6 +17,10 @@ public class ArchivesDTO {
@JsonProperty("categoryId") @JsonProperty("categoryId")
private String categoryId; private String categoryId;
@JSONField(name="delMan")
@JsonProperty("delMan")
private String delMan;
@JSONField(name="jsonString") @JSONField(name="jsonString")
@JsonProperty("jsonString") @JsonProperty("jsonString")
private String jsonString; private String jsonString;

69
archives/src/main/java/com/storeroom/modules/archives/service/impl/ArchivesServiceImpl.java

@ -5,10 +5,12 @@ import cn.hutool.json.JSONObject;
import com.storeroom.modules.archives.repository.ArchivesSummaryRepository; import com.storeroom.modules.archives.repository.ArchivesSummaryRepository;
import com.storeroom.modules.archives.service.ArchivesService; import com.storeroom.modules.archives.service.ArchivesService;
import com.storeroom.modules.archives.service.dto.ArchivesDTO; 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.ArchivesDictionary;
import com.storeroom.modules.dictionary.domain.ArchivesType; import com.storeroom.modules.dictionary.domain.ArchivesType;
import com.storeroom.modules.dictionary.repository.ArchivesDictionaryRepository; import com.storeroom.modules.dictionary.repository.ArchivesDictionaryRepository;
import com.storeroom.modules.dictionary.repository.ArchivesTypeRepository; import com.storeroom.modules.dictionary.repository.ArchivesTypeRepository;
import com.storeroom.utils.NanoIdUtils;
import com.storeroom.utils.StringUtils; import com.storeroom.utils.StringUtils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
@ -18,16 +20,15 @@ import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext; 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; import java.util.stream.Collectors;
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class ArchivesServiceImpl implements ArchivesService { public class ArchivesServiceImpl implements ArchivesService {
SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss.SSS");
private final ArchivesSummaryRepository archivesSummaryRepository; private final ArchivesSummaryRepository archivesSummaryRepository;
private final ArchivesTypeRepository archivesTypeRepository; private final ArchivesTypeRepository archivesTypeRepository;
private final ArchivesDictionaryRepository archivesDictionaryRepository; private final ArchivesDictionaryRepository archivesDictionaryRepository;
@ -36,7 +37,7 @@ public class ArchivesServiceImpl implements ArchivesService {
EntityManager entityManager; EntityManager entityManager;
@Override @Override
public Object initArchivesView(String categoryId, String query, Pageable page) {
public Object initArchivesView(String categoryId, String query, boolean isdel,Pageable page) {
categoryId = "FFAFBB1647D459C82080A"; categoryId = "FFAFBB1647D459C82080A";
Optional<ArchivesType> optional = archivesTypeRepository.findById(categoryId); Optional<ArchivesType> optional = archivesTypeRepository.findById(categoryId);
if(!optional.isPresent()) if(!optional.isPresent())
@ -52,10 +53,11 @@ public class ArchivesServiceImpl implements ArchivesService {
String[] splits = obj.toString().split(":"); String[] splits = obj.toString().split(":");
quertOrder += splits[0].trim()+" "+splits[1].trim() +","; 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) if(objects.length > 0)
quertOrder = " order by " + quertOrder.substring(0,quertOrder.length()-1); 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(); JSONObject json = new JSONObject();
json.put("queryFields",queryFields); json.put("queryFields",queryFields);
json.put("showlist",list); json.put("showlist",list);
@ -91,6 +93,10 @@ public class ArchivesServiceImpl implements ArchivesService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Object edit(ArchivesDTO dto) { 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()); JSONObject json = new JSONObject(dto.getJsonString());
String categoryId = "FFAFBB1647D459C82080A"; String categoryId = "FFAFBB1647D459C82080A";
ArchivesType archivesType = archivesTypeRepository.findById(categoryId).get(); ArchivesType archivesType = archivesTypeRepository.findById(categoryId).get();
@ -99,26 +105,55 @@ public class ArchivesServiceImpl implements ArchivesService {
String insertValue = ""; String insertValue = "";
String updateValue = ""; String updateValue = "";
for(ArchivesDictionary archivesDictionary:showFiled){ 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()) +","; : 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) : ""; insertFiled = insertFiled.length() != 0 ? insertFiled.substring(0,insertFiled.length()-1) : "";
insertValue = insertValue.length() != 0 ? insertValue.substring(0,insertValue.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 @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;
} }
} }

4
archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesDictionary.java

@ -67,6 +67,10 @@ public class ArchivesDictionary extends BaseEntity implements Serializable {
@ApiModelProperty(value = "字段长度") @ApiModelProperty(value = "字段长度")
private Integer isColumnLength; private Integer isColumnLength;
@Column(name = "is_column_type")
@ApiModelProperty(value = "字段类型 1.档案 2.档案附件")
private Integer isColumnType;
@Column(name = "is_sequence") @Column(name = "is_sequence")
@ApiModelProperty(value = "排序") @ApiModelProperty(value = "排序")
private Integer isSequence; private Integer isSequence;

Loading…
Cancel
Save