package com.unis.base.server.controller;

import com.github.pagehelper.PageInfo;
import com.unis.base.common.vo.ProfitVO;
import com.unis.base.common.vo.ReversePositionVo;
import com.unis.base.server.service.ReversePositionService;
import com.unis.common.utils.ResponseWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

/**
 * @author ceshi
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description:
 * @date 2019/10/3119:35
 */
@RestController
@Api(value = "倒仓信息数据", tags = "倒仓信息数据维护")
@Slf4j
public class ReversePositionController {
    @Autowired
    private ReversePositionService reversePositionService;

    /**
     * @Title: getPageList
     * @Description: TODO方法描述:(这里用一句话描述这个方法的作用)
     * @param @param profitVO
     * @param @param pageNum
     * @param @param pageSize
     * @param @return    设定文件
     * @return ResponseWrapper    返回类型
     * @throws
     */
    @ApiOperation(value = "列表 根据条件【分页查询】",notes = "待定")
    @PostMapping(value = "/getPageListt/{pageNum}/{pageSize}")
    public ResponseWrapper getPageList(@RequestBody ReversePositionVo reversePositionVo,
                                       @PathVariable(value = "pageNum") Integer pageNum,
                                       @PathVariable(value = "pageSize") Integer pageSize){
        try {
            PageInfo<ReversePositionVo> pageInfos = reversePositionService.getPageList(reversePositionVo,pageNum,pageSize);
            return ResponseWrapper.success(HttpStatus.OK.value(), "获取信息列表成功", pageInfos);
        } catch (Exception e) {
            log.error(e.getMessage());
            return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),"获取信息列表失败",null);
        }
    }

    /**
     *
     * @Title: deleteProfit
     * @Description:方法描述:(通过编号删除)
     * @param @param sybh
     * @param @return    设定文件
     * @return ResponseWrapper    返回类型
     * @throws
     */
    @ApiOperation(value = "根据编号【删除】",notes = "编号")
    @DeleteMapping(value = "/deleteProfit/{sybh}")
    public ResponseWrapper deleteProfit(@PathVariable("dcdbm")String dcdbm) {
        try {
            int pro = reversePositionService.deleteProfit(dcdbm);
            return ResponseWrapper.success(HttpStatus.OK.value(), "获取信息列表成功", pro);
        } catch (Exception e) {
            log.error(e.getMessage());
            return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),"获取信息列表失败",null);
        }
    }


    @ApiOperation(value = "数据录入",notes = "数据录入")
    @DeleteMapping(value = "/infoProfit")
    public ResponseWrapper infoProfit(@RequestBody ReversePositionVo reversePositionVo) {
        try {
            int pro = reversePositionService.infoProfit(reversePositionVo);
            return ResponseWrapper.success(HttpStatus.OK.value(), "获取信息列表成功", pro);
        } catch (Exception e) {
            log.error(e.getMessage());
            return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),"获取信息列表失败",null);
        }
    }

}
