package com.hys.app.controller.erp.use;

import com.hys.app.framework.database.WebPage;
import com.hys.app.model.erp.dto.EnterpriseDTO;
import com.hys.app.model.erp.dto.EnterpriseQueryParams;
import com.hys.app.model.erp.vo.EnterpriseVO;
import com.hys.app.model.support.LogClient;
import com.hys.app.model.support.validator.annotation.Log;
import com.hys.app.service.erp.EnterpriseManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 企业 API
 *
 * @author 张崧
 * 2024-03-25 15:44:10
 */
@RestController
@RequestMapping("/admin/erp/enterprise")
@Api(tags = "企业API")
@Validated
public class EnterpriseController {

    @Autowired
    private EnterpriseManager enterpriseManager;

    @ApiOperation(value = "分页列表")
    @GetMapping
    public WebPage<EnterpriseVO> list(EnterpriseQueryParams queryParams) {
        return enterpriseManager.list(queryParams);
    }

    @ApiOperation(value = "添加")
    @PostMapping
    @Log(client = LogClient.admin, detail = "创建名称为[${enterpriseDTO.name}]的部门信息")
    public void add(@RequestBody @Valid EnterpriseDTO enterpriseDTO) {
        enterpriseManager.add(enterpriseDTO);
    }

    @ApiOperation(value = "修改")
    @PutMapping("/{id}")
    @Log(client = LogClient.admin, detail = "修改名称为[${enterpriseDTO.name}]的部门信息")
    public void edit(@PathVariable Long id, @RequestBody @Valid EnterpriseDTO enterpriseDTO) {
        enterpriseDTO.setId(id);
        enterpriseManager.edit(enterpriseDTO);
    }

    @ApiOperation(value = "查询")
    @GetMapping("/{id}")
    public EnterpriseVO getDetail(@PathVariable Long id) {
        return enterpriseManager.getDetail(id);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/{ids}")
    @Log(client = LogClient.admin, detail = "删除id为[${ids}]的部门信息")
    public void delete(@PathVariable List<Long> ids) {
        enterpriseManager.delete(ids);
    }

}

