package com.njzscloud.supervisory.biz.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.common.security.util.SecurityUtil;
import com.njzscloud.supervisory.biz.constant.AuditStatus;
import com.njzscloud.supervisory.biz.pojo.entity.BizProjectEntity;
import com.njzscloud.supervisory.biz.pojo.result.SearchBizProjectResult;
import com.njzscloud.supervisory.biz.service.BizProjectService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目信息
 */
@Slf4j
@RestController
@RequestMapping("/biz_project")
@RequiredArgsConstructor
public class BizProjectController {

    private final BizProjectService bizProjectService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public R<?> add(@RequestBody BizProjectEntity bizProjectEntity) {
        Long userId = SecurityUtil.currentUserId();
        bizProjectService.add(bizProjectEntity.setUserId(userId));
        return R.success();
    }

    /**
     * 修改
     */
    @PostMapping("/modify")
    public R<?> modify(@RequestBody BizProjectEntity bizProjectEntity) {
        bizProjectService.modify(bizProjectEntity);
        return R.success();
    }

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

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

    /**
     * 分页查询
     */
    @GetMapping("/paging")
    public R<PageResult<SearchBizProjectResult>> paging(PageParam pageParam, BizProjectEntity bizProjectEntity) {
        return R.success(bizProjectService.paging(pageParam, bizProjectEntity));
    }

    /**
     * 查询合作的清运公司
     */
    @GetMapping("/paging_trans")
    public R<PageResult<SearchBizProjectResult>> pagingTrans(PageParam pageParam, BizProjectEntity bizProjectEntity) {
        return R.success(bizProjectService.pagingTrans(pageParam, bizProjectEntity));
    }

    /**
     * 审核
     *
     * @param id Id
     */
    @GetMapping("/audit")
    public R<?> audit(@RequestParam Long id,
                      @RequestParam AuditStatus auditStatus,
                      @RequestParam(required = false, defaultValue = "") String auditMemo) {
        bizProjectService.audit(id, auditStatus, auditMemo);
        return R.success();
    }

    /**
     * 撤销项目
     *
     * @param id Id
     */
    @PostMapping("/cancel")
    public R<?> cancel(@RequestParam Long id) {
        bizProjectService.cancel(id);
        return R.success();
    }
}
