package com.jwipc.sys.controller.pc;

import com.jwipc.page.PageView;
import com.jwipc.sys.dto.PurchaseOrgDTO;
import com.jwipc.sys.dto.UserPurOrgTreeDTO;
import com.jwipc.sys.logic.PurchaseOrgLogic;
import com.jwipc.sys.model.param.PurchaseOrgParam;
import com.jwipc.sys.model.query.PurchaseOrgQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.jwipc.sys.constant.ModuleConst.MODULE_ROOT;

/**
 * <p> </p>
 *
 * @author ZhangJie
 * @version 1.0
 * @since JDK 1.8
 */
@RequestMapping(MODULE_ROOT + "/purchaseOrg/rest/")
@RequiredArgsConstructor
@RestController
public class PurchaseOrgRestController {
    private final PurchaseOrgLogic purchaseOrgLogic;
    /**
     * 列表
     *
     * @param query
     * @return
     */
    @RequestMapping("/list")
    public PageView list(PurchaseOrgQuery query) {
        return purchaseOrgLogic.findByPage(query);
    }

    /**
     * 下拉列表
     *
     * @param query
     * @return
     */
    @RequestMapping("/listAll")
    public ResponseEntity<List<PurchaseOrgDTO>> listAll(PurchaseOrgQuery query) {
        return ResponseEntity.ok(purchaseOrgLogic.listAll(query));
    }

    /**
     * 保存更新
     * @param param 参数
     */
    @PostMapping("/saveOrUpdate")
    public ResponseEntity saveOrUpdate(PurchaseOrgParam param){
        purchaseOrgLogic.saveOrUpdate(param);
        return ResponseEntity.ok(true);
    }

    /**
     * 删除
     *
     * @param purchaseOrgCode 参数
     */
    @PostMapping("/remove")
    public ResponseEntity remove(String purchaseOrgCode) {
        purchaseOrgLogic.remove(purchaseOrgCode);
        return ResponseEntity.ok(true);
    }

    @GetMapping("getForTree")
    public ResponseEntity getForTree(Long userId) {
        List<UserPurOrgTreeDTO> list = purchaseOrgLogic.getForTree(userId);
        return ResponseEntity.ok(list);
    }
}
