package com.liang.controller;

import com.liang.WT.entity.ProjectEntity;
import com.liang.WT.service.PrjProjectService;
import com.liang.WT.service.ProgressService;
import com.liang.common.base.BaseController;
import com.liang.service.SysDictInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author ly
 * @Date 2025/3/21 14:33
 * @Version 1.0
 */
@Controller
@RequestMapping("/bugger")
public class BuggerController extends BaseController {
    @Resource
    private PrjProjectService pj;


    @Resource
    private SysDictInfoService sysDictInfoService;


    /**
     * 主页面
     * @return
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public String list(Model model){

        Map<String,String> map = sysDictInfoService.getDictMap("bug_project");
        model.addAttribute("bugproject",map);
        return "bug/list";
    }
    /**
     * 新建页面
     */

    @RequestMapping(value = "/add")
    public String add(Model model){
        Map<String,String> map = sysDictInfoService.getDictMap("bug_project");
        model.addAttribute("bugproject",map);

        return "bug/add";
    }

    /**
     * 编辑页面
     * @return
     */

    @RequestMapping(value = "/update/{id}",method = RequestMethod.GET)
    public String update(Model model,
                         @PathVariable Integer id){
        Map<String,String> map = sysDictInfoService.getDictMap("bug_project");
        model.addAttribute("bugproject",map);
        Map<String,Integer> maps = new HashMap<>();
        maps.put("id",id);
        List<ProjectEntity> list = pj.list(maps);
        if (list.size() == 1){
            model.addAttribute("projects",list.get(0));
        }
        return "bug/update";
    }

    /**
     * 查看页面
     * @return
     */

    @RequestMapping(value = "/view/{id}",method = RequestMethod.GET)
    public String view(Model model ,@PathVariable Integer id){
        Map<String,Integer> maps = new HashMap<>();
        maps.put("id",id);
        maps.put("xmId",id);
        List<ProjectEntity> list = pj.list(maps);
        if (list.size() == 1){
            model.addAttribute("projects",list.get(0));
            model.addAttribute("account",getSysUserAccount());
        }

        return "bug/view";
    }

    @RequestMapping(value = "/init/{id}",method = RequestMethod.GET)
    public String init(Model model,
                         @PathVariable Integer id){

        Map<String,Integer> maps = new HashMap<>();
        maps.put("id",id);
        List<ProjectEntity> list = pj.list(maps);
        if (list.size() == 1){
            model.addAttribute("projects",list.get(0));
        }
        return "bug/init";
    }
}
