feat(manager): introduce LabelDO, LabelManager, and LabelMapper xml

This commit is contained in:
pnoker
2023-11-03 00:03:33 +08:00
parent da1e7d33cc
commit ca5d0a5151
7 changed files with 218 additions and 58 deletions
@@ -0,0 +1,110 @@
package io.github.pnoker.center.manager.entity.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.Getter;
import lombok.Setter;
/**
* <p>
* 标签表
* </p>
*
* @author Automatic Generated By Mybatis Plus
* @since 2023-11-02
*/
@Getter
@Setter
@TableName("dc3_label")
public class LabelDO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键ID
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 标签名称
*/
@TableField("label_name")
private String labelName;
/**
* 标签颜色
*/
@TableField("color")
private String color;
/**
* 实体类型标识
*/
@TableField("entity_type_flag")
private Byte entityTypeFlag;
/**
* 使能标识
*/
@TableField("enable_flag")
private Byte enableFlag;
/**
* 租户ID
*/
@TableField("tenant_id")
private Long tenantId;
/**
* 描述
*/
@TableField("remark")
private String remark;
/**
* 创建者ID
*/
@TableField("creator_id")
private Long creatorId;
/**
* 创建者名称
*/
@TableField("creator_name")
private String creatorName;
/**
* 创建时间
*/
@TableField("create_time")
private LocalDateTime createTime;
/**
* 操作者ID
*/
@TableField("operator_id")
private Long operatorId;
/**
* 操作者名称
*/
@TableField("operator_name")
private String operatorName;
/**
* 操作时间
*/
@TableField("operate_time")
private LocalDateTime operateTime;
/**
* 逻辑删除标识,0:未删除,1:已删除
*/
@TableField("deleted")
private Byte deleted;
}
@@ -0,0 +1,16 @@
package io.github.pnoker.center.manager.manager;
import io.github.pnoker.center.manager.entity.model.LabelDO;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* <p>
* 标签表 服务类
* </p>
*
* @author Automatic Generated By Mybatis Plus
* @since 2023-11-02
*/
public interface LabelManager extends IService<LabelDO> {
}
@@ -0,0 +1,20 @@
package io.github.pnoker.center.manager.manager.impl;
import io.github.pnoker.center.manager.entity.model.LabelDO;
import io.github.pnoker.center.manager.mapper.LabelMapper;
import io.github.pnoker.center.manager.manager.LabelManager;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* <p>
* 标签表 服务实现类
* </p>
*
* @author Automatic Generated By Mybatis Plus
* @since 2023-11-02
*/
@Service
public class LabelManagerImpl extends ServiceImpl<LabelMapper, LabelDO> implements LabelManager {
}
@@ -1,31 +1,16 @@
/*
* Copyright 2016-present the IoT DC3 original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.pnoker.center.manager.mapper;
import io.github.pnoker.center.manager.entity.model.LabelDO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.github.pnoker.common.model.Label;
import org.apache.ibatis.annotations.Mapper;
/**
* Mapper
* <p>
* 标签表 Mapper 接口
* </p>
*
* @author pnoker
* @since 2022.1.0
* @author Automatic Generated By Mybatis Plus
* @since 2023-11-02
*/
@Mapper
public interface LabelMapper extends BaseMapper<Label> {
public interface LabelMapper extends BaseMapper<LabelDO> {
}
@@ -16,9 +16,9 @@
package io.github.pnoker.center.manager.service;
import io.github.pnoker.center.manager.entity.model.LabelDO;
import io.github.pnoker.center.manager.entity.query.LabelPageQuery;
import io.github.pnoker.common.base.Service;
import io.github.pnoker.common.model.Label;
/**
* Label Interface
@@ -26,7 +26,7 @@ import io.github.pnoker.common.model.Label;
* @author pnoker
* @since 2022.1.0
*/
public interface LabelService extends Service<Label, LabelPageQuery> {
public interface LabelService extends Service<LabelDO, LabelPageQuery> {
/**
* 根据标签 NAME 查询
*
@@ -34,5 +34,5 @@ public interface LabelService extends Service<Label, LabelPageQuery> {
* @param tenantId 租户ID
* @return Label
*/
Label selectByName(String name, String tenantId);
LabelDO selectByName(String name, Long tenantId);
}
@@ -16,24 +16,25 @@
package io.github.pnoker.center.manager.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.pnoker.center.manager.entity.query.LabelBindPageQuery;
import io.github.pnoker.center.manager.entity.model.LabelBindDO;
import io.github.pnoker.center.manager.entity.model.LabelDO;
import io.github.pnoker.center.manager.entity.query.LabelPageQuery;
import io.github.pnoker.center.manager.mapper.LabelMapper;
import io.github.pnoker.center.manager.service.LabelBindService;
import io.github.pnoker.center.manager.manager.LabelBindManager;
import io.github.pnoker.center.manager.manager.LabelManager;
import io.github.pnoker.center.manager.service.LabelService;
import io.github.pnoker.common.entity.common.Pages;
import io.github.pnoker.common.exception.*;
import io.github.pnoker.common.model.Label;
import io.github.pnoker.common.model.LabelBind;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* LabelService Impl
@@ -46,18 +47,18 @@ import javax.annotation.Resource;
public class LabelServiceImpl implements LabelService {
@Resource
private LabelMapper labelMapper;
private LabelManager labelManager;
@Resource
private LabelBindService labelBindService;
private LabelBindManager labelBindManager;
/**
* {@inheritDoc}
*/
@Override
public void add(Label entityDO) {
public void add(LabelDO entityDO) {
selectByName(entityDO.getLabelName(), entityDO.getTenantId());
if (labelMapper.insert(entityDO) < 1) {
if (!labelManager.save(entityDO)) {
throw new AddException("The label {} add failed", entityDO.getLabelName());
}
}
@@ -66,19 +67,19 @@ public class LabelServiceImpl implements LabelService {
* {@inheritDoc}
*/
@Override
public void delete(String id) {
LabelBindPageQuery labelBindPageQuery = new LabelBindPageQuery();
labelBindPageQuery.setLabelId(id);
Page<LabelBind> labelBindPage = labelBindService.list(labelBindPageQuery);
if (labelBindPage.getTotal() > 0) {
public void delete(Long id) {
LambdaQueryWrapper<LabelBindDO> queryWrapper = Wrappers.<LabelBindDO>query().lambda();
queryWrapper.eq(LabelBindDO::getLabelId, id);
List<LabelBindDO> labelBindPage = labelBindManager.list(queryWrapper);
if (CollUtil.isNotEmpty(labelBindPage)) {
throw new ServiceException("The label already bound by the entity");
}
Label label = selectById(id);
LabelDO label = selectById(id);
if (ObjectUtil.isNull(label)) {
throw new NotFoundException("The label does not exist");
}
if (labelMapper.deleteById(id) < 1) {
if (!labelManager.removeById(id)) {
throw new DeleteException("The label delete failed");
}
}
@@ -87,10 +88,10 @@ public class LabelServiceImpl implements LabelService {
* {@inheritDoc}
*/
@Override
public void update(Label entityDO) {
public void update(LabelDO entityDO) {
selectById(entityDO.getId());
entityDO.setOperateTime(null);
if (labelMapper.updateById(entityDO) < 1) {
if (!labelManager.updateById(entityDO)) {
throw new UpdateException("The label update failed");
}
}
@@ -99,8 +100,8 @@ public class LabelServiceImpl implements LabelService {
* {@inheritDoc}
*/
@Override
public Label selectById(String id) {
Label label = labelMapper.selectById(id);
public LabelDO selectById(Long id) {
LabelDO label = labelManager.getById(id);
if (ObjectUtil.isNull(label)) {
throw new NotFoundException();
}
@@ -111,12 +112,12 @@ public class LabelServiceImpl implements LabelService {
* {@inheritDoc}
*/
@Override
public Label selectByName(String name, String tenantId) {
LambdaQueryWrapper<Label> queryWrapper = Wrappers.<Label>query().lambda();
queryWrapper.eq(Label::getLabelName, name);
queryWrapper.eq(Label::getTenantId, tenantId);
public LabelDO selectByName(String name, Long tenantId) {
LambdaQueryWrapper<LabelDO> queryWrapper = Wrappers.<LabelDO>query().lambda();
queryWrapper.eq(LabelDO::getLabelName, name);
queryWrapper.eq(LabelDO::getTenantId, tenantId);
queryWrapper.last("limit 1");
Label label = labelMapper.selectOne(queryWrapper);
LabelDO label = labelManager.getOne(queryWrapper);
if (ObjectUtil.isNull(label)) {
throw new NotFoundException();
}
@@ -127,19 +128,19 @@ public class LabelServiceImpl implements LabelService {
* {@inheritDoc}
*/
@Override
public Page<Label> list(LabelPageQuery queryDTO) {
public Page<LabelDO> list(LabelPageQuery queryDTO) {
if (ObjectUtil.isNull(queryDTO.getPage())) {
queryDTO.setPage(new Pages());
}
return labelMapper.selectPage(queryDTO.getPage().convert(), fuzzyQuery(queryDTO));
return labelManager.page(queryDTO.getPage().convert(), fuzzyQuery(queryDTO));
}
private LambdaQueryWrapper<Label> fuzzyQuery(LabelPageQuery query) {
LambdaQueryWrapper<Label> queryWrapper = Wrappers.<Label>query().lambda();
private LambdaQueryWrapper<LabelDO> fuzzyQuery(LabelPageQuery query) {
LambdaQueryWrapper<LabelDO> queryWrapper = Wrappers.<LabelDO>query().lambda();
if (ObjectUtil.isNotNull(query)) {
queryWrapper.like(CharSequenceUtil.isNotEmpty(query.getLabelName()), Label::getLabelName, query.getLabelName());
queryWrapper.eq(CharSequenceUtil.isNotEmpty(query.getColor()), Label::getColor, query.getColor());
queryWrapper.eq(CharSequenceUtil.isNotEmpty(query.getTenantId()), Label::getTenantId, query.getTenantId());
queryWrapper.like(CharSequenceUtil.isNotEmpty(query.getLabelName()), LabelDO::getLabelName, query.getLabelName());
queryWrapper.eq(CharSequenceUtil.isNotEmpty(query.getColor()), LabelDO::getColor, query.getColor());
queryWrapper.eq(CharSequenceUtil.isNotEmpty(query.getTenantId()), LabelDO::getTenantId, query.getTenantId());
}
return queryWrapper;
}
@@ -0,0 +1,28 @@
<?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="io.github.pnoker.center.manager.mapper.LabelMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="io.github.pnoker.center.manager.entity.model.LabelDO">
<id column="id" property="id" />
<result column="label_name" property="labelName" />
<result column="color" property="color" />
<result column="entity_type_flag" property="entityTypeFlag" />
<result column="enable_flag" property="enableFlag" />
<result column="tenant_id" property="tenantId" />
<result column="remark" property="remark" />
<result column="creator_id" property="creatorId" />
<result column="creator_name" property="creatorName" />
<result column="create_time" property="createTime" />
<result column="operator_id" property="operatorId" />
<result column="operator_name" property="operatorName" />
<result column="operate_time" property="operateTime" />
<result column="deleted" property="deleted" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, label_name, color, entity_type_flag, enable_flag, tenant_id, remark, creator_id, creator_name, create_time, operator_id, operator_name, operate_time, deleted
</sql>
</mapper>