package com.weather.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;

import com.weather.entity.AgriculturalQualityCertification;
import com.weather.service.IAgriculturalQualityCertificationService;
import com.weather.vo.ApiResult;
import com.weather.vo.req.PageProductReq;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
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 java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 气候品质 品质认证 前端控制器
 * </p>
 *
 * @author : fengyuhao
 * @since 2021-03-28
 */
@RestController
@RequestMapping("/agricultural/quality/certification")
public class AgriculturalQualityCertificationController {

    @Autowired
    IAgriculturalQualityCertificationService certificationService;


    @PostMapping("page")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "品质认证列表", response = AgriculturalQualityCertification.class)
    public ApiResult list(@RequestBody PageProductReq req) throws ParseException {

        IPage<AgriculturalQualityCertification> page = new Page<>();
        page.setSize(req.getLimit());
        page.setCurrent(req.getPage());

        QueryWrapper<AgriculturalQualityCertification> wrapper = new QueryWrapper<>();
        wrapper.lambda().orderByDesc(AgriculturalQualityCertification::getCertiDate);

        page = certificationService.page(page, wrapper);
        List<AgriculturalQualityCertification> records = page.getRecords();
        if (records==null||records.size()<=0){
            return ApiResult.noData();
        }

        List<AgriculturalQualityCertification> resList=new ArrayList<>();
        AgriculturalQualityCertification model;

        for (AgriculturalQualityCertification record : records) {
            model=new AgriculturalQualityCertification();
            BeanUtils.copyProperties(record,model);
            // 其他字段处理

            resList.add(model);
        }
        return ApiResult.success(resList);
    }

}
