Commit 2315161b by 陈文顺

jsj

parent c78812d4
...@@ -23,6 +23,11 @@ ...@@ -23,6 +23,11 @@
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
<version>1.2.32</version> <version>1.2.32</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies> </dependencies>
......
package com.freemud.demo.service; package com.freemud.demo.service;
import com.freemud.demo.dto.DictDataDto; import com.freemud.demo.dto.*;
import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -9,18 +10,21 @@ import java.util.Map; ...@@ -9,18 +10,21 @@ import java.util.Map;
/** /**
* Created by chenwenshun on 2017/1/4. * Created by chenwenshun on 2017/1/4.
*/ */
@RequestMapping(value = "/dict",produces = "application/json")
public interface IDictService { public interface IDictService {
/** 根据主表cd获取数据列表 */ @PostMapping("/page")
public List<DictDataDto> loadDatasByTypeCd(String dictTypeCd); ResDto page(@RequestBody PageReq pageReq);
/** 根据dictTypeCd取得数据map,用于填充下拉框 */
public Map<String, String> loadDataMap(String dictTypeCd);
/** 根据cd取得数据字典 @GetMapping("/getById")
* @param dictTypeCd ResDto getById(@RequestParam("id") Long id);
* @param dictCd
* */
public DictDataDto getDictDataByCd(String dictTypeCd, String dictCd); @GetMapping( value = "/dictDatas/{dictTypeCd}")
ResDto dictDatas(@PathVariable("dictTypeCd") String dictTypeCd);
@GetMapping("/dictData/{dictTypeCd}/{dictCd}")
ResDto<DictDataDto> dictData(@PathVariable("dictTypeCd") String dictTypeCd ,@PathVariable("dictCd") String dictCd);
} }
...@@ -16,6 +16,7 @@ import com.github.pagehelper.PageHelper; ...@@ -16,6 +16,7 @@ import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example; import tk.mybatis.mapper.entity.Example;
...@@ -75,6 +76,7 @@ public class DictTypeServiceImpl implements IDictTypeService{ ...@@ -75,6 +76,7 @@ public class DictTypeServiceImpl implements IDictTypeService{
@Override @Override
@Async
public void saveDict(DictTypeDto dto) { public void saveDict(DictTypeDto dto) {
TDictType dictTypeEntity = new TDictType(); TDictType dictTypeEntity = new TDictType();
BeanUtils.copyProperties(dto,dictTypeEntity); BeanUtils.copyProperties(dto,dictTypeEntity);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version> <version>2.1.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</parent> </parent>
...@@ -27,9 +27,9 @@ ...@@ -27,9 +27,9 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<spring-cloud.version>Edgware.SR2</spring-cloud.version> <spring-cloud.version>Greenwich.SR1</spring-cloud.version>
<mybatis3.version>1.3.2</mybatis3.version> <mybatis3.version>1.3.2</mybatis3.version>
<mapper.version>1.1.1</mapper.version> <mapper.version>1.2.3</mapper.version>
<elasticSearch.version>3.1.5.RELEASE</elasticSearch.version> <elasticSearch.version>3.1.5.RELEASE</elasticSearch.version>
</properties> </properties>
......
...@@ -79,10 +79,10 @@ ...@@ -79,10 +79,10 @@
<artifactId>spring-cloud-starter-sleuth</artifactId> <artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency> </dependency>
<!--<dependency>--> <dependency>
<!--<groupId>org.springframework.cloud</groupId>--> <groupId>org.springframework.cloud</groupId>
<!--<artifactId>spring-cloud-starter-eureka</artifactId>--> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<!--</dependency>--> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId> <artifactId>spring-boot-starter-actuator</artifactId>
......
...@@ -4,9 +4,11 @@ import com.alibaba.fastjson.support.spring.FastJsonpHttpMessageConverter4; ...@@ -4,9 +4,11 @@ import com.alibaba.fastjson.support.spring.FastJsonpHttpMessageConverter4;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
...@@ -14,7 +16,8 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter ...@@ -14,7 +16,8 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
@SpringBootApplication @SpringBootApplication
@ComponentScan(basePackages = "com.freemud, cn.freemud") @ComponentScan(basePackages = "com.freemud, cn.freemud")
@MapperScan(basePackages = "com.freemud.demo.mapper") @MapperScan(basePackages = "com.freemud.demo.mapper")
//@EnableEurekaClient @EnableEurekaClient
@EnableAsync
public class SpringbootDemoApplication extends WebMvcConfigurerAdapter{ public class SpringbootDemoApplication extends WebMvcConfigurerAdapter{
public static void main(String[] args) { public static void main(String[] args) {
......
...@@ -4,8 +4,8 @@ import com.alibaba.druid.pool.DruidDataSource; ...@@ -4,8 +4,8 @@ import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
......
package com.freemud.springbootdemo.config;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.ByteBufOutputStream;
import org.redisson.client.codec.BaseCodec;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.Encoder;
import java.io.IOException;
/**
* Created by chenwenshun on 2019/4/25.
*/
public class FastjsonCodec extends BaseCodec{
private final Encoder encoder = in -> {
ByteBuf out = ByteBufAllocator.DEFAULT.buffer();
try {
ByteBufOutputStream os = new ByteBufOutputStream(out);
JSON.writeJSONString(os, in, SerializerFeature.WriteClassName);
return os.buffer();
} catch (IOException e) {
out.release();
throw e;
} catch (Exception e) {
out.release();
throw new IOException(e);
}
};
private final Decoder<Object> decoder = (buf, state) ->
JSON.parseObject(new ByteBufInputStream(buf), Object.class);
@Override
public Decoder<Object> getValueDecoder() {
return decoder;
}
@Override
public Encoder getValueEncoder() {
return encoder;
}
}
...@@ -2,6 +2,7 @@ package com.freemud.springbootdemo.controller; ...@@ -2,6 +2,7 @@ package com.freemud.springbootdemo.controller;
import com.freemud.demo.cache.DictRedisCache; import com.freemud.demo.cache.DictRedisCache;
import com.freemud.demo.dto.*; import com.freemud.demo.dto.*;
import com.freemud.demo.service.IDictService;
import com.freemud.demo.service.IDictTypeService; import com.freemud.demo.service.IDictTypeService;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -14,8 +15,7 @@ import java.util.List; ...@@ -14,8 +15,7 @@ import java.util.List;
* Created by chenwenshun on 2018/11/2. * Created by chenwenshun on 2018/11/2.
*/ */
@RestController @RestController
@RequestMapping(value = "/dict",produces = "application/json") public class DictController implements IDictService{
public class DictController {
@Autowired @Autowired
IDictTypeService dictTypeService; IDictTypeService dictTypeService;
...@@ -23,8 +23,8 @@ public class DictController { ...@@ -23,8 +23,8 @@ public class DictController {
@Autowired @Autowired
DictRedisCache dictRedisCache; DictRedisCache dictRedisCache;
@Override
@ApiOperation("分页查询列表") @ApiOperation("分页查询列表")
@PostMapping("/page")
public ResDto page(@RequestBody PageReq pageReq){ public ResDto page(@RequestBody PageReq pageReq){
PageData<DictTypeDto> pageData = dictTypeService.findPageDict(pageReq); PageData<DictTypeDto> pageData = dictTypeService.findPageDict(pageReq);
...@@ -32,6 +32,7 @@ public class DictController { ...@@ -32,6 +32,7 @@ public class DictController {
} }
@Override
@GetMapping("/getById") @GetMapping("/getById")
public ResDto getById(@RequestParam("id") Long id){ public ResDto getById(@RequestParam("id") Long id){
DictTypeDto dictTypeDto = dictRedisCache.getCache(id); DictTypeDto dictTypeDto = dictRedisCache.getCache(id);
...@@ -40,9 +41,10 @@ public class DictController { ...@@ -40,9 +41,10 @@ public class DictController {
} }
@Override
@ApiOperation("typeCd获取字典数据") @ApiOperation("typeCd获取字典数据")
@GetMapping( value = "/dictDatas/{dictTypeCd}") @GetMapping( value = "/dictDatas/{dictTypeCd}")
public ResDto dictDatas(@PathVariable String dictTypeCd){ public ResDto dictDatas(@PathVariable("dictTypeCd") String dictTypeCd){
List<DictDataDto> list = this.dictTypeService.loadDatasByTypeCd(dictTypeCd,true); List<DictDataDto> list = this.dictTypeService.loadDatasByTypeCd(dictTypeCd,true);
return new ResDto(list); return new ResDto(list);
...@@ -50,7 +52,7 @@ public class DictController { ...@@ -50,7 +52,7 @@ public class DictController {
@ApiOperation("typeCd & dataCd获取字典数据") @ApiOperation("typeCd & dataCd获取字典数据")
@GetMapping("/dictData/{dictTypeCd}/{dictCd}") @GetMapping("/dictData/{dictTypeCd}/{dictCd}")
public ResDto<DictDataDto> dictData(@PathVariable String dictTypeCd ,@PathVariable String dictCd){ public ResDto<DictDataDto> dictData(@PathVariable("dictTypeCd") String dictTypeCd ,@PathVariable("dictCd") String dictCd){
DictDataDto dictDataDto = this.dictTypeService.loadDictDataByCd(dictTypeCd,dictCd,true); DictDataDto dictDataDto = this.dictTypeService.loadDictDataByCd(dictTypeCd,dictCd,true);
return new ResDto(dictDataDto); return new ResDto(dictDataDto);
} }
......
...@@ -68,10 +68,14 @@ logging: ...@@ -68,10 +68,14 @@ logging:
# ignored: /**,/swagger*,/webjars/**,/v2/**,/swagger-resources/** # ignored: /**,/swagger*,/webjars/**,/v2/**,/swagger-resources/**
swagger_enable: true swagger_enable: true
#eureka: eureka:
# client: client:
# service-url: service-url:
# defaultZone: http://localhost:10001/eureka defaultZone: http://localhost:10001/eureka
healthcheck: enabled
instance:
lease-expiration-duration-in-seconds: 90
lease-renewal-interval-in-seconds: 30
#apollo: #apollo:
# bootstrap: # bootstrap:
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<appender name = "STDOUT_tid" class= "ch.qos.logback.core.ConsoleAppender" > <appender name = "STDOUT_tid" class= "ch.qos.logback.core.ConsoleAppender" >
<layout class = "ch.qos.logback.classic.PatternLayout"> <layout class = "ch.qos.logback.classic.PatternLayout">
<!--<Pattern >%d{HH:mm} %-5level %logger{36} - [springAppName:${springAppName:-}, TxId : %X{X-B3-TraceId:-} , SpanId : %X{X-B3-SpanId:-}] %msg%n</Pattern >--> <!--<Pattern >%d{HH:mm} %-5level %logger{36} - [springAppName:${springAppName:-}, TxId : %X{X-B3-TraceId:-} , SpanId : %X{X-B3-SpanId:-}] %msg%n</Pattern >-->
<Pattern >%d{HH:mm} %-5level %logger{36} - [spring-demo,%X{X-B3-TraceId:-},%X{X-B3-SpanId:-}] %msg%n</Pattern > <Pattern >%d{HH:mm:ss.SSS} %-5level %logger{36} - [spring-demo,%X{X-B3-TraceId:-},%X{X-B3-SpanId:-}] %msg%n</Pattern >
</layout > </layout >
</appender > </appender >
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment