package cn.ezhizao.project.business.controller;

import cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.framework.web.page.TableDataInfo;
import cn.ezhizao.project.business.domain.BizDayworkItemConsult;
import cn.ezhizao.project.business.service.IBizDayworkItemConsultService;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;


/**
 * 咨询Controller
 *
 * @author ezhizao
 * 日期 2023-11-14
 */
@RestController
@RequestMapping("/business/consult")
public class BizDayworkItemConsultController extends BaseController {
    @Resource
    private IBizDayworkItemConsultService iBizDayworkItemConsultService;
    @Resource
    private HttpServletRequest request;

    @PostMapping("/list")
    public TableDataInfo list(@RequestBody Map<String, Object> data) throws NoSuchFieldException, IllegalAccessException, JsonProcessingException {
        // 分页
        startPage();
        List<BizDayworkItemConsult> list = iBizDayworkItemConsultService.getList(data);
        return getDataTable(list);
    }

    /**
     * 获取咨询详细信息
     */
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(iBizDayworkItemConsultService.getById(id));
    }

    /**
     * 新增咨询
     */
    @Log(title = "咨询", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/save")
    public AjaxResult save(@RequestBody BizDayworkItemConsult bizDayworkItemConsult) throws NoSuchFieldException, IllegalAccessException {
        final String tenantId = request.getHeader("tenantId");
        bizDayworkItemConsult.setTenantId(Long.valueOf(tenantId));
        return toAjax(iBizDayworkItemConsultService.saveOrUpdate(bizDayworkItemConsult));
    }

    /**
     * 删除咨询
     */
    @PreAuthorize("@ss.hasPermi('business:consult:remove')")
    @Log(title = "咨询", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(iBizDayworkItemConsultService.removeBatchByIds(ids));
    }
}
