package com.bonus.bracelet.controller;


import com.bonus.bracelet.service.IQueryConstructionService;
import com.bonus.common.core.utils.poi.ExcelUtil;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.common.entity.bracelet.vo.QueryConstruction;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import com.bonus.common.security.annotation.RequiresPermissions;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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 javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 岗位信息操作处理
 * 
 * @author bonus
 */
@RestController
@RequestMapping("/construction")
@Slf4j
public class QueryConstructionController extends BaseController
{
    @Autowired
    private IQueryConstructionService constructionService;

    /**
     * 获取项目列表
     */
    @RequiresPermissions("bracelet:construction:list")
    @GetMapping("/list")
    @SysLog(title = "施工记录管理", businessType = OperaType.QUERY,module = "综合查询->施工记录管理")
    public TableDataInfo list(QueryConstruction construction) {
       try{
           startPage();
           List<QueryConstruction> list = constructionService.selectConstructionList(construction);
           return getDataTable(list);
       }catch (Exception e){
           log.error(e.toString(),e);
       }
       return  getDataTableError(new ArrayList<>());
    }

    @RequiresPermissions("bracelet:construction:export")
    @PostMapping("/export")
    @SysLog(title = "施工记录管理", businessType = OperaType.EXPORT,module = "综合查询->施工记录管理")
    public void export(HttpServletResponse response, QueryConstruction construction) {
        try{
            List<QueryConstruction> list = constructionService.selectConstructionList(construction);
            ExcelUtil<QueryConstruction> util = new ExcelUtil<QueryConstruction>(QueryConstruction.class);
            util.exportExcel(response, list, "项目部数据");
        }catch (Exception e){
            log.error(e.toString(),e);
        }
    }
}
