package io.renren.modules.business.controller;

import io.renren.common.utils.R;
import io.renren.modules.business.entity.BusinessPlanTwoEntity;
import io.renren.modules.business.entity.BusinessProjectEntity;
import io.renren.modules.business.service.BusinessPlanTwoService;
import io.renren.modules.business.service.BusinessProjectService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 两周计划
 *
 * @author jiaqiao
 * @email jiaqiao@163.com
 * @date 2022-10-11 11:40:25
 */
@RestController
@RequestMapping("business/businessplantwo")
public class BusinessPlanTwoController {
    @Autowired
    private BusinessPlanTwoService businessPlanTwoService;
    @Autowired
    private BusinessProjectService businessProjectService;

    /**
     * 列表
     */
    /*@RequestMapping("/list")
    @RequiresPermissions("business:businessplantwo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = businessPlanTwoService.queryPage(params);
        return R.ok().put("page", page);
    }*/
    /**
     * 根据时间区间获取列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("business:businessplantwo:list")
    public R list(@RequestParam Map<String, Object> params){
        BusinessPlanTwoEntity BusinessPlanTwoEntity = businessPlanTwoService.getMaxTime();
        params.put("twoEditTime",BusinessPlanTwoEntity.getTwoEditTime());
        List<BusinessPlanTwoEntity> page = businessPlanTwoService.queryList(params);
        return R.ok().put("page", page);
    }

    /**
     * 根据ids获取立项数据
     */
    @RequestMapping("/addList/{ids}")
    @RequiresPermissions("business:businessplantwo:info")
    public R addList(@PathVariable("ids") String ids){
        List<BusinessProjectEntity> page = businessProjectService.queryPerojectList(ids);
        return R.ok().put("businessPlanTwo", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("business:businessplantwo:info")
    public R info(@PathVariable("id") Integer id){
		BusinessPlanTwoEntity businessPlanTwo = businessPlanTwoService.getById(id);
        return R.ok().put("businessPlanTwo", businessPlanTwo);
    }



    /**
     * 立项详情信息
      */
    @RequestMapping("/projectInfo/{id}")
    @RequiresPermissions("business:businessplantwo:info")
    public R projectInfo(@PathVariable("id") Integer id){
        BusinessProjectEntity page = businessProjectService.projectInfo(id);
        return R.ok().put("page", page);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("business:businessplantwo:save")
    public R save(@RequestBody BusinessPlanTwoEntity businessPlanTwo){
		businessPlanTwoService.save(businessPlanTwo);
        return R.ok();
    }

    /**
     * 新保存  此方法包含  新增和删除需要传入 saveIds 和 deleteIds
     */
    @RequestMapping("/newSave")
    @RequiresPermissions("business:businessplantwo:save")
    public R newSave(@RequestParam Map<String, Object> params){
        businessPlanTwoService.newSave(params);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("business:businessplantwo:update")
    public R update(@RequestBody BusinessPlanTwoEntity businessPlanTwo){
		businessPlanTwoService.updateById(businessPlanTwo);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("business:businessplantwo:delete")
    public R delete(@RequestBody Integer[] ids){
		businessPlanTwoService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
