package com.sckw.system.controller;

import com.sckw.core.web.constant.HttpStatus;
import com.sckw.core.web.response.HttpResult;
import com.sckw.system.model.KwsEnterprise;
import com.sckw.system.model.vo.req.*;
import com.sckw.system.model.vo.req.FindListReqVo;
import com.sckw.system.service.KwsEnterpriseService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

/**
 * 企业信息
 * @author zk
 * @date 2023-05-31
 */
@RestController
@RequestMapping("/kwsEnt")
public class KwsEnterpriseController {

    @Autowired
    private KwsEnterpriseService kwsEntService;

    /**
     * @param id 主键ID
     * @return HttpResult
     * @description 根据主键查询
     * @author zk
     * @date 2023/06/02
     **/
    @GetMapping("/detail")
    public HttpResult detail(@RequestParam Long id,
                             @RequestParam (value = "isAll", required = false)Boolean isAll) {
        return HttpResult.ok(kwsEntService.detail(id, isAll));
    }

    /**
     * @desc 企业联系人信息
     * @param id 企业信息
     * @author zk
     * @date 2023/9/1
     **/
    @GetMapping("/detailOpen")
    public HttpResult detailOpen(@RequestParam Long id) {
        return HttpResult.ok(kwsEntService.detailOpen(id));
    }

    /**
     * @param pageReqVo
     * @return HttpResult
     * @description 分页查询
     * @author zk
     * @date 2023/5/30
     **/
    @PostMapping("/findPage")
    public HttpResult findPage(@RequestBody EntFindPageReqVo pageReqVo) {
        return HttpResult.ok(kwsEntService.findPage(pageReqVo));
    }

    /**
     * @param pageReqVo
     * @return HttpResult
     * @description 分页查询
     * @author zk
     * @date 2023/5/30
     **/
    @PostMapping("/findListGroup")
    public HttpResult findListGroup(@RequestBody EntFindPageReqVo pageReqVo) {
        return HttpResult.ok(kwsEntService.findListGroup(pageReqVo));
    }

    /**
     * @param id 主键ID
     * @return HttpResult
     * @description 企业资质信息
     * @author zk
     * @date 2023/06/02
     **/
    @GetMapping("/certificate")
    public HttpResult certificate(@RequestParam Long id) {
        return HttpResult.ok(kwsEntService.certificate(id));
    }

    /**
     * @return HttpResult
     * @description 注册 企业认证
     * @author zk
     * @date 2023/06/02
     **/
    @PostMapping("/register")
    public HttpResult register(@Valid @RequestBody EntRegisterReqVo reqVo) {
        kwsEntService.register(reqVo);
        return HttpResult.ok(HttpStatus.MSG_009);
    }

    /**
     * @param reqVo 新增企业入驻入参
     * @return HttpResult
     * @desc: 新增企业入驻
     * @author: czh
     * @date: 2023/6/19
     */
    @PostMapping("/addEntSettle")
    public HttpResult addEntSettle(@Valid @RequestBody AddEntSettleReqVo reqVo) {
        kwsEntService.addEntSettle(reqVo);
        return HttpResult.ok(HttpStatus.MSG_003);
    }

    /**
     * @param params {name 机构名称、company 是否公司}
     * @return HttpResult
     * @description 新增
     * @author zk
     * @date 2023/06/02
     **/
    @PostMapping("/add")
    @Deprecated
    public HttpResult add(@RequestBody KwsEnterprise params) {
        kwsEntService.add(params);
        return HttpResult.ok(HttpStatus.MSG_003);
    }

    /**
     * @return HttpResult
     * @description 更新企业信息
     * @author zk
     * @date 2023/06/02
     **/
    @Deprecated
    @PostMapping("/update")
    public HttpResult update(@RequestBody UpdateEntInfoReqVo reqVo) {
        kwsEntService.update(reqVo);
        return HttpResult.ok(HttpStatus.MSG_005);
    }

    /**
     * @return HttpResult
     * @description 更新资质
     * @author zk
     * @date 2023/06/02
     **/
    @PostMapping("/updateCertificate")
    public HttpResult updateCertificate(@RequestBody UpdateCertificateReqVo reqVo) {
        kwsEntService.updateCertificate(reqVo);
        return HttpResult.ok(HttpStatus.MSG_005);
    }



    /**
     * @param reqVo {ids：主键ID（多个以逗号隔开）}
     * @return HttpResult
     * @description 删除
     * @author zk
     * @date 2023/06/02
     **/
    @PostMapping("/dels")
    public HttpResult del(@RequestBody IdReqVo reqVo) {
        kwsEntService.deleteByKey(reqVo.getIds());
        return HttpResult.ok();
    }

    /**
     * @param {entId 企业id、status状态0正常1锁定、remark 审批意见}
     * @return HttpResult
     * @description 企业审批
     * @author zk
     * @date 2023/06/02
     **/
    @PostMapping(value = "/approval")
    public HttpResult approval(@Valid @RequestBody ApprovalReqVo reqVo) {
        kwsEntService.approval(reqVo);
        return HttpResult.ok(HttpStatus.MSG_004);
    }

    /**
     * @param entId 主键ID
     * @return HttpResult
     * @description 企业审批记录
     * @author zk
     * @date 2023/06/02
     **/
    @GetMapping("/entCheck")
    public HttpResult entCheck(@RequestParam Long entId) {
        return HttpResult.ok(kwsEntService.entCheck(entId));
    }

    /**
     * @param {entId 企业id、status 状态0正常1锁定}
     * @return HttpResult
     * @description 企业冻结/解冻
     * @author zk
     * @date 2023/06/02
     **/
    @PostMapping(value = "/freeze")
    public HttpResult freeze(@Valid @RequestBody FreezeReqVo reqVo) {
        kwsEntService.freeze(reqVo);
        return HttpResult.ok(HttpStatus.MSG_005);
    }

    /**
     * @param {entId 变更主账号企业ID, phone 替换账号，captcha 验证码}
     * @return HttpResult
     * @description 变更主账号（被替换账号冻结）
     * @author zk
     * @date 2023/06/02
     **/
    @PostMapping("/changeMasterAccount")
    public HttpResult changeMasterAccount(@RequestBody Map<String, String> params) {
        return null;
    }


    /**
     * @desc: 查企业下的员工
     * @param: reqVo 企业id
     * @author: czh
     * @date 2023/7/18
     * @return HttpResult
     */
    @PostMapping("findEntUser")
    public HttpResult findEntUser(@RequestBody FindListReqVo reqVo) {
        return HttpResult.ok(kwsEntService.findEntUser(reqVo));
    }

    /**
     * @desc: 查所有企业
     * @param: reqVo 企业id
     * @author: czh
     * @date 2023/7/18
     * @return HttpResult
     */
    @PostMapping("findList")
    public HttpResult findList(@RequestBody FindListReqVo reqVo) {
        return HttpResult.ok(kwsEntService.findList(reqVo));
    }

    /**
     * @param  reqVo id
     * @return  HttpResult
     * @desc: 查询企业的信息+主体机构信息
     * @author: czh
     * @date: 2023/7/22
     */
    @PostMapping("queryEntOrganization")
    public HttpResult queryEntOrganization(@RequestBody IdReqVo reqVo) {
        return HttpResult.ok(kwsEntService.queryCurrentOrganization(reqVo.getId()));
    }

    /**
     * @param  reqVo id
     * @return  HttpResult
     * @desc: 查询其他入驻企
     * @author: czh
     * @date: 2023/7/22
     */
    @PostMapping("queryOtherEnt")
    public HttpResult queryOtherEnt(@RequestBody IdReqVo reqVo) {
        return HttpResult.ok(kwsEntService.queryOtherEnt(reqVo.getId()));
    }

    /**
     * @param reqVo 查询
     * @return  HttpResult
     * @desc: 客户列表分组个数
     * @author: czh
     * @date: 2023/9/14
     */
    @PostMapping("queryCustomerGroup")
    public HttpResult queryCustomer(@RequestBody EntFindPageReqVo reqVo) {
        return HttpResult.ok(kwsEntService.queryCustomerGroup(reqVo));
    }

    /**
     * @desc: 入驻认证/客户列表导出
     * @author: czh
     * @date: 2023/9/21
     */
    @PostMapping(value = "exportEntSettle", produces = MediaType.APPLICATION_JSON_VALUE)
    public void exportEntSettle(@RequestBody EntFindPageReqVo pageReqVo, HttpServletResponse response) {
        kwsEntService.exportEntSettle(pageReqVo, response);
    }



}
