package com.ningdatech.carapi.industry.controller;


import com.ningdatech.basic.model.PageVo;
import com.ningdatech.carapi.common.util.ExcelDownUtil;
import com.ningdatech.carapi.industry.manage.ReadyMixedMortarManage;
import com.ningdatech.carapi.industry.model.dto.ReadyMixedMortarIndustryManageSaveDTO;
import com.ningdatech.carapi.industry.model.dto.ReadyMixedMortarIndustryManageUpdateDTO;
import com.ningdatech.carapi.industry.model.dto.ReadyMixedPageParamDTO;
import com.ningdatech.carapi.industry.model.vo.ReadyMixedMortarIndustryManageVO;
import com.ningdatech.carapi.user.util.LoginUserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * <p>
 * 预拌砂浆行业管理 前端控制器
 * </p>
 *
 * @author PoffyZhang
 * @since 2022-11-18
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/api/industry/ready-mixed-mortar")
@Api(value = "PassportManage", tags = "行业服务-通行证管理")
@RequiredArgsConstructor
public class ReadyMixedMortarIndustryManageController {

    private final ReadyMixedMortarManage readyMixedMortarManage;

    @ApiOperation(value = "列表查询", notes = "列表查询")
    @GetMapping("/list")
    public PageVo<ReadyMixedMortarIndustryManageVO> list(@Valid @ModelAttribute ReadyMixedPageParamDTO param) {
        return readyMixedMortarManage.list(param);
    }

    @ApiOperation(value = "通行证证书详情", notes = "通行证证书详情")
    @GetMapping("/details/{id}")
    public ReadyMixedMortarIndustryManageVO details(@Valid @PathVariable Long id) {
        return readyMixedMortarManage.details(id);
    }

    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/save")
    public ReadyMixedMortarIndustryManageVO save(@Valid @RequestBody ReadyMixedMortarIndustryManageSaveDTO data) {
        return readyMixedMortarManage.save(data, LoginUserUtil.loginUserDetail());
    }

    @ApiOperation(value = "编辑", notes = "编辑")
    @PostMapping("/modify")
    public ReadyMixedMortarIndustryManageVO modify(@Valid @RequestBody ReadyMixedMortarIndustryManageUpdateDTO data) {
        return readyMixedMortarManage.modify(data, LoginUserUtil.loginUserDetail());
    }

    @ApiOperation(value = "删除", notes = "删除")
    @DeleteMapping("/remove/{id}")
    public Boolean remove(@Valid @PathVariable Long id) {
        return readyMixedMortarManage.remove(id, LoginUserUtil.loginUserDetail());
    }

    @ApiOperation("导出")
    @GetMapping("/export")
    public void export(ReadyMixedPageParamDTO param, HttpServletResponse response) {
        ExcelDownUtil.downXls(response, param, readyMixedMortarManage::export);
    }
}
