Browse Source

app config

albertshaw 8 years ago
parent
commit
911b1d1f0a

+ 36 - 0
schema/20170816-appconfig.sql

@@ -0,0 +1,36 @@
+CREATE TABLE `app_config` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `cate` varchar(45) DEFAULT NULL COMMENT '分类',
+  `key` varchar(45) DEFAULT NULL COMMENT '关键字',
+  `name` varchar(45) DEFAULT NULL COMMENT '名称',
+  `value` varchar(45) DEFAULT NULL COMMENT '值',
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8;
+
+
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('collections', 'demand', '需求', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('collections', 'achievement', '成果', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('collections', 'expert', '专家', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('collections', 'company', '企业', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('collections', 'school', '高校', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('collections', 'institute', '院所', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('collections', 'policy', '政策', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('collections', 'activity', '活动', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('collections', 'news', '快讯', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('orders', 'hightech', '高企', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('orders', 'program', '科技项目', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('orders', 'patent', '专利', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('orders', 'copyright', '软著', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('orders', 'evalution', '评估', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('orders', 'activity', '活动', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('orders', 'crowdfunding', '众筹', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('orders', 'achievement', '买技术', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('orders', 'demand', '接需求', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('orders', 'date', '邀约专家', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('orders', 'consultant', '技术咨询', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('mytech', 'match', '匹配', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('mytech', 'intention', '意向', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('mytech', 'deal', '成交', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('myexpert', 'date', '邀约', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('myexpert', 'intention', '意向', '1');
+INSERT INTO `app_config` (`cate`, `key`, `name`, `value`) VALUES ('myexpert', 'deal', '成交', '1');

+ 27 - 0
src/main/java/com/goafanti/app/controller/MyAppApiController.java

@@ -0,0 +1,27 @@
+package com.goafanti.app.controller;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.goafanti.app.service.AppConfigService;
+import com.goafanti.common.bo.Result;
+import com.goafanti.common.controller.BaseApiController;
+import com.goafanti.common.utils.StringUtils;
+
+@RestController
+@RequestMapping(path = "/api/app", method = RequestMethod.GET)
+public class MyAppApiController extends BaseApiController {
+
+	@Autowired
+	AppConfigService appConfigService;
+
+	@RequestMapping(value = "/config", method = RequestMethod.GET)
+	public Result config(String noCache) {
+		if (StringUtils.equals(noCache, "1")) {
+			appConfigService.cleanList();
+		}
+		return res().data(appConfigService.findPortalAppConfigs());
+	}
+}

+ 34 - 0
src/main/java/com/goafanti/app/service/AppConfigService.java

@@ -0,0 +1,34 @@
+package com.goafanti.app.service;
+
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.stereotype.Service;
+
+import com.alibaba.fastjson.JSONObject;
+import com.goafanti.common.dao.AppConfigMapper;
+import com.goafanti.common.utils.LoggerUtils;
+import com.goafanti.core.mybatis.BaseMybatisDao;
+
+@Service
+public class AppConfigService extends BaseMybatisDao<AppConfigMapper> {
+	@Autowired
+	AppConfigMapper				appConfigMapper;
+
+	private static final Logger	logger	= LoggerFactory.getLogger(AppConfigService.class);
+
+	@Cacheable(value = "AppConfigListCache", key = "'AppConfigList'")
+	public List<JSONObject> findPortalAppConfigs() {
+		return appConfigMapper.findList();
+	}
+
+	@CacheEvict(value = "AppConfigListCache", key = "'AppConfigList'")
+	public void cleanList() {
+		LoggerUtils.debug(logger, "清除app配置列表缓存");
+	}
+
+}

+ 22 - 0
src/main/java/com/goafanti/common/dao/AppConfigMapper.java

@@ -0,0 +1,22 @@
+package com.goafanti.common.dao;
+
+import java.util.List;
+
+import com.alibaba.fastjson.JSONObject;
+import com.goafanti.common.model.AppConfig;
+
+public interface AppConfigMapper {
+	int deleteByPrimaryKey(Integer id);
+
+	int insert(AppConfig record);
+
+	int insertSelective(AppConfig record);
+
+	AppConfig selectByPrimaryKey(Integer id);
+
+	int updateByPrimaryKeySelective(AppConfig record);
+
+	int updateByPrimaryKey(AppConfig record);
+
+	List<JSONObject> findList();
+}

+ 98 - 0
src/main/java/com/goafanti/common/mapper/AppConfigMapper.xml

@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.goafanti.common.dao.AppConfigMapper">
+  <resultMap id="BaseResultMap" type="com.goafanti.common.model.AppConfig">
+    <id column="id" jdbcType="INTEGER" property="id" />
+    <result column="cate" jdbcType="VARCHAR" property="cate" />
+    <result column="key" jdbcType="VARCHAR" property="key" />
+    <result column="name" jdbcType="VARCHAR" property="name" />
+    <result column="value" jdbcType="VARCHAR" property="value" />
+  </resultMap>
+  <sql id="Base_Column_List">
+    `id`, `cate`, `key`, `name`, `value`
+  </sql>
+  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
+    select 
+    <include refid="Base_Column_List" />
+    from app_config
+    where id = #{id,jdbcType=INTEGER}
+  </select>
+  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
+    delete from app_config
+    where id = #{id,jdbcType=INTEGER}
+  </delete>
+  <insert id="insert" parameterType="com.goafanti.common.model.AppConfig">
+    insert into app_config (`id`, `cate`, `key`, 
+      `name`, `value`)
+    values (#{id,jdbcType=INTEGER}, #{cate,jdbcType=VARCHAR}, #{key,jdbcType=VARCHAR}, 
+      #{name,jdbcType=VARCHAR}, #{value,jdbcType=VARCHAR})
+  </insert>
+  <insert id="insertSelective" parameterType="com.goafanti.common.model.AppConfig">
+    insert into app_config
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+      <if test="id != null">
+        `id`,
+      </if>
+      <if test="cate != null">
+        `cate`,
+      </if>
+      <if test="key != null">
+        `key`,
+      </if>
+      <if test="name != null">
+        `name`,
+      </if>
+      <if test="value != null">
+        `value`,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
+      <if test="id != null">
+        #{id,jdbcType=INTEGER},
+      </if>
+      <if test="cate != null">
+        #{cate,jdbcType=VARCHAR},
+      </if>
+      <if test="key != null">
+        #{key,jdbcType=VARCHAR},
+      </if>
+      <if test="name != null">
+        #{name,jdbcType=VARCHAR},
+      </if>
+      <if test="value != null">
+        #{value,jdbcType=VARCHAR},
+      </if>
+    </trim>
+  </insert>
+  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.AppConfig">
+    update app_config
+    <set>
+      <if test="cate != null">
+        `cate` = #{cate,jdbcType=VARCHAR},
+      </if>
+      <if test="key != null">
+        `key` = #{key,jdbcType=VARCHAR},
+      </if>
+      <if test="name != null">
+        `name` = #{name,jdbcType=VARCHAR},
+      </if>
+      <if test="value != null">
+        `value` = #{value,jdbcType=VARCHAR},
+      </if>
+    </set>
+    where id = #{id,jdbcType=INTEGER}
+  </update>
+  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.AppConfig">
+    update app_config
+    set `cate` = #{cate,jdbcType=VARCHAR},
+      `key` = #{key,jdbcType=VARCHAR},
+      `name` = #{name,jdbcType=VARCHAR},
+      `value` = #{value,jdbcType=VARCHAR}
+    where id = #{id,jdbcType=INTEGER}
+  </update>
+  <select id="findList" resultType="com.alibaba.fastjson.JSONObject">
+    select 
+    <include refid="Base_Column_List" />
+    from app_config
+  </select>
+</mapper>

+ 66 - 0
src/main/java/com/goafanti/common/model/AppConfig.java

@@ -0,0 +1,66 @@
+package com.goafanti.common.model;
+
+public class AppConfig {
+	private Integer	id;
+
+	/**
+	 * 分类
+	 */
+	private String	cate;
+
+	/**
+	 * 关键字
+	 */
+	private String	key;
+
+	/**
+	 * 名称
+	 */
+	private String	name;
+
+	/**
+	 * 值
+	 */
+	private String	value;
+
+	public Integer getId() {
+		return id;
+	}
+
+	public void setId(Integer id) {
+		this.id = id;
+	}
+
+	public String getCate() {
+		return cate;
+	}
+
+	public void setCate(String cate) {
+		this.cate = cate;
+	}
+
+	public String getKey() {
+		return key;
+	}
+
+	public void setKey(String key) {
+		this.key = key;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public String getValue() {
+		return value;
+	}
+
+	public void setValue(String value) {
+		this.value = value;
+	}
+
+}