package cn.ezhizao.project.business.standardCpmpany.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import cn.ezhizao.project.business.standardCpmpany.domain.BizStandardCompany;
import cn.ezhizao.project.business.standardCpmpany.service.IBizStandardCompanyService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;

import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.framework.web.page.TableDataInfo;

/**
 * standardCompanyController
 *
 * @author ezhizao
 * @date 2023-10-30
 */
@RestController
@RequestMapping("/business/standardCompany")
public class BizStandardCompanyController extends BaseController
{
    @Resource
    private IBizStandardCompanyService bizStandardCompanyService;

    /**
     * 查询standardCompany列表
     */
    @PreAuthorize("@ss.hasPermi('business:standardCompany:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizStandardCompany bizStandardCompany) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizStandardCompany);
        startPage();
        List<BizStandardCompany> list = bizStandardCompanyService.getList(bizStandardCompany);
        return getDataTable(list);
    }

    /**
     * 导出standardCompany列表
     */
    @PreAuthorize("@ss.hasPermi('business:standardCompany:export')")
    @Log(title = "standardCompany", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizStandardCompany bizStandardCompany) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizStandardCompany);
        List<BizStandardCompany> list = bizStandardCompanyService.getList(bizStandardCompany);
        ExcelUtil<BizStandardCompany> util = new ExcelUtil<BizStandardCompany>(BizStandardCompany.class);
        util.exportExcel(response, list, "standardCompany数据");
    }

    /**
     * 获取standardCompany详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:standardCompany:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizStandardCompanyService.getById(id));
    }

    /**
     * 新增standardCompany
     */
    @PreAuthorize("@ss.hasPermi('business:standardCompany:add')")
    @Log(title = "standardCompany", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizStandardCompany bizStandardCompany) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizStandardCompany);
        return toAjax(bizStandardCompanyService.save(bizStandardCompany));
    }

    /**
     * 修改standardCompany
     */
    @PreAuthorize("@ss.hasPermi('business:standardCompany:edit')")
    @Log(title = "standardCompany", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizStandardCompany bizStandardCompany) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizStandardCompany);
        return toAjax(bizStandardCompanyService.updateById(bizStandardCompany));
    }

    /**
     * 删除standardCompany
     */
    @PreAuthorize("@ss.hasPermi('business:standardCompany:remove')")
    @Log(title = "standardCompany", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizStandardCompanyService.removeBatchByIds(ids));
    }

    /**
     * 修改负责人
     */
    @PreAuthorize("@ss.hasPermi('business:standardCompany:edit')")
    @Log(title = "负责人", businessType = BusinessType.UPDATE)
    @PostMapping("/Leader/{ids}")
    public AjaxResult updateStandardCompanyLeader( @PathVariable List<Long> ids,@RequestBody Long userId)
    {
        return toAjax(bizStandardCompanyService.updateUserId(ids,userId,0));
    }

    /**
     * 修改客服
     */
    @PreAuthorize("@ss.hasPermi('business:standardCompany:edit')")
    @Log(title = "客服", businessType = BusinessType.UPDATE)
    @PostMapping("/Adviser/{ids}")
    public AjaxResult updateStandardCompanyAdviser( @PathVariable List<Long> ids,@RequestBody Long userId)
    {
        return toAjax(bizStandardCompanyService.updateUserId(ids,userId,1));
    }
}
