package com.ym.mec.web.controller.education;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.entity.InspectionItemPlan;
import com.ym.mec.biz.dal.page.InspectionItemPlanQueryInfo;
import com.ym.mec.biz.service.InspectionItemPlanService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;
import com.ym.mec.common.page.PageInfo;
import com.ym.mec.util.date.DateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags = "教务巡查事项日程")
@RequestMapping("eduInspectionItemPlan")
@RestController
public class EduInspectionItemPlanController extends BaseController {
    @Autowired
    private InspectionItemPlanService inspectionItemPlanService;
    @Resource
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "巡查任务事项日程列表")
    @GetMapping("/queryPage")
    public HttpResponseResult<PageInfo<InspectionItemPlan>> queryPage(InspectionItemPlanQueryInfo queryInfo) {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            return failed("用户信息获取失败");
        }
        queryInfo.setUserId(sysUser.getId());
        if (queryInfo.getMonth() != null) {
            queryInfo.setStartTime(DateUtil.getFirstDayOfMonth(queryInfo.getMonth()));
            queryInfo.setEndTime(DateUtil.getLastTimeWithDay(DateUtil.getLastDayOfMonth(queryInfo.getMonth())));
        }
        return succeed(inspectionItemPlanService.getPageList(queryInfo));
    }
}
