package com.cool.store.controller.webb;

import com.alibaba.fastjson.JSONObject;
import com.cool.store.constants.CommonConstants;
import com.cool.store.constants.RedisConstant;
import com.cool.store.dao.*;
import com.cool.store.dto.FoodTokenDTO;
import com.cool.store.dto.GetAccessTokenDTO;
import com.cool.store.dto.HqtTokenDTO;
import com.cool.store.dto.ModifyPasswordDTO;
import com.cool.store.dto.huoma.*;
import com.cool.store.dto.wechat.CallbackMessageDTO;
import com.cool.store.dto.wechat.WechatTemplateMessageDTO;
import com.cool.store.entity.*;
import com.cool.store.enums.DownSystemTypeEnum;
import com.cool.store.enums.MessageEnum;
import com.cool.store.enums.SMSMsgEnum;
import com.cool.store.enums.point.ShopSubStageStatusEnum;
import com.cool.store.enums.wechat.WechatTemplateEnum;
import com.cool.store.handler.WeChatHandler;
import com.cool.store.job.XxlJobHandler;
import com.cool.store.mapper.FranchiseFeeMapper;
import com.cool.store.mapper.LineInfoMapper;
import com.cool.store.mapper.ShopInfoMapper;
import com.cool.store.mq.util.HttpRestTemplateService;
import com.cool.store.request.*;
import com.cool.store.request.bigdata.ProfitDataRequest;
import com.cool.store.request.huoma.ShopBasicInfoRequest;
import com.cool.store.request.oppty.*;
import com.cool.store.request.xgj.PushFranchiseFeeRequest;
import com.cool.store.response.ResponseResult;
import com.cool.store.response.bigdata.ActDataResponse;
import com.cool.store.response.bigdata.ApiResponse;
import com.cool.store.response.bigdata.ProfitDataResponse;
import com.cool.store.response.bigdata.ProfitRateResponse;
import com.cool.store.response.huoma.ShopBaseInfoResponse;
import com.cool.store.response.oppty.CityResponse;
import com.cool.store.response.oppty.OpportunityDetailResponse;
import com.cool.store.response.oppty.OpportunityInfoPageResponse;
import com.cool.store.service.*;
import com.cool.store.service.impl.CommonService;
import com.cool.store.service.impl.OrderSysInfoServiceImpl;
import com.cool.store.service.impl.UserAuthMappingServiceImpl;
import com.cool.store.service.wechat.WechatTemplateService;
import com.cool.store.service.xinfa.XinFaBusinessService;
import com.cool.store.service.xinfa.XinFaDeviceService;
import com.cool.store.utils.CoolDateUtils;
import com.cool.store.utils.RedisConstantUtil;
import com.cool.store.utils.RedisUtilPool;
import com.cool.store.utils.poi.StringUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@RestController
@RequestMapping("/pc/test")
public class PCTestController {

    @Resource
    private EnterpriseUserDAO enterpriseUserDAO;
    @Resource
    private BigRegionDAO bigRegionDAO;
    @Resource
    private ShopInfoDAO shopInfoDAO;
    @Resource
    private HqtAPIService hqtAPIService;
    @Resource
    private DecorationDesignInfoService decorationDesignInfoService;
    @Resource
    private DecorationMeasureService decorationMeasureService;
    @Resource
    private SyncMainSysServer syncMainSysServer;
    @Resource
    private CommonService commonService;
    @Resource
    private LineInfoDAO lineInfoDAO;
    @Resource
    private PointInfoDAO pointInfoDAO;
    @Resource
    private ShopService shopService;
    @Resource
    private LineInterviewDAO lineInterviewDAO;
    @Resource
    private XxlJobHandler xxlJobHandler;
    @Resource
    DataHandleService dataHandleService;
    static String url = "https://hzly.cloudcubic.net/ajaxHandle/synchronization/JCallBackSynchronizationHandler.ashx?action=app&controller=GetProjectDetails&projectid=";

    @Resource
    private SyncDataService syncDataService;
    @Resource
    private HttpRestTemplateService httpRestTemplateService;
    @Resource
    FranchiseFeeMapper franchiseFeeMapper;
    @Resource
    WechatTemplateService wechatTemplateService;
    @Resource
    ShopInfoMapper shopInfoMapper;
    @Resource
    LinePayService linePayService;
    @Resource
    LinePayDAO linePayDAO;
    @Autowired
    WeChatHandler weChatHandler;
    @GetMapping("/syncStore")
    public ResponseResult<Boolean> syncStore(@RequestParam("shopId")Long shopId){
        syncMainSysServer.syncStore(shopId);
        return ResponseResult.success(Boolean.TRUE);
    }

    @GetMapping("/sendMessage")
    public ResponseResult<Boolean> sendMessage(@RequestParam("lineId")Long lineId,
                                               @RequestParam("pointId")Long pointId,
                                               @RequestParam("shopId")Long shopId,
                                               @RequestParam MessageEnum messageEnum){
        LineInfoDO lineInfo = lineInfoDAO.getLineInfo(lineId);
        PointInfoDO pointInfo = pointInfoDAO.getPointInfoById(pointId);
        ShopInfoDO shopInfo = shopService.getShopInfo(shopId);
        Map<String, String> messageMap = new HashMap<>();
        messageMap.put("lineId", String.valueOf(lineId));
        messageMap.put("pointId", String.valueOf(pointId));
        messageMap.put("shopId", String.valueOf(shopId));
        messageMap.put("storeName", shopInfo.getShopName());
        messageMap.put("partnerUsername", lineInfo.getUsername());
        messageMap.put("partnerMobile", lineInfo.getMobile());
        messageMap.put("wantShopName", "杭州市余杭区");
        messageMap.put("appointmentTime", "2024-05-06 12:30");
        messageMap.put("interviewUsername", "章臣彪");
        messageMap.put("payTime", "2024-05-01 12:30");
        messageMap.put("submitTime", "2024-05-04 12:30");
        messageMap.put("pointName", pointInfo.getPointName());
        messageMap.put("pointAddress", pointInfo.getAddress());
        messageMap.put("reason", "表现一般不予通过");
        commonService.sendMessage(Arrays.asList("123836131931284423","020125244825417786"), messageEnum, messageMap);
        return ResponseResult.success(Boolean.FALSE);
    }

    @GetMapping("/sendSms")
    public ResponseResult<Boolean> sendSms(@RequestParam("startTime")String startTime, @RequestParam("endTime")String endTime){
        List<LineInterviewDO> interviewList = lineInterviewDAO.getInterviewRemindList(startTime, endTime);
        Map<String, String> templateParam = new HashMap<>();
        templateParam.put("pointName", "杭州门店A");
        List<SMSMsgEnum> smsMsgList = new ArrayList<>();
        for (SMSMsgEnum value : smsMsgList) {
            //commonService.sendSms("17681878615", value, templateParam);
        }
        return ResponseResult.success(Boolean.FALSE);
    }

    @GetMapping("/initShop")
    public ResponseResult<Boolean> initShop(@RequestParam("lineId")Long lineId){
        LineInfoDO lineInfo = lineInfoDAO.getLineInfo(lineId);
        shopService.initShop(lineInfo);
        return ResponseResult.success(Boolean.FALSE);
    }


    @GetMapping("/dataHandle")
    public ResponseResult<Boolean> dataHandle(@RequestParam("shopId")Long shopId){
        return ResponseResult.success(dataHandleService.dataHandleService(shopId));
    }

    @GetMapping("/dataHandleServiceV25")
    public ResponseResult<Integer> dataHandleServiceV25(){
        return ResponseResult.success(dataHandleService.dataHandleServiceV25());
    }

    @GetMapping("/licenseSync")
    public ResponseResult<Boolean> licenseSync(){
        xxlJobHandler.partnerSyncLicense();
        return ResponseResult.success(Boolean.TRUE);
    }
    @GetMapping("/testQWMessage")
    public ResponseResult<Boolean> testQWMessage(){
        List<String> userIds = new ArrayList<>();
        userIds.add("wpayJeDAAAhGIFgUJpJN-zg39JuNbYhg_woayJeDAAA52Wm6ZigyveSjniyimeqZQ");
        HashMap<String, String> map = new HashMap<>();
        map.put("partnerUsername","sx");
        map.put("partnerMobile","13563273279");
        commonService.sendQWMessage(userIds,
                MessageEnum.MESSAGE_14,
                map);

        return ResponseResult.success(Boolean.TRUE);
    }
    @Resource
    ThirdOpportunityService thirdOpportunityService;
    @Resource
    ThirdBigDataService thirdBigDataService;
    @Resource
    HuoMaService huoMaService;

    @PostMapping("/list")
    @ApiOperation("机会点列表/我的机会点")
    public ResponseResult<OpportunityInfoPageResponse> listOpportunities(@Valid @RequestBody OpportunityListRequest request) {
        OpportunityInfoPageResponse list = thirdOpportunityService.listOpportunities(request);
        return ResponseResult.success(list);
    }


    @PostMapping("/getOpportunitiesDetail")
    @ApiOperation("机会点详情")
    public ResponseResult<OpportunityDetailResponse> getOpportunitiesDetail(@Valid @RequestBody OpportunityDetailRequest request) {
        OpportunityDetailResponse list = thirdOpportunityService.getOpportunitiesDetail(request);
        return ResponseResult.success(list);
    }


    @PostMapping("/followOpportunity")
    @ApiOperation("关注/取消关注 机会点")
    public ResponseResult<String> followOpportunity(@Valid @RequestBody FollowRequest request) {
        return ResponseResult.success(thirdOpportunityService.followOpportunity(request));
    }

    @PostMapping("/inspectionOpportunity")
    @ApiOperation("考察机会点")
    public ResponseResult<String> inspectionOpportunity(@Valid @RequestBody InspectionRequest request) {
        return ResponseResult.success(thirdOpportunityService.inspectionOpportunity(request));
    }

    @PostMapping("/berthOperation")
    @ApiOperation("铺位关注机会点")
    public ResponseResult<String> berthOperation(@Valid @RequestBody BerthOperationRequest request) {
        return ResponseResult.success(thirdOpportunityService.berthOperation(request));
    }

    @PostMapping("/storeOperation")
    @ApiOperation("门店关注机会点")
    public ResponseResult<String> storeOperation(@Valid @RequestBody StoreOperationRequest request) {
        return ResponseResult.success(thirdOpportunityService.storeOperation(request));
    }

    @PostMapping("/cityList")
    @ApiOperation("省市区列表 查询省传0")
    public ResponseResult<List<CityResponse>> listOpportunities(@Valid @RequestBody CityRequest request) {
        // 调用第三方接口
        List<CityResponse> list = thirdOpportunityService.cityList(request);
        return ResponseResult.success(list);
    }

    @PostMapping("/getProfitData")
    @ApiOperation("昨天毛利")
    public ResponseResult<ProfitDataResponse> listOpportunities(@Valid @RequestBody ProfitDataRequest request) {
        // 调用第三方接口
        return ResponseResult.success(thirdBigDataService.getProfitData(request));
    }

    @PostMapping("/getCurMonthProfitData")
    @ApiOperation("本月毛利")
    public ResponseResult<ProfitDataResponse> getCurMonthProfitData(@Valid @RequestBody ProfitDataRequest request) {
        // 调用第三方接口
        return ResponseResult.success(thirdBigDataService.getCurMonthProfitData(request));
    }


    @PostMapping("/getPreMonthProfitData")
    @ApiOperation("上月毛利")
    public ResponseResult<ProfitDataResponse> getPreMonthProfitData(@Valid @RequestBody ProfitDataRequest request) {
        // 调用第三方接口
        return ResponseResult.success(thirdBigDataService.getPreMonthProfitData(request));
    }


    @PostMapping("/getMonthProfitTrend")
    @ApiOperation("毛利趋势")
    public ResponseResult<List<ProfitRateResponse>> getMonthProfitTrend(@Valid @RequestBody ProfitDataRequest request) {
        // 调用第三方接口
        return ResponseResult.success(thirdBigDataService.getMonthProfitTrend(request));
    }

    @PostMapping("/getActData")
    @ApiOperation("门店实收")
    public ResponseResult<ActDataResponse> getActData(@Valid @RequestBody ProfitDataRequest request) {
        // 调用第三方接口
        return ResponseResult.success(thirdBigDataService.getActData(request));
    }


    @PostMapping("/getShopInfo")
    @ApiOperation("火码 查询门店信息")
    public ResponseResult<ShopBaseInfoResponse> getShopInfo(@Valid @RequestBody ShopBasicInfoRequest request) {
        // 调用第三方接口
        return ResponseResult.success(huoMaService.getShopInfo(request));
    }

    @GetMapping("/getData")
    public  ResponseResult getData(@RequestParam("shopId")Long shopId,@RequestParam("type")Integer type){
        return ResponseResult.success(syncDataService.getData(shopId, DownSystemTypeEnum.getByCode(type)));
    }


    @Resource
    ShopAccountDAO shopAccountDAO;
    @Resource
    HyPartnerUserInfoDAO hyPartnerUserInfoDAO;
    @GetMapping("/initShopAccount")
    @ApiOperation("初始化门店账号")
    public ResponseResult<Integer> initShopAccount(@RequestParam(value = "partnerId", required = true) String partnerId,
                                                @RequestParam(value = "shopId", required = true) Long shopId) {
        // 调用第三方接口
        HyPartnerUserInfoDO hyPartnerUserInfoDO = hyPartnerUserInfoDAO.selectByPartnerId(partnerId);
        return ResponseResult.success(shopAccountDAO.initShopAccount(hyPartnerUserInfoDO,Arrays.asList(shopId)));
    }

    @Resource
    private PushService pushService;
    @GetMapping("/getXgjOrganization")
    @ApiOperation("获取新管家组织架构")
    public ResponseResult<Object> getXgjOrganization(@RequestParam(value = "partnerId", required = true,defaultValue = "0") String partnerId) {
        return ResponseResult.success(pushService.getXgjOrganization(partnerId));
    }

    @GetMapping("/getXgjAccessToken")
    @ApiOperation("获取新管家token")
    public ResponseResult<Object> getXgjAccessToken() {
        return ResponseResult.success(pushService.getXgjAccessToken());
    }

    @GetMapping("/getUnReadMessageNum")
    @ApiOperation("getUnReadMessageNum")
    public ResponseResult<Object> getUnReadMessageNum(@RequestParam(value = "partnerId", required = true,defaultValue = "0") String partnerId) {
        return ResponseResult.success(pushService.getUnReadMessageNum(partnerId));
    }



    @Resource
    ShopAccountService accountService;
    @Resource
    ThirdXinGuanJiaService thirdXinGuanJiaService;

    @ApiOperation("修改密码")
    @PostMapping("/modifyPassword")
    public ResponseResult<Boolean> modifyPassword(@RequestBody ModifyPasswordDTO request) {
        return ResponseResult.success(accountService.modifyPassword(request));
    }

    @ApiOperation("获取POS免登token")
    @PostMapping("/getPosToken")
    public ResponseResult<String> getPosToken(@RequestBody @Validated GetAccessTokenDTO dto) {
        return ResponseResult.success(pushService.getPosToken(dto));
    }



    @ApiOperation("获取加密子串")
    @PostMapping("/getEncryptedSubstring")
    public ResponseResult<String> getEncryptedSubstring(@RequestBody GetPasswordDTO dto) {
        return ResponseResult.success(thirdXinGuanJiaService.getPassword(dto));
    }

    @Resource
    UserAuthMappingServiceImpl userAuthMappingService;

    @GetMapping("/getAuthRegionIdAndSubRegionIdByUserId")
    @ApiOperation("获取管辖的子区域")
    public ResponseResult<List<String>> getAuthRegionIdAndSubRegionIdByUserId(@RequestParam(value = "userId", required = true) String userId) {
        return ResponseResult.success(userAuthMappingService.getAuthRegionIdAndSubRegionIdByUserId(userId));
    }
    @Resource
    ThirdFoodService thirdFoodService;
    @ApiOperation("获取菜品市场token")
    @PostMapping("/getFoodToken")
    public ResponseResult<String> getFoodToken(@RequestBody @Validated FoodTokenDTO dto) {
        return ResponseResult.success(thirdFoodService.getFoodToken(dto));
    }


    @GetMapping("/getToday")
    @ApiOperation("getToday")
    public ResponseResult<Boolean> getToday() {
        for (int i = 0; i < 10; i++) {
            System.out.println(linePayService.getPaymentReceiptCode());
        }
        return ResponseResult.success(Boolean.TRUE);
    }

    @GetMapping("/pushFranchiseFee")
    @ApiOperation("推送账单")
    public ResponseResult<Boolean> pushFranchiseFee(@RequestParam(value = "shopId", required = true) Long shopId) {
        FranchiseFeeDO franchiseFeeDO = franchiseFeeMapper.selectByShopId(shopId);
        ShopInfoDO shopInfoDO = shopInfoMapper.selectByPrimaryKey(shopId);
        LineInfoDO lineInfoDO = lineInfoDAO.getLineInfo(shopInfoDO.getLineId());
        PushFranchiseFeeRequest feeRequest = new PushFranchiseFeeRequest(shopInfoDO.getId(), lineInfoDO.getUsername(), franchiseFeeDO);
        pushService.pushFranchiseFeeToXGJ(feeRequest);
        return ResponseResult.success(Boolean.TRUE);
    }

    @GetMapping("/pushPay")
    @ApiOperation("推送收款单")
    public ResponseResult<Boolean> pushPay(@RequestParam(value = "shopId", required = true) Long shopId,
                                                @RequestParam(value = "payId", required = true) Long payId) {
        LinePayDO pay = linePayDAO.getById(payId);
        linePayService.pushPayInfo(shopId,pay);
        return ResponseResult.success(Boolean.TRUE);
    }

    @Resource
    ShopStageInfoDAO shopStageInfoDAO;

    @GetMapping("/franchiseFeeDataHandler")
    @ApiOperation("加盟费数据处理")
    public ResponseResult<Boolean> franchiseFeeDataHandler(){
        //查询所有的待加盟商缴费 推送账单
        List<ShopStageInfoDO> shopList = shopStageInfoDAO.getShopIdListByStageStatus(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_71.getShopSubStageStatus());
        log.info("----------开始推送账单数据---------");
        shopList.forEach(x->{
            try {
                FranchiseFeeDO franchiseFeeDO = franchiseFeeMapper.selectByShopId(x.getShopId());
                ShopInfoDO shopInfoDO = shopInfoMapper.selectByPrimaryKey(x.getShopId());
                LineInfoDO lineInfoDO = lineInfoDAO.getLineInfo(shopInfoDO.getLineId());
                PushFranchiseFeeRequest feeRequest = new PushFranchiseFeeRequest(shopInfoDO.getId(), lineInfoDO.getUsername(), franchiseFeeDO);
                pushService.pushFranchiseFeeToXGJ(feeRequest);
            } catch (Exception e) {
                log.error("推送数据失败  shopId {},异常信息：{}",x,e.getMessage());
            }
        });
        log.info("----------推送账单数据结束---------");
        //对账中
        log.info("----------开始推送账单与收款单数据---------");
        List<ShopStageInfoDO> shopList2 = shopStageInfoDAO.getShopIdListByStageStatus(ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_72.getShopSubStageStatus());
        shopList2.forEach(x->{
            //先推送账单
            try {
                FranchiseFeeDO franchiseFeeDO = franchiseFeeMapper.selectByShopId(x.getShopId());
                ShopInfoDO shopInfoDO = shopInfoMapper.selectByPrimaryKey(x.getShopId());
                LineInfoDO lineInfoDO = lineInfoDAO.getLineInfo(shopInfoDO.getLineId());
                PushFranchiseFeeRequest feeRequest = new PushFranchiseFeeRequest(shopInfoDO.getId(), lineInfoDO.getUsername(), franchiseFeeDO);
                pushService.pushFranchiseFeeToXGJ(feeRequest);
                List<LinePayDO> franchiseFeePayInfoByShopId = linePayDAO.getFranchiseFeePayInfoByShopId(x.getShopId());
                franchiseFeePayInfoByShopId.forEach(y->{
                    linePayService.pushPayInfo(x.getShopId(),y);
                });
            } catch (Exception e) {
                log.error("推送数据失败  shopId {},异常信息：{}",x,e.getMessage());
            }
        });
        log.info("----------账单与收款单数据推送完成---------");
        return ResponseResult.success(Boolean.TRUE);
    }

    @GetMapping("/getHqtToken")
    public ResponseResult<HqtTokenDTO> getHqtToken() {
        return ResponseResult.success(pushService.getHqtToken());
    }

    @ApiOperation("分配测量员，设计组")
    @PostMapping("/assignSurveyors")
    public ApiResponse<Boolean> assignSurveyors(@RequestBody @Validated AssignSurveyorsRequest request) {
        log.info("assignSurveyors request：{}", JSONObject.toJSONString(request));
        return ApiResponse.success(decorationMeasureService.assignSurveyors(request));
    }

    @ApiOperation("门店测量、上传测量图")
    @PostMapping("/submitMeasurementDiagram")
    public ApiResponse<Boolean> submitMeasurementDiagram(@RequestBody @Validated SubmitMeasurementRequest request) {
        log.info("submitMeasurementDiagram request：{}", JSONObject.toJSONString(request));
        return ApiResponse.success(decorationMeasureService.submitMeasurementDiagram(request));
    }

    @ApiOperation(" 分配设计师")
    @PostMapping("/assignDesigner")
    public ApiResponse<Boolean> assignDesigner(@RequestBody @Validated AssignDesignerRequest request) {
        log.info("assignDesigner request：{}", JSONObject.toJSONString(request));
        return ApiResponse.success(decorationDesignInfoService.assignDesigner(request));
    }

    @ApiOperation("上传设计图")
    @PostMapping("/submitDesignDrawing")
    public ApiResponse<Boolean> submitDesignDrawing(@RequestBody @Validated SubmitDesignDrawingRequest request) {
        log.info("submitDesignDrawing request：{}", JSONObject.toJSONString(request));
        return ApiResponse.success(decorationDesignInfoService.submitDesignDrawing(request));
    }

    @ApiOperation("分配报价员")
    @PostMapping("/assignQuotation")
    public ApiResponse<Boolean> assignQuotation(@RequestBody @Validated AssignQuotationRequest request) {
        log.info("assignQuotation request：{}", JSONObject.toJSONString(request));
        return ApiResponse.success(decorationDesignInfoService.assignQuotation(request));
    }

    @ApiOperation("上传报价单")
    @PostMapping("/submitQuotationSheet")
    public ApiResponse<Boolean> submitQuotationSheet(@RequestBody @Validated SubmitQuotationSheetRequest request) {
        log.info("submitQuotationSheet request：{}", JSONObject.toJSONString(request));
        return ApiResponse.success(decorationDesignInfoService.submitQuotationSheet(request));
    }

    @ApiOperation("施工派单")
    @PostMapping("/submitConstructionOrder")
    public ApiResponse<Boolean> submitConstructionOrder(@RequestBody @Validated ConstructionOrderRequest request) {
        log.info("submitConstructionOrder request：{}", JSONObject.toJSONString(request));
        return ApiResponse.success(decorationDesignInfoService.submitConstructionOrder(request));
    }

    @ApiOperation("实际进场确认")
    @PostMapping("/entryConfirmation")
    public ApiResponse<Boolean> entryConfirmation(@RequestBody @Validated EntryConfirmationRequest request) {
        log.info("entryConfirmation request：{}", JSONObject.toJSONString(request));
        return ApiResponse.success(decorationDesignInfoService.entryConfirmation(request));
    }

    @ApiOperation("施工完成")
    @PostMapping("/constructionCompleted")
    public ApiResponse<Boolean> constructionCompleted(@RequestBody @Validated ConstructionCompletedRequest request) {
        log.info("constructionCompleted request：{}", JSONObject.toJSONString(request));
        return ApiResponse.success(decorationDesignInfoService.constructionCompleted(request));
    }

    @ApiOperation("装修验收")
    @PostMapping("/decorationAcceptance")
    public ApiResponse<Boolean> decorationAcceptance(@RequestBody @Validated HqtDecorationAcceptanceRequest request) {
        log.info("decorationAcceptance request：{}", JSONObject.toJSONString(request));
        return ApiResponse.success(decorationDesignInfoService.decorationAcceptance(request));
    }

    @ApiOperation("测试红圈通建店")
    @GetMapping("/testHqtBuild")
    public ApiResponse<Boolean> testHqtBuild(@RequestParam("shopId")Long shopId) {
        HqtBuildRequest hqtBuildRequest = getHqtBuildRequest(shopId);
        hqtAPIService.pushHqtBuild(hqtBuildRequest);
        return ApiResponse.success(true);
    }

    @ApiOperation("测试红圈推送片区")
    @GetMapping("/testHqtRegion")
    public ApiResponse<Boolean> testHqtRegion() {
        hqtAPIService.pushHqtRegion(null);
        return ApiResponse.success(true);
    }






    public HqtBuildRequest getHqtBuildRequest(Long shopId) {
        ShopInfoDO shopInfo = shopInfoDAO.getShopInfo(shopId);
        LineInfoDO lineInfoDO = lineInfoDAO.getLineInfo(shopInfo.getLineId());
        EnterpriseUserDO userInfoById = enterpriseUserDAO.getUserInfoById(shopInfo.getInvestmentManager());
        BigRegionDO bigRegionDO = bigRegionDAO.getByRegionId(shopInfo.getRegionId());
        HqtBuildRequest request = new HqtBuildRequest();
        request.setShopId(shopId);
        request.setShopCode(shopInfo.getShopCode());
        request.setShopName(shopInfo.getShopName());
        request.setShopDecorationAttributes(shopInfo.getShopDecorationAttributes());
        request.setHqtRegionCode(bigRegionDO.getHqtRegionCode());
        request.setHqtRegionName(bigRegionDO.getHqtRegionName());
        request.setSupervisorName(userInfoById.getName());
        request.setSupervisorMobile(userInfoById.getMobile());
        request.setPartnershipSignatoryFirst(lineInfoDO.getUsername());
        request.setPartnershipSignatoryFirstMobile(lineInfoDO.getMobile());
        request.setShopAddress(shopInfo.getDetailAddress());
        request.setIsPayDesignFee(CommonConstants.ONE);
        if (StringUtils.isNotBlank(shopInfo.getFranchiseBrand())) {
            request.setFranchiseBrand(Integer.valueOf(shopInfo.getFranchiseBrand()));
        }
        return request;
    }


    @RequestMapping(value = "/testWxNotice", produces = "application/xml;charset=UTF-8")
    @ApiOperation("testWxNotice")
    public String handleWechatMessage(
            @RequestParam("signature") String signature,
            @RequestParam("timestamp") String timestamp,
            @RequestParam("nonce") String nonce,
            @RequestParam(value = "echostr", required = false) String echostr,
            @RequestBody(required = false) String requestBody) {

        System.out.println("收到微信消息:");
        System.out.println("signature: " + signature);
        System.out.println("timestamp: " + timestamp);
        System.out.println("nonce: " + nonce);
        System.out.println("echostr: " + echostr);
        System.out.println("requestBody: " + requestBody);

        if (StringUtils.isNotEmpty(requestBody)) {
            try {
                return weChatHandler.processMessage(weChatHandler.parseXmlToMap(requestBody));
            } catch (Exception e) {
                log.info("回调处理失败 e:{}",e.getMessage());
                return "success";
            }
        }
        return nonce;
    }

    @ApiOperation("测试小程序模板消息")
    @PostMapping("/testMiniAppTemplate")
    public ApiResponse<Boolean> testMiniAppTemplate() {
        Map<String, Object> data = new HashMap<>();
        data.put("character_string2", "ceshi002");
        data.put("thing10", "测试通知功能");
        data.put("time14", "2025-10-01 12:00:00");
        data.put("thing25", "正新管理有限公司");
        data.put("thing60", "上海市-松江区");
        wechatTemplateService.sendNormalTemplate("o9_unvpJy1SGdnkeun7igRBSLuB0", WechatTemplateEnum.QUESTION_NOTICE, data);
        return ApiResponse.success(true);
    }

    @Resource
    XinFaBusinessService xinFaBusinessService;
    @ApiOperation("测试门店设备信息")
    @GetMapping("/getStoreXinFaDeviceDetail")
    public ResponseResult<List<StoreXinFaDeviceDetail>> getStoreXinFaDeviceDetail(@RequestParam("storeNum")String storeNum) {
        return ResponseResult.success(xinFaBusinessService.getStoreXinFaDeviceDetail(storeNum));
    }

    @ApiOperation("测试标签信息")
    @GetMapping("/getAccountAllTags")
    public ResponseResult<List<TagDetailDTO>> getAccountAllTags(@RequestParam("storeNum")String storeNum,
                                                                @RequestParam("deviceName")String deviceName) {
        List<TagDetailDTO> accountAllTags = xinFaBusinessService.getAccountAllTags(storeNum,deviceName);
        return ResponseResult.success(accountAllTags);
    }

    @ApiOperation("获取节目列表")
    @PostMapping("/getProgramList")
    public ResponseResult<List<ProgramResponseDTO>> getProgramList(@RequestBody ProgramReqDTO programReqDTO) {
        List<ProgramResponseDTO> accountAllTags = xinFaBusinessService.getProgramList(programReqDTO);
        return ResponseResult.success(accountAllTags);
    }

    @ApiOperation("发布/上架")
    @PostMapping("/publishProgram")
    public ResponseResult<Boolean> publishProgram(@RequestBody PublishDTO publishDTO) {
        Boolean publishStatus = xinFaBusinessService.publishProgram(publishDTO);
        return ResponseResult.success(publishStatus);
    }

}
