package com.cigna.hmc.groupinsurance.server.service; import com.cigna.hmc.groupinsurance.server.con



/**
 * 发送核保结果信息给用户
 * 其功能被SmsUtils替代
 * @author p1guxx
 */
@Service
public class SendOrderInfoSmsService {

    @Value(value = "${sms.env}")
    private String smsEnv;

     @Autowired
     private SmsUtils smsUtils;

    @Autowired
    private ConfigurationImp configurationImp;
    @Autowired
    private SurgeryInfoService surgeryInfoService;
    @Autowired
    private OrderServiceImpl orderServiceImpl;

    private static Logger log = LoggerFactory.getLogger(SendOrderInfoSmsService.class);



    /**
     * @desc 发送核保结果短信  过时!!!
     *          仅用于兼容旧版短信接口,新需求不得再使用!!!
     *          新接口使用参考SmsUtilssendSMS方法
     *          以及SmsTest单元测试
     *
     *  如果有的人工核保没发送短信,查看UWNotifyServiceImpl 198行 的控制发送短信的列表
     *  
     * @param mobile_phone   手机号
     * @param organizationId
     * @param orderType      订单类型
     * @param name           用户姓名
     */
    @Deprecated
    public void sendUnderwritingMessage(String mobile_phone, String organizationId, String orderType, String name,
                                        String source) throws Exception {

        log.info("sendUnderwritingMessage mobile_phone:" + mobile_phone + " orderType:" + orderType + " userName"
                + name + " ;  source == " + source);

        if (StringUtils.isBlank(mobile_phone) || StringUtils.isBlank(orderType) || StringUtils.isBlank(name)
                || StringUtils.isBlank(source)) {
            return;
        }

        Map<String, String> config = configurationImp.getConfigurationFromFile(source);

        if (config == null) {
            config = configurationImp.getConfigurationFromFile(orderType);
        }
        String effectiveDate = config.get("effectiveDate");
        if (StringUtils.isEmpty(effectiveDate)) {
            Map<String, String> map = configurationImp.getConfigurationFromDB(source, organizationId,
                    Integer.parseInt(orderType), null);
            if (map == null || map.isEmpty()) {
                if (!"aon".equals(source) && !"cmbnt".equals(source) && !"cmb".equals(source)) {// 除了aoncmbnt其他项目需要有生效日期
                    log.info("source=" + source + ", need effectiveDate");
                    return;
                }
            }
            if (map != null) {
                effectiveDate = map.get("START_DATE");
            }
        }

        String message = "";
        String insuranceName = config.get("insuranceName_" + orderType);
        if (StringUtils.isBlank(insuranceName)){
            insuranceName=config.get("insuranceName_" + orderType+"_1");
        }

        //新短信发送方式
        //6
        String sms_type="igi_underwriting_003";
        if ("cmbnt".equals(source) || "mercer".equals(source) || "bosch".equals(source) || "sina2".equals(source)) {
            //2
            sms_type="igi_underwriting_001";
        } else if ("tencent".equals(source) || "sbabs".equals(source) || "jianyun".equals(source)) {
            //4
            sms_type="igi_underwriting_002";
        } else if ("cmb".equals(source)) {
            //7
            if ("1".equals(orderType)) {
                // 珍爱
                insuranceName="招商信诺珍爱百分百团体重大疾病保险";
            } else {
                // 智选
                insuranceName="招商信诺精英智选高端医疗团体保险";
            }
        } else if ("test2".equals(source) || "nuskin".equals(source) || "sina".equals(source) || "qihu".equals(source)
                || "qiwei".equals(source) || "zaaf".equals(source)||"xhxdd".equals(source)||"fc".equals(source)) {
            //4
            sms_type="igi_underwriting_002";
        } else if ("igipension".equals(source)) {
            //6
            sms_type="igi_underwriting_003";
        }

        log.info("UnderwritingMessage message=" + message);
        /*if (StringUtils.isNotBlank(effectiveDate) && !effectiveDate.contains("")){
            String[] arr=effectiveDate.split("-");
            effectiveDate=String.format("%s%%",arr[0],arr[1],arr[2]);
        }*/

        boolean result=false;


        if ("igi_underwriting_001".equals(sms_type)){
            result = smsUtils.sendSMS(sms_type,mobile_phone,name,insuranceName,name);
        }else{
            result = smsUtils.sendSMS(sms_type,mobile_phone,name,insuranceName,effectiveDate);
        }

        if (result) {
            log.info("sendUnderwritingMessage succeed");
        } else {
            log.info("sendUnderwritingMessage failed,failed mobile_phone"+mobile_phone+",username="+name);
        }
    }

    /**
     *@author : daniel.yang
     *@date : 2018/4/26
     *@desc : 支付成功通知短信发送接口  过时!!!
     *          仅用于兼容旧版短信接口,新需求不得再使用!!!
     *          新接口使用参考SmsUtilssendSMS方法
     *          以及SmsTest单元测试
     *
     *@debug 支付成功不能发送短信去payController查看sendSmsPaySuccess方法的短信控制列表里面有没有添加对应的source
     *
     *@param mobile_phone :
     *@param order_number :
     *@param order_type :
     *@param organizationId :
     *@param name :
     *@param source :
     */
    @Deprecated
    public boolean sendPaySuccessMessage(String mobile_phone, String order_number, Integer order_type,
                                         String organizationId, String name, String source) throws Exception {

        log.info(String.format("sendPaySuccessMessage mobile_phone:%s,order_number:%s,order_type:%s,name:%s,organizationId:%s,source:%s",
                mobile_phone,order_number,order_type,name,organizationId,source));

        if (StringUtils.isBlank(mobile_phone) || StringUtils.isBlank(order_number) || StringUtils.isBlank(name)
                || StringUtils.isBlank(source)) {
            log.info("mobile_phone=" + mobile_phone + ",order_number=" + order_number + ",order_type=" + order_type
                    + ",organizationId=" + organizationId + ",name=" + name + ",source=" + source);
            return false;
        }

        Map<String, String> config = configurationImp.getConfigurationFromFile(source);

        if (config == null) {
            config = configurationImp.getConfigurationFromFile(String.valueOf(order_type));
        }
        String effectiveDate = config.get("effectiveDate");
        if (StringUtils.isEmpty(effectiveDate)) {
            Map<String, String> map = configurationImp.getConfigurationFromDB(source, organizationId, order_type, null);
            if (map == null || map.isEmpty()) {
                if (!"aon".equals(source) && !"cmbnt".equals(source) && !"cmb".equals(source)
                        && !"surgery".equals(source)) {// 除了aoncmbnt其他项目需要有生效日期
                    log.info("source=" + source + ", need effectiveDate");
                    return false;
                }

            }
            if (map != null) {
                effectiveDate = map.get("START_DATE");
            }

        }
        //5
        String sms_type="igi_pay_online_002";
        if ("cmbnt".equals(source) || "mercer".equals(source) || "cmb".equals(source) || "bosch".equals(source) || "sina2".equals(source) || "ipmi".equals(source)) {
            //3.
            sms_type="igi_pay_online_001";
        } else if ("surgery".equals(source) || "surgery2".equals(source)) {
            List<Order> orders = orderServiceImpl.getOrderByOrderNumber(order_number);
            if (orders != null && orders.size() > 0) {
                Order order = orders.get(0);
                SurgeryInfo surgery = surgeryInfoService.getSurgeryInfoByOrderId(String.valueOf(order.getId()));
                //5
                effectiveDate=DateUtil.format(surgery.getOperationDate(), DateUtil.YYYY_MM_DD);
            }

        }
        if (StringUtils.isNotBlank(effectiveDate) && !effectiveDate.contains("")){
            String[] arr=effectiveDate.split("-");
            effectiveDate=String.format("%s%s%s",arr[0],arr[1],arr[2]);
           // effectiveDate= new SimpleDateFormat("yyyyMMdd").format(new SimpleDateFormat("yyyy-MM-dd").parse(effectiveDate));
        }

        boolean result = smsUtils.sendSMS(sms_type,mobile_phone,order_number,name,effectiveDate);

        if (result) {
            log.info("sendPaySuccessMessage succeed");
            return true;
        } else {
            log.info("sendPaySuccessMessage failed ,failed mobile_phone"+mobile_phone+",username="+name);
            return false;
        }
    }
}

猜你喜欢

转载自my.oschina.net/u/3055377/blog/1806371