package org.stm.plan.change.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.stm.plan.main.constant.PlanFlag;
import org.stm.plan.main.entity.StPlanMan;
import org.stm.plan.main.service.IStPlanManService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
* @Description: 计划编制
* @Author: jeecg-boot
* @Date:   2023-07-15
* @Version: V1.0
*/
@Api(tags="计划编制")
@RestController
@RequestMapping("/plan.change/stPlanMan")
@Slf4j
public class StPlanChangeController extends JeecgController<StPlanMan, IStPlanManService> {
   @Autowired
   private IStPlanManService stPlanManService;
   
   /**
    * 分页列表查询
    *
    * @param stPlanMan
    * @param pageNo
    * @param pageSize
    * @param req
    * @return
    */
   //@AutoLog(value = "计划编制-分页列表查询")
   @ApiOperation(value="计划改变-分页列表查询", notes="计划编制-分页列表查询")
   @GetMapping(value = "/list")
   public Result<IPage<StPlanMan>> queryPageList(StPlanMan stPlanMan,
                                  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                  HttpServletRequest req) {
       QueryWrapper<StPlanMan> queryWrapper = QueryGenerator.initQueryWrapper(stPlanMan, req.getParameterMap());
       queryWrapper.in("PLAN_FLAG",PlanFlag.CHANGE_LIST);
       Page<StPlanMan> page = new Page<StPlanMan>(pageNo, pageSize);
       IPage<StPlanMan> pageList = stPlanManService.page(page, queryWrapper);
       return Result.OK(pageList);
   }

    /**
     *  编辑
     *
     * @param stPlanMan
     * @return
     */
    @AutoLog(value = "计划变更-变更")
    @ApiOperation(value="计划变更-变更", notes="计划变更-变更")
    @RequiresPermissions("plan.change:st_plan_man:change")
    @RequestMapping(value = "/handleChange", method = {RequestMethod.PUT,RequestMethod.POST})
    public Result<String> handleChange(@RequestBody StPlanMan stPlanMan) {
        stPlanManService.handleChange(stPlanMan);
        return Result.OK("操作成功!");
    }

    /**
     *  编辑
     *
     * @param stPlanMan
     * @return
     */
    @AutoLog(value = "计划变更-废止")
    @ApiOperation(value="计划变更-废止", notes="计划变更-废止")
    @RequiresPermissions("plan.change:st_plan_man:repeal")
    @RequestMapping(value = "/handleRepeal", method = {RequestMethod.PUT,RequestMethod.POST})
    public Result<String> handleRepeal(@RequestBody StPlanMan stPlanMan) {
        stPlanManService.handleChange(stPlanMan);
        return Result.OK("操作成功!");
    }

}
