package vip.xiaonuo.quality.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.production.entity.ProductionWriteRate;
import vip.xiaonuo.production.param.ProductionPageParam;
import vip.xiaonuo.production.param.ProductionWriteRateAddParam;
import vip.xiaonuo.quality.entity.QualityWrite;
import vip.xiaonuo.quality.param.QualityWriteAddParam;
import vip.xiaonuo.quality.param.QualityWriteListParam;
import vip.xiaonuo.quality.service.IQualityWriteService;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 质量来料不合格填报 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-03-01
 */
@RestController
@Api(tags = "质量来料不合格填报")
@ApiSupport(author = "wang", order = 1)
@Validated
public class QualityWriteController {

    @Autowired
    private IQualityWriteService qualityWriteService;

    @PostMapping("/quality-write/add")
    @ApiOperationSupport(order = 1)
    @ApiOperation("质量来料不合格填报添加")
    public CommonResult add(@RequestBody QualityWriteAddParam param){
        return qualityWriteService.add(param);
    }

    @PostMapping("/quality-write/edit")
    @ApiOperationSupport(order = 2)
    @ApiOperation("质量来料不合格填报修改")
    public CommonResult edit(@RequestBody QualityWrite qualityWrite) {
        return qualityWriteService.edit(qualityWrite);
    }

    @PostMapping("/quality-write/delete")
    @ApiOperationSupport(order = 3)
    @ApiOperation("质量来料不合格填报删除")
    public CommonResult delete(@RequestBody Map<String, String> paramsMap) {
        return qualityWriteService.delete(paramsMap);
    }

    @PostMapping("/quality-write/page")
    @ApiOperationSupport(order = 4)
    @ApiOperation("质量来料不合格填报分页")
    public CommonResult<Page<QualityWrite>> page(@RequestBody ProductionPageParam pageParam) {
        return CommonResult.data(qualityWriteService.page(pageParam));
    }

    @PostMapping("/quality-write/list")
    @ApiOperationSupport(order = 5)
    @ApiOperation("质量来料不合格填报列表")
    public CommonResult<List<QualityWrite>> list(@RequestBody QualityWriteListParam listParam) {
        String orgId = listParam.getOrgId();
        String time = listParam.getTime();
        QueryWrapper<QualityWrite> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(orgId), "org_id", orgId);
        queryWrapper.between("create_time", time + "-01 00:00:00", time + "-31 23:59:59");
        return CommonResult.data(qualityWriteService.list(queryWrapper));
    }

}
