加入字段表逻辑

This commit is contained in:
yang.xie 2022-10-14 12:57:53 +08:00
parent ec9aee60c5
commit 7248aeb091
8 changed files with 234 additions and 2 deletions

View File

@ -0,0 +1,41 @@
package com.northtecom.visatrack.api.controller.api;
import com.northtecom.visatrack.api.controller.vo.DictionaryRespose;
import com.northtecom.visatrack.api.service.impl.DictionaryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* Created with IntelliJ IDEA.
*
* @Author: XieYang
* @Date: 2022/10/14/12:42
* @Description:
*/
@RestController
@Slf4j
@RequestMapping("/api/dictionary")
public class DictionaryController {
private final DictionaryService dictionaryService;
@Autowired
public DictionaryController(DictionaryService dictionaryService) {
this.dictionaryService = dictionaryService;
}
@GetMapping("/getAllDictionaries")
public List<DictionaryRespose> getAllDictionaries() {
return this.dictionaryService.getAllDictionaries();
}
@GetMapping("/getAllDictionaryByCategory")
public DictionaryRespose getAllDictionaryByCategory(String category) {
return this.dictionaryService.getAllDictionaryByCategory(category);
}
}

View File

@ -0,0 +1,19 @@
package com.northtecom.visatrack.api.controller.vo;
import com.northtecom.visatrack.api.data.entity.Dictionary;
import lombok.Data;
import java.util.List;
/**
* Created with IntelliJ IDEA.
*
* @Author: XieYang
* @Date: 2022/10/14/12:40
* @Description:
*/
@Data
public class DictionaryRespose {
private String category;
private List<Dictionary> items;
}

View File

@ -7,6 +7,7 @@ import org.hibernate.annotations.Type;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.time.LocalDateTime;
import java.util.List;
/**
@ -29,6 +30,8 @@ public class Blog extends BaseEntity<Long> {
private String blogSummary;
@Column(name = "summary", columnDefinition = "LONGTEXT COMMENT 'Summary'")
private String blogContent;
@Column(name = "publish_time", columnDefinition = "DateTime COMMENT 'Publish time'")
private LocalDateTime publishDatetime;
@Type(type = "json")
@Column(columnDefinition = "json")
private List<String> keywords;

View File

@ -1,7 +1,7 @@
package com.northtecom.visatrack.api.data.entity;
import com.northtecom.visatrack.api.base.data.BaseEntity;
import lombok.Data;
import org.springframework.data.jpa.domain.AbstractPersistable;
import javax.persistence.Column;
import javax.persistence.Entity;
@ -21,7 +21,7 @@ import javax.persistence.UniqueConstraint;
@UniqueConstraint(columnNames = {"month"})
})
@org.hibernate.annotations.Table(appliesTo = "case_visa_report", comment = "Visa case report")
public class CaseVisaReport extends AbstractPersistable<Long> {
public class CaseVisaReport extends BaseEntity<Long> {
/**
* report month
* eg: 2021-10

View File

@ -0,0 +1,54 @@
package com.northtecom.visatrack.api.data.entity;
import com.northtecom.visatrack.api.base.data.BaseEntity;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
/**
* Created with IntelliJ IDEA.
*
* @Author: XieYang
* @Date: 2022/10/14/9:18
* @Description:
*/
@Entity
@Data
@Table(name = "dictionary", uniqueConstraints = {
@UniqueConstraint(columnNames = {"dic_key", "category"})
})
@org.hibernate.annotations.Table(appliesTo = "dictionary", comment = "Dictionary")
public class Dictionary extends BaseEntity<Long> {
/**
* Dictionary key
*/
@Column(name = "dic_key", columnDefinition = "varchar(255) COMMENT 'Dictionary key'")
private String key;
/**
* Dictionary value
*/
@Column(name = "dic_value", columnDefinition = "varchar(255) COMMENT 'Dictionary value'")
private String value;
/**
* Dictionary category
*/
@Column(name = "category", columnDefinition = "varchar(255) COMMENT 'Dictionary category'")
private String category;
/**
* Dictionary remark
*/
@Column(name = "remark", columnDefinition = "varchar(255) COMMENT 'Dictionary remark'")
private String remark;
/**
* Dictionary sort
*/
@Column(name = "sort_index", columnDefinition = "INT COMMENT 'Dictionary sort'")
private Integer sortIndex;
}

View File

@ -0,0 +1,25 @@
package com.northtecom.visatrack.api.data.repository;
import com.northtecom.visatrack.api.data.entity.Dictionary;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import java.util.List;
/**
*
*/
public interface DictionaryRepository extends PagingAndSortingRepository<Dictionary, Long> {
@Query(value = "select d from Dictionary d where d.category = :categoryName order by d.sortIndex asc")
List<Dictionary> findAllByCategoryName(@Param("categoryName") String categoryName);
@Query(value = "select d from Dictionary d order by d.category asc, d.sortIndex asc")
List<Dictionary> findAllDictionarys();
@Query(value = "select distinct d.category from Dictionary d")
List<String> findAllCategorys();
}

View File

@ -0,0 +1,53 @@
package com.northtecom.visatrack.api.service.impl;
import com.northtecom.visatrack.api.controller.vo.DictionaryRespose;
import com.northtecom.visatrack.api.data.entity.Dictionary;
import com.northtecom.visatrack.api.data.repository.DictionaryRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* Created with IntelliJ IDEA.
*
* @Author: XieYang
* @Date: 2022/10/14/12:38
* @Description:
*/
@Service
@Slf4j
public class DictionaryService {
private final DictionaryRepository dictionaryRepository;
@Autowired
public DictionaryService(DictionaryRepository dictionaryRepository) {
this.dictionaryRepository = dictionaryRepository;
}
public List<DictionaryRespose> getAllDictionaries() {
List<DictionaryRespose> dictionaryResposes = new ArrayList<>();
List<String> categories = this.dictionaryRepository.findAllCategorys();
for (int i = 0; i < categories.size(); i++) {
String category = categories.get(i);
dictionaryResposes.add(getAllDictionaryByCategory(category));
}
return dictionaryResposes;
}
public DictionaryRespose getAllDictionaryByCategory(String category) {
List<Dictionary> items = this.dictionaryRepository.findAllByCategoryName(category);
DictionaryRespose dictionaryRespose = new DictionaryRespose();
dictionaryRespose.setCategory(category);
dictionaryRespose.setItems(items);
return dictionaryRespose;
}
}

View File

@ -1,13 +1,50 @@
package com.northtecom.visatrack.api;
import com.northtecom.visatrack.api.data.entity.Dictionary;
import com.northtecom.visatrack.api.data.repository.DictionaryRepository;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class VisaTrackApiApplicationTests {
@Autowired
private DictionaryRepository dictionaryRepository;
@Test
void contextLoads() {
}
@Test
@Disabled
void dataInit() {
CreateDictionary("DEGREE", "BS,MS,Ph.D,Others");
CreateDictionary("US_CONSULATE", "BeiJing,ChengDu,Chennai,Europe,GuangZhou,HongKong,Kolkata,MexicoCity," +
"Montreal," +
"Mumbai,NewDelhi,Ottawa,Quebec,ShangHai,ShenYang,Tijuana,Toronto,Vancouver,Others");
CreateDictionary("VISA_TYPE", "F1,F2,H1,H4,J1,J2,B1,B2,L1,L2,O1,O2");
CreateDictionary("VISA_STATUS", "Pending,Clear,Reject");
CreateDictionary("VISA_ENTRY", "New,Renewal");
}
private void CreateDictionary(String category, String keys) {
String[] dictionaryItems = keys.split(",");
for (int i = 0; i < dictionaryItems.length; i++) {
CreateDictionaryItem(category, dictionaryItems[i], dictionaryItems[i], "", i);
}
}
private void CreateDictionaryItem(String category, String key, String value, String remark, int sortIndex) {
Dictionary dictionary = new Dictionary();
dictionary.setCategory(category);
dictionary.setKey(key);
dictionary.setValue(value);
dictionary.setRemark(remark);
dictionary.setSortIndex(sortIndex);
dictionaryRepository.save(dictionary);
}
}