Commit e4ca7afc authored by dqjdda's avatar dqjdda
Browse files

阿里巴巴代码规范

parent 6d941c09
package me.zhengjie.modules.system.service;
import me.zhengjie.modules.system.domain.User;
import me.zhengjie.modules.system.service.dto.UserDTO;
import me.zhengjie.modules.system.service.dto.UserDto;
import me.zhengjie.modules.system.service.dto.UserQueryCriteria;
import org.springframework.data.domain.Pageable;
import org.springframework.web.multipart.MultipartFile;
......@@ -15,25 +15,79 @@ import java.util.List;
*/
public interface UserService {
UserDTO findById(long id);
/**
* 根据ID查询
* @param id ID
* @return /
*/
UserDto findById(long id);
UserDTO create(User resources);
/**
* 新增用户
* @param resources /
* @return /
*/
UserDto create(User resources);
/**
* 编辑用户
* @param resources /
*/
void update(User resources);
/**
* 删除用户
* @param id /
*/
void delete(Long id);
UserDTO findByName(String userName);
/**
* 根据用户名查询
* @param userName /
* @return /
*/
UserDto findByName(String userName);
/**
* 修改密码
* @param username 用户名
* @param encryptPassword 密码
*/
void updatePass(String username, String encryptPassword);
/**
* 修改头像
* @param file 文件
*/
void updateAvatar(MultipartFile file);
/**
* 修改邮箱
* @param username 用户名
* @param email 邮箱
*/
void updateEmail(String username, String email);
/**
* 查询全部
* @param criteria 条件
* @param pageable 分页参数
* @return /
*/
Object queryAll(UserQueryCriteria criteria, Pageable pageable);
List<UserDTO> queryAll(UserQueryCriteria criteria);
/**
* 查询全部不分页
* @param criteria 条件
* @return /
*/
List<UserDto> queryAll(UserQueryCriteria criteria);
void download(List<UserDTO> queryAll, HttpServletResponse response) throws IOException;
/**
* 导出数据
* @param queryAll 待导出的数据
* @param response /
* @throws IOException /
*/
void download(List<UserDto> queryAll, HttpServletResponse response) throws IOException;
}
package me.zhengjie.modules.system.service.dto;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import javax.validation.constraints.NotNull;
......@@ -12,24 +13,20 @@ import java.util.List;
* @author Zheng Jie
* @date 2019-03-25
*/
@Getter
@Setter
public class DeptDTO implements Serializable {
@Data
public class DeptDto implements Serializable {
// ID
private Long id;
// 名称
private String name;
@NotNull
private Boolean enabled;
// 上级部门
private Long pid;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<DeptDTO> children;
private List<DeptDto> children;
private Timestamp createTime;
......
......@@ -8,7 +8,7 @@ import java.io.Serializable;
* @date 2019-6-10 16:32:18
*/
@Data
public class DeptSmallDTO implements Serializable {
public class DeptSmallDto implements Serializable {
private Long id;
......
......@@ -12,7 +12,7 @@ import java.sql.Timestamp;
*/
@Getter
@Setter
public class DictDetailDTO implements Serializable {
public class DictDetailDto implements Serializable {
private Long id;
......@@ -22,7 +22,7 @@ public class DictDetailDTO implements Serializable {
private String sort;
private DictSmallDTO dict;
private DictSmallDto dict;
private Timestamp createTime;
}
\ No newline at end of file
......@@ -13,7 +13,7 @@ import java.util.List;
*/
@Getter
@Setter
public class DictDTO implements Serializable {
public class DictDto implements Serializable {
private Long id;
......@@ -21,7 +21,7 @@ public class DictDTO implements Serializable {
private String remark;
private List<DictDetailDTO> dictDetails;
private List<DictDetailDto> dictDetails;
private Timestamp createTime;
}
......@@ -4,12 +4,12 @@ import lombok.Data;
import me.zhengjie.annotation.Query;
/**
* @author Zheng Jie
* 公共查询类
*/
@Data
public class DictQueryCriteria {
// 多字段模糊
@Query(blurry = "name,remark")
private String blurry;
}
......@@ -10,7 +10,7 @@ import java.io.Serializable;
*/
@Getter
@Setter
public class DictSmallDTO implements Serializable {
public class DictSmallDto implements Serializable {
private Long id;
}
......@@ -14,7 +14,7 @@ import java.sql.Timestamp;
@Getter
@Setter
@NoArgsConstructor
public class JobDTO implements Serializable {
public class JobDto implements Serializable {
private Long id;
......@@ -24,13 +24,13 @@ public class JobDTO implements Serializable {
private Boolean enabled;
private DeptDTO dept;
private DeptDto dept;
private String deptSuperiorName;
private Timestamp createTime;
public JobDTO(String name, Boolean enabled) {
public JobDto(String name, Boolean enabled) {
this.name = name;
this.enabled = enabled;
}
......
......@@ -10,7 +10,7 @@ import java.io.Serializable;
*/
@Data
@NoArgsConstructor
public class JobSmallDTO implements Serializable {
public class JobSmallDto implements Serializable {
private Long id;
......
package me.zhengjie.modules.system.service.dto;
import lombok.Getter;
import lombok.Setter;
import lombok.Data;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;
......@@ -11,9 +9,8 @@ import java.util.List;
* @author Zheng Jie
* @date 2018-12-17
*/
@Getter
@Setter
public class MenuDTO implements Serializable {
@Data
public class MenuDto implements Serializable {
private Long id;
......@@ -41,7 +38,7 @@ public class MenuDTO implements Serializable {
private String icon;
private List<MenuDTO> children;
private List<MenuDto> children;
private Timestamp createTime;
}
......@@ -7,12 +7,12 @@ import java.sql.Timestamp;
import java.util.List;
/**
* @author Zheng Jie
* 公共查询类
*/
@Data
public class MenuQueryCriteria {
// 多字段模糊
@Query(blurry = "name,path,component")
private String blurry;
......
package me.zhengjie.modules.system.service.dto;
import lombok.Getter;
import lombok.Setter;
import lombok.Data;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Set;
......@@ -11,9 +9,8 @@ import java.util.Set;
* @author Zheng Jie
* @date 2018-11-23
*/
@Getter
@Setter
public class RoleDTO implements Serializable {
@Data
public class RoleDto implements Serializable {
private Long id;
......@@ -27,9 +24,9 @@ public class RoleDTO implements Serializable {
private String permission;
private Set<MenuDTO> menus;
private Set<MenuDto> menus;
private Set<DeptDTO> depts;
private Set<DeptDto> depts;
private Timestamp createTime;
}
......@@ -7,12 +7,12 @@ import java.sql.Timestamp;
import java.util.List;
/**
* @author Zheng Jie
* 公共查询类
*/
@Data
public class RoleQueryCriteria {
// 多字段模糊
@Query(blurry = "name,remark")
private String blurry;
......
......@@ -8,7 +8,7 @@ import java.io.Serializable;
* @date 2018-11-23
*/
@Data
public class RoleSmallDTO implements Serializable {
public class RoleSmallDto implements Serializable {
private Long id;
......
......@@ -2,9 +2,7 @@ package me.zhengjie.modules.system.service.dto;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.Data;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
......@@ -14,9 +12,8 @@ import java.util.Set;
* @author Zheng Jie
* @date 2018-11-23
*/
@Getter
@Setter
public class UserDTO implements Serializable {
@Data
public class UserDto implements Serializable {
@ApiModelProperty(hidden = true)
private Long id;
......@@ -37,12 +34,12 @@ public class UserDTO implements Serializable {
private Date lastPasswordResetTime;
@ApiModelProperty(hidden = true)
private Set<RoleSmallDTO> roles;
private Set<RoleSmallDto> roles;
@ApiModelProperty(hidden = true)
private JobSmallDTO job;
private JobSmallDto job;
private DeptSmallDTO dept;
private DeptSmallDto dept;
private Long deptId;
......
......@@ -20,7 +20,6 @@ public class UserQueryCriteria implements Serializable {
@Query(propName = "id", type = Query.Type.IN, joinName = "dept")
private Set<Long> deptIds;
// 多字段模糊
@Query(blurry = "email,username")
private String blurry;
......
......@@ -2,13 +2,13 @@ package me.zhengjie.modules.system.service.impl;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.domain.Dept;
import me.zhengjie.modules.system.service.dto.DeptDto;
import me.zhengjie.modules.system.service.dto.DeptQueryCriteria;
import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.QueryHelp;
import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.modules.system.repository.DeptRepository;
import me.zhengjie.modules.system.service.DeptService;
import me.zhengjie.modules.system.service.dto.DeptDTO;
import me.zhengjie.modules.system.service.mapper.DeptMapper;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
......@@ -43,13 +43,13 @@ public class DeptServiceImpl implements DeptService {
@Override
@Cacheable
public List<DeptDTO> queryAll(DeptQueryCriteria criteria) {
public List<DeptDto> queryAll(DeptQueryCriteria criteria) {
return deptMapper.toDto(deptRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}
@Override
@Cacheable(key = "#p0")
public DeptDTO findById(Long id) {
public DeptDto findById(Long id) {
Dept dept = deptRepository.findById(id).orElseGet(Dept::new);
ValidationUtil.isNull(dept.getId(),"Dept","id",id);
return deptMapper.toDto(dept);
......@@ -68,17 +68,17 @@ public class DeptServiceImpl implements DeptService {
@Override
@Cacheable
public Object buildTree(List<DeptDTO> deptDTOS) {
Set<DeptDTO> trees = new LinkedHashSet<>();
Set<DeptDTO> depts= new LinkedHashSet<>();
List<String> deptNames = deptDTOS.stream().map(DeptDTO::getName).collect(Collectors.toList());
public Object buildTree(List<DeptDto> deptDtos) {
Set<DeptDto> trees = new LinkedHashSet<>();
Set<DeptDto> depts= new LinkedHashSet<>();
List<String> deptNames = deptDtos.stream().map(DeptDto::getName).collect(Collectors.toList());
boolean isChild;
for (DeptDTO deptDTO : deptDTOS) {
for (DeptDto deptDTO : deptDtos) {
isChild = false;
if ("0".equals(deptDTO.getPid().toString())) {
trees.add(deptDTO);
}
for (DeptDTO it : deptDTOS) {
for (DeptDto it : deptDtos) {
if (it.getPid().equals(deptDTO.getId())) {
isChild = true;
if (deptDTO.getChildren() == null) {
......@@ -87,28 +87,29 @@ public class DeptServiceImpl implements DeptService {
deptDTO.getChildren().add(it);
}
}
if(isChild)
if(isChild) {
depts.add(deptDTO);
else if(!deptNames.contains(deptRepository.findNameById(deptDTO.getPid())))
} else if(!deptNames.contains(deptRepository.findNameById(deptDTO.getPid()))) {
depts.add(deptDTO);
}
}
if (CollectionUtils.isEmpty(trees)) {
trees = depts;
}
Integer totalElements = deptDTOS.size();
Integer totalElements = deptDtos.size();
Map<String,Object> map = new HashMap<>();
Map<String,Object> map = new HashMap<>(2);
map.put("totalElements",totalElements);
map.put("content",CollectionUtils.isEmpty(trees)?deptDTOS:trees);
map.put("content",CollectionUtils.isEmpty(trees)? deptDtos :trees);
return map;
}
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public DeptDTO create(Dept resources) {
public DeptDto create(Dept resources) {
return deptMapper.toDto(deptRepository.save(resources));
}
......@@ -133,9 +134,9 @@ public class DeptServiceImpl implements DeptService {
}
@Override
public void download(List<DeptDTO> deptDTOs, HttpServletResponse response) throws IOException {
public void download(List<DeptDto> deptDtos, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (DeptDTO deptDTO : deptDTOs) {
for (DeptDto deptDTO : deptDtos) {
Map<String,Object> map = new LinkedHashMap<>();
map.put("部门名称", deptDTO.getName());
map.put("部门状态", deptDTO.getEnabled() ? "启用" : "停用");
......
......@@ -7,7 +7,7 @@ import me.zhengjie.utils.QueryHelp;
import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.modules.system.repository.DictDetailRepository;
import me.zhengjie.modules.system.service.DictDetailService;
import me.zhengjie.modules.system.service.dto.DictDetailDTO;
import me.zhengjie.modules.system.service.dto.DictDetailDto;
import me.zhengjie.modules.system.service.mapper.DictDetailMapper;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
......@@ -46,7 +46,7 @@ public class DictDetailServiceImpl implements DictDetailService {
@Override
@Cacheable(key = "#p0")
public DictDetailDTO findById(Long id) {
public DictDetailDto findById(Long id) {
DictDetail dictDetail = dictDetailRepository.findById(id).orElseGet(DictDetail::new);
ValidationUtil.isNull(dictDetail.getId(),"DictDetail","id",id);
return dictDetailMapper.toDto(dictDetail);
......@@ -55,7 +55,7 @@ public class DictDetailServiceImpl implements DictDetailService {
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public DictDetailDTO create(DictDetail resources) {
public DictDetailDto create(DictDetail resources) {
return dictDetailMapper.toDto(dictDetailRepository.save(resources));
}
......
......@@ -2,7 +2,7 @@ package me.zhengjie.modules.system.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import me.zhengjie.modules.system.domain.Dict;
import me.zhengjie.modules.system.service.dto.DictDetailDTO;
import me.zhengjie.modules.system.service.dto.DictDetailDto;
import me.zhengjie.modules.system.service.dto.DictQueryCriteria;
import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.PageUtil;
......@@ -10,7 +10,7 @@ import me.zhengjie.utils.QueryHelp;
import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.modules.system.repository.DictRepository;
import me.zhengjie.modules.system.service.DictService;
import me.zhengjie.modules.system.service.dto.DictDTO;
import me.zhengjie.modules.system.service.dto.DictDto;
import me.zhengjie.modules.system.service.mapper.DictMapper;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
......@@ -54,14 +54,14 @@ public class DictServiceImpl implements DictService {
}
@Override
public List<DictDTO> queryAll(DictQueryCriteria dict) {
public List<DictDto> queryAll(DictQueryCriteria dict) {
List<Dict> list = dictRepository.findAll((root, query, cb) -> QueryHelp.getPredicate(root, dict, cb));
return dictMapper.toDto(list);
}
@Override
@Cacheable(key = "#p0")
public DictDTO findById(Long id) {
public DictDto findById(Long id) {
Dict dict = dictRepository.findById(id).orElseGet(Dict::new);
ValidationUtil.isNull(dict.getId(),"Dict","id",id);
return dictMapper.toDto(dict);
......@@ -70,7 +70,7 @@ public class DictServiceImpl implements DictService {
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public DictDTO create(Dict resources) {
public DictDto create(Dict resources) {
return dictMapper.toDto(dictRepository.save(resources));
}
......@@ -92,11 +92,11 @@ public class DictServiceImpl implements DictService {
}
@Override
public void download(List<DictDTO> dictDTOS, HttpServletResponse response) throws IOException {
public void download(List<DictDto> dictDtos, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (DictDTO dictDTO : dictDTOS) {
for (DictDto dictDTO : dictDtos) {
if(CollectionUtil.isNotEmpty(dictDTO.getDictDetails())){
for (DictDetailDTO dictDetail : dictDTO.getDictDetails()) {
for (DictDetailDto dictDetail : dictDTO.getDictDetails()) {
Map<String,Object> map = new LinkedHashMap<>();
map.put("字典名称", dictDTO.getName());
map.put("字典描述", dictDTO.getRemark());
......
......@@ -9,7 +9,7 @@ import me.zhengjie.utils.QueryHelp;
import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.modules.system.repository.JobRepository;
import me.zhengjie.modules.system.service.JobService;
import me.zhengjie.modules.system.service.dto.JobDTO;
import me.zhengjie.modules.system.service.dto.JobDto;
import me.zhengjie.modules.system.service.mapper.JobMapper;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
......@@ -52,7 +52,7 @@ public class JobServiceImpl implements JobService {
@Cacheable
public Map<String,Object> queryAll(JobQueryCriteria criteria, Pageable pageable) {
Page<Job> page = jobRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
List<JobDTO> jobs = new ArrayList<>();
List<JobDto> jobs = new ArrayList<>();
for (Job job : page.getContent()) {
jobs.add(jobMapper.toDto(job,deptRepository.findNameById(job.getDept().getPid())));
}
......@@ -61,14 +61,14 @@ public class JobServiceImpl implements JobService {
@Override
@Cacheable
public List<JobDTO> queryAll(JobQueryCriteria criteria) {
public List<JobDto> queryAll(JobQueryCriteria criteria) {
List<Job> list = jobRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder));
return jobMapper.toDto(list);
}
@Override
@Cacheable(key = "#p0")
public JobDTO findById(Long id) {
public JobDto findById(Long id) {
Job job = jobRepository.findById(id).orElseGet(Job::new);
ValidationUtil.isNull(job.getId(),"Job","id",id);
return jobMapper.toDto(job);
......@@ -77,7 +77,7 @@ public class JobServiceImpl implements JobService {
@Override
@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public JobDTO create(Job resources) {
public JobDto create(Job resources) {
return jobMapper.toDto(jobRepository.save(resources));
}
......@@ -99,9 +99,9 @@ public class JobServiceImpl implements JobService {
}
@Override
public void download(List<JobDTO> jobDTOs, HttpServletResponse response) throws IOException {
public void download(List<JobDto> jobDtos, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (JobDTO jobDTO : jobDTOs) {
for (JobDto jobDTO : jobDtos) {
Map<String,Object> map = new LinkedHashMap<>();
map.put("岗位名称", jobDTO.getName());
map.put("所属部门", jobDTO.getDept().getName());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment