Commit 98f484a0 authored by 周健威's avatar 周健威

Merge remote-tracking branch 'origin/base-modify' into base-modify

parents 630aee3b 220d969f
package com.github.wxiaoqi.security.common.util;
import java.util.Random;
/**
* 随机数工具
* @author Deacon
*
*/
public class RandomUtil
{
/**
* 获取随机数
*
* @param length 随机数长度
* @return
*/
public static String getRandomStr(int length)
{
// 根据长度, 计算需要相乘的数
int num = 1;
for (int i = 0; i < length; i++) {
num = num * 10;
}
// 保证随机数大于0.1
double random = Math.random();
if (random < 0.1) {
random = random + 0.1;
}
return String.valueOf((int) (random * num));
}
public static synchronized String gencRan(){
Random ran = new Random(System.nanoTime());
double nextDouble = ran.nextDouble();
return String.valueOf(nextDouble).substring(2, 6);
}
}
......@@ -17,8 +17,17 @@ public class SystemConfig {
public static String USER_HEADER_URL_DEFAULT = SystemProperty.getConfig("USER_HEADER_URL_DEFAULT");
// session有效时间
public static String USER_NIKENAME_DEFAULT = SystemProperty.getConfig("USER_NIKENAME_DEFAULT");
// 短信机key
public static String ACCESSKEYID = SystemProperty.getConfig("ACCESSKEYID");
// 短信机accske
public static String ACCESSKEYSECRET = SystemProperty.getConfig("ACCESSKEYSECRET");
//短信机code
public static String TEMPLATECODE = SystemProperty.getConfig("TEMPLATECODE");
// 短信机name
public static String SIGNNAME = SystemProperty.getConfig("SIGNNAME");
// 根据key名获取value
public static String getCongif(String key) {
return SystemProperty.getConfig(key);
}
}
......@@ -12,3 +12,8 @@ SESSION_TIME=3600
USER_HEADER_URL_DEFAULT=https://retail.xiaochengxucms.com/images/12/2018/11/fDK7kkrmkMReK50l4r1Le740Kmra8.jpg
#默认昵称
USER_NIKENAME_DEFAULT=XX_
#短信机
ACCESSKEYID=LTAIlXrgxOBAj2Ny
ACCESSKEYSECRET=zo8OkOCF4iygqOjYYoxRKfVRxDvgTI
TEMPLATECODE=SMS_166480010
SIGNNAME=升云
......@@ -35,6 +35,11 @@
<artifactId>ace-common</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.xxfc.platform</groupId>
<artifactId>xx-universal-api</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
......
......@@ -33,7 +33,7 @@ import java.util.List;
@EnableDiscoveryClient
@EnableCircuitBreaker
@SpringBootApplication
@EnableFeignClients({"com.github.wxiaoqi.security.auth.client.feign"})
@EnableFeignClients({"com.github.wxiaoqi.security.auth.client.feign", "com.xxfc.platform.universal.feign"})
@EnableScheduling
@EnableAceAuthClient
@EnableAceCache
......
......@@ -14,16 +14,15 @@ import com.github.wxiaoqi.security.common.util.VerificationUtils;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.github.wxiaoqi.security.common.util.process.SystemConfig;
import com.github.wxiaoqi.security.common.util.result.JsonResultUtil;
import com.xxfc.platform.universal.feign.ThirdFeign;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
......@@ -41,6 +40,9 @@ public class AppPermissionService {
@Autowired
ElementBiz elementBiz;
@Autowired
ThirdFeign thirdFeign;
private BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(12);
@Autowired
private RedisTemplate userRedisTemplate;
......@@ -125,31 +127,22 @@ public class AppPermissionService {
return JsonResultUtil.createFailedResult(ResultCode.EXIST_CODE, "手机号未注册");
}
// String sms = PassportUtil.SendSMS(phone, SystemConfig.SENDSMS_TITLE);
String mobilecode="123456";
String mobilecode=null;
JSONObject data=thirdFeign.send(phone);
if(data!=null&&data.getInteger("status")== ResultCode.SUCCESS_CODE){
mobilecode=data.getString("data");
}
log.info("调用短信发送接口返回值为:{}", mobilecode);
// 判断返回值是否为空,并且是否可以转换成JSONObject
if (StringUtils.isBlank(mobilecode))
return JsonResultUtil.createDefaultFail();
try {
/* JSONObject smsJSON = JSONObject.parseObject(sms);
if (smsJSON.getIntValue("error") != 0)
return JsonResultUtil.createDefaultFail();
JSONObject data = smsJSON.getJSONObject("data");
if (data == null)
return JsonResultUtil.createDefaultFail();
String mobilecode = data.getString("mobilecode");
if (mobilecode != null) {
result.put("mobilecode", mobilecode);
redisDao.set(phone + mobilecode, String.class, mobilecode, 300);
}*/
result.put("mobilecode", mobilecode);
// redisDao.set(phone + mobilecode, String.class, mobilecode, 300);
String redisLockKey = RedisKey.CONSTANT_CODE_PREFIX+phone+mobilecode;
Boolean suc = userRedisTemplate.opsForValue().setIfAbsent(redisLockKey, mobilecode);
if(suc){
userRedisTemplate.expire(redisLockKey,5, TimeUnit.MINUTES);//5分钟内过期
}
//userRedisTemplate.opsForValue().set(phone + mobilecode,mobilecode,300, TimeUnit.SECONDS);
} catch (Exception e) {
return JsonResultUtil.createFailedResult(ResultCode.EXCEPTION_CODE, "出现异常");
}
......
package com.xxfc.platform.universal.feign;
import com.alibaba.fastjson.JSONObject;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
/**
* ${DESCRIPTION}
*
* @author wanghaobin
* @create 2017-06-21 8:11
*/
@FeignClient(value = "xx-universal")
public interface ThirdFeign {
@RequestMapping(value = "/sms/app/unauth/send", method = RequestMethod.GET)
public JSONObject send(@RequestParam(value = "phone") String phone);
}
......@@ -18,6 +18,16 @@
<version>2.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.4.2</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-dysmsapi</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.xxfc.platform.universal.controller;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken;
import com.github.wxiaoqi.security.common.util.result.JsonResultUtil;
import com.xxfc.platform.universal.service.SmsService;
import com.xxfc.platform.universal.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
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.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.util.UUID;
/**
* Servlet implementation class FileDemo
*/
@RestController
@RequestMapping("sms")
@IgnoreUserToken
public class SmsController {
@Autowired
SmsService smsService;
@RequestMapping(value = "/app/unauth/send", method = RequestMethod.GET) //匹配的是href中的download请求
public JSONObject sendSms(@RequestParam("phone") String phone) throws Exception {
return smsService.smsCode(phone);
}
}
package com.xxfc.platform.universal.service;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.HttpResponse;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
import com.github.wxiaoqi.security.common.util.RandomUtil;
import com.github.wxiaoqi.security.common.util.process.SystemConfig;
import com.github.wxiaoqi.security.common.util.result.JsonResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Service
@Slf4j
public class SmsService {
//产品名称:云通信短信API产品,开发者无需替换
static final String product = "Dysmsapi";
//产品域名,开发者无需替换
static final String domain = "dysmsapi.aliyuncs.com";
// TODO 此处需要替换成开发者自己的AK(在阿里云访问控制台寻找)
static final String accessKeyId = SystemConfig.ACCESSKEYID;
static final String accessKeySecret = SystemConfig.ACCESSKEYSECRET;
//签名
static final String SignName = SystemConfig.SIGNNAME;
//短信模板id
static final String TemplateCode = SystemConfig.TEMPLATECODE;
static final String TemplateParam="{\"code\":\"str\"}";
public JSONObject smsCode(String mobile){
String code = RandomUtil.getRandomStr(6);// 6位短信验证码
try {
code=sendSms(mobile,code);
return JsonResultUtil.createSuccessResultWithObj(code);
} catch (ClientException e) {
e.printStackTrace();
return JsonResultUtil.createDefaultFail();
}
}
public String sendSms(String mobile, String code) throws ClientException {
//可自助调整超时时间
System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
System.setProperty("sun.net.client.defaultReadTimeout", "10000");
//初始化acsClient,暂不支持region化
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
IAcsClient acsClient = new DefaultAcsClient(profile);
//组装请求对象-具体描述见控制台-文档部分内容
SendSmsRequest request = new SendSmsRequest();
//必填:待发送手机号
request.setPhoneNumbers(mobile);
//必填:短信签名-可在短信控制台中找到
request.setSignName(SignName);
//必填:短信模板-可在短信控制台中找到
request.setTemplateCode(TemplateCode);
//可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
request.setTemplateParam(TemplateParam.replace("str",code));//\"name\":\"Tom\",
//选填-上行短信扩展码(无特殊需求用户请忽略此字段)
//request.setSmsUpExtendCode("90997");
//可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
//request.setOutId("yourOutId");
//hint 此处可能会抛出异常,注意catch
SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
log.info("短信接口返回的数据----------------");
log.info("Code=" + sendSmsResponse.getCode());
log.info("Message=" + sendSmsResponse.getMessage());
log.info("RequestId=" + sendSmsResponse.getRequestId());
log.info("BizId=" + sendSmsResponse.getBizId());
if(sendSmsResponse.getCode() != null && sendSmsResponse.getCode().equals("OK")) {
//请求成功
return code;
}
return null;
}
/* public static QuerySendDetailsResponse querySendDetails(String bizId) throws ClientException {
//可自助调整超时时间
System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
System.setProperty("sun.net.client.defaultReadTimeout", "10000");
//初始化acsClient,暂不支持region化
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
IAcsClient acsClient = new DefaultAcsClient(profile);
//组装请求对象
QuerySendDetailsRequest request = new QuerySendDetailsRequest();
//必填-号码
request.setPhoneNumber("15000000000");
//可选-流水号
request.setBizId(bizId);
//必填-发送日期 支持30天内记录查询,格式yyyyMMdd
SimpleDateFormat ft = new SimpleDateFormat("yyyyMMdd");
request.setSendDate(ft.format(new Date()));
//必填-页大小
request.setPageSize(10L);
//必填-当前页码从1开始计数
request.setCurrentPage(1L);
//hint 此处可能会抛出异常,注意catch
QuerySendDetailsResponse querySendDetailsResponse = acsClient.getAcsResponse(request);
return querySendDetailsResponse;
}
*/
public static void main(String[] args) throws ClientException, InterruptedException {
SmsService SmsService=new SmsService();
//发短信
String response = SmsService.sendSms("13612688539","123456");
/*System.out.println("短信接口返回的数据----------------");
System.out.println("Code=" + response.getCode());
System.out.println("Message=" + response.getMessage());
System.out.println("RequestId=" + response.getRequestId());
System.out.println("BizId=" + response.getBizId());*/
Thread.sleep(3000L);
/*
//查明细
if(response.getCode() != null && response.getCode().equals("OK")) {
QuerySendDetailsResponse querySendDetailsResponse = querySendDetails(response.getBizId());
System.out.println("短信明细查询接口返回数据----------------");
System.out.println("Code=" + querySendDetailsResponse.getCode());
System.out.println("Message=" + querySendDetailsResponse.getMessage());
int i = 0;
for(QuerySendDetailsResponse.SmsSendDetailDTO smsSendDetailDTO : querySendDetailsResponse.getSmsSendDetailDTOs())
{
System.out.println("SmsSendDetailDTO["+i+"]:");
System.out.println("Content=" + smsSendDetailDTO.getContent());
System.out.println("ErrCode=" + smsSendDetailDTO.getErrCode());
System.out.println("OutId=" + smsSendDetailDTO.getOutId());
System.out.println("PhoneNum=" + smsSendDetailDTO.getPhoneNum());
System.out.println("ReceiveDate=" + smsSendDetailDTO.getReceiveDate());
System.out.println("SendDate=" + smsSendDetailDTO.getSendDate());
System.out.println("SendStatus=" + smsSendDetailDTO.getSendStatus());
System.out.println("Template=" + smsSendDetailDTO.getTemplateCode());
}
System.out.println("TotalCount=" + querySendDetailsResponse.getTotalCount());
System.out.println("RequestId=" + querySendDetailsResponse.getRequestId());
}*/
}
}
......@@ -46,6 +46,16 @@ public class RedisKey {
*/
public static final String BRANCH_COMPANY_CACHE_ALL = BRANCH_COMPANY_CACHE + ":all";
/**
* 车型分类列表缓存key前缀
*/
public static final String BRANCH_CATA_CACHE ="cache:cata";
/**
* 车型分类列表缓存key前缀
*/
public static final String BRANCH_COMPANY_CATA_ALL = BRANCH_CATA_CACHE + ":all";
/**
* 片区对应的子公司缓存key前缀
*/
......
......@@ -2,12 +2,17 @@ package com.xxfc.platform.vehicle.biz;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.xxfc.platform.vehicle.common.RestResponse;
import com.xxfc.platform.vehicle.entity.VehicleCata;
import com.xxfc.platform.vehicle.mapper.VehicleCataMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import java.util.ArrayList;
import java.util.List;
@Service
......@@ -17,15 +22,36 @@ public class VehicleCataBiz extends BaseBiz<VehicleCataMapper, VehicleCata> {
//添加车辆配置
@Transactional
public void updateCataByModel(String ids,Integer modelId){
public RestResponse updateCataByModel(String ids, Integer modelId){
String [] cataIds=ids.split(",");
if(cataIds.length>0){
for (String cataId:cataIds) {
List<Integer> array=new ArrayList<>();
List<VehicleCata> all=new ArrayList<>();
for (String str:cataIds) {
Integer cataId=Integer.parseInt(str);
VehicleCata vehicleCata=mapper.getOne(modelId,cataId);
array.add(cataId);
if(vehicleCata==null){
vehicleCata=new VehicleCata();
vehicleCata.setCataId(cataId);
vehicleCata.setVehicleModelId(modelId);
vehicleCata.setCrtTime(System.currentTimeMillis());
vehicleCata.setUpdTime(System.currentTimeMillis());
all.add(vehicleCata);
continue;
}
}
if(array.size()>0){
mapper.delList(array,modelId);
}
if(all.size()>0){
mapper.addCataList(all);
}
}
return RestResponse.suc();
}
......
......@@ -37,7 +37,7 @@ public class VehicleLicenseBiz extends BaseBiz<VehicleLicenseMapper, VehicleUser
public PageDataVO<VehicleUserLicense> getAllByUserid(Integer page, Integer limit, Integer userid){
Example example = new Example(VehicleUserLicense.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("userid",userid);
criteria.andEqualTo("userid",userid).andEqualTo("isdel",0);
example.setOrderByClause("`id` desc");
PageHelper.startPage(page,limit);
PageInfo<VehicleUserLicense> campsitePageInfo = new PageInfo<VehicleUserLicense>(mapper.selectByExample(example));
......
package com.xxfc.platform.vehicle.biz;
import com.ace.cache.annotation.Cache;
import com.ace.cache.annotation.CacheClear;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.xxfc.platform.vehicle.common.RestResponse;
import com.xxfc.platform.vehicle.constant.RedisKey;
import com.xxfc.platform.vehicle.entity.VehiclePlatCata;
import com.xxfc.platform.vehicle.mapper.VehiclePlatCataMapper;
import com.xxfc.platform.vehicle.vo.CataVo;
......@@ -25,6 +28,7 @@ public class VehiclePlatCataBiz extends BaseBiz<VehiclePlatCataMapper, VehiclePl
//更新
@Transactional
@CacheClear(pre = RedisKey.BRANCH_CATA_CACHE)
public RestResponse update(CataVo cataVo){
VehiclePlatCata vehiclePlatCata = new VehiclePlatCata();
BeanUtils.copyProperties(cataVo,vehiclePlatCata);
......@@ -41,6 +45,7 @@ public class VehiclePlatCataBiz extends BaseBiz<VehiclePlatCataMapper, VehiclePl
* 获取无限级的类别资源
*/
@Transactional
@Cache(key = RedisKey.BRANCH_COMPANY_CATA_ALL)
public JSONObject findTypeTree() throws Exception {
//默认查询出所有的一级类别
JSONObject obj = new JSONObject();
......
package com.xxfc.platform.vehicle.mapper;
import com.xxfc.platform.vehicle.entity.VehicleCata;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;
/**
* 平台车型分类表
*
......@@ -12,4 +15,13 @@ import tk.mybatis.mapper.common.Mapper;
*/
public interface VehicleCataMapper extends Mapper<VehicleCata> {
//批量删除
int delList(@Param("list") List<Integer> list,@Param("vehicleModelId")Integer vehicleModelId);
//批量新增
int addCataList(@Param("list") List<VehicleCata> list);
//获取一条
VehicleCata getOne(@Param("vehicleModelId")Integer vehicleModelId,@Param("cataId")Integer cataId );
}
......@@ -36,6 +36,9 @@ import java.util.List;
public class VehicleCataController extends VehicleBaseController<VehiclePlatCataBiz> {
@Autowired
VehicleCataBiz vehicleCataBiz;
@RequestMapping(value = "/update", method = RequestMethod.POST)
public RestResponse update(@RequestBody CataVo cataVo) throws Exception {
......@@ -54,6 +57,18 @@ public class VehicleCataController extends VehicleBaseController<VehiclePlatCata
return RestResponse.data(baseBiz.findTypeTree());
}
@RequestMapping(value = "/bind", method = RequestMethod.POST)
public RestResponse bind(
@RequestParam(value = "ids",defaultValue = "") String ids,
@RequestParam(value = "modelId",defaultValue = "0") Integer modelId
) throws Exception {
return vehicleCataBiz.updateCataByModel(ids,modelId);
}
......
......@@ -23,8 +23,18 @@
</insert>
<select id="getOne" resultMap="vehicleCataMap">
SELECT * FROM vehicle_cata WHERE vehicle_model_id=#{vehicleModelId} AND cata_id=#{cataId} limit 1
SELECT * FROM vehicle_cata WHERE vehicle_model_id=#{vehicleModelId} AND cata_id=#{cataId} and isdel=0 limit 1
</select>
<update id="delList">
update vehicle_cata set isdel=1 where cata_id not in (
<trim suffixOverrides=",">
<foreach collection ="list" item="cataId">
#{cataId},
</foreach>
</trim>
) and vehicle_model_id=#{vehicleModelId}
</update>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment