package org.jeecg.modules.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 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.jeecg.modules.stm.plan.main.constant.PlanFlag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.jeecg.modules.stm.plan.main.entity.StPlanMan;
import org.jeecg.modules.stm.plan.main.service.IStPlanManService;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

/**
* @Description: 计划编制
* @Author: jeecg-boot
* @Date:   2023-07-15
* @Version: V1.0
*/
  
@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 = "计划编制-分页列表查询")
     
   @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 = "计划变更-变更")
      
    @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 = "计划变更-废止")
      
    @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("操作成功!");
    }

}
