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

升个版本号

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