|
|
@ -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; |
|
|
|
} |
|
|
|
|
|
|
|