package com.jwipc.sys.controller.pc;

import com.jwipc.page.PageView;
import com.jwipc.security.LoginUtil;
import com.jwipc.sys.dto.CompanyDTO;
import com.jwipc.sys.logic.CompanyLogic;
import com.jwipc.sys.model.query.CompanyQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
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;

/**
 * @author shenyang.ou
 * @date 2024/1/29 16:01
 * @desc 公司主数据
 */
@RestController
@RequestMapping(MODULE_ROOT + "/company/rest")
@RequiredArgsConstructor
public class CompanyRestController {
    private final CompanyLogic companyLogic;
    /**
     * 列表
     *
     * @param query
     * @return
     */
    @RequestMapping("/list")
    public PageView list(CompanyQuery query) {
        return companyLogic.findByPage(query);
    }
    /**
     * 公司主数据
     * @return 信息
     */
    @RequestMapping("/listAll")
    public ResponseEntity<List<CompanyDTO>> listAll(CompanyQuery query){
        if (query.getIsAuthority()!=null){
            query.setUserId(query.getIsAuthority()==1? LoginUtil.getUserId():null);
        }
        return ResponseEntity.ok(companyLogic.listAll(query));
    }
}
