|
|
@ -20,6 +20,8 @@ package com.elink.esua.epdc.service.impl; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.NumConstant; |
|
|
|
import com.elink.esua.epdc.commons.tools.exception.RenException; |
|
|
|
import com.elink.esua.epdc.commons.tools.page.PageData; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.FieldConstant; |
|
|
@ -84,6 +86,7 @@ public class NewsCategoryServiceImpl extends BaseServiceImpl<NewsCategoryDao, Ne |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void save(NewsCategoryDTO dto) { |
|
|
|
checkCategoryCodeAndName(dto.getId(), dto.getCategoryCode(), dto.getCategoryName()); |
|
|
|
NewsCategoryEntity entity = ConvertUtils.sourceToTarget(dto, NewsCategoryEntity.class); |
|
|
|
insert(entity); |
|
|
|
} |
|
|
@ -91,31 +94,48 @@ public class NewsCategoryServiceImpl extends BaseServiceImpl<NewsCategoryDao, Ne |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void update(NewsCategoryDTO dto) { |
|
|
|
NewsCategoryEntity entity = ConvertUtils.sourceToTarget(dto, NewsCategoryEntity.class); |
|
|
|
|
|
|
|
if (checkIsExist(dto.getId())) { |
|
|
|
throw new RenException("该类别下存在新闻不允许修改"); |
|
|
|
} |
|
|
|
checkCategoryCodeAndName(dto.getId(), dto.getCategoryCode(), dto.getCategoryName()); |
|
|
|
|
|
|
|
NewsCategoryEntity entity = ConvertUtils.sourceToTarget(dto, NewsCategoryEntity.class); |
|
|
|
updateById(entity); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 判断新闻类别名称或编码是否已存在 |
|
|
|
* |
|
|
|
* @param id 新闻类别id |
|
|
|
* @param code 新闻类别编码 |
|
|
|
* @param name 新闻类别名称 |
|
|
|
* @return void |
|
|
|
* @author |
|
|
|
* @date 2020/5/21 16:58 |
|
|
|
*/ |
|
|
|
private void checkCategoryCodeAndName(String id, String code, String name) { |
|
|
|
if (baseDao.selectCodeCount(code, id) > NumConstant.ZERO) { |
|
|
|
throw new RenException("类别编码已存在"); |
|
|
|
} |
|
|
|
if (baseDao.selectNameCount(name, id) > NumConstant.ZERO) { |
|
|
|
throw new RenException("类别名称已存在"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void delete(String[] ids) { |
|
|
|
if (checkIsExist(ids[0])) { |
|
|
|
throw new RenException("该类别下存在新闻不允许删除"); |
|
|
|
} |
|
|
|
// 逻辑删除(@TableLogic 注解)
|
|
|
|
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public int checkNameCategory(String categoryName, String id) { |
|
|
|
return baseDao.selectNameCount(categoryName, id); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public int checkCodeCategory(String categoryCode, String id) { |
|
|
|
return baseDao.selectCodeCount(categoryCode, id); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean checkIsExist(String id) { |
|
|
|
return newsService.checkCountByCategoryId(id) > 0 ? true : false; |
|
|
|
private boolean checkIsExist(String id) { |
|
|
|
return newsService.checkCountByCategoryId(id) > NumConstant.ZERO; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|