diff --git a/archives/src/main/java/com/storeroom/modules/archives/controller/ArchivesController.java b/archives/src/main/java/com/storeroom/modules/archives/controller/ArchivesController.java index 2a5441e..ad9a972 100644 --- a/archives/src/main/java/com/storeroom/modules/archives/controller/ArchivesController.java +++ b/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.dictionary.service.dto.FieldDTO; import com.storeroom.utils.ApiResponse; +import com.storeroom.utils.SecurityUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -22,9 +23,9 @@ public class ArchivesController { @ApiOperation("档案列表") @GetMapping("/initArchivesView") public ApiResponse 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("档案预编辑") @@ -43,13 +44,21 @@ public class ArchivesController { return ApiResponse.success(archivesService.edit(dto)); } + @ApiOperation("档案删除") + @PostMapping("/delete") + public ApiResponse delete( + @Validated @RequestBody ArchivesDTO dto + ){ + dto.setDelMan(SecurityUtils.getCurrentUsername()); + return ApiResponse.success(archivesService.delete(dto)); + } - @ApiOperation("测试档案") - @GetMapping("/test") - public ApiResponse test( + @ApiOperation("档案回收站删除") + @PostMapping("/completelyDelete") + public ApiResponse completelyDelete( + @Validated @RequestBody ArchivesDTO dto ){ - archivesService.test(); - return ApiResponse.success(null); + return ApiResponse.success(archivesService.completelyDelete(dto)); } } diff --git a/archives/src/main/java/com/storeroom/modules/archives/service/ArchivesService.java b/archives/src/main/java/com/storeroom/modules/archives/service/ArchivesService.java index b26a327..fc5117b 100644 --- a/archives/src/main/java/com/storeroom/modules/archives/service/ArchivesService.java +++ b/archives/src/main/java/com/storeroom/modules/archives/service/ArchivesService.java @@ -5,11 +5,13 @@ import org.springframework.data.domain.Pageable; 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 edit(ArchivesDTO dto); - - String test(); + //档案删除进回收站 + Object delete(ArchivesDTO dto); + //档案回收站删除 + Object completelyDelete(ArchivesDTO dto); } diff --git a/archives/src/main/java/com/storeroom/modules/archives/service/dto/ArchivesDTO.java b/archives/src/main/java/com/storeroom/modules/archives/service/dto/ArchivesDTO.java index d50251b..4cdcfd5 100644 --- a/archives/src/main/java/com/storeroom/modules/archives/service/dto/ArchivesDTO.java +++ b/archives/src/main/java/com/storeroom/modules/archives/service/dto/ArchivesDTO.java @@ -17,6 +17,10 @@ public class ArchivesDTO { @JsonProperty("categoryId") private String categoryId; + @JSONField(name="delMan") + @JsonProperty("delMan") + private String delMan; + @JSONField(name="jsonString") @JsonProperty("jsonString") private String jsonString; diff --git a/archives/src/main/java/com/storeroom/modules/archives/service/impl/ArchivesServiceImpl.java b/archives/src/main/java/com/storeroom/modules/archives/service/impl/ArchivesServiceImpl.java index 2e1ddd3..bc080b9 100644 --- a/archives/src/main/java/com/storeroom/modules/archives/service/impl/ArchivesServiceImpl.java +++ b/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.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 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 list = entityManager.createNativeQuery("select "+queryField+" from "+queryTable+quertOrder).getResultList(); + List 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 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; } } diff --git a/archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesDictionary.java b/archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesDictionary.java index 85ab169..9be8886 100644 --- a/archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesDictionary.java +++ b/archives/src/main/java/com/storeroom/modules/dictionary/domain/ArchivesDictionary.java @@ -67,6 +67,10 @@ public class ArchivesDictionary extends BaseEntity implements Serializable { @ApiModelProperty(value = "字段长度") private Integer isColumnLength; + @Column(name = "is_column_type") + @ApiModelProperty(value = "字段类型 1.档案 2.档案附件") + private Integer isColumnType; + @Column(name = "is_sequence") @ApiModelProperty(value = "排序") private Integer isSequence;