字典管理
This commit is contained in:
parent
f66fe430f6
commit
682d012bed
@ -0,0 +1,84 @@
|
||||
package com.cdzy.staff.controller;
|
||||
|
||||
import com.cdzy.common.model.request.PageParam;
|
||||
import com.cdzy.common.model.response.JsonResult;
|
||||
import com.cdzy.staff.model.entity.EbikeDic;
|
||||
import com.cdzy.staff.model.vo.EbikeDicVo;
|
||||
import com.cdzy.staff.service.EbikeDicService;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import static com.cdzy.staff.model.entity.table.EbikeDicTableDef.EBIKE_DIC;
|
||||
|
||||
/**
|
||||
* 字典表控制层。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-09-09
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/ebikeDic")
|
||||
public class EbikeDicController {
|
||||
|
||||
@Resource
|
||||
private EbikeDicService ebikeDicService;
|
||||
|
||||
/**
|
||||
* 添加。
|
||||
*
|
||||
* @param ebikeDic 字典
|
||||
* @return {@code 200} 添加成功,{@code 500} 添加失败
|
||||
*/
|
||||
@PostMapping("save")
|
||||
public JsonResult<?> save(@Validated @RequestBody EbikeDicVo ebikeDic) {
|
||||
ebikeDicService.saveDic(ebikeDic);
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据主键删除。
|
||||
*
|
||||
* @param dicId 字典主键
|
||||
* @return {@code 200} 删除成功,{@code 500} 删除失败
|
||||
*/
|
||||
@GetMapping("remove")
|
||||
public JsonResult<?> remove(@NotNull(message = "字典ID不能为空") Long dicId) {
|
||||
ebikeDicService.removeById(dicId);
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据主键更新。
|
||||
*
|
||||
* @param ebikeDic 字典
|
||||
* @return {@code 200} 更新成功,{@code 500} 更新失败
|
||||
*/
|
||||
@PostMapping("update")
|
||||
public JsonResult<?> update(@Validated @RequestBody EbikeDicVo ebikeDic) {
|
||||
ebikeDicService.updateDic(ebikeDic);
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param pageParam 分页参数
|
||||
* @param dicName 字典名
|
||||
* @param dicCode 字典编码
|
||||
* @return 分页
|
||||
*/
|
||||
@GetMapping("page")
|
||||
public JsonResult<?> page(PageParam pageParam,String dicName,String dicCode) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.where(EBIKE_DIC.DIC_NAME.like(dicName, StringUtil.hasText(dicName)))
|
||||
.where(EBIKE_DIC.DIC_CODE.like(dicCode, StringUtil.hasText(dicCode)));
|
||||
Page<EbikeDic> page = ebikeDicService.page(pageParam.getPage(),queryWrapper);
|
||||
return JsonResult.success(page);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,88 @@
|
||||
package com.cdzy.staff.controller;
|
||||
|
||||
import com.cdzy.common.model.request.PageParam;
|
||||
import com.cdzy.common.model.response.JsonResult;
|
||||
import com.cdzy.staff.model.entity.EbikeDicValue;
|
||||
import com.cdzy.staff.service.EbikeDicValueService;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典值表控制层。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-09-09
|
||||
*/
|
||||
@Validated
|
||||
@RestController
|
||||
@RequestMapping("/ebikeDicValue")
|
||||
public class EbikeDicValueController {
|
||||
|
||||
@Resource
|
||||
private EbikeDicValueService ebikeDicValueService;
|
||||
|
||||
/**
|
||||
* 添加。
|
||||
*
|
||||
* @param ebikeDicValue 字典值
|
||||
* @return {@code true} 添加成功,{@code false} 添加失败
|
||||
*/
|
||||
@PostMapping("save")
|
||||
public JsonResult<?> save(@Validated @RequestBody EbikeDicValue ebikeDicValue) {
|
||||
ebikeDicValueService.save(ebikeDicValue);
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据主键删除。
|
||||
*
|
||||
* @param dicValueId 主键
|
||||
* @return {@code true} 删除成功,{@code false} 删除失败
|
||||
*/
|
||||
@GetMapping("remove")
|
||||
public JsonResult<?> remove(@NotNull(message = "字典值ID不能为空") Long dicValueId) {
|
||||
ebikeDicValueService.removeById(dicValueId);
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据主键更新。
|
||||
*
|
||||
* @param ebikeDicValue 字典值
|
||||
* @return {@code true} 更新成功,{@code false} 更新失败
|
||||
*/
|
||||
@PostMapping("update")
|
||||
public JsonResult<?> update(@Validated @RequestBody EbikeDicValue ebikeDicValue) {
|
||||
ebikeDicValueService.updateById(ebikeDicValue);
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典编码查询字典值列表
|
||||
* @param dicCode 字典编码
|
||||
* @return 列表
|
||||
*/
|
||||
@GetMapping("list")
|
||||
public JsonResult<?> list(@NotNull(message = "字典编码不能为空") String dicCode) {
|
||||
List<EbikeDicValue> list = ebikeDicValueService.listByDicCode(dicCode);
|
||||
return JsonResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param pageParam 分页参数
|
||||
* @param dicCode 字典编码
|
||||
* @return 分页结果
|
||||
*/
|
||||
@GetMapping("page")
|
||||
public JsonResult<?> page(PageParam pageParam,@NotNull(message = "字典编码不能为空") String dicCode) {
|
||||
Page<EbikeDicValue> page = ebikeDicValueService.pageDicValue(pageParam,dicCode);
|
||||
return JsonResult.success(page);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package com.cdzy.staff.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.cdzy.staff.model.entity.EbikeDic;
|
||||
|
||||
/**
|
||||
* 映射层。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-09-09
|
||||
*/
|
||||
public interface EbikeDicMapper extends BaseMapper<EbikeDic> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package com.cdzy.staff.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.cdzy.staff.model.entity.EbikeDicValue;
|
||||
|
||||
/**
|
||||
* 映射层。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-09-09
|
||||
*/
|
||||
public interface EbikeDicValueMapper extends BaseMapper<EbikeDicValue> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
package com.cdzy.staff.model.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 实体类。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-09-09
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table("ebike_dic")
|
||||
public class EbikeDic implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@Id
|
||||
private Long dicId;
|
||||
|
||||
/**
|
||||
* 字典名称
|
||||
*/
|
||||
private String dicName;
|
||||
|
||||
/**
|
||||
* 字典编码
|
||||
*/
|
||||
private String dicCode;
|
||||
|
||||
private Long createBy;
|
||||
|
||||
@Column(onInsertValue = "now()")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
private Long updateBy;
|
||||
|
||||
@Column(onUpdateValue = "now()")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@Column(isLogicDelete = true)
|
||||
private Boolean isDeleted;
|
||||
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
package com.cdzy.staff.model.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import java.io.Serializable;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 实体类。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-09-09
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table("ebike_dic_value")
|
||||
public class EbikeDicValue implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
private Long dicValueId;
|
||||
|
||||
/**
|
||||
* 字典值名称
|
||||
*/
|
||||
@NotBlank(message = "字典值名称不能为空")
|
||||
private String dicValueName;
|
||||
|
||||
/**
|
||||
* 字典值
|
||||
*/
|
||||
@NotBlank(message = "字典值不能为空")
|
||||
private String dicValue;
|
||||
|
||||
/**
|
||||
* 字典id
|
||||
*/
|
||||
@NotNull(message = "字典id不能为空")
|
||||
private Long dicId;
|
||||
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package com.cdzy.staff.model.vo;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author attiya
|
||||
* @since 2025-09-09
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class EbikeDicVo {
|
||||
|
||||
private Long dicId;
|
||||
|
||||
/**
|
||||
* 字典名称
|
||||
*/
|
||||
@NotBlank(message = "字典名称不能为空")
|
||||
private String dicName;
|
||||
|
||||
/**
|
||||
* 字典编码
|
||||
*/
|
||||
@NotBlank(message = "字典编码不能为空")
|
||||
private String dicCode;
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package com.cdzy.staff.service;
|
||||
|
||||
import com.cdzy.staff.model.vo.EbikeDicVo;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.cdzy.staff.model.entity.EbikeDic;
|
||||
|
||||
/**
|
||||
* 服务层。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-09-09
|
||||
*/
|
||||
public interface EbikeDicService extends IService<EbikeDic> {
|
||||
|
||||
void saveDic(EbikeDicVo ebikeDic);
|
||||
|
||||
void updateDic(EbikeDicVo ebikeDic);
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package com.cdzy.staff.service;
|
||||
|
||||
import com.cdzy.common.model.request.PageParam;
|
||||
import com.cdzy.staff.model.entity.EbikeDicValue;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务层。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-09-09
|
||||
*/
|
||||
public interface EbikeDicValueService extends IService<EbikeDicValue> {
|
||||
|
||||
List<EbikeDicValue> listByDicCode(String dicCode);
|
||||
|
||||
Page<EbikeDicValue> pageDicValue(PageParam pageParam,String dicCode);
|
||||
}
|
||||
@ -0,0 +1,62 @@
|
||||
package com.cdzy.staff.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.cdzy.common.ex.EbikeException;
|
||||
import com.cdzy.staff.model.vo.EbikeDicVo;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.cdzy.staff.model.entity.EbikeDic;
|
||||
import com.cdzy.staff.mapper.EbikeDicMapper;
|
||||
import com.cdzy.staff.service.EbikeDicService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import static com.cdzy.staff.model.entity.table.EbikeDicTableDef.EBIKE_DIC;
|
||||
|
||||
/**
|
||||
* 服务层实现。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-09-09
|
||||
*/
|
||||
@Service
|
||||
public class EbikeDicServiceImpl extends ServiceImpl<EbikeDicMapper, EbikeDic> implements EbikeDicService {
|
||||
|
||||
@Resource
|
||||
private EbikeDicMapper ebikeDicMapper;
|
||||
|
||||
@Override
|
||||
public void saveDic(EbikeDicVo ebikeDic) {
|
||||
checkCode(ebikeDic.getDicCode());
|
||||
EbikeDic dic = EbikeDic.builder()
|
||||
.dicName(ebikeDic.getDicName())
|
||||
.dicCode(ebikeDic.getDicCode())
|
||||
.createBy(StpUtil.getLoginIdAsLong())
|
||||
.build();
|
||||
ebikeDicMapper.insert(dic);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateDic(EbikeDicVo ebikeDic) {
|
||||
EbikeDic dic = ebikeDicMapper.selectOneById(ebikeDic.getDicId());
|
||||
if (dic == null) {
|
||||
throw new EbikeException("该字典不存在");
|
||||
} else {
|
||||
checkCode(ebikeDic.getDicCode());
|
||||
dic.setDicName(ebikeDic.getDicName());
|
||||
dic.setDicCode(ebikeDic.getDicCode());
|
||||
dic.setUpdateBy(StpUtil.getLoginIdAsLong());
|
||||
ebikeDicMapper.update(dic);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkCode(String dicCode) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.where(EBIKE_DIC.DIC_CODE.eq(dicCode));
|
||||
EbikeDic one = ebikeDicMapper.selectOneByQuery(queryWrapper);
|
||||
if (one != null) {
|
||||
throw new EbikeException("该字典编码已被占用");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
package com.cdzy.staff.service.impl;
|
||||
|
||||
import com.cdzy.common.model.request.PageParam;
|
||||
import com.cdzy.staff.mapper.EbikeDicValueMapper;
|
||||
import com.cdzy.staff.model.entity.EbikeDicValue;
|
||||
import com.cdzy.staff.service.EbikeDicValueService;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.cdzy.staff.model.entity.table.EbikeDicTableDef.EBIKE_DIC;
|
||||
import static com.cdzy.staff.model.entity.table.EbikeDicValueTableDef.EBIKE_DIC_VALUE;
|
||||
|
||||
/**
|
||||
* 服务层实现。
|
||||
*
|
||||
* @author attiya
|
||||
* @since 2025-09-09
|
||||
*/
|
||||
@Service
|
||||
public class EbikeDicValueServiceImpl extends ServiceImpl<EbikeDicValueMapper, EbikeDicValue> implements EbikeDicValueService{
|
||||
|
||||
@Resource
|
||||
private EbikeDicValueMapper ebikeDicValueMapper;
|
||||
|
||||
@Override
|
||||
public List<EbikeDicValue> listByDicCode(String dicCode) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.leftJoin(EBIKE_DIC).on(EBIKE_DIC.DIC_ID.eq(EBIKE_DIC_VALUE.DIC_ID))
|
||||
.where(EBIKE_DIC.DIC_CODE.eq(dicCode));
|
||||
return ebikeDicValueMapper.selectListByQuery(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<EbikeDicValue> pageDicValue(PageParam pageParam, String dicCode) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.leftJoin(EBIKE_DIC).on(EBIKE_DIC.DIC_ID.eq(EBIKE_DIC_VALUE.DIC_ID))
|
||||
.where(EBIKE_DIC.DIC_CODE.eq(dicCode));
|
||||
return ebikeDicValueMapper.paginate(pageParam.getPage(),queryWrapper);
|
||||
}
|
||||
}
|
||||
@ -13,7 +13,7 @@ class EbikeStaffApplicationTests {
|
||||
private static final String mapperPath="D:/ebike_plus/ebike-staff/resources/mapper";
|
||||
private static final String packageName ="com.cdzy.staff";
|
||||
private static final String[] tables= new String[]{
|
||||
"ebike_permission"
|
||||
"ebike_dic","ebike_dic_value"
|
||||
};
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user