package io.renren.modules.business.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.business.entity.BusinessDictEntity;
import io.renren.modules.business.entity.BusinessWorkerEntity;
import io.renren.modules.business.service.BusinessDictService;
import io.renren.modules.business.service.BusinessProjectService;
import io.renren.modules.business.service.BusinessSearchByLxService;
import io.renren.modules.business.service.BusinessWorkerService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * @author lsr
 * @version 2022/8/24
 * 立项跟踪控制器
 */
@RestController
@RequestMapping("business/businesssearchbylx")
public class BusinessSearchByLxController {

    @Autowired
    private BusinessWorkerService businessWorkerService;
    @Autowired
    private BusinessDictService businessDictService;
    @Autowired
    private BusinessProjectService businessProjectService;
    @Autowired
    private BusinessSearchByLxService businessSearchByLxService;

    /**
     * 获取所有的人员信息
     */
    @RequestMapping("/workerAllList")
    @RequiresPermissions("business:businesssearchbylx:list")
    public R workerAllList(@RequestParam Map<String, Object> params){
        List<BusinessWorkerEntity> page = businessWorkerService.selectAllContainsDeparture(params);
        return R.ok().put("page", page);
    }

    /**
     * 获取字典里所有的信息
     */
    @RequestMapping("/dictList")
    @RequiresPermissions("business:businesssearchbylx:list")
    public R dicList(@RequestParam Map<String, Object> params){
        // PageUtils page = businessDictService.queryPage(params);
        List<BusinessDictEntity> businessDictEntity = businessDictService.listWithTree();
        return R.ok().put("data", businessDictEntity);
    }

    /**
     * 获取立项列表
     */
    @RequestMapping("/projectList")
    @RequiresPermissions("business:businesssearchbylx:list")
    public R projectList(@RequestParam Map<String, Object> params){
        PageUtils page = businessProjectService.queryPage(params);
        //List<BusinessProjectEntity> page = businessProjectService.quaryListNoPage(params);
        //System.out.println(page);
        return R.ok().put("page", page);
    }

    /**
     * 获取的对应的统计的信息
     */
    @RequestMapping("/getTotal")
    @RequiresPermissions("business:businesssearchbylx:list")
    public R getTotal(@RequestParam Map<String, Object> params){
        //System.out.println(params);
        List<Map<String,Object>> page = businessProjectService.getTotal(params);
        return R.ok().put("page", page);
    }

    /**
     * 立项负责工人idList
     */
    @RequestMapping("/ddIdList")
    @RequiresPermissions("business:businesssearchbylx:list")
    public R ddIdList(){
        //System.out.println(params);
        List<Integer> ddIdList = businessProjectService.ddIdList();
        return R.ok().put("page", ddIdList);
    }

    /**
     * 根据立项Id  获取所有相关的数据
     */
    @RequestMapping("/info/{projectId}")
    @RequiresPermissions("business:businesssearchbylx:info")
    public R info(@PathVariable("projectId") Integer projectId){
        Map<String, Object> page = businessSearchByLxService.getAllInfoById(projectId);
        return R.ok().put("page", page);
    }

}
