package com.dgtly.quartz.task;

import com.dgtly.common.utils.StringUtils;
import com.dgtly.sync.service.AnalysisDiyCustomerComponent;
import com.dgtly.sync.service.HanaOrderComponent;
import com.dgtly.sync.service.RelationCustomerOnlineComponent;
import com.dgtly.sync.service.ShopUserTypeComponent;
import com.dgtly.system.service.ISysUserOrderAuthorService;
import com.dgtly.system.service.HanaSalesOrderService;
import com.dgtly.wxportal.service.IWxSendMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

/**
 * 定时任务调度测试
 *
 * @author dgtly
 */
@Component("ryTask")
@Slf4j
public class RyTask
{

    @Autowired
    private AnalysisDiyCustomerComponent analysisDiyCustomerComponent;
    @Autowired
    private HanaOrderComponent hanaOrderComponent;
    @Autowired
    private RelationCustomerOnlineComponent relationCustomerOnlineComponent;
    @Autowired
    private ISysUserOrderAuthorService sysUserOrderAuthorService;
    @Autowired
    private IWxSendMessageService wxSendMessageService;
    @Autowired
    private HanaSalesOrderService HanaSalesOrderService;
    @Autowired
    private ShopUserTypeComponent shopUserTypeComponent;

//    private static RyTask ryTask;
//    @PostConstruct
//    public void init() {
//        ryTask = this;
//        ryTask.analysisDiyCustomerComponent = this.analysisDiyCustomerComponent;
//    }

    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
    {
        log.info(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params)
    {
        log.info("执行有参方法：" + params);
    }

    public void ryNoParams()
    {
        log.info("执行无参方法");
    }

    /*立邦DIY人员定时同步*/
    public void analyDiyCustomer(){
        analysisDiyCustomerComponent.analyDiyCustomer();
    }
    public void analyDiyCustomer1(){
        analysisDiyCustomerComponent.analyDiyCustomer1();
    }


    //针对特殊人的定时任务修改入库ass表
    public void analyDiyCustomer2(){
        analysisDiyCustomerComponent.analyDiyCustomer2();
    }
    /**
     * @description: 获取TUC仿石漆服务商人员
     * @param: []
     * @return: void
     * @author: njs
     * @date: 2025/8/18 13:53
     */
    public void shopStoneLikePaint() throws ParseException {
        //获取TUC仿石漆服务商人员
        shopUserTypeComponent.shopStoneLikePaint();
        //获取金牌店用户人员
        shopUserTypeComponent.shopGoldShopUser();
    }

    /**
     * @description: 获取金牌店用户人员
     * @param: []
     * @return: void
     * @author: njs
     * @date: 2025/9/1 10:39
     */
  /* public void shopGoldShopUser()throws ParseException{
       shopUserTypeComponent.shopGoldShopUser();
    }*/

    /*HANA订单数据定时同步*/
    public void hanaSalesOrderSync() throws Exception {
        hanaOrderComponent.hanaSalesOrderSync();
    }

    /**HANA交货单电子签收定时同时*/
    public void hanaSalesDeliverSignatureSync() throws Exception {
        hanaOrderComponent.hanaSalesDeliverSignatureSync();
    }

    /**定时同步公装经销商(主经销商认证则公装也认证)*/
    public void certificationSync() throws Exception {
        hanaOrderComponent.certificationSync();
    }

    /**
     * @description: C类产品订单标记
     * @param: []
     * @return: void
     * @author: njs
     * @date: 2025/5/7 13:22
     */
    public void hanaErpOrderSyncByC()throws Exception {
        hanaOrderComponent.hanaErpOrderSyncByC();
    }

    /*HANA交货单数据定时同步*/
    public void hanaDeliverOrderSync() throws Exception {
        hanaOrderComponent.hanaDeliverOrderSync();
    }

    /**HANA已复核线下月底手动过账的交货单仍需自提同步*/
    public void hanaSelfReviewedDeliverOrderSync()throws Exception{
        hanaOrderComponent.hanaSelfReviewedDeliverOrderSync();
    }

    /**HANA已冻结经销商**/
    public void hanaFreezeCustomer()throws Exception{
        hanaOrderComponent.hanaFreezeCustomer();
    }


    /*关联经销商上线定时任务*/
    public void relationCustomerOnlineSync() throws Exception {
        relationCustomerOnlineComponent.relationCustomerOnlineSync();
    }

    /*初始化用户权限*/
    public void initUserAuthor() throws Exception {
        sysUserOrderAuthorService.initUserAuthor();
    }
    /**
     *
     * 离职用户标识
     * **/
    public void quitUser()throws Exception {
        sysUserOrderAuthorService.quitUser();
    }



    /**
     *
     * 维护经销商表
     * **/
    public void updateCustomers()throws Exception {
        sysUserOrderAuthorService.updateCustomers();
    }

    /**
     * 用户账号重复通知邮件
     * **/
    public void sendmailUnionUser()throws Exception{
        sysUserOrderAuthorService.sendmailUnionUser();
    }

    /**
     * 有道接口经销商用户账号重复进行业务处理
     * **/
    public void unionCustomerUser(){
        sysUserOrderAuthorService.unionCustomerUser();
    }

    /**
     * @description: 无tms工厂的交货单更新状态和订单
     * @param: []
     * @return: void
     * @author: njs
     * @date: 2023/2/23 13:16
     */
    public void tmsPlantByOrder(){
        sysUserOrderAuthorService.tmsPlantByOrder();
    }

    /**
     * @description: 经销商自动上线
     * @param:
     * @return:
     * @author: njs
     * @date: 2023/2/23 13:16
     */
    public void customersStart(){
        sysUserOrderAuthorService.customersStart();
    }

    /**
     * @description: 自提未提货企微消息通知提醒
     * @param:
     * @return:
     * @author: njs
     * @date: 2023/5/15 11:29
     */
    public void sendWxTmsMessage(){
        wxSendMessageService.sendWxTmsMessage();
    }

    /**
     * @description: 未过信的经销商订单的要货记录id（做逻辑删除，重新要货）
     * @param: []
     * @return: void
     * @author: njs
     * @date: 2023/6/16 10:26
     */
  /*  public void  salesOrderBaseByCreditStatus(){
        HanaSalesOrderService.updateSalesOrderBaseNoCrditStatus();
    }*/


    /**
     * @description: 交货冻结取货定时任务
     *               从 meta_hana_not_freeze_customer 白名单确认当前所有已冻结经销商，
     *               在 sales_order_base 中查询满足以下条件的要货记录执行逻辑删除（取消）：
     *               1. 经销商属于已冻结名单（不在白名单中）
     *               2. 订单状态满足任一条件：未复核金额≠0、或冻结≠0、或信用状态不为空
     *               3. 订单尚未完成发货（NO_DELIVER_AMT != 0，已发货订单不取消）
     *               取消完成后记录操作日志，并通过企业微信向经销商负责人、要货人、对应销售推送通知。
     * @author: njs
     */
    public void cancelFreezeCustomerOrder() {
        List<Map<String, Object>> canceledList = HanaSalesOrderService.cancelFreezeCustomerOrder();
//        if (canceledList != null && !canceledList.isEmpty()) {
//            wxSendMessageService.sendFreezeCustomerCancelOrderMessage(canceledList);
//        }
    }


    /**
     * @description: 业绩进度指标预警邮件/企微消息通知
     * @param:
     * @return:
     * @author: njs
     * @date: 2024/2/4 9:21
     */
    public void sendMailAndWxEarlyTucMessage(){
        wxSendMessageService.sendMailAndWxEarlyTucMessage();
    }


}
