Commit 8d1cecdd authored by 张永's avatar 张永

升个版本号

parent 5d113dea
Pipeline #162 canceled with stages
package com.egolm.shop.config;
import javax.sql.DataSource;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import com.alibaba.druid.pool.DruidDataSource;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.jdbc.dialect.MySqlDialect;
@Configuration
public class DataSourceConfig {
@Bean
@Primary
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource getDataSource() {
return DataSourceBuilder.create().type(DruidDataSource.class).build();
}
@Bean
@Primary
public PlatformTransactionManager getTransactionManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
@Bean
@Primary
public JdbcTemplate getJdbcTemplate(DataSource dataSource) {
JdbcTemplate jdbcTemplate = new JdbcTemplate();
jdbcTemplate.setDataSource(dataSource);
jdbcTemplate.setDialect(new MySqlDialect());
jdbcTemplate.setSql_level(3);
return jdbcTemplate;
}
package com.egolm.shop.config;
import javax.sql.DataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import com.alibaba.druid.pool.DruidDataSource;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.jdbc.dialect.MySqlDialect;
@Configuration
public class DataSourceConfig {
@Bean
@Primary
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource getDataSource() {
return DataSourceBuilder.create().type(DruidDataSource.class).build();
}
@Bean
@Primary
public PlatformTransactionManager getTransactionManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
@Bean
@Primary
public JdbcTemplate getJdbcTemplate(DataSource dataSource) {
JdbcTemplate jdbcTemplate = new JdbcTemplate();
jdbcTemplate.setDataSource(dataSource);
jdbcTemplate.setDialect(new MySqlDialect());
jdbcTemplate.setSql_level(3);
return jdbcTemplate;
}
}
\ No newline at end of file
package com.egolm.shop.controller;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.Page;
import com.egolm.shop.service.SolrGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import redis.clients.jedis.JedisCommands;
@Api(tags={"搜索引擎商品相关接口"})
@Controller
@RequestMapping("solr/goods")
public class SolrGoodsController {
@Autowired
private SolrGoodsService service;
@Autowired
@Qualifier("redisTemplate")
private RedisTemplate<String, ?> redisTemplate;
@ResponseBody
@PostMapping("query")
@ApiOperation("搜索引擎商品搜索")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", dataType="long", allowMultiple=false, required=true, name="index", value="分页编号"),
@ApiImplicitParam(paramType = "query", dataType="long", allowMultiple=false, required=true, name="limit", value="分页大小"),
@ApiImplicitParam(paramType = "query", dataType="string", allowMultiple=false, required=true, name="queryKey", value="搜索关键字"),
@ApiImplicitParam(paramType = "query", dataType="string", allowMultiple=true, required=true, name="orders", value="排序关键字"),
@ApiImplicitParam(paramType = "query", dataType="string", allowMultiple=true, required=true, name="keywords", value="精确搜索条件"),
@ApiImplicitParam(paramType = "query", dataType="string", allowMultiple=true, required=true, name="facetFields", value="单字段分组字段"),
@ApiImplicitParam(paramType = "query", dataType="string", allowMultiple=true, required=true, name="facetPivotFields", value="多字段分组字段"),
@ApiImplicitParam(paramType = "query", name = "sign", dataType = "String", required = true, value = "签名", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "timestamp", dataType = "String", required = true, value = "时间戳", defaultValue = "")
})
public Object query(Long index, Long limit, String queryKey, String[] orders, String[] keywords, String[] facetFields, String[] facetPivotFields) {
Page page = new Page(index, limit, orders);
return service.query(page, queryKey, keywords, facetFields, facetPivotFields);
}
@ResponseBody
@PostMapping("updateByDistrictID")
@ApiOperation("搜索引擎按区域编号更新商品索引")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", dataType="string", allowMultiple=false, required=true, name="sDistrictID", value="区域编号"),
@ApiImplicitParam(paramType = "query", name = "sign", dataType = "String", required = true, value = "签名", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "timestamp", dataType = "String", required = true, value = "时间戳", defaultValue = "")
})
public Object updateByDistrictID(String sDistrictID) {
service.update(sDistrictID);
return Rjx.jsonOk();
}
@ResponseBody
@PostMapping("update")
@Scheduled(cron="0 0 4 * * ?")
@ApiOperation("搜索引擎更新全部商品索引")
public Object update() {
if(this.getLock().getCode() == 200) {
try {
service.update(null);
return Rjx.jsonOk();
} finally {
this.releaseLock();
}
} else {
return Rjx.jsonErr().setMessage("该任务正在运行,请不要重复执行");
}
}
public static final String SCHEDULE_LOCK_KEY = "SCHEDULE_LOCK_KEY";
public static Long SCHEDULE_LOCK_EXPIRE = 1000L*60*60;
@ResponseBody
@PostMapping("getLock")
@ApiOperation("设置搜索引擎更新索引定时任务分布式互斥锁")
public Rjx getLock() {
String result = redisTemplate.execute(new RedisCallback<String>() {
@Override
public String doInRedis(RedisConnection connection) throws DataAccessException {
JedisCommands commands = (JedisCommands) connection.getNativeConnection();
String uuid = UUID.randomUUID().toString();
return commands.set(SCHEDULE_LOCK_KEY, uuid, "NX", "PX", SCHEDULE_LOCK_EXPIRE);
}
});
if(result != null && result.equals("OK")) {
return Rjx.jsonOk();
} else {
return Rjx.jsonErr();
}
}
@ResponseBody
@PostMapping("releaseLock")
@ApiOperation("删除搜索引擎更新索引定时任务分布式互斥锁")
public Rjx releaseLock() {
redisTemplate.delete(SCHEDULE_LOCK_KEY);
return Rjx.jsonOk();
}
}
package com.egolm.shop.controller;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.Page;
import com.egolm.shop.service.SolrGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
@Api(tags={"搜索引擎商品相关接口"})
@Controller
@RequestMapping("solr/goods")
public class SolrGoodsController {
@Autowired
private SolrGoodsService service;
@Autowired
@Qualifier("redisTemplate")
private RedisTemplate<String, ?> redisTemplate;
@ResponseBody
@PostMapping("query")
@ApiOperation("搜索引擎商品搜索")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", dataType="long", allowMultiple=false, required=true, name="index", value="分页编号"),
@ApiImplicitParam(paramType = "query", dataType="long", allowMultiple=false, required=true, name="limit", value="分页大小"),
@ApiImplicitParam(paramType = "query", dataType="string", allowMultiple=false, required=true, name="queryKey", value="搜索关键字"),
@ApiImplicitParam(paramType = "query", dataType="string", allowMultiple=true, required=true, name="orders", value="排序关键字"),
@ApiImplicitParam(paramType = "query", dataType="string", allowMultiple=true, required=true, name="keywords", value="精确搜索条件"),
@ApiImplicitParam(paramType = "query", dataType="string", allowMultiple=true, required=true, name="facetFields", value="单字段分组字段"),
@ApiImplicitParam(paramType = "query", dataType="string", allowMultiple=true, required=true, name="facetPivotFields", value="多字段分组字段"),
@ApiImplicitParam(paramType = "query", name = "sign", dataType = "String", required = true, value = "签名", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "timestamp", dataType = "String", required = true, value = "时间戳", defaultValue = "")
})
public Object query(Long index, Long limit, String queryKey, String[] orders, String[] keywords, String[] facetFields, String[] facetPivotFields) {
Page page = new Page(index, limit, orders);
return service.query(page, queryKey, keywords, facetFields, facetPivotFields);
}
@ResponseBody
@PostMapping("updateByDistrictID")
@ApiOperation("搜索引擎按区域编号更新商品索引")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", dataType="string", allowMultiple=false, required=true, name="sDistrictID", value="区域编号"),
@ApiImplicitParam(paramType = "query", name = "sign", dataType = "String", required = true, value = "签名", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "timestamp", dataType = "String", required = true, value = "时间戳", defaultValue = "")
})
public Object updateByDistrictID(String sDistrictID) {
service.update(sDistrictID);
return Rjx.jsonOk();
}
@ResponseBody
@PostMapping("update")
@Scheduled(cron="0 0 4 * * ?")
@ApiOperation("搜索引擎更新全部商品索引")
public Object update() {
if(this.getLock().getCode() == 200) {
try {
service.update(null);
return Rjx.jsonOk();
} finally {
this.releaseLock();
}
} else {
return Rjx.jsonErr().setMessage("该任务正在运行,请不要重复执行");
}
}
public static final String SCHEDULE_LOCK_KEY = "SCHEDULE_LOCK_KEY";
public static Long SCHEDULE_LOCK_EXPIRE = 1000L*60*60;
@ResponseBody
@PostMapping("getLock")
@ApiOperation("设置搜索引擎更新索引定时任务分布式互斥锁")
public Rjx getLock() {
/*String result = redisTemplate.execute(new RedisCallback<String>() {
@Override
public String doInRedis(RedisConnection connection) throws DataAccessException {
JedisCommands commands = (JedisCommands) connection.getNativeConnection();
String uuid = UUID.randomUUID().toString();
return commands.set(SCHEDULE_LOCK_KEY, uuid, "NX", "PX", SCHEDULE_LOCK_EXPIRE);
}
});
if(result != null && result.equals("OK")) {
return Rjx.jsonOk();
} else {
return Rjx.jsonErr();
}*/
return Rjx.jsonOk().setMessage("这个注释掉了");
}
@ResponseBody
@PostMapping("releaseLock")
@ApiOperation("删除搜索引擎更新索引定时任务分布式互斥锁")
public Rjx releaseLock() {
redisTemplate.delete(SCHEDULE_LOCK_KEY);
return Rjx.jsonOk();
}
}
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