feat: 行政区划相关接口提交
This commit is contained in:
@ -30,13 +30,13 @@ public class DictionaryServiceImpl implements DictionaryService {
|
||||
public PageResponse<DictionaryVO> paginate(PageRequest<DictionaryDTO> pageRequest) {
|
||||
Page<Dictionary> paginate = Pages.paginate(pageRequest, dictionaryMapper, (dto, wrapper) -> {
|
||||
if (Strings.isNotBlank(dto.getName())) {
|
||||
wrapper.like("name", dto.getName());
|
||||
wrapper.like(Dictionary::getName, dto.getName());
|
||||
}
|
||||
if (Strings.isNotBlank(dto.getCode())) {
|
||||
wrapper.eq("code", dto.getCode());
|
||||
wrapper.eq(Dictionary::getCode, dto.getCode());
|
||||
}
|
||||
if (Strings.isNotBlank(dto.getType())) {
|
||||
wrapper.eq("type", dto.getType());
|
||||
wrapper.eq(Dictionary::getType, dto.getType());
|
||||
}
|
||||
|
||||
return wrapper;
|
||||
@ -53,16 +53,16 @@ public class DictionaryServiceImpl implements DictionaryService {
|
||||
public boolean update(DictionaryDTO record) {
|
||||
Dictionary dictionary = dictionaryMapper.selectById(record.getId());
|
||||
if (dictionary != null) {
|
||||
if (Strings.isNotBlank(dictionary.getName())) {
|
||||
if (Strings.isNotBlank(record.getName())) {
|
||||
dictionary.setName(dictionary.getName());
|
||||
}
|
||||
if (Strings.isNotBlank(dictionary.getCode())) {
|
||||
if (Strings.isNotBlank(record.getCode())) {
|
||||
dictionary.setCode(dictionary.getCode());
|
||||
}
|
||||
if (Strings.isNotBlank(dictionary.getType())) {
|
||||
if (Strings.isNotBlank(record.getType())) {
|
||||
dictionary.setType(dictionary.getType());
|
||||
}
|
||||
dictionary.setDescription(dictionary.getDescription());
|
||||
dictionary.setDescription(record.getDescription());
|
||||
dictionary.setUpdateTime(Timestamp.from(Instant.now()));
|
||||
return dictionaryMapper.updateById(dictionary) == 1;
|
||||
}
|
||||
|
||||
@ -23,4 +23,24 @@ public class RegionController {
|
||||
public ApiResponse<PageResponse<RegionVO>> paginate(@RequestBody PageRequest<RegionDTO> pageRequest) {
|
||||
return ApiResponse.success(regionService.paginate(pageRequest));
|
||||
}
|
||||
@PostMapping("/update")
|
||||
public ApiResponse<Boolean> update(@RequestBody RegionDTO record) {
|
||||
return ApiResponse.success(regionService.update(record));
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public ApiResponse<Boolean> delete(@RequestBody RegionDTO record) {
|
||||
return ApiResponse.success(regionService.delete(record.getId()));
|
||||
}
|
||||
|
||||
@PostMapping("/deleteBatch")
|
||||
public ApiResponse<Integer> deleteBatch(@RequestBody RegionDTO record) {
|
||||
return ApiResponse.success(regionService.deleteBatch(record.getIds()));
|
||||
}
|
||||
|
||||
@PostMapping("/insert")
|
||||
public ApiResponse<Boolean> insert(@RequestBody RegionDTO record) {
|
||||
return ApiResponse.success(regionService.insert(record));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package day.gitlab.dolphin.module.rbac.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import day.gitlab.dolphin.module.rbac.entity.Region;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@ -10,6 +12,10 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
@Mapper
|
||||
public interface RegionMapper extends BaseMapper<Region> {
|
||||
|
||||
default Region findByCode(String code) {
|
||||
LambdaQueryWrapper<Region> wrapper = Wrappers.<Region>lambdaQuery().eq(Region::getCode, code);
|
||||
return selectOne(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -5,10 +5,20 @@ import day.gitlab.dolphin.common.web.entity.PageResponse;
|
||||
import day.gitlab.dolphin.module.rbac.controller.dto.RegionDTO;
|
||||
import day.gitlab.dolphin.module.rbac.controller.vo.RegionVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 针对表【sys_rbac_region(区划项)】的数据库操作Service
|
||||
*/
|
||||
public interface RegionService {
|
||||
|
||||
PageResponse<RegionVO> paginate(PageRequest<RegionDTO> pageRequest);
|
||||
|
||||
boolean update(RegionDTO record);
|
||||
|
||||
boolean delete(String id);
|
||||
|
||||
int deleteBatch(List<String> ids);
|
||||
|
||||
boolean insert(RegionDTO record);
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package day.gitlab.dolphin.module.rbac.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import day.gitlab.dolphin.common.core.util.Strings;
|
||||
import day.gitlab.dolphin.common.mybatis.util.Pages;
|
||||
@ -14,6 +15,8 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -29,20 +32,93 @@ public class RegionServiceImpl implements RegionService {
|
||||
public PageResponse<RegionVO> paginate(PageRequest<RegionDTO> pageRequest) {
|
||||
Page<Region> paginate = Pages.paginate(pageRequest, regionMapper, (dto, wrapper) -> {
|
||||
if (Strings.isNotBlank(dto.getName())) {
|
||||
wrapper.like("name", dto.getName());
|
||||
wrapper.like(Region::getName, dto.getName());
|
||||
}
|
||||
if (Strings.isNotBlank(dto.getCode())) {
|
||||
wrapper.eq("code", dto.getCode());
|
||||
wrapper.eq(Region::getCode, dto.getCode());
|
||||
}
|
||||
|
||||
wrapper.isNull(Region::getParentId);
|
||||
return wrapper;
|
||||
});
|
||||
|
||||
return Pages.toPageResponse(paginate, (record) -> {
|
||||
PageResponse<RegionVO> pageResponse = Pages.toPageResponse(paginate, (record) -> {
|
||||
RegionVO dictionaryVO = new RegionVO();
|
||||
BeanUtils.copyProperties(record, dictionaryVO);
|
||||
return dictionaryVO;
|
||||
});
|
||||
|
||||
LambdaQueryWrapper<Region> wrapper = new LambdaQueryWrapper<>();
|
||||
RegionDTO dto = pageRequest.getQuery();
|
||||
if (Strings.isNotBlank(dto.getName())) {
|
||||
wrapper.like(Region::getName, dto.getName());
|
||||
}
|
||||
if (Strings.isNotBlank(dto.getCode())) {
|
||||
wrapper.eq(Region::getCode, dto.getCode());
|
||||
}
|
||||
List<Region> regions = regionMapper.selectList(wrapper);
|
||||
pageResponse.getRecords().forEach(record -> {
|
||||
list2tree(record, regions);
|
||||
});
|
||||
pageResponse.setTotal((long) regions.size());
|
||||
return pageResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(RegionDTO record) {
|
||||
Region region = regionMapper.selectById(record.getId());
|
||||
if (region != null) {
|
||||
region.setParentId(record.getParentId());
|
||||
region.setParentCode(record.getParentCode());
|
||||
region.setRootId(record.getRootId());
|
||||
region.setRootCode(record.getRootCode());
|
||||
if (Strings.isNotBlank(record.getName())) {
|
||||
region.setName(record.getName());
|
||||
}
|
||||
if (Strings.isNotBlank(record.getCode())) {
|
||||
region.setCode(record.getCode());
|
||||
}
|
||||
region.setCode(record.getExtCode());
|
||||
region.setSort(record.getSort() == null ? 0 : record.getSort());
|
||||
region.setDescription(record.getDescription());
|
||||
region.setUpdateTime(Timestamp.from(Instant.now()));
|
||||
return regionMapper.updateById(region) == 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(String id) {
|
||||
Region dictionary = regionMapper.selectById(id);
|
||||
if (dictionary != null) {
|
||||
return regionMapper.deleteById(dictionary.getId()) == 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteBatch(List<String> ids) {
|
||||
return regionMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean insert(RegionDTO record) {
|
||||
Region region = new Region();
|
||||
BeanUtils.copyProperties(record, region);
|
||||
region.setId(null);
|
||||
region.setCreateTime(Timestamp.from(Instant.now()));
|
||||
region.setUpdateTime(Timestamp.from(Instant.now()));
|
||||
if (regionMapper.insert(region) != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Strings.isBlank(region.getRootId()) && Strings.isBlank(region.getParentId())) {
|
||||
Region dbRegion = regionMapper.findByCode(record.getCode());
|
||||
|
||||
dbRegion.setRootId(dbRegion.getId());
|
||||
dbRegion.setRootCode(dbRegion.getCode());
|
||||
return regionMapper.updateById(dbRegion) == 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private List<RegionVO> list2tree(List<Region> records) {
|
||||
|
||||
Reference in New Issue
Block a user