package com.bonus.zlpt.company.controller;

import com.bonus.zlpt.common.core.utils.poi.ExcelUtil;
import com.bonus.zlpt.common.core.web.controller.BaseController;
import com.bonus.zlpt.common.core.web.domain.AjaxResult;
import com.bonus.zlpt.common.core.web.page.TableDataInfo;
import com.bonus.zlpt.common.security.utils.SecurityUtils;
import com.bonus.zlpt.company.api.domain.BusinessOpen;
import com.bonus.zlpt.company.api.domain.dto.BmCompanyDto;
import com.bonus.zlpt.company.api.domain.vo.BusinessOpenVo;
import com.bonus.zlpt.company.service.BusinessOpenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.time.LocalDateTime;
import java.util.List;


/**
 * 企业业务开通管理
 */
@RestController
@RequestMapping("/business/open")
@Api(value = "企业业务开通管理",tags = {"企业业务开通管理"})
public class BusinessOpenController extends BaseController {

    @Autowired
    private BusinessOpenService businessOpenService;


    /**
     * 根据条件查询企业业务开通信息列表
     * @param bmCompanyDto
     * @return
     */
    @PostMapping("/selectList")
    @ApiOperation("根据条件查询企业业务开通信息列表")
    public TableDataInfo selectList(@RequestBody BmCompanyDto bmCompanyDto){

        startPage(bmCompanyDto.getPageNum(),bmCompanyDto.getPageSize());
        List<BusinessOpenVo> list = businessOpenService.selectList(bmCompanyDto);
        return getDataTable(list);
    }

    /**
     * 新增业务开通请求
     * @param businessOpen
     * @return
     */
    @PostMapping("/insert")
    @ApiOperation("新增业务开通请求")
    public AjaxResult insertBusinessOpenInfo(@RequestBody BusinessOpen businessOpen){

        return toAjax(businessOpenService.insertBusinessOpenInfo(businessOpen));
    }


    /**
     * 企业业务开通数据修改
     * @return
     */
    @PostMapping("/updateBusiness")
    @ApiOperation("企业业务开通数据修改")
    public AjaxResult updateBusiness(@RequestBody BusinessOpen businessOpen){

        if(!"0".equals(businessOpen.getStatus()) && !"3".equals(businessOpen.getStatus())){

            businessOpen.setAuditor(SecurityUtils.getUsername());
            businessOpen.setAuditTime(LocalDateTime.now().toString());
        }
        return toAjax(businessOpenService.updateBusiness(businessOpen));
    }

    /**
     * 企业业务开通数据导出
     * @param response
     */
    @GetMapping("/exportExcel")
    @ApiOperation("企业业务开通数据导出")
    public void exportExcel(HttpServletResponse response) throws UnsupportedEncodingException {

        ExcelUtil<BusinessOpenVo> businessOpenVoExcelUtil = new ExcelUtil<>(BusinessOpenVo.class);
        businessOpenVoExcelUtil.exportExcel(response,businessOpenService.selectList(new BmCompanyDto()),"企业业务开通数据","","企业业务开通数据");

    }








}
