parent
6078569d23
commit
0e74b39b4d
@ -0,0 +1,45 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<groupId>com.hfkj</groupId> |
||||
<artifactId>hai-oil-parent</artifactId> |
||||
<version>1.0-SNAPSHOT</version> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<groupId>com.hfkj</groupId> |
||||
<artifactId>oil-bweb</artifactId> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>com.hfkj</groupId> |
||||
<artifactId>service</artifactId> |
||||
<version>PACKT-SNAPSHOT</version> |
||||
</dependency> |
||||
</dependencies> |
||||
|
||||
<build> |
||||
<resources> |
||||
<resource> |
||||
<directory>src/main/resources/${env}</directory> |
||||
<filtering>false</filtering> |
||||
</resource> |
||||
</resources> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-surefire-plugin</artifactId> |
||||
<configuration> |
||||
<skip>true</skip> |
||||
</configuration> |
||||
</plugin> |
||||
<plugin> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-maven-plugin</artifactId> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
|
||||
</project> |
@ -0,0 +1,32 @@ |
||||
package com; |
||||
|
||||
import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation; |
||||
import com.alicp.jetcache.anno.config.EnableMethodCache; |
||||
import com.hfkj.common.utils.SpringContextUtil; |
||||
import org.mybatis.spring.annotation.MapperScan; |
||||
import org.springframework.boot.SpringApplication; |
||||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
import org.springframework.boot.web.servlet.ServletComponentScan; |
||||
import org.springframework.context.ApplicationContext; |
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy; |
||||
import org.springframework.scheduling.annotation.EnableScheduling; |
||||
import org.springframework.transaction.annotation.EnableTransactionManagement; |
||||
|
||||
@SpringBootApplication |
||||
// @ComponentScan
|
||||
@EnableTransactionManagement |
||||
@EnableScheduling |
||||
@EnableMethodCache(basePackages = "com.hfkj") |
||||
@EnableCreateCacheAnnotation |
||||
@ServletComponentScan |
||||
@EnableAspectJAutoProxy(proxyTargetClass = true) |
||||
@MapperScan("com.hfkj.dao") |
||||
public class BWebApplication |
||||
{ |
||||
public static void main( String[] args ) |
||||
{ |
||||
ApplicationContext app = SpringApplication.run(BWebApplication.class, args); |
||||
SpringContextUtil.setApplicationContext(app); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,127 @@ |
||||
package com.bweb.config; |
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
import com.fasterxml.jackson.databind.module.SimpleModule; |
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; |
||||
import com.hfkj.common.security.UserCenter; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.http.converter.HttpMessageConverter; |
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; |
||||
import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest; |
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.List; |
||||
|
||||
@Configuration |
||||
public class AuthConfig implements WebMvcConfigurer { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(AuthConfig.class); |
||||
|
||||
@Resource |
||||
private UserCenter userCenter; |
||||
|
||||
/** |
||||
* 获取配置文件debug变量 |
||||
*/ |
||||
@Value("${debug}") |
||||
private boolean debug = false; |
||||
|
||||
/** |
||||
* 解决18位long类型数据转json失去精度问题 |
||||
* @param converters |
||||
*/ |
||||
@Override |
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters){ |
||||
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter(); |
||||
|
||||
ObjectMapper objectMapper = jsonConverter.getObjectMapper(); |
||||
SimpleModule simpleModule = new SimpleModule(); |
||||
simpleModule.addSerializer(Long.class, ToStringSerializer.instance); |
||||
simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); |
||||
objectMapper.registerModule(simpleModule); |
||||
|
||||
converters.add(jsonConverter); |
||||
} |
||||
|
||||
public void addInterceptors(InterceptorRegistry registry) { |
||||
registry.addInterceptor(new HandlerInterceptorAdapter() { |
||||
|
||||
@Override |
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, |
||||
Object handler) throws Exception { |
||||
if(debug){ |
||||
return true; |
||||
} |
||||
String token = request.getHeader("Authorization"); |
||||
if(StringUtils.isNotBlank(token) && userCenter.isLogin(token)){//如果未登录,将无法使用任何接口
|
||||
return true; |
||||
} else if(request instanceof StandardMultipartHttpServletRequest) { |
||||
StandardMultipartHttpServletRequest re = (StandardMultipartHttpServletRequest)request; |
||||
if(userCenter.isLogin(re.getRequest())){ |
||||
return true; |
||||
} else { |
||||
log.error("the user is not logged in,remoteAddr:"+getIpAddress(request)+",requestUrl:"+request.getRequestURL()); |
||||
response.setStatus(401); |
||||
return false; |
||||
} |
||||
} else{ |
||||
log.error("the user is not logged in,remoteAddr:"+getIpAddress(request)+",requestUrl:"+request.getRequestURL()); |
||||
response.setStatus(401); |
||||
return false; |
||||
} |
||||
} |
||||
}) |
||||
.addPathPatterns("/**") |
||||
.excludePathPatterns("/swagger-resources/**") |
||||
.excludePathPatterns("/**/api-docs") |
||||
.excludePathPatterns("/**/springfox-swagger-ui/**") |
||||
.excludePathPatterns("/**/swagger-ui.html") |
||||
.excludePathPatterns("/client/*") |
||||
.excludePathPatterns("/sms/*") |
||||
.excludePathPatterns("/secUser/login") |
||||
.excludePathPatterns("/secUser/loginOut") |
||||
; |
||||
} |
||||
|
||||
public String getIpAddress(HttpServletRequest request) { |
||||
// 获取请求主机IP地址,如果通过代理进来,则透过防火墙获取真实IP地址
|
||||
String ip = request.getHeader("X-Forwarded-For"); |
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { |
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { |
||||
ip = request.getHeader("Proxy-Client-IP"); |
||||
} |
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { |
||||
ip = request.getHeader("WL-Proxy-Client-IP"); |
||||
} |
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { |
||||
ip = request.getHeader("HTTP_CLIENT_IP"); |
||||
} |
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { |
||||
ip = request.getHeader("HTTP_X_FORWARDED_FOR"); |
||||
} |
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { |
||||
ip = request.getRemoteAddr(); |
||||
} |
||||
} else if (ip.length() > 15) { |
||||
String[] ips = ip.split(","); |
||||
for (int index = 0; index < ips.length; index++) { |
||||
String strIp = ips[index]; |
||||
if (!("unknown".equalsIgnoreCase(strIp))) { |
||||
ip = strIp; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
return ip; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,24 @@ |
||||
package com.bweb.config; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
||||
import javax.servlet.ServletContextEvent; |
||||
import javax.servlet.ServletContextListener; |
||||
import javax.servlet.annotation.WebListener; |
||||
|
||||
@WebListener |
||||
public class ConfigListener implements ServletContextListener { |
||||
|
||||
@Autowired |
||||
private SysConfig sysConfig; |
||||
|
||||
@Override |
||||
public void contextInitialized(ServletContextEvent sce) { |
||||
SysConst.setSysConfig(sysConfig); |
||||
} |
||||
|
||||
@Override |
||||
public void contextDestroyed(ServletContextEvent sce) { |
||||
} |
||||
|
||||
} |
@ -0,0 +1,49 @@ |
||||
package com.bweb.config; |
||||
|
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.web.cors.CorsConfiguration; |
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; |
||||
import org.springframework.web.filter.CorsFilter; |
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry; |
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @ClassName CorsConfig |
||||
* @Description: TODO () |
||||
* @Author 胡锐 |
||||
* @Date 2020/12/16 |
||||
**/ |
||||
@Configuration |
||||
public class CorsConfig extends WebMvcConfigurerAdapter { |
||||
@Override |
||||
public void addCorsMappings(CorsRegistry registry) { |
||||
registry.addMapping("/**") |
||||
.allowedOrigins("*") |
||||
.allowCredentials(true) |
||||
.allowedMethods("GET", "POST", "DELETE", "PUT") |
||||
.maxAge(3600); |
||||
} |
||||
private CorsConfiguration buildConfig() { |
||||
CorsConfiguration corsConfiguration = new CorsConfiguration(); |
||||
List<String> list = new ArrayList<>(); |
||||
list.add("*"); |
||||
corsConfiguration.setAllowedOrigins(list); |
||||
/* |
||||
// 请求常用的三种配置,*代表允许所有,当时你也可以自定义属性(比如header只能带什么,只能是post方式等等)
|
||||
*/ |
||||
corsConfiguration.addAllowedOrigin("*"); |
||||
corsConfiguration.addAllowedHeader("*"); |
||||
corsConfiguration.addAllowedMethod("*"); |
||||
return corsConfiguration; |
||||
} |
||||
@Bean |
||||
public CorsFilter corsFilter() { |
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); |
||||
source.registerCorsConfiguration("/**", buildConfig()); |
||||
return new CorsFilter(source); |
||||
} |
||||
} |
@ -0,0 +1,26 @@ |
||||
package com.bweb.config; |
||||
|
||||
import org.springframework.boot.web.servlet.MultipartConfigFactory; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
|
||||
import javax.servlet.MultipartConfigElement; |
||||
|
||||
@Configuration |
||||
public class MultipartConfig { |
||||
|
||||
/** |
||||
* 文件上传配置 |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public MultipartConfigElement multipartConfigElement() { |
||||
MultipartConfigFactory factory = new MultipartConfigFactory(); |
||||
//文件最大
|
||||
factory.setMaxFileSize("300MB"); //KB,MB
|
||||
//设置总上传数据总大小
|
||||
factory.setMaxRequestSize("350MB"); |
||||
return factory.createMultipartConfig(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,109 @@ |
||||
package com.bweb.config; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect; |
||||
import com.fasterxml.jackson.annotation.PropertyAccessor; |
||||
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
import org.springframework.cache.annotation.CachingConfigurerSupport; |
||||
import org.springframework.cache.annotation.EnableCaching; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.data.redis.connection.RedisConnectionFactory; |
||||
import org.springframework.data.redis.core.*; |
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; |
||||
import org.springframework.data.redis.serializer.StringRedisSerializer; |
||||
|
||||
|
||||
@Configuration |
||||
@EnableCaching //开启注解
|
||||
public class RedisConfig extends CachingConfigurerSupport { |
||||
|
||||
/** |
||||
* retemplate相关配置 |
||||
* @param factory |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) { |
||||
|
||||
RedisTemplate<String, Object> template = new RedisTemplate<>(); |
||||
// 配置连接工厂
|
||||
template.setConnectionFactory(factory); |
||||
|
||||
//使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值(默认使用JDK的序列化方式)
|
||||
Jackson2JsonRedisSerializer jacksonSeial = new Jackson2JsonRedisSerializer(Object.class); |
||||
|
||||
ObjectMapper om = new ObjectMapper(); |
||||
// 指定要序列化的域,field,get和set,以及修饰符范围,ANY是都有包括private和public
|
||||
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); |
||||
// 指定序列化输入的类型,类必须是非final修饰的,final修饰的类,比如String,Integer等会跑出异常
|
||||
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); |
||||
jacksonSeial.setObjectMapper(om); |
||||
|
||||
// 值采用json序列化
|
||||
template.setValueSerializer(jacksonSeial); |
||||
//使用StringRedisSerializer来序列化和反序列化redis的key值
|
||||
template.setKeySerializer(new StringRedisSerializer()); |
||||
|
||||
// 设置hash key 和value序列化模式
|
||||
template.setHashKeySerializer(new StringRedisSerializer()); |
||||
template.setHashValueSerializer(jacksonSeial); |
||||
template.afterPropertiesSet(); |
||||
|
||||
return template; |
||||
} |
||||
|
||||
/** |
||||
* 对hash类型的数据操作 |
||||
* |
||||
* @param redisTemplate |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public HashOperations<String, String, Object> hashOperations(RedisTemplate<String, Object> redisTemplate) { |
||||
return redisTemplate.opsForHash(); |
||||
} |
||||
|
||||
/** |
||||
* 对redis字符串类型数据操作 |
||||
* |
||||
* @param redisTemplate |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public ValueOperations<String, Object> valueOperations(RedisTemplate<String, Object> redisTemplate) { |
||||
return redisTemplate.opsForValue(); |
||||
} |
||||
|
||||
/** |
||||
* 对链表类型的数据操作 |
||||
* |
||||
* @param redisTemplate |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public ListOperations<String, Object> listOperations(RedisTemplate<String, Object> redisTemplate) { |
||||
return redisTemplate.opsForList(); |
||||
} |
||||
|
||||
/** |
||||
* 对无序集合类型的数据操作 |
||||
* |
||||
* @param redisTemplate |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public SetOperations<String, Object> setOperations(RedisTemplate<String, Object> redisTemplate) { |
||||
return redisTemplate.opsForSet(); |
||||
} |
||||
|
||||
/** |
||||
* 对有序集合类型的数据操作 |
||||
* |
||||
* @param redisTemplate |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) { |
||||
return redisTemplate.opsForZSet(); |
||||
} |
||||
} |
@ -0,0 +1,47 @@ |
||||
package com.bweb.config; |
||||
|
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import springfox.documentation.builders.ApiInfoBuilder; |
||||
import springfox.documentation.builders.RequestHandlerSelectors; |
||||
import springfox.documentation.service.ApiInfo; |
||||
import springfox.documentation.service.Contact; |
||||
import springfox.documentation.spi.DocumentationType; |
||||
import springfox.documentation.spring.web.plugins.Docket; |
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2; |
||||
|
||||
/** |
||||
* SwaggerConfig.java |
||||
* 项目名称: |
||||
* 包: |
||||
* 类名称: SwaggerConfig.java |
||||
* 类描述: 构建restful api接口文档 |
||||
* 创建人: |
||||
* 创建时间: 2017 下午4:23:45 |
||||
*/ |
||||
@Configuration |
||||
@EnableSwagger2 |
||||
public class SwaggerConfig |
||||
{ |
||||
|
||||
/** |
||||
* 描述api的基本信息 |
||||
* 基本信息会展现在文档页面中 |
||||
* @return [api的基本信息] |
||||
*/ |
||||
ApiInfo apiInfo() |
||||
{ |
||||
return new ApiInfoBuilder().title("hgj-BWeb").description("提供给管理平台的接口").termsOfServiceUrl("").version("1.0.0") |
||||
.contact(new Contact("", "", "")).build(); |
||||
} |
||||
|
||||
@Bean |
||||
public Docket customImplementation() |
||||
{ |
||||
return new Docket(DocumentationType.SWAGGER_2).select() |
||||
.apis(RequestHandlerSelectors.basePackage("com")) |
||||
.build().directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class) |
||||
.directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class).apiInfo(apiInfo()); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,31 @@ |
||||
package com.bweb.config; |
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties; |
||||
import org.springframework.context.annotation.PropertySource; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
@Component("sysConfig") |
||||
@ConfigurationProperties |
||||
@PropertySource("classpath:/config.properties") |
||||
public class SysConfig { |
||||
|
||||
private String fileUrl; |
||||
|
||||
private String cmsPath; |
||||
|
||||
public String getFileUrl() { |
||||
return fileUrl; |
||||
} |
||||
|
||||
public void setFileUrl(String fileUrl) { |
||||
this.fileUrl = fileUrl; |
||||
} |
||||
|
||||
public String getCmsPath() { |
||||
return cmsPath; |
||||
} |
||||
|
||||
public void setCmsPath(String cmsPath) { |
||||
this.cmsPath = cmsPath; |
||||
} |
||||
} |
@ -0,0 +1,19 @@ |
||||
package com.bweb.config; |
||||
|
||||
public class SysConst { |
||||
|
||||
private static SysConfig sysConfig; |
||||
|
||||
public static void setSysConfig(SysConfig arg){ |
||||
sysConfig = arg; |
||||
} |
||||
|
||||
public static SysConfig getSysConfig(){ |
||||
if (null == sysConfig) { |
||||
//防止空指针异常
|
||||
sysConfig = new SysConfig(); |
||||
return sysConfig; |
||||
} |
||||
return sysConfig; |
||||
} |
||||
} |
@ -0,0 +1,67 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.aliyuncs.CommonRequest; |
||||
import com.aliyuncs.CommonResponse; |
||||
import com.aliyuncs.DefaultAcsClient; |
||||
import com.aliyuncs.IAcsClient; |
||||
import com.aliyuncs.http.MethodType; |
||||
import com.aliyuncs.profile.DefaultProfile; |
||||
import com.hfkj.common.security.VerifyCode; |
||||
import com.hfkj.common.security.VerifyCodeStorage; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.model.ResponseData; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.util.Random; |
||||
|
||||
@RestController |
||||
@RequestMapping(value="/sms") |
||||
@Api(value="阿里云短信") |
||||
public class AliyuncsSmsController { |
||||
|
||||
Logger log = LoggerFactory.getLogger(AliyuncsSmsController.class); |
||||
|
||||
@RequestMapping(value="/sendVerificationCode",method= RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "发送验证码") |
||||
public ResponseData sendVerificationCode(@RequestParam(value = "phone", required = true) String phone) { |
||||
try { |
||||
|
||||
VerifyCode verifyCode = VerifyCodeStorage.getDate(phone); |
||||
String code; |
||||
if (verifyCode != null){ |
||||
code = verifyCode.getObject(); |
||||
}else{ |
||||
// 生成随机6位验证码
|
||||
code = String.valueOf(new Random().nextInt(899999) + 100000); |
||||
} |
||||
DefaultProfile profile = DefaultProfile.getProfile("default", "LTAI4FzFiDCZsspxJfQYoHxC", "tkS64fUpgK0Lr2R8ps0AVYRWZloFLl"); |
||||
IAcsClient client = new DefaultAcsClient(profile); |
||||
|
||||
CommonRequest request = new CommonRequest(); |
||||
//request.setProtocol(ProtocolType.HTTPS);
|
||||
request.setMethod(MethodType.POST); |
||||
request.setDomain("dysmsapi.aliyuncs.com"); |
||||
request.setVersion("2017-05-25"); |
||||
request.setAction("SendSms"); |
||||
request.putQueryParameter("PhoneNumbers", phone); |
||||
request.putQueryParameter("SignName", "银企服"); |
||||
request.putQueryParameter("TemplateCode", "SMS_210765573"); |
||||
request.putQueryParameter("TemplateParam", "{\"code\":\""+code+"\"}"); |
||||
|
||||
//发送短信
|
||||
CommonResponse response = client.getCommonResponse(request); |
||||
// 存入VerifyCodeStorage
|
||||
verifyCode = new VerifyCode(phone,code); |
||||
VerifyCodeStorage.save(verifyCode); |
||||
return ResponseMsgUtil.success(response.getData()); |
||||
|
||||
} catch (Exception e) { |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,174 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.security.UserCenter; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.BsAgent; |
||||
import com.hfkj.entity.SecUser; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.model.UserInfoModel; |
||||
import com.hfkj.service.BsAgentService; |
||||
import com.hfkj.service.SecUserService; |
||||
import com.hfkj.sysenum.SecUserObjectTypeEnum; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.Objects; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/agent") |
||||
@Api(value = "代理商管理") |
||||
public class BsAgentController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(BsAgentController.class); |
||||
|
||||
@Resource |
||||
private BsAgentService agentService; |
||||
@Resource |
||||
private SecUserService secUserService; |
||||
@Resource |
||||
private UserCenter userCenter; |
||||
|
||||
@RequestMapping(value = "/createAgent", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "创建代理商") |
||||
public ResponseData createAgent(@RequestBody JSONObject body) { |
||||
try { |
||||
|
||||
UserInfoModel userInfoModel = userCenter.getSessionModel(UserInfoModel.class); |
||||
if (userInfoModel == null || !userInfoModel.getSecUser().getObjectType().equals(SecUserObjectTypeEnum.type2.getNumber())) { |
||||
log.error("BsAgentController --> createAgent() error!", "用户身份错误或已过期"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.SEC_USER_EXPIRED, ""); |
||||
} |
||||
|
||||
if (body == null |
||||
|| StringUtils.isBlank(body.getString("loginName")) |
||||
|| StringUtils.isBlank(body.getString("name")) |
||||
|| StringUtils.isBlank(body.getString("contactsName")) |
||||
|| StringUtils.isBlank(body.getString("contactsTelephone")) |
||||
) { |
||||
log.error("BsAgentController --> createAgent() error!", "参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
BsAgent agent = new BsAgent(); |
||||
agent.setCompanyId(userInfoModel.getBsCompany().getId()); |
||||
agent.setCompanyName(userInfoModel.getBsCompany().getName()); |
||||
agent.setName(body.getString("name")); |
||||
agent.setContactsName(body.getString("contactsName")); |
||||
agent.setContactsTelephone(body.getString("contactsTelephone")); |
||||
|
||||
agentService.createAgent(body.getString("loginName"), agent); |
||||
return ResponseMsgUtil.success("创建成功"); |
||||
} catch (Exception e) { |
||||
log.error("BsAgentController --> createAgent() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/updateAgent", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "修改代理商") |
||||
public ResponseData updateAgent(@RequestBody JSONObject body) { |
||||
try { |
||||
|
||||
UserInfoModel userInfoModel = userCenter.getSessionModel(UserInfoModel.class); |
||||
if (userInfoModel == null || !userInfoModel.getSecUser().getObjectType().equals(SecUserObjectTypeEnum.type2.getNumber())) { |
||||
log.error("BsAgentController --> updateAgent() error!", "用户身份错误或已过期"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.SEC_USER_EXPIRED, ""); |
||||
} |
||||
|
||||
if (body == null |
||||
|| StringUtils.isBlank(body.getString("agentNo")) |
||||
|| StringUtils.isBlank(body.getString("name")) |
||||
|| StringUtils.isBlank(body.getString("contactsName")) |
||||
|| StringUtils.isBlank(body.getString("contactsTelephone")) |
||||
) { |
||||
log.error("BsAgentController --> updateAgent() error!", "参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
// 查询代理商
|
||||
BsAgent agent = agentService.getAgentByAgentNo(body.getString("agentNo")); |
||||
if (agent == null) { |
||||
log.error("BsAgentController --> updateAgent() error!", "参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的代理商"); |
||||
} |
||||
agent.setName(body.getString("name")); |
||||
agent.setContactsName(body.getString("contactsName")); |
||||
agent.setContactsTelephone(body.getString("contactsTelephone")); |
||||
agentService.updateAgent(agent); |
||||
|
||||
return ResponseMsgUtil.success("修改成功"); |
||||
} catch (Exception e) { |
||||
log.error("BsAgentController --> updateAgent() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
|
||||
@RequestMapping(value = "/queryAgentDetail", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询代理商详情") |
||||
public ResponseData queryAgentDetail(@RequestParam(name = "agentNo", required = true) String agentNo) { |
||||
try { |
||||
// 查询代理商
|
||||
BsAgent agent = agentService.getAgentByAgentNo(agentNo); |
||||
if (agent == null) { |
||||
log.error("BsAgentController --> queryAgentDetail() error!", "未找到代理商"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到代理商"); |
||||
} |
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("agent", agent); |
||||
|
||||
SecUser secUser = secUserService.getMainAccount(SecUserObjectTypeEnum.type3.getNumber(), agent.getId()); |
||||
if (secUser == null) { |
||||
log.error("BsAgentController --> queryAgentDetail() error!", "未找到代理商登录账户"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到代理商登录账户"); |
||||
} |
||||
secUser.setPassword(null); |
||||
param.put("account", secUser); |
||||
|
||||
return ResponseMsgUtil.success(param); |
||||
} catch (Exception e) { |
||||
log.error("BsAgentController --> queryAgentDetail() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/queryAgentList", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询代理商列表") |
||||
public ResponseData queryAgentList(@RequestParam(name = "companyId", required = false) Long companyId, |
||||
@RequestParam(name = "agentNo", required = false) String agentNo, |
||||
@RequestParam(name = "agentName", required = false) String agentName, |
||||
@RequestParam(name = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(name = "pageSize", required = true) Integer pageSize) { |
||||
try { |
||||
Map<String, Object> param = new HashMap<>(); |
||||
param.put("companyId", companyId); |
||||
param.put("agentNo", agentNo); |
||||
param.put("agentName", agentName); |
||||
|
||||
PageHelper.startPage(pageNum,pageSize); |
||||
return ResponseMsgUtil.success(new PageInfo<>(agentService.getAgentList(param))); |
||||
} catch (Exception e) { |
||||
log.error("BsAgentController --> queryAgentList() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,237 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.security.UserCenter; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.config.SpPrinterConfig; |
||||
import com.hfkj.entity.*; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.model.UserInfoModel; |
||||
import com.hfkj.service.BsCompanyService; |
||||
import com.hfkj.service.BsDeviceService; |
||||
import com.hfkj.service.BsMerchantService; |
||||
import com.hfkj.sysenum.DeviceTypeEnum; |
||||
import com.hfkj.sysenum.SecUserObjectTypeEnum; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/device") |
||||
@Api(value = "设备管理") |
||||
public class BsDeviceController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(BsDeviceController.class); |
||||
|
||||
@Resource |
||||
private UserCenter userCenter; |
||||
@Resource |
||||
private BsDeviceService deviceService; |
||||
@Resource |
||||
private BsMerchantService merchantService; |
||||
@Resource |
||||
private BsCompanyService companyService; |
||||
|
||||
@RequestMapping(value="/editDevice",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "编辑设备") |
||||
public ResponseData editDevice(@RequestBody BsDevice body) { |
||||
try { |
||||
|
||||
if (StringUtils.isBlank(body.getMerNo()) || body.getType() == null) { |
||||
log.error("BsDeviceController -> editDevice() error!","参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
if (DeviceTypeEnum.getNameByType(body.getType()) == null) { |
||||
log.error("BsDeviceController -> editDevice() error!","参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的设备类型"); |
||||
} |
||||
|
||||
if (body.getType().equals(DeviceTypeEnum.type1.getType()) |
||||
&& (StringUtils.isBlank(body.getDeviceSn()) || StringUtils.isBlank(body.getDeviceKey()))) { |
||||
log.error("BsDeviceController -> editDevice() error!","参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
|
||||
} |
||||
|
||||
BsDevice device; |
||||
if (body.getId() != null) { |
||||
// 查询设备
|
||||
device = deviceService.getDetailById(body.getId()); |
||||
if (device == null) { |
||||
log.error("HighDeviceController -> editDevice() error!","参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
} else { |
||||
device = new BsDevice(); |
||||
} |
||||
|
||||
// 查询商户
|
||||
BsMerchant merchant = merchantService.getMerchant(body.getMerNo()); |
||||
if (merchant == null) { |
||||
log.error("HighDeviceController -> editDevice() error!","参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的商户"); |
||||
} |
||||
|
||||
// 查询分公司
|
||||
BsCompany company = companyService.getCompanyById(merchant.getCompanyId()); |
||||
if (company == null) { |
||||
log.error("HighDeviceController -> editDevice() error!","参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的分公司"); |
||||
} |
||||
|
||||
if (body.getId() == null) { |
||||
if (body.getType().equals(DeviceTypeEnum.type1.getType())) { |
||||
SpPrinterConfig sp = new SpPrinterConfig(); |
||||
JSONObject jsonObject = JSONObject.parseObject(sp.addPrinter(body.getDeviceSn(), body.getDeviceKey(), merchant.getMerName())); |
||||
if (!jsonObject.getInteger("errorcode").equals(0)) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("errormsg")); |
||||
} |
||||
} |
||||
} |
||||
|
||||
device.setCompanyId(company.getId()); |
||||
device.setCompanyName(company.getName()); |
||||
device.setAgentId(merchant.getAgentId()); |
||||
device.setAgentName(merchant.getAgentName()); |
||||
device.setMerId(merchant.getId()); |
||||
device.setMerNo(merchant.getMerNo()); |
||||
device.setMerName(merchant.getMerName()); |
||||
device.setType(body.getType()); |
||||
device.setDeviceName(merchant.getMerName()); |
||||
device.setDeviceSn(body.getDeviceSn()); |
||||
device.setDeviceKey(body.getDeviceKey()); |
||||
device.setDeviceImei(body.getDeviceImei()); |
||||
device.setDeviceIccid(body.getDeviceIccid()); |
||||
device.setReceiptTop(body.getReceiptTop()); |
||||
device.setReceiptSource(body.getReceiptSource()); |
||||
device.setReceiptBottom(body.getReceiptBottom()); |
||||
deviceService.editDevice(device); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighDeviceController -> editDevice() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/delDevice",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "删除设备") |
||||
public ResponseData delDevice(@RequestBody JSONObject body) { |
||||
try { |
||||
|
||||
if (body.getLong("deviceId") == null) { |
||||
log.error("BsDeviceController -> delDevice() error!","参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
// 查询设备
|
||||
BsDevice device = deviceService.getDetailById(body.getLong("deviceId")); |
||||
if (device == null) { |
||||
log.error("HighDeviceCBsDeviceControllerontroller -> delDevice() error!","参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
if (device.getType().equals(DeviceTypeEnum.type1.getType())) { |
||||
SpPrinterConfig sp = new SpPrinterConfig(); |
||||
JSONObject jsonObject = JSONObject.parseObject(sp.deletePrinter(device.getDeviceSn())); |
||||
if (!jsonObject.getInteger("errorcode").equals(0)) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("errormsg")); |
||||
} |
||||
} |
||||
|
||||
device.setStatus(0); |
||||
deviceService.editDevice(device); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsDeviceController -> delDevice() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/getDetailById",method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "根据id查询设备详情") |
||||
public ResponseData getDetailById(@RequestParam(name = "deviceId", required = true) Long deviceId) { |
||||
try { |
||||
|
||||
return ResponseMsgUtil.success(deviceService.getDetailById(deviceId)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighDeviceController -> getDetailById() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/getDeviceList",method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询设备列表") |
||||
public ResponseData getDeviceList(@RequestParam(name = "companyId", required = false) Long companyId, |
||||
@RequestParam(name = "merNo", required = false) String merNo, |
||||
@RequestParam(name = "merName", required = false) String merName, |
||||
@RequestParam(name = "deviceName", required = false) String deviceName, |
||||
@RequestParam(name = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(name = "pageSize", required = true) Integer pageSize) { |
||||
try { |
||||
|
||||
UserInfoModel sessionModel = userCenter.getSessionModel(UserInfoModel.class); |
||||
if (sessionModel == null) { |
||||
log.error("HighDeviceController -> getDeviceList() error!",""); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到"); |
||||
} |
||||
|
||||
Map<String, Object> param = new HashMap<>(); |
||||
param.put("deviceName", deviceName); |
||||
|
||||
if (sessionModel.getSecUser().getObjectType().equals(SecUserObjectTypeEnum.type0.getNumber()) |
||||
|| sessionModel.getSecUser().getObjectType().equals(SecUserObjectTypeEnum.type1.getNumber())) { |
||||
param.put("companyId", companyId); |
||||
param.put("merNo", merNo); |
||||
param.put("merName", merName); |
||||
|
||||
} else if (sessionModel.getSecUser().getObjectType().equals(SecUserObjectTypeEnum.type2.getNumber())) { |
||||
param.put("companyId", sessionModel.getBsCompany().getId()); |
||||
param.put("merNo", merNo); |
||||
param.put("merName", merName); |
||||
|
||||
} else if (sessionModel.getSecUser().getObjectType().equals(SecUserObjectTypeEnum.type3.getNumber())) { |
||||
param.put("agentId", sessionModel.getAgent().getId()); |
||||
param.put("merNo", merNo); |
||||
param.put("merName", merName); |
||||
|
||||
}else if (sessionModel.getSecUser().getObjectType().equals(SecUserObjectTypeEnum.type4.getNumber())) { |
||||
param.put("merNo", sessionModel.getMerchant().getMerNo()); |
||||
|
||||
} else { |
||||
log.error("HighDeviceController -> getDeviceList() error!",""); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMPETENCE_INSUFFICIENT, ""); |
||||
} |
||||
|
||||
PageHelper.startPage(pageNum, pageSize); |
||||
return ResponseMsgUtil.success(new PageInfo<>(deviceService.getDeviceList(param))); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighDeviceController -> getDeviceList() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,253 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.security.UserCenter; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.config.SpPrinterConfig; |
||||
import com.hfkj.entity.BsCompany; |
||||
import com.hfkj.entity.BsDevice; |
||||
import com.hfkj.entity.BsDiscount; |
||||
import com.hfkj.entity.BsMerchant; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.model.UserInfoModel; |
||||
import com.hfkj.service.BsCompanyService; |
||||
import com.hfkj.service.BsDeviceService; |
||||
import com.hfkj.service.BsDiscountService; |
||||
import com.hfkj.service.BsMerchantService; |
||||
import com.hfkj.sysenum.*; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.Date; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/discount") |
||||
@Api(value = "优惠券管理") |
||||
public class BsDiscountController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(BsDiscountController.class); |
||||
@Resource |
||||
private BsDiscountService discountService; |
||||
@Resource |
||||
private BsMerchantService merchantService; |
||||
|
||||
@RequestMapping(value="/editDiscount",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "编辑优惠券") |
||||
public ResponseData editDiscount(@RequestBody BsDiscount body) { |
||||
try { |
||||
|
||||
if (StringUtils.isBlank(body.getMerNo()) |
||||
|| StringUtils.isBlank(body.getDiscountName()) |
||||
|| body.getDiscountType() == null |
||||
|| body.getDiscountPrice() == null |
||||
|| StringUtils.isBlank(body.getUseScope()) |
||||
|| body.getStartTime() == null |
||||
|| body.getEndTime() == null |
||||
) { |
||||
log.error("BsDiscountController -> editDiscount() error!","参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
if (DiscountTypeEnum.getNameByType(body.getDiscountType()) == null) { |
||||
log.error("BsDiscountController -> editDiscount() error!","未知优惠券类型"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知优惠券类型"); |
||||
} |
||||
// 满减条件
|
||||
if (DiscountTypeEnum.type1.getCode().equals(body.getDiscountType()) && body.getDiscountCondition() == null) { |
||||
log.error("BsDiscountController -> editDiscount() error!","未设置满减条件"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未设置满减条件"); |
||||
} |
||||
if (DiscountUseScopeEnum.type1.getCode().equals(body.getDiscountType()) && body.getDiscountCondition() == null) { |
||||
log.error("BsDiscountController -> editDiscount() error!","未设置满减条件"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未设置满减条件"); |
||||
} |
||||
BsDiscount discount; |
||||
if (StringUtils.isNotBlank(body.getDiscountNo())) { |
||||
// 查询优惠券
|
||||
discount = discountService.getDetail(body.getDiscountNo()); |
||||
if (discount == null) { |
||||
log.error("BsDiscountController -> editDiscount() error!","参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
} else { |
||||
discount = new BsDiscount(); |
||||
} |
||||
|
||||
// 查询商户
|
||||
BsMerchant merchant = merchantService.getMerchant(body.getMerNo()); |
||||
if (merchant == null) { |
||||
log.error("BsDiscountController -> editDiscount() error!","参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的商户"); |
||||
} |
||||
|
||||
discount.setMerId(merchant.getId()); |
||||
discount.setMerNo(merchant.getMerNo()); |
||||
discount.setMerName(merchant.getMerName()); |
||||
discount.setDiscountType(body.getDiscountType()); |
||||
discount.setDiscountName(body.getDiscountName()); |
||||
discount.setDiscountCondition(body.getDiscountCondition()); |
||||
discount.setDiscountPrice(body.getDiscountPrice()); |
||||
discount.setUseScope(body.getUseScope()); |
||||
discount.setStartTime(body.getStartTime()); |
||||
discount.setEndTime(body.getEndTime()); |
||||
discount.setStatus(DiscountStatusEnum.status1.getCode()); |
||||
discountService.editDiscount(discount); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsDiscountController -> editDiscount() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/updateEndTime",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "修改结束时间") |
||||
public ResponseData updateEndTime(@RequestBody JSONObject body) { |
||||
try { |
||||
|
||||
if (body == null |
||||
|| StringUtils.isBlank(body.getString("discountNo")) |
||||
|| body.getLong("endTime") == null) { |
||||
log.error("BsDiscountController -> updateEndTime() error!","参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
// 查询详情
|
||||
BsDiscount discount = discountService.getDetail(body.getString("discountNo")); |
||||
if (discount == null) { |
||||
log.error("BsDiscountController -> updateEndTime() error!","参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的优惠券"); |
||||
} |
||||
if (!discount.getStatus().equals(DiscountStatusEnum.status2.getCode())) { |
||||
log.error("BsDiscountController -> updateEndTime() error!","无法修改,优惠不处于上线状态"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法修改,优惠不处于上线状态"); |
||||
} |
||||
discount.setEndTime(new Date(body.getLong("endTime"))); |
||||
discountService.editDiscount(discount); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsDiscountController -> updateEndTime() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/online",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "上线优惠券") |
||||
public ResponseData online(@RequestBody JSONObject body) { |
||||
try { |
||||
|
||||
if (body == null || StringUtils.isBlank(body.getString("discountNo"))) { |
||||
log.error("BsDiscountController -> online() error!","参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
discountService.online(body.getString("discountNo")); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsDiscountController -> online() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/done",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "结束优惠券") |
||||
public ResponseData done(@RequestBody JSONObject body) { |
||||
try { |
||||
|
||||
if (body == null || StringUtils.isBlank(body.getString("discountNo"))) { |
||||
log.error("BsDiscountController -> done() error!","参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
discountService.done(body.getString("discountNo")); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsDiscountController -> done() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/delete",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "删除优惠券") |
||||
public ResponseData delete(@RequestBody JSONObject body) { |
||||
try { |
||||
|
||||
if (body == null || StringUtils.isBlank(body.getString("discountNo"))) { |
||||
log.error("BsDiscountController -> delDiscount() error!","参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
discountService.delete(body.getString("discountNo")); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsDiscountController -> delDiscount() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/queryDetail",method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询详情") |
||||
public ResponseData queryDetail(@RequestParam(name = "discountNo", required = true) String discountNo) { |
||||
try { |
||||
|
||||
return ResponseMsgUtil.success(discountService.getDetail(discountNo)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsDiscountController -> delDiscount() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/queryList",method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询列表") |
||||
public ResponseData queryList(@RequestParam(name = "merNo", required = false) String merNo, |
||||
@RequestParam(name = "discountName", required = false) String discountName, |
||||
@RequestParam(name = "discountType", required = false) Integer discountType, |
||||
@RequestParam(name = "status", required = false) Integer status, |
||||
@RequestParam(name = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(name = "pageSize", required = true) Integer pageSize) { |
||||
try { |
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("merNo", merNo); |
||||
param.put("discountName", discountName); |
||||
param.put("discountType", discountType); |
||||
param.put("status", status); |
||||
|
||||
PageHelper.startPage(pageNum,pageSize); |
||||
return ResponseMsgUtil.success(new PageInfo<>(discountService.getList(param))); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsDiscountController -> queryList() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,130 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.BsDiscount; |
||||
import com.hfkj.entity.BsDiscountStockCode; |
||||
import com.hfkj.entity.BsMerchant; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.service.BsDiscountService; |
||||
import com.hfkj.service.BsDiscountStockBatchService; |
||||
import com.hfkj.service.BsDiscountStockCodeService; |
||||
import com.hfkj.service.BsMerchantService; |
||||
import com.hfkj.sysenum.DiscountStatusEnum; |
||||
import com.hfkj.sysenum.DiscountTypeEnum; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import io.swagger.models.auth.In; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/discountStock") |
||||
@Api(value = "优惠券库存管理") |
||||
public class BsDiscountStockController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(BsDiscountStockController.class); |
||||
@Resource |
||||
private BsDiscountStockBatchService discountStockBatchService; |
||||
|
||||
@Resource |
||||
private BsDiscountStockCodeService discountStockCodeService; |
||||
|
||||
@RequestMapping(value="/addStock",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "增加优惠券库存") |
||||
public ResponseData addStock(@RequestBody JSONObject body) { |
||||
try { |
||||
|
||||
if (body == null |
||||
|| StringUtils.isBlank(body.getString("discountNo")) |
||||
|| body.getInteger("stockCount") == null) { |
||||
log.error("BsDiscountController -> editDiscount() error!","参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
discountStockBatchService.addStock(body.getString("discountNo"), body.getInteger("stockCount")); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsDiscountStockController -> addStock() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/queryStockBatchList",method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询库存批次") |
||||
public ResponseData queryStockBatchList(@RequestParam(name = "discountNo", required = false) String discountNo, |
||||
@RequestParam(name = "discountName", required = false) String discountName, |
||||
@RequestParam(name = "batchNo", required = false) String batchNo, |
||||
@RequestParam(name = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(name = "pageSize", required = true) Integer pageSize) { |
||||
try { |
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("discountNo", discountNo); |
||||
param.put("discountName", discountName); |
||||
param.put("batchNo", batchNo); |
||||
|
||||
PageHelper.startPage(pageNum,pageSize); |
||||
return ResponseMsgUtil.success(new PageInfo<>(discountStockBatchService.getStockBatchList(param))); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsDiscountStockController -> queryStockBatchList() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/queryStockBatchDetail",method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询库存批次详情") |
||||
public ResponseData queryStockBatchDetail(@RequestParam(name = "batchNo", required = true) String batchNo) { |
||||
try { |
||||
|
||||
return ResponseMsgUtil.success(discountStockBatchService.getStockBatchDetail(batchNo)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsDiscountStockController -> queryStockBatchDetail() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
@RequestMapping(value="/queryStockBatchCodeList",method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询库存批次优惠券code") |
||||
public ResponseData queryStockBatchCodeList(@RequestParam(name = "codeId", required = false) String codeId, |
||||
@RequestParam(name = "discountNo", required = false) String discountNo, |
||||
@RequestParam(name = "batchNo", required = false) String batchNo, |
||||
@RequestParam(name = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(name = "pageSize", required = true) Integer pageSize) { |
||||
try { |
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("codeId", codeId); |
||||
param.put("discountNo", discountNo); |
||||
param.put("batchNo", batchNo); |
||||
|
||||
PageHelper.startPage(pageNum,pageSize); |
||||
return ResponseMsgUtil.success(new PageInfo<>(discountStockCodeService.getCodeList(param))); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsDiscountStockController -> queryStockBatchCodeList() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,167 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.security.UserCenter; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.BsGasOilGunNo; |
||||
import com.hfkj.entity.BsGasOilPrice; |
||||
import com.hfkj.entity.BsMerchant; |
||||
import com.hfkj.entity.SecDictionary; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.model.UserInfoModel; |
||||
import com.hfkj.service.BsGasOilGunNoService; |
||||
import com.hfkj.service.BsGasOilPriceService; |
||||
import com.hfkj.service.BsMerchantService; |
||||
import com.hfkj.service.CommonService; |
||||
import com.hfkj.sysenum.GasOilPriceStatusEnum; |
||||
import com.hfkj.sysenum.SecUserObjectTypeEnum; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.math.BigDecimal; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.stream.Collectors; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/gasOilGunNo") |
||||
@Api(value = "加油站价格") |
||||
public class BsGasOilGunNoController { |
||||
private static Logger log = LoggerFactory.getLogger(BsGasOilGunNoController.class); |
||||
|
||||
@Resource |
||||
private BsGasOilPriceService gasOilPriceService; |
||||
@Resource |
||||
private BsGasOilGunNoService gasOilGunNoService; |
||||
@Resource |
||||
private BsMerchantService merchantService; |
||||
@Resource |
||||
private UserCenter userCenter; |
||||
|
||||
@RequestMapping(value = "/createOilGunNo", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "创建油品枪号") |
||||
public ResponseData createOilGunNo(@RequestBody BsGasOilGunNo body) { |
||||
try { |
||||
UserInfoModel userInfoModel = userCenter.getSessionModel(UserInfoModel.class); |
||||
if (userInfoModel == null || !userInfoModel.getSecUser().getObjectType().equals(SecUserObjectTypeEnum.type4.getNumber())) { |
||||
log.error("BsGasOilGunNoController --> createOilGunNo() error!", "用户身份错误或已过期"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.SEC_USER_EXPIRED, ""); |
||||
} |
||||
if (body == null |
||||
|| body.getMerNo() == null |
||||
|| StringUtils.isBlank(body.getOilNo()) |
||||
|| StringUtils.isBlank(body.getGunNo())){ |
||||
log.error("BsGasOilGunNoController --> createOilGunNo() error!", "参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
// 查询商户
|
||||
BsMerchant merchant = merchantService.getMerchant(body.getMerNo()); |
||||
if (merchant == null) { |
||||
log.error("BsGasOilGunNoController --> createOilGunNo() error!", "未知的商户"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的商户"); |
||||
} |
||||
if (!merchant.getId().equals(userInfoModel.getMerchant().getId())) { |
||||
log.error("BsGasOilGunNoController --> createOilGunNo() error!", "权限不足"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMPETENCE_INSUFFICIENT, ""); |
||||
} |
||||
// 油品
|
||||
BsGasOilPrice oilPrice = gasOilPriceService.getGasOilPrice(merchant.getId(), body.getOilNo()); |
||||
if (oilPrice == null) { |
||||
log.error("BsGasOilGunNoController --> createOilGunNo() error!", "商户未添加" + body.getOilNo() + "油品"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "商户未添加" + body.getOilNo() + "油品"); |
||||
} |
||||
if (gasOilGunNoService.getDetail(body.getMerNo(), body.getOilNo(), body.getGunNo()) != null) { |
||||
log.error("BsGasOilGunNoController --> createOilGunNo() error!", "油品枪号已存在"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "油品枪号已存在"); |
||||
} |
||||
|
||||
BsGasOilGunNo oilGunNo = new BsGasOilGunNo(); |
||||
oilGunNo.setGasOilPriceId(oilPrice.getId()); |
||||
oilGunNo.setMerId(oilPrice.getMerId()); |
||||
oilGunNo.setMerNo(oilPrice.getMerNo()); |
||||
oilGunNo.setOilType(oilPrice.getOilType()); |
||||
oilGunNo.setOilTypeName(oilPrice.getOilTypeName()); |
||||
oilGunNo.setOilNo(oilPrice.getOilNo()); |
||||
oilGunNo.setOilNoName(oilPrice.getOilNoName()); |
||||
oilGunNo.setGunNo(body.getGunNo()); |
||||
oilGunNo.setStatus(1); |
||||
gasOilGunNoService.editData(oilGunNo); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsGasOilGunNoController --> createOilGunNo() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/delete", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "删除抢号") |
||||
public ResponseData delete(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body == null || body.getLong("gunNoId") == null) { |
||||
log.error("BsGasOilGunNoController --> delete() error!", "请求参数校验失败"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
gasOilGunNoService.delete(body.getLong("gunNoId")); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsGasOilGunNoController --> delete() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/queryOilDetail", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询油品详情") |
||||
public ResponseData queryOilDetail(@RequestParam(value = "gunNoId", required = true) Long gunNoId) { |
||||
try { |
||||
|
||||
return ResponseMsgUtil.success(gasOilGunNoService.getDetail(gunNoId)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsGasOilGunNoController --> queryOilDetail() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/queryGunNoList", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询油品列表") |
||||
public ResponseData queryGunNoList(@RequestParam(value = "merNo", required = true) String merNo, |
||||
@RequestParam(value = "oilNo", required = false) String oilNo) { |
||||
try { |
||||
// 查询枪号
|
||||
List<BsGasOilGunNo> list = gasOilGunNoService.getOilGunNoList(merNo); |
||||
|
||||
if (StringUtils.isNotBlank(oilNo)) { |
||||
return ResponseMsgUtil.success(list.stream().filter(o -> o.getOilNo().equals(oilNo)).collect(Collectors.toList())); |
||||
} |
||||
|
||||
return ResponseMsgUtil.success(list); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsGasOilGunNoController --> queryGunNoList() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,251 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.security.UserCenter; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.*; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.model.UserInfoModel; |
||||
import com.hfkj.service.BsGasOilPriceService; |
||||
import com.hfkj.service.BsMerchantService; |
||||
import com.hfkj.service.CommonService; |
||||
import com.hfkj.sysenum.GasOilPriceStatusEnum; |
||||
import com.hfkj.sysenum.SecUserObjectTypeEnum; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.math.BigDecimal; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/gasOilPrice") |
||||
@Api(value = "加油站价格") |
||||
public class BsGasOilPriceController { |
||||
private static Logger log = LoggerFactory.getLogger(BsGasOilPriceController.class); |
||||
|
||||
@Resource |
||||
private BsGasOilPriceService gasOilPriceService; |
||||
@Resource |
||||
private BsMerchantService merchantService; |
||||
@Resource |
||||
private UserCenter userCenter; |
||||
@Resource |
||||
private CommonService commonService; |
||||
|
||||
@RequestMapping(value = "/createOil", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "创建油品") |
||||
public ResponseData createOil(@RequestBody BsGasOilPrice body) { |
||||
try { |
||||
|
||||
UserInfoModel userInfoModel = userCenter.getSessionModel(UserInfoModel.class); |
||||
if (userInfoModel == null || !userInfoModel.getSecUser().getObjectType().equals(SecUserObjectTypeEnum.type4.getNumber())) { |
||||
log.error("BsGasOilPriceController --> createOil() error!", "用户身份错误或已过期"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.SEC_USER_EXPIRED, ""); |
||||
} |
||||
|
||||
if (body == null |
||||
|| body.getMerNo() == null |
||||
|| StringUtils.isBlank(body.getOilNo()) |
||||
|| body.getPriceOfficial() == null |
||||
|| body.getGasStationDrop() == null){ |
||||
log.error("BsGasOilPriceController --> createOil() error!", "参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
// 查询商户
|
||||
BsMerchant merchant = merchantService.getMerchant(body.getMerNo()); |
||||
if (merchant == null) { |
||||
log.error("BsGasOilPriceController --> createOil() error!", "未知的商户"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的商户"); |
||||
} |
||||
if (!merchant.getId().equals(userInfoModel.getMerchant().getId())) { |
||||
log.error("BsGasOilPriceController --> createOil() error!", "权限不足"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMPETENCE_INSUFFICIENT, ""); |
||||
} |
||||
// 是否重复添加商户油品
|
||||
if (gasOilPriceService.getGasOilPrice(merchant.getId(), body.getOilNo()) != null) { |
||||
log.error("BsGasOilPriceController --> createOil() error!", "重复添加" + body.getOilNo() + "油品"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "重复添加" + body.getOilNo() + "油品"); |
||||
} |
||||
// 获取油品信息
|
||||
SecDictionary oilNo = commonService.mappingSysCode("OIL_NO", body.getOilNo()); |
||||
if (oilNo == null) { |
||||
log.error("BsGasOilPriceController --> createOil() error!", "油品不存在"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "油品不存在"); |
||||
} |
||||
// 获取油品类型
|
||||
SecDictionary oilNoType = commonService.mappingSysCode("OIL_NO_TYPE", oilNo.getExt1()); |
||||
if (oilNoType == null) { |
||||
log.error("BsGasOilPriceController --> createOil() error!", "未知的的油品类型"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的的油品类型"); |
||||
} |
||||
|
||||
BsGasOilPrice oilPrice = new BsGasOilPrice(); |
||||
oilPrice.setMerId(merchant.getId()); |
||||
oilPrice.setMerNo(merchant.getMerNo()); |
||||
oilPrice.setOilType(Integer.valueOf(oilNoType.getCodeValue())); |
||||
oilPrice.setOilTypeName(oilNoType.getCodeName()); |
||||
oilPrice.setOilNo(oilNo.getCodeValue()); |
||||
oilPrice.setOilNoName(oilNo.getCodeName()); |
||||
oilPrice.setPreferentialMargin(new BigDecimal("0")); |
||||
oilPrice.setGasStationDrop(body.getGasStationDrop()); |
||||
oilPrice.setPriceOfficial(body.getPriceOfficial()); |
||||
oilPrice.setPriceGun(oilPrice.getPriceOfficial().subtract(body.getGasStationDrop())); |
||||
oilPrice.setPriceVip(oilPrice.getPriceGun()); |
||||
oilPrice.setStatus(GasOilPriceStatusEnum.status1.getNumber()); |
||||
gasOilPriceService.editOilPrice(oilPrice); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsGasOilPriceController --> createOil() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/restore", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "恢复") |
||||
public ResponseData restore(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body == null |
||||
|| StringUtils.isBlank(body.getString("merNo")) |
||||
|| StringUtils.isBlank(body.getString("oilNo"))) { |
||||
log.error("BsMerchantController --> restoreMer() error!", "请求参数校验失败"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
// 查询商户
|
||||
BsMerchant merchant = merchantService.getMerchant(body.getString("merNo")); |
||||
if (merchant == null) { |
||||
log.error("BsGasOilPriceController --> restoreOil() error!", "未知的商户"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的商户"); |
||||
} |
||||
BsGasOilPrice oilPrice = gasOilPriceService.getGasOilPrice(merchant.getId(), body.getString("oilNo")); |
||||
if (oilPrice == null) { |
||||
log.error("BsGasOilPriceController --> restoreOil() error!", "未知的油品"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的油品"); |
||||
} |
||||
oilPrice.setStatus(GasOilPriceStatusEnum.status1.getNumber()); |
||||
gasOilPriceService.editOilPrice(oilPrice); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsMerchantController --> restoreMer() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/disable", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "禁用油品") |
||||
public ResponseData disable(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body == null |
||||
|| StringUtils.isBlank(body.getString("merNo")) |
||||
|| StringUtils.isBlank(body.getString("oilNo"))) { |
||||
log.error("BsMerchantController --> disableOil() error!", "请求参数校验失败"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
// 查询商户
|
||||
BsMerchant merchant = merchantService.getMerchant(body.getString("merNo")); |
||||
if (merchant == null) { |
||||
log.error("BsGasOilPriceController --> disableOil() error!", "未知的商户"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的商户"); |
||||
} |
||||
BsGasOilPrice oilPrice = gasOilPriceService.getGasOilPrice(merchant.getId(), body.getString("oilNo")); |
||||
if (oilPrice == null) { |
||||
log.error("BsGasOilPriceController --> disableOil() error!", "未知的油品"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的油品"); |
||||
} |
||||
oilPrice.setStatus(GasOilPriceStatusEnum.status2.getNumber()); |
||||
gasOilPriceService.editOilPrice(oilPrice); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
} catch (Exception e) { |
||||
log.error("BsMerchantController --> disableOil() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/delete", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "删除油品") |
||||
public ResponseData delete(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body == null |
||||
|| StringUtils.isBlank(body.getString("merNo")) |
||||
|| StringUtils.isBlank(body.getString("oilNo"))) { |
||||
log.error("BsMerchantController --> disableOil() error!", "请求参数校验失败"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
// 查询商户
|
||||
BsMerchant merchant = merchantService.getMerchant(body.getString("merNo")); |
||||
if (merchant == null) { |
||||
log.error("BsGasOilPriceController --> disableOil() error!", "未知的商户"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的商户"); |
||||
} |
||||
BsGasOilPrice oilPrice = gasOilPriceService.getGasOilPrice(merchant.getId(), body.getString("oilNo")); |
||||
if (oilPrice == null) { |
||||
log.error("BsGasOilPriceController --> disableOil() error!", "未知的油品"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的油品"); |
||||
} |
||||
gasOilPriceService.delete(oilPrice); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
} catch (Exception e) { |
||||
log.error("BsMerchantController --> disableOil() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/queryOilDetail", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询油品详情") |
||||
public ResponseData queryOilDetail(@RequestParam(value = "oilId", required = true) Long oilId) { |
||||
try { |
||||
|
||||
return ResponseMsgUtil.success(gasOilPriceService.getGasOilPrice(oilId)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsMerchantController --> queryOilDetail() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/queryOilList", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询油品列表") |
||||
public ResponseData queryOilList(@RequestParam(value = "merNo", required = true) String merNo, |
||||
@RequestParam(value = "oilNo", required = false) String oilNo, |
||||
@RequestParam(value = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(value = "pageSize", required = true) Integer pageSize) { |
||||
try { |
||||
Map<String,Object> map = new HashMap<>(); |
||||
map.put("merNo", merNo); |
||||
map.put("oilNo", oilNo); |
||||
|
||||
PageHelper.startPage(pageNum,pageSize); |
||||
return ResponseMsgUtil.success(new PageInfo<>(gasOilPriceService.getGasOilPriceList(map))); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsMerchantController --> queryOilList() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,269 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.security.UserCenter; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.BsGasOilPriceTask; |
||||
import com.hfkj.entity.BsMerchant; |
||||
import com.hfkj.entity.SecDictionary; |
||||
import com.hfkj.entity.SecRegion; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.model.UserInfoModel; |
||||
import com.hfkj.service.BsAgentService; |
||||
import com.hfkj.service.BsGasOilPriceTaskService; |
||||
import com.hfkj.service.BsMerchantService; |
||||
import com.hfkj.service.CommonService; |
||||
import com.hfkj.sysenum.GasOilPriceTaskExecutionTypeEnum; |
||||
import com.hfkj.sysenum.GasTaskPriceTypeEnum; |
||||
import com.hfkj.sysenum.SecUserObjectTypeEnum; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/gasOilPriceTask") |
||||
@Api(value = "油品价格配置") |
||||
public class BsGasOilPriceTaskController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(BsGasOilPriceTaskController.class); |
||||
|
||||
@Resource |
||||
private BsGasOilPriceTaskService gasOilPriceTaskService; |
||||
@Resource |
||||
private BsMerchantService merchantService; |
||||
@Resource |
||||
private UserCenter userCenter; |
||||
@Resource |
||||
private CommonService commonService; |
||||
|
||||
@RequestMapping(value="/batchAddTask",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "批量增加任务") |
||||
public ResponseData batchAddTask(@RequestBody List<BsGasOilPriceTask> taskList) { |
||||
try { |
||||
UserInfoModel userInfoModel = userCenter.getSessionModel(UserInfoModel.class); |
||||
if (userInfoModel == null) { |
||||
log.error("BsGasOilPriceTaskController -> batchAddTask() error!",""); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMPETENCE_INSUFFICIENT, ""); |
||||
} |
||||
if (taskList == null || taskList.size() == 0) { |
||||
log.error("BsGasOilPriceTaskController -> batchAddTask() error!",""); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
for (BsGasOilPriceTask task : taskList) { |
||||
if (task.getPriceType() == null |
||||
|| task.getPrice() == null |
||||
|| task.getOilNo() == null |
||||
|| task.getExecutionType() == null) { |
||||
log.error("BsGasOilPriceTaskController -> batchAddTask() error!",""); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
// 执行方式 1. 立刻执行 2. 定时执行
|
||||
if (task.getExecutionType().equals(GasOilPriceTaskExecutionTypeEnum.type2.getNumber()) && task.getStartTime() == null) { |
||||
log.error("BsGasOilPriceTaskController -> batchAddTask() error!",""); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未配置执行时间"); |
||||
} |
||||
|
||||
// 价格类型 1. 国标价 2. 油站价 3. 平台优惠 4. 油站直降
|
||||
if (task.getPriceType().equals(GasTaskPriceTypeEnum.type1.getStatus())) { |
||||
if (task.getRegionId() == null) { |
||||
log.error("HighGasDiscountOilPriceController -> updateOilPriceOfficial() error!",""); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未配置区域"); |
||||
} |
||||
// 加油站
|
||||
SecRegion region = commonService.getRegionsById(task.getRegionId()); |
||||
if (region == null) { |
||||
log.error("HighGasDiscountOilPriceController -> updateOilPriceOfficial() error!",""); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到区域"); |
||||
} |
||||
task.setRegionId(region.getRegionId()); |
||||
task.setRegionName(region.getRegionName()); |
||||
} |
||||
|
||||
// 价格类型 1. 国标价 2. 油站价 3. 平台优惠 4. 油站直降
|
||||
if (task.getPriceType().equals(GasTaskPriceTypeEnum.type2.getStatus()) |
||||
|| task.getPriceType().equals(GasTaskPriceTypeEnum.type3.getStatus()) |
||||
|| task.getPriceType().equals(GasTaskPriceTypeEnum.type4.getStatus()) ) { |
||||
|
||||
if (StringUtils.isBlank(task.getMerNo())) { |
||||
log.error("HighGasDiscountOilPriceController -> updateOilPriceOfficial() error!",""); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未配置加油站"); |
||||
} |
||||
// 加油站
|
||||
BsMerchant merchant = merchantService.getMerchant(task.getMerNo()); |
||||
if (merchant == null) { |
||||
log.error("HighGasDiscountOilPriceController -> updateOilPriceOfficial() error!",""); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到加油站"); |
||||
} |
||||
task.setRegionId(merchant.getProvinceCode()); |
||||
task.setRegionName(merchant.getProvinceName()); |
||||
task.setMerId(merchant.getId()); |
||||
task.setMerNo(merchant.getMerNo()); |
||||
task.setMerName(merchant.getMerName()); |
||||
task.setMerAddress(merchant.getAddress()); |
||||
} |
||||
// 查询油品
|
||||
SecDictionary oil = commonService.mappingSysCode("OIL_NO", task.getOilNo().toString()); |
||||
if (oil == null) { |
||||
log.error("HighGasDiscountOilPriceController -> updateOilPriceOfficial() error!",""); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
// 查询油品
|
||||
SecDictionary oilNoType = commonService.mappingSysCode("OIL_NO_TYPE", ""+oil.getExt1()); |
||||
if (oilNoType == null) { |
||||
log.error("HighGasDiscountOilPriceController -> updateOilPriceOfficial() error!",""); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
task.setOilType(Integer.valueOf(oilNoType.getCodeValue())); |
||||
task.setOilTypeName(oilNoType.getCodeName()); |
||||
task.setOilNoName(oil.getCodeName()); |
||||
task.setOpUserId(userInfoModel.getSecUser().getId()); |
||||
task.setOpUserName(userInfoModel.getSecUser().getUserName()); |
||||
|
||||
if (task.getOilPriceZoneId() != null) { |
||||
// 查询价区
|
||||
SecDictionary oilPriceZone = commonService.mappingSysCode("OIL_PRICE_ZONE", "" + task.getOilPriceZoneId()); |
||||
if (oilPriceZone != null) { |
||||
task.setOilPriceZoneId(Integer.valueOf(oilPriceZone.getCodeValue())); |
||||
task.setOilPriceZoneName(oilPriceZone.getCodeName()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
gasOilPriceTaskService.batchAddTask(taskList); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighGasOilPriceTaskController -> addTask() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/delTask",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "删除任务") |
||||
public ResponseData delTask(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body.getLong("taskId") == null) { |
||||
log.error("HighGasOilPriceTaskController -> delTask() error!",""); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
gasOilPriceTaskService.delTask(body.getLong("taskId")); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighGasOilPriceTaskController -> delTask() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/getTaskDetail",method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询任务详情") |
||||
public ResponseData getTaskDetail(@RequestParam(name = "taskId", required = true) Long taskId) { |
||||
try { |
||||
|
||||
return ResponseMsgUtil.success(gasOilPriceTaskService.getDetailById(taskId)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighGasOilPriceTaskController -> getTaskDetail() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/getTaskList",method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询任务列表") |
||||
public ResponseData getTaskList(@RequestParam(name = "regionId", required = false) Long regionId, |
||||
@RequestParam(name = "regionName", required = false) String regionName, |
||||
@RequestParam(name = "merId", required = false) Long merId, |
||||
@RequestParam(name = "merNo", required = false) String merNo, |
||||
@RequestParam(name = "merName", required = false) String merName, |
||||
@RequestParam(name = "oilType", required = false) Integer oilType, |
||||
@RequestParam(name = "oilNo", required = false) Integer oilNo, |
||||
@RequestParam(name = "priceType", required = false) Integer priceType, |
||||
@RequestParam(name = "executionType", required = false) Integer executionType, |
||||
@RequestParam(name = "status", required = false) Integer status, |
||||
@RequestParam(name = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(name = "pageSize", required = true) Integer pageSize) { |
||||
try { |
||||
UserInfoModel userInfoModel = userCenter.getSessionModel(UserInfoModel.class); |
||||
if (userInfoModel == null) { |
||||
log.error("HighGasController -> disabledOil() error!",""); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMPETENCE_INSUFFICIENT, ""); |
||||
} |
||||
|
||||
Map<String, Object> param = new HashMap<>(); |
||||
param.put("regionId", regionId); |
||||
param.put("regionName", regionName); |
||||
param.put("merId", merId); |
||||
param.put("merNo", merNo); |
||||
param.put("merName", merName); |
||||
|
||||
if (userInfoModel.getSecUser().getObjectType().equals(SecUserObjectTypeEnum.type0.getNumber()) |
||||
|| userInfoModel.getSecUser().getObjectType().equals(SecUserObjectTypeEnum.type1.getNumber())) { |
||||
|
||||
} else if (userInfoModel.getSecUser().getObjectType().equals(SecUserObjectTypeEnum.type2.getNumber())) { |
||||
param.put("regionId", userInfoModel.getBsCompany().getRegionId()); |
||||
|
||||
} else if (userInfoModel.getSecUser().getObjectType().equals(SecUserObjectTypeEnum.type3.getNumber())) { |
||||
if (merId == null) { |
||||
Map<String,Object> merParam = new HashMap<>(); |
||||
merParam.put("agentId", userInfoModel.getAgent().getId()); |
||||
// 查询代理商下的商户
|
||||
List<BsMerchant> merchantList = merchantService.getMerchantList(merParam); |
||||
String merNoListStr = ""; |
||||
if (merchantList.size() > 0) { |
||||
for (BsMerchant merchant : merchantList) { |
||||
if (StringUtils.isBlank(merNoListStr)) { |
||||
merNoListStr += merchant.getMerNo(); |
||||
} else { |
||||
merNoListStr += ","+merchant.getMerNo(); |
||||
} |
||||
} |
||||
param.put("merNoList", merNoListStr); |
||||
} else { |
||||
// 代理商没有商户 直接返回空数据
|
||||
return ResponseMsgUtil.success(new PageInfo<>(new ArrayList<>())); |
||||
} |
||||
} else { |
||||
param.put("merId", merId); |
||||
} |
||||
} else if (userInfoModel.getSecUser().getObjectType().equals(SecUserObjectTypeEnum.type4.getNumber())) { |
||||
param.put("merId", userInfoModel.getMerchant().getId()); |
||||
} |
||||
param.put("oilType", oilType); |
||||
param.put("oilNo", oilNo); |
||||
param.put("priceType", priceType); |
||||
param.put("executionType", executionType); |
||||
param.put("status", status); |
||||
|
||||
PageHelper.startPage(pageNum,pageSize); |
||||
return ResponseMsgUtil.success(new PageInfo<>(gasOilPriceTaskService.getTaskList(param))); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighGasOilPriceTaskController -> getTaskList() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,250 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.security.UserCenter; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.*; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.model.UserInfoModel; |
||||
import com.hfkj.service.*; |
||||
import com.hfkj.sysenum.MerchantStatusEnum; |
||||
import com.hfkj.sysenum.SecUserObjectTypeEnum; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.stream.Collectors; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/merchant") |
||||
@Api(value = "商户管理") |
||||
public class BsMerchantController { |
||||
private static Logger log = LoggerFactory.getLogger(BsMerchantController.class); |
||||
|
||||
@Resource |
||||
private BsMerchantService merchantService; |
||||
@Resource |
||||
private BsGasOilPriceService gasOilPriceService; |
||||
@Resource |
||||
private BsGasOilGunNoService gasOilGunNoService; |
||||
@Resource |
||||
private UserCenter userCenter; |
||||
@Resource |
||||
private CommonService commonService; |
||||
|
||||
@RequestMapping(value = "/editMerchant", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "编辑商户") |
||||
public ResponseData editMerchant(@RequestBody BsMerchant body) { |
||||
try { |
||||
if (body == null |
||||
|| body.getAreaCode() == null |
||||
|| StringUtils.isBlank(body.getMerLogo()) |
||||
|| StringUtils.isBlank(body.getMerName()) |
||||
|| StringUtils.isBlank(body.getContactsName()) |
||||
|| StringUtils.isBlank(body.getContactsTel()) |
||||
|| StringUtils.isBlank(body.getCustomerServiceTel()) |
||||
|| StringUtils.isBlank(body.getAddress()) |
||||
|| StringUtils.isBlank(body.getLongitude()) |
||||
|| StringUtils.isBlank(body.getLatitude()) |
||||
|| StringUtils.isBlank(body.getMerLabel()) |
||||
) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
BsMerchant merchant = null; |
||||
if (StringUtils.isNotBlank(body.getMerNo())) { |
||||
// 查询商户
|
||||
merchant = merchantService.getMerchant(body.getMerNo()); |
||||
if (merchant == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "未知商户"); |
||||
} |
||||
} else { |
||||
merchant = new BsMerchant(); |
||||
merchant.setStatus(MerchantStatusEnum.status1.getNumber()); |
||||
} |
||||
|
||||
if (body.getOilPriceZoneId() != null) { |
||||
// 查询价区
|
||||
SecDictionary oilPriceZone = commonService.mappingSysCode("OIL_PRICE_ZONE", body.getOilPriceZoneId().toString()); |
||||
if (oilPriceZone == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的价区"); |
||||
} |
||||
merchant.setOilPriceZoneId(Integer.valueOf(oilPriceZone.getCodeValue())); |
||||
merchant.setOilPriceZoneName(oilPriceZone.getCodeName()); |
||||
} |
||||
// 查询区域
|
||||
SecRegion areaRegion = commonService.getRegionsById(body.getAreaCode()); |
||||
if (areaRegion == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知地区"); |
||||
} |
||||
// 查询市
|
||||
SecRegion cityRegion = commonService.getRegionsById(areaRegion.getParentId()); |
||||
if (cityRegion == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的市级"); |
||||
} |
||||
// 查询省
|
||||
SecRegion provinceRegion = commonService.getRegionsById(cityRegion.getParentId()); |
||||
if (provinceRegion == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的省级"); |
||||
} |
||||
|
||||
merchant.setProvinceCode(provinceRegion.getRegionId()); |
||||
merchant.setProvinceName(provinceRegion.getRegionName()); |
||||
merchant.setCityCode(cityRegion.getRegionId()); |
||||
merchant.setCityName(cityRegion.getRegionName()); |
||||
merchant.setAreaCode(areaRegion.getRegionId()); |
||||
merchant.setAreaName(areaRegion.getRegionName()); |
||||
merchant.setMerLogo(body.getMerLogo()); |
||||
merchant.setMerName(body.getMerName()); |
||||
merchant.setContactsName(body.getContactsName()); |
||||
merchant.setContactsTel(body.getContactsTel()); |
||||
merchant.setCustomerServiceTel(body.getCustomerServiceTel()); |
||||
merchant.setAddress(body.getAddress()); |
||||
merchant.setLatitude(body.getLatitude()); |
||||
merchant.setLongitude(body.getLongitude()); |
||||
merchant.setMerLabel(body.getMerLabel()); |
||||
|
||||
if (merchant.getMerNo() == null) { |
||||
merchantService.createMerchant(merchant); |
||||
} else { |
||||
merchantService.updateMerchant(merchant); |
||||
} |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsMerchantController --> editMerchant() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/restoreMer", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "恢复商户") |
||||
public ResponseData restoreMer(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body == null || StringUtils.isBlank(body.getString("merNo"))) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
merchantService.updateMerStatus(body.getString("merNo"), MerchantStatusEnum.status1); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
} catch (Exception e) { |
||||
log.error("BsMerchantController --> restoreMer() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/disableMer", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "禁用商户") |
||||
public ResponseData disableMer(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body == null || StringUtils.isBlank(body.getString("merNo"))) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
merchantService.updateMerStatus(body.getString("merNo"), MerchantStatusEnum.status2); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
} catch (Exception e) { |
||||
log.error("BsMerchantController --> disableMer() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/resetMerPwd", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "重置商户密码") |
||||
public ResponseData resetMerPwd(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body == null || StringUtils.isBlank(body.getString("merNo"))) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
merchantService.resetMerPwd(body.getString("merNo")); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
} catch (Exception e) { |
||||
log.error("BsMerchantController --> resetMerPwd() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/queryMerDetail", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询商户详情") |
||||
public ResponseData queryMerDetail(@RequestParam(value = "merNo", required = true) String merNo) { |
||||
try { |
||||
// 查询商户
|
||||
BsMerchant merchant = merchantService.getMerchant(merNo); |
||||
if (merchant == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的商户号"); |
||||
} |
||||
|
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("merNo", merNo); |
||||
// 查询油品
|
||||
List<BsGasOilPrice> priceList = gasOilPriceService.getGasOilPriceList(param); |
||||
// 查询枪号
|
||||
List<BsGasOilGunNo> oilGunNoList = gasOilGunNoService.getOilGunNoList(merNo); |
||||
|
||||
// 获取枪号
|
||||
List<Object> oilsList = new ArrayList<>(); |
||||
for (BsGasOilPrice oilPrice : priceList) { |
||||
JSONObject oil = JSONObject.parseObject(JSONObject.toJSONString(oilPrice)); |
||||
// 获取枪号
|
||||
oil.put("gunNoList", oilGunNoList.stream().filter(o -> o.getOilNo().equals(oilPrice.getOilNo())).collect(Collectors.toList())); |
||||
oilsList.add(oil); |
||||
} |
||||
|
||||
Map<String,Object> map = new HashMap<>(); |
||||
map.put("merchant", merchant); |
||||
map.put("oils", oilsList); |
||||
return ResponseMsgUtil.success(map); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsMerchantController --> queryMer() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/queryMerList", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询商户列表") |
||||
public ResponseData queryMerList(@RequestParam(value = "merNo", required = false) String merNo, |
||||
@RequestParam(value = "merName", required = false) String merName, |
||||
@RequestParam(value = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(value = "pageSize", required = true) Integer pageSize) { |
||||
try { |
||||
Map<String,Object> map = new HashMap<>(); |
||||
map.put("merNo", merNo); |
||||
map.put("merName", merName); |
||||
|
||||
PageHelper.startPage(pageNum,pageSize); |
||||
return ResponseMsgUtil.success(new PageInfo<>(merchantService.getMerchantList(map))); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsMerchantController --> queryMerList() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,94 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.BsMerchant; |
||||
import com.hfkj.entity.BsMerchantPayConfig; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.service.BsMerchantPayConfigService; |
||||
import com.hfkj.service.BsMerchantService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
|
||||
/** |
||||
* @className: BsMerchantPayConfigController |
||||
* @author: HuRui |
||||
* @date: 2024/3/13 |
||||
**/ |
||||
@Controller |
||||
@RequestMapping(value = "/merchantPayConfig") |
||||
@Api(value = "商户支付配置") |
||||
public class BsMerchantPayConfigController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(BsMerchantPayConfigController.class); |
||||
|
||||
@Resource |
||||
private BsMerchantPayConfigService merchantPayConfigService; |
||||
@Resource |
||||
private BsMerchantService merchantService; |
||||
|
||||
@RequestMapping(value = "/editConfig", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "编辑配置") |
||||
public ResponseData editConfig(@RequestBody BsMerchantPayConfig body) { |
||||
try { |
||||
if (body == null |
||||
|| body.getMerNo() == null |
||||
|| StringUtils.isBlank(body.getChannelMerNo()) |
||||
|| StringUtils.isBlank(body.getChannelMerKey())) { |
||||
log.error("BsMerchantPayConfigController --> editConfig() error!", "参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
// 查询商户
|
||||
BsMerchant merchant = merchantService.getMerchant(body.getMerNo()); |
||||
if (merchant == null) { |
||||
log.error("BsMerchantPayConfigController --> editConfig() error!", "参数错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
// 查询配置
|
||||
BsMerchantPayConfig config = merchantPayConfigService.getConfig(body.getMerNo()); |
||||
if (config == null) { |
||||
config = new BsMerchantPayConfig(); |
||||
} |
||||
config.setMerId(merchant.getId()); |
||||
config.setMerNo(merchant.getMerNo()); |
||||
config.setMerName(merchant.getMerName()); |
||||
config.setChannelName("惠支付"); |
||||
config.setChannelCode("HUI_PAY"); |
||||
config.setChannelMerNo(body.getChannelMerNo()); |
||||
config.setChannelMerKey(body.getChannelMerKey()); |
||||
merchantPayConfigService.editData(config); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsMerchantPayConfigController --> editConfig() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
|
||||
@RequestMapping(value = "/queryConfig", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "获取配置") |
||||
public ResponseData queryConfig(@RequestParam(value = "merNo", required = true) String merNo) { |
||||
try { |
||||
|
||||
return ResponseMsgUtil.success(merchantPayConfigService.getConfig(merNo)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsMerchantPayConfigController --> queryConfig() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,108 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.model.UserInfoModel; |
||||
import com.hfkj.service.BsMerchantQrCodeService; |
||||
import com.hfkj.service.BsMerchantService; |
||||
import com.hfkj.sysenum.MerchantQrCodeStatusEnum; |
||||
import com.hfkj.sysenum.MerchantStatusEnum; |
||||
import com.hfkj.sysenum.SecUserObjectTypeEnum; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/merchantQrCode") |
||||
@Api(value = "商户二维码管理") |
||||
public class BsMerchantQrCodeController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(BsMerchantQrCodeController.class); |
||||
|
||||
@Resource |
||||
private BsMerchantQrCodeService merchantQrCodeService; |
||||
|
||||
@RequestMapping(value = "/restore", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "恢复") |
||||
public ResponseData restore(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body == null || body.getLong("qrCodeId") == null) { |
||||
log.error("BsMerchantQrCodeController --> restore() error!", "请求参数校验失败"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
merchantQrCodeService.updateQrCodeStatus(body.getLong("qrCodeId"), MerchantQrCodeStatusEnum.status1); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsMerchantQrCodeController --> restore() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/disable", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "禁用") |
||||
public ResponseData disable(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body == null || body.getLong("qrCodeId") == null) { |
||||
log.error("BsMerchantQrCodeController --> disable() error!", "请求参数校验失败"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
merchantQrCodeService.updateQrCodeStatus(body.getLong("qrCodeId"), MerchantQrCodeStatusEnum.status2); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsMerchantQrCodeController --> disable() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/queryQrCode", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询商户二维码详情") |
||||
public ResponseData queryQrCode(@RequestParam(value = "qrCodeId", required = true) Long qrCodeId) { |
||||
try { |
||||
|
||||
return ResponseMsgUtil.success(merchantQrCodeService.getMerQrCode(qrCodeId)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsMerchantController --> queryQrCode() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/queryQrCodeList", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询商户二维码列表") |
||||
public ResponseData queryQrCodeList(@RequestParam(value = "merNo", required = true) String merNo) { |
||||
try { |
||||
return ResponseMsgUtil.success(merchantQrCodeService.getMerQrCodeList(merNo)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsMerchantQrCodeController --> queryQrCodeList() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
} |
@ -0,0 +1,53 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.BsMerchantUser; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.service.BsMerchantUserService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestMethod; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/merUser") |
||||
@Api(value = "商户管理") |
||||
public class BsMerchantUserController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(BsMerchantUserController.class); |
||||
|
||||
@Resource |
||||
private BsMerchantUserService merchantUserService; |
||||
|
||||
@RequestMapping(value = "/queryList", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询列表") |
||||
public ResponseData queryList(@RequestParam(value = "merId", required = false) Long merId, |
||||
@RequestParam(value = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(value = "pageSize", required = true) Integer pageSize) { |
||||
try { |
||||
|
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("merId", merId); |
||||
|
||||
PageHelper.startPage(pageNum,pageSize); |
||||
return ResponseMsgUtil.success(new PageInfo<>(merchantUserService.getList(param))); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("BsMerchantUserController --> queryList() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,187 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONArray; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.CmsCategory; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.service.CmsCategoryService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
@Controller |
||||
@Api(value = "内容分类管理") |
||||
@RequestMapping(value = "/cmsCategory") |
||||
public class CmsCategoryController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(CmsCategoryController.class); |
||||
@Resource |
||||
private CmsCategoryService cmsCategoryService; |
||||
|
||||
@RequestMapping(value = "/addCategory", method = RequestMethod.POST) |
||||
@ApiOperation(value = "增加 分类") |
||||
@ResponseBody |
||||
public ResponseData addCategory(@RequestBody JSONObject jsonObject) { |
||||
try { |
||||
|
||||
CmsCategory cmsCategory = jsonObject.getObject("category", CmsCategory.class); |
||||
JSONArray jsonArray = jsonObject.getJSONArray("roles"); |
||||
Object[] roleArray = jsonArray.toArray(); |
||||
|
||||
if (cmsCategory == null || roleArray == null || roleArray.length == 0 |
||||
|| StringUtils.isBlank(cmsCategory.getName()) |
||||
|| StringUtils.isBlank(cmsCategory.getCode())) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
List<Integer> roleList = new ArrayList<>(); |
||||
for (Object object : roleArray) { |
||||
roleList.add(Integer.valueOf(object.toString())); |
||||
} |
||||
|
||||
if (cmsCategoryService.addCategory(cmsCategory, roleList) > 0) { |
||||
return ResponseMsgUtil.success("添加数据成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.ADD_DATA_ERROR, ""); |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryController --> addCategory() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/updateCategory", method = RequestMethod.POST) |
||||
@ApiOperation(value = "修改 内容分类") |
||||
@ResponseBody |
||||
public ResponseData updateCategory(@RequestBody JSONObject jsonObject) { |
||||
try { |
||||
|
||||
CmsCategory cmsCategory = jsonObject.getObject("category", CmsCategory.class); |
||||
JSONArray jsonArray = jsonObject.getJSONArray("roles"); |
||||
Object[] roleArray = jsonArray.toArray(); |
||||
|
||||
if (cmsCategory == null || roleArray == null || roleArray.length == 0 |
||||
|| cmsCategory.getId() == null |
||||
|| StringUtils.isBlank(cmsCategory.getName()) |
||||
|| StringUtils.isBlank(cmsCategory.getCode())) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
List<Integer> roleList = new ArrayList<>(); |
||||
for (Object object : roleArray) { |
||||
roleList.add(Integer.valueOf(object.toString())); |
||||
} |
||||
|
||||
if (cmsCategoryService.updateCategory(cmsCategory, roleList) > 0) { |
||||
return ResponseMsgUtil.success("修改数据成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.UPDATE_DATA_ERROR, ""); |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryController --> updateCategory() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/delCategory", method = RequestMethod.GET) |
||||
@ApiOperation(value = "删除 内容分类") |
||||
@ResponseBody |
||||
public ResponseData delCategory(@RequestParam(value = "id", required = true) Long id) { |
||||
try { |
||||
if (cmsCategoryService.delCategory(id) > 0) { |
||||
return ResponseMsgUtil.success("删除成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.DELETE_DATA_ERROR, ""); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryController --> updateCategory() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getCategoryById", method = RequestMethod.GET) |
||||
@ApiOperation(value = "查询 分类详情") |
||||
@ResponseBody |
||||
public ResponseData getCategoryById(@RequestParam(value = "id", required = true) Long id) { |
||||
try { |
||||
return ResponseMsgUtil.success(cmsCategoryService.getCategoryById(id)); |
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryController --> getCategoryById() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getCategoryTree", method = RequestMethod.GET) |
||||
@ApiOperation(value = "获取分类树") |
||||
@ResponseBody |
||||
public ResponseData getCategoryTree(@RequestParam(value = "roleType", required = false) Integer roleType, |
||||
@RequestParam(value = "parentCode", required = false) String parentCode) { |
||||
try { |
||||
Map<String, Object> paramMap = new HashMap<>(); |
||||
if (roleType != null) { |
||||
paramMap.put("roleType", roleType); |
||||
} |
||||
if (StringUtils.isNotBlank(parentCode)) { |
||||
paramMap.put("parentCode", parentCode); |
||||
} |
||||
|
||||
return ResponseMsgUtil.success(cmsCategoryService.getCategoryTree(paramMap)); |
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryController --> getCategoryTree() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getOwnCategoryTree", method = RequestMethod.GET) |
||||
@ApiOperation(value = "获取拥有的分类树") |
||||
@ResponseBody |
||||
public ResponseData getOwnCategoryTree(@RequestParam(value = "roleType", required = false) Integer roleType) { |
||||
try { |
||||
Map<String, Object> paramMap = new HashMap<>(); |
||||
if (roleType != null) { |
||||
paramMap.put("roleType", roleType); |
||||
} |
||||
|
||||
return ResponseMsgUtil.success(cmsCategoryService.getOwnCategoryTree(paramMap)); |
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryController --> getCategoryTree() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getRolesOfCategory", method = RequestMethod.GET) |
||||
@ApiOperation(value = "根据id查询 分类角色列表") |
||||
@ResponseBody |
||||
public ResponseData getRolesOfCategory(@RequestParam(value = "id", required = false) Long id) { |
||||
try { |
||||
List<Integer> roleList = new ArrayList<>(); |
||||
if (id != null) { |
||||
roleList = cmsCategoryService.getRolesOfCategory(id); |
||||
} else { |
||||
roleList.add(1); |
||||
} |
||||
|
||||
return ResponseMsgUtil.success(roleList); |
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryController --> getCategoryById() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,220 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.security.SessionObject; |
||||
import com.hfkj.common.security.UserCenter; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.CmsCategoryModule; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.model.UserInfoModel; |
||||
import com.hfkj.service.CmsCategoryModuleService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.Date; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
@Controller |
||||
@Api(value = "内容管理 模板") |
||||
@RequestMapping(value = "/cmsCategoryModule") |
||||
public class CmsCategoryModuleController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(CmsCategoryModuleController.class); |
||||
|
||||
@Resource |
||||
private UserCenter userCenter; |
||||
|
||||
@Resource |
||||
private CmsCategoryModuleService cmsCategoryModuleService; |
||||
|
||||
@RequestMapping(value = "/addCategoryModule", method = RequestMethod.POST) |
||||
@ApiOperation(value = "增加 模板") |
||||
@ResponseBody |
||||
public ResponseData addCategoryModule(@RequestBody CmsCategoryModule cmsCategoryModule, |
||||
HttpServletRequest request |
||||
) { |
||||
try { |
||||
if (cmsCategoryModule == null |
||||
|| cmsCategoryModule.getCategoryId() == null |
||||
|| StringUtils.isBlank(cmsCategoryModule.getModuleName()) |
||||
|| StringUtils.isBlank(cmsCategoryModule.getModulePath()) |
||||
) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
// 获取操作者
|
||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
||||
if(sessionObject == null){ |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.SEC_USER_EXPIRED, ""); |
||||
} |
||||
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); |
||||
|
||||
cmsCategoryModule.setStatus(1); |
||||
cmsCategoryModule.setCreateTime(new Date()); |
||||
cmsCategoryModule.setOpId(userInfoModel.getSecUser().getId()); |
||||
if (cmsCategoryModuleService.addCategoryModule(cmsCategoryModule) > 0) { |
||||
return ResponseMsgUtil.success("添加成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.ADD_DATA_ERROR, ""); |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryModuleController --> addCategoryModule() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/updateCategoryModule", method = RequestMethod.POST) |
||||
@ApiOperation(value = "修改 模板") |
||||
@ResponseBody |
||||
public ResponseData updateCategoryModule(@RequestBody CmsCategoryModule cmsCategoryModule) { |
||||
try { |
||||
if (cmsCategoryModule == null |
||||
|| cmsCategoryModule.getId() == null |
||||
|| cmsCategoryModule.getCategoryId() == null |
||||
|| StringUtils.isBlank(cmsCategoryModule.getModuleName()) |
||||
|| StringUtils.isBlank(cmsCategoryModule.getModulePath()) |
||||
) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
CmsCategoryModule categoryModule = cmsCategoryModuleService.getCategoryModuleById(cmsCategoryModule.getId()); |
||||
if (categoryModule == null || categoryModule.getStatus() == 0) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.CMS_CATEGORY_MODULE_NOT_FOUND, ""); |
||||
} |
||||
|
||||
cmsCategoryModule.setStatus(categoryModule.getStatus()); |
||||
cmsCategoryModule.setCreateTime(categoryModule.getCreateTime()); |
||||
cmsCategoryModule.setOpId(categoryModule.getOpId()); |
||||
if (cmsCategoryModuleService.updateCategoryModule(cmsCategoryModule) > 0) { |
||||
return ResponseMsgUtil.success("修改成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.UPDATE_DATA_ERROR, ""); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryModuleController --> updateCategoryModule() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/delCategoryModule", method = RequestMethod.GET) |
||||
@ApiOperation(value = "删除 模板") |
||||
@ResponseBody |
||||
public ResponseData delCategoryModule(@RequestParam(value = "id", required = true) Long id) { |
||||
try { |
||||
if (cmsCategoryModuleService.delCategoryModule(id) > 0) { |
||||
return ResponseMsgUtil.success("删除成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.DELETE_DATA_ERROR, ""); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryModuleController --> delCategoryModule() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getCategoryModuleById", method = RequestMethod.GET) |
||||
@ApiOperation(value = "根据id 查询模板") |
||||
@ResponseBody |
||||
public ResponseData getCategoryModuleById(@RequestParam(value = "id", required = true) Long id) { |
||||
try { |
||||
return ResponseMsgUtil.success(cmsCategoryModuleService.getCategoryModuleById(id)); |
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryModuleController --> getCategoryModuleById() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getModuleByCategoryId", method = RequestMethod.GET) |
||||
@ApiOperation(value = "根据分类id 查询模板列表") |
||||
@ResponseBody |
||||
public ResponseData getModuleByCategoryId(@RequestParam(value = "categoryId", required = true) Long categoryId) { |
||||
try { |
||||
Map<String, Object> paramsMap = new HashMap<>(); |
||||
paramsMap.put("categoryId", categoryId); |
||||
|
||||
return ResponseMsgUtil.success(cmsCategoryModuleService.getListCategoryModule(paramsMap)); |
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryModuleController --> getCategoryModuleById() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getListCategoryModule", method = RequestMethod.GET) |
||||
@ApiOperation(value = "查询列表 模板") |
||||
@ResponseBody |
||||
public ResponseData getListCategoryModule(@RequestParam(value = "categoryId", required = false) Long categoryId, |
||||
@RequestParam(value = "categoryCode", required = false) String categoryCode, |
||||
@RequestParam(value = "moduleName", required = false) String moduleName, |
||||
@RequestParam(value = "status", required = false) Integer status, |
||||
@RequestParam(name = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(name = "pageSize", required = true) Integer pageSize) { |
||||
try { |
||||
Map<String, Object> paramsMap = new HashMap<>(); |
||||
if (categoryId != null) { |
||||
paramsMap.put("categoryId", categoryId); |
||||
} |
||||
if (StringUtils.isNotBlank(categoryCode)) { |
||||
paramsMap.put("categoryCode", categoryCode); |
||||
} |
||||
if (StringUtils.isNotBlank(moduleName)) { |
||||
paramsMap.put("moduleName", moduleName); |
||||
} |
||||
if (status != null) { |
||||
paramsMap.put("status", status); |
||||
} |
||||
|
||||
PageHelper.startPage(pageNum, pageSize); |
||||
return ResponseMsgUtil.success(new PageInfo<>(cmsCategoryModuleService.getListCategoryModule(paramsMap))); |
||||
} catch (Exception e) { |
||||
log.error("CmsCategoryModuleController --> getListCategoryModule() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/updateStatusOfModule", method = RequestMethod.POST) |
||||
@ApiOperation(value = "更新 模板状态") |
||||
@ResponseBody |
||||
public ResponseData updateStatusOfContent(@RequestBody JSONObject jsonObject) { |
||||
try { |
||||
Long id = jsonObject.getLong("id"); |
||||
Integer status = jsonObject.getInteger("status"); |
||||
|
||||
if (id == null |
||||
|| status == null |
||||
|| (status != 1 && status != 2) |
||||
) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
CmsCategoryModule categoryModule = cmsCategoryModuleService.getCategoryModuleById(id); |
||||
if (categoryModule == null || categoryModule.getStatus() == 0) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.CMS_CATEGORY_MODULE_NOT_FOUND, ""); |
||||
} |
||||
|
||||
categoryModule.setStatus(status); |
||||
if (cmsCategoryModuleService.updateCategoryModule(categoryModule) > 0) { |
||||
return ResponseMsgUtil.success("修改成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.UPDATE_DATA_ERROR, ""); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> updateStatusOfContent() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,392 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONArray; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.security.SessionObject; |
||||
import com.hfkj.common.security.UserCenter; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.bweb.config.SysConfig; |
||||
import com.hfkj.entity.CmsContent; |
||||
import com.hfkj.entity.CmsPatch; |
||||
import com.hfkj.model.CmsContentModel; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.model.UserInfoModel; |
||||
import com.hfkj.service.CmsContentService; |
||||
import com.hfkj.service.CmsPatchService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.*; |
||||
|
||||
@Controller |
||||
@Api(value = "内容管理 内容发布") |
||||
@RequestMapping(value = "/cmsContent") |
||||
public class CmsContentController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(CmsContentController.class); |
||||
|
||||
@Resource |
||||
private SysConfig sysConfig; |
||||
|
||||
@Resource |
||||
private UserCenter userCenter; |
||||
|
||||
@Resource |
||||
private CmsContentService cmsContentService; |
||||
@Resource |
||||
private CmsPatchService cmsPatchService; |
||||
|
||||
@RequestMapping(value = "/addContent", method = RequestMethod.POST) |
||||
@ApiOperation(value = "创建内容") |
||||
@ResponseBody |
||||
public ResponseData addContent(@RequestBody JSONObject jsonObject, HttpServletRequest request) { |
||||
try { |
||||
CmsContent cmsContent = jsonObject.getObject("cmsContent", CmsContent.class); |
||||
Long moduleId = jsonObject.getLong("moduleId"); |
||||
JSONArray jsonArray = jsonObject.getJSONArray("patches"); |
||||
List<CmsPatch> patchList = new ArrayList<>(); |
||||
if (jsonArray != null) { |
||||
patchList = JSONObject.parseArray(jsonArray.toJSONString(), CmsPatch.class); |
||||
} |
||||
|
||||
if (cmsContent == null |
||||
|| StringUtils.isBlank(cmsContent.getTitle()) |
||||
|| cmsContent.getCategoryId() == null |
||||
|| cmsContent.getStatus() == null |
||||
|| (cmsContent.getStatus() != 1 && cmsContent.getStatus() != 2) |
||||
) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
// 获取操作者
|
||||
SessionObject sessionObject = userCenter.getSessionObject(request); |
||||
if(sessionObject == null){ |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.SEC_USER_EXPIRED, ""); |
||||
} |
||||
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); |
||||
|
||||
Map<String, String> paramsMap = new HashMap<>(); |
||||
if (moduleId != null) { |
||||
paramsMap.put("moduleId", moduleId.toString()); |
||||
} |
||||
|
||||
cmsContent.setCreateTime(new Date()); |
||||
cmsContent.setVisitCount(0); |
||||
cmsContent.setUpdateTime(cmsContent.getCreateTime()); |
||||
cmsContent.setCompanyId(userInfoModel.getBsCompany().getId()); |
||||
cmsContent.setOpId(userInfoModel.getSecUser().getId()); |
||||
if (cmsContentService.addContent(cmsContent, patchList, paramsMap,sysConfig.getFileUrl()) > 0) { |
||||
return ResponseMsgUtil.success("添加成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.ADD_DATA_ERROR, ""); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> addContent() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/updateContent", method = RequestMethod.POST) |
||||
@ApiOperation(value = "修改内容") |
||||
@ResponseBody |
||||
public ResponseData updateContent(@RequestBody CmsContent cmsContent) { |
||||
try { |
||||
if (cmsContent == null |
||||
|| cmsContent.getId() == null |
||||
|| StringUtils.isBlank(cmsContent.getTitle()) |
||||
|| cmsContent.getCategoryId() == null |
||||
) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
CmsContent content = cmsContentService.getContentById(cmsContent.getId()); |
||||
if (content == null || content.getStatus() == 0) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.CMS_CONTENT_NOT_FOUND, ""); |
||||
} else if (content.getStatus() != 1 && content.getStatus() != 3) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.STATUS_ERROR, ""); |
||||
} |
||||
|
||||
cmsContent.setCreateTime(content.getCreateTime()); |
||||
cmsContent.setStatus(content.getStatus()); |
||||
cmsContent.setVisitCount(content.getVisitCount()); |
||||
cmsContent.setJumpUrl(content.getJumpUrl()); |
||||
cmsContent.setUpdateTime(new Date()); |
||||
cmsContent.setCompanyId(content.getCompanyId()); |
||||
cmsContent.setOpId(content.getOpId()); |
||||
if (cmsContentService.updateContent(cmsContent, "updateContent", null,sysConfig.getFileUrl()) > 0) { |
||||
return ResponseMsgUtil.success("修改成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.UPDATE_DATA_ERROR, ""); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> updateContent() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/delContent", method = RequestMethod.GET) |
||||
@ApiOperation(value = "删除 内容") |
||||
@ResponseBody |
||||
public ResponseData delContent(@RequestParam(value = "id", required = true) Long id) { |
||||
try { |
||||
if (cmsContentService.delContent(id,sysConfig.getFileUrl()) > 0) { |
||||
return ResponseMsgUtil.success("删除成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.DELETE_DATA_ERROR, ""); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> delContent() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getContentById", method = RequestMethod.GET) |
||||
@ApiOperation(value = "根据id 查询内容基础信息") |
||||
@ResponseBody |
||||
public ResponseData getContentById(@RequestParam(value = "id", required = true) Long id) { |
||||
try { |
||||
return ResponseMsgUtil.success(cmsContentService.getContentDetail(id, null)); |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> getContentDetail() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getContentDetail", method = RequestMethod.GET) |
||||
@ApiOperation(value = "根据id 查询内容详情(包括附件列表)") |
||||
@ResponseBody |
||||
public ResponseData getContentDetail(@RequestParam(value = "id", required = true) Long id) { |
||||
try { |
||||
return ResponseMsgUtil.success(cmsContentService.getContentDetail(id, "queryWithPatches")); |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> getContentDetail() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getListContent", method = RequestMethod.GET) |
||||
@ApiOperation(value = "查询内容列表(不包括附件)") |
||||
@ResponseBody |
||||
public ResponseData getListContent(@RequestParam(value = "title", required = false) String title, |
||||
@RequestParam(value = "category", required = false) Long category, |
||||
@RequestParam(value = "categoryCode", required = false) String categoryCode, |
||||
@RequestParam(value = "tag", required = false) String tag, |
||||
@RequestParam(value = "status", required = false) Integer status, |
||||
@RequestParam(value = "companyId", required = false) Long companyId, |
||||
@RequestParam(name = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(name = "pageSize", required = true) Integer pageSize) { |
||||
try { |
||||
Map<String, String> paramsMap = new HashMap<>(); |
||||
if (StringUtils.isNotBlank(title)) { |
||||
paramsMap.put("title", title); |
||||
} |
||||
if (category != null) { |
||||
paramsMap.put("category", category.toString()); |
||||
} |
||||
if (categoryCode != null) { |
||||
paramsMap.put("categoryCode", categoryCode); |
||||
} |
||||
if (StringUtils.isNotBlank(tag)) { |
||||
paramsMap.put("tag", tag); |
||||
} |
||||
if (status != null) { |
||||
paramsMap.put("status", status.toString()); |
||||
} |
||||
if (companyId != null) { |
||||
paramsMap.put("companyId", companyId.toString()); |
||||
} |
||||
|
||||
PageHelper.startPage(pageNum, pageSize); |
||||
return ResponseMsgUtil.success(new PageInfo<>(cmsContentService.getListContent(paramsMap))); |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> getListContent() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/updateStatusOfContent", method = RequestMethod.POST) |
||||
@ApiOperation(value = "更新 内容发布状态") |
||||
@ResponseBody |
||||
public ResponseData updateStatusOfContent(@RequestBody JSONObject jsonObject) { |
||||
try { |
||||
Long id = jsonObject.getLong("id"); |
||||
Integer status = jsonObject.getInteger("status"); |
||||
Long moduleId = jsonObject.getLong("moduleId"); |
||||
|
||||
if (id == null |
||||
|| status == null |
||||
|| (status != 1 && status != 2 && status != 3) |
||||
) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
CmsContent content = cmsContentService.getContentById(id); |
||||
if (content == null || content.getStatus() == 0) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.CMS_CONTENT_NOT_FOUND, ""); |
||||
} |
||||
|
||||
Map<String, String> paramsMap = new HashMap<>(); |
||||
if (moduleId != null) { |
||||
paramsMap.put("moduleId", moduleId.toString()); |
||||
} |
||||
|
||||
content.setStatus(status); |
||||
if (cmsContentService.updateContent(content, "updateStatusOfContent", paramsMap,sysConfig.getFileUrl()) > 0) { |
||||
return ResponseMsgUtil.success("修改成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.UPDATE_DATA_ERROR, ""); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> updateStatusOfContent() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/updateContentQuantity", method = RequestMethod.GET) |
||||
@ApiOperation(value = "内容访问量+1") |
||||
@ResponseBody |
||||
public ResponseData updateContentQuantity(@RequestParam(value = "id", required = true) Long id) { |
||||
try { |
||||
CmsContent content = cmsContentService.getContentById(id); |
||||
if (content == null || content.getStatus() == 0) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.CMS_CONTENT_NOT_FOUND, ""); |
||||
} |
||||
|
||||
if (content.getVisitCount() != null) { |
||||
content.setVisitCount(content.getVisitCount() + 1); |
||||
} else { |
||||
content.setVisitCount(1); |
||||
} |
||||
if (cmsContentService.updateContent(content, "updateContent", null,null) > 0) { |
||||
return ResponseMsgUtil.success("修改成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.UPDATE_DATA_ERROR, ""); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> updateContentQuantity() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getListPatches", method = RequestMethod.GET) |
||||
@ApiOperation(value = "查询内容附件列表") |
||||
@ResponseBody |
||||
public ResponseData getListPatches(@RequestParam(value = "contentId", required = true) Long contentId, |
||||
@RequestParam(value = "patchType", required = false) Integer patchType, |
||||
@RequestParam(name = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(name = "pageSize", required = true) Integer pageSize) { |
||||
try { |
||||
Map<String, String> paramsMap = new HashMap<>(); |
||||
if (contentId != null) { |
||||
paramsMap.put("contentId", contentId.toString()); |
||||
} |
||||
if (patchType != null) { |
||||
paramsMap.put("patchType", patchType.toString()); |
||||
} |
||||
|
||||
PageHelper.startPage(pageNum, pageSize); |
||||
return ResponseMsgUtil.success(new PageInfo<>(cmsPatchService.getListPatch(paramsMap))); |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> getListContent() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getCompleteContentList", method = RequestMethod.GET) |
||||
@ApiOperation(value = "查询内容列表(包括附件)") |
||||
@ResponseBody |
||||
public ResponseData getCompleteContentList(@RequestParam(value = "title", required = false) String title, |
||||
@RequestParam(value = "category", required = false) Long category, |
||||
@RequestParam(value = "categoryCode", required = false) String categoryCode, |
||||
@RequestParam(value = "tag", required = false) String tag, |
||||
@RequestParam(value = "status", required = false) Integer status, |
||||
@RequestParam(value = "companyId", required = false) Long companyId, |
||||
@RequestParam(name = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(name = "pageSize", required = true) Integer pageSize) { |
||||
try { |
||||
Map<String, String> paramsMap = new HashMap<>(); |
||||
if (StringUtils.isNotBlank(title)) { |
||||
paramsMap.put("title", title); |
||||
} |
||||
if (category != null) { |
||||
paramsMap.put("category", category.toString()); |
||||
} |
||||
if (categoryCode != null) { |
||||
paramsMap.put("categoryCode", categoryCode); |
||||
} |
||||
if (StringUtils.isNotBlank(tag)) { |
||||
paramsMap.put("tag", tag); |
||||
} |
||||
if (status != null) { |
||||
paramsMap.put("status", status.toString()); |
||||
} |
||||
if (companyId != null) { |
||||
paramsMap.put("companyId", companyId.toString()); |
||||
} |
||||
PageHelper.startPage(pageNum, pageSize); |
||||
List<CmsContentModel> result = cmsContentService.getListContent(paramsMap); |
||||
|
||||
// 查询附件列表
|
||||
Map<String, String> params = new HashMap<>(); |
||||
List<CmsPatch> patchList = cmsPatchService.getListPatch(params); |
||||
// 将附件按类型挂到对应的内容
|
||||
for (CmsContentModel item : result) { |
||||
item.setPictures(new ArrayList<>()); |
||||
item.setMusics(new ArrayList<>()); |
||||
item.setVideos(new ArrayList<>()); |
||||
item.setDocuments(new ArrayList<>()); |
||||
item.setOthers(new ArrayList<>()); |
||||
|
||||
patchList.stream().filter(patch -> item.getId().equals(patch.getContentId())) |
||||
.forEach(patch -> { |
||||
switch (patch.getPatchType()){ |
||||
case 1: |
||||
item.getPictures().add(patch); |
||||
break; |
||||
case 2: |
||||
item.getMusics().add(patch); |
||||
break; |
||||
case 3: |
||||
item.getVideos().add(patch); |
||||
break; |
||||
case 4: |
||||
item.getDocuments().add(patch); |
||||
break; |
||||
case 5: |
||||
item.getOthers().add(patch); |
||||
break; |
||||
} |
||||
}); |
||||
} |
||||
|
||||
return ResponseMsgUtil.success(new PageInfo<>(result)); |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> getListContent() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getCorporateAdvertising", method = RequestMethod.GET) |
||||
@ApiOperation(value = "查询首页轮播图") |
||||
@ResponseBody |
||||
public ResponseData getCorporateAdvertising() { |
||||
try { |
||||
return ResponseMsgUtil.success(cmsContentService.getCorporateAdvertising()); |
||||
} catch (Exception e) { |
||||
log.error("CmsContentController --> getCorporateAdvertising() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,73 @@ |
||||
package com.bweb.controller; |
||||
|
||||
|
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.CmsPatch; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.service.CmsPatchService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.Date; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/cmsPatch") |
||||
@Api(value = "内容管理->附件") |
||||
public class CmsPatchController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(CmsPatchController.class); |
||||
@Resource |
||||
private CmsPatchService cmsPatchService; |
||||
|
||||
@RequestMapping(value = "/addPatch", method = RequestMethod.POST) |
||||
@ApiOperation(value = "添加 附件") |
||||
@ResponseBody |
||||
public ResponseData addPatch(@RequestBody CmsPatch cmsPatch) { |
||||
try { |
||||
if (cmsPatch == null |
||||
|| cmsPatch.getContentId() == null |
||||
|| StringUtils.isBlank(cmsPatch.getPatchName()) |
||||
|| cmsPatch.getPatchType() == null |
||||
|| StringUtils.isBlank(cmsPatch.getPatchPath()) |
||||
) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
cmsPatch.setAddTime(new Date()); |
||||
if (cmsPatchService.addPatch(cmsPatch) > 0) { |
||||
return ResponseMsgUtil.success("添加成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.ADD_DATA_ERROR, ""); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("CmsPatchController --> addPatch() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/delPatch", method = RequestMethod.GET) |
||||
@ApiOperation(value = "删除附件") |
||||
@ResponseBody |
||||
public ResponseData delPatch(@RequestParam(value = "id", required = true) Long id) { |
||||
try { |
||||
if (cmsPatchService.delPatch(id) > 0) { |
||||
return ResponseMsgUtil.success("删除成功"); |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.DELETE_DATA_ERROR, ""); |
||||
} |
||||
} catch (Exception e) { |
||||
log.error("CmsPatchController --> delPatch() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,52 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.service.sec.SecDictionaryService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestMethod; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.annotation.Resource; |
||||
|
||||
@Controller |
||||
@RequestMapping(value="/common") |
||||
@Api(value="共用接口") |
||||
public class CommonController { |
||||
Logger log = LoggerFactory.getLogger(CommonController.class); |
||||
@Resource |
||||
private SecDictionaryService secDictionaryService; |
||||
|
||||
@RequestMapping(value="/queryDictionary",method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询数据字典") |
||||
public ResponseData queryDictionary(@RequestParam(value = "codeType" , required = false) String codeType, |
||||
@RequestParam(value = "codeValue" , required = false) String codeValue) { |
||||
try { |
||||
|
||||
if (StringUtils.isBlank(codeType) && StringUtils.isBlank(codeValue)) { |
||||
return ResponseMsgUtil.success(secDictionaryService.getDictionary()); |
||||
|
||||
} else if (StringUtils.isNotBlank(codeType) && StringUtils.isNotBlank(codeValue)) { |
||||
return ResponseMsgUtil.success(secDictionaryService.getDictionary(codeType, codeValue)); |
||||
|
||||
} else if (StringUtils.isNotBlank(codeType)) { |
||||
return ResponseMsgUtil.success(secDictionaryService.getDictionary(codeType)); |
||||
} |
||||
|
||||
return ResponseMsgUtil.success(null); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,138 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.hfkj.common.utils.DateUtil; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.bweb.config.SysConfig; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.service.FileUploadService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.web.bind.annotation.*; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
import org.springframework.web.multipart.MultipartHttpServletRequest; |
||||
import org.springframework.web.multipart.commons.CommonsMultipartResolver; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.File; |
||||
import java.io.FileOutputStream; |
||||
import java.util.*; |
||||
|
||||
@RestController |
||||
@RequestMapping(value="/fileUpload") |
||||
@Api(value="文件上传") |
||||
public class FileUploadController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(FileUploadController.class); |
||||
|
||||
@Resource |
||||
private SysConfig sysConfig; |
||||
|
||||
@Resource |
||||
private FileUploadService fileUploadService; |
||||
|
||||
@RequestMapping(value="/uploadfile",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "文件上传") |
||||
public ResponseData uploadFile(@RequestParam(value = "files" , required = false) MultipartFile files, |
||||
HttpServletRequest request, |
||||
HttpServletResponse response) throws Exception { |
||||
try { |
||||
response.setHeader("Access-Control-Allow-Origin", "*"); |
||||
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver( |
||||
request.getSession().getServletContext()); |
||||
// 判断 request 是否有文件上传,即多部分请求
|
||||
List<String> fileNames = new ArrayList<String>(); |
||||
if (multipartResolver.isMultipart(request)) { |
||||
// 转换成多部分request
|
||||
MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request; |
||||
Iterator<String> iterator = multiRequest.getFileNames(); |
||||
|
||||
while (iterator.hasNext()) { |
||||
MultipartFile file = multiRequest.getFile(iterator.next()); |
||||
if (file != null) { |
||||
FileOutputStream out = null; |
||||
try { |
||||
String fileType = file.getOriginalFilename() |
||||
.substring(file.getOriginalFilename().lastIndexOf(".") + 1); |
||||
String fileName = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf(".")) + System.currentTimeMillis() + "." + fileType; |
||||
String childPath = DateUtil.date2String(new Date(), "yyyyMM"); |
||||
String destDirName = sysConfig.getFileUrl() + File.separator + childPath; |
||||
File dir = new File(destDirName); |
||||
if (!dir.exists()) { |
||||
dir.mkdirs(); |
||||
} |
||||
out = new FileOutputStream(destDirName + File.separator + fileName); |
||||
out.write(file.getBytes()); |
||||
out.flush(); |
||||
fileNames.add(childPath + "/" + fileName); |
||||
} catch (Exception e) { |
||||
log.error(e.getMessage(), e); |
||||
} finally { |
||||
if (out != null) { |
||||
out.close(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
return ResponseMsgUtil.success(fileNames); |
||||
|
||||
} catch (Exception e) { |
||||
log.error(e.getMessage(), e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
|
||||
} |
||||
|
||||
@RequestMapping(value = "/fileUpload", method = RequestMethod.POST) |
||||
@ApiOperation(value = "上传文件(新接口)") |
||||
@ResponseBody |
||||
public ResponseData fileUpload(@RequestParam(name = "requestFile") MultipartFile requestFile, |
||||
@RequestParam(value = "uploadType", required = true) String uploadType, |
||||
HttpServletRequest request |
||||
) { |
||||
try { |
||||
CommonsMultipartResolver multipartResolver = |
||||
new CommonsMultipartResolver(request.getSession().getServletContext()); |
||||
|
||||
// 提取文件列表
|
||||
List<MultipartFile> files = new ArrayList<>(); |
||||
if (multipartResolver.isMultipart(request)) { |
||||
MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request; |
||||
Iterator<String> iterator = multiRequest.getFileNames(); |
||||
|
||||
while (iterator.hasNext()) { |
||||
MultipartFile file = multiRequest.getFile(iterator.next()); |
||||
files.add(file); |
||||
} |
||||
} |
||||
|
||||
// 定制参数
|
||||
Map<String, String> paramsMap = new HashMap<>(); |
||||
if ("cmsModule".equals(uploadType)) { |
||||
paramsMap.put("pathPrefix", sysConfig.getFileUrl()); |
||||
paramsMap.put("childPath", "/CMS/module/"); |
||||
paramsMap.put("fileNameGenerator", "generateFileNameAndTimeStamp"); |
||||
} else if ("cmsPatch".equals(uploadType)) { |
||||
paramsMap.put("pathPrefix", sysConfig.getFileUrl()); |
||||
paramsMap.put("childPath", "/CMS/html/"); |
||||
paramsMap.put("fileNameGenerator", "generateFileNameAndTimeStamp"); |
||||
} else if ("cmsImg".equals(uploadType)) { |
||||
paramsMap.put("pathPrefix", sysConfig.getFileUrl()); |
||||
paramsMap.put("childPath", "/CMS/img/"); |
||||
paramsMap.put("fileNameGenerator", "generateFileNameAndTimeStamp"); |
||||
} |
||||
|
||||
return ResponseMsgUtil.success(fileUploadService.upload(files, paramsMap)); |
||||
} catch (Exception e) { |
||||
log.error("FileUploadController --> addCategoryModule() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,98 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.security.*; |
||||
import com.hfkj.common.utils.MD5Util; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.*; |
||||
import com.hfkj.model.MenuTreeModel; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.model.SecUserSessionObject; |
||||
import com.hfkj.model.UserInfoModel; |
||||
import com.hfkj.service.*; |
||||
import com.hfkj.service.sec.SecUserService; |
||||
import com.hfkj.sysenum.SecUserObjectTypeEnum; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestMethod; |
||||
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.List; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/login") |
||||
@Api(value = "登录") |
||||
public class LoginController { |
||||
|
||||
Logger log = LoggerFactory.getLogger(SecUserController.class); |
||||
@Resource |
||||
private SecUserService secUserService; |
||||
|
||||
@Resource |
||||
private UserCenter userCenter; |
||||
|
||||
@RequestMapping(value="/login",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "登录") |
||||
public ResponseData login(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body == null |
||||
|| StringUtils.isBlank(body.getString("loginName")) |
||||
|| StringUtils.isBlank(body.getString("password")) |
||||
) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
return ResponseMsgUtil.success(secUserService.login(body.getString("loginName"), body.getString("password"))); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/queryUser",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询账户") |
||||
public ResponseData queryUser() { |
||||
try { |
||||
|
||||
return ResponseMsgUtil.success(userCenter.getSessionModel(SecUserSessionObject.class)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/loginOut",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "退出登录") |
||||
public ResponseData loginOut(HttpServletRequest request) { |
||||
try { |
||||
try { |
||||
SecUserSessionObject session = userCenter.getSessionModel(SecUserSessionObject.class); |
||||
if (session != null) { |
||||
userCenter.remove(request); |
||||
} |
||||
} catch (Exception e) {} |
||||
return ResponseMsgUtil.success("退出成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,295 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.SecMenu; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.service.SecMenuService; |
||||
import com.hfkj.service.SecRoleMenuRelService; |
||||
import com.hfkj.sysenum.SecMenuTypeEnum; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.*; |
||||
import java.util.function.Function; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* @className: SecMenu |
||||
* @author: HuRui |
||||
* @date: 2024/3/28 |
||||
**/ |
||||
@Controller |
||||
@RequestMapping(value="/secMenu") |
||||
@Api(value="系统菜单管理") |
||||
public class SecMenuController { |
||||
|
||||
Logger log = LoggerFactory.getLogger(SecUserController.class); |
||||
|
||||
@Resource |
||||
private SecMenuService secMenuService; |
||||
@Resource |
||||
private SecRoleMenuRelService secRoleMenuRelService; |
||||
|
||||
@RequestMapping(value="/editMenu",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "编辑菜单") |
||||
public ResponseData editMenu(@RequestBody SecMenu body) { |
||||
try { |
||||
if (body == null |
||||
|| body.getMenuType() == null |
||||
|| StringUtils.isBlank(body.getMenuName()) |
||||
|| StringUtils.isBlank(body.getMenuUrl()) |
||||
|| body.getMenuSort() == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
SecMenu secMenu; |
||||
|
||||
if (body.getId() != null) { |
||||
// 查询菜单
|
||||
secMenu = secMenuService.queryDetail(body.getId()); |
||||
if (secMenu == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
} else { |
||||
secMenu = new SecMenu(); |
||||
} |
||||
if (secMenu.getMenuPSid() != null) { |
||||
// 查询父类菜单
|
||||
SecMenu parentMenu = secMenuService.queryDetail(secMenu.getMenuPSid()); |
||||
if (parentMenu == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
} |
||||
|
||||
secMenu.setMenuType(body.getMenuType()); |
||||
secMenu.setMenuName(body.getMenuName()); |
||||
secMenu.setMenuUrl(body.getMenuUrl()); |
||||
secMenu.setMenuUrlImg(body.getMenuUrlImg()); |
||||
secMenu.setMenuPSid(body.getMenuPSid()); |
||||
secMenu.setMenuSort(body.getMenuSort()); |
||||
secMenu.setMenuDesc(body.getMenuDesc()); |
||||
if (secMenu.getId() == null) { |
||||
secMenuService.create(secMenu); |
||||
} else { |
||||
secMenuService.update(secMenu); |
||||
} |
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/queryDetail",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询详情") |
||||
public ResponseData queryDetail(@RequestParam(value = "menuId" , required = true) Long menuId) { |
||||
try { |
||||
|
||||
return ResponseMsgUtil.success(secMenuService.queryDetail(menuId)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/delMenu",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "删除菜单") |
||||
public ResponseData delMenu(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body == null || body.getLong("menuId") == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
secMenuService.delete(body.getLong("menuId")); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/assignMenu",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "分配菜单") |
||||
public ResponseData assignMenu(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body == null |
||||
|| body.getLong("roleId") == null |
||||
|| body.getJSONArray("menuIds").isEmpty()) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
List<Long> list = body.getJSONArray("menuIds") |
||||
.stream().map(o -> Long.parseLong(o.toString())) |
||||
.collect(Collectors.toList()); |
||||
|
||||
secMenuService.assignMenu(body.getLong("roleId"),list ); |
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/queryMenuList",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询菜单列表") |
||||
public ResponseData queryMenuList() { |
||||
try { |
||||
|
||||
return ResponseMsgUtil.success(secMenuService.getAllList()); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/queryRoleMenuArray",method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询分配菜单树") |
||||
public ResponseData queryRoleMenuArray(@RequestParam(value = "roleId" , required = true) Long roleId) { |
||||
try { |
||||
|
||||
// 查询角色菜单权限
|
||||
Map<Long, SecMenu> roleMenu = secMenuService.queryRoleMenu(roleId, SecMenuTypeEnum.type1).stream() |
||||
.collect(Collectors.toMap(SecMenu::getId, Function.identity())); |
||||
|
||||
// 系统菜单叶节点
|
||||
List<String> menuLeafList = new ArrayList<>(); |
||||
|
||||
// 角色菜单叶节点
|
||||
List<String> roleLeafList = new ArrayList<>(); |
||||
|
||||
// 获取全部菜单
|
||||
List<SecMenu> menuList = secMenuService.getAllList(); |
||||
|
||||
// 获取最顶层菜单
|
||||
List<SecMenu> topLevelMenuList = menuList.stream() |
||||
.filter(o -> o.getMenuPSid() == null) |
||||
.sorted(Comparator.comparing(SecMenu::getMenuSort)) |
||||
.collect(Collectors.toList()); |
||||
// 递归获取系统菜单叶子节点
|
||||
for (SecMenu topLevelMenu : topLevelMenuList) { |
||||
if (topLevelMenu.getMenuType().equals(SecMenuTypeEnum.type1.getCode())) { |
||||
recursionMenu(menuList, topLevelMenu.getId(), menuLeafList); |
||||
} |
||||
} |
||||
|
||||
// 筛选角色菜单叶节点
|
||||
for (String leaf : menuLeafList) { |
||||
SecMenu menu = roleMenu.get(Long.parseLong(leaf)); |
||||
if (menu != null) { |
||||
roleLeafList.add(""+menu.getId()); |
||||
} |
||||
} |
||||
|
||||
return ResponseMsgUtil.success(roleLeafList); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/queryRoleMenuTree",method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询角色菜单树") |
||||
public ResponseData queryRoleMenuTree(@RequestParam(value = "roleId" , required = false) Long roleId) { |
||||
try { |
||||
|
||||
return ResponseMsgUtil.success(secMenuService.queryMenuTree(roleId)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/queryMenuTree",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询角色菜单树") |
||||
public ResponseData queryMenuTree() { |
||||
try { |
||||
List<Map<String,Object>> mapList = new ArrayList<>(); |
||||
Map<String,Object> map; |
||||
|
||||
// 获取全部菜单
|
||||
List<SecMenu> menuList = secMenuService.getAllList(); |
||||
|
||||
// 获取最顶层菜单
|
||||
List<SecMenu> topLevelMenuList = menuList.stream() |
||||
.filter(o -> o.getMenuPSid() == null) |
||||
.sorted(Comparator.comparing(SecMenu::getMenuSort)) |
||||
.collect(Collectors.toList()); |
||||
|
||||
for (SecMenu topLevelMenu : topLevelMenuList) { |
||||
if (topLevelMenu.getMenuType().equals(SecMenuTypeEnum.type1.getCode())) { |
||||
map = new LinkedHashMap<>(); |
||||
map.put("key", ""+topLevelMenu.getId()); |
||||
map.put("title", topLevelMenu.getMenuName()); |
||||
// 获取下级菜单
|
||||
map.put("children", recursionMenu(menuList, topLevelMenu.getId(), new ArrayList<>())); |
||||
mapList.add(map); |
||||
} |
||||
} |
||||
|
||||
return ResponseMsgUtil.success(mapList); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 递归获取菜单 |
||||
* @param dataSource 数据源 |
||||
* @param parentMenuId 父级菜单id |
||||
* @return |
||||
*/ |
||||
public List<Map<String,Object>> recursionMenu(List<SecMenu> dataSource, Long parentMenuId, List<String> leaf) { |
||||
List<Map<String,Object>> mapList = new ArrayList<>(); |
||||
Map<String,Object> map; |
||||
|
||||
List<SecMenu> collect = dataSource.stream() |
||||
.filter(o -> o.getMenuPSid() != null && o.getMenuPSid().equals(parentMenuId)) |
||||
.sorted(Comparator.comparing(SecMenu::getMenuSort)) |
||||
.collect(Collectors.toList()); |
||||
for (SecMenu menu : collect) { |
||||
if (menu.getMenuType().equals(SecMenuTypeEnum.type1.getCode())) { |
||||
map = new LinkedHashMap<>(); |
||||
map.put("key", ""+menu.getId()); |
||||
map.put("title", menu.getMenuName()); |
||||
// 获取下级菜单
|
||||
List<Map<String, Object>> recursioned = recursionMenu(dataSource, menu.getId(), leaf); |
||||
if (recursioned.isEmpty()) { |
||||
leaf.add(""+menu.getId()); |
||||
map.put("isLeaf", true); |
||||
} else { |
||||
map.put("children", recursioned); |
||||
} |
||||
mapList.add(map); |
||||
} |
||||
} |
||||
return mapList; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,139 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.SecRole; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.service.SecRoleService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @className: SecRoleController |
||||
* @author: HuRui |
||||
* @date: 2024/3/27 |
||||
**/ |
||||
@Controller |
||||
@RequestMapping(value="/secRole") |
||||
@Api(value="系统用户角色管理") |
||||
public class SecRoleController { |
||||
|
||||
Logger log = LoggerFactory.getLogger(SecUserController.class); |
||||
|
||||
@Resource |
||||
private SecRoleService secRoleService; |
||||
|
||||
@RequestMapping(value="/editRole",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "编辑角色") |
||||
public ResponseData editRole(@RequestBody SecRole body) { |
||||
try { |
||||
if (body == null || StringUtils.isBlank(body.getRoleName())) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
SecRole secRole; |
||||
if (body.getId() != null) { |
||||
// 查询角色
|
||||
secRole = secRoleService.getDetail(body.getId()); |
||||
if (secRole == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
} else { |
||||
secRole = new SecRole(); |
||||
secRole.setStatus(1); |
||||
} |
||||
secRole.setRoleName(body.getRoleName()); |
||||
secRole.setRoleDesc(body.getRoleDesc()); |
||||
secRoleService.editData(secRole); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/delRole",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "删除角色") |
||||
public ResponseData delRole(@RequestBody SecRole body) { |
||||
try { |
||||
if (body == null || body.getId() == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
secRoleService.delete(body.getId()); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/queryDetail",method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询详情") |
||||
public ResponseData queryDetail(@RequestParam(value = "roleId" , required = true) Long roleId) { |
||||
try { |
||||
|
||||
secRoleService.delete(roleId); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/queryList",method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询列表") |
||||
public ResponseData queryList(@RequestParam(value = "roleName" , required = false) String roleName, |
||||
@RequestParam(value = "pageNum" , required = true) Integer pageNum, |
||||
@RequestParam(value = "pageSize" , required = true) Integer pageSize) { |
||||
try { |
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("roleName", roleName); |
||||
|
||||
PageHelper.startPage(pageNum, pageSize); |
||||
return ResponseMsgUtil.success(new PageInfo<>(secRoleService.getList(param))); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/queryAllRole",method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询全部角色") |
||||
public ResponseData queryAllRole() { |
||||
try { |
||||
|
||||
return ResponseMsgUtil.success(secRoleService.getList(new HashMap<>())); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,251 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.utils.MD5Util; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.SecUser; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.service.sec.SecUserLoginLogService; |
||||
import com.hfkj.service.sec.SecUserService; |
||||
import com.hfkj.sysenum.SecUserObjectTypeEnum; |
||||
import com.hfkj.sysenum.SecUserStatusEnum; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
@Controller |
||||
@RequestMapping(value="/secUser") |
||||
@Api(value="系统用户管理") |
||||
public class SecUserController { |
||||
Logger log = LoggerFactory.getLogger(SecUserController.class); |
||||
|
||||
@Resource |
||||
private SecUserService secUserService; |
||||
@Resource |
||||
private SecUserLoginLogService secUserLoginLogService; |
||||
|
||||
@RequestMapping(value="/editUser",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "编辑用户") |
||||
public ResponseData editUser(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body == null |
||||
|| StringUtils.isBlank(body.getString("userName")) |
||||
|| StringUtils.isBlank(body.getString("loginName")) |
||||
|| body.getLong("roleId") == null |
||||
) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
SecUser secUser; |
||||
if (body.getLong("id") != null) { |
||||
// 查询账户
|
||||
secUser = secUserService.getDetail(body.getLong("id")); |
||||
// 校验重复登录账户
|
||||
SecUser user = secUserService.getDetailByLoginName(body.getString("loginName")); |
||||
if (user != null && !user.getId().equals(body.getLong("id"))) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "登录账户已存在"); |
||||
} |
||||
} else { |
||||
secUser = new SecUser(); |
||||
secUser.setPassword(MD5Util.encode("123456".getBytes())); |
||||
secUser.setObjectType(SecUserObjectTypeEnum.type1.getCode()); |
||||
secUser.setStatus(SecUserStatusEnum.status1.getCode()); |
||||
|
||||
// 校验重复登录账户
|
||||
if (secUserService.getDetailByLoginName(body.getString("loginName")) != null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "登录账户已存在"); |
||||
} |
||||
} |
||||
|
||||
secUser.setUserName(body.getString("userName")); |
||||
secUser.setLoginName(body.getString("loginName")); |
||||
secUser.setTelephone(body.getString("telephone")); |
||||
secUser.setRoleId(body.getLong("roleId")); |
||||
secUserService.editUser(secUser); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/delete",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "删除用户") |
||||
public ResponseData delete(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body == null || body.getLong("userId") == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
// 查询用户详情
|
||||
SecUser secUser = secUserService.getDetail(body.getLong("userId")); |
||||
if (secUser == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
secUser.setStatus(SecUserStatusEnum.status0.getCode()); |
||||
secUserService.editUser(secUser); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/restore",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "恢复") |
||||
public ResponseData restore(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body == null || body.getLong("userId") == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
// 查询用户详情
|
||||
SecUser secUser = secUserService.getDetail(body.getLong("userId")); |
||||
if (secUser == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
secUser.setStatus(SecUserStatusEnum.status1.getCode()); |
||||
secUserService.editUser(secUser); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/resetPwd",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "账户密码重置") |
||||
public ResponseData resetPwd(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body == null || body.getLong("userId") == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
secUserService.resetPwd(body.getLong("userId")); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
|
||||
@RequestMapping(value="/disable",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "禁用") |
||||
public ResponseData disable(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body == null || body.getLong("userId") == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
// 查询用户详情
|
||||
SecUser secUser = secUserService.getDetail(body.getLong("userId")); |
||||
if (secUser == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
secUser.setStatus(SecUserStatusEnum.status2.getCode()); |
||||
secUserService.editUser(secUser); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/queryDetail",method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询详情") |
||||
public ResponseData queryDetail(@RequestParam(value = "userId" , required = true) Long userId) { |
||||
try { |
||||
// 查询详情
|
||||
SecUser secUser = secUserService.getDetail(userId); |
||||
if (secUser != null) { |
||||
secUser.setPassword(null); |
||||
} |
||||
return ResponseMsgUtil.success(secUser); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/queryList",method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询列表") |
||||
public ResponseData queryList(@RequestParam(value = "userName", required = false) String userName, |
||||
@RequestParam(value = "loginName", required = false) String loginName, |
||||
@RequestParam(value = "telephone", required = false) String telephone, |
||||
@RequestParam(value = "objectType", required = false) Integer objectType, |
||||
@RequestParam(value = "status", required = false) Integer status, |
||||
@RequestParam(value = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(value = "pageSize", required = true) Integer pageSize) { |
||||
try { |
||||
|
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("userName", userName); |
||||
param.put("loginName", loginName); |
||||
param.put("telephone", telephone); |
||||
param.put("objectType", objectType); |
||||
param.put("status", status); |
||||
|
||||
PageHelper.startPage(pageNum, pageSize); |
||||
return ResponseMsgUtil.success(new PageInfo<>(secUserService.getList(param))); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
|
||||
@RequestMapping(value="/queryLoginLogList",method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询登录日志列表") |
||||
public ResponseData queryLoginLogList(@RequestParam(value = "userId", required = true) String userId, |
||||
@RequestParam(value = "status", required = false) Integer status, |
||||
@RequestParam(value = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(value = "pageSize", required = true) Integer pageSize) { |
||||
try { |
||||
|
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("userId", userId); |
||||
param.put("status", status); |
||||
|
||||
PageHelper.startPage(pageNum, pageSize); |
||||
return ResponseMsgUtil.success(secUserLoginLogService.getLogList(param)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,80 @@ |
||||
server: |
||||
port: 9802 |
||||
servlet: |
||||
context-path: /brest |
||||
|
||||
#配置是否为debug模式,debug模式下,不开启权限校验 |
||||
debug: false |
||||
|
||||
#datasource数据源设置 |
||||
spring: |
||||
datasource: |
||||
url: jdbc:mysql://139.9.154.68:3306/hai_oil?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false |
||||
username: root |
||||
password: HF123456. |
||||
type: com.alibaba.druid.pool.DruidDataSource |
||||
driver-class-name: com.mysql.jdbc.Driver |
||||
filters: stat |
||||
maxActive: 10 |
||||
initialSize: 5 |
||||
maxWait: 60000 |
||||
minIdle: 5 |
||||
timeBetweenEvictionRunsMillis: 60000 |
||||
minEvictableIdleTimeMillis: 300000 |
||||
validationQuery: select 'x' |
||||
testWhileIdle: true |
||||
testOnBorrow: false |
||||
testOnReturn: false |
||||
poolPreparedStatements: true |
||||
maxOpenPreparedStatements: 20 |
||||
redis: |
||||
database: 0 |
||||
host: 139.9.154.68 |
||||
port: 36379 |
||||
password: HF123456.Redis |
||||
timeout: 1000 |
||||
jedis: |
||||
pool: |
||||
max-active: 20 |
||||
max-wait: -1 |
||||
max-idle: 10 |
||||
min-idle: 0 |
||||
#配置日期返回至前台为时间戳 |
||||
jackson: |
||||
serialization: |
||||
write-dates-as-timestamps: true |
||||
|
||||
jetcache: |
||||
statIntervalMinutes: 15 |
||||
areaInCacheName: false |
||||
local: |
||||
default: |
||||
type: linkedhashmap |
||||
keyConvertor: fastjson |
||||
remote: |
||||
default: |
||||
type: redis |
||||
host: 139.9.154.68 |
||||
port: 36379 |
||||
password: HF123456.Redis |
||||
database: 0 |
||||
keyConvertor: fastjson |
||||
broadcastChannel: projectA |
||||
valueEncoder: java |
||||
valueDecoder: java |
||||
poolConfig: |
||||
minIdle: 5 |
||||
maxIdle: 20 |
||||
maxTotal: 50 |
||||
|
||||
mybatis: |
||||
mapperLocations: |
||||
- classpath*:sqlmap*/*.xml |
||||
type-aliases-package: |
||||
org.springboot.sample.entity |
||||
|
||||
pagehelper: |
||||
helperDialect: mysql |
||||
reasonable: true |
||||
supportMethodsArguments: true |
||||
params: count=countSql |
@ -0,0 +1,2 @@ |
||||
fileUrl=/home/project/oil/filesystem |
||||
cmsPath=/home/project/oil/filesystem/cmsPath |
@ -0,0 +1,72 @@ |
||||
<configuration> |
||||
<!-- %m输出的信息,%p日志级别,%t线程名,%d日期,%c类的全名,,,, --> |
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
||||
<encoder> |
||||
<pattern>%d %p (%file:%line\)- %m%n</pattern> |
||||
<charset>UTF-8</charset> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="baselog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/base.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/base.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="daolog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/dao.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/dao.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="errorlog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/error.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/error.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<root level="DEBUG"> |
||||
<appender-ref ref="STDOUT" /> |
||||
</root> |
||||
<logger name="com.hfkj" level="DEBUG"> |
||||
<appender-ref ref="baselog" /> |
||||
</logger> |
||||
<logger name="com.hfkj.dao" level="DEBUG"> |
||||
<appender-ref ref="daolog" /> |
||||
</logger> |
||||
<logger name="com.hfkj" level="ERROR"> |
||||
<appender-ref ref="errorlog" /> |
||||
</logger> |
||||
</configuration> |
@ -0,0 +1,56 @@ |
||||
server: |
||||
port: 9302 |
||||
servlet: |
||||
context-path: /brest |
||||
|
||||
#配置是否为debug模式,debug模式下,不开启权限校验 |
||||
debug: false |
||||
|
||||
#datasource数据源设置 |
||||
spring: |
||||
datasource: |
||||
url: jdbc:mysql://139.159.177.244:3306/hsg_pre?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false |
||||
username: root |
||||
password: HF123456. |
||||
type: com.alibaba.druid.pool.DruidDataSource |
||||
driver-class-name: com.mysql.jdbc.Driver |
||||
filters: stat |
||||
maxActive: 10 |
||||
initialSize: 5 |
||||
maxWait: 60000 |
||||
minIdle: 5 |
||||
timeBetweenEvictionRunsMillis: 60000 |
||||
minEvictableIdleTimeMillis: 300000 |
||||
validationQuery: select 'x' |
||||
testWhileIdle: true |
||||
testOnBorrow: false |
||||
testOnReturn: false |
||||
poolPreparedStatements: true |
||||
maxOpenPreparedStatements: 20 |
||||
redis: |
||||
database: 1 |
||||
host: 139.159.177.244 |
||||
port: 36379 |
||||
password: HF123456.Redis |
||||
timeout: 1000 |
||||
jedis: |
||||
pool: |
||||
max-active: 20 |
||||
max-wait: -1 |
||||
max-idle: 10 |
||||
min-idle: 0 |
||||
#配置日期返回至前台为时间戳 |
||||
jackson: |
||||
serialization: |
||||
write-dates-as-timestamps: true |
||||
mybatis: |
||||
mapperLocations: |
||||
- classpath*:sqlmap*/*.xml |
||||
type-aliases-package: |
||||
org.springboot.sample.entity |
||||
|
||||
pagehelper: |
||||
helperDialect: mysql |
||||
reasonable: true |
||||
supportMethodsArguments: true |
||||
params: count=countSql |
@ -0,0 +1,2 @@ |
||||
fileUrl=/home/project/hsg/filesystem |
||||
cmsPath=/home/project/hsg/filesystem/cmsPath |
@ -0,0 +1,72 @@ |
||||
<configuration> |
||||
<!-- %m输出的信息,%p日志级别,%t线程名,%d日期,%c类的全名,,,, --> |
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
||||
<encoder> |
||||
<pattern>%d %p (%file:%line\)- %m%n</pattern> |
||||
<charset>UTF-8</charset> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="baselog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/base.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/base.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="daolog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/dao.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/dao.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="errorlog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/error.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/error.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<root level="DEBUG"> |
||||
<appender-ref ref="STDOUT" /> |
||||
</root> |
||||
<logger name="com.hfkj" level="DEBUG"> |
||||
<appender-ref ref="baselog" /> |
||||
</logger> |
||||
<logger name="com.hfkj.dao" level="DEBUG"> |
||||
<appender-ref ref="daolog" /> |
||||
</logger> |
||||
<logger name="com.hfkj" level="ERROR"> |
||||
<appender-ref ref="errorlog" /> |
||||
</logger> |
||||
</configuration> |
@ -0,0 +1,57 @@ |
||||
server: |
||||
port: 9302 |
||||
servlet: |
||||
context-path: /brest |
||||
|
||||
#配置是否为debug模式,debug模式下,不开启权限校验 |
||||
debug: false |
||||
|
||||
#datasource数据源设置 |
||||
spring: |
||||
datasource: |
||||
url: jdbc:mysql://127.0.0.1:3306/hsg?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8 |
||||
username: root |
||||
password: HF123456. |
||||
type: com.alibaba.druid.pool.DruidDataSource |
||||
driver-class-name: com.mysql.jdbc.Driver |
||||
filters: stat |
||||
maxActive: 10 |
||||
initialSize: 5 |
||||
maxWait: 60000 |
||||
minIdle: 5 |
||||
timeBetweenEvictionRunsMillis: 60000 |
||||
minEvictableIdleTimeMillis: 300000 |
||||
validationQuery: select 'x' |
||||
testWhileIdle: true |
||||
testOnBorrow: false |
||||
testOnReturn: false |
||||
poolPreparedStatements: true |
||||
maxOpenPreparedStatements: 20 |
||||
redis: |
||||
database: 0 |
||||
host: 127.0.0.1 |
||||
port: 36379 |
||||
password: HF123456.Redis |
||||
timeout: 1000 |
||||
jedis: |
||||
pool: |
||||
max-active: 20 |
||||
max-wait: -1 |
||||
max-idle: 10 |
||||
min-idle: 0 |
||||
#配置日期返回至前台为时间戳 |
||||
jackson: |
||||
serialization: |
||||
write-dates-as-timestamps: true |
||||
|
||||
mybatis: |
||||
mapperLocations: |
||||
- classpath*:sqlmap*/*.xml |
||||
type-aliases-package: |
||||
org.springboot.sample.entity |
||||
|
||||
pagehelper: |
||||
helperDialect: mysql |
||||
reasonable: true |
||||
supportMethodsArguments: true |
||||
params: count=countSql |
@ -0,0 +1,2 @@ |
||||
fileUrl=/home/project/hsg/filesystem |
||||
cmsPath=/home/project/hsg/filesystem/cmsPath |
@ -0,0 +1,72 @@ |
||||
<configuration> |
||||
<!-- %m输出的信息,%p日志级别,%t线程名,%d日期,%c类的全名,,,, --> |
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
||||
<encoder> |
||||
<pattern>%d %p (%file:%line\)- %m%n</pattern> |
||||
<charset>UTF-8</charset> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="baselog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/base.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/base.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="daolog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/dao.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/dao.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="errorlog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/error.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/error.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<root level="DEBUG"> |
||||
<appender-ref ref="STDOUT" /> |
||||
</root> |
||||
<logger name="com.hfkj" level="DEBUG"> |
||||
<appender-ref ref="baselog" /> |
||||
</logger> |
||||
<logger name="com.hfkj.dao" level="DEBUG"> |
||||
<appender-ref ref="daolog" /> |
||||
</logger> |
||||
<logger name="com.hfkj" level="ERROR"> |
||||
<appender-ref ref="errorlog" /> |
||||
</logger> |
||||
</configuration> |
@ -0,0 +1,34 @@ |
||||
package common; |
||||
|
||||
import com.alibaba.excel.context.AnalysisContext; |
||||
import com.alibaba.excel.event.AnalysisEventListener; |
||||
import com.alibaba.fastjson.JSON; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @Auther: 胡锐 |
||||
* @Description: |
||||
* @Date: 2021/3/20 20:51 |
||||
*/ |
||||
public class DemoDataListener extends AnalysisEventListener<ExcelModel> { |
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(DemoDataListener.class); |
||||
|
||||
List<ExcelModel> list = new ArrayList<>(); |
||||
|
||||
@Override |
||||
public void invoke(ExcelModel excelModel, AnalysisContext analysisContext) { |
||||
System.out.println(JSON.toJSONString(excelModel)); |
||||
list.add(excelModel); |
||||
} |
||||
|
||||
@Override |
||||
public void doAfterAllAnalysed(AnalysisContext analysisContext) { |
||||
LOGGER.info("所有数据解析完成!"); |
||||
System.out.println("所有数据解析完成"); |
||||
} |
||||
} |
@ -0,0 +1,22 @@ |
||||
package common; |
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty; |
||||
|
||||
/** |
||||
* @Auther: 胡锐 |
||||
* @Description: |
||||
* @Date: 2021/3/20 20:26 |
||||
*/ |
||||
public class ExcelModel { |
||||
|
||||
@ExcelProperty("二维码地址") |
||||
private String codeUrl; |
||||
|
||||
public String getCodeUrl() { |
||||
return codeUrl; |
||||
} |
||||
|
||||
public void setCodeUrl(String codeUrl) { |
||||
this.codeUrl = codeUrl; |
||||
} |
||||
} |
@ -0,0 +1,44 @@ |
||||
package common; |
||||
|
||||
import com.BWebApplication; |
||||
import com.alibaba.excel.EasyExcel; |
||||
import com.alibaba.fastjson.JSON; |
||||
import com.hfkj.entity.SecRegion; |
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
import org.springframework.boot.test.context.SpringBootTest; |
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
||||
import org.springframework.test.context.web.WebAppConfiguration; |
||||
|
||||
import java.io.FileOutputStream; |
||||
import java.io.OutputStreamWriter; |
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Auther: 胡锐 |
||||
* @Description: |
||||
* @Date: 2021/3/20 20:26 |
||||
*/ |
||||
@RunWith(SpringJUnit4ClassRunner.class) |
||||
@SpringBootTest(classes = BWebApplication.class) |
||||
@WebAppConfiguration |
||||
public class ExcelTest { |
||||
|
||||
|
||||
@Test |
||||
public void test(){ |
||||
try { |
||||
|
||||
List<ExcelModel> list = new ArrayList<>(); |
||||
EasyExcel.read("F:\\卡券列表记录.xlsx", ExcelModel.class, new DemoDataListener()).sheet().doRead(); |
||||
|
||||
|
||||
}catch (Exception e){ |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,106 @@ |
||||
package common; |
||||
|
||||
import com.BWebApplication; |
||||
import com.alibaba.excel.EasyExcel; |
||||
import com.alibaba.fastjson.JSON; |
||||
import com.hfkj.common.Base64Util; |
||||
import com.hfkj.common.security.AESEncodeUtil; |
||||
import com.hfkj.entity.HighDiscountAgentCode; |
||||
import com.hfkj.entity.SecRegion; |
||||
import com.hfkj.service.CommonService; |
||||
|
||||
import com.hfkj.service.HighDiscountAgentCodeService; |
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
import org.springframework.boot.test.context.SpringBootTest; |
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
||||
import org.springframework.test.context.web.WebAppConfiguration; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.io.FileOutputStream; |
||||
import java.io.OutputStreamWriter; |
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @ClassName RegionTest |
||||
* @Description: TODO () |
||||
* @Author 胡锐 |
||||
* @Date 2020/12/29 |
||||
**/ |
||||
@RunWith(SpringJUnit4ClassRunner.class) |
||||
@SpringBootTest(classes = BWebApplication.class) |
||||
@WebAppConfiguration |
||||
public class RegionTest { |
||||
|
||||
@Resource |
||||
private CommonService commonService; |
||||
|
||||
@Resource |
||||
private HighDiscountAgentCodeService highDiscountAgentCodeService; |
||||
|
||||
@Test |
||||
public void addLogs(){ |
||||
try { |
||||
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("exampleWrite.json"),"UTF-8"); |
||||
List<Map<String,Object>> jobTypeList = new ArrayList<>(); |
||||
List<Map<String,Object>> children1; |
||||
|
||||
List<SecRegion> parentRegion = commonService.getCities(); |
||||
for (SecRegion parent : parentRegion) { |
||||
Map<String,Object> map = new HashMap<>(); |
||||
map.put("value", parent.getRegionId()); |
||||
map.put("label", parent.getRegionName()); |
||||
|
||||
// 查询二级
|
||||
List<SecRegion> chinRegion = commonService.getRegionsByParentId(parent.getRegionId()); |
||||
children1 = new ArrayList<>(); |
||||
for (SecRegion chin : chinRegion) { |
||||
Map<String,Object> map1 = new HashMap<>(); |
||||
map1.put("value", chin.getRegionId()); |
||||
map1.put("label", chin.getRegionName()); |
||||
children1.add(map1); |
||||
} |
||||
|
||||
map.put("children", children1); |
||||
jobTypeList.add(map); |
||||
} |
||||
|
||||
osw.write(JSON.toJSONString(jobTypeList)); |
||||
osw.flush();//清空缓冲区,强制输出数据
|
||||
osw.close();//关闭输出流
|
||||
}catch (Exception e){ |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void simpleWrite() throws Exception { |
||||
// 写法1
|
||||
String fileName = "D:\\simpleWrite.xlsx"; |
||||
|
||||
|
||||
Map<String,Object> paramMap = new HashMap<>(); |
||||
paramMap.put("discountAgentId", ""); |
||||
List<HighDiscountAgentCode> codeList = highDiscountAgentCodeService.getDiscountCode(paramMap); |
||||
|
||||
List<ExcelModel> list = new ArrayList<>(); |
||||
ExcelModel excelModel; |
||||
|
||||
Map<String,Object> map = new HashMap<>(); |
||||
map.put("type", "DISCOUNT"); |
||||
|
||||
for (HighDiscountAgentCode code : codeList) { |
||||
excelModel = new ExcelModel(); |
||||
map.put("id", code.getId()); |
||||
String param = "https://hsg.dctpay.com/wx/?action=gogogo&id=" + Base64Util.encode(AESEncodeUtil.aesEncrypt(JSON.toJSONString(map))); |
||||
excelModel.setCodeUrl(param); |
||||
list.add(excelModel); |
||||
} |
||||
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
|
||||
// 如果这里想使用03 则 传入excelType参数即可
|
||||
EasyExcel.write(fileName, ExcelModel.class).sheet("模板").doWrite(list); |
||||
} |
||||
} |
@ -0,0 +1,45 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<groupId>com.hfkj</groupId> |
||||
<artifactId>hai-oil-parent</artifactId> |
||||
<version>1.0-SNAPSHOT</version> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<groupId>com.hfkj</groupId> |
||||
<artifactId>oil-cweb</artifactId> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>com.hfkj</groupId> |
||||
<artifactId>service</artifactId> |
||||
<version>PACKT-SNAPSHOT</version> |
||||
</dependency> |
||||
</dependencies> |
||||
|
||||
<build> |
||||
<resources> |
||||
<resource> |
||||
<directory>src/main/resources/${env}</directory> |
||||
<filtering>false</filtering> |
||||
</resource> |
||||
</resources> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-surefire-plugin</artifactId> |
||||
<configuration> |
||||
<skip>true</skip> |
||||
</configuration> |
||||
</plugin> |
||||
<plugin> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-maven-plugin</artifactId> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
|
||||
</project> |
@ -0,0 +1,26 @@ |
||||
package com; |
||||
|
||||
import com.hfkj.common.utils.SpringContextUtil; |
||||
import org.mybatis.spring.annotation.MapperScan; |
||||
import org.springframework.boot.SpringApplication; |
||||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
import org.springframework.boot.web.servlet.ServletComponentScan; |
||||
import org.springframework.context.ApplicationContext; |
||||
import org.springframework.scheduling.annotation.EnableScheduling; |
||||
import org.springframework.transaction.annotation.EnableTransactionManagement; |
||||
|
||||
@SpringBootApplication |
||||
//@ComponentScan
|
||||
@EnableTransactionManagement |
||||
@EnableScheduling |
||||
@ServletComponentScan |
||||
@MapperScan("com.hfkj.dao") |
||||
public class CWebApplication |
||||
{ |
||||
public static void main( String[] args ) |
||||
{ |
||||
ApplicationContext app = SpringApplication.run(CWebApplication.class, args); |
||||
SpringContextUtil.setApplicationContext(app); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,127 @@ |
||||
package com.cweb.config; |
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
import com.fasterxml.jackson.databind.module.SimpleModule; |
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; |
||||
import com.hfkj.common.security.UserCenter; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.http.converter.HttpMessageConverter; |
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; |
||||
import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest; |
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.List; |
||||
|
||||
@Configuration |
||||
public class AuthConfig implements WebMvcConfigurer { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(AuthConfig.class); |
||||
|
||||
@Resource |
||||
private UserCenter userCenter; |
||||
|
||||
/** |
||||
* 获取配置文件debug变量 |
||||
*/ |
||||
@Value("${debug}") |
||||
private boolean debug = false; |
||||
|
||||
/** |
||||
* 解决18位long类型数据转json失去精度问题 |
||||
* @param converters |
||||
*/ |
||||
@Override |
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters){ |
||||
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter(); |
||||
|
||||
ObjectMapper objectMapper = jsonConverter.getObjectMapper(); |
||||
SimpleModule simpleModule = new SimpleModule(); |
||||
simpleModule.addSerializer(Long.class, ToStringSerializer.instance); |
||||
simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); |
||||
objectMapper.registerModule(simpleModule); |
||||
|
||||
converters.add(jsonConverter); |
||||
} |
||||
|
||||
public void addInterceptors(InterceptorRegistry registry) { |
||||
registry.addInterceptor(new HandlerInterceptorAdapter() { |
||||
|
||||
@Override |
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, |
||||
Object handler) throws Exception { |
||||
if(debug){ |
||||
return true; |
||||
} |
||||
String token = request.getHeader("Authorization"); |
||||
if(StringUtils.isNotBlank(token) && userCenter.isLogin(token)){//如果未登录,将无法使用任何接口
|
||||
return true; |
||||
} else if(request instanceof StandardMultipartHttpServletRequest) { |
||||
StandardMultipartHttpServletRequest re = (StandardMultipartHttpServletRequest)request; |
||||
if(userCenter.isLogin(re.getRequest())){ |
||||
return true; |
||||
} else { |
||||
log.error("the user is not logged in,remoteAddr:"+getIpAddress(request)+",requestUrl:"+request.getRequestURL()); |
||||
response.setStatus(401); |
||||
return false; |
||||
} |
||||
} else{ |
||||
log.error("the user is not logged in,remoteAddr:"+getIpAddress(request)+",requestUrl:"+request.getRequestURL()); |
||||
response.setStatus(401); |
||||
return false; |
||||
} |
||||
} |
||||
}) |
||||
.addPathPatterns("/**") |
||||
.excludePathPatterns("/swagger-resources/**") |
||||
.excludePathPatterns("/**/api-docs") |
||||
.excludePathPatterns("/**/springfox-swagger-ui/**") |
||||
.excludePathPatterns("/**/swagger-ui.html") |
||||
.excludePathPatterns("/client/*") |
||||
.excludePathPatterns("/sms/*") |
||||
.excludePathPatterns("/secUser/login") |
||||
.excludePathPatterns("/secUser/loginOut") |
||||
; |
||||
} |
||||
|
||||
public String getIpAddress(HttpServletRequest request) { |
||||
// 获取请求主机IP地址,如果通过代理进来,则透过防火墙获取真实IP地址
|
||||
String ip = request.getHeader("X-Forwarded-For"); |
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { |
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { |
||||
ip = request.getHeader("Proxy-Client-IP"); |
||||
} |
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { |
||||
ip = request.getHeader("WL-Proxy-Client-IP"); |
||||
} |
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { |
||||
ip = request.getHeader("HTTP_CLIENT_IP"); |
||||
} |
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { |
||||
ip = request.getHeader("HTTP_X_FORWARDED_FOR"); |
||||
} |
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { |
||||
ip = request.getRemoteAddr(); |
||||
} |
||||
} else if (ip.length() > 15) { |
||||
String[] ips = ip.split(","); |
||||
for (int index = 0; index < ips.length; index++) { |
||||
String strIp = ips[index]; |
||||
if (!("unknown".equalsIgnoreCase(strIp))) { |
||||
ip = strIp; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
return ip; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,25 @@ |
||||
package com.cweb.config; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.ServletContextEvent; |
||||
import javax.servlet.ServletContextListener; |
||||
import javax.servlet.annotation.WebListener; |
||||
|
||||
@WebListener |
||||
public class ConfigListener implements ServletContextListener { |
||||
|
||||
@Resource |
||||
private SysConfig sysConfig; |
||||
|
||||
@Override |
||||
public void contextInitialized(ServletContextEvent sce) { |
||||
SysConst.setSysConfig(sysConfig); |
||||
} |
||||
|
||||
@Override |
||||
public void contextDestroyed(ServletContextEvent sce) { |
||||
} |
||||
|
||||
} |
@ -0,0 +1,49 @@ |
||||
package com.cweb.config; |
||||
|
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.web.cors.CorsConfiguration; |
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; |
||||
import org.springframework.web.filter.CorsFilter; |
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry; |
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @ClassName CorsConfig |
||||
* @Description: TODO () |
||||
* @Author 胡锐 |
||||
* @Date 2020/12/16 |
||||
**/ |
||||
@Configuration |
||||
public class CorsConfig extends WebMvcConfigurerAdapter { |
||||
@Override |
||||
public void addCorsMappings(CorsRegistry registry) { |
||||
registry.addMapping("/**") |
||||
.allowedOrigins("*") |
||||
.allowCredentials(true) |
||||
.allowedMethods("GET", "POST", "DELETE", "PUT") |
||||
.maxAge(3600); |
||||
} |
||||
private CorsConfiguration buildConfig() { |
||||
CorsConfiguration corsConfiguration = new CorsConfiguration(); |
||||
List<String> list = new ArrayList<>(); |
||||
list.add("*"); |
||||
corsConfiguration.setAllowedOrigins(list); |
||||
/* |
||||
// 请求常用的三种配置,*代表允许所有,当时你也可以自定义属性(比如header只能带什么,只能是post方式等等)
|
||||
*/ |
||||
corsConfiguration.addAllowedOrigin("*"); |
||||
corsConfiguration.addAllowedHeader("*"); |
||||
corsConfiguration.addAllowedMethod("*"); |
||||
return corsConfiguration; |
||||
} |
||||
@Bean |
||||
public CorsFilter corsFilter() { |
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); |
||||
source.registerCorsConfiguration("/**", buildConfig()); |
||||
return new CorsFilter(source); |
||||
} |
||||
} |
@ -0,0 +1,26 @@ |
||||
package com.cweb.config; |
||||
|
||||
import org.springframework.boot.web.servlet.MultipartConfigFactory; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
|
||||
import javax.servlet.MultipartConfigElement; |
||||
|
||||
@Configuration |
||||
public class MultipartConfig { |
||||
|
||||
/** |
||||
* 文件上传配置 |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public MultipartConfigElement multipartConfigElement() { |
||||
MultipartConfigFactory factory = new MultipartConfigFactory(); |
||||
//文件最大
|
||||
factory.setMaxFileSize("300MB"); //KB,MB
|
||||
//设置总上传数据总大小
|
||||
factory.setMaxRequestSize("350MB"); |
||||
return factory.createMultipartConfig(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,110 @@ |
||||
package com.cweb.config; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect; |
||||
import com.fasterxml.jackson.annotation.PropertyAccessor; |
||||
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
import org.springframework.cache.annotation.CachingConfigurerSupport; |
||||
import org.springframework.cache.annotation.EnableCaching; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.data.redis.connection.RedisConnectionFactory; |
||||
import org.springframework.data.redis.core.*; |
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; |
||||
import org.springframework.data.redis.serializer.StringRedisSerializer; |
||||
|
||||
|
||||
@Configuration |
||||
@EnableCaching //开启注解
|
||||
public class RedisConfig extends CachingConfigurerSupport { |
||||
|
||||
/** |
||||
* retemplate相关配置 |
||||
* @param factory |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) { |
||||
|
||||
RedisTemplate<String, Object> template = new RedisTemplate<>(); |
||||
// 配置连接工厂
|
||||
template.setConnectionFactory(factory); |
||||
|
||||
//使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值(默认使用JDK的序列化方式)
|
||||
Jackson2JsonRedisSerializer jacksonSeial = new Jackson2JsonRedisSerializer(Object.class); |
||||
|
||||
ObjectMapper om = new ObjectMapper(); |
||||
// 指定要序列化的域,field,get和set,以及修饰符范围,ANY是都有包括private和public
|
||||
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); |
||||
// 指定序列化输入的类型,类必须是非final修饰的,final修饰的类,比如String,Integer等会跑出异常
|
||||
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); |
||||
jacksonSeial.setObjectMapper(om); |
||||
|
||||
// 值采用json序列化
|
||||
template.setValueSerializer(jacksonSeial); |
||||
//使用StringRedisSerializer来序列化和反序列化redis的key值
|
||||
template.setKeySerializer(new StringRedisSerializer()); |
||||
|
||||
// 设置hash key 和value序列化模式
|
||||
template.setHashKeySerializer(new StringRedisSerializer()); |
||||
template.setHashValueSerializer(jacksonSeial); |
||||
template.afterPropertiesSet(); |
||||
|
||||
return template; |
||||
} |
||||
|
||||
/** |
||||
* 对hash类型的数据操作 |
||||
* |
||||
* @param redisTemplate |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public HashOperations<String, String, Object> hashOperations(RedisTemplate<String, Object> redisTemplate) { |
||||
return redisTemplate.opsForHash(); |
||||
} |
||||
|
||||
/** |
||||
* 对redis字符串类型数据操作 |
||||
* |
||||
* @param redisTemplate |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public ValueOperations<String, Object> valueOperations(RedisTemplate<String, Object> redisTemplate) { |
||||
return redisTemplate.opsForValue(); |
||||
} |
||||
|
||||
/** |
||||
* 对链表类型的数据操作 |
||||
* |
||||
* @param redisTemplate |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public ListOperations<String, Object> listOperations(RedisTemplate<String, Object> redisTemplate) { |
||||
return redisTemplate.opsForList(); |
||||
} |
||||
|
||||
/** |
||||
* 对无序集合类型的数据操作 |
||||
* |
||||
* @param redisTemplate |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public SetOperations<String, Object> setOperations(RedisTemplate<String, Object> redisTemplate) { |
||||
return redisTemplate.opsForSet(); |
||||
} |
||||
|
||||
/** |
||||
* 对有序集合类型的数据操作 |
||||
* |
||||
* @param redisTemplate |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) { |
||||
return redisTemplate.opsForZSet(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,53 @@ |
||||
package com.cweb.config; |
||||
|
||||
import java.util.Map; |
||||
import java.util.concurrent.ConcurrentHashMap; |
||||
|
||||
public class SessionKeyCache { |
||||
|
||||
private static Map<String, CacheData> CACHE_DATA = new ConcurrentHashMap<>(); |
||||
|
||||
public static <T> T getData(String key) { |
||||
CacheData<T> data = CACHE_DATA.get(key); |
||||
if (data != null){ |
||||
if(data.getExpire() <= 0 || data.getSaveTime() >= System.currentTimeMillis()) { |
||||
return data.getData(); |
||||
}else{ |
||||
clear(key); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public static <T> void setData(String key, T data, int expire) { |
||||
CACHE_DATA.put(key, new CacheData(data, expire)); |
||||
} |
||||
|
||||
public static void clear(String key) { |
||||
CACHE_DATA.remove(key); |
||||
} |
||||
|
||||
private static class CacheData<T> { |
||||
CacheData(T t, int expire) { |
||||
this.data = t; |
||||
this.expire = expire <= 0 ? 0 : expire*1000; |
||||
this.saveTime = System.currentTimeMillis() + this.expire; |
||||
} |
||||
|
||||
private T data; |
||||
private long saveTime; // 存活时间
|
||||
private long expire; // 过期时间 小于等于0标识永久存活
|
||||
|
||||
public T getData() { |
||||
return data; |
||||
} |
||||
|
||||
public long getExpire() { |
||||
return expire; |
||||
} |
||||
|
||||
public long getSaveTime() { |
||||
return saveTime; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,47 @@ |
||||
package com.cweb.config; |
||||
|
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import springfox.documentation.builders.ApiInfoBuilder; |
||||
import springfox.documentation.builders.RequestHandlerSelectors; |
||||
import springfox.documentation.service.ApiInfo; |
||||
import springfox.documentation.service.Contact; |
||||
import springfox.documentation.spi.DocumentationType; |
||||
import springfox.documentation.spring.web.plugins.Docket; |
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2; |
||||
|
||||
/** |
||||
* SwaggerConfig.java |
||||
* 项目名称: |
||||
* 包: |
||||
* 类名称: SwaggerConfig.java |
||||
* 类描述: 构建restful api接口文档 |
||||
* 创建人: |
||||
* 创建时间: 2017 下午4:23:45 |
||||
*/ |
||||
@Configuration |
||||
@EnableSwagger2 |
||||
public class SwaggerConfig |
||||
{ |
||||
|
||||
/** |
||||
* 描述api的基本信息 |
||||
* 基本信息会展现在文档页面中 |
||||
* @return [api的基本信息] |
||||
*/ |
||||
ApiInfo apiInfo() |
||||
{ |
||||
return new ApiInfoBuilder().title("hgj-CWeb").description("提供给用户端的接口").termsOfServiceUrl("").version("1.0.0") |
||||
.contact(new Contact("", "", "")).build(); |
||||
} |
||||
|
||||
@Bean |
||||
public Docket customImplementation() |
||||
{ |
||||
return new Docket(DocumentationType.SWAGGER_2).select() |
||||
.apis(RequestHandlerSelectors.basePackage("com")) |
||||
.build().directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class) |
||||
.directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class).apiInfo(apiInfo()); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,31 @@ |
||||
package com.cweb.config; |
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties; |
||||
import org.springframework.context.annotation.PropertySource; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
@Component("sysConfig") |
||||
@ConfigurationProperties |
||||
@PropertySource("classpath:/config.properties") |
||||
public class SysConfig { |
||||
|
||||
private String fileUrl; |
||||
|
||||
private String cmsPath; |
||||
|
||||
public String getFileUrl() { |
||||
return fileUrl; |
||||
} |
||||
|
||||
public void setFileUrl(String fileUrl) { |
||||
this.fileUrl = fileUrl; |
||||
} |
||||
|
||||
public String getCmsPath() { |
||||
return cmsPath; |
||||
} |
||||
|
||||
public void setCmsPath(String cmsPath) { |
||||
this.cmsPath = cmsPath; |
||||
} |
||||
} |
@ -0,0 +1,19 @@ |
||||
package com.cweb.config; |
||||
|
||||
public class SysConst { |
||||
|
||||
private static SysConfig sysConfig; |
||||
|
||||
public static void setSysConfig(SysConfig arg){ |
||||
sysConfig = arg; |
||||
} |
||||
|
||||
public static SysConfig getSysConfig(){ |
||||
if (null == sysConfig) { |
||||
//防止空指针异常
|
||||
sysConfig = new SysConfig(); |
||||
return sysConfig; |
||||
} |
||||
return sysConfig; |
||||
} |
||||
} |
@ -0,0 +1,33 @@ |
||||
package com.cweb.config; |
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService; |
||||
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; |
||||
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; |
||||
import org.springframework.context.annotation.Configuration; |
||||
|
||||
import javax.annotation.PostConstruct; |
||||
|
||||
@Configuration |
||||
public class WxMaConfiguration { |
||||
|
||||
private static WxMaService maService; |
||||
|
||||
public static WxMaService getMaService() { |
||||
if (maService == null) { |
||||
throw new IllegalArgumentException(String.format("未找到对应的配置,请核实!")); |
||||
} |
||||
|
||||
return maService; |
||||
} |
||||
|
||||
@PostConstruct |
||||
public void init() { |
||||
/*WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); |
||||
config.setAppid(SysConst.getSysConfig().getWxAppId()); |
||||
config.setSecret(SysConst.getSysConfig().getWxAppSecret()); |
||||
|
||||
maService = new WxMaServiceImpl(); |
||||
maService.setWxMaConfig(config);*/ |
||||
} |
||||
|
||||
} |
@ -0,0 +1,55 @@ |
||||
package com.cweb.config; |
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaMsgService; |
||||
import cn.binarywang.wx.miniapp.api.WxMaService; |
||||
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage; |
||||
import com.hfkj.common.utils.DateUtil; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.util.*; |
||||
|
||||
public class WxMsgConfig { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(WxMsgConfig.class); |
||||
|
||||
public static void pushOneUser(String orderName , String price , String orderNo , Date payTime , String remark , Long orderId , String openId) { |
||||
|
||||
try { |
||||
List<WxMaSubscribeMessage.Data> list = new ArrayList<>(); |
||||
|
||||
Map<String, String> m = new HashMap<>(); |
||||
|
||||
m.put("thing1", orderName); |
||||
m.put("amount2", price + "元"); |
||||
m.put("character_string3", orderNo); |
||||
m.put("time4", DateUtil.date2String(payTime , "yyyy年MM月dd日 HH:mm:ss")); |
||||
m.put("thing6", remark); |
||||
|
||||
for (String key: m.keySet()) { |
||||
WxMaSubscribeMessage.Data msgElement = new WxMaSubscribeMessage.Data(); |
||||
msgElement.setName(key); |
||||
msgElement.setValue(m.get(key)); |
||||
list.add(msgElement); |
||||
} |
||||
|
||||
WxMaSubscribeMessage subscribeMessage = new WxMaSubscribeMessage(); |
||||
subscribeMessage.setToUser(openId); // 小程序openId
|
||||
subscribeMessage.setTemplateId("oUvaCPeeOg4wH6HTvCcSabU6FnzXUXOBXsqBYAPOV-U"); |
||||
subscribeMessage.setData(list); |
||||
subscribeMessage.setPage("pages/user/order_details/order_details?id=" + orderId); |
||||
subscribeMessage.setMiniprogramState("developer"); |
||||
|
||||
final WxMaService wxService = WxMaConfiguration.getMaService(); |
||||
WxMaMsgService maMsgService = wxService.getMsgService(); |
||||
maMsgService.sendSubscribeMsg(subscribeMessage); |
||||
} catch (Exception e) { |
||||
log.error(String.valueOf(e)); |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
} |
@ -0,0 +1,25 @@ |
||||
package com.cweb.controller; |
||||
|
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.service.CommonService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
|
||||
|
||||
@RestController |
||||
@RequestMapping(value="/common") |
||||
@Api(value="共用接口") |
||||
public class CommonController { |
||||
|
||||
Logger log = LoggerFactory.getLogger(CommonController.class); |
||||
|
||||
@Resource |
||||
private CommonService commonService; |
||||
|
||||
} |
@ -0,0 +1,79 @@ |
||||
package com.cweb.controller.pay; |
||||
|
||||
import com.hfkj.common.pay.WechatPayUtil; |
||||
import com.hfkj.common.pay.util.IOUtil; |
||||
import com.hfkj.common.pay.util.XmlUtil; |
||||
import com.hfkj.common.pay.util.sdk.WXPayConstants; |
||||
import com.hfkj.service.pay.NotifyService; |
||||
import com.hfkj.service.pay.PayRecordService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestMethod; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.BufferedOutputStream; |
||||
import java.util.*; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/wechatpay") |
||||
@Api(value = "微信支付") |
||||
public class WechatPayController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(WechatPayController.class); |
||||
|
||||
private WXPayConstants.SignType signType; |
||||
|
||||
@Resource |
||||
private NotifyService notifyService; |
||||
|
||||
@Resource |
||||
private PayRecordService payRecordService; |
||||
|
||||
@Resource |
||||
private WechatPayUtil wechatPayUtil; |
||||
|
||||
|
||||
@RequestMapping(value = "/notify", method = RequestMethod.POST) |
||||
@ApiOperation(value = "微信支付 -> 异步回调") |
||||
public void wechatNotify(HttpServletRequest request, HttpServletResponse response) { |
||||
try { |
||||
log.info("微信支付 -> 异步通知:处理开始"); |
||||
|
||||
String resXml = ""; // 反馈给微信服务器
|
||||
String notifyXml = null; // 微信支付系统发送的数据(<![CDATA[product_001]]>格式)
|
||||
notifyXml = IOUtil.inputStreamToString(request.getInputStream(), "UTF-8"); |
||||
|
||||
log.info("微信支付系统发送的数据:" + notifyXml); |
||||
SortedMap<String, String> map = XmlUtil.parseXmlToTreeMap(notifyXml, "UTF-8"); |
||||
|
||||
resXml = notifyService.wechatNotify(map); |
||||
|
||||
/* if (SignatureUtil.reCheckIsSignValidFromWeiXin(notifyXml, SysConst.getSysConfig().getWxApiKey(), "UTF-8")) { |
||||
log.info("微信支付系统发送的数据:" + notifyXml); |
||||
SortedMap<String, String> map = XmlUtil.parseXmlToTreeMap(notifyXml, "UTF-8"); |
||||
|
||||
resXml = notifyService.wechatNotify(map); |
||||
} else { |
||||
log.error("微信支付 -> 异步通知:验签失败"); |
||||
log.error("apiKey:" + SysConst.getSysConfig().getWxApiKey()); |
||||
log.error("返回信息:" + notifyXml); |
||||
resXml = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>" |
||||
+ "<return_msg><![CDATA[签名验证错误]]></return_msg>" + "</xml> "; |
||||
}*/ |
||||
|
||||
BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream()); |
||||
out.write(resXml.getBytes()); |
||||
out.flush(); |
||||
out.close(); |
||||
log.info("微信支付 -> 异步通知:处理完成"); |
||||
} catch (Exception e) { |
||||
log.error("WechatPayController --> wechatNotify() error!", e); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,56 @@ |
||||
server: |
||||
port: 9801 |
||||
servlet: |
||||
context-path: /crest |
||||
|
||||
#配置是否为debug模式,debug模式下,不开启权限校验 |
||||
debug: false |
||||
|
||||
#datasource数据源设置 |
||||
spring: |
||||
datasource: |
||||
url: jdbc:mysql://139.159.177.244:3306/hfkj?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false |
||||
username: root |
||||
password: HF123456. |
||||
type: com.alibaba.druid.pool.DruidDataSource |
||||
driver-class-name: com.mysql.jdbc.Driver |
||||
filters: stat |
||||
maxActive: 10 |
||||
initialSize: 5 |
||||
maxWait: 60000 |
||||
minIdle: 5 |
||||
timeBetweenEvictionRunsMillis: 60000 |
||||
minEvictableIdleTimeMillis: 300000 |
||||
validationQuery: select 'x' |
||||
testWhileIdle: true |
||||
testOnBorrow: false |
||||
testOnReturn: false |
||||
poolPreparedStatements: true |
||||
maxOpenPreparedStatements: 20 |
||||
redis: |
||||
database: 0 |
||||
host: 139.159.177.244 |
||||
port: 36379 |
||||
password: HF123456.Redis |
||||
timeout: 1000 |
||||
jedis: |
||||
pool: |
||||
max-active: 20 |
||||
max-wait: -1 |
||||
max-idle: 10 |
||||
min-idle: 0 |
||||
#配置日期返回至前台为时间戳 |
||||
jackson: |
||||
serialization: |
||||
write-dates-as-timestamps: true |
||||
mybatis: |
||||
mapperLocations: |
||||
- classpath*:sqlmap*/*.xml |
||||
type-aliases-package: |
||||
org.springboot.sample.entity |
||||
|
||||
pagehelper: |
||||
helperDialect: mysql |
||||
reasonable: true |
||||
supportMethodsArguments: true |
||||
params: count=countSql |
@ -0,0 +1,2 @@ |
||||
fileUrl=/home/project/hsg/filesystem |
||||
cmsPath=/home/project/hsg/filesystem/cmsPath |
@ -0,0 +1,72 @@ |
||||
<configuration> |
||||
<!-- %m输出的信息,%p日志级别,%t线程名,%d日期,%c类的全名,,,, --> |
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
||||
<encoder> |
||||
<pattern>%d %p (%file:%line\)- %m%n</pattern> |
||||
<charset>UTF-8</charset> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="baselog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/base.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/base.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="daolog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/dao.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/dao.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="errorlog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/error.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/error.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<root level="DEBUG"> |
||||
<appender-ref ref="STDOUT" /> |
||||
</root> |
||||
<logger name="com.hfkj" level="DEBUG"> |
||||
<appender-ref ref="baselog" /> |
||||
</logger> |
||||
<logger name="com.hfkj.dao" level="DEBUG"> |
||||
<appender-ref ref="daolog" /> |
||||
</logger> |
||||
<logger name="com.hfkj" level="ERROR"> |
||||
<appender-ref ref="errorlog" /> |
||||
</logger> |
||||
</configuration> |
@ -0,0 +1,56 @@ |
||||
server: |
||||
port: 9301 |
||||
servlet: |
||||
context-path: /crest |
||||
|
||||
#配置是否为debug模式,debug模式下,不开启权限校验 |
||||
debug: false |
||||
|
||||
#datasource数据源设置 |
||||
spring: |
||||
datasource: |
||||
url: jdbc:mysql://139.159.177.244:3306/hsg_pre?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false |
||||
username: root |
||||
password: HF123456. |
||||
type: com.alibaba.druid.pool.DruidDataSource |
||||
driver-class-name: com.mysql.jdbc.Driver |
||||
filters: stat |
||||
maxActive: 10 |
||||
initialSize: 5 |
||||
maxWait: 60000 |
||||
minIdle: 5 |
||||
timeBetweenEvictionRunsMillis: 60000 |
||||
minEvictableIdleTimeMillis: 300000 |
||||
validationQuery: select 'x' |
||||
testWhileIdle: true |
||||
testOnBorrow: false |
||||
testOnReturn: false |
||||
poolPreparedStatements: true |
||||
maxOpenPreparedStatements: 20 |
||||
redis: |
||||
database: 1 |
||||
host: 139.159.177.244 |
||||
port: 36379 |
||||
password: HF123456.Redis |
||||
timeout: 1000 |
||||
jedis: |
||||
pool: |
||||
max-active: 20 |
||||
max-wait: -1 |
||||
max-idle: 10 |
||||
min-idle: 0 |
||||
#配置日期返回至前台为时间戳 |
||||
jackson: |
||||
serialization: |
||||
write-dates-as-timestamps: true |
||||
mybatis: |
||||
mapperLocations: |
||||
- classpath*:sqlmap*/*.xml |
||||
type-aliases-package: |
||||
org.springboot.sample.entity |
||||
|
||||
pagehelper: |
||||
helperDialect: mysql |
||||
reasonable: true |
||||
supportMethodsArguments: true |
||||
params: count=countSql |
@ -0,0 +1,2 @@ |
||||
fileUrl=/home/project/hsg/filesystem |
||||
cmsPath=/home/project/hsg/filesystem/cmsPath |
@ -0,0 +1,72 @@ |
||||
<configuration> |
||||
<!-- %m输出的信息,%p日志级别,%t线程名,%d日期,%c类的全名,,,, --> |
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
||||
<encoder> |
||||
<pattern>%d %p (%file:%line\)- %m%n</pattern> |
||||
<charset>UTF-8</charset> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="baselog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/base.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/base.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="daolog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/dao.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/dao.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="errorlog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/error.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/error.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<root level="DEBUG"> |
||||
<appender-ref ref="STDOUT" /> |
||||
</root> |
||||
<logger name="com.hfkj" level="DEBUG"> |
||||
<appender-ref ref="baselog" /> |
||||
</logger> |
||||
<logger name="com.hfkj.dao" level="DEBUG"> |
||||
<appender-ref ref="daolog" /> |
||||
</logger> |
||||
<logger name="com.hfkj" level="ERROR"> |
||||
<appender-ref ref="errorlog" /> |
||||
</logger> |
||||
</configuration> |
@ -0,0 +1,57 @@ |
||||
server: |
||||
port: 9301 |
||||
servlet: |
||||
context-path: /crest |
||||
|
||||
#配置是否为debug模式,debug模式下,不开启权限校验 |
||||
debug: false |
||||
|
||||
#datasource数据源设置 |
||||
spring: |
||||
datasource: |
||||
url: jdbc:mysql://127.0.0.1:3306/hsg?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8 |
||||
username: root |
||||
password: HF123456. |
||||
type: com.alibaba.druid.pool.DruidDataSource |
||||
driver-class-name: com.mysql.jdbc.Driver |
||||
filters: stat |
||||
maxActive: 10 |
||||
initialSize: 5 |
||||
maxWait: 60000 |
||||
minIdle: 5 |
||||
timeBetweenEvictionRunsMillis: 60000 |
||||
minEvictableIdleTimeMillis: 300000 |
||||
validationQuery: select 'x' |
||||
testWhileIdle: true |
||||
testOnBorrow: false |
||||
testOnReturn: false |
||||
poolPreparedStatements: true |
||||
maxOpenPreparedStatements: 20 |
||||
|
||||
redis: |
||||
database: 0 |
||||
host: 127.0.0.1 |
||||
port: 36379 |
||||
password: HF123456.Redis |
||||
timeout: 1000 |
||||
jedis: |
||||
pool: |
||||
max-active: 20 |
||||
max-wait: -1 |
||||
max-idle: 10 |
||||
min-idle: 0 |
||||
#配置日期返回至前台为时间戳 |
||||
jackson: |
||||
serialization: |
||||
write-dates-as-timestamps: true |
||||
mybatis: |
||||
mapperLocations: |
||||
- classpath*:sqlmap*/*.xml |
||||
type-aliases-package: |
||||
org.springboot.sample.entity |
||||
|
||||
pagehelper: |
||||
helperDialect: mysql |
||||
reasonable: true |
||||
supportMethodsArguments: true |
||||
params: count=countSql |
@ -0,0 +1,2 @@ |
||||
fileUrl=/home/project/hsg/filesystem |
||||
cmsPath=/home/project/hsg/filesystem/cmsPath |
@ -0,0 +1,72 @@ |
||||
<configuration> |
||||
<!-- %m输出的信息,%p日志级别,%t线程名,%d日期,%c类的全名,,,, --> |
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
||||
<encoder> |
||||
<pattern>%d %p (%file:%line\)- %m%n</pattern> |
||||
<charset>UTF-8</charset> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="baselog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/base.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/base.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="daolog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/dao.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/dao.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="errorlog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/error.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/error.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<root level="DEBUG"> |
||||
<appender-ref ref="STDOUT" /> |
||||
</root> |
||||
<logger name="com.hfkj" level="DEBUG"> |
||||
<appender-ref ref="baselog" /> |
||||
</logger> |
||||
<logger name="com.hfkj.dao" level="DEBUG"> |
||||
<appender-ref ref="daolog" /> |
||||
</logger> |
||||
<logger name="com.hfkj" level="ERROR"> |
||||
<appender-ref ref="errorlog" /> |
||||
</logger> |
||||
</configuration> |
@ -0,0 +1,67 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<groupId>com.hfkj</groupId> |
||||
<artifactId>hai-oil-parent</artifactId> |
||||
<packaging>pom</packaging> |
||||
<version>1.0-SNAPSHOT</version> |
||||
|
||||
<parent> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-parent</artifactId> |
||||
<version>2.0.5.RELEASE</version> |
||||
<relativePath/> |
||||
</parent> |
||||
|
||||
<properties> |
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> |
||||
<springfox-version>2.6.1</springfox-version> |
||||
<joda-time-version>2.9.9</joda-time-version> |
||||
</properties> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>commons-net</groupId> |
||||
<artifactId>commons-net</artifactId> |
||||
<version>3.6</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>net.coobird</groupId> |
||||
<artifactId>thumbnailator</artifactId> |
||||
<version>0.4.8</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>junit</groupId> |
||||
<artifactId>junit</artifactId> |
||||
<version>4.12</version> |
||||
<!-- 表示开发的时候引入,发布的时候不会加载此包 --> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-test</artifactId> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.github.binarywang</groupId> |
||||
<artifactId>weixin-java-mp</artifactId> |
||||
<version>3.8.0</version> |
||||
</dependency> |
||||
</dependencies> |
||||
<build> |
||||
<defaultGoal>compile</defaultGoal> |
||||
</build> |
||||
|
||||
<modules> |
||||
<module>service</module> |
||||
<module>cweb</module> |
||||
<module>bweb</module> |
||||
<module>schedule</module> |
||||
</modules> |
||||
|
||||
|
||||
</project> |
@ -0,0 +1,47 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
<parent> |
||||
<groupId>com.hfkj</groupId> |
||||
<artifactId>hai-oil-parent</artifactId> |
||||
<version>1.0-SNAPSHOT</version> |
||||
</parent> |
||||
|
||||
<groupId>com.hfkj</groupId> |
||||
<artifactId>oil-schedule</artifactId> |
||||
<name>schedule</name> |
||||
<version>1.0-SNAPSHOT</version> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>com.hfkj</groupId> |
||||
<artifactId>service</artifactId> |
||||
<version>PACKT-SNAPSHOT</version> |
||||
</dependency> |
||||
</dependencies> |
||||
|
||||
<build> |
||||
<resources> |
||||
<resource> |
||||
<directory>src/main/resources/${env}</directory> |
||||
<filtering>false</filtering> |
||||
</resource> |
||||
</resources> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-surefire-plugin</artifactId> |
||||
<configuration> |
||||
<skip>true</skip> |
||||
</configuration> |
||||
</plugin> |
||||
<plugin> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-maven-plugin</artifactId> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
|
||||
</project> |
@ -0,0 +1,30 @@ |
||||
package com.hfkj; |
||||
|
||||
import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation; |
||||
import com.alicp.jetcache.anno.config.EnableMethodCache; |
||||
import com.hfkj.common.utils.SpringContextUtil; |
||||
import org.mybatis.spring.annotation.MapperScan; |
||||
import org.springframework.boot.SpringApplication; |
||||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
import org.springframework.boot.web.servlet.ServletComponentScan; |
||||
import org.springframework.context.ApplicationContext; |
||||
import org.springframework.scheduling.annotation.EnableScheduling; |
||||
import org.springframework.transaction.annotation.EnableTransactionManagement; |
||||
|
||||
@SpringBootApplication |
||||
//@ComponentScan
|
||||
@EnableTransactionManagement |
||||
@EnableScheduling |
||||
@EnableMethodCache(basePackages = "com.hfkj") |
||||
@EnableCreateCacheAnnotation |
||||
@ServletComponentScan |
||||
@MapperScan("com.hfkj.dao") |
||||
public class ScheduleApplication |
||||
{ |
||||
public static void main( String[] args ) |
||||
{ |
||||
ApplicationContext app = SpringApplication.run(ScheduleApplication.class, args); |
||||
SpringContextUtil.setApplicationContext(app); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,123 @@ |
||||
package com.hfkj.config; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect; |
||||
import com.fasterxml.jackson.annotation.PropertyAccessor; |
||||
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
import org.springframework.cache.annotation.CachingConfigurerSupport; |
||||
import org.springframework.cache.annotation.EnableCaching; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.data.redis.connection.RedisConnectionFactory; |
||||
import org.springframework.data.redis.core.*; |
||||
import org.springframework.data.redis.listener.PatternTopic; |
||||
import org.springframework.data.redis.listener.RedisMessageListenerContainer; |
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; |
||||
import org.springframework.data.redis.serializer.StringRedisSerializer; |
||||
|
||||
|
||||
@Configuration |
||||
@EnableCaching //开启注解
|
||||
public class RedisConfig extends CachingConfigurerSupport { |
||||
|
||||
|
||||
@Bean |
||||
public RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory factory) { |
||||
RedisMessageListenerContainer container = new RedisMessageListenerContainer(); |
||||
container.setConnectionFactory(factory); |
||||
|
||||
//可以添加多个 messageListener
|
||||
// container.addMessageListener(new OilPriceTaskMsgListener(), new PatternTopic(MsgTopic.oilPriceTask.getName()));
|
||||
|
||||
return container; |
||||
} |
||||
|
||||
/** |
||||
* retemplate相关配置 |
||||
* @param factory |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) { |
||||
|
||||
RedisTemplate<String, Object> template = new RedisTemplate<>(); |
||||
// 配置连接工厂
|
||||
template.setConnectionFactory(factory); |
||||
|
||||
//使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值(默认使用JDK的序列化方式)
|
||||
Jackson2JsonRedisSerializer jacksonSeial = new Jackson2JsonRedisSerializer(Object.class); |
||||
|
||||
ObjectMapper om = new ObjectMapper(); |
||||
// 指定要序列化的域,field,get和set,以及修饰符范围,ANY是都有包括private和public
|
||||
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); |
||||
// 指定序列化输入的类型,类必须是非final修饰的,final修饰的类,比如String,Integer等会跑出异常
|
||||
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); |
||||
jacksonSeial.setObjectMapper(om); |
||||
|
||||
// 值采用json序列化
|
||||
template.setValueSerializer(jacksonSeial); |
||||
//使用StringRedisSerializer来序列化和反序列化redis的key值
|
||||
template.setKeySerializer(new StringRedisSerializer()); |
||||
|
||||
// 设置hash key 和value序列化模式
|
||||
template.setHashKeySerializer(new StringRedisSerializer()); |
||||
template.setHashValueSerializer(jacksonSeial); |
||||
template.afterPropertiesSet(); |
||||
|
||||
return template; |
||||
} |
||||
|
||||
/** |
||||
* 对hash类型的数据操作 |
||||
* |
||||
* @param redisTemplate |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public HashOperations<String, String, Object> hashOperations(RedisTemplate<String, Object> redisTemplate) { |
||||
return redisTemplate.opsForHash(); |
||||
} |
||||
|
||||
/** |
||||
* 对redis字符串类型数据操作 |
||||
* |
||||
* @param redisTemplate |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public ValueOperations<String, Object> valueOperations(RedisTemplate<String, Object> redisTemplate) { |
||||
return redisTemplate.opsForValue(); |
||||
} |
||||
|
||||
/** |
||||
* 对链表类型的数据操作 |
||||
* |
||||
* @param redisTemplate |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public ListOperations<String, Object> listOperations(RedisTemplate<String, Object> redisTemplate) { |
||||
return redisTemplate.opsForList(); |
||||
} |
||||
|
||||
/** |
||||
* 对无序集合类型的数据操作 |
||||
* |
||||
* @param redisTemplate |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public SetOperations<String, Object> setOperations(RedisTemplate<String, Object> redisTemplate) { |
||||
return redisTemplate.opsForSet(); |
||||
} |
||||
|
||||
/** |
||||
* 对有序集合类型的数据操作 |
||||
* |
||||
* @param redisTemplate |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) { |
||||
return redisTemplate.opsForZSet(); |
||||
} |
||||
} |
@ -0,0 +1,199 @@ |
||||
package com.hfkj.config; |
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties; |
||||
import org.springframework.context.annotation.PropertySource; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
@Component("sysConfig") |
||||
@ConfigurationProperties |
||||
@PropertySource("classpath:/config.properties") |
||||
public class SysConfig { |
||||
|
||||
private String wxAppId; |
||||
private String wxAppSecret; |
||||
|
||||
private String ys7AppKey; |
||||
private String ys7AppSecret; |
||||
|
||||
private String classVideoPath; |
||||
|
||||
private String app_id; |
||||
|
||||
private String app_secret; |
||||
|
||||
private String notify_url; |
||||
|
||||
private String api_key; |
||||
|
||||
private String mch_id; |
||||
|
||||
private String unified_order_url; |
||||
|
||||
private String rectifyPath; |
||||
|
||||
private String graduatePath; |
||||
|
||||
private String fileUrl; |
||||
|
||||
private String arcsoftlibUrl; |
||||
|
||||
private String arcsoftAppId; |
||||
|
||||
private String arcsoftKey; |
||||
|
||||
private String ffmpegPath; |
||||
|
||||
private String tmpFilePath; |
||||
|
||||
public String getGraduatePath() { |
||||
return graduatePath; |
||||
} |
||||
|
||||
public void setGraduatePath(String graduatePath) { |
||||
this.graduatePath = graduatePath; |
||||
} |
||||
|
||||
public String getArcsoftAppId() { |
||||
return arcsoftAppId; |
||||
} |
||||
|
||||
public void setArcsoftAppId(String arcsoftAppId) { |
||||
this.arcsoftAppId = arcsoftAppId; |
||||
} |
||||
|
||||
public String getArcsoftKey() { |
||||
return arcsoftKey; |
||||
} |
||||
|
||||
public void setArcsoftKey(String arcsoftKey) { |
||||
this.arcsoftKey = arcsoftKey; |
||||
} |
||||
|
||||
public String getArcsoftlibUrl() { |
||||
return arcsoftlibUrl; |
||||
} |
||||
|
||||
public void setArcsoftlibUrl(String arcsoftlibUrl) { |
||||
this.arcsoftlibUrl = arcsoftlibUrl; |
||||
} |
||||
|
||||
public String getFileUrl() { |
||||
return fileUrl; |
||||
} |
||||
|
||||
public void setFileUrl(String fileUrl) { |
||||
this.fileUrl = fileUrl; |
||||
} |
||||
|
||||
public String getRectifyPath() { |
||||
return rectifyPath; |
||||
} |
||||
|
||||
public void setRectifyPath(String rectifyPath) { |
||||
this.rectifyPath = rectifyPath; |
||||
} |
||||
|
||||
public String getWxAppId() { |
||||
return wxAppId; |
||||
} |
||||
|
||||
public void setWxAppId(String wxAppId) { |
||||
this.wxAppId = wxAppId; |
||||
} |
||||
|
||||
public String getWxAppSecret() { |
||||
return wxAppSecret; |
||||
} |
||||
|
||||
public void setWxAppSecret(String wxAppSecret) { |
||||
this.wxAppSecret = wxAppSecret; |
||||
} |
||||
|
||||
public String getYs7AppKey() { |
||||
return ys7AppKey; |
||||
} |
||||
|
||||
public void setYs7AppKey(String ys7AppKey) { |
||||
this.ys7AppKey = ys7AppKey; |
||||
} |
||||
|
||||
public String getYs7AppSecret() { |
||||
return ys7AppSecret; |
||||
} |
||||
|
||||
public void setYs7AppSecret(String ys7AppSecret) { |
||||
this.ys7AppSecret = ys7AppSecret; |
||||
} |
||||
|
||||
public String getClassVideoPath() { |
||||
return classVideoPath; |
||||
} |
||||
|
||||
public void setClassVideoPath(String classVideoPath) { |
||||
this.classVideoPath = classVideoPath; |
||||
} |
||||
|
||||
public String getApp_id() { |
||||
return app_id; |
||||
} |
||||
|
||||
public void setApp_id(String app_id) { |
||||
this.app_id = app_id; |
||||
} |
||||
|
||||
public String getApp_secret() { |
||||
return app_secret; |
||||
} |
||||
|
||||
public void setApp_secret(String app_secret) { |
||||
this.app_secret = app_secret; |
||||
} |
||||
|
||||
public String getNotify_url() { |
||||
return notify_url; |
||||
} |
||||
|
||||
public void setNotify_url(String notify_url) { |
||||
this.notify_url = notify_url; |
||||
} |
||||
|
||||
public String getApi_key() { |
||||
return api_key; |
||||
} |
||||
|
||||
public void setApi_key(String api_key) { |
||||
this.api_key = api_key; |
||||
} |
||||
|
||||
public String getMch_id() { |
||||
return mch_id; |
||||
} |
||||
|
||||
public void setMch_id(String mch_id) { |
||||
this.mch_id = mch_id; |
||||
} |
||||
|
||||
public String getUnified_order_url() { |
||||
return unified_order_url; |
||||
} |
||||
|
||||
public void setUnified_order_url(String unified_order_url) { |
||||
this.unified_order_url = unified_order_url; |
||||
} |
||||
|
||||
public String getFfmpegPath() { |
||||
return ffmpegPath; |
||||
} |
||||
|
||||
public void setFfmpegPath(String ffmpegPath) { |
||||
this.ffmpegPath = ffmpegPath; |
||||
} |
||||
|
||||
public String getTmpFilePath() { |
||||
return tmpFilePath; |
||||
} |
||||
|
||||
public void setTmpFilePath(String tmpFilePath) { |
||||
this.tmpFilePath = tmpFilePath; |
||||
} |
||||
} |
@ -0,0 +1,20 @@ |
||||
package com.hfkj.msg; |
||||
|
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.data.redis.connection.Message; |
||||
import org.springframework.data.redis.connection.MessageListener; |
||||
import org.springframework.data.redis.core.RedisTemplate; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
@Service(value = "driverLBSMsgListener") |
||||
public class OilPriceTaskMsgListener implements MessageListener { |
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(OilPriceTaskMsgListener.class); |
||||
private RedisTemplate<String, Object> redisTemplate; |
||||
|
||||
@Override |
||||
public void onMessage(Message message, byte[] pattern) { |
||||
System.out.println(message); |
||||
} |
||||
} |
@ -0,0 +1,48 @@ |
||||
package com.hfkj.msg; |
||||
|
||||
import com.hfkj.entity.BsGasOilPriceTask; |
||||
import com.hfkj.service.BsGasOilPriceTaskService; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.data.redis.connection.Message; |
||||
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener; |
||||
import org.springframework.data.redis.listener.RedisMessageListenerContainer; |
||||
import org.springframework.stereotype.Component; |
||||
import javax.annotation.Resource; |
||||
|
||||
|
||||
@Component |
||||
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener { |
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(RedisKeyExpirationListener.class); |
||||
|
||||
@Resource |
||||
private BsGasOilPriceTaskService gasOilPriceTaskService; |
||||
|
||||
public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) { |
||||
super(listenerContainer); |
||||
} |
||||
|
||||
public void onMessage(Message message, byte[] pattern) { |
||||
try { |
||||
if (message != null && StringUtils.isNotBlank(message.toString())) { |
||||
// 加油站价格任务
|
||||
if (message.toString().contains(MsgTopic.oilPriceTask.getName())) { |
||||
// 截取任务id
|
||||
Long taskId = Long.parseLong(StringUtils.substringAfterLast(message.toString(), MsgTopic.oilPriceTask.getName() + "-")); |
||||
if (taskId != null) { |
||||
// 查询任务
|
||||
BsGasOilPriceTask gasOilPriceTask = gasOilPriceTaskService.getDetailById(taskId); |
||||
if (gasOilPriceTask != null) { |
||||
// 任务处理
|
||||
gasOilPriceTaskService.businessHandle(gasOilPriceTask); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} catch (Exception e) { |
||||
logger.error("redis过期事件异常:", e); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,59 @@ |
||||
server: |
||||
port: 9303 |
||||
servlet: |
||||
context-path: /schedule |
||||
|
||||
#配置是否为debug模式,debug模式下,不开启权限校验 |
||||
debug: false |
||||
|
||||
#datasource数据源设置 |
||||
spring: |
||||
datasource: |
||||
url: jdbc:mysql://139.159.177.244:3306/hsg?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8 |
||||
username: root |
||||
password: HF123456. |
||||
type: com.alibaba.druid.pool.DruidDataSource |
||||
driver-class-name: com.mysql.jdbc.Driver |
||||
filters: stat |
||||
maxActive: 10 |
||||
initialSize: 5 |
||||
maxWait: 60000 |
||||
minIdle: 5 |
||||
timeBetweenEvictionRunsMillis: 60000 |
||||
minEvictableIdleTimeMillis: 300000 |
||||
validationQuery: select 'x' |
||||
testWhileIdle: true |
||||
testOnBorrow: false |
||||
testOnReturn: false |
||||
poolPreparedStatements: true |
||||
maxOpenPreparedStatements: 20 |
||||
|
||||
redis: |
||||
database: 0 |
||||
host: 139.159.177.244 |
||||
port: 36379 |
||||
password: HF123456.Redis |
||||
timeout: 1000 |
||||
jedis: |
||||
pool: |
||||
max-active: 20 |
||||
max-wait: -1 |
||||
max-idle: 10 |
||||
min-idle: 0 |
||||
|
||||
#配置日期返回至前台为时间戳 |
||||
jackson: |
||||
serialization: |
||||
write-dates-as-timestamps: true |
||||
|
||||
mybatis: |
||||
mapperLocations: |
||||
- classpath*:sqlmap*/*.xml |
||||
type-aliases-package: |
||||
org.springboot.sample.entity |
||||
|
||||
pagehelper: |
||||
helperDialect: mysql |
||||
reasonable: true |
||||
supportMethodsArguments: true |
||||
params: count=countSql |
@ -0,0 +1,72 @@ |
||||
<configuration> |
||||
<!-- %m输出的信息,%p日志级别,%t线程名,%d日期,%c类的全名,,,, --> |
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
||||
<encoder> |
||||
<pattern>%d %p (%file:%line\)- %m%n</pattern> |
||||
<charset>UTF-8</charset> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="baselog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/base.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/base.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="daolog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/dao.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/dao.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="errorlog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/error.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/error.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<root level="DEBUG"> |
||||
<appender-ref ref="STDOUT" /> |
||||
</root> |
||||
<logger name="com.hfkj" level="DEBUG"> |
||||
<appender-ref ref="baselog" /> |
||||
</logger> |
||||
<logger name="com.hfkj.dao" level="DEBUG"> |
||||
<appender-ref ref="daolog" /> |
||||
</logger> |
||||
<logger name="com.hfkj" level="ERROR"> |
||||
<appender-ref ref="errorlog" /> |
||||
</logger> |
||||
</configuration> |
@ -0,0 +1,59 @@ |
||||
server: |
||||
port: 9303 |
||||
servlet: |
||||
context-path: /schedule |
||||
|
||||
#配置是否为debug模式,debug模式下,不开启权限校验 |
||||
debug: false |
||||
|
||||
#datasource数据源设置 |
||||
spring: |
||||
datasource: |
||||
url: jdbc:mysql://139.159.177.244:3306/hsg_pre?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8 |
||||
username: root |
||||
password: HF123456. |
||||
type: com.alibaba.druid.pool.DruidDataSource |
||||
driver-class-name: com.mysql.jdbc.Driver |
||||
filters: stat |
||||
maxActive: 10 |
||||
initialSize: 5 |
||||
maxWait: 60000 |
||||
minIdle: 5 |
||||
timeBetweenEvictionRunsMillis: 60000 |
||||
minEvictableIdleTimeMillis: 300000 |
||||
validationQuery: select 'x' |
||||
testWhileIdle: true |
||||
testOnBorrow: false |
||||
testOnReturn: false |
||||
poolPreparedStatements: true |
||||
maxOpenPreparedStatements: 20 |
||||
|
||||
redis: |
||||
database: 0 |
||||
host: 139.159.177.244 |
||||
port: 36379 |
||||
password: HF123456.Redis |
||||
timeout: 1000 |
||||
jedis: |
||||
pool: |
||||
max-active: 20 |
||||
max-wait: -1 |
||||
max-idle: 10 |
||||
min-idle: 0 |
||||
|
||||
#配置日期返回至前台为时间戳 |
||||
jackson: |
||||
serialization: |
||||
write-dates-as-timestamps: true |
||||
|
||||
mybatis: |
||||
mapperLocations: |
||||
- classpath*:sqlmap*/*.xml |
||||
type-aliases-package: |
||||
org.springboot.sample.entity |
||||
|
||||
pagehelper: |
||||
helperDialect: mysql |
||||
reasonable: true |
||||
supportMethodsArguments: true |
||||
params: count=countSql |
@ -0,0 +1,72 @@ |
||||
<configuration> |
||||
<!-- %m输出的信息,%p日志级别,%t线程名,%d日期,%c类的全名,,,, --> |
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
||||
<encoder> |
||||
<pattern>%d %p (%file:%line\)- %m%n</pattern> |
||||
<charset>UTF-8</charset> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="baselog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/base.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/base.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="daolog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/dao.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/dao.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="errorlog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/error.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/error.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<root level="DEBUG"> |
||||
<appender-ref ref="STDOUT" /> |
||||
</root> |
||||
<logger name="com.hfkj" level="DEBUG"> |
||||
<appender-ref ref="baselog" /> |
||||
</logger> |
||||
<logger name="com.hfkj.dao" level="DEBUG"> |
||||
<appender-ref ref="daolog" /> |
||||
</logger> |
||||
<logger name="com.hfkj" level="ERROR"> |
||||
<appender-ref ref="errorlog" /> |
||||
</logger> |
||||
</configuration> |
@ -0,0 +1,59 @@ |
||||
server: |
||||
port: 9303 |
||||
servlet: |
||||
context-path: /schedule |
||||
|
||||
#配置是否为debug模式,debug模式下,不开启权限校验 |
||||
debug: false |
||||
|
||||
#datasource数据源设置 |
||||
spring: |
||||
datasource: |
||||
url: jdbc:mysql://127.0.0.1:3306/hsg?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8 |
||||
username: root |
||||
password: HF123456. |
||||
type: com.alibaba.druid.pool.DruidDataSource |
||||
driver-class-name: com.mysql.jdbc.Driver |
||||
filters: stat |
||||
maxActive: 10 |
||||
initialSize: 5 |
||||
maxWait: 60000 |
||||
minIdle: 5 |
||||
timeBetweenEvictionRunsMillis: 60000 |
||||
minEvictableIdleTimeMillis: 300000 |
||||
validationQuery: select 'x' |
||||
testWhileIdle: true |
||||
testOnBorrow: false |
||||
testOnReturn: false |
||||
poolPreparedStatements: true |
||||
maxOpenPreparedStatements: 20 |
||||
|
||||
redis: |
||||
database: 0 |
||||
host: 127.0.0.1 |
||||
port: 36379 |
||||
password: HF123456.Redis |
||||
timeout: 1000 |
||||
jedis: |
||||
pool: |
||||
max-active: 20 |
||||
max-wait: -1 |
||||
max-idle: 10 |
||||
min-idle: 0 |
||||
|
||||
#配置日期返回至前台为时间戳 |
||||
jackson: |
||||
serialization: |
||||
write-dates-as-timestamps: true |
||||
|
||||
mybatis: |
||||
mapperLocations: |
||||
- classpath*:sqlmap*/*.xml |
||||
type-aliases-package: |
||||
org.springboot.sample.entity |
||||
|
||||
pagehelper: |
||||
helperDialect: mysql |
||||
reasonable: true |
||||
supportMethodsArguments: true |
||||
params: count=countSql |
@ -0,0 +1,72 @@ |
||||
<configuration> |
||||
<!-- %m输出的信息,%p日志级别,%t线程名,%d日期,%c类的全名,,,, --> |
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
||||
<encoder> |
||||
<pattern>%d %p (%file:%line\)- %m%n</pattern> |
||||
<charset>UTF-8</charset> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="baselog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/base.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/base.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="daolog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/dao.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/dao.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<appender name="errorlog" |
||||
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
<File>log/error.log</File> |
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
<fileNamePattern>log/error.log.%d.%i</fileNamePattern> |
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
||||
<!-- or whenever the file size reaches 64 MB --> |
||||
<maxFileSize>64 MB</maxFileSize> |
||||
</timeBasedFileNamingAndTriggeringPolicy> |
||||
</rollingPolicy> |
||||
<encoder> |
||||
<pattern> |
||||
%d %p (%file:%line\)- %m%n |
||||
</pattern> |
||||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
||||
</encoder> |
||||
</appender> |
||||
<root level="DEBUG"> |
||||
<appender-ref ref="STDOUT" /> |
||||
</root> |
||||
<logger name="com.hfkj" level="DEBUG"> |
||||
<appender-ref ref="baselog" /> |
||||
</logger> |
||||
<logger name="com.hfkj.dao" level="DEBUG"> |
||||
<appender-ref ref="daolog" /> |
||||
</logger> |
||||
<logger name="com.hfkj" level="ERROR"> |
||||
<appender-ref ref="errorlog" /> |
||||
</logger> |
||||
</configuration> |
@ -0,0 +1,271 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<groupId>com.hfkj</groupId> |
||||
<artifactId>hai-oil-parent</artifactId> |
||||
<version>1.0-SNAPSHOT</version> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<artifactId>service</artifactId> |
||||
<version>PACKT-SNAPSHOT</version> |
||||
|
||||
<properties> |
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> |
||||
<java.version>1.8</java.version> |
||||
<springfox-version>2.6.1</springfox-version> |
||||
<joda-time-version>2.9.9</joda-time-version> |
||||
</properties> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-web</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-jdbc</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.mybatis.spring.boot</groupId> |
||||
<artifactId>mybatis-spring-boot-starter</artifactId> |
||||
<version>1.3.1</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-test</artifactId> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-data-redis</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.thymeleaf</groupId> |
||||
<artifactId>thymeleaf</artifactId> |
||||
<version>3.0.9.RELEASE</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.thymeleaf</groupId> |
||||
<artifactId>thymeleaf-spring4</artifactId> |
||||
<version>3.0.9.RELEASE</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.github.pagehelper</groupId> |
||||
<artifactId>pagehelper-spring-boot-starter</artifactId> |
||||
<version>1.2.10</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.aspectj</groupId> |
||||
<artifactId>aspectjweaver</artifactId> |
||||
<version>1.8.13</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>tk.mybatis</groupId> |
||||
<artifactId>mapper</artifactId> |
||||
<version>3.3.0</version> |
||||
</dependency> |
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient --> |
||||
<dependency> |
||||
<groupId>org.apache.httpcomponents</groupId> |
||||
<artifactId>httpclient</artifactId> |
||||
<version>4.5.3</version> |
||||
</dependency> |
||||
|
||||
<!-- mysql连接驱动 --> |
||||
<dependency> |
||||
<groupId>mysql</groupId> |
||||
<artifactId>mysql-connector-java</artifactId> |
||||
<version>5.1.34</version> |
||||
</dependency> |
||||
|
||||
<!-- druid连接池 --> |
||||
<dependency> |
||||
<groupId>com.alibaba</groupId> |
||||
<artifactId>druid</artifactId> |
||||
<version>1.0.20</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>io.springfox</groupId> |
||||
<artifactId>springfox-swagger2</artifactId> |
||||
<version>${springfox-version}</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>io.springfox</groupId> |
||||
<artifactId>springfox-swagger-ui</artifactId> |
||||
<version>${springfox-version}</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>joda-time</groupId> |
||||
<artifactId>joda-time</artifactId> |
||||
<version>${joda-time-version}</version> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>org.slf4j</groupId> |
||||
<artifactId>slf4j-api</artifactId> |
||||
<version>1.7.25</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.slf4j</groupId> |
||||
<artifactId>slf4j-simple</artifactId> |
||||
<version>1.7.25</version> |
||||
<scope>provided</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.commons</groupId> |
||||
<artifactId>commons-lang3</artifactId> |
||||
<version>3.7</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.commons</groupId> |
||||
<artifactId>commons-collections4</artifactId> |
||||
<version>4.2</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>commons-codec</groupId> |
||||
<artifactId>commons-codec</artifactId> |
||||
<version>1.10</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>commons-logging</groupId> |
||||
<artifactId>commons-logging</artifactId> |
||||
<version>1.2</version> |
||||
</dependency> |
||||
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload --> |
||||
<dependency> |
||||
<groupId>commons-fileupload</groupId> |
||||
<artifactId>commons-fileupload</artifactId> |
||||
<version>1.4</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>junit</groupId> |
||||
<artifactId>junit</artifactId> |
||||
<version>4.12</version> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>commons-io</groupId> |
||||
<artifactId>commons-io</artifactId> |
||||
<version>2.6</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.alibaba</groupId> |
||||
<artifactId>fastjson</artifactId> |
||||
<version>1.2.7</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.httpcomponents</groupId> |
||||
<artifactId>httpmime</artifactId> |
||||
<version>4.5.6</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>dom4j</groupId> |
||||
<artifactId>dom4j</artifactId> |
||||
<version>1.6.1</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.poi</groupId> |
||||
<artifactId>poi</artifactId> |
||||
<version>4.1.2</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.poi</groupId> |
||||
<artifactId>poi-ooxml</artifactId> |
||||
<version>4.1.2</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.poi</groupId> |
||||
<artifactId>poi-ooxml-schemas</artifactId> |
||||
<version>4.1.2</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.google.zxing</groupId> |
||||
<artifactId>core</artifactId> |
||||
<version>3.3.0</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.aliyun</groupId> |
||||
<artifactId>aliyun-java-sdk-core</artifactId> |
||||
<version>4.1.0</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.google.zxing</groupId> |
||||
<artifactId>javase</artifactId> |
||||
<version>3.3.0</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.google.code.gson</groupId> |
||||
<artifactId>gson</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.slf4j</groupId> |
||||
<artifactId>slf4j-api</artifactId> |
||||
<version>1.7.7</version> |
||||
</dependency> |
||||
<!-- https://mvnrepository.com/artifact/com.alipay.sdk/alipay-sdk-java --> |
||||
<dependency> |
||||
<groupId>com.alipay.sdk</groupId> |
||||
<artifactId>alipay-sdk-java</artifactId> |
||||
<version>4.9.79.ALL</version> |
||||
</dependency> |
||||
<!-- https://mvnrepository.com/artifact/com.thoughtworks.xstream/xstream --> |
||||
<dependency> |
||||
<groupId>com.thoughtworks.xstream</groupId> |
||||
<artifactId>xstream</artifactId> |
||||
<version>1.4.11.1</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.github.binarywang</groupId> |
||||
<artifactId>weixin-java-miniapp</artifactId> |
||||
<version>3.8.0</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.alibaba</groupId> |
||||
<artifactId>easyexcel</artifactId> |
||||
<version>2.2.6</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.github.wechatpay-apiv3</groupId> |
||||
<artifactId>wechatpay-apache-httpclient</artifactId> |
||||
<version>0.2.2</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.sun.jersey</groupId> |
||||
<artifactId>jersey-client</artifactId> |
||||
<version>1.16</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>com.alicp.jetcache</groupId> |
||||
<artifactId>jetcache-starter-redis</artifactId> |
||||
<version>2.5.0</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.projectlombok</groupId> |
||||
<artifactId>lombok</artifactId> |
||||
</dependency> |
||||
</dependencies> |
||||
<build> |
||||
<resources> |
||||
<resource> |
||||
<directory>src/main/resources/${env}</directory> |
||||
<filtering>false</filtering> |
||||
</resource> |
||||
</resources> |
||||
</build> |
||||
</project> |
@ -0,0 +1,42 @@ |
||||
package com.hfkj.common; |
||||
|
||||
import java.util.Base64; |
||||
|
||||
public class Base64Util { |
||||
/** |
||||
* @param data |
||||
* @return str |
||||
* @throws Exception |
||||
*/ |
||||
public static String encode(String data) throws Exception{ |
||||
// String encodeBase64 = new BASE64Encoder().encode(data.getBytes("utf-8"));
|
||||
String encodeBase64 = Base64.getEncoder().encodeToString(data.getBytes("utf-8")); |
||||
String safeBase64Str = encodeBase64.replace('+', '-'); |
||||
safeBase64Str = safeBase64Str.replace('/', '_'); |
||||
safeBase64Str = safeBase64Str.replaceAll("=", ""); |
||||
return safeBase64Str.replaceAll("\\s*", ""); |
||||
} |
||||
|
||||
/** |
||||
* @param safeBase64Str |
||||
* @return str |
||||
* @throws Exception |
||||
*/ |
||||
public static String decode(final String safeBase64Str) throws Exception{ |
||||
String base64Str = safeBase64Str.replace('-', '+'); |
||||
base64Str = base64Str.replace('_', '/'); |
||||
int mod4 = base64Str.length() % 4; |
||||
if(mod4 > 0){ |
||||
base64Str += "====".substring(mod4); |
||||
} |
||||
|
||||
// byte[] ret = new BASE64Decoder().decodeBuffer(base64Str);
|
||||
byte[] ret = Base64.getDecoder().decode(base64Str); |
||||
return new String(ret, "utf-8"); |
||||
} |
||||
|
||||
public static void main(String[] args) throws Exception { |
||||
System.out.println(encode("abcd1234")); |
||||
System.out.println(decode("YWJjZDEyMzQ")); |
||||
} |
||||
} |
@ -0,0 +1,43 @@ |
||||
package com.hfkj.common; |
||||
|
||||
import com.google.zxing.BarcodeFormat; |
||||
import com.google.zxing.WriterException; |
||||
import com.google.zxing.client.j2se.MatrixToImageWriter; |
||||
import com.google.zxing.common.BitMatrix; |
||||
import com.google.zxing.qrcode.QRCodeWriter; |
||||
|
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
|
||||
/** |
||||
* @Auther: 胡锐 |
||||
* @Description: 生成二维码 |
||||
* @Date: 2021/3/27 12:07 |
||||
*/ |
||||
public class QRCodeGenerator { |
||||
|
||||
public static void generateQRCodeImage(String text, int width, int height, String filePath) throws WriterException, IOException { |
||||
QRCodeWriter qrCodeWriter = new QRCodeWriter(); |
||||
|
||||
BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height); |
||||
|
||||
File file = new File(filePath); |
||||
if(!file.exists()){ |
||||
file.mkdirs(); |
||||
} |
||||
//Path path = FileSystems.getDefault().getPath(filePath);
|
||||
MatrixToImageWriter.writeToFile(bitMatrix, "PNG", file); |
||||
|
||||
} |
||||
|
||||
public static void main(String[] args) { |
||||
try { |
||||
generateQRCodeImage("This is my first QR Code", 350, 350, "D:\\/ss/qr1.png"); |
||||
} catch (WriterException e) { |
||||
System.out.println("Could not generate QR Code, WriterException :: " + e.getMessage()); |
||||
} catch (IOException e) { |
||||
System.out.println("Could not generate QR Code, IOException :: " + e.getMessage()); |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,10 @@ |
||||
package com.hfkj.common.exception; |
||||
|
||||
/** |
||||
* 数据异常,只影响部分功能的异常,例如本应该为x的数据,莫名其妙为Y |
||||
*/ |
||||
public class AppException extends BaseException { |
||||
AppException(String errorCode, String errorMsg) { |
||||
super(errorCode,errorMsg); |
||||
} |
||||
} |
@ -0,0 +1,23 @@ |
||||
package com.hfkj.common.exception; |
||||
|
||||
/** |
||||
* sl框架基础异常,不允许自己new实例,需要同步工具类进行实例化 |
||||
*/ |
||||
public class BaseException extends RuntimeException { |
||||
protected String errorCode; |
||||
protected String errorMsg; |
||||
|
||||
BaseException(String errorCode, String errorMsg) { |
||||
super("errorCode="+errorCode+", errorMsg="+errorMsg); |
||||
this.errorCode = errorCode; |
||||
this.errorMsg = errorMsg; |
||||
} |
||||
|
||||
public String getErrorCode() { |
||||
return errorCode; |
||||
} |
||||
|
||||
public String getErrorMsg() { |
||||
return errorMsg; |
||||
} |
||||
} |
@ -0,0 +1,10 @@ |
||||
package com.hfkj.common.exception; |
||||
|
||||
/** |
||||
* 用户操作异常 |
||||
*/ |
||||
public class BizException extends BaseException { |
||||
BizException(String errorCode, String errorMsg) { |
||||
super(errorCode,errorMsg); |
||||
} |
||||
} |
@ -0,0 +1,66 @@ |
||||
package com.hfkj.common.exception; |
||||
|
||||
/** |
||||
* |
||||
* @ClassName: ErrorCode |
||||
* @Description: |
||||
* 代码code规则: |
||||
* 0000-0999 系统异常 |
||||
* 1000-1999 app异常 |
||||
* 2000-2999 biz异常 |
||||
* 999999 未知异常 |
||||
* @author: 机器猫 |
||||
* @date: 2018年8月12日 上午11:43:30 |
||||
* |
||||
* @Copyright: 2018 www.shinwoten.com Inc. All rights reserved. |
||||
*/ |
||||
public enum ErrorCode { |
||||
|
||||
//////////////////sys////////////////
|
||||
DB_CONNECT_ERROR("0000","数据库连接异常"), |
||||
FTP_CONNECT_ERROR("0001","FTP服务器连接失败"), |
||||
FTP_CONFIG_NOT_FOUND("0002","FTP服务地址路径配置缺失"), |
||||
|
||||
//////////////////APP///////////////
|
||||
WECHAT_DECRYPT_ERROR("3001","微信解密错误->%s"), |
||||
WECHAT_LOGIN_ERROR("3002","微信登录失败"), |
||||
WECHAT_LOGIN_TEACHER_ERROR("3003","当前微信用户不是老师,请联系管理员"), |
||||
SERVER_BUSY_ERROR("3004","服务器繁忙,请稍后重试"), |
||||
|
||||
//////////////////业务异常/////////////
|
||||
COMMON_ERROR("2000",""), |
||||
REQ_PARAMS_ERROR("2001","请求参数校验失败"), |
||||
ACCOUNT_LOGIN_EXPIRE("2002","登录账户已过期"), |
||||
ACCOUNT_LOGIN_NOT("2003","账户未登录"), |
||||
|
||||
MSG_EVENT_NULL("2999","消息类型为空"), |
||||
USE_VISIT_ILLEGAL("4001","用户身份错误"), |
||||
RC_VISIT_ERROR("2998",""), |
||||
UNKNOW_ERROR("999999","未知异常"), |
||||
EXCEL_ERROR("80000","Excel处理异常"), |
||||
;//注意:上面为逗号,此次为分号
|
||||
|
||||
|
||||
private String code; |
||||
private String msg; |
||||
ErrorCode(String code, String msg){ |
||||
this.code = code; |
||||
this.msg = msg; |
||||
} |
||||
|
||||
public String getCode() { |
||||
return code; |
||||
} |
||||
|
||||
// public void setCode(String code) {
|
||||
// this.code = code;
|
||||
// }
|
||||
|
||||
public String getMsg() { |
||||
return msg; |
||||
} |
||||
|
||||
// public void setMsg(String msg) {
|
||||
// this.msg = msg;
|
||||
// }
|
||||
} |
@ -0,0 +1,23 @@ |
||||
package com.hfkj.common.exception; |
||||
|
||||
public class ErrorHelp { |
||||
|
||||
public static BaseException genException(SysCode sc, ErrorCode ec, Object... args){ |
||||
String errorCode = sc.getCode()+ec.getCode(); |
||||
StringBuilder sb = new StringBuilder(); |
||||
if (args != null && args.length != 0) { |
||||
for(Object o : args){ |
||||
sb.append(o.toString()); |
||||
} |
||||
} |
||||
String errorMsg = ec.getMsg()+sb.toString();//@TODO 这里需要处理变参
|
||||
char a = ec.getCode().charAt(0); |
||||
if (a == '0') {//系统异常
|
||||
return new SysException(errorCode,errorMsg); |
||||
} else if (a == '1') {//APP异常
|
||||
return new AppException(errorCode,errorMsg); |
||||
} else {//业务异常
|
||||
return new BizException(errorCode,errorMsg); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,24 @@ |
||||
package com.hfkj.common.exception; |
||||
|
||||
public enum SysCode { |
||||
System("10","System"), |
||||
Auth("20","Auth"), |
||||
MiniProgram("30","小程序"); |
||||
|
||||
private String code; |
||||
private String name; |
||||
|
||||
SysCode(String code,String name){ |
||||
this.code = code; |
||||
this.name = name; |
||||
} |
||||
|
||||
public String getCode(){ |
||||
return this.code; |
||||
} |
||||
|
||||
public String getName() { |
||||
return this.name; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,10 @@ |
||||
package com.hfkj.common.exception; |
||||
|
||||
/** |
||||
* 系统异常,例如网络断开,数据库不可访问等影响系统正常运行的异常 |
||||
*/ |
||||
public class SysException extends BaseException { |
||||
SysException(String errorCode, String errorMsg) { |
||||
super(errorCode,errorMsg); |
||||
} |
||||
} |
@ -0,0 +1,72 @@ |
||||
package com.hfkj.common.pay; |
||||
|
||||
import com.hfkj.common.pay.entity.WeChatPayReqInfo; |
||||
import com.hfkj.common.pay.entity.WechatCallBackInfo; |
||||
import com.hfkj.common.pay.util.HttpReqUtil; |
||||
import com.hfkj.common.pay.util.SignatureUtil; |
||||
import com.hfkj.common.pay.util.XmlUtil; |
||||
import com.hfkj.service.pay.PayRecordService; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Component; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.Map; |
||||
import java.util.SortedMap; |
||||
import java.util.TreeMap; |
||||
|
||||
@Component |
||||
public class WechatPayUtil { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(WechatPayUtil.class); |
||||
@Resource |
||||
private PayRecordService payRecordService; |
||||
|
||||
/** |
||||
* @throws |
||||
* @Title: goAlipay |
||||
* @Description: 微信支付请求体 |
||||
* @author: 魏真峰 |
||||
* @param: [orderId] |
||||
* @return: java.lang.String |
||||
*/ |
||||
@RequestMapping("/goWechatPay") |
||||
@ResponseBody |
||||
public SortedMap<Object,Object> goWechatPay(WeChatPayReqInfo weChatPayReqInfo, Map<String,String> map) throws Exception{ |
||||
log.info("微信支付 -> 组装支付参数:开始"); |
||||
|
||||
String sign = SignatureUtil.createSign(weChatPayReqInfo, map.get("api_key"), "UTF-8"); |
||||
weChatPayReqInfo.setSign(sign); |
||||
String unifiedXmL = XmlUtil.toSplitXml(weChatPayReqInfo); |
||||
|
||||
String unifiedOrderResultXmL = HttpReqUtil.HttpsDefaultExecute("POST", map.get("unified_order_url"), null, unifiedXmL, null); |
||||
// 签名校验
|
||||
SortedMap<Object,Object> sortedMap = null; |
||||
if (SignatureUtil.checkIsSignValidFromWeiXin(unifiedOrderResultXmL, map.get("api_key"), "UTF-8")) { |
||||
// 组装支付参数
|
||||
WechatCallBackInfo wechatCallBackInfo = XmlUtil.getObjectFromXML(unifiedOrderResultXmL, WechatCallBackInfo.class); |
||||
Long timeStamp = System.currentTimeMillis()/1000; |
||||
sortedMap = new TreeMap<>(); |
||||
sortedMap.put("appId",map.get("app_id")); |
||||
// sortedMap.put("partnerid",SysConst.getSysConfig().getMch_id());
|
||||
// sortedMap.put("prepayid",wechatCallBackInfo.getPrepay_id());
|
||||
sortedMap.put("nonceStr",wechatCallBackInfo.getNonce_str()); |
||||
sortedMap.put("timeStamp",timeStamp.toString()); |
||||
sortedMap.put("signType","MD5"); |
||||
sortedMap.put("package", "prepay_id=" + wechatCallBackInfo.getPrepay_id()); |
||||
String secondSign = SignatureUtil.createSign(sortedMap, map.get("api_key"), "UTF-8"); |
||||
sortedMap.put("sign",secondSign); |
||||
|
||||
|
||||
log.info("微信支付 -> 组装支付参数:完成"); |
||||
} else { |
||||
log.error("微信支付 -> 组装支付参数:支付信息错误"); |
||||
log.error("错误信息:" + unifiedOrderResultXmL); |
||||
} |
||||
|
||||
return sortedMap; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,151 @@ |
||||
package com.hfkj.common.pay.entity; |
||||
|
||||
/** |
||||
* @Description: 支付宝統一下单参数 |
||||
*/ |
||||
public class AliPayReqInfo { |
||||
private String timeout_express; //该笔订单允许的最晚付款时间,逾期将关闭交易。取值范围:1m~15d。m-分钟,h-小时,d-天,1c-当天(1c-当天的情况下,无论交易何时创建,都在0点关闭)。 该参数数值不接受小数点, 如 1.5h,可转换为 90m。 90m
|
||||
private String total_amount; //必填。订单总金额,单位为元,精确到小数点后两位,取值范围[0.01,100000000] 9.00
|
||||
private String seller_id; //收款支付宝用户ID。 如果该值为空,则默认为商户签约账号对应的支付宝用户ID 2088102147948060
|
||||
private String product_code; //销售产品码,商家和支付宝签约的产品码 QUICK_MSECURITY_PAY
|
||||
private String body; //对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body。 Iphone6 16G
|
||||
private String subject; //必填。商品的标题/交易标题/订单标题/订单关键字等。 大乐透
|
||||
private String out_trade_no; //必填。商户网站唯一订单号 70501111111S001111119
|
||||
private String time_expire; //绝对超时时间,格式为yyyy-MM-dd HH:mm。 2016-12-31 10:05
|
||||
private String goods_type; //商品主类型 :0-虚拟类商品,1-实物类商品 0
|
||||
private String promo_params; //优惠参数
|
||||
private String passback_params; //必填。公用回传参数,如果请求时传递了该参数,则返回给商户时会回传该参数。支付宝只会在同步返回(包括跳转回商户网站)和异步通知时将该参数原样返回。本参数必须进行UrlEncode之后才可以发送给支付宝。 merchantBizType%3d3C%26merchantBizNo%3d2016010101111
|
||||
private String enable_pay_channels; //可用渠道,用户只能在指定渠道范围内支付
|
||||
private String store_id; //商户门店编号 NJ_001
|
||||
private String specified_channel; //指定渠道,目前仅支持传入pcredit
|
||||
private String disable_pay_channels; //禁用渠道,用户不可用指定渠道支付
|
||||
private String business_params; //商户传入业务信息,具体值要和支付宝约定,应用于安全,营销等参数直传场景,格式为json格式
|
||||
|
||||
public String getTimeout_express() { |
||||
return timeout_express; |
||||
} |
||||
|
||||
public void setTimeout_express(String timeout_express) { |
||||
this.timeout_express = timeout_express; |
||||
} |
||||
|
||||
public String getTotal_amount() { |
||||
return total_amount; |
||||
} |
||||
|
||||
public void setTotal_amount(String total_amount) { |
||||
this.total_amount = total_amount; |
||||
} |
||||
|
||||
public String getSeller_id() { |
||||
return seller_id; |
||||
} |
||||
|
||||
public void setSeller_id(String seller_id) { |
||||
this.seller_id = seller_id; |
||||
} |
||||
|
||||
public String getProduct_code() { |
||||
return product_code; |
||||
} |
||||
|
||||
public void setProduct_code(String product_code) { |
||||
this.product_code = product_code; |
||||
} |
||||
|
||||
public String getBody() { |
||||
return body; |
||||
} |
||||
|
||||
public void setBody(String body) { |
||||
this.body = body; |
||||
} |
||||
|
||||
public String getSubject() { |
||||
return subject; |
||||
} |
||||
|
||||
public void setSubject(String subject) { |
||||
this.subject = subject; |
||||
} |
||||
|
||||
public String getOut_trade_no() { |
||||
return out_trade_no; |
||||
} |
||||
|
||||
public void setOut_trade_no(String out_trade_no) { |
||||
this.out_trade_no = out_trade_no; |
||||
} |
||||
|
||||
public String getTime_expire() { |
||||
return time_expire; |
||||
} |
||||
|
||||
public void setTime_expire(String time_expire) { |
||||
this.time_expire = time_expire; |
||||
} |
||||
|
||||
public String getGoods_type() { |
||||
return goods_type; |
||||
} |
||||
|
||||
public void setGoods_type(String goods_type) { |
||||
this.goods_type = goods_type; |
||||
} |
||||
|
||||
public String getPromo_params() { |
||||
return promo_params; |
||||
} |
||||
|
||||
public void setPromo_params(String promo_params) { |
||||
this.promo_params = promo_params; |
||||
} |
||||
|
||||
public String getPassback_params() { |
||||
return passback_params; |
||||
} |
||||
|
||||
public void setPassback_params(String passback_params) { |
||||
this.passback_params = passback_params; |
||||
} |
||||
|
||||
public String getEnable_pay_channels() { |
||||
return enable_pay_channels; |
||||
} |
||||
|
||||
public void setEnable_pay_channels(String enable_pay_channels) { |
||||
this.enable_pay_channels = enable_pay_channels; |
||||
} |
||||
|
||||
public String getStore_id() { |
||||
return store_id; |
||||
} |
||||
|
||||
public void setStore_id(String store_id) { |
||||
this.store_id = store_id; |
||||
} |
||||
|
||||
public String getSpecified_channel() { |
||||
return specified_channel; |
||||
} |
||||
|
||||
public void setSpecified_channel(String specified_channel) { |
||||
this.specified_channel = specified_channel; |
||||
} |
||||
|
||||
public String getDisable_pay_channels() { |
||||
return disable_pay_channels; |
||||
} |
||||
|
||||
public void setDisable_pay_channels(String disable_pay_channels) { |
||||
this.disable_pay_channels = disable_pay_channels; |
||||
} |
||||
|
||||
public String getBusiness_params() { |
||||
return business_params; |
||||
} |
||||
|
||||
public void setBusiness_params(String business_params) { |
||||
this.business_params = business_params; |
||||
} |
||||
} |
@ -0,0 +1,46 @@ |
||||
package com.hfkj.common.pay.entity; |
||||
|
||||
public enum OrderType { |
||||
// 建议将支付频率高的模块放在前面
|
||||
GOODS_ORDER("GOODS_ORDER", "goodsOrderService", "购买商品"), |
||||
RECHARGE_ORDER("RECHARGE_ORDER", "rechargeOrderService", "充值订单"), |
||||
KFC_ORDER("KFC", "kfcOrderService", "KFC订单"), |
||||
CINEMA_ORDER("CINEMA", "cinemaOrderService", "电影票订单"), |
||||
MOBILE_ORDER("MOBILE", "mobileOrderService", "话费充值订单"), |
||||
TEST("TEST", "testPayService", "支付测试"), |
||||
; |
||||
|
||||
private String moduleCode; |
||||
private String service; |
||||
private String moduleName; |
||||
|
||||
private OrderType(String moduleCode, String service, String moduleName) { |
||||
this.moduleCode = moduleCode; |
||||
this.service = service; |
||||
this.moduleName = moduleName; |
||||
} |
||||
|
||||
public String getModuleCode() { |
||||
return moduleCode; |
||||
} |
||||
|
||||
private void setModuleCode(String moduleCode) { |
||||
this.moduleCode = moduleCode; |
||||
} |
||||
|
||||
public String getService() { |
||||
return service; |
||||
} |
||||
|
||||
private void setService(String service) { |
||||
this.service = service; |
||||
} |
||||
|
||||
public String getModuleName() { |
||||
return moduleName; |
||||
} |
||||
|
||||
private void setModuleName(String moduleName) { |
||||
this.moduleName = moduleName; |
||||
} |
||||
} |
@ -0,0 +1,240 @@ |
||||
package com.hfkj.common.pay.entity; |
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Description: 微信統一下单参数 |
||||
*/ |
||||
public class WeChatPayReqInfo implements Serializable { |
||||
|
||||
private static final long serialVersionUID = -7642108447915413137L; |
||||
private String appid; // 公众号id 必填
|
||||
private String mch_id; // 商户号 必填
|
||||
private String sub_appid; // 微信支付分配的子商户号 必填
|
||||
private String sub_mch_id; // 微信支付分配的子商户号 必填
|
||||
private String nonce_str; // 随机字符串 必填
|
||||
private String sign; // 签名 必填
|
||||
private String device_info; // 设备号 可以为终端设备号(门店号或收银设备ID),PC网页或公众号内支付可以传"WEB"
|
||||
private String body; // 商品描述 必填
|
||||
private String detail; // 商品详情
|
||||
private String attach; // 附加数据
|
||||
private String out_trade_no; // 商户订单号 必填
|
||||
private String fee_type; // 货币类型 默认为人民币CNY
|
||||
private Integer total_fee; // 总金额 传入int型的数据 必填
|
||||
private String spbill_create_ip; // 终端ip 必填
|
||||
private String time_start; // 交易起始时间 订单生成时间
|
||||
private String time_expire; // 交易结束时间 订单失效时间
|
||||
private String goods_tag; // 订单优惠标记
|
||||
private String notify_url; // 通知url 必填
|
||||
private String trade_type; // 交易类型 JSAPI,NATIVE,APP 必填
|
||||
private String product_id; //商品id trade_type=NATIVE时(即扫码支付),此参数必传
|
||||
private String limit_pay; // 指定支付方式 no_credit--可限制用户不能使用信用卡支付
|
||||
private String openid; // 用户标识(trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识)
|
||||
private String sub_openid; // 用户标识(trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识)
|
||||
private String profit_sharing; |
||||
|
||||
public String getProfit_sharing() { |
||||
return profit_sharing; |
||||
} |
||||
|
||||
public void setProfit_sharing(String profit_sharing) { |
||||
this.profit_sharing = profit_sharing; |
||||
} |
||||
|
||||
public String getSub_openid() { |
||||
return sub_openid; |
||||
} |
||||
|
||||
public void setSub_openid(String sub_openid) { |
||||
this.sub_openid = sub_openid; |
||||
} |
||||
|
||||
private String scene_info; // 该字段用于统一下单时上报场景信息,目前支持上报实际门店信息 格式{"store_id":// "SZT10000", "store_name":"腾讯大厦腾大餐厅"}
|
||||
|
||||
public static long getSerialVersionUID() { |
||||
return serialVersionUID; |
||||
} |
||||
|
||||
public String getAppid() { |
||||
return appid; |
||||
} |
||||
|
||||
public void setAppid(String appid) { |
||||
this.appid = appid; |
||||
} |
||||
|
||||
public String getMch_id() { |
||||
return mch_id; |
||||
} |
||||
|
||||
public void setMch_id(String mch_id) { |
||||
this.mch_id = mch_id; |
||||
} |
||||
|
||||
public String getNonce_str() { |
||||
return nonce_str; |
||||
} |
||||
|
||||
public void setNonce_str(String nonce_str) { |
||||
this.nonce_str = nonce_str; |
||||
} |
||||
|
||||
public String getSign() { |
||||
return sign; |
||||
} |
||||
|
||||
public void setSign(String sign) { |
||||
this.sign = sign; |
||||
} |
||||
|
||||
public String getDevice_info() { |
||||
return device_info; |
||||
} |
||||
|
||||
public void setDevice_info(String device_info) { |
||||
this.device_info = device_info; |
||||
} |
||||
|
||||
public String getBody() { |
||||
return body; |
||||
} |
||||
|
||||
public void setBody(String body) { |
||||
this.body = body; |
||||
} |
||||
|
||||
public String getDetail() { |
||||
return detail; |
||||
} |
||||
|
||||
public void setDetail(String detail) { |
||||
this.detail = detail; |
||||
} |
||||
|
||||
public String getAttach() { |
||||
return attach; |
||||
} |
||||
|
||||
public void setAttach(String attach) { |
||||
this.attach = attach; |
||||
} |
||||
|
||||
public String getOut_trade_no() { |
||||
return out_trade_no; |
||||
} |
||||
|
||||
public void setOut_trade_no(String out_trade_no) { |
||||
this.out_trade_no = out_trade_no; |
||||
} |
||||
|
||||
public String getFee_type() { |
||||
return fee_type; |
||||
} |
||||
|
||||
public void setFee_type(String fee_type) { |
||||
this.fee_type = fee_type; |
||||
} |
||||
|
||||
public Integer getTotal_fee() { |
||||
return total_fee; |
||||
} |
||||
|
||||
public void setTotal_fee(Integer total_fee) { |
||||
this.total_fee = total_fee; |
||||
} |
||||
|
||||
public String getSpbill_create_ip() { |
||||
return spbill_create_ip; |
||||
} |
||||
|
||||
public void setSpbill_create_ip(String spbill_create_ip) { |
||||
this.spbill_create_ip = spbill_create_ip; |
||||
} |
||||
|
||||
public String getTime_start() { |
||||
return time_start; |
||||
} |
||||
|
||||
public void setTime_start(String time_start) { |
||||
this.time_start = time_start; |
||||
} |
||||
|
||||
public String getTime_expire() { |
||||
return time_expire; |
||||
} |
||||
|
||||
public void setTime_expire(String time_expire) { |
||||
this.time_expire = time_expire; |
||||
} |
||||
|
||||
public String getGoods_tag() { |
||||
return goods_tag; |
||||
} |
||||
|
||||
public void setGoods_tag(String goods_tag) { |
||||
this.goods_tag = goods_tag; |
||||
} |
||||
|
||||
public String getNotify_url() { |
||||
return notify_url; |
||||
} |
||||
|
||||
public void setNotify_url(String notify_url) { |
||||
this.notify_url = notify_url; |
||||
} |
||||
|
||||
public String getTrade_type() { |
||||
return trade_type; |
||||
} |
||||
|
||||
public void setTrade_type(String trade_type) { |
||||
this.trade_type = trade_type; |
||||
} |
||||
|
||||
public String getProduct_id() { |
||||
return product_id; |
||||
} |
||||
|
||||
public void setProduct_id(String product_id) { |
||||
this.product_id = product_id; |
||||
} |
||||
|
||||
public String getLimit_pay() { |
||||
return limit_pay; |
||||
} |
||||
|
||||
public void setLimit_pay(String limit_pay) { |
||||
this.limit_pay = limit_pay; |
||||
} |
||||
|
||||
public String getOpenid() { |
||||
return openid; |
||||
} |
||||
|
||||
public void setOpenid(String openid) { |
||||
this.openid = openid; |
||||
} |
||||
|
||||
public String getScene_info() { |
||||
return scene_info; |
||||
} |
||||
|
||||
public void setScene_info(String scene_info) { |
||||
this.scene_info = scene_info; |
||||
} |
||||
|
||||
public String getSub_mch_id() { |
||||
return sub_mch_id; |
||||
} |
||||
|
||||
public void setSub_mch_id(String sub_mch_id) { |
||||
this.sub_mch_id = sub_mch_id; |
||||
} |
||||
|
||||
public String getSub_appid() { |
||||
return sub_appid; |
||||
} |
||||
|
||||
public void setSub_appid(String sub_appid) { |
||||
this.sub_appid = sub_appid; |
||||
} |
||||
} |
@ -0,0 +1,154 @@ |
||||
package com.hfkj.common.pay.entity; |
||||
|
||||
/** |
||||
* 统一下单返回结果 |
||||
* @author phil |
||||
* @data 2017年6月27日 |
||||
* |
||||
*/ |
||||
public class WechatCallBackInfo { |
||||
|
||||
private static final long serialVersionUID = 9030465964635155064L; |
||||
private String appid; // 公众号id
|
||||
private String mch_id; // 商户号
|
||||
private String nonce_str; // 随机字符串
|
||||
private String sign; // 签名
|
||||
private String return_code; // 返回状态码
|
||||
private String return_msg; // 返回信息
|
||||
// 以下字段在return_code为SUCCESS的时候有返回(包括父类)
|
||||
private String device_info; // 设备号
|
||||
private String result_code; // 业务结果 SUCCESS/FAIL
|
||||
private String err_code; // 错误代码
|
||||
private String err_code_des; // 错误代码描述
|
||||
// 以下字段在return_code 和result_code都为SUCCESS的时候有返回
|
||||
private String trade_type; // 交易类型
|
||||
private String prepay_id; // 预支付交易会话标识,有效期为2小时
|
||||
private String code_url; // 二维码链接
|
||||
|
||||
public static long getSerialVersionUID() { |
||||
return serialVersionUID; |
||||
} |
||||
|
||||
public String getAppid() { |
||||
return appid; |
||||
} |
||||
|
||||
public void setAppid(String appid) { |
||||
this.appid = appid; |
||||
} |
||||
|
||||
public String getMch_id() { |
||||
return mch_id; |
||||
} |
||||
|
||||
public void setMch_id(String mch_id) { |
||||
this.mch_id = mch_id; |
||||
} |
||||
|
||||
public String getNonce_str() { |
||||
return nonce_str; |
||||
} |
||||
|
||||
public void setNonce_str(String nonce_str) { |
||||
this.nonce_str = nonce_str; |
||||
} |
||||
|
||||
public String getSign() { |
||||
return sign; |
||||
} |
||||
|
||||
public void setSign(String sign) { |
||||
this.sign = sign; |
||||
} |
||||
|
||||
public String getReturn_code() { |
||||
return return_code; |
||||
} |
||||
|
||||
public void setReturn_code(String return_code) { |
||||
this.return_code = return_code; |
||||
} |
||||
|
||||
public String getReturn_msg() { |
||||
return return_msg; |
||||
} |
||||
|
||||
public void setReturn_msg(String return_msg) { |
||||
this.return_msg = return_msg; |
||||
} |
||||
|
||||
public String getDevice_info() { |
||||
return device_info; |
||||
} |
||||
|
||||
public void setDevice_info(String device_info) { |
||||
this.device_info = device_info; |
||||
} |
||||
|
||||
public String getResult_code() { |
||||
return result_code; |
||||
} |
||||
|
||||
public void setResult_code(String result_code) { |
||||
this.result_code = result_code; |
||||
} |
||||
|
||||
public String getErr_code() { |
||||
return err_code; |
||||
} |
||||
|
||||
public void setErr_code(String err_code) { |
||||
this.err_code = err_code; |
||||
} |
||||
|
||||
public String getErr_code_des() { |
||||
return err_code_des; |
||||
} |
||||
|
||||
public void setErr_code_des(String err_code_des) { |
||||
this.err_code_des = err_code_des; |
||||
} |
||||
|
||||
public String getTrade_type() { |
||||
return trade_type; |
||||
} |
||||
|
||||
public void setTrade_type(String trade_type) { |
||||
this.trade_type = trade_type; |
||||
} |
||||
|
||||
public String getPrepay_id() { |
||||
return prepay_id; |
||||
} |
||||
|
||||
public void setPrepay_id(String prepay_id) { |
||||
this.prepay_id = prepay_id; |
||||
} |
||||
|
||||
public String getCode_url() { |
||||
return code_url; |
||||
} |
||||
|
||||
public void setCode_url(String code_url) { |
||||
this.code_url = code_url; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "WechatCallBackInfo{" + |
||||
"appid='" + appid + '\'' + |
||||
", mch_id='" + mch_id + '\'' + |
||||
", nonce_str='" + nonce_str + '\'' + |
||||
", sign='" + sign + '\'' + |
||||
", return_code='" + return_code + '\'' + |
||||
", return_msg='" + return_msg + '\'' + |
||||
", device_info='" + device_info + '\'' + |
||||
", result_code='" + result_code + '\'' + |
||||
", err_code='" + err_code + '\'' + |
||||
", err_code_des='" + err_code_des + '\'' + |
||||
", trade_type='" + trade_type + '\'' + |
||||
", prepay_id='" + prepay_id + '\'' + |
||||
", code_url='" + code_url + '\'' + |
||||
'}'; |
||||
} |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue