add feeding record
parent
eecdbf01b3
commit
1b2ad66e16
@ -0,0 +1,95 @@
|
|||||||
|
package cn.iocoder.yudao.module.mes.controller.admin.feedingplan;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||||
|
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.mes.controller.admin.feedingplan.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.mes.dal.dataobject.feedingplan.FeedingRecordPlanDO;
|
||||||
|
import cn.iocoder.yudao.module.mes.service.feedingplan.FeedingRecordPlanService;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
@Tag(name = "管理后台 - 投料分配计划")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/mes/feeding-record-plan")
|
||||||
|
@Validated
|
||||||
|
public class FeedingRecordPlanController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private FeedingRecordPlanService feedingRecordPlanService;
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
@Operation(summary = "创建投料分配计划")
|
||||||
|
@PreAuthorize("@ss.hasPermission('mes:feeding-record-plan:create')")
|
||||||
|
public CommonResult<Long> createFeedingRecordPlan(@Valid @RequestBody FeedingRecordPlanSaveReqVO createReqVO) {
|
||||||
|
return success(feedingRecordPlanService.createFeedingRecordPlan(createReqVO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update")
|
||||||
|
@Operation(summary = "更新投料分配计划")
|
||||||
|
@PreAuthorize("@ss.hasPermission('mes:feeding-record-plan:update')")
|
||||||
|
public CommonResult<Boolean> updateFeedingRecordPlan(@Valid @RequestBody FeedingRecordPlanSaveReqVO updateReqVO) {
|
||||||
|
feedingRecordPlanService.updateFeedingRecordPlan(updateReqVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete")
|
||||||
|
@Operation(summary = "删除投料分配计划")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true)
|
||||||
|
@PreAuthorize("@ss.hasPermission('mes:feeding-record-plan:delete')")
|
||||||
|
public CommonResult<Boolean> deleteFeedingRecordPlan(@RequestParam("id") Long id) {
|
||||||
|
feedingRecordPlanService.deleteFeedingRecordPlan(id);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get")
|
||||||
|
@Operation(summary = "获得投料分配计划")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||||
|
@PreAuthorize("@ss.hasPermission('mes:feeding-record-plan:query')")
|
||||||
|
public CommonResult<FeedingRecordPlanRespVO> getFeedingRecordPlan(@RequestParam("id") Long id) {
|
||||||
|
FeedingRecordPlanDO feedingRecordPlan = feedingRecordPlanService.getFeedingRecordPlan(id);
|
||||||
|
return success(BeanUtils.toBean(feedingRecordPlan, FeedingRecordPlanRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/page")
|
||||||
|
@Operation(summary = "获得投料分配计划分页")
|
||||||
|
@PreAuthorize("@ss.hasPermission('mes:feeding-record-plan:query')")
|
||||||
|
public CommonResult<PageResult<FeedingRecordPlanRespVO>> getFeedingRecordPlanPage(@Valid FeedingRecordPlanPageReqVO pageReqVO) {
|
||||||
|
PageResult<FeedingRecordPlanDO> pageResult = feedingRecordPlanService.getFeedingRecordPlanPage(pageReqVO);
|
||||||
|
return success(BeanUtils.toBean(pageResult, FeedingRecordPlanRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/export-excel")
|
||||||
|
@Operation(summary = "导出投料分配计划 Excel")
|
||||||
|
@PreAuthorize("@ss.hasPermission('mes:feeding-record-plan:export')")
|
||||||
|
@ApiAccessLog(operateType = EXPORT)
|
||||||
|
public void exportFeedingRecordPlanExcel(@Valid FeedingRecordPlanPageReqVO pageReqVO,
|
||||||
|
HttpServletResponse response) throws IOException {
|
||||||
|
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||||
|
List<FeedingRecordPlanDO> list = feedingRecordPlanService.getFeedingRecordPlanPage(pageReqVO).getList();
|
||||||
|
// 导出 Excel
|
||||||
|
ExcelUtils.write(response, "投料分配计划.xls", "数据", FeedingRecordPlanRespVO.class,
|
||||||
|
BeanUtils.toBean(list, FeedingRecordPlanRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,48 @@
|
|||||||
|
package cn.iocoder.yudao.module.mes.controller.admin.feedingplan.vo;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
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 FeedingRecordPlanPageReqVO extends PageParam {
|
||||||
|
|
||||||
|
@Schema(description = "记录id", example = "997")
|
||||||
|
private Long recordId;
|
||||||
|
|
||||||
|
@Schema(description = "记录明细id", example = "2395")
|
||||||
|
private Long recordDetailId;
|
||||||
|
|
||||||
|
@Schema(description = "计划id", example = "17658")
|
||||||
|
private Long planId;
|
||||||
|
|
||||||
|
@Schema(description = "原料id", example = "19133")
|
||||||
|
private Long itemId;
|
||||||
|
|
||||||
|
@Schema(description = "重量")
|
||||||
|
private BigDecimal weight;
|
||||||
|
|
||||||
|
@Schema(description = "单位", example = "27598")
|
||||||
|
private Long unitId;
|
||||||
|
|
||||||
|
@Schema(description = "记录人", example = "14853")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@Schema(description = "投料时间")
|
||||||
|
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||||
|
private LocalDateTime[] feedingTime;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间")
|
||||||
|
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||||
|
private LocalDateTime[] createTime;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
package cn.iocoder.yudao.module.mes.controller.admin.feedingplan.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import com.alibaba.excel.annotation.*;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 投料分配计划 Response VO")
|
||||||
|
@Data
|
||||||
|
@ExcelIgnoreUnannotated
|
||||||
|
public class FeedingRecordPlanRespVO {
|
||||||
|
|
||||||
|
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "881")
|
||||||
|
@ExcelProperty("id")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "记录id", example = "997")
|
||||||
|
@ExcelProperty("记录id")
|
||||||
|
private Long recordId;
|
||||||
|
|
||||||
|
@Schema(description = "记录明细id", example = "2395")
|
||||||
|
@ExcelProperty("记录明细id")
|
||||||
|
private Long recordDetailId;
|
||||||
|
|
||||||
|
@Schema(description = "计划id", example = "17658")
|
||||||
|
@ExcelProperty("计划id")
|
||||||
|
private Long planId;
|
||||||
|
|
||||||
|
@Schema(description = "原料id", example = "19133")
|
||||||
|
@ExcelProperty("原料id")
|
||||||
|
private Long itemId;
|
||||||
|
|
||||||
|
@Schema(description = "重量")
|
||||||
|
@ExcelProperty("重量")
|
||||||
|
private BigDecimal weight;
|
||||||
|
|
||||||
|
@Schema(description = "单位", example = "27598")
|
||||||
|
@ExcelProperty("单位")
|
||||||
|
private Long unitId;
|
||||||
|
|
||||||
|
@Schema(description = "记录人", example = "14853")
|
||||||
|
@ExcelProperty("记录人")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@Schema(description = "投料时间")
|
||||||
|
@ExcelProperty("投料时间")
|
||||||
|
private LocalDateTime feedingTime;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("创建时间")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
package cn.iocoder.yudao.module.mes.controller.admin.feedingplan.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.*;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Schema(description = "管理后台 - 投料分配计划新增/修改 Request VO")
|
||||||
|
@Data
|
||||||
|
public class FeedingRecordPlanSaveReqVO {
|
||||||
|
|
||||||
|
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "881")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "记录id", example = "997")
|
||||||
|
private Long recordId;
|
||||||
|
|
||||||
|
@Schema(description = "记录明细id", example = "2395")
|
||||||
|
private Long recordDetailId;
|
||||||
|
|
||||||
|
@Schema(description = "计划id", example = "17658")
|
||||||
|
private Long planId;
|
||||||
|
|
||||||
|
@Schema(description = "原料id", example = "19133")
|
||||||
|
private Long itemId;
|
||||||
|
|
||||||
|
@Schema(description = "重量")
|
||||||
|
private BigDecimal weight;
|
||||||
|
|
||||||
|
@Schema(description = "单位", example = "27598")
|
||||||
|
private Long unitId;
|
||||||
|
|
||||||
|
@Schema(description = "记录人", example = "14853")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
@Schema(description = "投料时间")
|
||||||
|
private LocalDateTime feedingTime;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,65 @@
|
|||||||
|
package cn.iocoder.yudao.module.mes.dal.dataobject.feedingplan;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
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("mes_feeding_record_plan")
|
||||||
|
@KeySequence("mes_feeding_record_plan_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class FeedingRecordPlanDO extends BaseDO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@TableId
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 记录id
|
||||||
|
*/
|
||||||
|
private Long recordId;
|
||||||
|
/**
|
||||||
|
* 记录明细id
|
||||||
|
*/
|
||||||
|
private Long recordDetailId;
|
||||||
|
/**
|
||||||
|
* 计划id
|
||||||
|
*/
|
||||||
|
private Long planId;
|
||||||
|
/**
|
||||||
|
* 原料id
|
||||||
|
*/
|
||||||
|
private Long itemId;
|
||||||
|
/**
|
||||||
|
* 重量
|
||||||
|
*/
|
||||||
|
private BigDecimal weight;
|
||||||
|
/**
|
||||||
|
* 单位
|
||||||
|
*/
|
||||||
|
private Long unitId;
|
||||||
|
/**
|
||||||
|
* 记录人
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
/**
|
||||||
|
* 投料时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime feedingTime;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
package cn.iocoder.yudao.module.mes.dal.dataobject.feedingrecord;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
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("mes_feeding_record_detail")
|
||||||
|
@KeySequence("mes_feeding_record_detail_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class FeedingRecordDetailDO extends BaseDO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@TableId
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 记录id
|
||||||
|
*/
|
||||||
|
private Long recordId;
|
||||||
|
/**
|
||||||
|
* 原料id
|
||||||
|
*/
|
||||||
|
private Long itemId;
|
||||||
|
/**
|
||||||
|
* 重量
|
||||||
|
*/
|
||||||
|
private BigDecimal weight;
|
||||||
|
/**
|
||||||
|
* 单位
|
||||||
|
*/
|
||||||
|
private Long unitId;
|
||||||
|
/**
|
||||||
|
* 记录人
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
/**
|
||||||
|
* 投料时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime feedingTime;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
package cn.iocoder.yudao.module.mes.dal.mysql.feedingplan;
|
||||||
|
|
||||||
|
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.mes.dal.dataobject.feedingplan.FeedingRecordPlanDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import cn.iocoder.yudao.module.mes.controller.admin.feedingplan.vo.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 投料分配计划 Mapper
|
||||||
|
*
|
||||||
|
* @author 内蒙必硕
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface FeedingRecordPlanMapper extends BaseMapperX<FeedingRecordPlanDO> {
|
||||||
|
|
||||||
|
default PageResult<FeedingRecordPlanDO> selectPage(FeedingRecordPlanPageReqVO reqVO) {
|
||||||
|
return selectPage(reqVO, new LambdaQueryWrapperX<FeedingRecordPlanDO>()
|
||||||
|
.eqIfPresent(FeedingRecordPlanDO::getRecordId, reqVO.getRecordId())
|
||||||
|
.eqIfPresent(FeedingRecordPlanDO::getRecordDetailId, reqVO.getRecordDetailId())
|
||||||
|
.eqIfPresent(FeedingRecordPlanDO::getPlanId, reqVO.getPlanId())
|
||||||
|
.eqIfPresent(FeedingRecordPlanDO::getItemId, reqVO.getItemId())
|
||||||
|
.eqIfPresent(FeedingRecordPlanDO::getWeight, reqVO.getWeight())
|
||||||
|
.eqIfPresent(FeedingRecordPlanDO::getUnitId, reqVO.getUnitId())
|
||||||
|
.eqIfPresent(FeedingRecordPlanDO::getUserId, reqVO.getUserId())
|
||||||
|
.betweenIfPresent(FeedingRecordPlanDO::getFeedingTime, reqVO.getFeedingTime())
|
||||||
|
.betweenIfPresent(FeedingRecordPlanDO::getCreateTime, reqVO.getCreateTime())
|
||||||
|
.orderByDesc(FeedingRecordPlanDO::getId));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
package cn.iocoder.yudao.module.mes.dal.mysql.feedingrecord;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import cn.iocoder.yudao.module.mes.dal.dataobject.feedingrecord.FeedingRecordDetailDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 投料记录明细 Mapper
|
||||||
|
*
|
||||||
|
* @author 内蒙必硕
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface FeedingRecordDetailMapper extends BaseMapperX<FeedingRecordDetailDO> {
|
||||||
|
|
||||||
|
default List<FeedingRecordDetailDO> selectListByRecordId(Long recordId) {
|
||||||
|
return selectList(FeedingRecordDetailDO::getRecordId, recordId);
|
||||||
|
}
|
||||||
|
|
||||||
|
default int deleteByRecordId(Long recordId) {
|
||||||
|
return delete(FeedingRecordDetailDO::getRecordId, recordId);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,55 @@
|
|||||||
|
package cn.iocoder.yudao.module.mes.service.feedingplan;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.mes.controller.admin.feedingplan.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.mes.dal.dataobject.feedingplan.FeedingRecordPlanDO;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 投料分配计划 Service 接口
|
||||||
|
*
|
||||||
|
* @author 内蒙必硕
|
||||||
|
*/
|
||||||
|
public interface FeedingRecordPlanService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建投料分配计划
|
||||||
|
*
|
||||||
|
* @param createReqVO 创建信息
|
||||||
|
* @return 编号
|
||||||
|
*/
|
||||||
|
Long createFeedingRecordPlan(@Valid FeedingRecordPlanSaveReqVO createReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新投料分配计划
|
||||||
|
*
|
||||||
|
* @param updateReqVO 更新信息
|
||||||
|
*/
|
||||||
|
void updateFeedingRecordPlan(@Valid FeedingRecordPlanSaveReqVO updateReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除投料分配计划
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
*/
|
||||||
|
void deleteFeedingRecordPlan(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得投料分配计划
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @return 投料分配计划
|
||||||
|
*/
|
||||||
|
FeedingRecordPlanDO getFeedingRecordPlan(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得投料分配计划分页
|
||||||
|
*
|
||||||
|
* @param pageReqVO 分页查询
|
||||||
|
* @return 投料分配计划分页
|
||||||
|
*/
|
||||||
|
PageResult<FeedingRecordPlanDO> getFeedingRecordPlanPage(FeedingRecordPlanPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,75 @@
|
|||||||
|
package cn.iocoder.yudao.module.mes.service.feedingplan;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import cn.iocoder.yudao.module.mes.controller.admin.feedingplan.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.mes.dal.dataobject.feedingplan.FeedingRecordPlanDO;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.mes.dal.mysql.feedingplan.FeedingRecordPlanMapper;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 投料分配计划 Service 实现类
|
||||||
|
*
|
||||||
|
* @author 内蒙必硕
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Validated
|
||||||
|
public class FeedingRecordPlanServiceImpl implements FeedingRecordPlanService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private FeedingRecordPlanMapper feedingRecordPlanMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long createFeedingRecordPlan(FeedingRecordPlanSaveReqVO createReqVO) {
|
||||||
|
// 插入
|
||||||
|
FeedingRecordPlanDO feedingRecordPlan = BeanUtils.toBean(createReqVO, FeedingRecordPlanDO.class);
|
||||||
|
feedingRecordPlanMapper.insert(feedingRecordPlan);
|
||||||
|
// 返回
|
||||||
|
return feedingRecordPlan.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateFeedingRecordPlan(FeedingRecordPlanSaveReqVO updateReqVO) {
|
||||||
|
// 校验存在
|
||||||
|
validateFeedingRecordPlanExists(updateReqVO.getId());
|
||||||
|
// 更新
|
||||||
|
FeedingRecordPlanDO updateObj = BeanUtils.toBean(updateReqVO, FeedingRecordPlanDO.class);
|
||||||
|
feedingRecordPlanMapper.updateById(updateObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteFeedingRecordPlan(Long id) {
|
||||||
|
// 校验存在
|
||||||
|
validateFeedingRecordPlanExists(id);
|
||||||
|
// 删除
|
||||||
|
feedingRecordPlanMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateFeedingRecordPlanExists(Long id) {
|
||||||
|
if (feedingRecordPlanMapper.selectById(id) == null) {
|
||||||
|
throw exception(FEEDING_RECORD_PLAN_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FeedingRecordPlanDO getFeedingRecordPlan(Long id) {
|
||||||
|
return feedingRecordPlanMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<FeedingRecordPlanDO> getFeedingRecordPlanPage(FeedingRecordPlanPageReqVO pageReqVO) {
|
||||||
|
return feedingRecordPlanMapper.selectPage(pageReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,160 @@
|
|||||||
|
package cn.iocoder.yudao.module.mes.service.feedingplan;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.mes.controller.admin.feedingplan.vo.*;
|
||||||
|
import cn.iocoder.yudao.module.mes.dal.dataobject.feedingplan.FeedingRecordPlanDO;
|
||||||
|
import cn.iocoder.yudao.module.mes.dal.mysql.feedingplan.FeedingRecordPlanMapper;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import static cn.hutool.core.util.RandomUtil.*;
|
||||||
|
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
|
||||||
|
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
|
||||||
|
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link FeedingRecordPlanServiceImpl} 的单元测试类
|
||||||
|
*
|
||||||
|
* @author 内蒙必硕
|
||||||
|
*/
|
||||||
|
@Import(FeedingRecordPlanServiceImpl.class)
|
||||||
|
public class FeedingRecordPlanServiceImplTest extends BaseDbUnitTest {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private FeedingRecordPlanServiceImpl feedingRecordPlanService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private FeedingRecordPlanMapper feedingRecordPlanMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateFeedingRecordPlan_success() {
|
||||||
|
// 准备参数
|
||||||
|
FeedingRecordPlanSaveReqVO createReqVO = randomPojo(FeedingRecordPlanSaveReqVO.class).setId(null);
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
Long feedingRecordPlanId = feedingRecordPlanService.createFeedingRecordPlan(createReqVO);
|
||||||
|
// 断言
|
||||||
|
assertNotNull(feedingRecordPlanId);
|
||||||
|
// 校验记录的属性是否正确
|
||||||
|
FeedingRecordPlanDO feedingRecordPlan = feedingRecordPlanMapper.selectById(feedingRecordPlanId);
|
||||||
|
assertPojoEquals(createReqVO, feedingRecordPlan, "id");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateFeedingRecordPlan_success() {
|
||||||
|
// mock 数据
|
||||||
|
FeedingRecordPlanDO dbFeedingRecordPlan = randomPojo(FeedingRecordPlanDO.class);
|
||||||
|
feedingRecordPlanMapper.insert(dbFeedingRecordPlan);// @Sql: 先插入出一条存在的数据
|
||||||
|
// 准备参数
|
||||||
|
FeedingRecordPlanSaveReqVO updateReqVO = randomPojo(FeedingRecordPlanSaveReqVO.class, o -> {
|
||||||
|
o.setId(dbFeedingRecordPlan.getId()); // 设置更新的 ID
|
||||||
|
});
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
feedingRecordPlanService.updateFeedingRecordPlan(updateReqVO);
|
||||||
|
// 校验是否更新正确
|
||||||
|
FeedingRecordPlanDO feedingRecordPlan = feedingRecordPlanMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||||
|
assertPojoEquals(updateReqVO, feedingRecordPlan);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateFeedingRecordPlan_notExists() {
|
||||||
|
// 准备参数
|
||||||
|
FeedingRecordPlanSaveReqVO updateReqVO = randomPojo(FeedingRecordPlanSaveReqVO.class);
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> feedingRecordPlanService.updateFeedingRecordPlan(updateReqVO), FEEDING_RECORD_PLAN_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteFeedingRecordPlan_success() {
|
||||||
|
// mock 数据
|
||||||
|
FeedingRecordPlanDO dbFeedingRecordPlan = randomPojo(FeedingRecordPlanDO.class);
|
||||||
|
feedingRecordPlanMapper.insert(dbFeedingRecordPlan);// @Sql: 先插入出一条存在的数据
|
||||||
|
// 准备参数
|
||||||
|
Long id = dbFeedingRecordPlan.getId();
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
feedingRecordPlanService.deleteFeedingRecordPlan(id);
|
||||||
|
// 校验数据不存在了
|
||||||
|
assertNull(feedingRecordPlanMapper.selectById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteFeedingRecordPlan_notExists() {
|
||||||
|
// 准备参数
|
||||||
|
Long id = randomLongId();
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> feedingRecordPlanService.deleteFeedingRecordPlan(id), FEEDING_RECORD_PLAN_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||||
|
public void testGetFeedingRecordPlanPage() {
|
||||||
|
// mock 数据
|
||||||
|
FeedingRecordPlanDO dbFeedingRecordPlan = randomPojo(FeedingRecordPlanDO.class, o -> { // 等会查询到
|
||||||
|
o.setRecordId(null);
|
||||||
|
o.setRecordDetailId(null);
|
||||||
|
o.setPlanId(null);
|
||||||
|
o.setItemId(null);
|
||||||
|
o.setWeight(null);
|
||||||
|
o.setUnitId(null);
|
||||||
|
o.setUserId(null);
|
||||||
|
o.setFeedingTime(null);
|
||||||
|
o.setCreateTime(null);
|
||||||
|
});
|
||||||
|
feedingRecordPlanMapper.insert(dbFeedingRecordPlan);
|
||||||
|
// 测试 recordId 不匹配
|
||||||
|
feedingRecordPlanMapper.insert(cloneIgnoreId(dbFeedingRecordPlan, o -> o.setRecordId(null)));
|
||||||
|
// 测试 recordDetailId 不匹配
|
||||||
|
feedingRecordPlanMapper.insert(cloneIgnoreId(dbFeedingRecordPlan, o -> o.setRecordDetailId(null)));
|
||||||
|
// 测试 planId 不匹配
|
||||||
|
feedingRecordPlanMapper.insert(cloneIgnoreId(dbFeedingRecordPlan, o -> o.setPlanId(null)));
|
||||||
|
// 测试 itemId 不匹配
|
||||||
|
feedingRecordPlanMapper.insert(cloneIgnoreId(dbFeedingRecordPlan, o -> o.setItemId(null)));
|
||||||
|
// 测试 weight 不匹配
|
||||||
|
feedingRecordPlanMapper.insert(cloneIgnoreId(dbFeedingRecordPlan, o -> o.setWeight(null)));
|
||||||
|
// 测试 unitId 不匹配
|
||||||
|
feedingRecordPlanMapper.insert(cloneIgnoreId(dbFeedingRecordPlan, o -> o.setUnitId(null)));
|
||||||
|
// 测试 userId 不匹配
|
||||||
|
feedingRecordPlanMapper.insert(cloneIgnoreId(dbFeedingRecordPlan, o -> o.setUserId(null)));
|
||||||
|
// 测试 feedingTime 不匹配
|
||||||
|
feedingRecordPlanMapper.insert(cloneIgnoreId(dbFeedingRecordPlan, o -> o.setFeedingTime(null)));
|
||||||
|
// 测试 createTime 不匹配
|
||||||
|
feedingRecordPlanMapper.insert(cloneIgnoreId(dbFeedingRecordPlan, o -> o.setCreateTime(null)));
|
||||||
|
// 准备参数
|
||||||
|
FeedingRecordPlanPageReqVO reqVO = new FeedingRecordPlanPageReqVO();
|
||||||
|
reqVO.setRecordId(null);
|
||||||
|
reqVO.setRecordDetailId(null);
|
||||||
|
reqVO.setPlanId(null);
|
||||||
|
reqVO.setItemId(null);
|
||||||
|
reqVO.setWeight(null);
|
||||||
|
reqVO.setUnitId(null);
|
||||||
|
reqVO.setUserId(null);
|
||||||
|
reqVO.setFeedingTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||||
|
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
PageResult<FeedingRecordPlanDO> pageResult = feedingRecordPlanService.getFeedingRecordPlanPage(reqVO);
|
||||||
|
// 断言
|
||||||
|
assertEquals(1, pageResult.getTotal());
|
||||||
|
assertEquals(1, pageResult.getList().size());
|
||||||
|
assertPojoEquals(dbFeedingRecordPlan, pageResult.getList().get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue