Commit 2f4f38c8 authored by jiaorz's avatar jiaorz

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

parents 427b3d04 dd3357f5
......@@ -192,8 +192,9 @@ public class AuthController {
public JSONObject registryWithApplet(
@RequestParam(value="username",defaultValue="")String username,
@RequestParam(value="nickname",defaultValue="")String nickname,
@RequestParam(value="headimgurl",defaultValue="")String headimgurl)throws Exception {
JSONObject data=appAuthService.appletRegistry(username,nickname,headimgurl);
@RequestParam(value="headimgurl",defaultValue="")String headimgurl,
@RequestParam(value="userid",defaultValue="0")Integer userid)throws Exception {
JSONObject data=appAuthService.appletRegistry(username,nickname,headimgurl,userid);
if(data!=null&&data.getInteger("status")== ResultCode.SUCCESS_CODE){
JSONObject result=data.getJSONObject("data");
if(result==null){
......
......@@ -65,5 +65,6 @@ public interface IUserService {
* @return
*/
@PostMapping("/api/app/applet/registry")
public JSONObject appletRegistry(@RequestParam(value="username")String username, @RequestParam(value="nickname")String nickname,@RequestParam(value="headimgurl")String headimgurl);
public JSONObject appletRegistry(@RequestParam(value="username")String username, @RequestParam(value="nickname")String nickname,
@RequestParam(value="headimgurl")String headimgurl,@RequestParam(value="userid",defaultValue="0")Integer userid);
}
......@@ -32,5 +32,5 @@ public interface AuthService {
* @param nickname
* @return
*/
JSONObject appletRegistry(String username,String headimgurl,String nickname);
JSONObject appletRegistry(String username,String headimgurl,String nickname,Integer userid);
}
......@@ -92,8 +92,8 @@ public class AppAuthServiceImpl implements AuthService {
}
@Override
public JSONObject appletRegistry(String username,String headimgurl,String nickname) {
return userService.appletRegistry(username,headimgurl,nickname);
public JSONObject appletRegistry(String username,String headimgurl,String nickname,Integer userid) {
return userService.appletRegistry(username,headimgurl,nickname,userid);
}
}
......@@ -90,7 +90,7 @@ public class AuthServiceImpl implements AuthService {
}
@Override
public JSONObject appletRegistry(String username,String headimgurl,String nickname) {
return userService.appletRegistry(username,headimgurl,nickname);
public JSONObject appletRegistry(String username,String headimgurl,String nickname,Integer userid) {
return userService.appletRegistry(username,headimgurl,nickname,userid);
}
}
package com.github.wxiaoqi.security.admin.entity;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 用户关系表
*
* @author libin
* @email 18178966185@163.com
* @date 2019-07-03 16:36:44
*/
@Data
@Table(name = "app_user_relation")
public class AppUserRelation 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;
/**
* 父id
*/
@Column(name = "parent_id")
@ApiModelProperty(value = "父id")
private Integer parentId;
/**
* 绑定的来源:1-app;2-小程序
*/
@Column(name = "bind_type")
@ApiModelProperty(value = "绑定的来源:1-app;2-小程序")
private Integer bindType;
/**
* 绑定时间
*/
@Column(name = "bind_time")
@ApiModelProperty(value = "绑定时间")
private Long bindTime;
/**
* 是否永久绑定关系:0-否;1-是
*/
@Column(name = "is_forever")
@ApiModelProperty(value = "是否永久绑定关系:0-否;1-是")
private Integer isForever;
/**
* 创建时间
*/
@Column(name = "ctr_time")
@ApiModelProperty(value = "创建时间")
private Long ctrTime;
/**
* 更新时间
*/
@Column(name = "upd_time")
@ApiModelProperty(value = "更新时间", hidden = true )
private Long updTime;
/**
* 是否删除:0-正常;1-删除
*/
@Column(name = "is_del")
@ApiModelProperty(value = "是否删除:0-正常;1-删除")
private Integer isDel;
}
package com.github.wxiaoqi.security.admin.entity;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 用户临时关系绑定表
*
* @author libin
* @email 18178966185@163.com
* @date 2019-07-03 16:36:44
*/
@Data
@Table(name = "app_user_relation_temp")
public class AppUserRelationTemp implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键id
*/
@Id
@GeneratedValue(generator = "JDBC")
@ApiModelProperty("主键id")
private Integer id;
/**
* 别的服务(比如小程序)用户id
*/
@Column(name = "temp_id")
@ApiModelProperty(value = "别的服务(比如小程序)用户id")
private Integer tempId;
/**
* 类型:1-小程序
*/
@Column(name = "type")
@ApiModelProperty(value = "类型:1-小程序")
private Integer type;
/**
* app用户id
*/
@Column(name = "user_id")
@ApiModelProperty(value = "app用户id")
private Integer userId;
/**
* 是否有效:0-有效;1-无效
*/
@Column(name = "is_valid")
@ApiModelProperty(value = "是否有效:0-有效;1-无效")
private Integer isValid;
/**
* 创建时间
*/
@Column(name = "crt_time")
@ApiModelProperty(value = "创建时间", hidden = true )
private Long crtTime;
/**
* 更新时间
*/
@Column(name = "upd_time")
@ApiModelProperty(value = "更新时间", hidden = true )
private Long updTime;
/**
* 是否删除:0-正常;1-删除
*/
@Column(name = "is_del")
@ApiModelProperty(value = "是否删除:0-正常;1-删除")
private Integer isDel;
}
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.entity.AppUserRelationTemp;
import com.github.wxiaoqi.security.admin.vo.AppUserVo;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.wxiaoqi.security.admin.entity.AppUserRelation;
import com.github.wxiaoqi.security.admin.mapper.AppUserRelationMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
/**
* 用户关系表
*
* @author libin
* @email 18178966185@163.com
* @date 2019-07-03 16:36:44
*/
@Service
public class AppUserRelationBiz extends BaseBiz<AppUserRelationMapper,AppUserRelation> {
@Autowired
AppUserRelationTempBiz relationTempBiz;
@Autowired
AppUserDetailBiz userDetailBiz;
/**
* 关系绑定
* @param userId
* @param parentId
*/
public void bindRelation(Integer userId,Integer parentId){
AppUserRelation relation=getMyBiz().getRelationByUserId(parentId);
if(relation==null){
relation=new AppUserRelation();
relation.setUserId(parentId);
insertSelective(relation);
}
relation=getMyBiz().getRelationByUserId(userId);
Long time=System.currentTimeMillis();
if(relation==null){
relation=new AppUserRelation();
relation.setUserId(userId);
relation.setParentId(parentId);
relation.setBindType(2);
relation.setBindTime(time);
insertSelective(relation);
}else {
if(relation.getParentId()==null||relation.getParentId()==0||(relation.getIsForever()!=1&&(time-relation.getBindTime())>3600)){
relation.setParentId(parentId);
relation.setBindType(2);
relation.setBindTime(time);
getMyBiz().updRelation(relation);
}
}
}
/**
* 小程序分享上下线绑定
* @param userid 当前人小程序id
* @param pid 分享人id
* @param platform_userid 当前人统一平台id
*/
public ObjectRestResponse shareParentByUserId(Integer userid, Integer pid, Integer platform_userid){
if(pid==null||pid==0||((platform_userid==null||platform_userid==0)&&(userid==0||userid==null))){
return ObjectRestResponse.createFailedResult(ResultCode.NULL_CODE, "参数为空");
}
if(platform_userid==null||platform_userid==0){
upRelationTemp(pid,userid);
}else {
AppUserVo userVo=userDetailBiz.getUserInfoById(platform_userid);
if(userVo==null){
upRelationTemp(pid,userid);
}else {
bindRelation(platform_userid,pid);
}
}
return ObjectRestResponse.succ();
}
/**
* 新增临时关系
* @param pid
* @param userid
*/
public void upRelationTemp(Integer pid,Integer userid){
AppUserRelationTemp relationTemp=new AppUserRelationTemp();
relationTemp.setUserId(pid);
relationTemp.setIsDel(0);
relationTemp.setType(1);
AppUserRelationTemp relationTemp1= relationTempBiz.selectOne(relationTemp);
if(relationTemp1==null){
relationTemp.setTempId(userid);
relationTempBiz.insertSelective(relationTemp);
}
}
/**
* 小程序上下线绑定
* @param platform_userid 当前人统一平台id
* @param userid 当前人小程序id
*/
public void bindByUserId(Integer platform_userid,Integer userid){
if(platform_userid==null||platform_userid==0||userid==null||userid==0){
return;
}
AppUserRelationTemp relationTemp =new AppUserRelationTemp();
relationTemp.setTempId(userid);
relationTemp.setIsValid(0);
relationTemp.setType(1);
relationTemp.setIsDel(0);
relationTemp=relationTempBiz.selectOne(relationTemp);
if(relationTemp==null){
return;
}
Integer parentId=relationTemp.getUserId();
bindRelation(platform_userid,parentId);
}
/**
* 获取用户的上线关系
* @param userId
* @return
*/
@Cache(key="user:relation{1}")
public AppUserRelation getRelationByUserId(Integer userId){
AppUserRelation relation=new AppUserRelation();
relation.setUserId(userId);
return selectOne(relation);
}
@CacheClear(key="user:relation{1.userId}")
public int updRelation(AppUserRelation appUserRelation){
return super.updateSelectiveByIdRe(appUserRelation);
}
private AppUserRelationBiz getMyBiz() {
return AopContext.currentProxy() != null ? (AppUserRelationBiz) AopContext.currentProxy() : this;
}
}
\ No newline at end of file
package com.github.wxiaoqi.security.admin.biz;
import org.springframework.stereotype.Service;
import com.github.wxiaoqi.security.admin.entity.AppUserRelationTemp;
import com.github.wxiaoqi.security.admin.mapper.AppUserRelationTempMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
/**
* 用户临时关系绑定表
*
* @author libin
* @email 18178966185@163.com
* @date 2019-07-03 16:36:44
*/
@Service
public class AppUserRelationTempBiz extends BaseBiz<AppUserRelationTempMapper,AppUserRelationTemp> {
}
\ No newline at end of file
package com.github.wxiaoqi.security.admin.mapper;
import com.github.wxiaoqi.security.admin.entity.AppUserRelation;
import tk.mybatis.mapper.common.Mapper;
/**
* 用户关系表
*
* @author libin
* @email 18178966185@163.com
* @date 2019-07-03 16:36:44
*/
public interface AppUserRelationMapper extends Mapper<AppUserRelation> {
}
package com.github.wxiaoqi.security.admin.mapper;
import com.github.wxiaoqi.security.admin.entity.AppUserRelationTemp;
import tk.mybatis.mapper.common.Mapper;
/**
* 用户临时关系绑定表
*
* @author libin
* @email 18178966185@163.com
* @date 2019-07-03 16:36:44
*/
public interface AppUserRelationTempMapper extends Mapper<AppUserRelationTemp> {
}
package com.github.wxiaoqi.security.admin.rest;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.BaseController;
import com.github.wxiaoqi.security.admin.biz.AppUserRelationBiz;
import com.github.wxiaoqi.security.admin.entity.AppUserRelation;
import io.swagger.annotations.ApiModelProperty;
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;
@RestController
@RequestMapping("relation")
public class AppUserRelationController extends BaseController<AppUserRelationBiz,AppUserRelation> {
@RequestMapping(value = "app/unauth/small/share",method = RequestMethod.GET)
@ApiModelProperty("小程序分享绑定")
public ObjectRestResponse share(
@RequestParam(value = "userid",defaultValue = "0")Integer userid,
@RequestParam(value = "pid",defaultValue = "0")Integer pid,
@RequestParam(value = "platform_userid",defaultValue = "0")Integer platform_userid
){
return baseBiz.shareParentByUserId(userid,pid,platform_userid);
}
}
\ No newline at end of file
......@@ -186,14 +186,16 @@ public class AppUserRest {
public JSONObject appletRegistry(
@RequestParam(value="username",defaultValue="")String username,
@RequestParam(value="nickname",defaultValue="")String nickname,
@RequestParam(value="headimgurl",defaultValue="")String headimgurl){
@RequestParam(value="headimgurl",defaultValue="")String headimgurl,
@RequestParam(value="userid",defaultValue="0")Integer userid
){
if(StringUtils.isBlank(headimgurl)){
headimgurl=SystemConfig.USER_HEADER_URL_DEFAULT;
}
if(StringUtils.isBlank(nickname)){
nickname=SystemConfig.USER_NIKENAME_DEFAULT+(int)((Math.random()*9+1)*100000);
}
return appPermissionService.appletRegistry(username,headimgurl,nickname);
return appPermissionService.appletRegistry(username,headimgurl,nickname,userid);
}
......
package com.github.wxiaoqi.security.admin.rpc.service;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.admin.biz.*;
import com.github.wxiaoqi.security.admin.biz.AppUserBiz;
import com.github.wxiaoqi.security.admin.biz.AppUserDetailBiz;
import com.github.wxiaoqi.security.admin.biz.AppUserLoginBiz;
......@@ -32,7 +33,6 @@ 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 javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -62,6 +62,9 @@ public class AppPermissionService {
@Autowired
ActivityFeign activityFeign;
@Autowired
AppUserRelationBiz relationBiz;
@Resource
private RegionFeign regionFeign;
......@@ -701,7 +704,7 @@ public class AppPermissionService {
* @param nickname
*/
@Transactional
public JSONObject applyRegister(String username, String password, String headimgurl,String nickname) {
public JSONObject applyRegister(String username, String password, String headimgurl,String nickname,Integer small_id) {
// 判断参数
if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) {
return JsonResultUtil.createFailedResult(ResultCode.NULL_CODE, "参数为空");
......@@ -740,6 +743,8 @@ public class AppPermissionService {
rsUserDetail.setChannel(UserSourceEnum.APPLET.getCode());
appUserDetailBiz.insertSelective(rsUserDetail);
log.error("注册:新增用户详情: " + userid);
//上线绑定
relationBiz.bindByUserId(userid,small_id);
//自动登录获取优惠卷
authCoupn(userid);
//发送短信通知用户
......@@ -747,7 +752,7 @@ public class AppPermissionService {
// 登录结果要做做统一处理
JSONObject data = autoLogin(userid, username, headimgurl, nickname);
// 到im注册,获取返回结果
Map<String,Object> map=registerIm(username,appUserLogin.getPassword(),nickname);
/*Map<String,Object> map=registerIm(username,appUserLogin.getPassword(),nickname);
if(map!=null){
Integer imUserId=Integer.parseInt(map.get("userId").toString());
String access_token=map.get("access_token").toString();
......@@ -763,7 +768,7 @@ public class AppPermissionService {
}
data.put("imToken",access_token);
data.put("imUserId",imUserId);
}
}*/
if (data != null) {
return JsonResultUtil.createSuccessResultWithObj(data);
......@@ -783,7 +788,7 @@ public class AppPermissionService {
* @param username
* @return
*/
public JSONObject appletRegistry(String username,String headimgurl,String nickname ){
public JSONObject appletRegistry(String username,String headimgurl,String nickname,Integer small_id){
try {
// 是否已存在
......@@ -791,9 +796,13 @@ public class AppPermissionService {
JSONObject data=new JSONObject();
if (null == user) {
String password="12345678";
data=applyRegister(username,password,headimgurl,nickname);
data=applyRegister(username,password,headimgurl,nickname,small_id);
}else{
data=appletLoginByUserId(user.getId());
Integer userid=user.getId();
//上线绑定
relationBiz.bindByUserId(userid,small_id);
//登录
data=appletLoginByUserId(userid);
}
return data;
} catch (Exception e) {
......@@ -808,14 +817,14 @@ public class AppPermissionService {
*/
public void setCreateIPInfo(AppUserLogin appUserLogin){
String crtHost = appUserLogin.getCrtHost();
String ipinfo = restTemplate.getForObject(String.format("%s%s", IPCommon.BASE_IP_PARSING_URL, crtHost), String.class);
String base_data = JSONObject.parseObject(ipinfo).getString(IPCommon.BASE_DATA);
JSONObject ipJsonObject = JSONObject.parseObject(base_data);
// Integer provinceCode = ipJsonObject.getInteger(IPCommon.PROVINCE_CODE);
// Integer cityCode = ipJsonObject.getInteger(IPCommon.CITY_CODE);
String ipAddress = restTemplate.getForObject(String.format("%s%s", IPAddress.BASE_IP_PARSING_URL, crtHost), String.class);
String data = JSONObject.parseObject(ipAddress).getString(IPAddress.BASE_DATA);
JSONObject ipJsonObject = JSONObject.parseObject(data);
// Integer provinceCode = ipJsonObject.getInteger(IPAddress.PROVINCE_CODE);
// Integer cityCode = ipJsonObject.getInteger(IPAddress.CITY_CODE);
//appUserLogin.setProvinceCode(provinceCode);
//appUserLogin.setCityCode(cityCode);
String cityName = ipJsonObject.getString(IPCommon.CITY_NAME);
String cityName = ipJsonObject.getString(IPAddress.CITY_NAME);
RegionDTO regionDTO = regionFeign.getRegionByCityName(cityName);
if (null!=regionDTO){
appUserLogin.setProvinceCode(Integer.valueOf(String.valueOf(regionDTO.getParentId())));
......@@ -826,9 +835,9 @@ public class AppPermissionService {
/**
* @author libin
* @version 1.0.0
* @dec ip返回字段名常量
* @dec ip 解析返回的地址信息
*/
static class IPCommon{
private static class IPAddress{
public static final String BASE_IP_PARSING_URL="http://ip.taobao.com/service/getIpInfo.php?ip=";
public static final String BASE_DATA="data";
public static final String PROVINCE_CODE="region_id";
......
......@@ -10,7 +10,7 @@ spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://10.5.52.3:3306/xxfc_tour?useUnicode=true&characterEncoding=UTF-8
url: jdbc:mysql://10.5.52.3:3306/ag_admin_v1?useUnicode=true&characterEncoding=UTF-8
username: root
password: sslcloud123*()
jackson:
......
#\u4EE3\u7801\u751F\u6210\u5668\uFF0C\u914D\u7F6E\u4FE1\u606F
#\u5305\u540D
package=com.xxfc.platform.tour
package=com.github.wxiaoqi.security.admin
#\u4F5C\u8005
author=libin
#Email
......
......@@ -65,4 +65,7 @@ public class CampsiteShopDetailDTO {
@ApiModelProperty(value = "纬度")
private Double latitude;
@ApiModelProperty(value = "电话")
private String phone;
}
......@@ -89,4 +89,7 @@ public class CampsiteShopDetailVo {
*/
@ApiModelProperty("轮播图列表")
private List<CampsiteShopCarouselDetailVo> campsiteShopCarouselDetailVos;
@ApiModelProperty(value = "電話")
private String phone;
}
......@@ -26,7 +26,6 @@ import tk.mybatis.spring.annotation.MapperScan;
@EnableScheduling
@EnableFeignClients(value = {"com.github.wxiaoqi.security.auth.client.feign", "com.github.wxiaoqi.security.admin.feign","com.xxfc.platform"},defaultConfiguration = HeaderConfig.class)
@EnableAceCache
@EnableCaching
@MapperScan(basePackages = "com.xxfc.platform.campsite.mapper")
public class CampSiteApplication {
public static void main(String[] args) {
......
package com.xxfc.platform.campsite.biz;
import com.ace.cache.annotation.Cache;
import com.ace.cache.annotation.CacheClear;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.github.wxiaoqi.security.common.vo.GoodDataVO;
......@@ -10,6 +12,9 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import com.xxfc.platform.campsite.entity.CampsiteShop;
......@@ -18,6 +23,7 @@ import com.github.wxiaoqi.security.common.biz.BaseBiz;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
......@@ -33,25 +39,48 @@ import java.util.stream.Collectors;
*/
@Service
@Slf4j
public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper,CampsiteShop> {
/**
public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper, CampsiteShop> {
/**
* 地球半径,单位 km
*/
private static final double EARTH_RADIUS = 6378.137;
private static final double EARTH_RADIUS = 6378.137;
@Autowired
private CampsiteShopTagBiz campsiteShopTagBiz;
@Autowired
private CampsiteShopCarouselBiz campsiteShopCarouselBiz;
@Autowired
private RedisTemplate<String, String> redisTemplate;
@Resource(name = "customRedisTemplate")
HashOperations<String, String, String> campHashOperations;
@Autowired
private CampsiteShopTagBiz campsiteShopTagBiz;
@Resource(name = "customRedisTemplate")
ValueOperations<String, String> campsiteValueOperations;
@Autowired
private CampsiteShopCarouselBiz campsiteShopCarouselBiz;
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";
/**
* 根据店铺类型查找列表
*
* @param type
* @return
*/
public PageDataVO<CampsiteShopPageVo> findCampsiteShopPageByType(Integer type,Integer pageNo,Integer pageSize) {
//根据type类型查找店铺
public PageDataVO<CampsiteShopPageVo> findCampsiteShopPageByType(Integer type, Integer pageNo, Integer pageSize) {
//根据type类型查找店铺
String result = null;
if (Objects.isNull(type)) {
result = campHashOperations.get(CAMPSITE_CACHE, CAMPSITE_CACHE_ALL);
} else {
result = campHashOperations.get(CAMPSITE_CACHE, String.format("%s%d%d", String.valueOf(type), pageNo, pageSize));
}
if (result != null) {
return JSONObject.parseObject(result,new TypeReference<PageDataVO<CampsiteShopPageVo>>(){});
}
PageDataVO<CampsiteShopPageDTO> pageDataVO = PageDataVO.pageInfo(pageNo, pageSize, () -> mapper.findAllCampsiteShopsByType(type));
List<CampsiteShopPageDTO> campsiteShopPageDTOS = pageDataVO.getData();
......@@ -60,77 +89,91 @@ public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper,CampsiteShop> {
campsiteShopPageDataVO.setTotalCount(pageDataVO.getTotalCount());
campsiteShopPageDataVO.setPageSize(pageDataVO.getPageSize());
campsiteShopPageDataVO.setPageNum(pageDataVO.getPageNum());
if (CollectionUtils.isEmpty(campsiteShopPageDTOS)){
if (CollectionUtils.isEmpty(campsiteShopPageDTOS)) {
campsiteShopPageDataVO.setData(new ArrayList<CampsiteShopPageVo>());
return campsiteShopPageDataVO;
return campsiteShopPageDataVO;
}
if (log.isDebugEnabled()){
log.debug("根据type=【{}】查询到的店铺数据:【{}】",type,campsiteShopPageDTOS);
if (log.isDebugEnabled()) {
log.debug("根据type=【{}】查询到的店铺数据:【{}】", type, campsiteShopPageDTOS);
}
List<CampsiteShopPageVo> campsiteShopPageVoList = new ArrayList<>();
campsiteShopPageDTOS = campsiteShopPageDTOS.stream().distinct().collect(Collectors.toList());
for (CampsiteShopPageDTO campsiteShopPageDTO : campsiteShopPageDTOS) {
CampsiteShopPageVo campsiteShopPageVo = new CampsiteShopPageVo();
BeanUtils.copyProperties(campsiteShopPageDTO,campsiteShopPageVo);
BeanUtils.copyProperties(campsiteShopPageDTO, campsiteShopPageVo);
campsiteShopPageVoList.add(campsiteShopPageVo);
}
campsiteShopPageVoList.sort(Comparator.comparing(CampsiteShopPageVo::getHot).reversed().thenComparing(CampsiteShopPageVo::getCrtTime).reversed());
campsiteShopPageDataVO.setData(campsiteShopPageVoList);
if (Objects.isNull(type)) {
campHashOperations.put(CAMPSITE_CACHE, CAMPSITE_CACHE_ALL, JSONObject.toJSONString(campsiteShopPageDataVO));
} else {
campHashOperations.put(CAMPSITE_CACHE, String.format("%s%d%d", String.valueOf(type), pageNo, pageSize), JSONObject.toJSONString(campsiteShopPageDataVO));
}
return campsiteShopPageDataVO;
}
/**
* 根据店铺id查询店铺详情
*
* @param id
* @return
*/
public CampsiteShopDetailVo findCampsiteShopDetailById(Integer id,Double longitude,Double latitude) {
public CampsiteShopDetailVo findCampsiteShopDetailById(Integer id, Double longitude, Double latitude) {
String result = campsiteValueOperations.get(String.format("%s%d", CAMSITE_DETAIL_CACHE, id));
if (Objects.nonNull(result)){
return JSONObject.parseObject(result,new TypeReference<CampsiteShopDetailVo>(){});
}
CampsiteShopDetailVo campsiteShopDetailVo = new CampsiteShopDetailVo();
//从店铺表根据店铺id查询
CampsiteShopDetailDTO campsiteShopDetailDTO = mapper.findCampsiteShopDetailById(id);
if (log.isDebugEnabled()){
log.debug("根据店铺id=【{}】查询出店铺信息【{}】",id,campsiteShopDetailDTO);
}
BeanUtils.copyProperties(campsiteShopDetailDTO,campsiteShopDetailVo);
//从轮播表根据店铺id查询
List<CampsiteShopCarouselDetailDTO> campsiteShopCarouselDTOS = campsiteShopCarouselBiz.findByCampsiteShopId(id);
if (log.isDebugEnabled()){
log.debug("根据店铺id=【{}】查询出店铺轮播图信息:【{}】",id,campsiteShopCarouselDTOS);
}
List<CampsiteShopCarouselDetailVo> campsiteShopCarouselDetailVos = new ArrayList<>();
if (CollectionUtils.isNotEmpty(campsiteShopCarouselDTOS)) {
campsiteShopCarouselDTOS.forEach(campsiteShopCarouselDetailDTO -> {
CampsiteShopCarouselDetailVo carouselDetailVo = new CampsiteShopCarouselDetailVo();
BeanUtils.copyProperties(campsiteShopCarouselDetailDTO, carouselDetailVo);
campsiteShopCarouselDetailVos.add(carouselDetailVo);
});
}
campsiteShopDetailVo.setCampsiteShopCarouselDetailVos(campsiteShopCarouselDetailVos);
//从店铺类型表根据店铺id查询 -->类型列表拼接
CampsiteShopDetailDTO campsiteShopDetailDTO = mapper.findCampsiteShopDetailById(id);
if (log.isDebugEnabled()) {
log.debug("根据店铺id=【{}】查询出店铺信息【{}】", id, campsiteShopDetailDTO);
}
if (Objects.isNull(campsiteShopDetailDTO)){
return campsiteShopDetailVo;
}
BeanUtils.copyProperties(campsiteShopDetailDTO, campsiteShopDetailVo);
//从轮播表根据店铺id查询
List<CampsiteShopCarouselDetailDTO> campsiteShopCarouselDTOS = campsiteShopCarouselBiz.findByCampsiteShopId(id);
if (log.isDebugEnabled()) {
log.debug("根据店铺id=【{}】查询出店铺轮播图信息:【{}】", id, campsiteShopCarouselDTOS);
}
List<CampsiteShopCarouselDetailVo> campsiteShopCarouselDetailVos = new ArrayList<>();
if (CollectionUtils.isNotEmpty(campsiteShopCarouselDTOS)) {
campsiteShopCarouselDTOS.forEach(campsiteShopCarouselDetailDTO -> {
CampsiteShopCarouselDetailVo carouselDetailVo = new CampsiteShopCarouselDetailVo();
BeanUtils.copyProperties(campsiteShopCarouselDetailDTO, carouselDetailVo);
campsiteShopCarouselDetailVos.add(carouselDetailVo);
});
}
campsiteShopDetailVo.setCampsiteShopCarouselDetailVos(campsiteShopCarouselDetailVos);
//从店铺类型表根据店铺id查询 -->类型列表拼接
List<CampsiteShopTagDTO> shopTagDTOS = campsiteShopTagBiz.findByCampsiteShopId(id);
if (log.isDebugEnabled()){
log.debug("根据店铺id=【{}】查询出店铺类型:【{}】",id,shopTagDTOS);
}
campsiteShopDetailVo.setTypeNames(shopTagDTOS==null?Collections.EMPTY_LIST:shopTagDTOS.stream().map(CampsiteShopTagDTO::getName).collect(Collectors.toList()));
if (log.isDebugEnabled()) {
log.debug("根据店铺id=【{}】查询出店铺类型:【{}】", id, shopTagDTOS);
}
campsiteShopDetailVo.setTypeNames(shopTagDTOS == null ? Collections.EMPTY_LIST : shopTagDTOS.stream().map(CampsiteShopTagDTO::getName).collect(Collectors.toList()));
//根据经纬度算距离
double distance = getDistance(campsiteShopDetailDTO.getLongitude(),campsiteShopDetailDTO.getLatitude(),longitude,latitude);
if (log.isDebugEnabled()){
log.debug("根据店铺经度=【{}】,纬度=【{}】和自己所在位置的经度=【{}】,纬度=【{}】计算出的距离:【{}km】",campsiteShopDetailDTO.getLongitude(),campsiteShopDetailDTO.getLatitude(),longitude,latitude,distance);
}
campsiteShopDetailVo.setDistance(String.format("%.1f",distance));
return campsiteShopDetailVo;
double distance = getDistance(campsiteShopDetailDTO.getLongitude(), campsiteShopDetailDTO.getLatitude(), longitude, latitude);
if (log.isDebugEnabled()) {
log.debug("根据店铺经度=【{}】,纬度=【{}】和自己所在位置的经度=【{}】,纬度=【{}】计算出的距离:【{}km】", campsiteShopDetailDTO.getLongitude(), campsiteShopDetailDTO.getLatitude(), longitude, latitude, distance);
}
campsiteShopDetailVo.setDistance(String.format("%.1f", distance));
campsiteValueOperations.set(String.format("%s%d",CAMSITE_DETAIL_CACHE,id),JSONObject.toJSONString(campsiteShopDetailVo));
return campsiteShopDetailVo;
}
/**
* 根据创建时间或营地名称来查找营地列表
*
* @param campsiteShopAdminFindDTO
* @return
*/
public PageDataVO<CampsiteShopAdminPageVo> findCampsiteShopPage(CampsiteShopAdminFindDTO campsiteShopAdminFindDTO) {
if (log.isDebugEnabled()){
log.debug("查询条件:【{}】",campsiteShopAdminFindDTO);
if (log.isDebugEnabled()) {
log.debug("查询条件:【{}】", campsiteShopAdminFindDTO);
}
//筛选时间处理
......@@ -146,21 +189,21 @@ public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper,CampsiteShop> {
campsiteShopAdminFindDTO.setStartTime(processStartTime(startTime));
campsiteShopAdminFindDTO.setEndTime(processEndTime(endTime));
}*/
PageDataVO<CampsiteShopAdminPageDTO> campsiteShopAdminpageDTOPageDataVO = PageDataVO.pageInfo(campsiteShopAdminFindDTO.getPage(),campsiteShopAdminFindDTO.getLimit(),()->mapper.findAllCampsiteShops(campsiteShopAdminFindDTO));
PageDataVO<CampsiteShopAdminPageDTO> campsiteShopAdminpageDTOPageDataVO = PageDataVO.pageInfo(campsiteShopAdminFindDTO.getPage(), campsiteShopAdminFindDTO.getLimit(), () -> mapper.findAllCampsiteShops(campsiteShopAdminFindDTO));
List<CampsiteShopAdminPageDTO> campsiteShopAdminPageDTOS = campsiteShopAdminpageDTOPageDataVO.getData();
if (log.isDebugEnabled()){
log.debug("查询结果:【{}】",campsiteShopAdminPageDTOS);
if (log.isDebugEnabled()) {
log.debug("查询结果:【{}】", campsiteShopAdminPageDTOS);
}
PageDataVO<CampsiteShopAdminPageVo> campsiteShopAdminPageDataVos = new PageDataVO<>();
if (CollectionUtils.isEmpty(campsiteShopAdminPageDTOS)){
if (CollectionUtils.isEmpty(campsiteShopAdminPageDTOS)) {
return campsiteShopAdminPageDataVos;
}
//转换成营地ids
List<Integer> campsiteShopIds = campsiteShopAdminPageDTOS.stream().map(CampsiteShopAdminPageDTO::getId).collect(Collectors.toList());
//根据营地ids查询营地对应的标签 键营地id 值对应的标签列表
Map<Integer,List<String>> shopTagsMap = campsiteShopTagBiz.findByCampsiteShopIds(campsiteShopIds);
if (log.isDebugEnabled()){
log.debug("营地id为:【{}】的类型【{}】",campsiteShopIds,shopTagsMap);
Map<Integer, List<String>> shopTagsMap = campsiteShopTagBiz.findByCampsiteShopIds(campsiteShopIds);
if (log.isDebugEnabled()) {
log.debug("营地id为:【{}】的类型【{}】", campsiteShopIds, shopTagsMap);
}
campsiteShopAdminPageDTOS = campsiteShopAdminPageDTOS.stream().peek(campsiteShopAdminPageDTO -> {
if (Objects.nonNull(shopTagsMap)) {
......@@ -173,52 +216,56 @@ public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper,CampsiteShop> {
campsiteShopAdminPageDataVos.setTotalCount(campsiteShopAdminpageDTOPageDataVO.getTotalCount());
campsiteShopAdminPageDataVos.setPageSize(campsiteShopAdminpageDTOPageDataVO.getPageSize());
campsiteShopAdminPageDataVos.setPageNum(campsiteShopAdminpageDTOPageDataVO.getPageNum());
campsiteShopAdminPageDataVos.setData(JSONObject.parseObject(JSONObject.toJSONString(campsiteShopAdminPageDTOS),new TypeReference<List<CampsiteShopAdminPageVo>>(){}));
campsiteShopAdminPageDataVos.setData(JSONObject.parseObject(JSONObject.toJSONString(campsiteShopAdminPageDTOS), new TypeReference<List<CampsiteShopAdminPageVo>>() {
}));
return campsiteShopAdminPageDataVos;
}
/**
* 营地保存或更新
*
* @param campsiteShopAdminDTO
* @return
*/
@Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public int saveCampsiteShop(CampsiteShopAdminDTO campsiteShopAdminDTO) {
CampsiteShop campsiteShop = new CampsiteShop();
campsiteShopAdminDTO.setName(campsiteShopAdminDTO.getName()==null?null:campsiteShopAdminDTO.getName().trim());
BeanUtils.copyProperties(campsiteShopAdminDTO,campsiteShop);
campsiteShopAdminDTO.setName(campsiteShopAdminDTO.getName() == null ? null : campsiteShopAdminDTO.getName().trim());
BeanUtils.copyProperties(campsiteShopAdminDTO, campsiteShop);
int effectRows = 0;
if (Objects.nonNull(campsiteShopAdminDTO.getId())){
if (log.isDebugEnabled()){
log.debug("更新营地的信息:【{}】",campsiteShop);
if (Objects.nonNull(campsiteShopAdminDTO.getId())) {
if (log.isDebugEnabled()) {
log.debug("更新营地的信息:【{}】", campsiteShop);
}
//更新操作
//更新操作
campsiteShop.setUpdTime(Instant.now().toEpochMilli());
effectRows = mapper.updateByPrimaryKeySelective(campsiteShop);
}else {
effectRows = mapper.updateByPrimaryKeySelective(campsiteShop);
} else {
//保存操作
//保存营地信息
if (log.isDebugEnabled()){
log.debug("保存营地的信息:【{}】",campsiteShop);
if (log.isDebugEnabled()) {
log.debug("保存营地的信息:【{}】", campsiteShop);
}
campsiteShop.setCrtTime(Instant.now().toEpochMilli());
effectRows = mapper.insertSelective(campsiteShop);
effectRows = mapper.insertSelective(campsiteShop);
}
//保存或更新 * 营地与 轮播图信息
List<CampsiteShopCarouselDTO> carouselDTOS = campsiteShopAdminDTO.getCarouselDTOS();
if (CollectionUtils.isNotEmpty(carouselDTOS)) {
carouselDTOS.stream().peek(campsiteShopCarouselDTO -> campsiteShopCarouselDTO.setShopId(campsiteShop.getId())).count();
}
campsiteShopCarouselBiz.saveBatch(carouselDTOS,campsiteShop.getId());
campsiteShopCarouselBiz.saveBatch(carouselDTOS, campsiteShop.getId());
//保存或更新 * 营地与营地类型信息
List<Integer> campsiteTagDTOS = campsiteShopAdminDTO.getCampsiteTagDTOS();
campsiteShopTagBiz.saveBatch(campsiteTagDTOS,campsiteShop.getId());
campsiteShopTagBiz.saveBatch(campsiteTagDTOS, campsiteShop.getId());
redisTemplate.delete(CAMPSITE_CACHE);
return effectRows;
}
/**
* 编辑查询
*
* @param id
* @return
*/
......@@ -251,50 +298,67 @@ public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper,CampsiteShop> {
});
campsiteShopAdminVO.setCampsiteTagListVos(shopTagVos);
}
campsiteShopAdminVO.setCarouse(campsiteShopAdminVO.getCarouse()==null?new ArrayList<CampsiteShopCarouselVo>():campsiteShopAdminVO.getCarouse());
campsiteShopAdminVO.setCampsiteTagListVos(campsiteShopAdminVO.getCampsiteTagListVos()==null?new ArrayList<CampsiteTagListVo>():campsiteShopAdminVO.getCampsiteTagListVos());
campsiteShopAdminVO.setCarouse(campsiteShopAdminVO.getCarouse() == null ? new ArrayList<CampsiteShopCarouselVo>() : campsiteShopAdminVO.getCarouse());
campsiteShopAdminVO.setCampsiteTagListVos(campsiteShopAdminVO.getCampsiteTagListVos() == null ? new ArrayList<CampsiteTagListVo>() : campsiteShopAdminVO.getCampsiteTagListVos());
redisTemplate.delete(String.format("%s%d",CAMSITE_DETAIL_CACHE,id));
redisTemplate.delete(CAMPSITE_CACHE);
return campsiteShopAdminVO;
}
/**
* 逻辑删除
*
* @param id
* @return
*/
public int updateCampsiteSatus(int id) {
return mapper.updateCampsiteStatusById(id,1);
int effectRows = mapper.updateCampsiteStatusById(id, 1);
if (effectRows>0){
redisTemplate.delete(String.format("%s%d",CAMSITE_DETAIL_CACHE,id));
redisTemplate.delete(CAMPSITE_CACHE);
}
return effectRows;
}
/**
* 上下架
*
* @param id
* @param status
* @return
*/
public int updateCampsiteSaleStatus(Integer id, Integer status) {
return mapper.updateCampsiteSaleStatusById(id,status);
int effectRows = mapper.updateCampsiteSaleStatusById(id, status);
if (effectRows>0){
redisTemplate.delete(String.format("%s%d",CAMSITE_DETAIL_CACHE,id));
redisTemplate.delete(CAMPSITE_CACHE);
}
return effectRows;
}
/**
* 检验营地名称是否存在
*
* @param id
* @param name
* @return
*/
public Boolean chekcCampsiteNameExist(Integer id, String name) {
int count = mapper.checkNameExist(id,name);
if (count == 0) {
return false;
}
int count = mapper.checkNameExist(id, name);
if (count == 0) {
return false;
}
return true;
}
/**
* 处理开始时间
*
* @param time
* @return
*/
private long processStartTime(Long time){
return LocalDateTime.ofInstant(new Date(time).toInstant(), ZoneOffset.ofHours(+8))
private long processStartTime(Long time) {
return LocalDateTime.ofInstant(new Date(time).toInstant(), ZoneOffset.ofHours(+8))
.withHour(0)
.withMinute(0)
.withSecond(0)
......@@ -305,18 +369,20 @@ public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper,CampsiteShop> {
/**
* 处理结束时间
*
* @param time
* @return
*/
private long processEndTime(Long time){
return LocalDateTime.ofInstant(new Date(time).toInstant(), ZoneOffset.ofHours(+8))
.withHour(23)
.withMinute(59)
.withSecond(59)
.withNano(999)
.toInstant(ZoneOffset.ofHours(+8))
.toEpochMilli();
private long processEndTime(Long time) {
return LocalDateTime.ofInstant(new Date(time).toInstant(), ZoneOffset.ofHours(+8))
.withHour(23)
.withMinute(59)
.withSecond(59)
.withNano(999)
.toInstant(ZoneOffset.ofHours(+8))
.toEpochMilli();
}
/**
* 根据经纬度,计算两点间的距离
*
......@@ -341,20 +407,22 @@ public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper,CampsiteShop> {
double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(b / 2), 2)));
// 弧长乘地球半径, 返回单位: 千米
s = s * EARTH_RADIUS;
s = s * EARTH_RADIUS;
return s;
}
/**
* 首页营地列表
*
* @param page
* @param limit
* @return
*/
public List<GoodDataVO> getAllByHome(Integer page, Integer limit){
return mapper.findAllByHome((page-1)*limit,limit);
};
public List<GoodDataVO> getAllByHome(Integer page, Integer limit) {
return mapper.findAllByHome((page - 1) * limit, limit);
}
;
}
\ No newline at end of file
......@@ -5,9 +5,12 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import java.util.Objects;
/**
* ${DESCRIPTION}
*
......@@ -19,7 +22,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
@Primary
public class RedisConfiguration {
@Bean
@Bean("customRedisTemplate")
public RedisTemplate<String, Object> customRedisTemplate(RedisConnectionFactory factory) {
RedisTemplate redisTemplate = new RedisTemplate();
redisTemplate.setConnectionFactory(factory);
......@@ -27,7 +30,7 @@ public class RedisConfiguration {
redisTemplate.setKeySerializer(stringSerializer);
redisTemplate.setValueSerializer(stringSerializer);
redisTemplate.setHashKeySerializer(stringSerializer);
redisTemplate.setHashValueSerializer(stringSerializer);
redisTemplate.setHashValueSerializer(new Jackson2JsonRedisSerializer<Object>(Object.class));
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
......
......@@ -58,7 +58,7 @@
<!--根据id查询详情-->
<select id="findCampsiteShopDetailById" resultType="com.xxfc.platform.campsite.dto.CampsiteShopDetailDTO">
select `name` as `name`,`province_name` as `provinceName`,`city_name` as `cityName`,`address` as `address`,
select `name` as `name`,`province_name` as `provinceName`,`city_name` as `cityName`,`address` as `address`,`service_phone` as `phone`,
`content` as `content`,`configure` as `configure`,`longitude` as `longitude`,`latitude` as `latitude` from `campsite_shop` where `id`=#{id}
</select>
......
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