package com.njzscloud.dispose.cst.org.controller;

import com.njzscloud.common.core.utils.R;
import com.njzscloud.common.mp.support.PageParam;
import com.njzscloud.common.mp.support.PageResult;
import com.njzscloud.dispose.cst.org.pojo.entity.OrgEntity;
import com.njzscloud.dispose.cst.org.pojo.param.AddOrgParam;
import com.njzscloud.dispose.cst.org.pojo.param.OrgPagingParam;
import com.njzscloud.dispose.cst.org.pojo.result.OrgResult;
import com.njzscloud.dispose.cst.org.service.OrgService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 组织信息
 */
@Slf4j
@RestController
@RequestMapping("/org")
@RequiredArgsConstructor
public class OrgController {
    private final OrgService orgService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public R<?> add(@RequestBody AddOrgParam addOrgParam) {
        orgService.add(addOrgParam);
        return R.success();
    }

    /**
     * 修改
     */
    @PostMapping("/modify")
    public R<?> modify(@RequestBody OrgEntity orgEntity) {
        orgService.modify(orgEntity);
        return R.success();
    }

    /**
     * 删除
     */
    @PostMapping("/del")
    public R<?> del(@RequestBody List<Long> ids) {
        orgService.del(ids);
        return R.success();
    }

    /**
     * 详情
     */
    @GetMapping("/detail")
    public R<OrgEntity> detail(@RequestParam("id") Long id) {
        return R.success(orgService.detail(id));
    }

    /**
     * 申请加入企业
     */
    @GetMapping("/apply")
    public R<?> apply(@RequestParam("customerId") Long customerId,
                      @RequestParam("orgId") Long orgId) {
        orgService.apply(customerId, orgId);
        return R.success();
    }

    /**
     * 退出企业
     */
    @GetMapping("/quit")
    public R<?> quit(@RequestParam("id") Long customerId) {
        orgService.quit(customerId);
        return R.success();
    }

    /**
     * 同意/拒绝申请
     */
    @GetMapping("/agree")
    public R<?> agree(@RequestParam("id") Long id,
                      @RequestParam("isAgree") Boolean isAgree,
                      @RequestParam("cause") String cause) {
        orgService.agree(id, isAgree, cause);
        return R.success();
    }

    /**
     * 分页查询
     */
    @GetMapping("/paging")
    public R<PageResult<OrgResult>> paging(PageParam pageParam, OrgPagingParam orgPagingParam) {
        return R.success(orgService.paging(pageParam, orgPagingParam));
    }

    /**
     * 运输方分页查询
     *
     * @param pageParam 分页参数
     * @param sortType 排序类型：TIME-按创建时间倒序、CLEARANCE-按清运数排序、EVALUATE-按综合评价倒序、DISTANCE-按距离正序
     * @param lng      经度（DISTANCE 排序时必传）
     * @param lat      纬度（DISTANCE 排序时必传）
     */
    @GetMapping("/transOrgPaging")
    public R<PageResult<OrgResult>> transOrgPaging(PageParam pageParam,
                                                   @RequestParam(value = "sortType", required = false) String sortType,
                                                   @RequestParam(value = "lng", required = false) Double lng,
                                                   @RequestParam(value = "lat", required = false) Double lat) {
        return R.success(orgService.transOrgPaging(pageParam, sortType, lng, lat));
    }

}
