package com.huimv.manage.eartag.controller;

import com.huimv.manage.eartag.service.IPackageService;
import com.huimv.manage.util.Result;
import com.huimv.manage.webservice.Soap;
import com.huimv.manage.webservice.task.PackageTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.Date;

/**
 * @Project : huimv.shiwan
 * @Package : com.huimv.biosafety.uface.controller
 * @Description : TODO
 * @Version : 1.0
 * @Author : ZhuoNing
 * @Create : 2020-12-25
 **/
@CrossOrigin
@RestController
@Slf4j
@RequestMapping(value = "/eartag/package")
public class PackageController {
    @Value("${webservice.url}")
    private String webServiceUrl;
    @Value("${webservice.producerId}")
    private String producerId;
    @Autowired
    private Soap soap;
    @Autowired
    private PackageTask packageTask;
    @Autowired
    private IPackageService packageService;

    /**
     * @Method : listPackage
     * @Description : 展示列表
     * @Params : [pageSize]
     * @Return : com.huimv.manage.util.Result
     * @Author : ZhuoNing
     * @Date : 2021/10/29
     * @Time : 15:37
     */
    @RequestMapping(value = "/listPackage", method = RequestMethod.GET)
//    public Result listPackage(@RequestParam(value = "pageSize")int pageSize){
    public Result listPackage(
            @RequestParam(value = "applyId", required = false) Integer applyId,
            @RequestParam(value = "packageId", required = false) Integer packageId,
            @RequestParam(value = "startDate", required = false) Date startDate,
            @RequestParam(value = "endDate", required = false) Date endDate,
            @RequestParam(value = "returnState", required = false) Integer returnState,
            @RequestParam(value = "pageSize", required = true) Integer pageSize,
            @RequestParam(value = "pageNum", required = true) Integer pageNo) {
        //
        return packageService.listPackage(applyId,packageId,startDate,endDate,returnState,pageSize,pageNo);
    }

    /**
     * @Method : getNewPackage
     * @Description : 根据任务号下载新批次
     * @Params : [applyId]
     * @Return : com.huimv.manage.util.Result
     * @Author : ZhuoNing
     * @Date : 2021/10/29
     * @Time : 15:42
     */
    @RequestMapping(value = "/getNewPackage", method = RequestMethod.GET)
    public Result getNewPackage(@RequestParam(value = "applyId") int applyId, HttpServletRequest request) throws UnsupportedEncodingException {
        //
        return packageService.getNewPackage(applyId);
    }

    /**
     * @Method : setReturnDownloadState
     * @Description : 设置返回批次已下载状态
     * @Params : [packageIds, ids]
     * @Return : com.huimv.manage.util.Result
     * @Author : ZhuoNing
     * @Date : 2021/10/29
     * @Time : 18:51
     */
    @RequestMapping(value = "/setReturnDownloadState", method = RequestMethod.GET)
    public Result setReturnDownloadState(@RequestParam(value = "packageIds") String packageIds, @RequestParam(value = "ids") String ids, HttpServletRequest request) throws UnsupportedEncodingException {
        //
        return packageService.setReturnDownloadState(packageIds, ids);
    }

    /**
     * @Method : setProduceState
     * @Description : 设置生产状态
     * @Params : []
     * @Return : com.huimv.manage.util.Result
     * @Author : ZhuoNing
     * @Date : 2021/10/29
     * @Time : 19:22
     */
    @RequestMapping(value = "/setProduceState", method = RequestMethod.GET)
    public Result setProduceState(@RequestParam(value = "ids") String ids, @RequestParam(value = "state") int state, HttpServletRequest request) {
        //
        return packageService.setProduceState(ids, state);
    }


}
