package com.malk.lingmingguangzi.controller;

import com.malk.lingmingguangzi.service.LingmingguangziService;
import com.malk.server.common.McR;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.Map;
import java.util.Objects;

@RestController
@Slf4j
public class LingmingguangziController {
    @Autowired
    private LingmingguangziService lingmingguangziService;

    @GetMapping("/test")
    public McR test() {
        return lingmingguangziService.test();
    }

    /**
     * 获取车载客户回收问卷数量
     */
    @GetMapping("/getCustomerQuestionnaireCount")
    public McR getVehicleCustomerCount(Long start, Long end) {
        return lingmingguangziService.getCustomerQuestionnaireCount(start, end);
    }

    /**
     * 获取消费客户回收问卷列表
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/getCustomerQuestionnaireCount2")
    public McR getCustomerQuestionnaireCount2(Long start, Long end) {
        return lingmingguangziService.getCustomerQuestionnaireCount2(start, end);
    }

    /**
     * 客户新增后更新线索状态
     * @param map
     * @return
     */
    @PostMapping("/updateClueStatus")
    public McR updateClue(@RequestBody Map map) {
        return lingmingguangziService.updateClueStatus(map);
    }
    /**
     * 获取tb转阶段申请交付件等详情
     * @param
     * @return
     */
    @GetMapping("/getTbStageDetails")
    public McR getTbStageDetails(String projectName,String projectId,String parentTaskId) {
        return lingmingguangziService.getTbStageDetails(projectName,projectId,parentTaskId);
    }

    /**
     * 创建tb项目
     * @param map
     * @return
     */
    @PostMapping("/createTbProject")
    public McR createTbProject(@RequestBody Map map) {
        return lingmingguangziService.createTbProject(map);
    }

    /**
     * 获取tb转阶段选项
     * @return
     */
    @GetMapping("/getTbStageOptions")
    public McR getTbStageOptions(String projectName,String projectId,String stageName) {
        return lingmingguangziService.getTbStageOptions(projectName,projectId,stageName);
    }

    /**
     * 新增客户
     * @param map
     * @return
     */
    @PostMapping("/addCustomer")
    public McR addCustomer(@RequestBody Map map) {
        return lingmingguangziService.addCustomer(map);
    }

    /**
     * 更新客户
     * @param map
     * @return
     */
    @PostMapping("/updateCustomer")
    public McR updateCustomer(@RequestBody Map map) {
        return lingmingguangziService.updateCustomer(map);
    }

    /**
     * 线索选择关联客户后新增联系人
     * @param map
     * @return
     */
    @PostMapping("/addContacts")
    public McR addContacts(@RequestBody Map map){
        return lingmingguangziService.addContacts(map);
    }


    //更新客户信息流程
    @PostMapping("/updateCustomerProcess")
    public McR updateCustomerProcess(@RequestBody Map map) {
        return lingmingguangziService.updateCustomerProcess(map);
    }

    /**
     * 获取产品交付状态
     * @param keyword
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/getProductDeliveryStatus")
    public McR getProductDeliveryStatus(String keyword,int pageNo,int pageSize,String type) {
        return lingmingguangziService.getProductDeliveryStatus(keyword,pageNo,pageSize,type);
    }

    /**
     * 新增销售订单
     * @param map
     * @return
     */
    @PostMapping("/addSaleOrder")
    public McR addSaleOrder(@RequestBody Map map) {
        return lingmingguangziService.addSaleOrder(map);
    }

    /**
     * 更新销售订单
     * @param map
     * @return
     */
    /*@PostMapping("/updateSaleOrder")
    public McR updateSaleOrder(@RequestBody Map map) {
        return lingmingguangziService.updateSaleOrder(map);
    }*/

    /**
     * 销售计划发起销售周报
     * @param map
     * @return
     */
    @PostMapping("/addWeeklyReport")
    public McR addWeeklyReport(@RequestBody Map map) {
        return lingmingguangziService.addWeeklyReport(map);
    }

    /**
     * 认领商机
     * @param map
     * @return
     */
    @PostMapping("/claimBusinessOpportunities")
    public McR claimBusinessOpportunities(@RequestBody Map map) {
        return lingmingguangziService.claimBusinessOpportunities(map);
    }
    /**
     * 定时更新工序
     */
    @Scheduled(cron = "0 0 0 * * ? ")
    @GetMapping("/updateProcess")
    public McR updateProcess() {
        lingmingguangziService.updateProcess();
        return McR.success();
    }

    /**
     * 定时更新币别
     * @return
     */
    @Scheduled(cron = "0 0 0 * * ? ")
    @GetMapping("/updateCurrency")
    public McR updateCurrency() {
        lingmingguangziService.updateCurrency();
        return McR.success();
    }

    /**
     * 定时更新税率
     * @return
     */
    @Scheduled(cron = "0 0 0 * * ? ")
    @GetMapping("/updateTaxRate")
    public McR updateTaxRate() {
        lingmingguangziService.updateTaxRate();
        return McR.success();
    }

    /**
     * 终止流程
     * @param map
     * @return
     */
    @PostMapping("/stopProcess")
    public McR stopProcess(@RequestBody Map map) {
        return lingmingguangziService.stopProcess(map);
    }

    @GetMapping("/testDownloadFile")
    public McR downloadFile(String ydDownloadUrl,String path,String fileName) throws IOException {
        lingmingguangziService.downloadFile(ydDownloadUrl,path,fileName);
        return McR.success();
    }
}
