Commit 3329cd46 authored by jiaorz's avatar jiaorz

Merge branch 'base-modify' of http://113.105.137.151:22280/youjj/cloud-platform into base-modify

parents 80757579 eb427261
......@@ -2,6 +2,7 @@ package com.github.wxiaoqi.security.auth;
import com.github.wxiaoqi.security.api.vo.config.HeaderConfig;
import com.github.wxiaoqi.security.auth.feign.IUserService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
......
......@@ -12,7 +12,7 @@ public class ClientConfiguration {
private String clientId;
@Value("${client.secret}")
private String clientSecret;
@Value("${client.token-header}")
@Value("${client.token-header:Authorization}")
private String clientTokenHeader;
public String getClientTokenHeader() {
......
......@@ -5,6 +5,9 @@ import com.github.wxiaoqi.security.auth.service.AuthService;
import com.github.wxiaoqi.security.auth.util.user.JwtAuthenticationRequest;
import com.github.wxiaoqi.security.common.constant.RequestTypeConstants;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.ClientUtil;
import com.github.wxiaoqi.security.common.util.EntityUtils;
import com.github.wxiaoqi.security.common.util.IpUtil;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
......@@ -12,6 +15,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
......@@ -135,6 +141,7 @@ public class AuthController {
@RequestParam(value="password",defaultValue="")String password,
@RequestParam(value="type",defaultValue="1")Integer type)throws Exception{
log.info(username+"----require login...");
JSONObject data=appAuthService.tlogin(username,password,mobilecode,type);
if(data!=null&&data.getInteger("status")== ResultCode.SUCCESS_CODE){
JSONObject result=data.getJSONObject("data");
......
......@@ -2,11 +2,15 @@ package com.github.wxiaoqi.security.auth.interceptor;
import com.github.wxiaoqi.security.auth.configuration.ClientConfiguration;
import com.github.wxiaoqi.security.auth.service.AuthClientService;
import com.github.wxiaoqi.security.common.util.ClientUtil;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
/**
* Created by ace on 2017/9/12.
......@@ -21,7 +25,9 @@ public class ClientTokenInterceptor implements RequestInterceptor {
@Override
public void apply(RequestTemplate requestTemplate) {
try {
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
requestTemplate.header(clientConfiguration.getClientTokenHeader(), authClientService.apply(clientConfiguration.getClientId(), clientConfiguration.getClientSecret()));
requestTemplate.header("userHost", ClientUtil.getClientIp(requestAttributes.getRequest()));
} catch (Exception e) {
e.printStackTrace();
}
......
package com.xxfc.platform.order.interceptor;
package com.github.wxiaoqi.security.common.interceptor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.cors.CorsUtils;
......
......@@ -86,4 +86,6 @@ public class BaseController<Biz extends BaseBiz,Entity> extends CommonBaseContro
//查询列表数据
return ObjectRestResponse.succ(baseBiz.selectList(entity));
}
}
package com.github.wxiaoqi.security.common.util;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
public class IpUtil {
/**
* 获取服务器本地的ip地址
*
* @return
*/
public static String getLocalIp() {
InetAddress ip = null;
String localIp = "127.0.0.2";
try {
Enumeration netInterfaces = NetworkInterface.getNetworkInterfaces();
while (netInterfaces.hasMoreElements()) {
NetworkInterface ni = (NetworkInterface) netInterfaces
.nextElement();
ip = (InetAddress) ni.getInetAddresses().nextElement();
if (!ip.isLoopbackAddress()
&& ip.getHostAddress().indexOf(":") == -1) {
localIp = ip.getHostAddress();
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return localIp;
}
/**
* 获取客户机的ip地址
*
* @return
*/
public static String getClientIp(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
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.getRemoteAddr();
}
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");
}
// 如果是多级代理,那么取第一个ip为客户ip
if (ip != null && ip.indexOf(",") != -1) {
ip = ip.substring(ip.lastIndexOf(",") + 1, ip.length()).trim();
}
return ip;
}
public static long transIP2Int(String ip) {
String[] temp = ip.split("\\.");
int[] ipInt = new int[temp.length];
for (int i = 0; i < temp.length; i++) {
ipInt[i] = new Integer(temp[i]).intValue();
}
long ipNum = (long) ipInt[0] * 256 * 256 * 256 + ipInt[1] * 256 * 256
+ ipInt[2] * 256 + ipInt[3];
return ipNum;
}
}
package com.github.wxiaoqi.security.admin.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
* 用户信息表
*/
@Data
public class AppUserManageDTO {
/**
* 每页条数
*/
private Integer limit;
/**
* 当前页数
*/
private Integer page;
/**
* 手机号
*/
private Integer mobile;
/**
* 注册终端
*/
private Integer channel;
/**
* 会员等级
*/
private Integer memberLevel;
/**
* 注册时间(开始)
*/
@JsonFormat(pattern = "yyyy-MM-DD HH:mm", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-DD HH:mm")
private Date registrationTimeBegin;
/**
* 注册时间(结束)
*/
@JsonFormat(pattern = "yyyy-MM-DD HH:mm", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-DD HH:mm")
private Date registrationTimeEnd;
public Long getRegistrationTimeBegin() {
return registrationTimeBegin.getTime();
}
public Long getRegistrationTimeEnd() {
return registrationTimeEnd.getTime();
}
}
package com.github.wxiaoqi.security.admin.dto;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 用户会员信息
*/
@Data
public class BaseUserMemberVO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键id
*/
@Id
@GeneratedValue(generator = "JDBC")
@ApiModelProperty("主键id")
private Integer id;
/**
* 用户id
*/
@Column(name = "user_id")
@ApiModelProperty(value = "用户id")
private Integer userId;
/**
* 会员等级
*/
@Column(name = "member_level")
@ApiModelProperty(value = "会员等级")
private Integer memberLevel;
/**
* 赠送总天数
*/
@Column(name = "total_number")
@ApiModelProperty(value = "赠送总天数")
private Integer totalNumber;
/**
* 剩余天数
*/
@Column(name = "rent_free_days")
@ApiModelProperty(value = "剩余天数")
private Integer rentFreeDays;
/**
* 购买会员次数
*/
@Column(name = "buy_count")
@ApiModelProperty(value = "购买会员次数")
private Integer buyCount;
/**
* 有效期;0代表永久
*/
@Column(name = "valid_time")
@ApiModelProperty(value = "有效期;0代表永久")
private Long validTime;
}
......@@ -32,5 +32,26 @@ public class AppUserDetail {
private Long updatetime;
private Integer isdel;
private Integer channel;
/**
* 省份编号
*/
@Column(name = "province_code")
private Integer provinceCode;
/**
* 市编号
*/
@Column(name = "city_code")
private Integer cityCode;
/**
* 创建ip
*/
@Column(name = "crt_host")
private String crtHost;
/**
* 更新ip
*/
@Column(name = "upd_host")
private String updHost;
}
......@@ -35,39 +35,15 @@ public class AppUserLogin {
private String idNumber;
@Column(name = "certification_status")
private Integer certificationStatus;
/**
* 创建ip
*/
@Column(name = "crt_host")
private String crtHost;
/**
* 更新ip
*/
@Column(name = "upd_host")
private String updHost;
/**
* 最后登录ip
*/
@Column(name = "last_host")
private String lastHost;
/**
* 最后登录时间
*/
@Column(name = "last_time")
private Long lastTime;
/**
* 省份编号
*/
@Column(name = "province_code")
private Integer provinceCode;
/**
* 市编号
*/
@Column(name = "city_code")
private Integer cityCode;
}
......@@ -132,6 +132,9 @@ public class BaseUserMember implements Serializable {
@Column(name = "is_del")
@ApiModelProperty(value = "是否删除;0-正常;1-删除")
private Integer isDel;
@Column(name = "recent_recharge")
private Long recentRecharge;
}
package com.github.wxiaoqi.security.admin.vo;
import lombok.Data;
import javax.persistence.Column;
/**
* 用户信息表
*/
@Data
public class AppUserManageVo {
/**
* 用户id
*/
@Column(name = "userid")
private Integer userId;
/**
* 注册终端
*/
@Column(name = "channel")
private String channel;
/**
* 是否是会员:0-不是;1-会员
*/
@Column(name = "is_member")
private Integer isMember;
/**
* 真实姓名
*/
@Column(name = "realname")
private String realName;
/**
* 状态:0-正常,1-禁用
*/
@Column(name = "isdel")
private Integer isDel;
/**
* 昵称
*/
@Column(name = "nickname")
private String nickName;
/**
* 用户来源:0-自来,1-公司人员推荐,2-用户推荐
*/
@Column(name = "source")
private Integer source;
/**
* 邀请人id
*/
@Column(name = "Inviter_account")
private Integer InviterAccount;
/**
* 账号申请所在地
*/
@Column(name = "address")
private String address;
/**
* 用户性别
*/
@Column(name = "sex")
private Integer sex;
/**
* 用户邮箱
*/
@Column(name = "email")
private String email;
/**
* 用户名(手机号码)
*/
@Column(name = "username")
private String username;
/**
* 实名认证状态:0-未认证,1-已认证
*/
@Column(name = "certification_status")
private String certification_status;
/**
* 身份证号
*/
@Column(name = "id_number")
private String idNumber;
/**
* 会员等级
*/
@Column(name = "member_level")
private Integer memberLevel;
/**
* 有效期;0代表永久
*/
@Column(name = "valid_time")
private Integer validTime;
/**
* 创建时间
*/
@Column(name = "createtime")
private Long createTime;
/**
* 最后的登录时间
*/
@Column(name = "last_time")
private Long lastTime;
/**
* 购买会员次数
*/
@Column(name = "buy_count")
private String buyCount;
/**
* 赠送总天数
*/
@Column(name = "total_number")
private String totalNumber;
/**
* 剩余天数
*/
@Column(name = "rent_free_days")
private String rentFreeDays;
/**
* 加入会员时间
*/
private Long timeOfMembership;
/**
* 最近充值时间
*/
@Column(name = "recent_recharge")
private Long recentRecharge;
/**
* 会员名称
*/
private String memberName;
}
......@@ -4,12 +4,15 @@ import com.ace.cache.annotation.Cache;
import com.ace.cache.annotation.CacheClear;
import com.github.wxiaoqi.security.admin.entity.AppUserDetail;
import com.github.wxiaoqi.security.admin.mapper.AppUserDetailMapper;
import com.github.wxiaoqi.security.admin.rpc.service.AppPermissionService;
import com.github.wxiaoqi.security.admin.vo.AppUserVo;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import java.time.Instant;
import java.util.List;
/**
......@@ -64,6 +67,8 @@ public class AppUserDetailBiz extends BaseBiz<AppUserDetailMapper, AppUserDetail
try {
BeanUtils.copyProperties(entity,userVo);
if(entity!=null){
entity.setUpdHost(AppPermissionService.getIp());
entity.setUpdatetime(Instant.now().toEpochMilli());
super.updateSelectiveById(entity);
}
} catch (Exception e) {
......
package com.github.wxiaoqi.security.admin.biz;
import com.github.wxiaoqi.security.admin.dto.AppUserManageDTO;
import com.github.wxiaoqi.security.admin.entity.*;
import com.github.wxiaoqi.security.admin.mapper.*;
import com.github.wxiaoqi.security.admin.vo.AppUserManageVo;
import com.github.wxiaoqi.security.admin.vo.AppUserVo;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import org.apache.commons.beanutils.BeanUtilsBean;
......@@ -24,42 +26,58 @@ public class AppUserManageBiz extends BaseBiz<AppUserDetailMapper, AppUserDetail
@Autowired
private AppUserLoginMapper appUserLoginMapper;
@Autowired
private BaseUserMemberMapper baseUserMemberMapper;
/**
* 根据条件查询
*
* @param appUserVo
* @param appUserManageDTO 查询条件
* @return
*/
public AppUserVo findAllByQuery(AppUserVo appUserVo) {
return mapper.selectAppUserManage(appUserVo);
public AppUserManageVo findAllByQuery(AppUserManageDTO appUserManageDTO) {
return mapper.selectAppUserManage(appUserManageDTO);
}
@Transactional
public void deleteAppUser(Integer id) {
/**
* 禁用账户
* @param id
*/
@Transactional(rollbackFor =Exception.class)
public void deleteAppUser(Integer id,Integer isDel) {
AppUserLogin appUserLogin = new AppUserLogin();
appUserLogin.setIsdel(1);
//修改为禁用并设置修改时间
appUserLogin.setIsdel(isDel);
appUserLogin.setUpdatetime(System.currentTimeMillis());
Example example = new Example(AppUserLogin.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("id", id);
appUserLogin.setUpdatetime(System.currentTimeMillis());
appUserLoginMapper.updateByExampleSelective(appUserLogin, example);
//设置
AppUserDetail appUserDetail = new AppUserDetail();
appUserDetail.setIsdel(1);
appUserDetail.setIsdel(isDel);
appUserDetail.setUpdatetime(System.currentTimeMillis());
Example detailExample = new Example(AppUserLogin.class);
Example.Criteria detailCriteria = detailExample.createCriteria();
criteria.andEqualTo("id", id);
mapper.updateByExampleSelective(appUserDetail, detailCriteria);
}
/**
* 查询一条
* @param id
* @return
*/
public AppUserVo findOneById(Integer id) {
return mapper.getUserInfo(id);
}
@Transactional
/**
*
* @param appUserVo
*/
@Transactional(rollbackFor =Exception.class)
public void save(AppUserVo appUserVo) {
AppUserLogin appUserLogin = new AppUserLogin();
AppUserDetail appUserDetail = new AppUserDetail();
......
......@@ -2,18 +2,28 @@ package com.github.wxiaoqi.security.admin.biz;
import com.ace.cache.annotation.Cache;
import com.ace.cache.annotation.CacheClear;
import com.github.wxiaoqi.security.admin.dto.BaseUserMemberVO;
import com.github.wxiaoqi.security.admin.dto.UserMemberDTO;
import com.github.wxiaoqi.security.admin.vo.AppUserVo;
import com.github.wxiaoqi.security.admin.vo.UserMemberVo;
import com.github.wxiaoqi.security.common.exception.BaseException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskExecutor;
import org.springframework.integration.amqp.dsl.Amqp;
import org.springframework.stereotype.Service;
import com.github.wxiaoqi.security.admin.entity.BaseUserMember;
import com.github.wxiaoqi.security.admin.mapper.BaseUserMemberMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.weekend.WeekendSqls;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
/**
* 用户会员表
......@@ -30,6 +40,9 @@ public class BaseUserMemberBiz extends BaseBiz<BaseUserMemberMapper,BaseUserMemb
@Autowired
AppUserDetailBiz detailBiz;
@Autowired
private TaskExecutor taskExecutor;
//获取用户会员信息
@Cache(key = "user:member{1}")
public UserMemberVo getMemberInfoByUserId(Integer userId){
......@@ -155,5 +168,56 @@ public class BaseUserMemberBiz extends BaseBiz<BaseUserMemberMapper,BaseUserMemb
return AopContext.currentProxy() != null ? (BaseUserMemberBiz) AopContext.currentProxy() : this;
}
/**
* 获取用户会员信息
* @param userId
* @return
*/
public BaseUserMember findOneByUserId(Integer userId) {
Example exa = new Example(BaseUserMember.class);
Example.Criteria criteria = exa.createCriteria();
criteria.andEqualTo("userId",userId);
List<BaseUserMember> baseUserMembers = mapper.selectByExample(exa);
if (baseUserMembers.size()>1) {
throw new BaseException("Member purchase repeat!");
}
return baseUserMembers!=null&&baseUserMembers.size()!=0 ? baseUserMembers.get(0): null;
}
/**
* 设置用户会员
* @param baseUserMemberVO
*/
@Transactional(rollbackFor = Exception.class)
public void setUserMember(BaseUserMemberVO baseUserMemberVO) throws InvocationTargetException, IllegalAccessException {
Example exa = Example.builder(BaseUserMember.class).where(
WeekendSqls.<BaseUserMember>custom()
.andEqualTo(BaseUserMember::getUserId, baseUserMemberVO.getUserId())
).build();
List<BaseUserMember> baseUserMembers = mapper.selectByExample(exa);
BaseUserMember baseUserMember = new BaseUserMember();
BeanUtilsBean.getInstance().copyProperties(baseUserMember,baseUserMemberVO);
if (baseUserMembers==null||baseUserMembers.size()==0) {
baseUserMember.setCrtTime(System.currentTimeMillis());
baseUserMember.setIsDel(0);
baseUserMember.setPayCount(0);
baseUserMember.setCardLeave(0);
baseUserMember.setRecentRecharge(System.currentTimeMillis());
insertSelective(baseUserMember);
return;
}else if (baseUserMembers.size()==1){
baseUserMember.setUpdTime(System.currentTimeMillis());
updateSelectiveById(baseUserMember);
}else {
throw new BaseException("Member purchase repeat!");
}
}
}
\ No newline at end of file
package com.github.wxiaoqi.security.admin.mapper;
import com.github.wxiaoqi.security.admin.dto.AppUserManageDTO;
import com.github.wxiaoqi.security.admin.entity.AppUserDetail;
import com.github.wxiaoqi.security.admin.entity.AppUserManage;
import com.github.wxiaoqi.security.admin.vo.AppUserManageVo;
import com.github.wxiaoqi.security.admin.vo.AppUserVo;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.Mapper;
......@@ -11,5 +12,5 @@ public interface AppUserDetailMapper extends Mapper<AppUserDetail> {
//查询用户信息
public AppUserVo getUserInfo(@Param("userId") Integer userId);
AppUserVo selectAppUserManage(AppUserVo appUserVo);
AppUserManageVo selectAppUserManage(AppUserManageDTO appUserManageDTO);
}
\ No newline at end of file
package com.github.wxiaoqi.security.admin.rest;
import com.github.wxiaoqi.security.admin.biz.AppUserManageBiz;
import com.github.wxiaoqi.security.admin.dto.AppUserManageDTO;
import com.github.wxiaoqi.security.admin.dto.BaseUserMemberVO;
import com.github.wxiaoqi.security.admin.entity.AppUserManage;
import com.github.wxiaoqi.security.admin.vo.AppUserManageVo;
import com.github.wxiaoqi.security.admin.vo.AppUserVo;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.BaseController;
......@@ -20,18 +23,18 @@ public class AppUsersManageController extends BaseController<AppUserManageBiz,Ap
* @return
*/
@GetMapping("/findAll")
public ObjectRestResponse<AppUserVo> findAllByQuery(@RequestBody AppUserVo appUserVo){
return ObjectRestResponse.succ(baseBiz.findAllByQuery(appUserVo));
public ObjectRestResponse<AppUserManageVo> findAllByQuery(@RequestBody AppUserManageDTO appUserManageDTO){
return ObjectRestResponse.succ(baseBiz.findAllByQuery(appUserManageDTO));
}
/**
* 删除
* 禁用
* @param id
* @return
*/
@DeleteMapping("/deleteById/{id}")
public ObjectRestResponse deleteById(@PathVariable Integer id){
baseBiz.deleteAppUser(id);
@DeleteMapping("/deleteById/{id}/{isDel}")
public ObjectRestResponse deleteById(@PathVariable Integer id,@PathVariable Integer isDel){
baseBiz.deleteAppUser(id,isDel);
return ObjectRestResponse.succ();
}
......@@ -45,6 +48,11 @@ public class AppUsersManageController extends BaseController<AppUserManageBiz,Ap
return ObjectRestResponse.succ(baseBiz.findOneById(id));
}
/**
* 保存
* @param appUserVo
* @return
*/
@PostMapping("/save")
public ObjectRestResponse save(@RequestBody AppUserVo appUserVo){
baseBiz.save(appUserVo);
......
package com.github.wxiaoqi.security.admin.rest;
import com.github.wxiaoqi.security.admin.biz.BaseUserMemberBiz;
import com.github.wxiaoqi.security.admin.dto.BaseUserMemberVO;
import com.github.wxiaoqi.security.admin.entity.AppUserManage;
import com.github.wxiaoqi.security.admin.entity.BaseUserMember;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.BaseController;
import org.springframework.web.bind.annotation.*;
import java.lang.reflect.InvocationTargetException;
/**
* 用户会员
* @author Administrator
*/
@RestController
@RequestMapping("baseUserMember")
public class BaseUserMemberController extends BaseController<BaseUserMemberBiz, BaseUserMember> {
@RequestMapping("/findOne/{userId}")
public ObjectRestResponse<AppUserManage> findOneByUserId(@PathVariable Integer userId){
BaseUserMember oneByUserId = baseBiz.findOneByUserId(userId);
if (oneByUserId==null) {
return ObjectRestResponse.succ();
}
return ObjectRestResponse.succ(oneByUserId);
}
/**
* 设置用户会员
* @param baseUserMemberVO
* @return
*/
@PostMapping("/setUserMember")
public ObjectRestResponse setUserMember(@RequestBody BaseUserMemberVO baseUserMemberVO)
throws InvocationTargetException, IllegalAccessException {
baseBiz.setUserMember(baseUserMemberVO);
return ObjectRestResponse.succ();
}
}
......@@ -148,6 +148,7 @@ public class AppUserRest {
@RequestParam(value="password",defaultValue="")String password,
@RequestParam(value="type",defaultValue="1")Integer type
){
return appPermissionService.login(username,password,mobilecode,type);
}
......
......@@ -15,7 +15,6 @@ import com.github.wxiaoqi.security.api.vo.user.AppUserInfo;
import com.github.wxiaoqi.security.common.msg.BaseResponse;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.EmojiFilter;
import com.github.wxiaoqi.security.common.util.EntityUtils;
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;
......@@ -33,7 +32,12 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -136,8 +140,9 @@ public class AppPermissionService {
JSONObject result = new JSONObject();
if (type == 0) {
AppUserLogin rsUserLogin = appUserLoginBiz.checkeUserLogin(phone);
if (rsUserLogin != null)
if (rsUserLogin != null) {
return JsonResultUtil.createFailedResult(ResultCode.EXIST_CODE, "用户已存在");
}
} else if (type == 1) {
AppUserLogin rsUserLogin = appUserLoginBiz.checkeUserLogin(phone);
......@@ -164,8 +169,9 @@ public class AppPermissionService {
}
log.info("调用短信发送接口返回值为:{}", mobilecode);
// 判断返回值是否为空,并且是否可以转换成JSONObject
if (StringUtils.isBlank(mobilecode))
if (StringUtils.isBlank(mobilecode)) {
return JsonResultUtil.createDefaultFail();
}
try {
result.put("mobilecode", mobilecode);
String redisLockKey = RedisKey.CONSTANT_CODE_PREFIX + phone + mobilecode;
......@@ -211,9 +217,6 @@ public class AppPermissionService {
try {
Long now = System.currentTimeMillis() / 1000;
AppUserLogin appUserLogin = new AppUserLogin();
//主要是ip地址
EntityUtils.setCreatAndUpdatInfo(appUserLogin);
setCreateIPInfo(appUserLogin);
appUserLogin.setUsername(username);
appUserLogin.setPassword(password);
......@@ -243,6 +246,8 @@ public class AppPermissionService {
rsUserDetail.setCreatetime(now);
rsUserDetail.setUpdatetime(now);
rsUserDetail.setIsdel(0);
rsUserDetail.setCrtHost(getIp());
setCreateIPInfo(rsUserDetail);
appUserDetailBiz.insertSelective(rsUserDetail);
log.error("注册:新增用户详情: " + userid);
//自动登录获取优惠卷
......@@ -305,15 +310,19 @@ public class AppPermissionService {
data.put("userId", userid);
data.put("imUserId", userVo.getImUserid());
//更新登录时间 和 ip
AppUserLogin userLoign= new AppUserLogin();
EntityUtils.setCreateInfo(userLoign);
appUserLoginBiz.updateLoginInfo(userid,userLoign.getCrtHost());
String clientIp = getIp();
appUserLoginBiz.updateLoginInfo(userid,clientIp);
}
return data;
}
public static String getIp() {
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
return requestAttributes.getRequest().getHeader("userHost");
}
/**
* 微信绑定/注册
*
......@@ -353,6 +362,14 @@ public class AppPermissionService {
headimgurl = SystemConfig.USER_HEADER_URL_DEFAULT;
}
if (type == 1) { // 绑定
String redisLockKey = RedisKey.CONSTANT_CODE_PREFIX + username + mobilecode;
String mobilecodeRedis = userRedisTemplate.opsForValue().get(redisLockKey) == null ? "" : userRedisTemplate.opsForValue().get(redisLockKey).toString();
log.error("注册接口,获取redis中的验证码:" + mobilecodeRedis);
// 获取到缓存的验证码后要先清空缓存对应键的值
userRedisTemplate.delete(redisLockKey);
if (StringUtils.isBlank(mobilecodeRedis)) {
return JsonResultUtil.createFailedResult(ResultCode.NOTEXIST_CODE, "验证码错误");
}
Long now = System.currentTimeMillis() / 1000;
AppUserLogin userLogin = appUserLoginBiz.checkeUserLogin(username);
if ((isQQ == 1 && StringUtils.isNotBlank(userLogin.getOpenid())) || (isQQ == 0 && StringUtils.isNotBlank(userLogin.getWxOpenid()))) {
......@@ -378,6 +395,8 @@ public class AppPermissionService {
userDetail.setCreatetime(now);
userDetail.setUpdatetime(now);
userDetail.setIsdel(0);
userDetail.setCrtHost(getIp());
setCreateIPInfo(userDetail);
appUserDetailBiz.insertSelective(userDetail);
} /*else {
userDetail.setId(userVo.getId());
......@@ -718,9 +737,6 @@ public class AppPermissionService {
try {
Long now = System.currentTimeMillis() / 1000;
AppUserLogin appUserLogin = new AppUserLogin();
//主要是ip地址
EntityUtils.setCreatAndUpdatInfo(appUserLogin);
setCreateIPInfo(appUserLogin);
appUserLogin.setUsername(username);
appUserLogin.setPassword(password);
appUserLogin.setIsdel(0);
......@@ -740,6 +756,8 @@ public class AppPermissionService {
rsUserDetail.setIsdel(0);
//设置来源
rsUserDetail.setChannel(UserSourceEnum.APPLET.getCode());
rsUserDetail.setCrtHost(getIp());
setCreateIPInfo(rsUserDetail);
appUserDetailBiz.insertSelective(rsUserDetail);
log.error("注册:新增用户详情: " + userid);
//上线绑定
......@@ -809,11 +827,13 @@ public class AppPermissionService {
/**
* ip地址 信息解析
* @param appUserLogin
* @param appUserDetail
*/
public void setCreateIPInfo(AppUserLogin appUserLogin){
String crtHost = appUserLogin.getCrtHost();
public void setCreateIPInfo(AppUserDetail appUserDetail){
String crtHost = appUserDetail.getCrtHost();
String ipAddress = restTemplate.getForObject(String.format("%s%s", IPAddress.BASE_IP_PARSING_URL, crtHost), String.class);
log.info("----setCreateIPInfo--crtHost========"+crtHost);
String data = JSONObject.parseObject(ipAddress).getString(IPAddress.BASE_DATA);
JSONObject ipJsonObject = JSONObject.parseObject(data);
// Integer provinceCode = ipJsonObject.getInteger(IPAddress.PROVINCE_CODE);
......@@ -823,8 +843,8 @@ public class AppPermissionService {
String cityName = ipJsonObject.getString(IPAddress.CITY_NAME);
RegionDTO regionDTO = regionFeign.getRegionByCityName(cityName);
if (null!=regionDTO){
appUserLogin.setProvinceCode(Integer.valueOf(String.valueOf(regionDTO.getParentId())));
appUserLogin.setCityCode(Integer.valueOf(String.valueOf(regionDTO.getId())));
appUserDetail.setProvinceCode(Integer.valueOf(String.valueOf(regionDTO.getParentId())));
appUserDetail.setCityCode(Integer.valueOf(String.valueOf(regionDTO.getId())));
}
}
......
......@@ -32,85 +32,69 @@
where d.userid = #{userId} limit 1
</select>
<select id="selectAppUserManage" parameterType="Integer" resultMap="AppUserVoMap">
select l.im_userid,l.username,l.wx_openid,l.unionid,l.openid,l.status,l.id_number,l.certification_status,d.* from app_user_login l
left join app_user_detail d
on d.userid = l.id where 1=1
<if test="id != null">
and d.id =#{id}
</if>
<if test="userid != null" >
and d.userid = #{userId}
</if>
<if test="username != null" >
and l.username=#{username}
</if>
<if test="imUserd != null" >
and l.im_userid=#{imUserid}
</if>
<if test="wxOpenid != null" >
and l.wx_openid=#{wxOpenid}
</if>
<if test="unionid != null" >
and l.unionid=#{unionid}
</if>
<if test="openid != null" >
and l.openid=#{openid}
</if>
<if test="status != null" >
and l.status=#{status}
</if>
<if test="idNumber != null" >
and l.id_number=#{idNumber}
</if>
<if test="certificationStatus != null" >
and l.certification_status=#{certificationStatus}
</if>
<if test="isMember != null" >
and d.is member=#{isMember}
</if>
<if test="nickname != null" >
and d.nickname=#{nickname}
</if>
<if test="realname != null" >
and d.realname=#{realname}
</if>
<if test="email != null" >
and d.email=#{email}
</if>
<if test="sex != null" >
and d.sex=#{sex}
</if>
<if test="birthday != null" >
and d.birthday=#{birthday}
</if>
<if test="personSign != null" >
and d.person_sign=#{personSign}
</if>
<if test="remark != null" >
and d.remark=#{remark}
</if>
<select id="selectAppUserManage" parameterType="com.github.wxiaoqi.security.admin.dto.AppUserManageDTO"
resultType="com.github.wxiaoqi.security.admin.vo.AppUserManageVo">
select
d.userid,
d.channel,
d.is_member,
d.realname,
d.isdel,
d.nickname,
d.source,
d.Inviter_account,
d.address,
d.sex,
d.email,
l.username,
l.certification_status,
l.id_number,
l.createtime,
l.last_time,
m.member_level,
m.valid_time,
m.buy_count,
m.total_number,
m.rent_free_days,
m.crt_time AS timeOfMembership,
m.recent_recharge,
m.name as memberName
from
app_user_login l
left join
app_user_detail d
on d.userid = l.id
left join
(
select
b.*,
ml.name
from
base_user_member b
left join
base_user_member_level ml
on
ml.id = b.member_level
) m
on
l.id = m.user_id
where 1=1
<if test="mobile !=null || mobile ! = ''">
and l.username=#{mobile}
</if>
<if test="channel !=null || channel != ''">
and d.channel=#{channel}
</if>
<if test="memberLevel !=null || memberLevel != ''">
and m.member_level = #{memberLevel}
</if>
<if test="registrationTimeBegin !=null || registrationTimeBegin != ''">
and l.createtime &gt;= #{registrationTimeBegin}
</if>
<if test="registrationTimeEnd!=null || registrationTimeEnd != ''">
and l.createtime &lt;= #{registrationTimeEn}
</if>
</select>
......
//package com.xxfc.platform.app.utils;
//
//import lombok.extern.slf4j.Slf4j;
//
//import java.io.*;
//import java.net.*;
//import java.util.Map;
//import java.util.UUID;
//@Slf4j
//public class UploadUtil {
//
//
// public static final String TAG = UploadUtil.class.getName();
//
// private static final String CHARSET = "utf-8"; // 设置编码
// private static final int TIME_OUT = 8*1000;
// public static String result = null;
// /**
// * Android上传文件到服务端
// *
// * @param file 需要上传的文件
// * @param RequestURL 请求的url
// * @return 返回响应的内容
// */
// public static String uploadFile(final File file, final String RequestURL) {
//
//// Thread thread = new Thread(new Runnable() {
//// @Override
//// public void run() {
// String result = null;
// String BOUNDARY = UUID.randomUUID().toString(); // 边界标识 随机生成
// String PREFIX = "--", LINE_END = "\r\n";
// String CONTENT_TYPE = "multipart/form-data"; // 内容类型
// try {
// URL url = new URL(RequestURL);
// HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//
// conn.setReadTimeout(TIME_OUT);
// conn.setConnectTimeout(TIME_OUT);
// conn.setDoInput(true); // 允许输入流
// conn.setDoOutput(true); // 允许输出流
// conn.setUseCaches(false); // 不允许使用缓存
// conn.setRequestMethod("POST"); // 请求方式
// conn.setRequestProperty("Charset", CHARSET); // 设置编码
// conn.setRequestProperty("connection", "keep-alive");
// conn.setRequestProperty("Content-Type", CONTENT_TYPE + ";boundary=" + BOUNDARY);
//
//
// if (file != null) {
// /**
// * 当文件不为空,把文件包装并且上传
// */
// DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
// StringBuffer sb = new StringBuffer();
// sb.append(PREFIX);
// sb.append(BOUNDARY);
// sb.append(LINE_END);
// /**
// * 这里重点注意: name里面的值为服务端需要key 只有这个key 才可以得到对应的文件
// * filename是文件的名字,包含后缀名的 比如:abc.png
// */
//
// sb.append("Content-Disposition: form-data; name=\"upload\"; filename=\""
// + file.getName() + "\"" + LINE_END);
// sb.append("Content-Type: application/octet-stream; charset=" + CHARSET + LINE_END);
// sb.append(LINE_END);
// dos.write(sb.toString().getBytes());
// InputStream is = new FileInputStream(file);
// byte[] bytes = new byte[1024];
// int len = 0;
// while ((len = is.read(bytes)) != -1) {
// dos.write(bytes, 0, len);
// }
// is.close();
// dos.write(LINE_END.getBytes());
// byte[] end_data = (PREFIX + BOUNDARY + PREFIX + LINE_END).getBytes();
// dos.write(end_data);
// dos.flush();
// /**
// * 获取响应码 200=成功 当响应成功,获取响应的流
// */
// int res = conn.getResponseCode();
// LOG.i(TAG, "response code:" + res);
// if(res==200)
// {
// LOG.i(TAG, "request success");
// InputStream input = conn.getInputStream();
// StringBuffer sb1 = new StringBuffer();
// int ss;
// while ((ss = input.read()) != -1) {
// sb1.append((char) ss);
// }
// result = sb1.toString();
// UploadUtil.result = new String(result.getBytes("iso-8859-1"),"utf-8");
// LOG.i(TAG, "result : " + UploadUtil.result);
// input.close();
// }
// else{
// LOG.e(TAG, "request error");
// }
//
// }
// } catch (MalformedURLException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// } catch (UnsupportedEncodingException e) {
// e.printStackTrace();
// } catch (ProtocolException e) {
// e.printStackTrace();
// } catch (MalformedURLException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }
//
//// }
//// });
//// thread.start();
// LOG.i(TAG, "---"+UploadUtil.result+"---");
// return UploadUtil.result;
// }
//
//
// /**
// * 通过拼接的方式构造请求内容,实现参数传输以及文件传输
// *
// * @param url Service net address
// * @param params text content
// * @param files pictures
// * @return String result of Service response
// * @throws IOException
// */
// public static String post(String url, Map<String, String> params, Map<String, File> files)
// throws IOException {
// String BOUNDARY = java.util.UUID.randomUUID().toString();
// String PREFIX = "--", LINEND = "\r\n";
// String MULTIPART_FROM_DATA = "multipart/form-data";
// String CHARSET = "UTF-8";
//
//
// URL uri = new URL(url);
// HttpURLConnection conn = (HttpURLConnection) uri.openConnection();
// conn.setReadTimeout(10 * 1000); // 缓存的最长时间
// conn.setDoInput(true);// 允许输入
// conn.setDoOutput(true);// 允许输出
// conn.setUseCaches(false); // 不允许使用缓存
// conn.setRequestMethod("POST");
// conn.setRequestProperty("connection", "keep-alive");
// conn.setRequestProperty("Charsert", "UTF-8");
// conn.setRequestProperty("Content-Type", MULTIPART_FROM_DATA + ";boundary=" + BOUNDARY);
//
//
// // 首先组拼文本类型的参数
// StringBuilder sb = new StringBuilder();
// for (Map.Entry<String, String> entry : params.entrySet()) {
// sb.append(PREFIX);
// sb.append(BOUNDARY);
// sb.append(LINEND);
// sb.append("Content-Disposition: form-data; name=\"" + entry.getKey() + "\"" + LINEND);
// sb.append("Content-Type: text/plain; charset=" + CHARSET + LINEND);
// sb.append("Content-Transfer-Encoding: 8bit" + LINEND);
// sb.append(LINEND);
// sb.append(entry.getValue());
// sb.append(LINEND);
// }
//
//
// DataOutputStream outStream = new DataOutputStream(conn.getOutputStream());
// outStream.write(sb.toString().getBytes());
// // 发送文件数据
// if (files != null)
// for (Map.Entry<String, File> file : files.entrySet()) {
// StringBuilder sb1 = new StringBuilder();
// sb1.append(PREFIX);
// sb1.append(BOUNDARY);
// sb1.append(LINEND);
// sb1.append("Content-Disposition: form-data; name=\"upload\"; filename=\""
// + file.getValue().getName() + "\"" + LINEND);
// sb1.append("Content-Type: application/octet-stream; charset=" + CHARSET + LINEND);
// sb1.append(LINEND);
// outStream.write(sb1.toString().getBytes());
//
//
// InputStream is = new FileInputStream(file.getValue());
// byte[] buffer = new byte[1024];
// int len = 0;
// while ((len = is.read(buffer)) != -1) {
// outStream.write(buffer, 0, len);
// }
//
//
// is.close();
// outStream.write(LINEND.getBytes());
// }
//
//
// // 请求结束标志
// byte[] end_data = (PREFIX + BOUNDARY + PREFIX + LINEND).getBytes();
// outStream.write(end_data);
// outStream.flush();
// // 得到响应码
// int res = conn.getResponseCode();
// InputStream in = conn.getInputStream();
// StringBuilder sb2 = new StringBuilder();
// if (res == 200) {
// int ch;
// while ((ch = in.read()) != -1) {
// sb2.append((char) ch);
// }
// }
// outStream.close();
// conn.disconnect();
// return sb2.toString();
// }
//
//}
package com.xxfc.platform.app.biz;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken;
import com.github.wxiaoqi.security.common.constant.RestCode;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.xxfc.platform.vehicle.common.RestResponse;
import com.xxfc.platform.vehicle.constant.RedisKey;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import com.xxfc.platform.app.entity.AppVersion;
import com.xxfc.platform.app.mapper.AppVersionMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import org.springframework.transaction.annotation.Transactional;
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.multipart.MultipartFile;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.weekend.WeekendSqls;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
*
......@@ -22,6 +46,13 @@ import java.util.List;
@Service
public class AppVersionBiz extends BaseBiz<AppVersionMapper,AppVersion> {
@Value("${app.uploadPath}")
private String uploadPath;
@Autowired
private RedisTemplate redisTemplate;
public static final DateTimeFormatter DEFAULT_DATE_TIME_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd");
public ObjectRestResponse getVersion(String version,Integer type){
if (StringUtils.isBlank(version)||type==null){
......@@ -49,4 +80,79 @@ public class AppVersionBiz extends BaseBiz<AppVersionMapper,AppVersion> {
}
return ObjectRestResponse.succ();
}
public RestResponse uploadDrivingLicense(MultipartFile file) throws IOException {
DateTime now = DateTime.now();
String dirPathToday = File.separator + now.toString(DEFAULT_DATE_TIME_FORMATTER);
String redisNoKey = RedisKey.UPLOAD_FILE_NO_PREFIX + now.toString(DEFAULT_DATE_TIME_FORMATTER);
// Long no = redisTemplate.opsForValue().increment(redisNoKey);
// if(no.equals(1L)){
// redisTemplate.expire(redisNoKey,1, TimeUnit.DAYS);
// }
String fileName = file.getOriginalFilename();
String realFileRelPath = dirPathToday + File.separator+fileName.substring(fileName.lastIndexOf("/"));
String filePath = uploadPath + realFileRelPath;
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(filePath));
return RestResponse.suc(filePath);
}
/**
* 下载行驶证图片
* @param realFileRelPath
* @return
* @throws Exception
*/
public ResponseEntity<byte[]> downloadInstallationPackage(String realFileRelPath) throws Exception{
String filePath = uploadPath + realFileRelPath;
File file = new File(filePath);//新建一个文件
HttpHeaders headers = new HttpHeaders();//http头信息
String downloadFileName = new String(file.getName());//设置编码
headers.setContentDispositionFormData("attachment", downloadFileName);
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);
}
/**
* 添加版本信息
* @param appVersion
*/
@Transactional
public void insertAppVersion(AppVersion appVersion) {
appVersion.setDownloadSwitch(0);
insertSelective(appVersion);
}
public AppVersion get(Integer id) {
if (id==null) {
throw new IllegalArgumentException("Parameter is null");
}
return selectById(id);
}
/**
* 修改一条信息
* @param appVersion
*/
@Transactional
public void updateAppVersionById(AppVersion appVersion) {
updateSelectiveById(appVersion);
}
/**
* 删除
* @param id
*/
public void remove(Integer id) {
AppVersion appVersion = new AppVersion();
appVersion.setIsDel(1);
Example example = Example.builder(AppVersion.class)
.where(WeekendSqls.<AppVersion>custom().andEqualTo(AppVersion::getId,id))
.build();
mapper.updateByExampleSelective(appVersion,example);
}
}
\ No newline at end of file
......@@ -2,17 +2,15 @@ package com.xxfc.platform.app.rest;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreClientToken;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.BaseController;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.github.wxiaoqi.security.common.vo.GoodDataVO;
import com.xxfc.platform.app.biz.CofigBiz;
import com.xxfc.platform.app.entity.Cofig;
import com.xxfc.platform.campsite.feign.CampsiteFeign;
import com.xxfc.platform.tour.feign.TourFeign;
import com.xxfc.platform.vehicle.feign.VehicleFeign;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
......@@ -35,6 +33,11 @@ public class AppHomeController extends BaseController<CofigBiz,Cofig> {
@Autowired
TourFeign tourFeign;
@Autowired
VehicleFeign vehicleFeign;
@RequestMapping(value ="/app/unauth/goodList",method = RequestMethod.GET)
@IgnoreUserToken
public ObjectRestResponse<List<GoodDataVO>> goodList(
......@@ -47,6 +50,8 @@ public class AppHomeController extends BaseController<CofigBiz,Cofig> {
list=tourFeign.goodList(page,limit);
}else if (type==3){
list=campsiteFeign.goodList(page,limit);
}else if (type==4){
list=vehicleFeign.goodList(page,limit);
}
return new ObjectRestResponse<>().rel(true).data(list);
}
......
......@@ -9,14 +9,24 @@ import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.xxfc.platform.app.biz.AppVersionBiz;
import com.xxfc.platform.app.entity.AppVersion;
import com.xxfc.platform.app.entity.Cofig;
import com.xxfc.platform.vehicle.common.RestResponse;
import com.xxfc.platform.vehicle.constant.ResCode.ResCode;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Delete;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
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.RestController;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
......@@ -24,7 +34,9 @@ import java.util.List;
@RequestMapping("version")
@IgnoreClientToken
public class AppVersionController extends BaseController<AppVersionBiz,AppVersion> {
//最大上传500MB
private Long MAX_DRIVING_LICENSE_SIZE =1024*1024*500L;
private int id;
@ApiModelProperty("app自动更新")
@RequestMapping(value ="/app/unauth/info",method = RequestMethod.GET)
......@@ -36,4 +48,63 @@ public class AppVersionController extends BaseController<AppVersionBiz,AppVersio
return baseBiz.getVersion(version,type);
}
@Override
@ApiOperation("添加")
@RequestMapping(value = "/add",method = RequestMethod.POST)
public ObjectRestResponse<AppVersion> add(@RequestBody AppVersion appVersion){
baseBiz.insertAppVersion(appVersion);
return new ObjectRestResponse<AppVersion>();
}
@ApiOperation("查询")
@RequestMapping(value = "/{id}",method = RequestMethod.GET)
public ObjectRestResponse<AppVersion> get(@PathVariable Integer id){
return ObjectRestResponse.succ(baseBiz.get(id));
}
@Override
@ApiOperation("修改")
@RequestMapping(value = "/update/{id}",method = RequestMethod.PUT)
public ObjectRestResponse<AppVersion> update(@RequestBody AppVersion appVersion){
baseBiz.updateAppVersionById(appVersion);
return new ObjectRestResponse<AppVersion>();
}
@ApiOperation("删除")
@DeleteMapping(value = "/remove/{id}")
public ObjectRestResponse<AppVersion> remove(@PathVariable Integer id){
baseBiz.remove(id);
return new ObjectRestResponse<AppVersion>();
}
@PostMapping(value = "/upload/installationPackage")
@ApiOperation(value = "上传app安装包")
public RestResponse uploadInstallationPackage(@RequestParam("file") MultipartFile file)
throws Exception {
Assert.notNull(file);
String contentType = file.getContentType(); //文件类型
//// String fileName = file.getOriginalFilename(); //文件名
if (!contentType.equals("apk") && !contentType.equals("ipa")) {
return RestResponse.code(ResCode.INVALID_REST_REQ_PARAM.getCode());
}
if (file.getSize() > MAX_DRIVING_LICENSE_SIZE) {
return RestResponse.code(ResCode.INVALID_REST_REQ_PARAM.getCode());
}
return baseBiz.uploadDrivingLicense(file);
}
@IgnoreUserToken
@GetMapping(value = "/download/installationPackage/{realFileRelPath}") //匹配的是href中的download请求
@ApiOperation(value = "下载app安装包")
public ResponseEntity<byte[]> downloadInstallationPackage(@RequestParam("realFileRelPath") String realFileRelPath) throws Exception {
return baseBiz.downloadInstallationPackage(realFileRelPath);
}
}
\ No newline at end of file
......@@ -63,6 +63,7 @@ public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper, CampsiteShop> {
private static final String CAMPSITE_CACHE = "campsite_cache:";
private static final String CAMSITE_DETAIL_CACHE="campsite:detail:cache:";
private static final String CAMPSITE_CACHE_ALL = "all";
private static final long CAMPSITE_EXPIRE_TIME=6000;
/**
* 根据店铺类型查找列表
......
......@@ -61,5 +61,4 @@ public class CampsiteShopController extends BaseController<CampsiteShopBiz, Camp
return getBaseBiz().getAllByHome(page,limit);
}
}
\ No newline at end of file
......@@ -6,7 +6,13 @@ import lombok.Data;
import java.math.BigDecimal;
@Data
public class UnitPriceDTO {
public class OrderAboutParamDTO {
@ApiModelProperty(value = "旅游保险单价")
private BigDecimal insurePrice;
@ApiModelProperty(value = "租车订单自动取消时间(毫秒)")
private Long actRent;
@ApiModelProperty(value = "旅游订单自动取消时间(毫秒)")
private Long actTour;
}
\ No newline at end of file
......@@ -176,12 +176,7 @@ public class BaseOrderBiz extends BaseBiz<BaseOrderMapper,BaseOrder> {
setCancelReason(baseOrder.getCancelReason());
setVersion(baseOrder.getVersion());
}};
int updateResult = this.updateSelectiveByIdRe(updateOrder);
//如果取消失败,则抛异常
if(updateResult <= 0) {
throw new BaseException(ResultCode.DB_OPERATION_FAIL_CODE);
}
BaseOrder hasUpdateOrder = this.updateSelectiveByIdReT(updateOrder);
//触发退款流程
//判断是否已支付
......@@ -193,14 +188,14 @@ public class BaseOrderBiz extends BaseBiz<BaseOrderMapper,BaseOrder> {
}});
//退款流程
rentRefundProcess(baseOrder, orvd.getDeposit(), orvd.getStartTime(), APP_ORDER+ "_"+ RENT_REFUND);
rentRefundProcess(hasUpdateOrder, orvd.getDeposit(), orvd.getStartTime(), APP_ORDER+ "_"+ RENT_REFUND);
}else if (OrderTypeEnum.TOUR.getCode().equals(baseOrder.getType())) {
OrderTourDetail otd = orderTourDetailBiz.selectOne(new OrderTourDetail(){{
setOrderId(baseOrder.getId());
}});
//退款流程
rentRefundProcess(baseOrder, otd.getStartTime(), APP_ORDER+ "_"+ TOUR_REFUND);
rentRefundProcess(hasUpdateOrder, otd.getStartTime(), APP_ORDER+ "_"+ TOUR_REFUND);
}
}
......@@ -324,8 +319,10 @@ public class BaseOrderBiz extends BaseBiz<BaseOrderMapper,BaseOrder> {
//更新订单的退款状态和退款时间
if(SYS_TRUE.equals(flag) && null != refundStatus) {
updateSelectiveByIdReT(new BaseOrder(){{
setId(baseOrder.getId());
setRefundStatus(refundStatus);
setRefundTime(System.currentTimeMillis());
setVersion(baseOrder.getVersion());
}});
}
}
......
......@@ -3,7 +3,7 @@ package com.xxfc.platform.order.config;
import com.github.wxiaoqi.security.auth.client.interceptor.ServiceAuthRestInterceptor;
import com.github.wxiaoqi.security.auth.client.interceptor.UserAuthRestInterceptor;
import com.github.wxiaoqi.security.common.handler.GlobalExceptionHandler;
import com.xxfc.platform.order.interceptor.CorsInterceptor;
import com.github.wxiaoqi.security.common.interceptor.CorsInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
......
......@@ -24,10 +24,9 @@ import com.xxfc.platform.order.entity.BaseOrder;
import com.xxfc.platform.order.mqhandler.RabbitProduct;
import com.xxfc.platform.order.pojo.order.CancelOrderDTO;
import com.xxfc.platform.order.pojo.order.OrderPageVO;
import com.xxfc.platform.order.pojo.order.UnitPriceDTO;
import com.xxfc.platform.order.pojo.order.OrderAboutParamDTO;
import com.xxfc.platform.order.pojo.pay.RentVehicleOrderPayVO;
import com.xxfc.platform.universal.constant.DictionaryKey;
import com.xxfc.platform.universal.constant.enumerate.PayChannelEnum;
import com.xxfc.platform.universal.entity.Dictionary;
import com.xxfc.platform.universal.feign.ThirdFeign;
import com.xxfc.platform.universal.vo.OrderPayVo;
......@@ -47,7 +46,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
......@@ -94,13 +92,28 @@ public class BaseOrderController extends CommonBaseController {
@ApiOperation(value = "获取订单相关的单价")
@IgnoreClientToken
@IgnoreUserToken
public ObjectRestResponse<UnitPriceDTO> getOrderUnitPrice() {
public ObjectRestResponse<OrderAboutParamDTO> getOrderUnitPrice() {
Map<String, Dictionary> dictionaryMap = thirdFeign.dictionaryGetAll4Map().getData();
return ObjectRestResponse.succ(new UnitPriceDTO(){{
return ObjectRestResponse.succ(new OrderAboutParamDTO(){{
setInsurePrice(new BigDecimal(dictionaryMap.get(APP_ORDER+ "_"+ DictionaryKey.INSURE_PRICE).getDetail()));
}});
}
@RequestMapping(value = "/app/unauth/getOrderParam", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "获取订单相关的参数")
@IgnoreClientToken
@IgnoreUserToken
public ObjectRestResponse<OrderAboutParamDTO> getOrderParam() {
Map<String, Dictionary> dictionaryMap = thirdFeign.dictionaryGetAll4Map().getData();
return ObjectRestResponse.succ(new OrderAboutParamDTO(){{
setInsurePrice(new BigDecimal(dictionaryMap.get(APP_ORDER+ "_"+ DictionaryKey.INSURE_PRICE).getDetail()));
setActRent(new Long(dictionaryMap.get(APP_ORDER+ "_"+ DictionaryKey.ACT_RENT).getDetail()));
setActTour(new Long(dictionaryMap.get(APP_ORDER+ "_"+ DictionaryKey.ACT_TOUR).getDetail()));
}});
}
@RequestMapping(value = "/page", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "订单列表")
......
......@@ -65,9 +65,16 @@ public class TourUserController extends TourBaseController<TourUserBiz> {
if (tourUser.getId()==null||tourUser.getId()==0) {
AppUserDTO userInfo = getUserInfo();
if (userInfo==null||userInfo.getUserid()==null||userInfo.getUserid()==0) {
ObjectRestResponse.createDefaultFail();
return ObjectRestResponse.createDefaultFail();
}
Integer userid = userInfo.getUserid();
TourUser tourUser1=new TourUser();
tourUser1.setUserid(userid);
tourUser1.setIdCard(tourUser.getIdCard());
tourUser1=baseBiz.selectOne(tourUser1);
if(tourUser1!=null){
return ObjectRestResponse.createFailedResult(ResultCode.FAILED_CODE,"出游人证件号一样");
}
tourUser.setUserid(userid);
tourUser.setCrtTime(System.currentTimeMillis());
tourUser.setIsdel(0);
......@@ -85,6 +92,26 @@ public class TourUserController extends TourBaseController<TourUserBiz> {
}
/**
* 添加和更新
* @param id
* @return
*/
@ApiOperation("删除")
@PostMapping(value = "/app/del")
@Transactional
public ObjectRestResponse<TourUser> del(@RequestBody TourUser tourUser){
try {
tourUser.setIsdel(1);
baseBiz.updateSelectiveById(tourUser);
return ObjectRestResponse.succ();
} catch (Exception e) {
e.printStackTrace();
throw new BaseException(ResultCode.FAILED_CODE);
}
}
@ApiOperation("通过id查询")
@GetMapping(value = "/app/findById/{id}")
......
package com.xxfc.platform.universal.api;
import com.xxfc.platform.universal.api.pojo.Authentication;
import com.xxfc.platform.universal.entity.IdInformation;
/**
* 调用外部接口实现类。调用不同的外部接口,需要编写不同了类实现该类
*/
public interface BaseAuthentication {
Authentication getAuthentication(IdInformation idInformation);
}
package com.xxfc.platform.universal.api.impl;
import com.xxfc.platform.universal.api.BaseAuthentication;
import com.xxfc.platform.universal.api.pojo.Authentication;
import com.xxfc.platform.universal.entity.IdInformation;
public class FQAuthentication implements BaseAuthentication {
@Override
public Authentication getAuthentication(IdInformation idInformation) {
return null;
}
}
package com.xxfc.platform.universal.api.pojo;
public class Authentication {
}
package com.xxfc.platform.universal.constant;
public class RedisKey {
/**
......@@ -94,4 +97,5 @@ public class RedisKey {
public static final String CACHE_DICTIONARY_ALL =CACHE_DICTIONARY_PREFIX + "all:";
public static final String CACHE_DICTIONARY_ALL_MAP =CACHE_DICTIONARY_ALL + "map:";
public static final String ILLEGAL_VEHICLE_ENQUIRIES ="cache:violation";
}
......@@ -3,7 +3,6 @@ package com.xxfc.platform.universal.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
......@@ -12,8 +11,6 @@ import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
......
......@@ -57,7 +57,6 @@ public interface ThirdFeign {
@GetMapping("/LicensePlateType")
ObjectRestResponse getLicensePlateType();
/***************************************** 数据字典 ********************************************/
......@@ -65,7 +64,7 @@ public interface ThirdFeign {
@RequestMapping(value = "/dictionary/getParents", method = RequestMethod.GET)
public ObjectRestResponse<List<Dictionary>> dictionaryGetParent(@RequestParam(value = "type") String type);
// @GetMapping(value = "/dictionary/get")
// @GetMapping(value = "/dictionary/get")
@RequestMapping(value = "/dictionary/get", method = RequestMethod.GET)
public ObjectRestResponse<List<Dictionary>> dictionaryGet(@RequestParam(value = "dictionary") Map<String, Object> dictionary);
......@@ -77,4 +76,5 @@ public interface ThirdFeign {
@GetMapping("/3p/tv/getRentViolation")
public ObjectRestResponse<List<ViolationVO>> getRentViolation(@RequestParam(value = "rentViolationDTO") Map<String, Object> rentViolationDTO);
}
......@@ -18,7 +18,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.task.TaskExecutor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.weekend.WeekendSqls;
......@@ -148,7 +147,7 @@ public class SysRegionBiz extends BaseBiz<SysRegionMapper, SysRegion> {
/**
* 5分钟内刷新数据到缓存
*/
@Scheduled(cron = "0 */5 * * * *")//每5分钟刷新一次数据
//@Scheduled(cron = "0 */5 * * * *")//每5分钟刷新一次数据
public void refreshCache(){
String redisLockKey = RedisKey.SYS_REGION_REFRESH_LOCK +(DateTime.now().getMinuteOfDay()/5);//同一日每5分钟只刷新一次
......
......@@ -2,21 +2,24 @@ package com.xxfc.platform.universal.controller;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.xxfc.platform.universal.service.TrafficViolationsService;
import com.xxfc.platform.universal.vo.RentViolationDTO;
import com.xxfc.platform.universal.vo.TrafficViolations;
import com.xxfc.platform.universal.vo.ViolationVO;
import com.xxfc.platform.vehicle.entity.Vehicle;
import com.xxfc.platform.vehicle.feign.VehicleFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("3p/tv")
public class TrafficViolationsController {
@Autowired
private VehicleFeign vehicleFeign;
@Autowired
TrafficViolationsService tvService;
......@@ -64,10 +67,17 @@ public class TrafficViolationsController {
@GetMapping("/getRentViolation")
public ObjectRestResponse<List<ViolationVO>> getRentViolation(RentViolationDTO rentViolationDTO) {
return ObjectRestResponse.succ(new ArrayList<ViolationVO>(){{
add(new ViolationVO(){{setPrice(new BigDecimal("100.00"));}});
add(new ViolationVO(){{setPrice(new BigDecimal("200.00"));}});
}});
String vehicleId = rentViolationDTO.getVehicleId();
if (rentViolationDTO==null||rentViolationDTO.getVehicleId()==null) {
return ObjectRestResponse.createFailedResult(ResultCode.FAILED_CODE,"Vehicle information is empty");
}
Vehicle vehicle = vehicleFeign.get(vehicleId).getData();
if (vehicle==null) {
return ObjectRestResponse.createFailedResult(ResultCode.FAILED_CODE,"No corresponding vehicle information");
}
return ObjectRestResponse.succ(tvService.getRentViolation(rentViolationDTO,vehicle));
}
......
......@@ -3,9 +3,12 @@ package com.xxfc.platform.universal.service;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.xxfc.platform.universal.biz.LicensePlateTypeBiz;
import com.xxfc.platform.universal.constant.RedisKey;
import com.xxfc.platform.universal.entity.LicensePlateType;
import com.xxfc.platform.universal.utils.CertifHttpUtils;
import com.xxfc.platform.universal.vo.RentViolationDTO;
import com.xxfc.platform.universal.vo.TrafficViolations;
import com.xxfc.platform.vehicle.entity.Vehicle;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
......@@ -14,6 +17,7 @@ import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.task.TaskExecutor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
......@@ -60,6 +64,9 @@ public class TrafficViolationsService {
private static final String FRAMENO_NAME="frameno";
private static final String AUTHORIZATION="Authorization";
@Autowired
private RedisTemplate redisTemplate;
/**
* 支持查询的城市
......@@ -209,4 +216,18 @@ public class TrafficViolationsService {
licensePlateTypeBiz.insertLicensePlateType(finalLicensePlateTypes);
}
/**
* 订单完成后调用接口获取车辆信息
* @param rentViolationDTO
* @param vehicle
* @return
*/
public String getRentViolation(RentViolationDTO rentViolationDTO, Vehicle vehicle) {
String stringViolationVOS = (String) redisTemplate.opsForValue()
.get(RedisKey.ILLEGAL_VEHICLE_ENQUIRIES+rentViolationDTO.getVehicleId());
if (StringUtils.isBlank(stringViolationVOS)) {
}
return null;
}
}
......@@ -2,7 +2,7 @@ package com.xxfc.platform.universal.service;
import com.github.wxiaoqi.security.common.util.process.SystemConfig;
import com.xxfc.platform.vehicle.constant.RedisKey;
import com.xxfc.platform.universal.constant.RedisKey;
import org.apache.commons.io.FileUtils;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
......
package com.xxfc.platform.vehicle.entity;
import lombok.Data;
import tk.mybatis.mapper.annotation.KeySql;
import javax.persistence.Column;
import javax.persistence.Id;
......
package com.xxfc.platform.vehicle.feign;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.vo.GoodDataVO;
import com.xxfc.platform.vehicle.common.RestResponse;
import com.xxfc.platform.vehicle.entity.*;
import com.xxfc.platform.vehicle.pojo.CompanyDetail;
......@@ -63,4 +64,13 @@ public interface VehicleFeign {
@RequestMapping(value = "/user/license/company/getOne", method = RequestMethod.GET)
public RestResponse<VehicleUserLicense> getOne(
@RequestParam(value="id",defaultValue="0")Integer id) throws Exception ;
/**
* 获取优质车型接口
* @param page
* @param limit
* @return 返回
*/
@GetMapping(value = "/vehicleModel/goodList")
List<GoodDataVO> goodList(@RequestParam(value = "page") Integer page, @RequestParam("limit") Integer limit);
}
......@@ -2,17 +2,22 @@ package com.xxfc.platform.vehicle.pojo;
import com.xxfc.platform.vehicle.entity.BranchCompany;
import com.xxfc.platform.vehicle.entity.VehicleModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class UsableVehicleModelVO {
//车辆id
@ApiModelProperty(value = "公里数")
BigDecimal distance;
@ApiModelProperty(value = "车型信息")
VehicleModel vehicleModel;
@ApiModelProperty(value = "公司信息")
BranchCompany company;
@ApiModelProperty(value = "是否有车")
Integer hasVehicle;
}
\ No newline at end of file
......@@ -39,6 +39,9 @@ public class UsableVeicleDTO extends PageParam {
@ApiModelProperty(value = "分类列表", hidden = true)
Map<Integer, List<VehiclePlatCata>> catas;
@ApiModelProperty(hidden = true)
Boolean yearNo4Where;
public void setStartDateTamp(Long startDateTamp) {
this.startDateTamp = startDateTamp;
this.startDate = DEFAULT_DATE_TIME_FORMATTER.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(startDateTamp), ZoneOffset.ofHours(8)));
......
......@@ -126,6 +126,7 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> {
* @throws Exception
*/
public ResponseEntity<byte[]> downloadDrivingLicense(String realFileRelPath) throws Exception{
String filePath = baseUploadPath + realFileRelPath;
File file = new File(filePath);//新建一个文件
HttpHeaders headers = new HttpHeaders();//http头信息
......@@ -152,7 +153,7 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> {
params.put("vehicle",vehicle);
params.put("yearMonth",yearMonth);
List<VehicleBookInfo> vehicleBookInfoList = vehicleBookInfoMapper.getByVehicleIdAndYearMonth(params);
return CollectionUtils.isEmpty(vehicleBookInfoList)?null:vehicleBookInfoList.get(0);
return CollectionUtils.isEmpty(vehicleBookInfoList)? null:vehicleBookInfoList.get(0);
}
/**
......
package com.xxfc.platform.vehicle.biz;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.vo.GoodDataVO;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.xxfc.platform.vehicle.entity.Vehicle;
import com.xxfc.platform.vehicle.pojo.VehicleModelQueryCondition;
import com.xxfc.platform.vehicle.pojo.VehicleModelVo;
import lombok.extern.slf4j.Slf4j;
......@@ -12,7 +17,10 @@ import com.xxfc.platform.vehicle.mapper.VehicleModelMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.weekend.WeekendSqls;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
......@@ -36,20 +44,19 @@ public class VehicleModelBiz extends BaseBiz<VehicleModelMapper, VehicleModel> {
updateSelectiveById(model);
}
/**
* 分页查询车型列表
* @param vmqc
* @return
*/
public ObjectRestResponse findVehicleModelPage(VehicleModelQueryCondition vmqc) {
// List<VehicleModelVo > vehicleModelPage = mapper.findVehicleModelPage(vmqc);
// log.debug("vehicleModelPage"+vehicleModelPage);
try {
PageDataVO<VehicleModelVo> mPageDataVO = PageDataVO.pageInfo(vmqc.getPage(),
vmqc.getLimit(), () -> mapper.findVehicleModelPage(vmqc));
// List<VehicleModelVo> vehicleModelVos = mPageDataVO.getData();
// vehicleModelVos.parallelStream().forEach(vehicleModelVo -> vehicleModelVo.setPicture(vehicleModelVo.getPicture().split(",")[0]));
return ObjectRestResponse.succ(mPageDataVO);
} catch (Exception e) {
e.printStackTrace();
......@@ -85,4 +92,34 @@ public class VehicleModelBiz extends BaseBiz<VehicleModelMapper, VehicleModel> {
public void updateByPrimaryKeySelective(VehicleModel vm){
mapper.updateByPrimaryKeySelective(vm);
}
/**
* 分页查询返回List<GoodDataVO>
* @param page
* @param limit
* @return
*/
public List<GoodDataVO> goodList(Integer page, Integer limit) {
List<GoodDataVO> goodDataVOS = Arrays.asList();
/*设置分页*/
Page<VehicleModel> pages = PageHelper.startPage(page, limit);
Example example = Example.builder(VehicleModel.class)
.where(WeekendSqls.<VehicleModel>custom().andEqualTo(VehicleModel::getIsdel, 0)).orderByDesc("hot_sign").build();
selectByExample(example);
PageInfo<VehicleModel> pageInfo= PageInfo.of(pages.getResult());
List<VehicleModel> vehicleModelList = pageInfo.getList();
/*遍历车型列表设置List<GoodDataVO>*/
for (VehicleModel vm : vehicleModelList) {
GoodDataVO goodDataVO = new GoodDataVO();
goodDataVO.setId(vm.getId());
goodDataVO.setImgUrl(vm.getPicture());
goodDataVO.setName(vm.getName());
goodDataVO.setName1(vm.getKeyword());
goodDataVO.setPrice(String.valueOf(vm.getBuyPrice()));
goodDataVOS.add(goodDataVO);
}
return goodDataVOS;
}
}
\ No newline at end of file
......@@ -3,7 +3,7 @@ package com.xxfc.platform.vehicle.config;
import com.github.wxiaoqi.security.auth.client.interceptor.ServiceAuthRestInterceptor;
import com.github.wxiaoqi.security.auth.client.interceptor.UserAuthRestInterceptor;
import com.github.wxiaoqi.security.common.handler.GlobalExceptionHandler;
import com.xxfc.platform.vehicle.interceptor.CorsInterceptor;
import com.github.wxiaoqi.security.common.interceptor.CorsInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
......
package com.xxfc.platform.vehicle.interceptor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.cors.CorsUtils;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Created by ace on 2017/9/12.
*/
public class CorsInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (request.getHeader(HttpHeaders.ORIGIN) != null) {
response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Allow-Credentials", "true");
response.addHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT, HEAD");
response.addHeader("Access-Control-Allow-Headers", "Content-Type,authorization");
response.addHeader("Access-Control-Max-Age", "3600");
}
if(CorsUtils.isPreFlightRequest(request)){//是否跨域前option请求,使得话不执行后面拦截器
return Boolean.FALSE;
}
return super.preHandle(request, response, handler);
}
}
......@@ -375,8 +375,10 @@ public class VehicleController extends BaseController<VehicleBiz> {
vpcs.add(vpc);
vpcMap.put(vpc.getParentId(), vpcs);
}
dto.setCatas(vpcMap);
//设置显示是否有车
//dto.setYearNo4Where(Boolean.TRUE);
}
return new ObjectRestResponse<>().data(vehicleBiz.searchUsableModel(dto)).rel(true);
}
......
package com.xxfc.platform.vehicle.rest;
import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageInfo;
import com.github.wxiaoqi.security.admin.feign.UserFeign;
import com.github.wxiaoqi.security.admin.feign.dto.UserDTO;
import com.github.wxiaoqi.security.auth.client.config.UserAuthConfig;
......@@ -9,6 +10,7 @@ import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.BaseController;
import com.github.wxiaoqi.security.common.util.Query;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.github.wxiaoqi.security.common.vo.GoodDataVO;
import com.xxfc.platform.vehicle.biz.VehicleBiz;
import com.xxfc.platform.vehicle.biz.VehicleCataBiz;
import com.xxfc.platform.vehicle.biz.VehicleModelBiz;
......@@ -37,6 +39,7 @@ import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.weekend.WeekendSqls;
import javax.servlet.http.HttpServletRequest;
import java.awt.print.Pageable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
......@@ -93,28 +96,22 @@ public class VehicleModelController extends BaseController<VehicleModelBiz, Vehi
* @return
*/
@ApiOperation("车型列表")
@PostMapping(value = "/app/findVehicleModelPage")
public ObjectRestResponse<VehicleModelVo> findVehicleModelPage(
@PostMapping(value = "/app/unauthfind/findVehicleModelPage")
public ObjectRestResponse<VehicleModelVo> findVehicleModelPageUnauthfind(
@RequestBody @ApiParam("查询条件") VehicleModelQueryCondition vmqc ,HttpServletRequest request) {
// UserDTO user = userFeign.userinfoByToken(userAuthConfig.getToken(request)).getData();
//
// if (user!=null) {
// if (user.getDataAll()==2) {
//
// }
// }
if (vmqc.getIsDel()==null) {
vmqc.setIsDel(0);
}
if (vmqc == null || vmqc.getPage() == null || vmqc.getLimit() == null || vmqc.getPage() < 0 || vmqc.getLimit() <= 0) {
return ObjectRestResponse.createDefaultFail();
}
return vehicleModelBiz.findVehicleModelPage(vmqc);
}
/**
* 添加车型
*
......@@ -124,7 +121,6 @@ public class VehicleModelController extends BaseController<VehicleModelBiz, Vehi
*/
@ApiOperation("添加")
@PostMapping(value = "/app/add")
@ResponseBody
@Transactional
public ObjectRestResponse<VehicleModel> add(@RequestBody VehicleModel vm, HttpServletRequest request) {
if (vm == null) {
......@@ -156,6 +152,7 @@ public class VehicleModelController extends BaseController<VehicleModelBiz, Vehi
//设置信息
vm.setCrtName(uorr.getData().getName());
vm.setCrtUser(uorr.getData().getId());
vm.setHotSign(2);
vm.setCrtTime(new Date());
vm.setCrtHost(host);
vm.setIsdel(0);
......@@ -193,7 +190,6 @@ public class VehicleModelController extends BaseController<VehicleModelBiz, Vehi
@ApiOperation("修改")
@PutMapping(value = "/app/update")
@ResponseBody
@Transactional
public ObjectRestResponse<VehicleModel> update(@RequestBody VehicleModel vm, HttpServletRequest request) {
......@@ -252,26 +248,9 @@ public class VehicleModelController extends BaseController<VehicleModelBiz, Vehi
@Override
@ApiOperation("删除")
@DeleteMapping(value = "/app/{id}")
@ResponseBody
@Transactional
public ObjectRestResponse<VehicleModel> remove(@PathVariable int id) {
//1.先判断是否有属于该车型可用的车辆,有不能删除,无可以进行删除
//根据车型查询对应的车辆
// Example exa = Example.builder(Vehicle.class).where(
// WeekendSqls.<Vehicle>custom()
// .andEqualTo(Vehicle::getModelId, id)
// .andEqualTo(Vehicle::getStatus, 1)
// .orEqualTo(Vehicle::getStatus,"2")
// ).build();
//
// List<Vehicle> vehicles = vehicleBiz.selectByExample(exa);
//
// //判断是查询到对应的车辆
// if (vehicles != null) {
// ObjectRestResponse.createFailedResult(ResultCode.FAILED_CODE, "该车型,无法删除");
// }
if (id==1||id==14) {
return ObjectRestResponse.createFailedResult(ResultCode.FAILED_CODE,"The label cannot be deleted");
}
......@@ -302,4 +281,34 @@ public class VehicleModelController extends BaseController<VehicleModelBiz, Vehi
return ObjectRestResponse.succ(baseBiz.selectList(vehicleModel));
}
@ApiOperation("查询所有")
@GetMapping(value = "/goodList")
public List<GoodDataVO> goodList(@RequestParam("page") Integer page,@RequestParam("limit") Integer limit){
return baseBiz.goodList(page,limit);
}
/**
* 车型列表查
*
* @param vmqc 条件
* @return
*/
@ApiOperation("车型列表")
@PostMapping(value = "/app/findVehicleModelPage")
public ObjectRestResponse<VehicleModelVo> findVehicleModelPage(
@RequestBody @ApiParam("查询条件") VehicleModelQueryCondition vmqc ) {
if (vmqc.getIsDel()==null) {
vmqc.setIsDel(0);
}
if (vmqc == null || vmqc.getPage() == null || vmqc.getLimit() == null || vmqc.getPage() < 0 || vmqc.getLimit() <= 0) {
return ObjectRestResponse.createDefaultFail();
}
return vehicleModelBiz.findVehicleModelPage(vmqc);
}
}
\ No newline at end of file
......@@ -363,6 +363,14 @@
<if test=" catas != null ">
,GROUP_CONCAT(vc.cata_id) as catas
</if>
<!-- yearNo4Where 标识时间参数不用于where条件,用于select部分 -->
<if test=" yearMonthAndParam !=null and yearNo4Where != null and yearNo4Where == true">
,(
<foreach collection="yearMonthAndParam" index="yearMonth" item="andOperation" separator="and">
<include refid="yearMonthAndParamSql"></include>
</foreach>
) as hasVehicle
</if>
<if test="lon != null and lat != null">
,st_distance_sphere(point(#{lon}, #{lat}), point(bc.longitude, bc.latitude)) as distance
</if>
......@@ -372,6 +380,7 @@
and bc.id is not null
GROUP BY model_id, company_id
<if test="lon != null and lat != null">, distance</if>
<if test=" yearMonthAndParam !=null and yearNo4Where != null and yearNo4Where == true">, hasVehicle</if>
<!-- 循环 相同父级 数据做并集, 不同父级做或集 -->
<if test=" catas != null ">
......@@ -391,7 +400,10 @@
<if test="lon != null and lat != null">
order by
distance asc
<if test=" yearMonthAndParam !=null and yearNo4Where != null and yearNo4Where == true">
hasVehicle desc,
</if>
distance asc
</if>
</select>
......@@ -535,10 +547,10 @@
GROUP BY status
</select>
<!-- 查询可用车辆/车型 的公用 from 和 where 部分条件 -->
<sql id="searchUsableSql">
from vehicle v
<if test=" yearMonthAndParam !=null ">
<if test=" yearMonthAndParam !=null ">
left join
vehicle_book_info vbi on v.`id` = vbi.vehicle
</if>
......@@ -549,15 +561,14 @@
</if>
<where>
<!-- 若需根据预定日期条件查询,针对换为位操作 -->
<if test=" yearMonthAndParam !=null ">
<!-- yearNo4Where 标识时间参数是否用于where条件 -->
<if test=" yearMonthAndParam !=null and yearNo4Where == null">
<foreach collection="yearMonthAndParam" index="yearMonth" item="andOperation">
and
( (vbi.`year_month` = #{yearMonth} or vbi.`year_month` is null) and
ifnull(vbi.`booked_date`,0) &amp; #{andOperation.andOperationFactor} =
#{andOperation.andOperationRs}
)
and
<include refid="yearMonthAndParamSql"></include>
</foreach>
</if>
<if test=" modelId != null ">
and v.model_id = #{modelId}
</if>
......@@ -570,4 +581,13 @@
</where>
</sql>
<!-- 时间参数循环 -->
<sql id = "yearMonthAndParamSql">
<!-- 若需根据预定日期条件查询,针对换为位操作 -->
( (vbi.`year_month` = #{yearMonth} or vbi.`year_month` is null) and
ifnull(vbi.`booked_date`,0) &amp; #{andOperation.andOperationFactor} =
#{andOperation.andOperationRs}
)
</sql>
</mapper>
\ No newline at end of file
package com.xxfc.platform.vehicle;
import org.junit.Test;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;
public class ListTest {
@Test
public void ListTest(){
List<Object> objects = Arrays.asList();
System.out.println("objects.size()"+objects.get(0));
}
}
package com.xxfc.platform.vehicle;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.file.FileWriter;
import cn.hutool.json.JSONUtil;
import com.github.wxiaoqi.security.common.msg.TableResultResponse;
import com.github.wxiaoqi.security.common.util.Query;
import com.xxfc.platform.vehicle.biz.SysRegionBiz;
import com.xxfc.platform.vehicle.entity.SysRegion;
import lombok.Data;
import com.xxfc.platform.vehicle.entity.SimpleGenId;
import com.xxfc.platform.vehicle.entity.Student;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes={VehicleApplication.class})
......@@ -48,22 +38,16 @@ public class TimeTest {
}
@Test
public void testMapper(){
Student sOne = new Student("张4", "14",1);
sOne.getId();
// Assert.assertEquals();
SimpleGenId simpleGenId = new SimpleGenId();
Long aLong = simpleGenId.genId("6696", "122223");
}
}
@Data
class Student implements Serializable {
private String name;
private String age;
private int code;
public Student(String name, String age, int code) {
this.name=name;
this.age=age;
this.code=code;
}
public Student(String name, String age) {
this.name=name;
this.age=age;
}
}
package com.xxfc.platform.vehicle;
import org.junit.Test;
import org.springframework.core.task.TaskExecutor;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class TimedTaskTest {
public static void main(String[] args) {
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
executorService.scheduleWithFixedDelay(new MyRunnable(),0,4000,TimeUnit.MILLISECONDS);
}
// @Test
// public void fn1() {
// TaskExecutor taskExecutor = new TaskExecutor() {
// @Override
// public void execute(Runnable task) {
//
// ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
// executorService.scheduleAtFixedRate(
// () -> System.out.println("测试定时任务11111111111111" + System.currentTimeMillis()), 0, 100, TimeUnit.MILLISECONDS);
// System.out.println("========================================================================");
// executorService.schedule(new Runnable() {
// @Override
// public void run() {
// System.out.println("测试定时任务222222222222222222" + System.currentTimeMillis());
// }
// }, 10, TimeUnit.MILLISECONDS);
// }
// };
//
// }
private static class MyRunnable implements Runnable {
@Override
public void run() {
System.out.println("测试+++++++++++"+System.currentTimeMillis());
// ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
//
// executorService.scheduleWithFixedDelay(new Runnable() {
// @Override
// public void run() {
// System.out.println("测试+++++++"+System.currentTimeMillis());
// }
// },0,100,TimeUnit.MILLISECONDS);
}
}
}
package com.xxfc.platform.vehicle.entity;
public class IdService {
}
package com.xxfc.platform.vehicle.entity;
import tk.mybatis.mapper.genid.GenId;
public class SimpleGenId implements GenId<Long> {
private Long time;
private Integer seq;
@Override
public synchronized Long genId(String table, String column) {
long current = System.currentTimeMillis();
if (time == null || time != current) {
time = current;
seq = 1;
} else if (current == time) {
seq++;
}
return (time << 20) | seq;
}
}
\ No newline at end of file
package com.xxfc.platform.vehicle.entity;
import com.xxfc.platform.vehicle.entity.UUIdGenId;
import lombok.Data;
import tk.mybatis.mapper.annotation.KeySql;
import javax.persistence.Id;
import java.io.Serializable;
@Data
public class Student implements Serializable {
public static final Integer NO_AMOUNT_LIMIT = -1;
@Id
@KeySql(genId = UUIdGenId.class)
private Integer id;
private String name;
private String age;
private int code;
public Student(String name, String age, int code) {
this.name=name;
this.age=age;
this.code=code;
}
public Student(String name, String age) {
this.name=name;
this.age=age;
}
}
package com.xxfc.platform.vehicle.entity;
import tk.mybatis.mapper.genid.GenId;
import java.util.UUID;
public class UUIdGenId implements GenId {
@Override
public Object genId(String table, String column) {
return UUID.randomUUID().toString();
}
}
//package com.xxfc.platform.vehicle.entity;
//import tk.mybatis.mapper.genid.GenId;
//
//public class VestaGenId implements GenId<Long> {
// public Long genId(String table, String column){
// //ApplicationUtil.getBean 需要自己实现
// IdService idService = ApplicationUtil.getBean(IdService.class);
// return idService.genId();
// }
//}
\ 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