refactor:区域管理
This commit is contained in:
@@ -26,7 +26,7 @@ import org.nl.b_lms.sch.region.service.IschBaseRegionService;
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/schBaseRegion")
|
||||
@RequestMapping("/api/region")
|
||||
@Slf4j
|
||||
public class SchBaseRegionController {
|
||||
|
||||
@@ -56,7 +56,7 @@ public class SchBaseRegionController {
|
||||
*/
|
||||
@PostMapping
|
||||
@Log("新增区域基础表")
|
||||
public ResponseEntity<Object> create(SchBaseRegion entity) {
|
||||
public ResponseEntity<Object> create(@RequestBody SchBaseRegion entity) {
|
||||
schBaseRegionService.create(entity);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
@@ -71,7 +71,7 @@ public class SchBaseRegionController {
|
||||
@PutMapping
|
||||
@Log("修改区域基础表")
|
||||
//@SaCheckPermission("@el.check(SchBaseRegion:edit')")
|
||||
public ResponseEntity<Object> update(SchBaseRegion entity) {
|
||||
public ResponseEntity<Object> update(@RequestBody SchBaseRegion entity) {
|
||||
schBaseRegionService.update(entity);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.nl.b_lms.sch.region.dao;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.*;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
@@ -16,10 +14,6 @@ import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@ToString
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("sch_base_region")
|
||||
public class SchBaseRegion extends Model<SchBaseRegion> {
|
||||
@@ -73,7 +67,7 @@ public class SchBaseRegion extends Model<SchBaseRegion> {
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private Long create_id;
|
||||
private String create_id;
|
||||
|
||||
|
||||
/**
|
||||
@@ -92,13 +86,13 @@ public class SchBaseRegion extends Model<SchBaseRegion> {
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
private Long update_optid;
|
||||
private String update_id;
|
||||
|
||||
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
private String update_optname;
|
||||
private String update_name;
|
||||
|
||||
|
||||
/**
|
||||
@@ -108,16 +102,6 @@ public class SchBaseRegion extends Model<SchBaseRegion> {
|
||||
private String update_time;
|
||||
|
||||
|
||||
/**
|
||||
* 获取主键值
|
||||
*
|
||||
* @return 主键值
|
||||
*/
|
||||
@Override
|
||||
protected Serializable pkVal() {
|
||||
return this.region_id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package org.nl.b_lms.sch.region.service.impl;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.nl.b_lms.sch.region.dao.SchBaseRegion;
|
||||
import org.nl.b_lms.sch.region.dao.mapper.SchBaseRegionMapper;
|
||||
@@ -8,6 +12,7 @@ import cn.hutool.core.date.DateUtil;
|
||||
import org.nl.common.utils.SecurityUtils;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
@@ -40,16 +45,14 @@ public class SchBaseRegionServiceImpl extends ServiceImpl<SchBaseRegionMapper, S
|
||||
*/
|
||||
@Override
|
||||
public IPage<SchBaseRegion> queryAll(Map whereJson, PageQuery page) {
|
||||
return schBaseRegionMapper.selectPage(new Page<>(page.getPage() + 1, page.getSize()), new QueryWrapper<SchBaseRegion>()
|
||||
.lambda()
|
||||
// .like(StringUtils.isNotBlank(form.name()), User::getName, form.name())
|
||||
// .between(form.beginTime != null && form.endTime != null, User::getCreateTime, beginTime, endTime)
|
||||
// .in(form.Status != null, User::getStatus
|
||||
// , UserStatusEnum.NOT_SUBMITTED
|
||||
// , UserStatusEnum.TO_REVIEWED)
|
||||
// .orderByDesc(User::getId)
|
||||
//.eq(SchBaseRegion::getIs_delete, 0)
|
||||
);
|
||||
String blurry = MapUtil.getStr(whereJson, "region_code");
|
||||
LambdaQueryWrapper<SchBaseRegion> lam = new LambdaQueryWrapper<>();
|
||||
lam.like(ObjectUtil.isNotEmpty(blurry), SchBaseRegion::getRegion_code, blurry)
|
||||
.or(ObjectUtil.isNotEmpty(blurry), la -> la.like(SchBaseRegion::getRegion_name, blurry))
|
||||
.orderByAsc(SchBaseRegion::getRegion_code);
|
||||
IPage<SchBaseRegion> pages = new Page<>(page.getPage() + 1, page.getSize());
|
||||
schBaseRegionMapper.selectPage(pages, lam);
|
||||
return pages;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,9 +63,19 @@ public class SchBaseRegionServiceImpl extends ServiceImpl<SchBaseRegionMapper, S
|
||||
*/
|
||||
@Override
|
||||
public void create(SchBaseRegion entity) {
|
||||
SchBaseRegion region = getByCode(entity.getRegion_code());
|
||||
if (ObjectUtil.isNotEmpty(region)) {
|
||||
throw new BadRequestException("区域[" + entity.getRegion_code() + "]已存在!");
|
||||
}
|
||||
schBaseRegionMapper.insert(getBasicInfo(entity, true));
|
||||
}
|
||||
|
||||
private SchBaseRegion getByCode(String regionCode) {
|
||||
LambdaQueryWrapper<SchBaseRegion> lam = new LambdaQueryWrapper<>();
|
||||
lam.eq(SchBaseRegion::getRegion_code, regionCode);
|
||||
return this.getOne(lam);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
@@ -71,10 +84,13 @@ public class SchBaseRegionServiceImpl extends ServiceImpl<SchBaseRegionMapper, S
|
||||
*/
|
||||
@Override
|
||||
public void update(SchBaseRegion entity) {
|
||||
// SchBaseRegion dto = schBaseRegionMapper.selectById(entity.getId);
|
||||
// if (dto == null) {
|
||||
// throw new BadRequestException("不存在该数据!");
|
||||
// }
|
||||
SchBaseRegion region = getById(entity.getRegion_id());
|
||||
if (ObjectUtil.isEmpty(region)) {
|
||||
throw new BadRequestException("区域[" + entity.getRegion_code() + "]不存在!");
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(region) && !entity.getRegion_id().equals(region.getRegion_id())) {
|
||||
throw new BadRequestException("区域[" + entity.getRegion_code() + "]已存在!");
|
||||
}
|
||||
schBaseRegionMapper.updateById(getBasicInfo(entity, false));
|
||||
}
|
||||
|
||||
@@ -98,14 +114,15 @@ public class SchBaseRegionServiceImpl extends ServiceImpl<SchBaseRegionMapper, S
|
||||
* @param isCreate 是否创建
|
||||
*/
|
||||
private SchBaseRegion getBasicInfo(SchBaseRegion entity, boolean isCreate) {
|
||||
// if (isCreate) {
|
||||
// entity.setCreate_id(Long.valueOf(SecurityUtils.getCurrentUserId()));
|
||||
// entity.setCreate_name(SecurityUtils.getCurrentNickName());
|
||||
// entity.setCreate_time(DateUtil.now());
|
||||
// }
|
||||
// entity.setUpdate_optid(Long.valueOf(SecurityUtils.getCurrentUserId()));
|
||||
// entity.setUpdate_optname(SecurityUtils.getCurrentNickName());
|
||||
// entity.setUpdate_time(DateUtil.now());
|
||||
if (isCreate) {
|
||||
entity.setRegion_id(IdUtil.getSnowflake(1,1).nextIdStr());
|
||||
entity.setCreate_id(SecurityUtils.getCurrentUserId());
|
||||
entity.setCreate_name(SecurityUtils.getCurrentNickName());
|
||||
entity.setCreate_time(DateUtil.now());
|
||||
}
|
||||
entity.setUpdate_id(SecurityUtils.getCurrentUserId());
|
||||
entity.setUpdate_name(SecurityUtils.getCurrentNickName());
|
||||
entity.setUpdate_time(DateUtil.now());
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.Map;
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
|
||||
@RequestMapping("/api/region")
|
||||
@RequestMapping("/api/region2")
|
||||
@Slf4j
|
||||
public class RegionController {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user