package com.style24.admin.biz.web;

import java.util.Collection;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.style24.admin.biz.service.TsaBusinessService;
import com.style24.admin.biz.service.TsaRendererService;
import com.style24.admin.support.controller.TsaBaseController;
import com.style24.admin.support.security.session.TsaSession;
import com.style24.core.biz.service.TscEnvsetService;
import com.style24.core.biz.service.TscKcpService;
import com.style24.core.support.env.TscConstants;
import com.style24.core.support.message.TscMessageByLocale;
import com.style24.persistence.domain.Aflink;
import com.style24.persistence.domain.Bizday;
import com.style24.persistence.domain.Brand;
import com.style24.persistence.domain.BrandGroup;
import com.style24.persistence.domain.BrandMd;
import com.style24.persistence.domain.CustAccount;
import com.style24.persistence.domain.DeliveryLoc;
import com.style24.persistence.domain.DelvFeePolicy;
import com.style24.persistence.domain.SellStore;
import com.style24.persistence.domain.ShipCompany;
import com.style24.persistence.domain.SiteBrand;
import com.style24.persistence.domain.StockSyncBase;
import com.style24.persistence.domain.SupplyCompany;

import lombok.extern.slf4j.Slf4j;

import com.gagaframework.web.parameter.GagaMap;
import com.gagaframework.web.rest.server.GagaResponse;

/**
 * 영업관리 Controller
 *
 * @author gagamel
 * @since 2020. 10. 14
 */
@Controller
@RequestMapping("/business")
@Slf4j
public class TsaBusinessController extends TsaBaseController {

	@Autowired
	private TscMessageByLocale message;

	@Autowired
	private TsaBusinessService businessService;

	@Autowired
	private TsaRendererService rendererService;

	@Autowired
	private TscEnvsetService cenvsetService;

	@Autowired
	private TscKcpService coreKcpService;

	@Autowired
	private ObjectMapper mapper;

	/**
	 * 공급벤더관리 화면
	 * @return
	 * @author gagamel
	 * @since 2021. 1. 18
	 */
	@GetMapping("/supply/vendor/form")
	public ModelAndView supplyVendorForm() {
		ModelAndView mav = new ModelAndView();

		mav.setViewName("/business/SupplyVendorForm");

		return mav;
	}

	/**
	 * 공급벤더 목록
	 * @param supplyComp - 공급벤더 정보
	 * @return
	 * @author gagamel
	 * @since 2021. 1. 18
	 */
	@PostMapping("/supply/vendor/list")
	@ResponseBody
	public Collection<SupplyCompany> getSupplyVendorList(@RequestBody SupplyCompany supplyComp) {
		return businessService.getSupplyVendorList(supplyComp);
	}

	/**
	 * 공급벤더 저장 처리
	 * @param supplyComp - 공급벤더 정보
	 * @return
	 * @author gagamel
	 * @since 2020. 10. 14
	 */
	@PostMapping("/supply/vendor/save")
	@ResponseBody
	public GagaResponse saveSupplyVendor(@RequestBody SupplyCompany supplyComp) {
		supplyComp.setRegNo(TsaSession.getInfo().getUserNo());
		supplyComp.setUpdNo(TsaSession.getInfo().getUserNo());

		businessService.saveSupplyVendor(supplyComp);

		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 공급벤더팝업 화면
	 * @param returnCode - 반환할코드. 필수
	 * @param returnName - 반환할명칭. 필수
	 * @param supplyVendorNm - 공급업체명. 옵션
	 * @return
	 * @author gagamel
	 * @since 2021. 1. 18
	 */
	@GetMapping("/supply/vendor/popup/form")
	public ModelAndView supplyVendorPopupForm(@RequestParam(value = "returnCode") String returnCode, @RequestParam(value = "returnName") String returnName, @RequestParam(value = "supplyVendorNm", required = false) String supplyVendorNm) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("returnCode", returnCode);
		mav.addObject("returnName", returnName);
		mav.addObject("supplyVendorNm", StringUtils.defaultString(supplyVendorNm, ""));

		mav.setViewName("/business/SupplyVendorPopupForm");

		return mav;
	}

	/**
	 * 공급업체관리 화면
	 * @return
	 * @author gagamel
	 * @since 2020. 10. 14
	 */
	@GetMapping("/supply/company/form")
	public ModelAndView supplyCompanyForm() {
		ModelAndView mav = new ModelAndView();

		// 입점상태
		mav.addObject("supplyStatList", rendererService.getAvailCommonCodeList("G010"));

		// 유통구분
		mav.addObject("distributionGbList", rendererService.getAvailCommonCodeList("G065"));

		// 은행
		mav.addObject("bankList", rendererService.getAvailCommonCodeList("G942"));

		// 정산일
		mav.addObject("settleDayList", rendererService.getAvailCommonCodeList("G075"));

		mav.setViewName("/business/SupplyCompanyForm");

		return mav;
	}

	/**
	 * 공급업체 목록
	 * @param supplyComp - 공급업체 정보
	 * @return
	 * @author gagamel
	 * @since 2020. 10. 14
	 */
	@PostMapping("/supply/company/list")
	@ResponseBody
	public Collection<SupplyCompany> getSupplyCompanyList(@RequestBody SupplyCompany supplyComp) {
		// multi row 검색관련 처리
		if (!StringUtils.isBlank(supplyComp.getSearchSupplyCompCd())) {
			supplyComp.setMultiSupplyCompCd(supplyComp.getSearchSupplyCompCd().replaceAll("\r", "").trim().split("\n"));
		}
		if (!StringUtils.isBlank(supplyComp.getSearchSupplyCompNm())) {
			supplyComp.setMultiSupplyCompNm(supplyComp.getSearchSupplyCompNm().replaceAll("\r", "").trim().split("\n"));
		}
		//log.info("supplyComp  {}", supplyComp);
		return businessService.getSupplyCompanyList(supplyComp);
	}

	/**
	 * 공급업체 저장 처리
	 * @param supplyComp - 공급업체 정보
	 * @return
	 * @author gagamel
	 * @since 2020. 10. 14
	 */
	@PostMapping("/supply/company/save")
	@ResponseBody
	public GagaResponse saveSupplyCompany(@RequestBody SupplyCompany supplyComp) {
		supplyComp.setRegNo(TsaSession.getInfo().getUserNo());
		supplyComp.setUpdNo(TsaSession.getInfo().getUserNo());

		businessService.saveSupplyCompany(supplyComp);

		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 공급업체출고처관리 화면
	 * @return
	 * @author gagamel
	 * @since 2020. 10. 16
	 **/
	@GetMapping("/supply/company/delvloc/form")
	public ModelAndView deliveryLocForm() {
		ModelAndView mav = new ModelAndView();

		// 공급업체
		mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(TsaSession.getInfo().getSupplyCompCd()));

		// 출고처분류
		mav.addObject("delvLocClsfList", rendererService.getAvailCommonCodeList("G024"));

		// 송장출력형태
		mav.addObject("invoicePrintTypeList", rendererService.getAvailCommonCodeList("G025"));

		mav.setViewName("business/DeliveryLocForm");

		return mav;
	}

	/**
	 * 공급업체출고처 목록
	 * @param delvLoc - 출고처 정보
	 * @return
	 * @author gagamel
	 * @since 2020. 10. 16
	 **/
	@PostMapping("/supply/company/delvloc/list")
	@ResponseBody
	public Collection<DeliveryLoc> getDeliveryLocList(@RequestBody DeliveryLoc delvLoc) {
		if (!StringUtils.isBlank(delvLoc.getSupplyCompList())) {
			try {
				String[] arrSupplyComp = mapper.readValue(delvLoc.getSupplyCompList(), String[].class);
				delvLoc.setMultiSupplyComp(arrSupplyComp);
			} catch (Exception e) {
				throw new IllegalStateException("업체코드 검색중 오류로 인해 조회되지 않았습니다.");
			}
		}

		return businessService.getDeliveryLocList(delvLoc);
	}

	/**
	 * 공급업체출고처 저장 처리
	 * @param delvLoc - 출고처 정보
	 * @return
	 * @author gagamel
	 * @since 2020. 10. 16
	 */
	@PostMapping("/supply/company/delvloc/save")
	@ResponseBody
	public GagaResponse saveDeliveryLoc(@RequestBody DeliveryLoc delvLoc) {
		delvLoc.setRegNo(TsaSession.getInfo().getUserNo());
		delvLoc.setUpdNo(TsaSession.getInfo().getUserNo());
		businessService.saveDeliveryLoc(delvLoc);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 배송비정책 목록
	 * @param supplyCompCd - 공급업체코드
	 * @return
	 * @author gagamel
	 * @since 2020. 11. 24
	 **/
	@GetMapping("/delivery/fee/policy/list/{supplyCompCd}")
	@ResponseBody
	public Collection<DelvFeePolicy> getDeliveryFeePolicyList(@PathVariable String supplyCompCd) {
		DelvFeePolicy delvFeePolicy = new DelvFeePolicy();
		delvFeePolicy.setSupplyCompCd(supplyCompCd);
		return businessService.getDeliveryFeePolicyList(delvFeePolicy);
	}

	/**
	 * 배송비정책 등록/수정 처리
	 * @param delvFeePolicyList - 배송비정책 목록
	 * @return
	 * @author gagamel
	 * @since 2020. 11. 24
	 */
	@PostMapping("/delivery/fee/policy/list/save")
	@ResponseBody
	public GagaResponse saveDeliveryFeePolicyList(@RequestBody Collection<DelvFeePolicy> delvFeePolicyList) {
		if (delvFeePolicyList == null || delvFeePolicyList.isEmpty()) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		businessService.saveDeliveryFeePolicyList(delvFeePolicyList);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 브랜드관리 화면
	 * @return
	 * @author gagamel
	 * @since 2020. 11. 4
	 */
	@GetMapping("/brand/form")
	public ModelAndView supplyCompanyBrandForm() {
		ModelAndView mav = new ModelAndView();

		// 공급업체
		mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(TsaSession.getInfo().getSupplyCompCd()));

		// 유통구분
		mav.addObject("distributionGbList", rendererService.getAvailCommonCodeList("G065"));

		// 사이트
		mav.addObject("siteList", rendererService.getAvailCommonCodeList("G000"));

		// 구매적립포인트율
		mav.addObject("pntInfo", cenvsetService.getEnvset(TscConstants.Site.STYLE24.value(), "C14"));

		mav.setViewName("business/BrandForm");

		return mav;
	}

	/**
	 * 브랜드 목록
	 * @param brand - 브랜드 정보
	 * @return
	 * @author gagamel
	 * @since 2020. 11. 4
	 */
	@PostMapping("/brand/list")
	@ResponseBody
	public Collection<Brand> getBrandList(@RequestBody Brand brand) {

		// multi row 검색관련 처리
		if (!StringUtils.isBlank(brand.getSearchBrandCd())) {
			brand.setMultiBrandCd(brand.getSearchBrandCd().replaceAll("\r", "").trim().split("\n"));
		}
		if (!StringUtils.isBlank(brand.getSearchBrandNm())) {
			brand.setMultiBrandNm(brand.getSearchBrandNm().replaceAll("\r", "").trim().split("\n"));
		}

		return businessService.getBrandList(brand);
	}

	/**
	 * 담당MD 목록 화면
	 * @param brandMd - 담당MD 정보
	 * @return
	 * @author gagamel
	 * @since 2020. 11. 4
	 */
	@GetMapping("/md/list/form")
	public ModelAndView mdListForm(BrandMd brandMd) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("params", brandMd);

		mav.setViewName("business/MdListForm");

		return mav;
	}

	/**
	 * 브랜드담당MD 목록
	 * @param brandCd - 브랜드코드
	 * @return
	 * @author gagamel
	 * @since 2020. 11. 4
	 */
	@PostMapping("/md/list")
	@ResponseBody
	public Collection<BrandMd> getMdList(@RequestBody BrandMd brandMd) {
		return businessService.getMdList(brandMd);
	}

	/**
	 * 브랜드담당MD 목록
	 * @param brandCd - 브랜드코드
	 * @return
	 * @author gagamel
	 * @since 2020. 11. 4
	 */
	@GetMapping("/brand/md/list/{brandCd}")
	@ResponseBody
	public Collection<BrandMd> getBrandMdList(@PathVariable String brandCd) {
		return businessService.getBrandMdList(brandCd);
	}

	/**
	 * 브랜드 담당MD 등록/수정 처리
	 * @param brandMdList - 브랜드담당MD 목록
	 * @return
	 * @author gagamel
	 * @since 2020. 11. 4
	 */
	@PostMapping("/brand/md/save")
	@ResponseBody
	public GagaResponse saveBrandMdList(@RequestBody Collection<BrandMd> brandMdList) {
		if (brandMdList == null || brandMdList.isEmpty()) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		businessService.saveBrandMdList(brandMdList);

		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 브랜드 노출사이트 목록
	 * @param brandCd - 브랜드코드
	 * @return
	 * @author gagamel
	 * @since 2020. 11. 4
	 */
	@GetMapping("/brand/site/list/{brandCd}")
	@ResponseBody
	public Collection<SiteBrand> getBrandSiteList(@PathVariable String brandCd) {
		return businessService.getBrandSiteList(brandCd);
	}

	/**
	 * 브랜드 노출사이트 등록/수정 처리
	 * @param brandSiteList - 브랜드사이트 목록
	 * @return
	 * @author gagamel
	 * @since 2020. 11. 4
	 */
	@PostMapping("/brand/site/save")
	@ResponseBody
	public GagaResponse saveBrandSiteList(@RequestBody Collection<SiteBrand> brandSiteList) {
		if (brandSiteList == null || brandSiteList.isEmpty()) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		businessService.saveBrandSiteList(brandSiteList);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 브랜드 공급업체 목록
	 * @param brandCd - 브랜드코드
	 * @return
	 * @author eskim
	 * @since 2021. 01. 21
	 */
	@GetMapping("/brand/supply/list/{brandCd}")
	@ResponseBody
	public Collection<Brand> getBrandSupplyList(@PathVariable String brandCd) {
		return businessService.getBrandSupplyList(brandCd);
	}

	/**
	 * 브랜드 등록/수정 처리
	 * @param brand - 브랜드 정보
	 * @return
	 * @author gagamel
	 * @since 2020. 11. 5
	 */
	@PostMapping("/brand/save")
	@ResponseBody
	public GagaResponse saveBrand(@RequestBody Brand brand) {
		brand.setRegNo(TsaSession.getInfo().getUserNo());
		brand.setUpdNo(TsaSession.getInfo().getUserNo());
		businessService.saveBrand(brand);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 재고연계관리 화면
	 * @return
	 * @author gagamel
	 * @since 2020. 11. 7
	 */
	@GetMapping("/stock/sync/form")
	public ModelAndView stockSyncForm() {
		ModelAndView mav = new ModelAndView();

		// 자사공급업체
		mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(TsaSession.getInfo().getSupplyCompCd(), "Y"));

		// 출고처 분류
		String[] exceptCds = {"G024_20", "G024_30"};
		mav.addObject("delvLocClsfList", rendererService.getCommonCodeList("G024", "Y", exceptCds));

		// 정상이월구분
		mav.addObject("formalGbList", rendererService.getAvailCommonCodeList("G009"));

		mav.setViewName("business/StockSyncForm");

		return mav;
	}

	/**
	 * 재고연계관리 - 출고처 목록
	 * @param delvLoc - 출고처 정보
	 * @return
	 * @author gagamel
	 * @since 2020. 11. 7
	 */
	@PostMapping("/stock/sync/delvloc/list")
	@ResponseBody
	public Collection<DeliveryLoc> getStockSyncDeliveryLocList(@RequestBody DeliveryLoc delvLoc) {
		return businessService.getStockSyncDeliveryLocList(delvLoc);
	}

	/**
	 * 재고연계관리 - 재고연계기준 목록
	 * @param supplyCompCd - 공급업체코드
	 * @param delvLocCd - 출고처코드
	 * @return
	 * @author gagamel
	 * @since 2020. 11. 7
	 */
	@GetMapping("/stock/sync/base/list/{supplyCompCd}/{delvLocCd}")
	@ResponseBody
	public Collection<StockSyncBase> getStockSyncBaseList(@PathVariable String supplyCompCd, @PathVariable String delvLocCd) {
		StockSyncBase stockSyncBase = new StockSyncBase();
		stockSyncBase.setSupplyCompCd(supplyCompCd);
		stockSyncBase.setDelvLocCd(delvLocCd);
		return businessService.getStockSyncBaseList(stockSyncBase);
	}

	/**
	 * 재고연계관리 - 재고연계기준 목록 저장 처리
	 * @param stockSyncBaseList - 재고연계기준 목록
	 * @return
	 * @author gagamel
	 * @since 2020. 11. 7
	 */
	@PostMapping("/stock/sync/base/save")
	@ResponseBody
	public GagaResponse saveStockSyncBaseList(@RequestBody Collection<StockSyncBase> stockSyncBaseList) {
		if (stockSyncBaseList == null || stockSyncBaseList.isEmpty()) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		businessService.saveStockSyncBaseList(stockSyncBaseList);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 판매매장관리 화면
	 * @return
	 * @author gagamel
	 * @since 2020. 10. 20
	 */
	@GetMapping("/sellstore/form")
	public ModelAndView sellStoreForm() {
		ModelAndView mav = new ModelAndView();

		// 공급업체
		mav.addObject("supplyCompList", rendererService.getSupplyCompanyList(TsaSession.getInfo().getSupplyCompCd()));

		mav.setViewName("business/SellStoreForm");

		return mav;
	}

	/**
	 * 판매매장 목록
	 * @param sellStore - 판매매장 정보
	 * @return
	 * @author gagamel
	 * @since 2020. 10. 20
	 */
	@PostMapping("/sellstore/list")
	@ResponseBody
	public Collection<SellStore> getSellStoreList(@RequestBody SellStore sellStore) {
		return businessService.getSellStoreList(sellStore);
	}

	/**
	 * 판매매장 목록 저장 처리
	 * @param sellStoreList - 판매매장 목록
	 * @return
	 * @author gagamel
	 * @since 2020. 10. 20
	 */
	@PostMapping("/sellstore/list/save")
	@ResponseBody
	public GagaResponse saveSellStoreList(@RequestBody Collection<SellStore> sellStoreList) {
		if (sellStoreList == null || sellStoreList.isEmpty()) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		businessService.saveSellStoreList(sellStoreList);

		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 제휴채널관리
	 * @return
	 * @author gagamel
	 * @since 2020. 10. 20
	 */
	@GetMapping("/aflink/form")
	public ModelAndView aflinkForm() {
		ModelAndView mav = new ModelAndView();

		// 제휴채널 콤보박스 목록
		mav.addObject("afChannelList", rendererService.getCommonCodeList("G053"));

		mav.setViewName("business/AflinkForm");

		return mav;
	}

	/**
	 * 제휴채널 목록
	 * @param afChannel - 제휴채널
	 * @return
	 * @author gagamel
	 * @since 2020. 10. 20
	 */
	@PostMapping("/aflink/list")
	@ResponseBody
	public Collection<Aflink> getAflinkList(@RequestParam(value = "afChannel", required = false) String afChannel) {
		Aflink aflink = new Aflink();
		aflink.setAfChannel(afChannel);
		return businessService.getAflinkList(aflink);
	}

	/**
	 * 제휴채널 저장 처리
	 * @param aflink - 제휴링크 정보
	 * @return
	 * @author gagamel
	 * @since 2020. 10. 20
	 */
	@PostMapping("/aflink/save")
	@ResponseBody
	public GagaResponse saveAflink(@RequestBody Aflink aflink) {
		businessService.saveAflink(aflink);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 제휴채널 목록 사용안함 처리
	 * @param aflinkList - 제휴링크 목록
	 * @return
	 * @author gagamel
	 * @since 2020. 10. 20
	 */
	@PostMapping("/aflink/list/delete")
	@ResponseBody
	public GagaResponse deleteAflinkList(@RequestBody Collection<Aflink> aflinkList) {
		if (aflinkList == null || aflinkList.isEmpty()) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		businessService.deleteAflinkList(aflinkList);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 배송업체관리 화면
	 * @return
	 * @author gagamel
	 * @since 2020. 10. 20
	 */
	@GetMapping("/ship/company/form")
	public ModelAndView deliveryCompanyForm() {
		ModelAndView mav = new ModelAndView();

		mav.setViewName("business/ShipCompanyForm");

		return mav;
	}

	/**
	 * 배송업체 목록
	 * @return
	 * @author gagamel
	 * @since 2020. 10. 20
	 */
	@GetMapping("/ship/company/list")
	@ResponseBody
	public Collection<ShipCompany> getShipCompanyList() {
		return businessService.getShipCompanyList();
	}

	/**
	 * 배송업체 목록 저장
	 * @param shipCompList - 배송업체 목록
	 * @return
	 * @author gagamel
	 * @since 2020. 10. 20
	 */
	@PostMapping("/ship/company/list/save")
	@ResponseBody
	public GagaResponse saveShipCompanyList(@RequestBody Collection<ShipCompany> shipCompList) {
		if (shipCompList == null || shipCompList.isEmpty()) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		businessService.saveShipCompanyList(shipCompList);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 배송업체 목록 삭제
	 * @param shipCompList - 배송업체 목록
	 * @return
	 * @author gagamel
	 * @since 2020. 10. 20
	 */
	@PostMapping("/ship/company/list/delete")
	@ResponseBody
	public GagaResponse deleteShipCompanyList(@RequestBody Collection<ShipCompany> shipCompList) {
		if (shipCompList == null || shipCompList.isEmpty()) {
			throw new IllegalStateException(message.getMessage("FAIL_1004"));
		}

		businessService.deleteShipCompanyList(shipCompList);
		return super.ok(message.getMessage("SUCC_0003"));
	}

	/**
	 * 브랜드 목록 화면(팝업)
	 * @param brand - 담당MD 정보
	 * @return
	 * @author gagamel
	 * @since 2020. 11. 4
	 */
	@GetMapping("/brand/search/form")
	public ModelAndView brandSearchForm(Brand brand) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("params", brand);
		mav.setViewName("business/BrandPopupForm");
		return mav;
	}

	/**
	 * 공급업체 목록 화면(팝업)
	 * @param brandMd - 담당MD 정보
	 * @return
	 * @author xodud1202
	 * @since 2020. 12. 23
	 */
	@GetMapping("/comapny/search/form")
	public ModelAndView companySearchForm(SupplyCompany company) {
		ModelAndView mav = new ModelAndView();
		log.info("company={}", company);
		mav.addObject("params", company);
		mav.setViewName("business/SupplyCompanyPopupForm");
		return mav;
	}

	/**
	 * 브랜드 그룹 목록 화면(팝업)
	 * @param
	 * @return
	 * @author eskim
	 * @since 2021. 02. 19
	 */
	@GetMapping("/brand/group/popup/form")
	@ResponseBody
	public ModelAndView brandGroupForm(BrandGroup brandGroup) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("params", brandGroup);
		mav.setViewName("business/BrandGroupPopupForm");
		return mav;
	}

	/**
	 * 브랜드 그룹 목록
	 * @return
	 * @author eskim
	 * @since 2021. 02. 19
	 */
	@PostMapping("/brand/group/list")
	@ResponseBody
	public Collection<BrandGroup> getBrandGroupList(@RequestBody BrandGroup brandGroup) {
		// multi row 검색관련 처리
		if (!StringUtils.isBlank(brandGroup.getSearchBrandGroupNo())) {
			brandGroup.setMultiBrandGroupNo(brandGroup.getSearchBrandGroupNo().replaceAll("\r", "").trim().split("\n"));
		}
		if (!StringUtils.isBlank(brandGroup.getSearchBrandGroupNm())) {
			brandGroup.setMultiBrandGroupNm(brandGroup.getSearchBrandGroupNm().replaceAll("\r", "").trim().split("\n"));
		}
		return businessService.getBrandGroupList(brandGroup);
	}

	/**
	 * 브랜드 그룹 저장
	 * @param brandGroup
	 * @return
	 * @author eskim
	 * @since 2021. 02. 19
	 */
	@PostMapping("/brand/group/save")
	@ResponseBody
	public GagaResponse saveBrandGroupList(@RequestBody BrandGroup brandGroup) {
		if (brandGroup == null) {
			throw new IllegalStateException(message.getMessage("FAIL_1001"));
		}

		brandGroup.setRegNo(TsaSession.getInfo().getUserNo());
		brandGroup.setUpdNo(TsaSession.getInfo().getUserNo());
		businessService.saveBrandGroup(brandGroup);
		return super.ok(message.getMessage("SUCC_0001"));
	}

	/**
	 * 제휴채널 조회팝업
	 * @param afChannel
	 * @return
	 * @author sowon
	 * @since 2021. 03. 4
	 */
	@GetMapping("/channel/popup/form")
	public ModelAndView getAfChannelList(Aflink aflink) {
		ModelAndView mav = new ModelAndView();
		// 제휴채널 콤보박스 목록
		mav.addObject("afChannelList", rendererService.getCommonCodeList("G053"));
		mav.addObject("params", aflink);
		mav.setViewName("business/AfChannelPopupForm");

		return mav;
	}

	/**
	 * 영업일관리 화면
	 * @return
	 * @author gagamel
	 * @since 2021. 3. 16
	 */
	@GetMapping("/bizday/form")
	public ModelAndView bizdayForm() {
		ModelAndView mav = new ModelAndView();

		mav.setViewName("business/BizdayForm");

		return mav;
	}

	/**
	 * 휴무일 목록
	 * @param bizday - 영업일 정보
	 * @return
	 * @author gagamel
	 * @since 2021. 3. 16
	 */
	@GetMapping("/holiday/list")
	@ResponseBody
	public Collection<Bizday> getHolidayList(Bizday bizday) {
		return businessService.getHolidayList(bizday);
	}

	/**
	 * 영업일 저장
	 * @param bizday - 영업일 정보
	 * @return
	 * @author gagamel
	 * @since 2021. 3. 16
	 */
	@PostMapping("/bizday/save")
	@ResponseBody
	public GagaResponse saveBizday(@RequestBody Bizday bizday) {
		businessService.saveBizday(bizday);
		return super.ok(message.getMessage("SUCC_0009"));
	}

	/**
	 * 계좌인증
	 *
	 * @return GagaMap - 결과
	 * @author jsshin
	 * @since 2021. 06. 14
	 */
	@PostMapping("/account/check")
	@ResponseBody
	public GagaMap getAccountCheck(@RequestBody CustAccount custAccount) {
		boolean isValid = false;

		GagaMap result = coreKcpService.checkAccount(custAccount);

		if ("0000".equals(result.get("resCd"))) {
			isValid = true;
		}

		result.setBoolean("isValid", isValid);
		return result;
	}
}
