package com.njcn.csdevice.controller.project;

import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.csdevice.pojo.param.CsMarketDataParam;
import com.njcn.csdevice.pojo.param.EngineerIdParam;
import com.njcn.csdevice.pojo.po.CsLedger;
import com.njcn.csdevice.pojo.vo.CsLedgerVO;
import com.njcn.csdevice.pojo.vo.CsMarketDataVO;
import com.njcn.csdevice.service.CsLinePOService;
import com.njcn.csdevice.service.CsMarketDataService;
import com.njcn.web.controller.BaseController;
import com.njcn.web.utils.RequestUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Description:
 * Date: 2023/7/31  9:28【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@RestController
@Slf4j
@Api(tags = "营销,工程数据配置")
@AllArgsConstructor
@RequestMapping("/csMarketData")
public class CsMarketDataController extends BaseController {
    private final CsMarketDataService csMarketDataService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/add")
    @ApiOperation("新增营销,工程数据")
    @ApiImplicitParam(name = "csMarketDataParams", value = "新增营销数据参数", required = true)
    public HttpResult<Boolean> add( @RequestBody List<CsMarketDataParam> csMarketDataParams){
        String methodDescribe = getMethodDescribe("add");

        Boolean flag = csMarketDataService.add(csMarketDataParams);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/follow")
    @ApiOperation("工程人员新增关注")
    @ApiImplicitParam(name = "engineerIdParams", value = "新增营销数据参数", required = true)
    public HttpResult<Boolean> follow( @RequestBody EngineerIdParam engineerIdParams){
        String methodDescribe = getMethodDescribe("follow");

        Boolean flag = csMarketDataService.follow(engineerIdParams);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/remove")
    @ApiOperation("移除营销,工程数据")
//    @ApiImplicitParam(name = "ids", value = "删除id集合", required = true)
    public HttpResult<Boolean> remove(@RequestParam("ids") List<String> ids){
        String methodDescribe = getMethodDescribe("remove");

        Boolean flag = csMarketDataService.removeByIds(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryByUseId")
    @ApiOperation("查询营销,工程数据")
    public HttpResult<List<CsMarketDataVO>> queryByUseId(@RequestParam("userId")String userId){
        String methodDescribe = getMethodDescribe("queryByUseId");

        List<CsMarketDataVO> list = csMarketDataService.queryByUseId(userId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryEnginnerByUseId")
    @ApiOperation("查询营销,工程人员未选择的工程")
    public HttpResult<List<CsLedger>> queryEnginnerByUseId(@RequestParam("userId")String userId){
        String methodDescribe = getMethodDescribe("queryByUseId");

        List<CsLedger> list = csMarketDataService.queryEnginnerByUseId(userId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryAllEnginner")
    @ApiOperation("查询营销,工程人员工程")
    public HttpResult<List<CsMarketDataVO>> queryAllEnginner(){
        String methodDescribe = getMethodDescribe("queryAllEnginner");
        String userId = RequestUtil.getUserIndex();
        List<CsMarketDataVO> list = csMarketDataService.queryAllEnginner(userId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/insert")
    @ApiOperation("根据用户、工程新增数据")
    public HttpResult<Boolean> insertData(@RequestParam("userId")String userId, @RequestParam("engineeringId")String engineeringId){
        String methodDescribe = getMethodDescribe("insertData");
        Boolean result = csMarketDataService.insertData(userId,engineeringId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }
}
