package com.jeeplus.modules.sg.picking.activiti.web;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.modules.act.entity.Act;
import com.jeeplus.modules.act.service.ActProcessService;
import com.jeeplus.modules.act.service.ActTaskService;
import com.jeeplus.modules.sg.managementcenter.activiti.service.ConstructionService;
import com.jeeplus.modules.sg.managementcenter.materialProvided.service.MaterialProvidedService;
import com.jeeplus.modules.sg.managementcenter.project.service.ProjectService;
import com.jeeplus.modules.sg.picking.activiti.entity.PickIng;
import com.jeeplus.modules.sg.picking.activiti.entity.PickList;
import com.jeeplus.modules.sg.picking.activiti.entity.ProjectNumber;
import com.jeeplus.modules.sg.picking.activiti.entity.ShowList;
import com.jeeplus.modules.sg.picking.activiti.service.PickIngService;
import com.jeeplus.modules.sg.picking.activiti.service.ShowListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author enford
 * 物资上报
 */
@Controller
@RequestMapping(value = "${adminPath}/picking/materialReport")
public class MaterialReportController extends BaseController {

    @Autowired
    private PickIngService pickIngService;
    @Autowired
    private ShowListService showListService;
    @Autowired
    private ActProcessService actProcessService;
    @Autowired
    private ActTaskService actTaskService;
    @Autowired
    private ConstructionService constructionService;
    @Autowired
    private ProjectService projectService;
    @Autowired
    private MaterialProvidedService materialProvidedService;

    /**
     * 填写项目表
     */
    @RequestMapping(value = "list")
    public String form(ShowList showList, Model model) {
        String procInsId = showList.getAct().getProcInsId();
        String s = pickIngService.selectVersion(procInsId);
        ProjectNumber projectNumber = pickIngService.projectNumber(procInsId);
        PickIng pickIng = new PickIng();
        List<PickList> pickListList = pickIngService.newAllList(pickIng, s);
        model.addAttribute("showList", showList);
        model.addAttribute("projectNumber", projectNumber);
        model.addAttribute("pickListList", pickListList);
        return "modules/sg/picking/activiti/materialReport";
    }

    /**
     * 配网物资专职
     */
    @RequestMapping(value = "listMaterial")
    public String formMaterial(ShowList showList, Model model, Act act) {
        model.addAttribute("showList", showList);
        ProjectNumber projectNumber = pickIngService.projectNumber(showList.getProcInsId());
        model.addAttribute("projectNumber", projectNumber);
        model.addAttribute("act", act);
        return "modules/sg/picking/activiti/materialReportForm";
    }

    /**
     * 模块清单显示页面
     * */
    @ResponseBody
    @RequestMapping(value = "constructionTemData")
    public Map<String, Object> constructionTemData(ShowList showList, String procInsId, HttpServletRequest request, HttpServletResponse response, Model model) {
        Page<ShowList> page = showListService.findMaterialReport(new Page<ShowList>(request, response), showList);
        return getBootstrapData(page);
    }
}
