package com.muchinfo.mtp3century.controller;

import com.muchinfo.mtp3century.service.ISystemSetUpService;
import com.muchinfo.mtp3century.utils.AjaxResult;
import com.muchinfo.mtp3century.utils.CenturyDecryptUtil;
import com.muchinfo.mtp3century.vo.TreeNode;
import com.muchinfo.mtp3common.enumtype.Constants;
import com.muchinfo.mtp3common.enumtype.MessageType;
import com.muchinfo.mtp3common.utils.JsonUtils;
import com.muchinfo.mtp3common.vo.PageResult;
import com.muchinfo.mtp3pojos.entity.*;
import com.muchinfo.mtp3pojos.vo.systemsetup.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Map;

@Controller
@RequestMapping("/setup")
@Api(value = "基础数据API", description = "基础数据管理")
public class SystemSetUpController {

    private final Logger log = LoggerFactory.getLogger(this.getClass());
    @Resource
    private ISystemSetUpService iSystemSetUpService;

    @ApiOperation("基础数据管理-->系统参数管理-->获取列表")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/queryParam")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    private PageResult<Systemparam> query(Integer pageNum, Integer pageSize, HttpServletRequest request) {
        return iSystemSetUpService.queryByPage(pageNum, pageSize, request);
    }

    @ApiOperation("基础数据管理-->系统参数管理-->修改")
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/dealParam")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult query(@RequestBody SystemParamUpdate paramUpdate, HttpServletRequest request) {
        return iSystemSetUpService.dealParam(paramUpdate, request);
    }

    @ApiOperation("基础数据管理-->错误码管理-->获取列表")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/queryErr")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    private PageResult<Errorcode> queryErr(SystemErrorCodeParam param, HttpServletRequest request) {
        return iSystemSetUpService.queryErr(param, request);
    }

    @ApiOperation("基础数据管理-->错误码管理-->修改")
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/dealErr")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult dealErr(@RequestBody SystemErrorCodeParam param, HttpServletRequest request) {
        return iSystemSetUpService.dealErr(param, request);
    }

    @ApiOperation("基础数据管理-->市场板块设置-->获取列表")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/queryMarketSet")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    private PageResult<SystemMarketSectionResult> queryMarketSet(SystemMarketSectionParam param, HttpServletRequest request) {
        return iSystemSetUpService.queryMarketSet(param, request);
    }

    @ApiOperation("基础数据管理-->市场板块设置-->详情")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/marketSetDetail")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult<SystemMarketSetDetail> marketSetDetail(Integer marketsectionid, HttpServletRequest request) {
        return iSystemSetUpService.marketSetDetail(marketsectionid, request);
    }

    @ApiOperation("基础数据管理-->市场板块设置-->删除")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/deletemarketSet")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult deletemarketSet(Integer marketsectionid, HttpServletRequest request) {
        return iSystemSetUpService.deletemarketSet(marketsectionid, request);
    }

    @ApiOperation("基础数据管理-->市场板块设置-->新增初始化市场")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/querytrademodes")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult<SystemMarketSetResult> querytrademodes(Integer editmarketsectionid, String selectedmarketids, HttpServletRequest request) {
        return iSystemSetUpService.querytrademodes(request,editmarketsectionid,selectedmarketids);
    }

    @ApiOperation("基础数据管理-->市场板块设置-->新增,修改")
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/delmarket")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult delmarket(@RequestBody String param, HttpServletRequest request) {
        try {
            SystemMarketSectionAddParam current = JsonUtils.toBean(CenturyDecryptUtil.decryptForJson(param, request), SystemMarketSectionAddParam.class);
            return iSystemSetUpService.delmarket(current, request);
        } catch (Exception e) {
            log.error("新增,修改失败原因：" + Arrays.toString(e.getStackTrace()));
            return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM002.getCode(), request.getHeader("Accept-Language"));
        }
    }

    @ApiOperation("基础数据管理-->终端图片管理-->获取列表")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/querypicture")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    private PageResult<Szdz2Imageconfig> querypicture(SystemPictureSetParam param, HttpServletRequest request) {
        return iSystemSetUpService.querypicture(param, request);
    }

    @ApiOperation("基础数据管理-->终端图片管理-->详情")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/pictureDetail")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult<Szdz2Imageconfig> pictureDetail(Integer configid, HttpServletRequest request) {
        return iSystemSetUpService.pictureDetail(configid, request);
    }

    @ApiOperation("基础数据管理-->终端图片管理-->删除")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/deletepicture")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult deletepicture(Integer configid, HttpServletRequest request) {
        return iSystemSetUpService.deletepicture(configid, request);
    }

    @ApiOperation("基础数据管理-->终端图片管理-->新增,修改")
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/dealpicture")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult dealpicture(@RequestBody SystemPictureDealParam param, HttpServletRequest request) {
        return iSystemSetUpService.dealpicture(param, request);
    }

    @ApiOperation("基础数据管理-->网上开户配置-->详情")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/oaconfig")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult<WskhConfigResult> oaconfig(HttpServletRequest request) {
        return iSystemSetUpService.oaconfig(request);
    }

    @ApiOperation("基础数据管理-->网上开户配置-->保存")
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/oaconfigAdd")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult oaconfigAdd(@RequestBody String param, HttpServletRequest request) {
        try {
            OaConfigParam current = JsonUtils.toBean(CenturyDecryptUtil.decryptForJson(param, request), OaConfigParam.class);
            return iSystemSetUpService.oaconfigAdd(current, request);
        } catch (Exception e) {
            log.error("网上开户配置，保存失败原因：" + Arrays.toString(e.getStackTrace()));
            return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM002.getCode(), request.getHeader("Accept-Language"));
        }
    }

    @ApiOperation("基础数据管理-->行政区域管理-->获取菜单树")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/divisiontree")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult<TreeNode> divisiontree(HttpServletRequest request) {
        return iSystemSetUpService.divisiontree(request);
    }

    @ApiOperation("基础数据管理-->行政区域管理-->获取详情")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/queryAreaByCondition")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult<Division> queryAreaByCondition(HttpServletRequest request, String parentcode) {
        return iSystemSetUpService.queryAreaByCondition(request, parentcode);
    }

    @ApiOperation("基础数据管理-->行政区域管理-->获取地区信息")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/getParentByAreacode")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult<Division> getParentByAreacode(HttpServletRequest request, String parentcode) {
        return iSystemSetUpService.getParentByAreacode(request, parentcode);
    }

    @ApiOperation("基础数据管理-->行政区域管理-->新增、修改")
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/dealDiv")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult dealDiv(HttpServletRequest request, @RequestBody DivisionAddParam param) {
        return iSystemSetUpService.dealDiv(request, param);
    }

    @ApiOperation("基础数据管理-->行政区域管理-->删除")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/deleteDiv")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult deleteDiv(HttpServletRequest request, Long areaid) {
        return iSystemSetUpService.deleteDiv(request, areaid);
    }

    @ApiOperation("基础数据管理-->系统设置-->同步开户信息")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/syncTaToCenter")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult syncTaToCenter(HttpServletRequest request) {
        return iSystemSetUpService.syncTaToCenter(request);
    }

    @ApiOperation("基础数据管理-->系统设置-->更新交易权限")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/updateTransaction")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult updateTransaction(HttpServletRequest request) {
        return iSystemSetUpService.updateTransaction(request);
    }

    @ApiOperation("基础数据管理-->系统设置-->详情")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/initdetail")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult<SystemSetUpDetail> initdetail(HttpServletRequest request) {
        return iSystemSetUpService.initdetail(request);
    }

    @ApiOperation("基础数据管理-->系统设置-->保存")
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/update")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult update(@RequestBody SystemSetUpDetail param, HttpServletRequest request) {
        return iSystemSetUpService.update(request, param);
    }

    @ApiOperation("基础数据管理-->系统设置-->清空运行时段")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/clearMarketRunPlan")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult clearMarketRunPlan(HttpServletRequest request) {
        return iSystemSetUpService.clearMarketRunPlan(request);
    }

    @ApiOperation("基础数据管理-->数据字典管理-->获取树结构")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/getEnumDics")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult<EnumDicsResult> getEnumDics(HttpServletRequest request) {
        return iSystemSetUpService.getEnumDics(request);
    }

    @ApiOperation("基础数据管理-->数据字典管理-->获取列表")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/queryEnumDicItemByPage")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private PageResult<EnumDicsPageResult> queryEnumDicItemByPage(EnumDicsPageParam param, HttpServletRequest request) {
        return iSystemSetUpService.queryEnumDicItemByPage(param, request);
    }

    @ApiOperation("基础数据管理-->数据字典管理-->获取详情(二级)")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/editEnumDic")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult<Enumdic> editEnumDic(Long autoid, Long enumgroupid, HttpServletRequest request) {
        return iSystemSetUpService.editEnumDic(autoid, enumgroupid, request);
    }

    @ApiOperation("基础数据管理-->数据字典管理-->新增(二级)")
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/saveEnumDic")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult saveEnumDic(@RequestBody String param, HttpServletRequest request) {
        try {
            Enumdic current = JsonUtils.toBean(CenturyDecryptUtil.decryptForJson(param, request), Enumdic.class);
            return iSystemSetUpService.saveEnumDic(current, request);
        } catch (Exception e) {
            log.error("数据字典管理，新增(二级)失败原因：" + Arrays.toString(e.getStackTrace()));
            return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM002.getCode(), request.getHeader("Accept-Language"));
        }
    }

    @ApiOperation("基础数据管理-->数据字典管理-->获取详情(三级)")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/editEnumDicItem")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult<EnumdicitemVoResult> editEnumDicItem(Long autoid, String enumdiccode, Integer ismappingtobank, HttpServletRequest request) {
        return iSystemSetUpService.editEnumDicItem(autoid, enumdiccode, ismappingtobank, request);
    }

    @ApiOperation("基础数据管理-->数据字典管理-->新增(三级)")
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/updateOrSave")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult updateOrSave(@RequestBody String param, HttpServletRequest request) {
        try {
            EnumDicItemSave current = JsonUtils.toBean(CenturyDecryptUtil.decryptForJson(param, request), EnumDicItemSave.class);
            return iSystemSetUpService.updateOrSave(current, request);
        } catch (Exception e) {
            log.error("数据字典管理，新增(三级)失败原因：" + Arrays.toString(e.getStackTrace()));
            return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM002.getCode(), request.getHeader("Accept-Language"));
        }
    }

    @ApiOperation("基础数据管理-->数据字典管理-->删除")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/delEnumdicItem")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult delEnumdicItem(Long autoid, Integer flag, HttpServletRequest request) {
        return iSystemSetUpService.delEnumdicItem(autoid, flag, request);
    }

    @ApiOperation("基础数据管理-->数据字典管理-->更新缓存")
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/refreshredis")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult refreshredis(HttpServletRequest request) {
        return iSystemSetUpService.refreshredis(request);
    }
}
