package com.yh.saas.plugin.yiliangyiyun.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.yh.saas.plugin.yiliangyiyun.entity.SalePlanInfo;
import com.yh.saas.plugin.yiliangyiyun.service.ISalePlanInfoService;
import com.yh.saas.plugin.yiliangyiyun.service.IWarehouseInOutInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 记录销售计划 前端控制器
 * </p>
 *
 * @author Gongdc
 * @since 2021-08-04
 */
@RestController
@RequestMapping("/salePlanInfo")
public class SalePlanInfoController {
    @Autowired
    private ISalePlanInfoService salePlanInfoService;
    @Autowired
    private IWarehouseInOutInfoService warehouseInOutInfoService;

    /**
     * 查看销售计划
     * @param id
     * @return
     */
    @GetMapping("/getSalePlanInfo")
    public SalePlanInfo getSalePlanInfo(String id){
        return salePlanInfoService.getSalePlanInfo(id);
    }

    /**
     * 编辑销售计划
     * @param salePlanInfo
     * @return
     */
    @PostMapping("/api/editSalePlanInfo")
    public String editSalePlanInfo(@RequestBody SalePlanInfo salePlanInfo){
        return salePlanInfoService.editSalePlanInfo(salePlanInfo);
    }

    /**
     * 删除销售计划
     *  @param salePlanInfo
     * @return
     */
    @PostMapping("/api/deleteSalePlanInfo")
    public void deleteSalePlanInfo(@RequestBody SalePlanInfo salePlanInfo) {
        salePlanInfoService.deleteSalePlanInfo(salePlanInfo.getId());
    }

    /**
     * 销售计划列表
     * @param salePlanInfo
     * @return
     */
    @GetMapping("/selectSalePlanInfo")
    public Page<SalePlanInfo> selectSalePlanInfo(SalePlanInfo salePlanInfo) {
        return salePlanInfoService.selectSalePlanInfo(salePlanInfo);
    }

    /**
     * 添加销售计划
     * @param salePlanInfo
     * @return
     */
    @PostMapping("/api/insertSalePlanInfo")
    public String insertSalePlanInfo(@RequestBody SalePlanInfo salePlanInfo) {
        return salePlanInfoService.insertSalePlanInfo(salePlanInfo);
    }

    /**
     * 更改状态/基差/单价
     * @param salePlanInfo
     * @return
     */
    @PostMapping("/api/editStatus")
    public String editStatus(@RequestBody SalePlanInfo salePlanInfo){
        return salePlanInfoService.editStatus(salePlanInfo);

    }
    /**
     * 审核
     * @param salePlanInfo
     * @return
     */
    @PostMapping("/api/examine")
    public String examine(@RequestBody SalePlanInfo salePlanInfo){
        return salePlanInfoService.examine(salePlanInfo);

    }
    /**
     * 获取tips
     * @param phone
     * @return
     */
    @GetMapping("/getTips")
    public SalePlanInfo getTips(String  phone) {
        SalePlanInfo salePlanInfo = new SalePlanInfo();
        salePlanInfo.setTaskTip(warehouseInOutInfoService.selectCountByPhone(phone));
        salePlanInfo.setContractTip(0);
        salePlanInfo.setMyTip(salePlanInfo.getContractTip()+salePlanInfo.getTaskTip());
        return salePlanInfo;
    }
}

