dev:培训类型信息

main
SondonYong 2025-11-26 17:02:54 +08:00
parent 3fff4c7563
commit 28e7a192bf
13 changed files with 122 additions and 16 deletions

View File

@ -2,10 +2,7 @@ package com.zcloud.edu.web;
import com.zcloud.edu.api.TrainingTypeServiceI; import com.zcloud.edu.api.TrainingTypeServiceI;
import com.zcloud.edu.dto.TrainingTypeAddCmd; import com.zcloud.edu.dto.*;
import com.zcloud.edu.dto.TrainingTypePageQry;
import com.zcloud.edu.dto.TrainingTypeUpdateCmd;
import com.zcloud.edu.dto.TrainingTypeRemoveCmd;
import com.alibaba.cola.dto.MultiResponse; import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.PageResponse; import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.Response; import com.alibaba.cola.dto.Response;
@ -53,8 +50,8 @@ public class TrainingTypeController {
@ApiOperation("所有数据") @ApiOperation("所有数据")
@PostMapping("/listAll") @PostMapping("/listAll")
public MultiResponse<TrainingTypeCO> listAll() { public MultiResponse<TrainingTypeCO> listAll(@RequestBody TrainingTypeListQry qry) {
return MultiResponse.of(new ArrayList<TrainingTypeCO>()); return trainingTypeService.list(qry);
} }
@ApiOperation("详情") @ApiOperation("详情")

View File

@ -4,12 +4,14 @@ import com.zcloud.edu.domain.gateway.TrainingTypeGateway;
import com.zcloud.edu.domain.model.TrainingTypeE; import com.zcloud.edu.domain.model.TrainingTypeE;
import com.zcloud.edu.dto.TrainingTypeAddCmd; import com.zcloud.edu.dto.TrainingTypeAddCmd;
import com.alibaba.cola.exception.BizException; import com.alibaba.cola.exception.BizException;
import com.zcloud.edu.persistence.dataobject.TrainingTypeDO;
import com.zcloud.edu.persistence.repository.TrainingTypeRepository;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/** /**
@ -21,10 +23,15 @@ import org.springframework.transaction.annotation.Transactional;
@AllArgsConstructor @AllArgsConstructor
public class TrainingTypeAddExe { public class TrainingTypeAddExe {
private final TrainingTypeGateway trainingTypeGateway; private final TrainingTypeGateway trainingTypeGateway;
private final TrainingTypeRepository trainingTypeRepository;
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean execute(TrainingTypeAddCmd cmd) { public boolean execute(TrainingTypeAddCmd cmd) {
TrainingTypeE trainingTypeE = new TrainingTypeE(); TrainingTypeE trainingTypeE = new TrainingTypeE();
List<TrainingTypeDO> trainingTypeDOS = trainingTypeRepository.listByName(cmd.getName());
trainingTypeE.checkList(trainingTypeDOS == null ? 0 : trainingTypeDOS.size());
BeanUtils.copyProperties(cmd, trainingTypeE); BeanUtils.copyProperties(cmd, trainingTypeE);
boolean res = false; boolean res = false;
try { try {

View File

@ -21,6 +21,8 @@ public class TrainingTypeRemoveExe {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean execute(Long id) { public boolean execute(Long id) {
// todo 校验是否有其他业务调用
boolean res = trainingTypeGateway.deletedTrainingTypeById(id); boolean res = trainingTypeGateway.deletedTrainingTypeById(id);
if(!res){ if(!res){
throw new BizException("删除失败"); throw new BizException("删除失败");
@ -30,6 +32,8 @@ public class TrainingTypeRemoveExe {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean execute(Long[] ids) { public boolean execute(Long[] ids) {
// todo 校验是否有其他业务调用
boolean res = trainingTypeGateway.deletedTrainingTypeByIds(ids); boolean res = trainingTypeGateway.deletedTrainingTypeByIds(ids);
if(!res){ if(!res){
throw new BizException("删除失败"); throw new BizException("删除失败");

View File

@ -4,12 +4,14 @@ import com.alibaba.cola.exception.BizException;
import com.zcloud.edu.domain.gateway.TrainingTypeGateway; import com.zcloud.edu.domain.gateway.TrainingTypeGateway;
import com.zcloud.edu.domain.model.TrainingTypeE; import com.zcloud.edu.domain.model.TrainingTypeE;
import com.zcloud.edu.dto.TrainingTypeUpdateCmd; import com.zcloud.edu.dto.TrainingTypeUpdateCmd;
import com.zcloud.edu.persistence.dataobject.TrainingTypeDO;
import com.zcloud.edu.persistence.repository.TrainingTypeRepository;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/** /**
@ -21,10 +23,15 @@ import org.springframework.transaction.annotation.Transactional;
@AllArgsConstructor @AllArgsConstructor
public class TrainingTypeUpdateExe { public class TrainingTypeUpdateExe {
private final TrainingTypeGateway trainingTypeGateway; private final TrainingTypeGateway trainingTypeGateway;
private final TrainingTypeRepository trainingTypeRepository;
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void execute(TrainingTypeUpdateCmd cmd) { public void execute(TrainingTypeUpdateCmd cmd) {
TrainingTypeE trainingTypeE = new TrainingTypeE(); TrainingTypeE trainingTypeE = new TrainingTypeE();
List<TrainingTypeDO> trainingTypeDOS = trainingTypeRepository.listByNameAndId(cmd.getName(), cmd.getId());
trainingTypeE.checkList(trainingTypeDOS == null ? 0 : trainingTypeDOS.size());
BeanUtils.copyProperties(cmd, trainingTypeE); BeanUtils.copyProperties(cmd, trainingTypeE);
boolean res = trainingTypeGateway.update(trainingTypeE); boolean res = trainingTypeGateway.update(trainingTypeE);
if (!res) { if (!res) {

View File

@ -1,6 +1,8 @@
package com.zcloud.edu.command.query; package com.zcloud.edu.command.query;
import com.alibaba.cola.dto.MultiResponse;
import com.zcloud.edu.command.convertor.TrainingTypeCoConvertor; import com.zcloud.edu.command.convertor.TrainingTypeCoConvertor;
import com.zcloud.edu.dto.TrainingTypeListQry;
import com.zcloud.edu.dto.TrainingTypePageQry; import com.zcloud.edu.dto.TrainingTypePageQry;
import com.zcloud.edu.dto.clientobject.TrainingTypeCO; import com.zcloud.edu.dto.clientobject.TrainingTypeCO;
import com.zcloud.edu.persistence.dataobject.TrainingTypeDO; import com.zcloud.edu.persistence.dataobject.TrainingTypeDO;
@ -31,23 +33,27 @@ public class TrainingTypeQueryExe {
/** /**
* *
* *
* @param trainingTypePageQry
* @return * @return
*/ */
public PageResponse<TrainingTypeCO> execute(TrainingTypePageQry trainingTypePageQry) { public PageResponse<TrainingTypeCO> execute(TrainingTypePageQry qry) {
Map<String,Object> params = PageQueryHelper.toHashMap(trainingTypePageQry); Map<String,Object> params = PageQueryHelper.toHashMap(qry);
PageResponse<TrainingTypeDO> pageResponse = trainingTypeRepository.listPage(params); PageResponse<TrainingTypeDO> pageResponse = trainingTypeRepository.listPage(params);
List<TrainingTypeCO> examCenterCOS = trainingTypeCoConvertor.converDOsToCOs(pageResponse.getData()); List<TrainingTypeCO> examCenterCOS = trainingTypeCoConvertor.converDOsToCOs(pageResponse.getData());
return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex()); return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
} }
public MultiResponse<TrainingTypeCO> execute(TrainingTypeListQry qry) {
Map<String,Object> params = PageQueryHelper.toHashMap(qry);
List<TrainingTypeDO> list = trainingTypeRepository.list(params);
List<TrainingTypeCO> examCenterCOS = trainingTypeCoConvertor.converDOsToCOs(list);
return MultiResponse.of(examCenterCOS);
}
public SingleResponse<TrainingTypeCO> execute(Long id) { public SingleResponse<TrainingTypeCO> execute(Long id) {
SingleResponse<TrainingTypeDO> trainingTypeDO = trainingTypeRepository.getInfoById(id); SingleResponse<TrainingTypeDO> trainingTypeDO = trainingTypeRepository.getInfoById(id);
SingleResponse<TrainingTypeCO> trainingTypeCO = new SingleResponse<>();
TrainingTypeCO co = new TrainingTypeCO(); TrainingTypeCO co = new TrainingTypeCO();
BeanUtils.copyProperties(trainingTypeDO.getData(), co); BeanUtils.copyProperties(trainingTypeDO.getData(), co);
trainingTypeCO.setData(co); return SingleResponse.of(co);
return trainingTypeCO;
} }
} }

View File

@ -1,11 +1,13 @@
package com.zcloud.edu.service; package com.zcloud.edu.service;
import com.alibaba.cola.dto.MultiResponse;
import com.zcloud.edu.api.TrainingTypeServiceI; import com.zcloud.edu.api.TrainingTypeServiceI;
import com.zcloud.edu.command.TrainingTypeAddExe; import com.zcloud.edu.command.TrainingTypeAddExe;
import com.zcloud.edu.command.TrainingTypeRemoveExe; import com.zcloud.edu.command.TrainingTypeRemoveExe;
import com.zcloud.edu.command.TrainingTypeUpdateExe; import com.zcloud.edu.command.TrainingTypeUpdateExe;
import com.zcloud.edu.command.query.TrainingTypeQueryExe; import com.zcloud.edu.command.query.TrainingTypeQueryExe;
import com.zcloud.edu.dto.TrainingTypeAddCmd; import com.zcloud.edu.dto.TrainingTypeAddCmd;
import com.zcloud.edu.dto.TrainingTypeListQry;
import com.zcloud.edu.dto.TrainingTypePageQry; import com.zcloud.edu.dto.TrainingTypePageQry;
import com.zcloud.edu.dto.TrainingTypeUpdateCmd; import com.zcloud.edu.dto.TrainingTypeUpdateCmd;
@ -33,6 +35,11 @@ public class TrainingTypeServiceImpl implements TrainingTypeServiceI {
return trainingTypeQueryExe.execute(qry); return trainingTypeQueryExe.execute(qry);
} }
@Override
public MultiResponse<TrainingTypeCO> list(TrainingTypeListQry qry) {
return trainingTypeQueryExe.execute(qry);
}
@Override @Override
public SingleResponse<TrainingTypeCO> getInfoById(Long id){ public SingleResponse<TrainingTypeCO> getInfoById(Long id){
return trainingTypeQueryExe.execute(id); return trainingTypeQueryExe.execute(id);

View File

@ -1,6 +1,8 @@
package com.zcloud.edu.api; package com.zcloud.edu.api;
import com.alibaba.cola.dto.MultiResponse;
import com.zcloud.edu.dto.TrainingTypeAddCmd; import com.zcloud.edu.dto.TrainingTypeAddCmd;
import com.zcloud.edu.dto.TrainingTypeListQry;
import com.zcloud.edu.dto.TrainingTypePageQry; import com.zcloud.edu.dto.TrainingTypePageQry;
import com.zcloud.edu.dto.TrainingTypeUpdateCmd; import com.zcloud.edu.dto.TrainingTypeUpdateCmd;
@ -16,6 +18,8 @@ import com.zcloud.edu.dto.clientobject.TrainingTypeCO;
public interface TrainingTypeServiceI { public interface TrainingTypeServiceI {
PageResponse<TrainingTypeCO> listPage(TrainingTypePageQry qry); PageResponse<TrainingTypeCO> listPage(TrainingTypePageQry qry);
MultiResponse<TrainingTypeCO> list(TrainingTypeListQry qry);
SingleResponse<TrainingTypeCO> getInfoById(Long id); SingleResponse<TrainingTypeCO> getInfoById(Long id);
SingleResponse<TrainingTypeCO> add(TrainingTypeAddCmd cmd); SingleResponse<TrainingTypeCO> add(TrainingTypeAddCmd cmd);

View File

@ -0,0 +1,27 @@
package com.zcloud.edu.dto;
import com.alibaba.cola.dto.PageQuery;
import lombok.Data;
/**
* web-client
* @Author SondonYong
* @Date 2025-11-26 15:04:07
*/
@Data
public class TrainingTypeListQry extends PageQuery {
/**
* ,
* - `like`: SQLLIKE
* - `eq`: SQL=
* - `gt`:
* - `lt`:
* - `ge`:
* - `le`:
* - `ne`: SQL!=
*/
private String likeName;
}

View File

@ -23,6 +23,6 @@ public class TrainingTypePageQry extends PageQuery {
* - `le`: * - `le`:
* - `ne`: SQL!= * - `ne`: SQL!=
*/ */
private String likeTrainingTypeId; private String likeName;
} }

View File

@ -18,15 +18,19 @@ import javax.validation.constraints.*;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class TrainingTypeUpdateCmd extends Command { public class TrainingTypeUpdateCmd extends Command {
@ApiModelProperty(value = "id", name = "id", required = true) @ApiModelProperty(value = "id", name = "id", required = true)
@NotNull(message = "id不能为空") @NotNull(message = "id不能为空")
private Long id; private Long id;
@ApiModelProperty(value = "业务主键id", name = "trainingTypeId", required = true) @ApiModelProperty(value = "业务主键id", name = "trainingTypeId", required = true)
@NotEmpty(message = "业务主键id不能为空") @NotEmpty(message = "业务主键id不能为空")
private String trainingTypeId; private String trainingTypeId;
@ApiModelProperty(value = "名称", name = "name", required = true) @ApiModelProperty(value = "名称", name = "name", required = true)
@NotEmpty(message = "名称不能为空") @NotEmpty(message = "名称不能为空")
private String name; private String name;
@ApiModelProperty(value = "排序", name = "sort", required = true) @ApiModelProperty(value = "排序", name = "sort", required = true)
@NotNull(message = "排序不能为空") @NotNull(message = "排序不能为空")
private Integer sort; private Integer sort;

View File

@ -1,5 +1,6 @@
package com.zcloud.edu.domain.model; package com.zcloud.edu.domain.model;
import com.alibaba.cola.exception.BizException;
import com.jjb.saas.framework.domain.model.BaseE; import com.jjb.saas.framework.domain.model.BaseE;
import lombok.Data; import lombok.Data;
@ -20,5 +21,12 @@ public class TrainingTypeE extends BaseE {
private String name; private String name;
//排序 //排序
private Integer sort; private Integer sort;
public void checkList(int size){
if(size > 0){
throw new BizException("培训类型名称重复。");
}
}
} }

View File

@ -4,6 +4,8 @@ import com.zcloud.edu.persistence.dataobject.TrainingTypeDO;
import com.alibaba.cola.dto.SingleResponse; import com.alibaba.cola.dto.SingleResponse;
import com.alibaba.cola.dto.PageResponse; import com.alibaba.cola.dto.PageResponse;
import com.jjb.saas.framework.repository.repo.BaseRepository; import com.jjb.saas.framework.repository.repo.BaseRepository;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -15,6 +17,12 @@ public interface TrainingTypeRepository extends BaseRepository<TrainingTypeDO> {
PageResponse<TrainingTypeDO> listPage(Map<String,Object> params); PageResponse<TrainingTypeDO> listPage(Map<String,Object> params);
List<TrainingTypeDO> list(Map<String,Object> params);
List<TrainingTypeDO> listByName(String name);
List<TrainingTypeDO> listByNameAndId(String name, Long id);
SingleResponse<TrainingTypeDO> getInfoById(Long id); SingleResponse<TrainingTypeDO> getInfoById(Long id);
} }

View File

@ -13,6 +13,9 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jjb.saas.framework.repository.repo.impl.BaseRepositoryImpl; import com.jjb.saas.framework.repository.repo.impl.BaseRepositoryImpl;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -30,11 +33,35 @@ public class TrainingTypeRepositoryImpl extends BaseRepositoryImpl<TrainingTypeM
IPage<TrainingTypeDO> iPage = new Query<TrainingTypeDO>().getPage(params); IPage<TrainingTypeDO> iPage = new Query<TrainingTypeDO>().getPage(params);
QueryWrapper<TrainingTypeDO> queryWrapper = new QueryWrapper<>(); QueryWrapper<TrainingTypeDO> queryWrapper = new QueryWrapper<>();
queryWrapper = PageQueryHelper.createPageQueryWrapper(queryWrapper, params); queryWrapper = PageQueryHelper.createPageQueryWrapper(queryWrapper, params);
queryWrapper.orderByDesc("create_time"); queryWrapper.orderByAsc("sort");
IPage<TrainingTypeDO> result = trainingTypeMapper.selectPage(iPage, queryWrapper); IPage<TrainingTypeDO> result = trainingTypeMapper.selectPage(iPage, queryWrapper);
return PageHelper.pageToResponse(result, result.getRecords()); return PageHelper.pageToResponse(result, result.getRecords());
} }
@Override
public List<TrainingTypeDO> list(Map<String, Object> params) {
QueryWrapper<TrainingTypeDO> queryWrapper = new QueryWrapper<>();
queryWrapper = PageQueryHelper.createPageQueryWrapper(queryWrapper, params);
queryWrapper.orderByAsc("sort");
List<TrainingTypeDO> trainingTypeDOS = trainingTypeMapper.selectList(queryWrapper);
return trainingTypeDOS;
}
@Override
public List<TrainingTypeDO> listByName(String name) {
QueryWrapper<TrainingTypeDO> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("name", name);
return list(queryWrapper);
}
@Override
public List<TrainingTypeDO> listByNameAndId(String name, Long id) {
QueryWrapper<TrainingTypeDO> queryWrapper = new QueryWrapper<>();
queryWrapper.ne("id", id);
queryWrapper.eq("name", name);
return list(queryWrapper);
}
@Override @Override
public SingleResponse<TrainingTypeDO> getInfoById(Long id) { public SingleResponse<TrainingTypeDO> getInfoById(Long id) {
return SingleResponse.of(trainingTypeMapper.selectById(id)); return SingleResponse.of(trainingTypeMapper.selectById(id));