package com.sunxung.factoring.web.sys;


import com.sunxung.factoring.entity.CommonVO;
import com.sunxung.factoring.entity.GridPage;
import com.sunxung.factoring.entity.ResponseJson;
import com.sunxung.factoring.entity.sys.request.ClientUserQueryRequest;
import com.sunxung.factoring.entity.sys.request.DistributePMRequest;
import com.sunxung.factoring.entity.sys.request.DistributeRMRequest;
import com.sunxung.factoring.entity.sys.vo.ClientUserVO;
import com.sunxung.factoring.service.sys.ClientUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("clientUser")
public class ClientUserController {


  @Autowired
  private ClientUserService clientUserService;

  /**
   * 列表查询
   * @param clientUserQueryRequest
   * @return
   */
  @GetMapping("list")
  public Object do_list(ClientUserQueryRequest clientUserQueryRequest) {

    GridPage<ClientUserVO> clientUserVOGridPage = clientUserService.pageList(
        clientUserQueryRequest);
    return clientUserVOGridPage;
  }


  /**
   * 认领
   * @param clientUserId
   * @return
   */
  @PostMapping("receive/{clientUserId}")
  public Object do_receive(@PathVariable("clientUserId") Long clientUserId) {
     clientUserService.receive(clientUserId);
     return true;
  }


  /**
   * 分配项目经理
   * @param clientUserId
   * @return
   */
  @PostMapping("distributePM/{clientUserId}/{projectManagerId}/{flag}")
  public Object do_distributeProjectManager(@PathVariable("clientUserId") Long clientUserId,
      @PathVariable("projectManagerId") Long projectManagerId,
      @PathVariable("flag") boolean flag) {
    clientUserService.distributeProjectManager(clientUserId,projectManagerId,flag);
    return true;
  }

  /**
   * 批量---分配项目经理
   * @param distributePMRequest
   * @return
   */
  @PostMapping("distributePMs")
  public Object do_distributeProjectManagers(@Validated  @RequestBody  DistributePMRequest distributePMRequest) {
    clientUserService.distributeProjectManagers(distributePMRequest);
    return true;
  }


  /**
   * 分配风险经理--并移交业务
   * @param clientUserId
   * @return
   */
  @PostMapping("distributeRM/{clientUserId}/{riskManagerId}")
  public Object do_distributeRiskManager(@PathVariable("clientUserId") Long clientUserId,@PathVariable("riskManagerId") Long riskManagerId) {
    clientUserService.distributeRiskManager(clientUserId,riskManagerId);
    return true;
  }


  /**
   * 批量 -----分配风险经理
   * @param distributeRMRequest
   * @return
   */
  @PostMapping("distributeRMs")
  public Object do_distributeRiskManagers(@Validated @RequestBody  DistributeRMRequest distributeRMRequest) {
    clientUserService.distributeRiskManagers(distributeRMRequest);
    return true;
  }



  /**
   * 获取 项目经理待选列表
   * @param clientUserId
   * @return
   */
  @GetMapping("projectManagers")
  public Object do_projectManagers(@RequestParam(value = "clientUserId",required=false) Long clientUserId) {
    List<CommonVO> pMs = clientUserService.getPMs(clientUserId);
    return pMs;
  }



  /**
   * 获取 风险经理待选列表
   * @return
   */
  @GetMapping("riskManagers")
  public Object do_riskManagers() {
    List<CommonVO> rMs = clientUserService.getRMs();
    return rMs;
  }

  /**
   * 重置密码 a123456
   * @return
   */
  @GetMapping("resetPassword")
  public ResponseJson resetPassword(@RequestParam Long clientUserId) {
    clientUserService.resetPassword(clientUserId);
    return new ResponseJson();
  }

}
