Browse Source

更新标签功能

master
xia 3 years ago
parent
commit
25e71f7443
  1. 13
      archives/src/main/java/com/storeroom/modules/archives/controller/CaseController.java
  2. 5
      archives/src/main/java/com/storeroom/modules/archives/repository/ArchivesCaseRepository.java
  3. 10
      archives/src/main/java/com/storeroom/modules/archives/repository/ArchivesSummaryRepository.java
  4. 6
      archives/src/main/java/com/storeroom/modules/archives/service/ArchivesCaseService.java
  5. 4
      archives/src/main/java/com/storeroom/modules/archives/service/dto/CaseDTO.java
  6. 68
      archives/src/main/java/com/storeroom/modules/archives/service/impl/ArchivesCaseServiceImpl.java
  7. 9
      archives/src/main/java/com/storeroom/modules/archives/service/impl/ArchivesServiceImpl.java
  8. 9
      archives/src/main/java/com/storeroom/modules/dictionary/controller/DictrionaryController.java
  9. 3
      archives/src/main/java/com/storeroom/modules/dictionary/repository/DictionaryRepository.java
  10. 2
      archives/src/main/java/com/storeroom/modules/dictionary/service/DictionaryService.java
  11. 30
      archives/src/main/java/com/storeroom/modules/dictionary/service/impl/DictionaryServiceImpl.java
  12. 4
      common/src/main/java/com/storeroom/exception/constant/ResponseStatus.java

13
archives/src/main/java/com/storeroom/modules/archives/controller/CaseController.java

@ -1,7 +1,8 @@
package com.storeroom.modules.archives.controller;
import com.storeroom.exception.constant.ResponseStatus;
import com.storeroom.modules.archives.service.ArchivesCaseService;
import com.storeroom.modules.dictionary.service.dto.CaseDTO;
import com.storeroom.modules.archives.service.dto.CaseDTO;
import com.storeroom.utils.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -39,11 +40,13 @@ public class CaseController {
public ApiResponse<Object> bingdingLabel(
@Validated @RequestBody CaseDTO dto
){
Integer bindingCount = caseService.findIsBingdingLabel(dto.getTid(),dto.getLabelType());
if(bindingCount == 0){
return ApiResponse.success(null);
String binding = caseService.findIsBingdingLabel(dto.getTid());
String[] bindings = binding.split(",");
if("0".equals(bindings[1]) || dto.getCoverLabel()){
return ApiResponse.success(caseService.addCaseTag(dto.getId(),dto.getTid(),dto.getLabelType(),bindings[1],bindings[0]));
}else{
return ApiResponse.error();
return ApiResponse.error(ResponseStatus.LABEL_BOUND);
}
}

5
archives/src/main/java/com/storeroom/modules/archives/repository/ArchivesCaseRepository.java

@ -4,6 +4,7 @@ import com.storeroom.modules.archives.domain.ArchivesCase;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface ArchivesCaseRepository extends JpaRepository<ArchivesCase, String>{
@ -11,4 +12,8 @@ public interface ArchivesCaseRepository extends JpaRepository<ArchivesCase, Stri
Integer countAllByTid(String tid);
@Query(nativeQuery = true,
value = "update archives_case set tid = null where tid = ?1")
void unbindTag(String tid);
}

10
archives/src/main/java/com/storeroom/modules/archives/repository/ArchivesSummaryRepository.java

@ -11,4 +11,14 @@ public interface ArchivesSummaryRepository extends JpaRepository<ArchivesSummary
Integer countAllByTagNo(String tid);
@Query(nativeQuery = true,
value = "update archives_summary set tag_no = null where tag_no = ?1 ")
void unbindTag(String tid);
@Query(nativeQuery = true,
value = "update archives_summary set tag_no ?1 where archives_id = ?2 ")
void bindTag(String tid,String archivesId);
ArchivesSummary findFirstByTagNo(String tagNo);
}

6
archives/src/main/java/com/storeroom/modules/archives/service/ArchivesCaseService.java

@ -1,6 +1,6 @@
package com.storeroom.modules.archives.service;
import com.storeroom.modules.dictionary.service.dto.CaseDTO;
import com.storeroom.modules.archives.service.dto.CaseDTO;
import org.springframework.data.domain.Pageable;
public interface ArchivesCaseService {
@ -9,7 +9,9 @@ public interface ArchivesCaseService {
//编辑档案盒信息
Object edit(CaseDTO dto);
//查询该标签是否绑定过
Integer findIsBingdingLabel(String label,Integer labelType);
String findIsBingdingLabel(String label);
//添加盒标签
Object addCaseTag(String caseId,String tid,Integer labelType,String bindingCount,String tagType);
}

4
archives/src/main/java/com/storeroom/modules/dictionary/service/dto/CaseDTO.java → archives/src/main/java/com/storeroom/modules/archives/service/dto/CaseDTO.java

@ -1,4 +1,4 @@
package com.storeroom.modules.dictionary.service.dto;
package com.storeroom.modules.archives.service.dto;
import lombok.Getter;
import lombok.Setter;
@ -14,6 +14,8 @@ public class CaseDTO {
private String tid;
//标签类型
private Integer labelType;
//是否覆盖标签
private Boolean coverLabel;
//盒架位
private String folderLocation;

68
archives/src/main/java/com/storeroom/modules/archives/service/impl/ArchivesCaseServiceImpl.java

@ -1,10 +1,11 @@
package com.storeroom.modules.archives.service.impl;
import com.storeroom.modules.archives.domain.ArchivesCase;
import com.storeroom.modules.archives.domain.ArchivesSummary;
import com.storeroom.modules.archives.repository.ArchivesCaseRepository;
import com.storeroom.modules.archives.repository.ArchivesSummaryRepository;
import com.storeroom.modules.archives.service.ArchivesCaseService;
import com.storeroom.modules.dictionary.service.dto.CaseDTO;
import com.storeroom.modules.archives.service.dto.CaseDTO;
import com.storeroom.utils.NanoIdUtils;
import com.storeroom.utils.PageUtil;
import com.storeroom.utils.StringUtils;
@ -12,8 +13,10 @@ import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.sql.Timestamp;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Service
@ -22,6 +25,8 @@ public class ArchivesCaseServiceImpl implements ArchivesCaseService {
private final ArchivesCaseRepository caseRepository;
private final ArchivesSummaryRepository archivesSummaryRepository;
@PersistenceContext
EntityManager entityManager;
@Override
public Object initCaseList(String tid, String caseName, Pageable page) {
@ -32,6 +37,7 @@ public class ArchivesCaseServiceImpl implements ArchivesCaseService {
}
@Override
@Transactional(rollbackFor = Exception.class)
public Object edit(CaseDTO dto) {
ArchivesCase archivesCase = null;
if(!StringUtils.isEmpty(dto.getId())){
@ -47,15 +53,55 @@ public class ArchivesCaseServiceImpl implements ArchivesCaseService {
}
@Override
public Integer findIsBingdingLabel(String tid,Integer labelType) {
if(labelType==1){
return archivesSummaryRepository.countAllByTagNo(tid);
}else if(labelType==2){
return caseRepository.countAllByTid(tid);
}else if(labelType==3){
return 0;
}else{
return 0;
public String findIsBingdingLabel(String tid) {
Integer archivesTag = archivesSummaryRepository.countAllByTagNo(tid);
if(archivesTag == 0){
Integer caseTag = caseRepository.countAllByTid(tid);
if(caseTag==0){
return "0,0";
}else{
return "2,"+caseTag;
}
}else{
return "1,"+archivesTag;
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public Object addCaseTag(String caseId, String tid,Integer labelType, String bindingCount,String tagType) {
String archivesTable = "";
//若标签已绑定 先解绑
if(!"0".equals(bindingCount)){
switch (tagType){
case "1":
ArchivesSummary archivesSummary = archivesSummaryRepository.findFirstByTagNo(tid);
archivesSummaryRepository.unbindTag(tid);
archivesTable = archivesSummary.getArchivesTableName();
String sql = "update "+archivesTable+" set tid = null where id = '"+archivesSummary.getArchivesId()+"'";
entityManager.createNativeQuery(sql).executeUpdate();
break;
case "2":
caseRepository.unbindTag(tid);
break;
default:
break;
}
//绑定标签
switch (labelType){
case 1:
archivesSummaryRepository.bindTag(tid,caseId);
break;
case 2:
break;
case 3:
break;
default:
break;
}
}
return null;
}
}

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

@ -50,6 +50,7 @@ public class ArchivesServiceImpl implements ArchivesService {
return "未查询到到门类信息!";
ArchivesType archivesType = optional.get();
List<String> queryFields = archivesDictionaryRepository.findDisPlayField(categoryId);
queryFields.add("id");
String queryField = queryFields.stream().map(String::valueOf).collect(Collectors.joining(","));
String queryTable = archivesType.getEnName();
String quertOrder = "";
@ -118,14 +119,14 @@ public class ArchivesServiceImpl implements ArchivesService {
for(ArchivesDictionary archivesDictionary:showFiled){
//是否必填
if(archivesDictionary.getIsRequired()){
if(null == json.get(archivesDictionary.getFieldName()) || "".equals(json.get(archivesDictionary.getFieldName()))){
if(null == json.get(archivesDictionary.getFieldName()) || "null".equals(json.get(archivesDictionary.getFieldName())) || "".equals(json.get(archivesDictionary.getFieldName()))){
return archivesDictionary.getFieldName()+"不可为空!";
}
}
//是否重复
if(archivesDictionary.getIsRepeat()){
//判断是否为空
if(null != json.get(archivesDictionary.getFieldName()) && !"".equals(json.get(archivesDictionary.getFieldName()))){
if(null != json.get(archivesDictionary.getFieldName()) && !"".equals(json.get(archivesDictionary.getFieldName())) && !"null".equals(json.get(archivesDictionary.getFieldName()))){
String thissql = "select id,"+archivesDictionary.getFieldName()+" from "+archivesType.getEnName()+" where "+
archivesDictionary.getFieldName() +" = '"+json.get(archivesDictionary.getFieldName())+"'";
List<Object[]> list = entityManager.createNativeQuery(thissql).getResultList();
@ -144,11 +145,11 @@ public class ArchivesServiceImpl implements ArchivesService {
if(StringUtils.isEmpty(dto.getId())){
insertFiled +=archivesDictionary.getFieldName()+",";
insertValue += archivesDictionary.getIsDataType() == 1 ?
null == json.get(archivesDictionary.getFieldName()) ? null+"," : "'"+json.get(archivesDictionary.getFieldName())+"',"
null == json.get(archivesDictionary.getFieldName()) || "null".equals(json.get(archivesDictionary.getFieldName())+"") ? null+"," : "'"+json.get(archivesDictionary.getFieldName())+"',"
: json.get(archivesDictionary.getFieldName()) +",";
}else {
String thisValue = archivesDictionary.getIsDataType() == 1 ?
json.get(archivesDictionary.getFieldName()) == null ? null : "'" + json.get(archivesDictionary.getFieldName()) + "'"
json.get(archivesDictionary.getFieldName()) == null || "null".equals(json.get(archivesDictionary.getFieldName())+"") ? null : "'" + json.get(archivesDictionary.getFieldName()) + "'"
: json.get(archivesDictionary.getFieldName()) + "";
updateValue += archivesDictionary.getFieldName() + "=" + thisValue + ",";
}

9
archives/src/main/java/com/storeroom/modules/dictionary/controller/DictrionaryController.java

@ -65,4 +65,13 @@ public class DictrionaryController {
return ApiResponse.success(dictionaryService.findSubsetById(criteria.getId(),page));
}
@ApiOperation("根据字典id分页查询子集")
@GetMapping("/findAllSubsetById")
// @AnonymousGetMapping(value = "/findSubsetById")
public ApiResponse<Object> findAllSubsetById(
DictionaryQueryCriteria criteria
){
return ApiResponse.success(dictionaryService.findAllSubsetById(criteria.getId()));
}
}

3
archives/src/main/java/com/storeroom/modules/dictionary/repository/DictionaryRepository.java

@ -17,6 +17,9 @@ public interface DictionaryRepository extends JpaRepository<Dictionary, String>{
@Query(" from Dictionary order by dicSequence asc")
List<Dictionary> findAllOrderBy();
@Query(" from Dictionary where dicPid = ?1 order by dicSequence asc")
List<Dictionary> findAllByPidOrderBy(String pid);
@Query("select id from Dictionary where dicPid = ?1 ")
List<String> findAllByPid(String pid);

2
archives/src/main/java/com/storeroom/modules/dictionary/service/DictionaryService.java

@ -17,4 +17,6 @@ public interface DictionaryService {
void delete(String dictionaryId);
//根据字典id查询子集
Object findSubsetById(String id, Pageable pageable);
//根据字典id查询所有子集
Object findAllSubsetById(String id);
}

30
archives/src/main/java/com/storeroom/modules/dictionary/service/impl/DictionaryServiceImpl.java

@ -91,6 +91,36 @@ public class DictionaryServiceImpl implements DictionaryService {
return PageUtil.toPage(pageMap);
}
@Override
public List<DictionaryVO> findAllSubsetById(String id) {
List<DictionaryVO> menuList = new ArrayList<>();
List<Dictionary> dictionaryList = dictionaryRepository.findAllByPidOrderBy(id);
for (int i = 0; i < dictionaryList.size(); i++) {
Dictionary dictionary = dictionaryList.get(i);
menuList.add(BeanUtil.copyProperties(dictionary,DictionaryVO.class));
}
for (DictionaryVO menu : menuList) {
menu.setChildMenus(getAllSubsetById(menu.getId()));
}
return menuList;
}
public List<DictionaryVO> getAllSubsetById(String pid){
List<DictionaryVO> menuList = new ArrayList<>();
List<Dictionary> dictionaryList = dictionaryRepository.findAllByPidOrderBy(pid);
if(dictionaryList.size() == 0){
return null;
}
for (int i = 0; i < dictionaryList.size(); i++) {
Dictionary dictionary = dictionaryList.get(i);
menuList.add(BeanUtil.copyProperties(dictionary,DictionaryVO.class));
}
for (DictionaryVO menu : menuList) {
menu.setChildMenus(getAllSubsetById(menu.getId()));
}
return menuList;
}
private List<String> getChildId(String id,List<String> deleteIds){
if(null == id){
return deleteIds;

4
common/src/main/java/com/storeroom/exception/constant/ResponseStatus.java

@ -20,7 +20,9 @@ public enum ResponseStatus {
//token 为空
TOKEN_IS_NULL(4002,"找不到当前登录信息"),
//Field重复
FIELD_REPEAT(5001,"当前字段重复");
FIELD_REPEAT(5001,"当前字段重复"),
//当前标签已被绑定
LABEL_BOUND(6201,"当前标签已被绑定");

Loading…
Cancel
Save