package com.jeeplus.test.jobPosion.controller;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.jeeplus.aop.demo.annotation.DemoMode;
import com.jeeplus.aop.logging.annotation.ApiLog;
import com.jeeplus.core.excel.ExcelOptions;
import com.jeeplus.core.excel.ExportMode;
import com.jeeplus.core.excel.utils.EasyPoiUtil;
import com.jeeplus.core.query.QueryWrapperGenerator;
import com.jeeplus.sys.constant.enums.LogTypeEnum;
import com.jeeplus.sys.domain.Office;
import com.jeeplus.sys.service.OfficeService;
import com.jeeplus.sys.service.dto.UserDTO;
import com.jeeplus.sys.utils.StringUtils;
import com.jeeplus.sys.utils.UserUtils;
import com.jeeplus.test.jobPosion.domain.JobPosition;
import com.jeeplus.test.jobPosion.domain.Position;
import com.jeeplus.test.jobPosion.domain.PositionLog;
import com.jeeplus.test.jobPosion.service.JobPositionService;
import com.jeeplus.test.jobPosion.service.PositionLogService;
import com.jeeplus.test.jobPosion.service.PositionService;
import com.jeeplus.test.jobPosion.service.dto.JobPositionDTO;
import com.jeeplus.test.jobPosion.service.dto.PositionLogDTO;
import com.jeeplus.test.jobPosion.service.mapstruct.JobPositionWrapper;
import com.jeeplus.test.jobPosion.service.mapstruct.PositionLogWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;

@Api("职位体系变更记录管理")
@RestController
@RequestMapping(value = "/job/position_log")
public class PositionLogController {

    @Autowired
    private PositionLogService positionLogService;

    /**
     * 查询职位列表
     * @param positionLogDTO
     * @param page
     * @return
     * @throws Exception
     */
    @ApiLog("查询变更记录列表")
    @GetMapping("list")
    public ResponseEntity<IPage<PositionLog>> data(PositionLogDTO positionLogDTO, Page<PositionLog> page) throws Exception {
        PositionLog positionLog = PositionLogWrapper.INSTANCE.toEntity(positionLogDTO);
        QueryWrapper<PositionLog> queryWrapper = QueryWrapperGenerator.buildQueryCondition ( positionLog, PositionLog.class );
        queryWrapper.like(StringUtils.isNotBlank(positionLog.getCreateBy()),"su.login_name",positionLog.getCreateBy());
        if(ObjectUtil.isNotEmpty(positionLogDTO.getCreateDateStart())&&ObjectUtil.isNotEmpty(positionLogDTO.getCreateDateEnd())){
            queryWrapper.ge("pl.create_date",positionLogDTO.getCreateDateStart()).le("pl.create_date",positionLogDTO.getCreateDateEnd());
        }
        IPage<PositionLog> result = positionLogService.findList (page,queryWrapper);
        return ResponseEntity.ok (result);
    }

}
