package com.icomsys.main_vm.biz.rcp.oprManage;

import com.icomsys.main_vm.biz.common.login.res.UserVo;
import com.icomsys.main_vm.biz.common.system.vo.DslDataTableRes;
import com.icomsys.main_vm.biz.common.system.vo.SystemBotTtsTagVo;
import com.icomsys.main_vm.biz.common.system.vo.SystemCommoncodeReq;
import com.icomsys.main_vm.biz.common.system.vo.SystemCommoncodeRes;
import com.icomsys.main_vm.biz.rcp.oprManage.service.OprManageTTSTagService;
import com.icomsys.main_vm.db.jpa.entity.system.TbBotCommonCode;
import com.icomsys.main_vm.db.jpa.repo.oprManage.TbBotTtsTagRepo;
import com.icomsys.main_vm.db.jpa.repo.system.TbBotCommonCodeRepo;
import com.icomsys.main_vm.db.mybatis.alias.LoginVO;
import com.querydsl.core.QueryResults;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/admin/rcp/oprmanage")
public class OprManageTTSTagController {

    private final TbBotTtsTagRepo tbBotTtsTagRepo;
    private final TbBotCommonCodeRepo tbBotCommonCodeRepo;
    private final OprManageTTSTagService oprManageTTSTagService;
    private final MappingJackson2JsonView ajaxMainView;

    @GetMapping("/ttstag/manage.do")
    public String ttsTag() {
        return "/adm/rcp/oprmanage/ttstag";
    }

    @ResponseBody
    @RequestMapping(value = "/ttstag/ttsproduct.do",method = RequestMethod.GET)
    public DslDataTableRes<SystemCommoncodeRes> ttsProduct(HttpServletRequest request, @RequestParam String custCode, String serviceGroup) {
        LoginVO resultVO = (LoginVO) request.getSession().getAttribute("LoginVO");
        UserVo userVo = new UserVo();
        userVo.setRoleVal(resultVO.getAuthCode());
        SystemCommoncodeReq dto = new SystemCommoncodeReq();
        dto.setUserVo(userVo);
        dto.setServiceGroup(serviceGroup);
        dto.setOprmngCode(custCode + "_RCP_" + serviceGroup);
        dto.setCodeType("TTS_PRODUCT");
        QueryResults<SystemCommoncodeRes> result = tbBotCommonCodeRepo.SystemCommoncodeProductList(dto);

        return new DslDataTableRes<SystemCommoncodeRes>(result);
    }

    @RequestMapping(value = "/ttstag/ttstaglist.do",method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView ttsTagList(@RequestParam Map<String, String> dataMap) {
        ModelAndView mv = new ModelAndView(ajaxMainView);
        List<HashMap> list = oprManageTTSTagService.selectTtsTagListService(dataMap);
        mv.addObject("list", list);
        return mv;
    }

    @RequestMapping(value = "/ttstag/updatettstag.do",method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView updateTtsTag(HttpServletRequest request, @RequestBody SystemBotTtsTagVo vo) {
        return oprManageTTSTagService.updateTtsTagListService(request, vo);
    }

}
