package cn.iocoder.yudao.module.mes.controller.admin.qc.patrol;
|
|
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
import jakarta.annotation.Resource;
|
import jakarta.validation.Valid;
|
import jakarta.validation.constraints.*;
|
import lombok.Data;
|
import lombok.EqualsAndHashCode;
|
import org.apache.ibatis.annotations.Mapper;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.*;
|
import java.math.BigDecimal;
|
import java.time.LocalDateTime;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
@RestController
|
@RequestMapping("/mes/qc/patrol")
|
@Validated
|
public class MesQcPatrolController {
|
@Resource private PatrolMapper mapper;
|
@Resource private cn.iocoder.yudao.module.mdm.api.item.MdmItemApi itemApi;
|
@Resource private cn.iocoder.yudao.module.system.api.user.AdminUserApi userApi;
|
|
@TableName("mes_qc_patrol") @Data @EqualsAndHashCode(callSuper = true)
|
public static class Patrol extends BaseDO {
|
@TableId private Long id;
|
@NotBlank @Size(max=100) private String code;
|
@NotBlank @Size(max=255) private String name;
|
@NotNull private Long itemId;
|
@Size(max=128) private String reelNo;
|
@Size(max=128) private String batchCode;
|
@NotNull @DecimalMin("0") private BigDecimal qualifiedQuantity;
|
@NotNull @DecimalMin("0") private BigDecimal unqualifiedQuantity;
|
@NotNull private LocalDateTime inspectDate;
|
@NotNull private Long inspectorUserId;
|
@Size(max=1000) private String remark;
|
}
|
@Data @EqualsAndHashCode(callSuper=true) public static class Query extends PageParam { private String code; private String reelNo; private Long itemId; }
|
|
@GetMapping("/page") @PreAuthorize("@ss.hasPermission('mes:qc-patrol:query')")
|
public CommonResult<PageResult<Patrol>> page(@Valid Query query) {
|
return success(mapper.selectPage(query, new LambdaQueryWrapperX<Patrol>()
|
.likeIfPresent(Patrol::getCode, query.getCode()).likeIfPresent(Patrol::getReelNo, query.getReelNo())
|
.eqIfPresent(Patrol::getItemId, query.getItemId()).orderByDesc(Patrol::getId)));
|
}
|
@GetMapping("/get") @PreAuthorize("@ss.hasPermission('mes:qc-patrol:query')")
|
public CommonResult<Patrol> get(@RequestParam Long id) { return success(require(id)); }
|
@PostMapping("/create") @PreAuthorize("@ss.hasPermission('mes:qc-patrol:create')")
|
public CommonResult<Long> create(@Valid @RequestBody Patrol row) { row.setId(null); validate(row); mapper.insert(row); return success(row.getId()); }
|
@PutMapping("/update") @PreAuthorize("@ss.hasPermission('mes:qc-patrol:update')")
|
public CommonResult<Boolean> update(@Valid @RequestBody Patrol row) { if(row.getId()==null) throw new ServiceException(400,"记录编号不能为空"); require(row.getId()); validate(row); mapper.updateById(row); return success(true); }
|
@DeleteMapping("/delete") @PreAuthorize("@ss.hasPermission('mes:qc-patrol:delete')")
|
public CommonResult<Boolean> delete(@RequestParam Long id) { require(id); mapper.deleteById(id); return success(true); }
|
private Patrol require(Long id) { Patrol p=mapper.selectById(id); if(p==null) throw new ServiceException(400,"巡检记录不存在"); return p; }
|
private void validate(Patrol row) { itemApi.validateItemExists(row.getItemId()); userApi.validateUser(row.getInspectorUserId()); if(row.getQualifiedQuantity().add(row.getUnqualifiedQuantity()).signum()<=0) throw new ServiceException(400,"巡检数量必须大于零"); }
|
}
|