package com.sifang.modules.customer.controller;

import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.customer.Service.CrmEntryCombinerBoxGroupService;
import com.sifang.modules.sunshine.SystemSetting.utils.Result;
import com.sifang.modules.sys.common.UserUtils;
import com.sifang.modules.sys.common.entity.User;
import com.sifang.modules.sys.entity.Operator;
import com.sifang.modules.sys.util.LayuiPage;
import com.sifang.modules.sys.web.BaseExceptionController;
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 java.util.List;

@Controller
@RequestMapping(value = "${adminPath}/combinerBoxGroupSet")
public class CrmEntryCombinerBoxGroupController extends BaseExceptionController {


    @Autowired
    private CrmEntryCombinerBoxGroupService boxGroupService;

    //选择汇流组页面
    @RequestMapping(value = "choiceBoxGroupPage")
    public String choiceBoxGroupPage(HttpServletRequest request, Model model){
        String entryId=request.getParameter("entryId");
        model.addAttribute("entryId",entryId);
        return "modules/yangguang/customer/boxGroup/boxGroupSetPage";
    }

    @ResponseBody
    @RequestMapping(value = "boxGroupData")
    public Object boxGroupData(HttpServletRequest request){
        LayuiPage<Record> page = new LayuiPage<>(request);
        String entryId=request.getParameter("entryId");
        List<Record> list=boxGroupService.choiceBoxGroupList(entryId);
        page.setData(list);
        return page.renderJson();
    }

    //保存新建/选择的整村汇流组
    @ResponseBody
    @RequestMapping(value = "saveOneOwner")
    public Result saveOneOwner(String entryId,Integer totalCount,String boxGroupId){
        User user= UserUtils.getUser();
        boxGroupService.saveOneOwner(entryId,totalCount,boxGroupId, Operator.of(user));
        return Result.ok();
    }

}
