package com.pusong.business.controller;

import java.util.List;

import cn.dev33.satoken.annotation.SaIgnore;
import com.pusong.business.domain.bo.PsCompanyQueryBo;
import com.pusong.business.domain.bo.PsCustomRecordQueryBo;
import com.pusong.business.domain.vo.PsCompanyQueryVo;
import com.pusong.business.domain.vo.PsContractInfoVo;
import com.pusong.business.domain.vo.PsCustomerRecordVo;
import com.pusong.common.core.validate.QueryGroup;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.pusong.common.idempotent.annotation.RepeatSubmit;
import com.pusong.common.log.annotation.Log;
import com.pusong.common.web.core.BaseController;
import com.pusong.common.mybatis.core.page.PageQuery;
import com.pusong.common.core.domain.R;
import com.pusong.common.core.validate.AddGroup;
import com.pusong.common.core.validate.EditGroup;
import com.pusong.common.log.enums.BusinessType;
import com.pusong.common.excel.utils.ExcelUtil;
import com.pusong.business.domain.vo.PsCompanyInfoVo;
import com.pusong.business.domain.bo.PsCompanyInfoBo;
import com.pusong.business.service.IPsCompanyInfoService;
import com.pusong.common.mybatis.core.page.TableDataInfo;

/**
 * 公司信息
 *
 * @author wls
 * @date 2024-07-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/companyInfo")
@SaIgnore
public class PsCompanyInfoController extends BaseController {

    private final IPsCompanyInfoService psCompanyInfoService;

    /**
     * 查询公司信息列表
     */
    @SaCheckPermission("business:companyInfo:list")
    @GetMapping("/list")
    public R<List<PsCompanyInfoVo>> list(@Validated(QueryGroup.class) PsCompanyInfoBo bo) {
        return R.ok(psCompanyInfoService.queryList(bo));
    }


    /**
     * 分页查询公司信息列表
     */
    @SaCheckPermission("business:companyInfo:list")
    @GetMapping("/pageList")
    public TableDataInfo<PsCompanyInfoVo>  pageList(PsCompanyQueryBo bo, PageQuery pageQuery) {
        return psCompanyInfoService.queryPageList(bo,pageQuery);
    }

    /**
     * 服务公司列表
     */
    @SaCheckPermission("business:customInfo:list")
    @Log(title = "服务公司列表" )
    @GetMapping("/serviceList")
    public TableDataInfo<PsCompanyInfoVo> serviceList(PsCompanyQueryBo queryBo, PageQuery pageQuery) {
        return psCompanyInfoService.queryServiceCompany(queryBo, pageQuery);
    }
    @SaCheckPermission("business:customInfo:list")
    @Log(title = "服务公司列表" )
    @GetMapping("/searchServiceCompany")
    public TableDataInfo<PsCompanyInfoVo> searchServiceCompany(@RequestParam("keyWorld") String keyWorld) {
        return psCompanyInfoService.searchServiceCompany(keyWorld);
    }

    /**
     * 停止代账
     */
    @SaCheckPermission("business:customInfo:list")
    @Log(title = "停止代账" )
    @GetMapping("/applyTerminationService")
    public  R<Void> terminationService(PsCompanyQueryBo queryBo, PageQuery pageQuery) {
        psCompanyInfoService.terminationService(queryBo.getId());
        return R.ok();
    }


    /**
     * 新增公司信息
     */
    @SaCheckPermission("business:companyInfo:add")
    @Log(title = "公司信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PsCompanyInfoBo bo) {
        return toAjax(psCompanyInfoService.saveBo(bo));
    }

    /**
     * 修改公司信息
     */
    @SaCheckPermission("business:companyInfo:edit")
    @Log(title = "公司信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PsCompanyInfoBo bo) {
        return toAjax(psCompanyInfoService.saveBo(bo));
    }

    /**
     * 删除公司信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("business:companyInfo:remove")
    @Log(title = "公司信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(psCompanyInfoService.deleteWithValidByIds(List.of(ids), true));
    }


}
