新增检测项目子表

This commit is contained in:
许允枞 2024-11-07 14:53:07 +08:00
parent 95bb7a285e
commit b2682976d5
11 changed files with 438 additions and 4 deletions

View File

@ -2,10 +2,13 @@ package cn.iocoder.yudao.module.inspection.entity;
import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO;
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 lombok.*;
import java.util.List;
/**
* 检测项目
*
@ -38,4 +41,6 @@ public class DlInspectionProject extends TenantBaseDO {
*/
private String remark;
@TableField(exist = false)
private List<ProjectRoyalty> projectRoyaltyList;
}

View File

@ -0,0 +1,50 @@
package cn.iocoder.yudao.module.inspection.entity;
import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 检测项目子表项目提成 DO
*
* @author 若依
*/
@TableName("inspection_project_royalty")
@KeySequence("inspection_project_royalty_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ProjectRoyalty extends TenantBaseDO {
/**
* 主键
*/
@TableId
private Long id;
/**
* 检测项目主键
*/
private String projectId;
/**
* 商品主键
*/
private Long goodsId;
/**
* 提成金额 单位
*/
private Long royaltyAmount;
/**
* 商品名称
*/
@TableField(exist = false)
private String title;
}

View File

@ -0,0 +1,29 @@
package cn.iocoder.yudao.module.inspection.mapper;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.inspection.entity.ProjectRoyalty;
import cn.iocoder.yudao.module.inspection.vo.ProjectRoyaltyPageReqVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* 检测项目子表项目提成 Mapper
*
* @author 若依
*/
@Mapper
public interface ProjectRoyaltyMapper extends BaseMapper<ProjectRoyalty> {
void insertBatch(@Param("createReq") List<ProjectRoyalty> createReq);
void deleteByProjectId(String projectId);
List<ProjectRoyalty> selectListByProjrctId(String projectId);
void updtaBatch(@Param("list") List<ProjectRoyalty> createReq);
}

View File

@ -0,0 +1,82 @@
package cn.iocoder.yudao.module.inspection.service;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.module.inspection.entity.ProjectRoyalty;
import cn.iocoder.yudao.module.inspection.vo.ProjectRoyaltyPageReqVO;
import cn.iocoder.yudao.module.inspection.vo.ProjectRoyaltySaveReqVO;
/**
* 检测项目子表项目提成 Service 接口
*
* @author 若依
*/
public interface ProjectRoyaltyService {
/**
* 创建检测项目子表项目提成
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createProjectRoyalty(@Valid ProjectRoyaltySaveReqVO createReqVO);
/**
* 批量创建检测项目子表项目提成
*
* @param createReq 创建信息
*/
void batchInsertProjectRoyalty(@Valid List<ProjectRoyalty> createReq);
/**
* 根据项目id删除检测项目子表项目提成
* @param projectId
*/
void deleteInsertProjectRoyalty(String projectId);
/**
* 根据项目id查询检测项目子表项目提成
* @param projectId
* @return
*/
List<ProjectRoyalty> getProjectRoyaltyList(String projectId);
/**
* 批量更新检测项目子表项目提成
* @param createReq
*/
void updtaBatch(List<ProjectRoyalty> createReq);
// /**
// * 更新检测项目子表项目提成
// *
// * @param updateReqVO 更新信息
// */
// void updateProjectRoyalty(@Valid ProjectRoyaltySaveReqVO updateReqVO);
//
// /**
// * 删除检测项目子表项目提成
// *
// * @param id 编号
// */
// void deleteProjectRoyalty(Long id);
//
// /**
// * 获得检测项目子表项目提成
// *
// * @param id 编号
// * @return 检测项目子表项目提成
// */
// ProjectRoyalty getProjectRoyalty(Long id);
//
// /**
// * 获得检测项目子表项目提成分页
// *
// * @param pageReqVO 分页查询
// * @return 检测项目子表项目提成分页
// */
// PageResult<ProjectRoyalty> getProjectRoyaltyPage(ProjectRoyaltyPageReqVO pageReqVO);
}

View File

@ -1,10 +1,14 @@
package cn.iocoder.yudao.module.inspection.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.inspection.entity.DlInspectionProject;
import cn.iocoder.yudao.module.inspection.entity.ProjectRoyalty;
import cn.iocoder.yudao.module.inspection.mapper.DlInspectionProjectMapper;
import cn.iocoder.yudao.module.inspection.mapper.ProjectRoyaltyMapper;
import cn.iocoder.yudao.module.inspection.service.DlInspectionProjectService;
import cn.iocoder.yudao.module.inspection.service.ProjectRoyaltyService;
import cn.iocoder.yudao.module.inspection.vo.DlInspectionProjectPageReqVO;
import cn.iocoder.yudao.module.inspection.vo.DlInspectionProjectRespVO;
import cn.iocoder.yudao.module.inspection.vo.DlInspectionProjectSaveReqVO;
@ -12,9 +16,14 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
import static com.github.yulichang.method.SqlMethod.collect;
/**
@ -29,7 +38,11 @@ public class DlInspectionProjectServiceImpl extends ServiceImpl<DlInspectionProj
@Resource
private DlInspectionProjectMapper dlInspectionProjectMapper;
@Resource
private ProjectRoyaltyService projectRoyaltyService;
@Override
@Transactional(rollbackFor = Exception.class)
public String createDlInspectionProject(DlInspectionProjectSaveReqVO createReqVO) {
//查询项目名称是否存在
DlInspectionProject dlInspectionProject1 = baseMapper.selectOne(new LambdaQueryWrapper<DlInspectionProject>()
@ -41,29 +54,45 @@ public class DlInspectionProjectServiceImpl extends ServiceImpl<DlInspectionProj
DlInspectionProject dlInspectionProject = BeanUtils.toBean(createReqVO, DlInspectionProject.class);
dlInspectionProject.setDeleted(false);
dlInspectionProjectMapper.insert(dlInspectionProject);
//插入项目子表
List<ProjectRoyalty> projectRoyaltyList = createReqVO.getProjectRoyaltyList();
//设置项目id
List<ProjectRoyalty> collect = projectRoyaltyList.stream().map(item -> item.setProjectId(dlInspectionProject.getId())).collect(Collectors.toList());
projectRoyaltyService.batchInsertProjectRoyalty(collect);
// 返回
return dlInspectionProject.getId();
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateDlInspectionProject(DlInspectionProjectSaveReqVO updateReqVO) {
// 更新
DlInspectionProject updateObj = BeanUtils.toBean(updateReqVO, DlInspectionProject.class);
dlInspectionProjectMapper.updateById(updateObj);
// 更新项目子表
List<ProjectRoyalty> projectRoyaltyList = updateReqVO.getProjectRoyaltyList();
projectRoyaltyService.updtaBatch(projectRoyaltyList);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteDlInspectionProject(String id) {
// 删除
dlInspectionProjectMapper.deleteById(id);
//删除项目子表
projectRoyaltyService.deleteInsertProjectRoyalty(id);
}
@Override
public DlInspectionProject getDlInspectionProject(String id) {
return dlInspectionProjectMapper.selectById(id);
DlInspectionProject dlInspectionProject = dlInspectionProjectMapper.selectById(id);
List<ProjectRoyalty> projectRoyaltyList = projectRoyaltyService.getProjectRoyaltyList(id);
dlInspectionProject.setProjectRoyaltyList(projectRoyaltyList);
return dlInspectionProject;
}
@Override

View File

@ -0,0 +1,102 @@
package cn.iocoder.yudao.module.inspection.service.impl;
import cn.iocoder.yudao.module.inspection.entity.ProjectRoyalty;
import cn.iocoder.yudao.module.inspection.mapper.ProjectRoyaltyMapper;
import cn.iocoder.yudao.module.inspection.service.ProjectRoyaltyService;
import cn.iocoder.yudao.module.inspection.vo.ProjectRoyaltySaveReqVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import java.util.List;
/**
* 检测项目子表项目提成 Service 实现类
*
* @author 若依
*/
@Service
@Validated
public class ProjectRoyaltyServiceImpl extends ServiceImpl<ProjectRoyaltyMapper, ProjectRoyalty> implements ProjectRoyaltyService {
@Resource
private ProjectRoyaltyMapper projectRoyaltyMapper;
@Override
public Long createProjectRoyalty(ProjectRoyaltySaveReqVO createReqVO) {
// 插入
ProjectRoyalty projectRoyalty = BeanUtils.toBean(createReqVO, ProjectRoyalty.class);
projectRoyaltyMapper.insert(projectRoyalty);
// 返回
return projectRoyalty.getId();
}
/**
* 批量创建检测项目子表项目提成
*
* @param createReq 创建信息
*/
@Override
public void batchInsertProjectRoyalty(List<ProjectRoyalty> createReq) {
projectRoyaltyMapper.insertBatch(createReq);
}
/**
* 根据项目id删除检测项目子表项目提成
*
* @param projectId
*/
@Override
public void deleteInsertProjectRoyalty(String projectId) {
projectRoyaltyMapper.deleteByProjectId(projectId);
}
/**
* 根据项目id查询检测项目子表项目提成
*
* @param projectId
* @return
*/
@Override
public List<ProjectRoyalty> getProjectRoyaltyList(String projectId) {
return baseMapper.selectListByProjrctId(projectId);
}
/**
* 批量更新检测项目子表项目提成
*
* @param createReq
*/
@Override
public void updtaBatch(List<ProjectRoyalty> createReq) {
projectRoyaltyMapper.updtaBatch(createReq);
}
// @Override
// public void updateProjectRoyalty(ProjectRoyaltySaveReqVO updateReqVO) {
// // 校验存在
// validateProjectRoyaltyExists(updateReqVO.getId());
// // 更新
// ProjectRoyalty updateObj = BeanUtils.toBean(updateReqVO, ProjectRoyalty.class);
// projectRoyaltyMapper.updateById(updateObj);
// }
//
// @Override
// public void deleteProjectRoyalty(Long id) {
// // 校验存在
// validateProjectRoyaltyExists(id);
// // 删除
// projectRoyaltyMapper.deleteById(id);
// }
//
//
// @Override
// public ProjectRoyalty getProjectRoyalty(Long id) {
// return projectRoyaltyMapper.selectById(id);
// }
}

View File

@ -1,13 +1,18 @@
package cn.iocoder.yudao.module.inspection.vo;
import cn.iocoder.yudao.module.inspection.entity.DlInspectionProject;
import cn.iocoder.yudao.module.inspection.entity.ProjectRoyalty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Schema(description = "管理后台 - 检测项目新增/修改 Request VO")
@Data
public class DlInspectionProjectSaveReqVO extends DlInspectionProject {
/**
* 项目提成
*/
private List<ProjectRoyalty> projectRoyaltyList;
}

View File

@ -0,0 +1,31 @@
package cn.iocoder.yudao.module.inspection.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 检测项目子表(项目提成)分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProjectRoyaltyPageReqVO extends PageParam {
@Schema(description = "检测项目主键", example = "21579")
private String projectId;
@Schema(description = "商品主键", example = "3154")
private Long goodsId;
@Schema(description = "提成金额 单位:分")
private Long royaltyAmount;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -0,0 +1,35 @@
package cn.iocoder.yudao.module.inspection.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
@Schema(description = "管理后台 - 检测项目子表(项目提成) Response VO")
@Data
@ExcelIgnoreUnannotated
public class ProjectRoyaltyRespVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "18948")
@ExcelProperty("主键")
private Long id;
@Schema(description = "检测项目主键", example = "21579")
@ExcelProperty("检测项目主键")
private String projectId;
@Schema(description = "商品主键", example = "3154")
@ExcelProperty("商品主键")
private Long goodsId;
@Schema(description = "提成金额 单位:分")
@ExcelProperty("提成金额 单位:分")
private Long royaltyAmount;
@Schema(description = "创建时间")
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -0,0 +1,24 @@
package cn.iocoder.yudao.module.inspection.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 检测项目子表(项目提成)新增/修改 Request VO")
@Data
public class ProjectRoyaltySaveReqVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "18948")
private Long id;
@Schema(description = "检测项目主键", example = "21579")
private String projectId;
@Schema(description = "商品主键", example = "3154")
private Long goodsId;
@Schema(description = "提成金额 单位:分")
private Long royaltyAmount;
}

View File

@ -0,0 +1,42 @@
<?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="cn.iocoder.yudao.module.inspection.mapper.ProjectRoyaltyMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
<insert id="insertBatch">
INSERT INTO inspection_project_royalty (project_id, goods_id, royalty_amount, deleted, create_time) VALUES
<foreach collection="createReq" item="item" separator=",">
(#{item.projectId},#{item.goodsId},#{item.royaltyAmount},0, NOW())
</foreach>
</insert>
<update id="updtaBatch">
UPDATE inspection_project_royalty
SET royalty_amount =
CASE
<foreach collection="list" item="item" index="index">
WHEN id = #{item.id} THEN #{item.royaltyAmount}
</foreach>
ELSE royalty_amount
END
WHERE id IN
<foreach collection="list" item="item" open="(" separator="," close=")">
#{item.id}
</foreach>
</update>
<delete id="deleteByProjectId" parameterType="java.lang.String">
UPDATE inspection_project_royalty SET deleted = 1 WHERE project_id = #{projectId}
</delete>
<select id="selectListByProjrctId" resultType="cn.iocoder.yudao.module.inspection.entity.ProjectRoyalty"
parameterType="java.lang.String">
SELECT ir.royalty_amount / 100 royaltyAmount, goods.title title, ir.id id, goods.id goodsId
FROM inspection_project_royalty ir
LEFT JOIN shop_inspection_goods goods ON goods.id = ir.goods_id
WHERE ir.project_id = #{projectId}
</select>
</mapper>