21 changed files with 887 additions and 19 deletions
-
7archives/pom.xml
-
39archives/src/main/java/com/storeroom/modules/dictionary/controller/DictrionaryController.java
-
48archives/src/main/java/com/storeroom/modules/dictionary/controller/FieldController.java
-
60archives/src/main/java/com/storeroom/modules/dictionary/domain/Field.java
-
14archives/src/main/java/com/storeroom/modules/dictionary/domain/vo/DictionaryVO.java
-
65archives/src/main/java/com/storeroom/modules/dictionary/domain/vo/FieldVO.java
-
22archives/src/main/java/com/storeroom/modules/dictionary/repository/DictionaryRepository.java
-
22archives/src/main/java/com/storeroom/modules/dictionary/repository/FieldRepository.java
-
11archives/src/main/java/com/storeroom/modules/dictionary/service/DictionaryService.java
-
19archives/src/main/java/com/storeroom/modules/dictionary/service/FieldService.java
-
52archives/src/main/java/com/storeroom/modules/dictionary/service/dto/DictionaryDTO.java
-
33archives/src/main/java/com/storeroom/modules/dictionary/service/dto/DictionaryQueryCriteria.java
-
64archives/src/main/java/com/storeroom/modules/dictionary/service/dto/FieldDTO.java
-
22archives/src/main/java/com/storeroom/modules/dictionary/service/dto/PrimaryDTO.java
-
62archives/src/main/java/com/storeroom/modules/dictionary/service/impl/DictionaryServiceImpl.java
-
55archives/src/main/java/com/storeroom/modules/dictionary/service/impl/FieldServiceImpl.java
-
4common/src/main/java/com/storeroom/exception/constant/ResponseStatus.java
-
65common/src/main/java/com/storeroom/utils/HttpServletUtil.java
-
19common/src/main/java/com/storeroom/utils/MapUtil.java
-
81common/src/main/java/com/storeroom/utils/PageSort.java
-
142common/src/main/java/com/storeroom/utils/ResultUtils.java
@ -0,0 +1,48 @@ |
|||||
|
package com.storeroom.modules.dictionary.controller; |
||||
|
|
||||
|
import com.storeroom.annotaion.rest.AnonymousGetMapping; |
||||
|
import com.storeroom.annotaion.rest.AnonymousPostMapping; |
||||
|
import com.storeroom.exception.constant.ResponseStatus; |
||||
|
import com.storeroom.modules.dictionary.service.FieldService; |
||||
|
import com.storeroom.modules.dictionary.service.dto.FieldDTO; |
||||
|
import com.storeroom.modules.dictionary.service.dto.PrimaryDTO; |
||||
|
import com.storeroom.utils.ApiResponse; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import org.springframework.data.domain.Pageable; |
||||
|
import org.springframework.http.HttpStatus; |
||||
|
import org.springframework.validation.annotation.Validated; |
||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
@RestController |
||||
|
@RequiredArgsConstructor |
||||
|
@Api(tags = "字段表管理") |
||||
|
@RequestMapping("/api/field") |
||||
|
public class FieldController { |
||||
|
|
||||
|
private final FieldService fieldService; |
||||
|
|
||||
|
@ApiOperation("编辑字段表") |
||||
|
// @GetMapping("/edit") |
||||
|
@AnonymousPostMapping(value = "/edit") |
||||
|
public ApiResponse<Object> edit( |
||||
|
@Validated @RequestBody FieldDTO dto |
||||
|
){ |
||||
|
String returnCode = fieldService.edit(dto,"test"); |
||||
|
return returnCode != null ? ApiResponse.error(ResponseStatus.FIELD_REPEAT) : |
||||
|
ApiResponse.success(dto.getId() == null ? ResponseStatus.SUCCESS : HttpStatus.NO_CONTENT); |
||||
|
} |
||||
|
|
||||
|
@ApiOperation("分类查询字段表") |
||||
|
// @GetMapping("/findGroupType") |
||||
|
@AnonymousGetMapping(value = "/findGroupType") |
||||
|
public ApiResponse<Object> findGroupType( |
||||
|
Integer is_type |
||||
|
){ |
||||
|
return ApiResponse.success(fieldService.findGroupType(is_type)); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,60 @@ |
|||||
|
package com.storeroom.modules.dictionary.domain; |
||||
|
|
||||
|
import com.storeroom.base.BaseEntity; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
import org.hibernate.annotations.GenericGenerator; |
||||
|
|
||||
|
import javax.persistence.*; |
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
@Entity |
||||
|
@Getter |
||||
|
@Setter |
||||
|
@Table(name="sys_field") |
||||
|
public class Field extends BaseEntity implements Serializable { |
||||
|
|
||||
|
@Id |
||||
|
@Column(name = "id") |
||||
|
@GeneratedValue(generator = "idGenerator") |
||||
|
@GenericGenerator(name = "idGenerator", strategy = "uuid") |
||||
|
private String id; |
||||
|
|
||||
|
@Column(name = "field_name") |
||||
|
@ApiModelProperty(value = "字段名称") |
||||
|
private String fieldName; |
||||
|
|
||||
|
@Column(name = "field_cn_name") |
||||
|
@ApiModelProperty(value = "字段含义") |
||||
|
private String fieldCnName; |
||||
|
|
||||
|
@Column(name = "is_default_value") |
||||
|
@ApiModelProperty(value = "默认值") |
||||
|
private String isDefaultValue; |
||||
|
|
||||
|
@Column(name = "dictionary_id") |
||||
|
@ApiModelProperty(value = "字典id") |
||||
|
private String dictionaryId; |
||||
|
|
||||
|
@Column(name = "is_data_type") |
||||
|
@ApiModelProperty(value = "数据类型") |
||||
|
private Integer isDataType; |
||||
|
|
||||
|
@Column(name = "is_column_length") |
||||
|
@ApiModelProperty(value = "字段长度") |
||||
|
private Integer isColumnLength; |
||||
|
|
||||
|
@Column(name = "is_sequence") |
||||
|
@ApiModelProperty(value = "排序") |
||||
|
private Integer isSequence; |
||||
|
|
||||
|
@Column(name = "is_type") |
||||
|
@ApiModelProperty(value = "功能") |
||||
|
private Integer isType; |
||||
|
|
||||
|
@Column(name = "is_system") |
||||
|
@ApiModelProperty(value = "是否为系统字段") |
||||
|
private Boolean isSystem; |
||||
|
|
||||
|
} |
@ -0,0 +1,65 @@ |
|||||
|
package com.storeroom.modules.dictionary.domain.vo; |
||||
|
|
||||
|
import com.alibaba.fastjson.annotation.JSONField; |
||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
@Getter |
||||
|
@Setter |
||||
|
public class FieldVO { |
||||
|
|
||||
|
@ApiModelProperty(value = "字段id") |
||||
|
@JSONField(name="id") |
||||
|
@JsonProperty("id") |
||||
|
private String id; |
||||
|
|
||||
|
@ApiModelProperty(value = "字段名称") |
||||
|
@JSONField(name="fieldName") |
||||
|
@JsonProperty("field_name") |
||||
|
private String fieldName; |
||||
|
|
||||
|
@ApiModelProperty(value = "字段含义") |
||||
|
@JSONField(name="fieldCnName") |
||||
|
@JsonProperty("field_cn_name") |
||||
|
private String fieldCnName; |
||||
|
|
||||
|
@ApiModelProperty(value = "默认值") |
||||
|
@JSONField(name="isDefaultValue") |
||||
|
@JsonProperty("is_default_value") |
||||
|
private String isDefaultValue; |
||||
|
|
||||
|
@ApiModelProperty(value = "字典id") |
||||
|
@JSONField(name="dictionaryId") |
||||
|
@JsonProperty("dictionary_id") |
||||
|
private String dictionaryId; |
||||
|
|
||||
|
@ApiModelProperty(value = "数据类型") |
||||
|
@JSONField(name="isDataType") |
||||
|
@JsonProperty("is_data_type") |
||||
|
private Integer isDataType; |
||||
|
|
||||
|
@ApiModelProperty(value = "字段长度") |
||||
|
@JSONField(name="isColumnLength") |
||||
|
@JsonProperty("is_column_length") |
||||
|
private Integer isColumnLength; |
||||
|
|
||||
|
@ApiModelProperty(value = "排序") |
||||
|
@JSONField(name="isSequence") |
||||
|
@JsonProperty("is_sequence") |
||||
|
private Integer isSequence; |
||||
|
|
||||
|
@ApiModelProperty(value = "功能") |
||||
|
@JSONField(name="isType") |
||||
|
@JsonProperty("is_type") |
||||
|
private Integer isType; |
||||
|
|
||||
|
@ApiModelProperty(value = "是否为系统字段") |
||||
|
@JSONField(name="isSystem") |
||||
|
@JsonProperty("is_system") |
||||
|
private Boolean isSystem; |
||||
|
|
||||
|
} |
@ -1,14 +1,32 @@ |
|||||
package com.storeroom.modules.dictionary.repository; |
package com.storeroom.modules.dictionary.repository; |
||||
|
|
||||
import com.storeroom.modules.dictionary.domain.Dictionary; |
import com.storeroom.modules.dictionary.domain.Dictionary; |
||||
|
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.JpaRepository; |
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
||||
|
import org.springframework.data.jpa.repository.Modifying; |
||||
import org.springframework.data.jpa.repository.Query; |
import org.springframework.data.jpa.repository.Query; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
|
||||
import java.util.List; |
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
public interface DictionaryRepository extends JpaRepository<Dictionary, String> { |
|
||||
|
public interface DictionaryRepository extends JpaRepository<Dictionary, String>{ |
||||
|
|
||||
@Query(" from Dictionary ") |
|
||||
|
@Query(" from Dictionary order by dicSequence asc") |
||||
List<Dictionary> findAllOrderBy(); |
List<Dictionary> findAllOrderBy(); |
||||
|
|
||||
|
@Query("select id from Dictionary where dicPid = ?1 ") |
||||
|
List<String> findAllByPid(String pid); |
||||
|
|
||||
|
@Modifying |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
@Query(nativeQuery = true,value = "delete from sys_dictionary where id in ?1 ") |
||||
|
void deleteByIds(List<String> ids); |
||||
|
|
||||
|
@Query(nativeQuery = true, |
||||
|
countQuery = "SELECT count(1) FROM sys_dictionary where dic_pid = ?1", |
||||
|
value = "SELECT id,dic_name as dicName,dic_code as dicCode,dic_explain as dicExplain,dic_sequence as dicSequence,dic_type as dicType,dic_pid as dicPid FROM sys_dictionary where dic_pid = ?1") |
||||
|
Page<Map<String,Object>> findSubsetById(String id, Pageable page); |
||||
} |
} |
@ -0,0 +1,22 @@ |
|||||
|
package com.storeroom.modules.dictionary.repository; |
||||
|
|
||||
|
import com.storeroom.modules.dictionary.domain.Field; |
||||
|
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.Modifying; |
||||
|
import org.springframework.data.jpa.repository.Query; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
public interface FieldRepository extends JpaRepository<Field, String>{ |
||||
|
|
||||
|
@Query(nativeQuery = true,value = "select id from sys_field where field_name = ?1 limit 0,1 ") |
||||
|
String findIdFirstByFieldName(String fieldName); |
||||
|
|
||||
|
@Query("from Field where isType = ?1 order by isSequence asc ") |
||||
|
List<Field> findAllByIsType(Integer isType); |
||||
|
|
||||
|
} |
@ -1,9 +1,20 @@ |
|||||
package com.storeroom.modules.dictionary.service; |
package com.storeroom.modules.dictionary.service; |
||||
|
|
||||
|
import com.storeroom.modules.dictionary.domain.Dictionary; |
||||
import com.storeroom.modules.dictionary.domain.vo.DictionaryVO; |
import com.storeroom.modules.dictionary.domain.vo.DictionaryVO; |
||||
|
import com.storeroom.modules.dictionary.service.dto.DictionaryDTO; |
||||
|
import com.storeroom.utils.ResultUtils; |
||||
|
import org.springframework.data.domain.Pageable; |
||||
|
|
||||
import java.util.List; |
import java.util.List; |
||||
|
|
||||
public interface DictionaryService { |
public interface DictionaryService { |
||||
|
//获取字典目录 |
||||
List<DictionaryVO> findDictrionaryMenu(); |
List<DictionaryVO> findDictrionaryMenu(); |
||||
|
//编辑字典信息 |
||||
|
void edit(DictionaryDTO dto,String userName); |
||||
|
//删除字典信息 |
||||
|
void delete(String dictionaryId); |
||||
|
//根据字典id查询子集 |
||||
|
ResultUtils<List<DictionaryVO>> findSubsetById(String id, Pageable pageable); |
||||
} |
} |
@ -0,0 +1,19 @@ |
|||||
|
package com.storeroom.modules.dictionary.service; |
||||
|
|
||||
|
import com.storeroom.modules.dictionary.domain.vo.DictionaryVO; |
||||
|
import com.storeroom.modules.dictionary.domain.vo.FieldVO; |
||||
|
import com.storeroom.modules.dictionary.service.dto.DictionaryDTO; |
||||
|
import com.storeroom.modules.dictionary.service.dto.FieldDTO; |
||||
|
import com.storeroom.utils.ResultUtils; |
||||
|
import org.springframework.data.domain.Pageable; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
public interface FieldService { |
||||
|
|
||||
|
//编辑字段信息 |
||||
|
String edit(FieldDTO dto,String userName); |
||||
|
//分类获取字段数据 |
||||
|
List<FieldVO> findGroupType(Integer isType); |
||||
|
|
||||
|
} |
@ -0,0 +1,52 @@ |
|||||
|
package com.storeroom.modules.dictionary.service.dto; |
||||
|
|
||||
|
import com.alibaba.fastjson.annotation.JSONField; |
||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
|
import com.storeroom.annotaion.Query; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
import javax.persistence.Column; |
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
@Getter |
||||
|
@Setter |
||||
|
public class DictionaryDTO implements Serializable { |
||||
|
|
||||
|
@Query |
||||
|
@JSONField(name="id") |
||||
|
@JsonProperty("id") |
||||
|
private String id; |
||||
|
|
||||
|
@Query |
||||
|
@JSONField(name="dic_name") |
||||
|
@JsonProperty("dic_name") |
||||
|
private String dicName; |
||||
|
|
||||
|
@Query |
||||
|
@JSONField(name="dic_code") |
||||
|
@JsonProperty("dic_code") |
||||
|
private String dicCode; |
||||
|
|
||||
|
@Query |
||||
|
@JSONField(name="dic_explain") |
||||
|
@JsonProperty("dic_explain") |
||||
|
private String dicExplain; |
||||
|
|
||||
|
@Query |
||||
|
@JSONField(name="dic_sequence") |
||||
|
@JsonProperty("dic_sequence") |
||||
|
private Integer dicSequence; |
||||
|
|
||||
|
@Query |
||||
|
@JSONField(name="dic_type") |
||||
|
@JsonProperty("dic_type") |
||||
|
private Boolean dicType; |
||||
|
|
||||
|
@Query |
||||
|
@JSONField(name="dic_pid") |
||||
|
@JsonProperty("dic_pid") |
||||
|
private String dicPid; |
||||
|
|
||||
|
} |
@ -1,7 +1,40 @@ |
|||||
package com.storeroom.modules.dictionary.service.dto; |
package com.storeroom.modules.dictionary.service.dto; |
||||
|
|
||||
|
import com.alibaba.fastjson.annotation.JSONField; |
||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
|
import com.storeroom.annotaion.Query; |
||||
import lombok.Data; |
import lombok.Data; |
||||
|
|
||||
@Data |
@Data |
||||
public class DictionaryQueryCriteria { |
public class DictionaryQueryCriteria { |
||||
|
|
||||
|
@Query |
||||
|
@JSONField(name="id") |
||||
|
@JsonProperty("id") |
||||
|
private String id; |
||||
|
|
||||
|
@Query |
||||
|
@JSONField(name="dic_name") |
||||
|
@JsonProperty("dic_name") |
||||
|
private String dic_name; |
||||
|
|
||||
|
@Query |
||||
|
@JSONField(name="dic_code") |
||||
|
@JsonProperty("dic_code") |
||||
|
private String dic_code; |
||||
|
|
||||
|
@Query |
||||
|
@JSONField(name="dic_explain") |
||||
|
@JsonProperty("dic_explain") |
||||
|
private String dic_explain; |
||||
|
|
||||
|
@Query |
||||
|
@JSONField(name="dic_sequence") |
||||
|
@JsonProperty("dic_sequence") |
||||
|
private Integer dic_sequence; |
||||
|
|
||||
|
@Query |
||||
|
@JSONField(name="dic_pid") |
||||
|
@JsonProperty("dic_pid") |
||||
|
private Integer dic_pid; |
||||
} |
} |
@ -0,0 +1,64 @@ |
|||||
|
package com.storeroom.modules.dictionary.service.dto; |
||||
|
|
||||
|
import com.alibaba.fastjson.annotation.JSONField; |
||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
|
import com.storeroom.annotaion.Query; |
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
@Getter |
||||
|
@Setter |
||||
|
public class FieldDTO implements Serializable { |
||||
|
|
||||
|
@Query |
||||
|
@JSONField(name="id") |
||||
|
@JsonProperty("id") |
||||
|
private String id; |
||||
|
|
||||
|
@Query |
||||
|
@JSONField(name="field_name") |
||||
|
@JsonProperty("field_name") |
||||
|
private String fieldName; |
||||
|
|
||||
|
@Query |
||||
|
@JSONField(name="field_cn_name") |
||||
|
@JsonProperty("field_cn_name") |
||||
|
private String fieldCnName; |
||||
|
|
||||
|
@Query |
||||
|
@JSONField(name="is_default_value") |
||||
|
@JsonProperty("is_default_value") |
||||
|
private String isDefaultValue; |
||||
|
|
||||
|
@Query |
||||
|
@JSONField(name="dictionary_id") |
||||
|
@JsonProperty("dictionary_id") |
||||
|
private String dictionaryId; |
||||
|
|
||||
|
@Query |
||||
|
@JSONField(name="is_data_type") |
||||
|
@JsonProperty("is_data_type") |
||||
|
private Integer isDataType; |
||||
|
|
||||
|
@Query |
||||
|
@JSONField(name="is_column_length") |
||||
|
@JsonProperty("is_column_length") |
||||
|
private Integer isColumnLength; |
||||
|
|
||||
|
@Query |
||||
|
@JSONField(name="is_sequence") |
||||
|
@JsonProperty("is_sequence") |
||||
|
private Integer isSequence; |
||||
|
|
||||
|
@Query |
||||
|
@JSONField(name="is_type") |
||||
|
@JsonProperty("is_type") |
||||
|
private Integer isType; |
||||
|
|
||||
|
@Query |
||||
|
@JSONField(name="is_system") |
||||
|
@JsonProperty("is_system") |
||||
|
private Boolean isSystem; |
||||
|
} |
@ -0,0 +1,22 @@ |
|||||
|
package com.storeroom.modules.dictionary.service.dto; |
||||
|
|
||||
|
import com.alibaba.fastjson.annotation.JSONField; |
||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
@Getter |
||||
|
@Setter |
||||
|
public class PrimaryDTO { |
||||
|
|
||||
|
@JSONField(name="id") |
||||
|
@JsonProperty("id") |
||||
|
private String id; |
||||
|
|
||||
|
@JSONField(name="ids") |
||||
|
@JsonProperty("ids") |
||||
|
private List<String> ids; |
||||
|
|
||||
|
} |
@ -0,0 +1,55 @@ |
|||||
|
package com.storeroom.modules.dictionary.service.impl; |
||||
|
|
||||
|
import cn.hutool.core.bean.BeanUtil; |
||||
|
import com.storeroom.modules.dictionary.domain.Field; |
||||
|
import com.storeroom.modules.dictionary.domain.vo.FieldVO; |
||||
|
import com.storeroom.modules.dictionary.repository.FieldRepository; |
||||
|
import com.storeroom.modules.dictionary.service.FieldService; |
||||
|
import com.storeroom.modules.dictionary.service.dto.FieldDTO; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@Service |
||||
|
@RequiredArgsConstructor |
||||
|
public class FieldServiceImpl implements FieldService { |
||||
|
|
||||
|
private final FieldRepository fieldRepository; |
||||
|
|
||||
|
@Override |
||||
|
public String edit(FieldDTO dto, String userName) { |
||||
|
Field field = new Field(); |
||||
|
if(null != dto.getId()){ |
||||
|
field = fieldRepository.findById(dto.getId()).get(); |
||||
|
}else{ |
||||
|
field.setCreateBy(userName); |
||||
|
} |
||||
|
String origId = fieldRepository.findIdFirstByFieldName(dto.getFieldName()); |
||||
|
if(null != origId && origId.equals(dto.getId())){ |
||||
|
return "已存在该字段"; |
||||
|
} |
||||
|
field.setFieldName(dto.getFieldName()); |
||||
|
field.setFieldCnName(dto.getFieldCnName()); |
||||
|
field.setIsDefaultValue(dto.getIsDefaultValue()); |
||||
|
field.setDictionaryId(dto.getDictionaryId()); |
||||
|
field.setIsDataType(dto.getIsDataType()); |
||||
|
field.setIsColumnLength(dto.getIsColumnLength()); |
||||
|
field.setIsSequence(dto.getIsSequence()); |
||||
|
field.setIsType(dto.getIsType()); |
||||
|
field.setIsSystem(dto.getIsSystem()); |
||||
|
field = fieldRepository.saveAndFlush(field); |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<FieldVO> findGroupType(Integer isType) { |
||||
|
List<Field> fieldList = fieldRepository.findAllByIsType(isType); |
||||
|
List<FieldVO> fieldVOList = new ArrayList<>(); |
||||
|
for(Field field:fieldList){ |
||||
|
fieldVOList.add(BeanUtil.copyProperties(field,FieldVO.class)); |
||||
|
} |
||||
|
return fieldVOList; |
||||
|
} |
||||
|
} |
@ -0,0 +1,65 @@ |
|||||
|
package com.storeroom.utils; |
||||
|
|
||||
|
|
||||
|
import org.springframework.web.context.request.RequestContextHolder; |
||||
|
import org.springframework.web.context.request.ServletRequestAttributes; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletRequest; |
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
|
||||
|
/* |
||||
|
*@Description:获取HttpServlet子对象 |
||||
|
*@Author: Liu_Lee |
||||
|
*/ |
||||
|
public class HttpServletUtil { |
||||
|
|
||||
|
/** |
||||
|
* 获取ServletRequestAttributes对象 |
||||
|
*/ |
||||
|
public static ServletRequestAttributes getServletRequest(){ |
||||
|
return (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取HttpServletRequest对象 |
||||
|
*/ |
||||
|
public static HttpServletRequest getRequest(){ |
||||
|
return getServletRequest().getRequest(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取HttpServletResponse对象 |
||||
|
*/ |
||||
|
public static HttpServletResponse getResponse(){ |
||||
|
return getServletRequest().getResponse(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取请求参数 |
||||
|
*/ |
||||
|
public static String getParameter(String param){ |
||||
|
return getRequest().getParameter(param); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取请求参数,带默认值 |
||||
|
*/ |
||||
|
public static String getParameter(String param, String defaultValue){ |
||||
|
String parameter = getRequest().getParameter(param); |
||||
|
return StringUtils.isEmpty(parameter) ? defaultValue : parameter; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取请求参数转换为int类型 |
||||
|
*/ |
||||
|
public static Integer getParameterInt(String param){ |
||||
|
return Integer.valueOf(getRequest().getParameter(param)); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取请求参数转换为int类型,带默认值 |
||||
|
*/ |
||||
|
public static Integer getParameterInt(String param, Integer defaultValue){ |
||||
|
return Integer.valueOf(getParameter(param, String.valueOf(defaultValue))); |
||||
|
} |
||||
|
} |
@ -0,0 +1,19 @@ |
|||||
|
package com.storeroom.utils; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSONArray; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
public class MapUtil { |
||||
|
/** |
||||
|
* List<Map<String, Object>> 到 List<T> 数据转换 |
||||
|
*/ |
||||
|
public static <T> List<T> setList(final List<Map<String, Object>> srcList, Class<T> clazz) { |
||||
|
JSONArray jsonArray = new JSONArray(); |
||||
|
jsonArray.addAll(srcList); |
||||
|
List<T> addList = jsonArray.toJavaList(clazz); |
||||
|
return addList; |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,81 @@ |
|||||
|
package com.storeroom.utils; |
||||
|
|
||||
|
|
||||
|
import org.springframework.data.domain.PageRequest; |
||||
|
import org.springframework.data.domain.Sort; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/* |
||||
|
*@Description:分页排序数据 |
||||
|
*@Author: Liu_Lee |
||||
|
*@Date: 2020/9/16 13:30 |
||||
|
*@program: exhibit-admin |
||||
|
*/ |
||||
|
public class PageSort { |
||||
|
private static final Integer PAGE_SIZE_DEF = 10; |
||||
|
private static final String ORDER_BY_COLUMN_DEF = "createtime"; |
||||
|
private static final Sort.Direction SORT_DIRECTION = Sort.Direction.DESC; |
||||
|
|
||||
|
|
||||
|
|
||||
|
public static PageRequest pageRequest() { |
||||
|
return pageRequest(PAGE_SIZE_DEF, ORDER_BY_COLUMN_DEF, SORT_DIRECTION); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 创建分页排序对象 |
||||
|
* |
||||
|
* @param sortDirection 排序方式默认值 |
||||
|
*/ |
||||
|
public static PageRequest pageRequest(Integer page, Sort.Direction sortDirection) { |
||||
|
return pageRequest(PAGE_SIZE_DEF, ORDER_BY_COLUMN_DEF, sortDirection); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 创建分页排序对象 |
||||
|
* |
||||
|
* @param orderByColumnDef 排序字段名称默认值 |
||||
|
* @param sortDirection 排序方式默认值 |
||||
|
*/ |
||||
|
public static PageRequest pageRequest(Integer page, String orderByColumnDef, Sort.Direction sortDirection) { |
||||
|
return pageRequest(PAGE_SIZE_DEF, orderByColumnDef, sortDirection); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 创建分页排序对象 |
||||
|
* |
||||
|
* @param pageSizeDef 分页数据数量默认值 |
||||
|
* @param orderByColumnDef 排序字段名称默认值 |
||||
|
* @param sortDirection 排序方式默认值 |
||||
|
*/ |
||||
|
public static PageRequest pageRequest(Integer page, Integer pageSizeDef, String orderByColumnDef, Sort.Direction sortDirection) { |
||||
|
Integer pageIndex = HttpServletUtil.getParameterInt("page", page); |
||||
|
Integer pageSize = HttpServletUtil.getParameterInt("size", pageSizeDef); |
||||
|
String orderByColumn = HttpServletUtil.getParameter("orderByColumn", orderByColumnDef); |
||||
|
String direction = HttpServletUtil.getParameter("isAsc", sortDirection.toString()); |
||||
|
Sort sort = Sort.by(Sort.Direction.fromString(direction), orderByColumn); |
||||
|
|
||||
|
return PageRequest.of(pageIndex - 1, pageSize, sort); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 创建分页排序对象 |
||||
|
* |
||||
|
* @param pageSizeDef 分页数据数量默认值 |
||||
|
* @param orderByColumnDef 多个排序字段名称默认值 |
||||
|
* @param sortDirection 多个排序方式默认值 |
||||
|
*/ |
||||
|
public static PageRequest pageRequest(Integer page, Integer pageSizeDef, List<String> orderByColumnDef, List<Sort.Direction> sortDirection) { |
||||
|
Integer pageIndex = HttpServletUtil.getParameterInt("page", page); |
||||
|
Integer pageSize = HttpServletUtil.getParameterInt("size", pageSizeDef); |
||||
|
List orderList = new ArrayList(); |
||||
|
for(int i = 0;i<orderByColumnDef.size();i++){ |
||||
|
Sort.Order order = new Sort.Order(sortDirection.get(i),orderByColumnDef.get(i)); |
||||
|
orderList.add(order); |
||||
|
} |
||||
|
Sort sort = Sort.by(orderList); |
||||
|
return PageRequest.of(pageIndex - 1, pageSize, sort); |
||||
|
} |
||||
|
} |
@ -0,0 +1,142 @@ |
|||||
|
package com.storeroom.utils; |
||||
|
|
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.AccessLevel; |
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
import org.springframework.data.domain.Page; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
import java.util.Collections; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@Getter |
||||
|
@Setter |
||||
|
public class ResultUtils<T> { |
||||
|
|
||||
|
@ApiModelProperty(value = "返回数据") |
||||
|
private List<T> content; |
||||
|
|
||||
|
@Getter(AccessLevel.NONE) |
||||
|
@ApiModelProperty(value = "返回数据") |
||||
|
private T contentT; |
||||
|
|
||||
|
@ApiModelProperty(value = "返回状态") |
||||
|
private boolean bReturn; |
||||
|
|
||||
|
@ApiModelProperty(value = "返回信息") |
||||
|
private String Msg; |
||||
|
|
||||
|
@ApiModelProperty(value = "是否有上一页") |
||||
|
private boolean hasPrevious; |
||||
|
|
||||
|
@ApiModelProperty(value = "是否有下一页") |
||||
|
private boolean hasNext; |
||||
|
|
||||
|
@ApiModelProperty(value = "总数量") |
||||
|
private long totalElements; |
||||
|
|
||||
|
@ApiModelProperty(value = "总页数") |
||||
|
private int totalPages; |
||||
|
|
||||
|
@ApiModelProperty(value = "当前页数") |
||||
|
private int number; |
||||
|
|
||||
|
@ApiModelProperty(value = "每页显示数量") |
||||
|
private int size; |
||||
|
|
||||
|
public ResultUtils() { } |
||||
|
|
||||
|
public ResultUtils(List<T> content, boolean hasPrevious, boolean hasNext, long totalElements, int totalPages, int number, int size) { |
||||
|
this.content = content; |
||||
|
this.bReturn = true; |
||||
|
this.Msg = "OK"; |
||||
|
this.hasPrevious = hasPrevious; |
||||
|
this.hasNext = hasNext; |
||||
|
this.totalElements = totalElements; |
||||
|
this.totalPages = totalPages; |
||||
|
this.number = number; |
||||
|
this.size = size; |
||||
|
} |
||||
|
|
||||
|
public ResultUtils(T contentT) { |
||||
|
List<T> tList = new ArrayList<>(); |
||||
|
tList.add(contentT); |
||||
|
this.content = tList; |
||||
|
this.bReturn = true; |
||||
|
this.Msg = "OK"; |
||||
|
this.hasPrevious = false; |
||||
|
this.hasNext = false; |
||||
|
this.totalElements = 1; |
||||
|
this.totalPages = 1; |
||||
|
this.number = 1; |
||||
|
this.size = 1; |
||||
|
} |
||||
|
|
||||
|
public ResultUtils(List<T> content){ |
||||
|
this.content = content; |
||||
|
this.bReturn = true; |
||||
|
this.Msg = "OK"; |
||||
|
this.hasPrevious = false; |
||||
|
this.hasNext = false; |
||||
|
this.totalElements = content.size(); |
||||
|
this.totalPages = 1; |
||||
|
this.number = 1; |
||||
|
this.size = content.size(); |
||||
|
} |
||||
|
|
||||
|
public ResultUtils(boolean bReturn, String Msg){ |
||||
|
this.bReturn = bReturn; |
||||
|
this.Msg = Msg; |
||||
|
} |
||||
|
|
||||
|
/*** |
||||
|
* 单条数据返回 |
||||
|
* @param content 数据 |
||||
|
* @param <T> 泛型类 |
||||
|
* @return 分页返回 |
||||
|
*/ |
||||
|
public static <T> ResultUtils<T> getResult(T content) { |
||||
|
return (ResultUtils<T>) new ResultUtils(Collections.singletonList(content)); |
||||
|
} |
||||
|
|
||||
|
/*** |
||||
|
* 多条数据返回 |
||||
|
* @param content 数据 |
||||
|
* @param <T> 泛型类 |
||||
|
* @return 分页返回 |
||||
|
*/ |
||||
|
public static <T> ResultUtils<List<T>> getResult(List<T> content) { |
||||
|
return (ResultUtils<List<T>>) new ResultUtils(content); |
||||
|
} |
||||
|
|
||||
|
/*** |
||||
|
* 多条数据分页返回 |
||||
|
* @param content 数据 |
||||
|
* @param pages 分页 |
||||
|
* @param <T> 泛型类 |
||||
|
* @return 分页返回 |
||||
|
*/ |
||||
|
public static <T> ResultUtils<List<T>> getResult(List<T> content, Page pages) { |
||||
|
return (ResultUtils<List<T>>) new ResultUtils(content, pages.hasPrevious(), pages.hasNext(), pages.getTotalElements(), pages.getTotalPages(), pages.getNumber() + 1, pages.getSize()); |
||||
|
} |
||||
|
|
||||
|
/*** |
||||
|
* 无返回时(添加、编辑、删除)返回成功 |
||||
|
* @return 无返回时(添加、编辑、删除)返回成功 |
||||
|
* @param <T> 泛型类 |
||||
|
*/ |
||||
|
public static <T> ResultUtils<T> Succsee(){ |
||||
|
return (ResultUtils<T>) new ResultUtils(true,"OK"); |
||||
|
} |
||||
|
|
||||
|
/*** |
||||
|
* 无返回时(添加、编辑、删除)返回失败 |
||||
|
* @param Msg 返回信息 |
||||
|
* @param <T> 泛型类 |
||||
|
* @return 无返回时(添加、编辑、删除)返回失败 |
||||
|
*/ |
||||
|
public static <T> ResultUtils<T> Error(String Msg){ |
||||
|
return (ResultUtils<T>) new ResultUtils(true,Msg); |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue