package com.jwipc.web.config;

import com.jwipc.prop.PriceHandle;
import com.jwipc.prop.SysProp;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * @author shenyang.ou
 * @date 2024/3/13 20:27
 * @desc 配置全局变量
 */
@Slf4j
@Configuration
@Data
@RequiredArgsConstructor
public class FreeMarkerConfig {
    private final freemarker.template.Configuration configuration;
    private final SysProp sysProp;
    private final PriceHandle priceHandle;

    @PostConstruct
    public void setConfigure() throws Exception {
        configuration.setSharedVariable("sysProp", sysProp);
        configuration.setSharedVariable("priceHandle", priceHandle);
        configuration.setSharedVariable("formatterPrice", new FormatterPriceMethod(priceHandle.getPrecision(),priceHandle.getRepair(),priceHandle.getThousand(),priceHandle.getCutType()));
        configuration.setSharedVariable("formatterFormPrice", new FormatterFormPriceMethod(2,true,priceHandle.getThousand(),priceHandle.getCutType()));
        configuration.setNumberFormat("#");
    }
}
