com.ctvit.vdp.product.baseconfig.service.SystemConfigService.java Source code

Java tutorial

Introduction

Here is the source code for com.ctvit.vdp.product.baseconfig.service.SystemConfigService.java

Source

package com.ctvit.vdp.product.baseconfig.service;

import java.util.ArrayList;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.Element;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

import com.ctvit.vdp.common.Constants;
import com.ctvit.vdp.framework.services.BaseServices;
import com.ctvit.vdp.product.baseconfig.dao.SystemConfigMapper;
import com.ctvit.vdp.product.baseconfig.entity.SystemConfig;
import com.ctvit.vdp.utils.EncryptionUtil;
import com.ctvit.vdp.utils.XMLUtil;

public class SystemConfigService extends BaseServices {
    private static final long serialVersionUID = -3419274835562296788L;

    private SystemConfigMapper systemConfigDao;

    public SystemConfigMapper getSystemConfigDao() {
        return systemConfigDao;
    }

    public void setSystemConfigDao(SystemConfigMapper systemConfigDao) {
        this.systemConfigDao = systemConfigDao;
    }

    public SystemConfig load(String id) {
        return systemConfigDao.selectByPrimaryKey(id);
    }

    public String getSystemConfig(String id) {
        try {
            SystemConfig systemconfig = systemConfigDao.selectByPrimaryKey(id);
            return systemconfig.getValue();
        } catch (Exception e) {
            logger.error("???" + e.getMessage());
            return null;
        }
    }

    public ArrayList<String[]> getOrgTypes() throws Exception {
        String[] typeBean = null;
        ArrayList<String[]> resultList = new ArrayList<String[]>();
        Document doc = XMLUtil.transforXml(getSystemConfig("EnumDefines"));
        Element root = doc.getRootElement();
        List<Element> selectedNodes = root.selectNodes("Enum");
        for (Element element : selectedNodes) {
            if ("".equals(element.attributeValue("enumid"))) {
                List<Element> el = element.elements("EnumNode");
                for (Element element1 : el) {
                    typeBean = new String[2];
                    typeBean[0] = element1.attributeValue("label");
                    typeBean[1] = element1.attributeValue("value");
                    resultList.add(typeBean);
                }
                break;
            }
        }
        return resultList;
    }

    public int updateSystemConfig(SystemConfig systemConfig) {
        try {
            int flag = 0;
            logger.debug("??" + systemConfig.getId() + "" + systemConfig.getValue());

            //?License?
            if (systemConfig.getId().equals("License")) {
                systemConfig.setValue(EncryptionUtil.get3DESDecrypt(systemConfig.getValue(), Constants.SPKEY));
                logger.debug("??" + systemConfig.getId() + "?"
                        + systemConfig.getValue());
            }

            SystemConfig config = load(systemConfig.getId());
            if (config != null) {
                flag = systemConfigDao.updateByPrimaryKeyWithBLOBs(systemConfig);
            } else {
                flag = systemConfigDao.insert(systemConfig);
            }
            return flag;
        } catch (Exception e) {
            logger.error("??", e);
            return -1;
        }
    }

    public static void main(String[] args) {
        BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("./config/applicationContext.xml"));
        SystemConfigService service = (SystemConfigService) beanFactory.getBean("systemConfigService");
        //      SystemConfig conf = new SystemConfig();
        //      conf.setId("product_auto_publish");
        //      conf.setValue("dda346cf0a484b359b7d4817a63f2848,0512e10c1b5f4739b12fa66a00aefa51,2e94335740c84c83924c57f7952b79c3,06bbae116af34aba989228501d5c38f9,14eaac6448ef4371a99d9ae0bf217839,2b47f793f45644e78240e6af4fb6de5e,eda38672b618425585be6c2b787b48a7");
        //      int flag = service.updateSystemConfig(conf);
        //      System.out.println(flag);
        try {
            service.getOrgTypes();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        String name = "1.jpg";
        System.out.println(name.substring(name.indexOf("/."), name.length()));

    }

}