forked from luyan/epmet-cloud-lingshan
9 changed files with 467 additions and 3 deletions
@ -0,0 +1,74 @@ |
|||||
|
package com.epmet.dto; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
import java.util.Date; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 文章栏目表 |
||||
|
* |
||||
|
* @author generator generator@elink-cn.com |
||||
|
* @since v1.0.0 2023-04-11 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class CategoryDictDTO implements Serializable { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
*/ |
||||
|
private String id; |
||||
|
|
||||
|
/** |
||||
|
* 客户id |
||||
|
*/ |
||||
|
private String customerId; |
||||
|
|
||||
|
/** |
||||
|
* 分类栏目名称 |
||||
|
*/ |
||||
|
private String categoryName; |
||||
|
|
||||
|
/** |
||||
|
* 父栏目ID |
||||
|
*/ |
||||
|
private String pid; |
||||
|
|
||||
|
/** |
||||
|
* 排序 |
||||
|
*/ |
||||
|
private Integer sort; |
||||
|
|
||||
|
/** |
||||
|
* 删除标识 0.未删除 1.已删除 |
||||
|
*/ |
||||
|
private Integer delFlag; |
||||
|
|
||||
|
/** |
||||
|
* 乐观锁 |
||||
|
*/ |
||||
|
private Integer revision; |
||||
|
|
||||
|
/** |
||||
|
* 创建人 |
||||
|
*/ |
||||
|
private String createdBy; |
||||
|
|
||||
|
/** |
||||
|
* 创建时间 |
||||
|
*/ |
||||
|
private Date createdTime; |
||||
|
|
||||
|
/** |
||||
|
* 更新人 |
||||
|
*/ |
||||
|
private String updatedBy; |
||||
|
|
||||
|
/** |
||||
|
* 更新时间 |
||||
|
*/ |
||||
|
private Date updatedTime; |
||||
|
|
||||
|
} |
@ -0,0 +1,72 @@ |
|||||
|
package com.epmet.controller; |
||||
|
|
||||
|
import com.epmet.commons.tools.aop.NoRepeatSubmit; |
||||
|
import com.epmet.commons.tools.page.PageData; |
||||
|
import com.epmet.commons.tools.utils.Result; |
||||
|
import com.epmet.commons.tools.validator.AssertUtils; |
||||
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
||||
|
import com.epmet.commons.tools.validator.group.AddGroup; |
||||
|
import com.epmet.commons.tools.validator.group.UpdateGroup; |
||||
|
import com.epmet.commons.tools.validator.group.DefaultGroup; |
||||
|
import com.epmet.dto.CategoryDictDTO; |
||||
|
import com.epmet.service.CategoryDictService; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 文章栏目表 |
||||
|
* |
||||
|
* @author generator generator@elink-cn.com |
||||
|
* @since v1.0.0 2023-04-11 |
||||
|
*/ |
||||
|
@RestController |
||||
|
@RequestMapping("categoryDict") |
||||
|
public class CategoryDictController { |
||||
|
|
||||
|
@Autowired |
||||
|
private CategoryDictService categoryDictService; |
||||
|
|
||||
|
@RequestMapping("list") |
||||
|
public Result<List<CategoryDictDTO>> list(@RequestParam Integer pageNo, @RequestParam Integer pageSize){ |
||||
|
List<CategoryDictDTO> list = categoryDictService.list(pageNo, pageSize); |
||||
|
return new Result<List<CategoryDictDTO>>().ok(list); |
||||
|
} |
||||
|
|
||||
|
@RequestMapping(value = "{id}",method = {RequestMethod.POST,RequestMethod.GET}) |
||||
|
public Result<CategoryDictDTO> get(@PathVariable("id") String id){ |
||||
|
CategoryDictDTO data = categoryDictService.get(id); |
||||
|
return new Result<CategoryDictDTO>().ok(data); |
||||
|
} |
||||
|
|
||||
|
@NoRepeatSubmit |
||||
|
@PostMapping("save") |
||||
|
public Result save(@RequestBody CategoryDictDTO dto){ |
||||
|
//效验数据
|
||||
|
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); |
||||
|
categoryDictService.save(dto); |
||||
|
return new Result(); |
||||
|
} |
||||
|
|
||||
|
@NoRepeatSubmit |
||||
|
@PostMapping("update") |
||||
|
public Result update(@RequestBody CategoryDictDTO dto){ |
||||
|
//效验数据
|
||||
|
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); |
||||
|
categoryDictService.update(dto); |
||||
|
return new Result(); |
||||
|
} |
||||
|
|
||||
|
@PostMapping("delete") |
||||
|
public Result delete(@RequestBody String[] ids){ |
||||
|
//效验数据
|
||||
|
AssertUtils.isArrayEmpty(ids, "id"); |
||||
|
categoryDictService.delete(ids); |
||||
|
return new Result(); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,16 @@ |
|||||
|
package com.epmet.dao; |
||||
|
|
||||
|
import com.epmet.commons.mybatis.dao.BaseDao; |
||||
|
import com.epmet.entity.CategoryDictEntity; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
|
||||
|
/** |
||||
|
* 文章栏目表 |
||||
|
* |
||||
|
* @author generator generator@elink-cn.com |
||||
|
* @since v1.0.0 2023-04-11 |
||||
|
*/ |
||||
|
@Mapper |
||||
|
public interface CategoryDictDao extends BaseDao<CategoryDictEntity> { |
||||
|
|
||||
|
} |
@ -0,0 +1,44 @@ |
|||||
|
package com.epmet.entity; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
|
||||
|
import com.epmet.commons.mybatis.entity.BaseEpmetEntity; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* 文章栏目表 |
||||
|
* |
||||
|
* @author generator generator@elink-cn.com |
||||
|
* @since v1.0.0 2023-04-11 |
||||
|
*/ |
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper=false) |
||||
|
@TableName("category_dict") |
||||
|
public class CategoryDictEntity extends BaseEpmetEntity { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** |
||||
|
* 客户id |
||||
|
*/ |
||||
|
private String customerId; |
||||
|
|
||||
|
/** |
||||
|
* 分类栏目名称 |
||||
|
*/ |
||||
|
private String categoryName; |
||||
|
|
||||
|
/** |
||||
|
* 父栏目ID |
||||
|
*/ |
||||
|
private String pid; |
||||
|
|
||||
|
/** |
||||
|
* 排序 |
||||
|
*/ |
||||
|
private Integer sort; |
||||
|
|
||||
|
} |
@ -0,0 +1,88 @@ |
|||||
|
package com.epmet.service; |
||||
|
|
||||
|
import com.epmet.commons.mybatis.service.BaseService; |
||||
|
import com.epmet.commons.tools.page.PageData; |
||||
|
import com.epmet.dto.CategoryDictDTO; |
||||
|
import com.epmet.entity.CategoryDictEntity; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* 文章栏目表 |
||||
|
* |
||||
|
* @author generator generator@elink-cn.com |
||||
|
* @since v1.0.0 2023-04-11 |
||||
|
*/ |
||||
|
public interface CategoryDictService extends BaseService<CategoryDictEntity> { |
||||
|
|
||||
|
/** |
||||
|
* 默认分页 |
||||
|
* |
||||
|
* @param params |
||||
|
* @return PageData<CategoryDictDTO> |
||||
|
* @author generator |
||||
|
* @date 2023-04-11 |
||||
|
*/ |
||||
|
PageData<CategoryDictDTO> page(Map<String, Object> params); |
||||
|
|
||||
|
/** |
||||
|
* 默认查询 |
||||
|
* |
||||
|
* @param params |
||||
|
* @return java.util.List<CategoryDictDTO> |
||||
|
* @author generator |
||||
|
* @date 2023-04-11 |
||||
|
*/ |
||||
|
List<CategoryDictDTO> list(Map<String, Object> params); |
||||
|
|
||||
|
/** |
||||
|
* 单条查询 |
||||
|
* |
||||
|
* @param id |
||||
|
* @return CategoryDictDTO |
||||
|
* @author generator |
||||
|
* @date 2023-04-11 |
||||
|
*/ |
||||
|
CategoryDictDTO get(String id); |
||||
|
|
||||
|
/** |
||||
|
* 默认保存 |
||||
|
* |
||||
|
* @param dto |
||||
|
* @return void |
||||
|
* @author generator |
||||
|
* @date 2023-04-11 |
||||
|
*/ |
||||
|
void save(CategoryDictDTO dto); |
||||
|
|
||||
|
/** |
||||
|
* 默认更新 |
||||
|
* |
||||
|
* @param dto |
||||
|
* @return void |
||||
|
* @author generator |
||||
|
* @date 2023-04-11 |
||||
|
*/ |
||||
|
void update(CategoryDictDTO dto); |
||||
|
|
||||
|
/** |
||||
|
* 批量删除 |
||||
|
* |
||||
|
* @param ids |
||||
|
* @return void |
||||
|
* @author generator |
||||
|
* @date 2023-04-11 |
||||
|
*/ |
||||
|
void delete(String[] ids); |
||||
|
|
||||
|
/** |
||||
|
* @description: 列表 |
||||
|
* @param pageNo: |
||||
|
* @param pageSize: |
||||
|
* @return java.util.List<com.epmet.dto.CategoryDictDTO> |
||||
|
* @author: WangXianZhang |
||||
|
* @date: 2023/4/11 7:06 PM |
||||
|
*/ |
||||
|
List<CategoryDictDTO> list(Integer pageNo, Integer pageSize); |
||||
|
} |
@ -0,0 +1,149 @@ |
|||||
|
package com.epmet.service.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
||||
|
import com.epmet.commons.tools.distributedlock.DistributedLock; |
||||
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
||||
|
import com.epmet.commons.tools.exception.EpmetException; |
||||
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
||||
|
import com.epmet.commons.tools.page.PageData; |
||||
|
import com.epmet.commons.tools.utils.ConvertUtils; |
||||
|
import com.epmet.commons.tools.constant.FieldConstant; |
||||
|
import com.epmet.commons.tools.utils.EpmetRequestHolder; |
||||
|
import com.epmet.dao.CategoryDictDao; |
||||
|
import com.epmet.dto.CategoryDictDTO; |
||||
|
import com.epmet.entity.CategoryDictEntity; |
||||
|
import com.epmet.service.CategoryDictService; |
||||
|
import org.apache.commons.lang3.StringUtils; |
||||
|
import org.redisson.api.RLock; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
|
||||
|
import java.util.Arrays; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* 文章栏目表 |
||||
|
* |
||||
|
* @author generator generator@elink-cn.com |
||||
|
* @since v1.0.0 2023-04-11 |
||||
|
*/ |
||||
|
@Service |
||||
|
public class CategoryDictServiceImpl extends BaseServiceImpl<CategoryDictDao, CategoryDictEntity> implements CategoryDictService { |
||||
|
|
||||
|
@Autowired |
||||
|
private DistributedLock distributedLock; |
||||
|
|
||||
|
@Override |
||||
|
public PageData<CategoryDictDTO> page(Map<String, Object> params) { |
||||
|
IPage<CategoryDictEntity> page = baseDao.selectPage( |
||||
|
getPage(params, FieldConstant.CREATED_TIME, false), |
||||
|
getWrapper(params) |
||||
|
); |
||||
|
return getPageData(page, CategoryDictDTO.class); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<CategoryDictDTO> list(Map<String, Object> params) { |
||||
|
List<CategoryDictEntity> entityList = baseDao.selectList(getWrapper(params)); |
||||
|
|
||||
|
return ConvertUtils.sourceToTarget(entityList, CategoryDictDTO.class); |
||||
|
} |
||||
|
|
||||
|
private QueryWrapper<CategoryDictEntity> getWrapper(Map<String, Object> params){ |
||||
|
String id = (String)params.get(FieldConstant.ID_HUMP); |
||||
|
|
||||
|
QueryWrapper<CategoryDictEntity> wrapper = new QueryWrapper<>(); |
||||
|
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); |
||||
|
|
||||
|
return wrapper; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public CategoryDictDTO get(String id) { |
||||
|
CategoryDictEntity entity = baseDao.selectById(id); |
||||
|
return ConvertUtils.sourceToTarget(entity, CategoryDictDTO.class); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void save(CategoryDictDTO dto) { |
||||
|
String customerId = EpmetRequestHolder.getLoginUserCustomerId(); |
||||
|
|
||||
|
// 重名检查,客户下不能重名
|
||||
|
LambdaQueryWrapper<CategoryDictEntity> query = new LambdaQueryWrapper<>(); |
||||
|
query.eq(CategoryDictEntity::getCustomerId, customerId); |
||||
|
query.eq(CategoryDictEntity::getCategoryName, dto.getCategoryName()); |
||||
|
|
||||
|
// 加锁
|
||||
|
RLock lock = distributedLock.getLock("voice:categorydict"); |
||||
|
try { |
||||
|
if (baseDao.selectCount(query) > 0) { |
||||
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), null, "栏目名称已存在"); |
||||
|
} |
||||
|
|
||||
|
dto.setCustomerId(customerId); |
||||
|
CategoryDictEntity entity = ConvertUtils.sourceToTarget(dto, CategoryDictEntity.class); |
||||
|
insert(entity); |
||||
|
|
||||
|
} catch (EpmetException ee) { |
||||
|
throw ee; |
||||
|
} catch (Exception e) { |
||||
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), null, "【文章】新增文章栏目失败:" + ExceptionUtils.getErrorStackTrace(e)); |
||||
|
} finally { |
||||
|
// 解锁
|
||||
|
lock.unlock(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void update(CategoryDictDTO dto) { |
||||
|
String customerId = EpmetRequestHolder.getLoginUserCustomerId(); |
||||
|
|
||||
|
// 重名检查,客户下不能重名
|
||||
|
LambdaQueryWrapper<CategoryDictEntity> query = new LambdaQueryWrapper<>(); |
||||
|
query.eq(CategoryDictEntity::getCustomerId, customerId); |
||||
|
query.eq(CategoryDictEntity::getCategoryName, dto.getCategoryName()); |
||||
|
|
||||
|
RLock lock = distributedLock.getLock("voice:categorydict"); |
||||
|
try { |
||||
|
CategoryDictEntity inDb = null; |
||||
|
// 能查询到一条数据,并且该条数据的ID不是当前修改的这条数据的ID,说明已存在同名的其他标签,该名字已被其他标签占用
|
||||
|
if ((inDb = baseDao.selectOne(query)) != null |
||||
|
&& !inDb.getId().equals(dto.getId())) { |
||||
|
|
||||
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), null, "栏目名称已存在"); |
||||
|
} |
||||
|
|
||||
|
dto.setCustomerId(customerId); |
||||
|
CategoryDictEntity entity = ConvertUtils.sourceToTarget(dto, CategoryDictEntity.class); |
||||
|
updateById(entity); |
||||
|
|
||||
|
} catch (EpmetException ee) { |
||||
|
throw ee; |
||||
|
} catch (Exception e) { |
||||
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), null, "【文章】新增文章栏目失败:" + ExceptionUtils.getErrorStackTrace(e)); |
||||
|
} finally { |
||||
|
// 解锁
|
||||
|
lock.unlock(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void delete(String[] ids) { |
||||
|
// 逻辑删除(@TableLogic 注解)
|
||||
|
baseDao.deleteBatchIds(Arrays.asList(ids)); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<CategoryDictDTO> list(Integer pageNo, Integer pageSize) { |
||||
|
List<CategoryDictEntity> list = baseDao.selectList(null); |
||||
|
return ConvertUtils.sourceToTarget(list, CategoryDictDTO.class); |
||||
|
} |
||||
|
} |
@ -0,0 +1,21 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
|
|
||||
|
<mapper namespace="com.epmet.dao.CategoryDictDao"> |
||||
|
|
||||
|
<resultMap type="com.epmet.entity.CategoryDictEntity" id="categoryDictMap"> |
||||
|
<result property="id" column="ID"/> |
||||
|
<result property="customerId" column="CUSTOMER_ID"/> |
||||
|
<result property="categoryName" column="CATEGORY_NAME"/> |
||||
|
<result property="pid" column="PID"/> |
||||
|
<result property="sort" column="SORT"/> |
||||
|
<result property="delFlag" column="DEL_FLAG"/> |
||||
|
<result property="revision" column="REVISION"/> |
||||
|
<result property="createdBy" column="CREATED_BY"/> |
||||
|
<result property="createdTime" column="CREATED_TIME"/> |
||||
|
<result property="updatedBy" column="UPDATED_BY"/> |
||||
|
<result property="updatedTime" column="UPDATED_TIME"/> |
||||
|
</resultMap> |
||||
|
|
||||
|
|
||||
|
</mapper> |
Loading…
Reference in new issue