Commit d81b08a4 authored by libin's avatar libin

wg

parent e9911094
...@@ -32,7 +32,6 @@ import java.lang.reflect.Parameter; ...@@ -32,7 +32,6 @@ import java.lang.reflect.Parameter;
*/ */
@Aspect @Aspect
@Component @Component
@ComponentScan("com.xxfc.platform")
@ConditionalOnClass(value = UserFeign.class) @ConditionalOnClass(value = UserFeign.class)
public class TokenAop { public class TokenAop {
......
package com.xxfc.platform.campsite.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.Table;
import java.io.Serializable;
/**
* 店铺类型表
*
* @author libin
* @email 18178966185@163.com
* @date 2019-06-17 10:28:48
*/
@Data
@Table(name = "campsite_tag")
@ApiModel(value = "店铺类型dto")
public class CampsiteTagListDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("主键id")
private Integer id;
/**
* 名称
*/
@ApiModelProperty(value = "名称")
private String name;
}
...@@ -28,6 +28,18 @@ public class CampsiteShopDetailVo { ...@@ -28,6 +28,18 @@ public class CampsiteShopDetailVo {
@ApiModelProperty("店铺名称") @ApiModelProperty("店铺名称")
private String name; private String name;
/**
* 地址-省/直辖市(名称)
*/
@ApiModelProperty("地址-省/直辖市(名称)")
private String provinceName;
/**
* 地址-市(名称)
*/
@ApiModelProperty("地址-市(名称)")
private String cityName;
/** /**
* 具体地址 * 具体地址
*/ */
...@@ -57,7 +69,20 @@ public class CampsiteShopDetailVo { ...@@ -57,7 +69,20 @@ public class CampsiteShopDetailVo {
* *
*/ */
@ApiModelProperty("类型列表") @ApiModelProperty("类型列表")
private String typeNames; private List<String> typeNames;
/**
* 经度
*/
@ApiModelProperty(value = "经度")
private Double longitude;
/**
* 纬度
*/
@ApiModelProperty(value = "纬度")
private Double latitude;
/** /**
*轮播图列表 *轮播图列表
......
package com.xxfc.platform.campsite.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.Table;
import java.io.Serializable;
/**
* 店铺类型表
*
* @author libin
* @email 18178966185@163.com
* @date 2019-06-17 10:28:48
*/
@Data
@Table(name = "campsite_tag")
@ApiModel(value = "店铺类型vo")
public class CampsiteTagListVo implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("主键id")
private Integer id;
/**
* 名称
*/
@ApiModelProperty(value = "名称")
private String name;
}
...@@ -64,7 +64,7 @@ public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper,CampsiteShop> { ...@@ -64,7 +64,7 @@ public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper,CampsiteShop> {
return campsiteShopPageDataVO; return campsiteShopPageDataVO;
} }
if (log.isDebugEnabled()){ if (log.isDebugEnabled()){
log.debug("根据type=[{}]查询到的店铺数据:[{}]",type,campsiteShopPageDTOS); log.debug("根据type=【{}】查询到的店铺数据:【{}】",type,campsiteShopPageDTOS);
} }
List<CampsiteShopPageVo> campsiteShopPageVoList = new ArrayList<>(); List<CampsiteShopPageVo> campsiteShopPageVoList = new ArrayList<>();
for (CampsiteShopPageDTO campsiteShopPageDTO : campsiteShopPageDTOS) { for (CampsiteShopPageDTO campsiteShopPageDTO : campsiteShopPageDTOS) {
...@@ -88,13 +88,13 @@ public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper,CampsiteShop> { ...@@ -88,13 +88,13 @@ public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper,CampsiteShop> {
//从店铺表根据店铺id查询 //从店铺表根据店铺id查询
CampsiteShopDetailDTO campsiteShopDetailDTO = mapper.findCampsiteShopDetailById(id); CampsiteShopDetailDTO campsiteShopDetailDTO = mapper.findCampsiteShopDetailById(id);
if (log.isDebugEnabled()){ if (log.isDebugEnabled()){
log.debug("根据店铺id=[{}]查询出店铺信息[{}]",id,campsiteShopDetailDTO); log.debug("根据店铺id=【{}】查询出店铺信息【{}】",id,campsiteShopDetailDTO);
} }
BeanUtils.copyProperties(campsiteShopDetailDTO,campsiteShopDetailVo); BeanUtils.copyProperties(campsiteShopDetailDTO,campsiteShopDetailVo);
//从轮播表根据店铺id查询 //从轮播表根据店铺id查询
List<CampsiteShopCarouselDetailDTO> campsiteShopCarouselDTOS = campsiteShopCarouselBiz.findByCampsiteShopId(id); List<CampsiteShopCarouselDetailDTO> campsiteShopCarouselDTOS = campsiteShopCarouselBiz.findByCampsiteShopId(id);
if (log.isDebugEnabled()){ if (log.isDebugEnabled()){
log.debug("根据店铺id=[{}]查询出店铺轮播图信息:[{}]",id,campsiteShopCarouselDTOS); log.debug("根据店铺id=【{}】查询出店铺轮播图信息:【{}】",id,campsiteShopCarouselDTOS);
} }
List<CampsiteShopCarouselDetailVo> campsiteShopCarouselDetailVos = new ArrayList<>(); List<CampsiteShopCarouselDetailVo> campsiteShopCarouselDetailVos = new ArrayList<>();
campsiteShopCarouselDTOS.forEach(campsiteShopCarouselDetailDTO -> { campsiteShopCarouselDTOS.forEach(campsiteShopCarouselDetailDTO -> {
...@@ -106,15 +106,13 @@ public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper,CampsiteShop> { ...@@ -106,15 +106,13 @@ public class CampsiteShopBiz extends BaseBiz<CampsiteShopMapper,CampsiteShop> {
//从店铺类型表根据店铺id查询 -->类型列表拼接 //从店铺类型表根据店铺id查询 -->类型列表拼接
List<String> typeNameList = campsiteShopTagBiz.findByCampsiteShopId(id); List<String> typeNameList = campsiteShopTagBiz.findByCampsiteShopId(id);
if (log.isDebugEnabled()){ if (log.isDebugEnabled()){
log.debug("根据店铺id=[{}]查询出店铺类型:[{}]",id,typeNameList); log.debug("根据店铺id=【{}】查询出店铺类型:【{}】",id,typeNameList);
} }
campsiteShopDetailVo.setTypeNames(typeNameList.stream().collect(Collectors.joining("|"))); campsiteShopDetailVo.setTypeNames(typeNameList);
//具体地址拼接
campsiteShopDetailVo.setAddress(String.format("%s%s%s",campsiteShopDetailDTO.getProvinceName(),campsiteShopDetailDTO.getCityName(),campsiteShopDetailDTO.getAddress()));
//根据经纬度算距离 //根据经纬度算距离
double distance = getDistance(campsiteShopDetailDTO.getLongitude(),campsiteShopDetailDTO.getLatitude(),longitude,latitude); double distance = getDistance(campsiteShopDetailDTO.getLongitude(),campsiteShopDetailDTO.getLatitude(),longitude,latitude);
if (log.isDebugEnabled()){ if (log.isDebugEnabled()){
log.debug("根据店铺经度=[{}],纬度=[{}]和自己所在位置的经度=[{}],纬度=[{}]计算出的距离:[{}km]",campsiteShopDetailDTO.getLongitude(),campsiteShopDetailDTO.getLatitude(),longitude,latitude,distance); log.debug("根据店铺经度=【{}】,纬度=【{}】和自己所在位置的经度=【{}】,纬度=【{}】计算出的距离:【{}km】",campsiteShopDetailDTO.getLongitude(),campsiteShopDetailDTO.getLatitude(),longitude,latitude,distance);
} }
campsiteShopDetailVo.setDistance(String.format("%.1f",distance)); campsiteShopDetailVo.setDistance(String.format("%.1f",distance));
return campsiteShopDetailVo; return campsiteShopDetailVo;
......
package com.xxfc.platform.campsite.biz; package com.xxfc.platform.campsite.biz;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.xxfc.platform.campsite.dto.CampsiteTagListDTO;
import com.xxfc.platform.campsite.vo.CampsiteTagListVo;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.xxfc.platform.campsite.entity.CampsiteTag; import com.xxfc.platform.campsite.entity.CampsiteTag;
import com.xxfc.platform.campsite.mapper.CampsiteTagMapper; import com.xxfc.platform.campsite.mapper.CampsiteTagMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz; import com.github.wxiaoqi.security.common.biz.BaseBiz;
import java.util.List;
/** /**
* 店铺类型表 * 店铺类型表
* *
...@@ -15,4 +23,17 @@ import com.github.wxiaoqi.security.common.biz.BaseBiz; ...@@ -15,4 +23,17 @@ import com.github.wxiaoqi.security.common.biz.BaseBiz;
*/ */
@Service @Service
public class CampsiteTagBiz extends BaseBiz<CampsiteTagMapper,CampsiteTag> { public class CampsiteTagBiz extends BaseBiz<CampsiteTagMapper,CampsiteTag> {
/**
* 查询营地列表
* @return
*/
public List<CampsiteTagListVo> findCampsiteTags() {
List<CampsiteTagListDTO> campsiteTagListDTOS = mapper.findCampsiteTags();
if (CollectionUtils.isEmpty(campsiteTagListDTOS)){
return null;
}
List<CampsiteTagListVo> campsiteTagListVos = JSONObject.parseObject(JSONObject.toJSONString(campsiteTagListDTOS),new TypeReference<List<CampsiteTagListVo>>(){});
return campsiteTagListVos;
}
} }
\ No newline at end of file
package com.xxfc.platform.campsite.config;
import org.springframework.context.annotation.Bean;
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.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* ${DESCRIPTION}
*
* @author wanghaobin
* @create 2017-06-21 8:39
*/
@Configuration
@Primary
public class RedisConfiguration {
@Bean
public RedisTemplate<String, Object> customRedisTemplate(RedisConnectionFactory factory) {
RedisTemplate redisTemplate = new RedisTemplate();
redisTemplate.setConnectionFactory(factory);
RedisSerializer<String> stringSerializer = new StringRedisSerializer();
redisTemplate.setKeySerializer(stringSerializer);
redisTemplate.setValueSerializer(stringSerializer);
redisTemplate.setHashKeySerializer(stringSerializer);
redisTemplate.setHashValueSerializer(stringSerializer);
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
}
package com.xxfc.platform.campsite.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
@Configuration
public class RestConfiguration {
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
package com.xxfc.platform.campsite.mapper; package com.xxfc.platform.campsite.mapper;
import com.xxfc.platform.campsite.dto.CampsiteTagListDTO;
import com.xxfc.platform.campsite.entity.CampsiteTag; import com.xxfc.platform.campsite.entity.CampsiteTag;
import tk.mybatis.mapper.common.Mapper; import tk.mybatis.mapper.common.Mapper;
import java.util.List;
/** /**
* 店铺类型表 * 店铺类型表
* *
...@@ -12,4 +15,10 @@ import tk.mybatis.mapper.common.Mapper; ...@@ -12,4 +15,10 @@ import tk.mybatis.mapper.common.Mapper;
*/ */
public interface CampsiteTagMapper extends Mapper<CampsiteTag> { public interface CampsiteTagMapper extends Mapper<CampsiteTag> {
/**
* 查询可用营地列表
* @return
*/
List<CampsiteTagListDTO> findCampsiteTags();
} }
package com.xxfc.platform.campsite.rest; package com.xxfc.platform.campsite.rest;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreClientToken;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.BaseController; import com.github.wxiaoqi.security.common.rest.BaseController;
import com.xxfc.platform.campsite.biz.CampsiteTagBiz; import com.xxfc.platform.campsite.biz.CampsiteTagBiz;
import com.xxfc.platform.campsite.entity.CampsiteTag; import com.xxfc.platform.campsite.entity.CampsiteTag;
import org.springframework.stereotype.Controller; import com.xxfc.platform.campsite.vo.CampsiteTagListVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/** /**
* @author libin * @author libin
* @version 1.0 * @version 1.0
...@@ -17,4 +22,15 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -17,4 +22,15 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("campsiteTag") @RequestMapping("campsiteTag")
public class CampsiteTagController extends BaseController<CampsiteTagBiz,CampsiteTag> { public class CampsiteTagController extends BaseController<CampsiteTagBiz,CampsiteTag> {
/**
* 查询营地列表
* @return
*/
@GetMapping("/app/unauth/tags")
@IgnoreClientToken
public ObjectRestResponse<CampsiteTagListVo> findCampstieTags(){
List<CampsiteTagListVo> campsiteTagListVolist = getBaseBiz().findCampsiteTags();
return ObjectRestResponse.succ(campsiteTagListVolist);
}
} }
\ No newline at end of file
...@@ -15,4 +15,7 @@ ...@@ -15,4 +15,7 @@
<result property="isDel" column="is_del"/> <result property="isDel" column="is_del"/>
</resultMap> </resultMap>
<select id="findCampsiteTags" resultType="com.xxfc.platform.campsite.dto.CampsiteTagListDTO">
select `id`,`name` from `campsite_tag` where `is_del`=0;
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -3,6 +3,7 @@ package com.xxfc.platform.vehicle.pojo.dto; ...@@ -3,6 +3,7 @@ package com.xxfc.platform.vehicle.pojo.dto;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotNull;
import java.util.List; import java.util.List;
/** /**
...@@ -18,6 +19,20 @@ public class VehicleUserScoreDTO { ...@@ -18,6 +19,20 @@ public class VehicleUserScoreDTO {
@ApiModelProperty("主键id") @ApiModelProperty("主键id")
private Integer id; private Integer id;
/**
* 订单id
*/
@ApiModelProperty(value = "订单id")
@NotNull(message = "订单id不能为空")
private Integer orderId;
/**
* 车型id
*/
@ApiModelProperty(value = "车型id")
@NotNull(message = "车型id不能为空")
private Integer modelId;
/** /**
* 评分类型 * 评分类型
*/ */
......
package com.xxfc.platform.vehicle.pojo.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author libin
* @version 1.0
* @description 车型评分
* @data 2019/6/18 15:15
*/
@Data
public class VehicleUserScoreDetailDTO {
/**
* 用户id
*/
@ApiModelProperty("用户id")
private Integer userId;
/**
* 评价分
*/
@ApiModelProperty(value = "评价分")
private Integer aveScore;
/**
* 评价
*/
@ApiModelProperty(value = "评价")
private String comment;
/**
* 图片
*/
@ApiModelProperty(value = "图片")
private String imgs;
/**
* 车型名称
*/
@ApiModelProperty(value ="车型名称")
private String modelName;
/**
* 车型关键标签
*/
@ApiModelProperty(value = "车型关键标签")
private String modelKeyWorld;
/**
* 创建时间
*/
@ApiModelProperty(value = "创建时间", hidden = true )
private Long crtTime;
/**
* 评分明细
*/
@ApiModelProperty(value = "评分明细")
private String scores;
}
\ No newline at end of file
package com.xxfc.platform.vehicle.pojo.vo;
import com.xxfc.platform.vehicle.constant.VehicleScoreType;
import lombok.Data;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
/**
* @author libin
* @version 1.0
* @description TODO
* @data 2019/6/18 15:45
*/
@Data
public class ScoreTypeVo {
/**
* 评分类型
*/
@Enumerated(EnumType.STRING)
private VehicleScoreType vehicleScoreType;
/**
* 评分
*/
private int score;
}
...@@ -3,10 +3,12 @@ package com.xxfc.platform.vehicle.pojo.vo; ...@@ -3,10 +3,12 @@ package com.xxfc.platform.vehicle.pojo.vo;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.util.List;
/** /**
* @author libin * @author libin
* @version 1.0 * @version 1.0
* @description TODO * @description 订单评价vo
* @data 2019/6/18 15:26 * @data 2019/6/18 15:26
*/ */
@Data @Data
...@@ -21,8 +23,8 @@ public class VehicleUserScoreVo { ...@@ -21,8 +23,8 @@ public class VehicleUserScoreVo {
/** /**
* 用户id * 用户id
*/ */
@ApiModelProperty(value = "用户id") @ApiModelProperty("用户id")
private Integer userId; private String userId;
/** /**
* 用户名 * 用户名
...@@ -67,10 +69,26 @@ public class VehicleUserScoreVo { ...@@ -67,10 +69,26 @@ public class VehicleUserScoreVo {
@ApiModelProperty(value = "图片") @ApiModelProperty(value = "图片")
private String imgs; private String imgs;
/**
* 车型名称
*/
@ApiModelProperty(value ="车型名称")
private String modelName;
/**
* 车型关键标签
*/
@ApiModelProperty(value = "车型关键标签")
private String modelKeyWorld;
/** /**
* 创建时间 * 创建时间
*/ */
@ApiModelProperty(value = "创建时间", hidden = true ) @ApiModelProperty(value = "创建时间", hidden = true )
private Long crtTime; private Long crtTime;
/**
* 类型-评分
*/
private List<ScoreTypeVo> scoreTypeVos;
} }
...@@ -64,4 +64,13 @@ public class VehicleModelBiz extends BaseBiz<VehicleModelMapper, VehicleModel> { ...@@ -64,4 +64,13 @@ public class VehicleModelBiz extends BaseBiz<VehicleModelMapper, VehicleModel> {
} }
/**
*更新车型的评分
* @param modelId
* @param avgScore
* @return
*/
public int updateScoreByModelIdAndavgScore(Integer modelId, int avgScore) {
return mapper.updateScoreByModelIdAndavgScore(modelId,avgScore);
}
} }
\ No newline at end of file
package com.xxfc.platform.vehicle.biz; package com.xxfc.platform.vehicle.biz;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.github.wxiaoqi.security.admin.feign.UserFeign; import com.github.wxiaoqi.security.admin.feign.UserFeign;
import com.github.wxiaoqi.security.admin.feign.dto.AppUserDTO; import com.github.wxiaoqi.security.admin.feign.dto.AppUserDTO;
import com.github.wxiaoqi.security.admin.vo.AppUserVo;
import com.github.wxiaoqi.security.common.biz.BaseBiz; import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.vo.PageDataVO; import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.xxfc.platform.vehicle.entity.VehicleUserScore; import com.xxfc.platform.vehicle.entity.VehicleUserScore;
import com.xxfc.platform.vehicle.mapper.VehicleUserScoreMapper; import com.xxfc.platform.vehicle.mapper.VehicleUserScoreMapper;
import com.xxfc.platform.vehicle.pojo.dto.ScoreTypeDTO; import com.xxfc.platform.vehicle.pojo.dto.ScoreTypeDTO;
import com.xxfc.platform.vehicle.pojo.dto.VehicleUserScoreDTO; import com.xxfc.platform.vehicle.pojo.dto.VehicleUserScoreDTO;
import com.xxfc.platform.vehicle.pojo.dto.VehicleUserScoreDetailDTO;
import com.xxfc.platform.vehicle.pojo.dto.VehicleUserScoreListDTO; import com.xxfc.platform.vehicle.pojo.dto.VehicleUserScoreListDTO;
import com.xxfc.platform.vehicle.pojo.vo.ScoreTypeVo;
import com.xxfc.platform.vehicle.pojo.vo.VehicleUserScoreVo; import com.xxfc.platform.vehicle.pojo.vo.VehicleUserScoreVo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.Instant; import java.time.Instant;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -32,16 +44,48 @@ import java.util.stream.Collectors; ...@@ -32,16 +44,48 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
public class VehicleUserScoreBiz extends BaseBiz<VehicleUserScoreMapper, VehicleUserScore> { public class VehicleUserScoreBiz extends BaseBiz<VehicleUserScoreMapper, VehicleUserScore> {
@Resource
private UserFeign userFeign;
@Autowired
private VehicleModelBiz vehicleModelBiz;
/** /**
* 根据车型id查询 * 根据车型id查询
* @param modelId * @param modelId
* @return * @return
*/ */
public PageDataVO<VehicleUserScoreVo> findVehicleUserScorePageByModelId(Integer modelId,Integer pageNo,Integer pageSize) { public PageDataVO<VehicleUserScoreVo> findVehicleUserScorePageByModelId(Integer modelId,Integer pageNo,Integer pageSize) {
PageDataVO<VehicleUserScoreVo> pageDataVO = new PageDataVO<>();
//根据模型id查找 //根据模型id查找
PageDataVO<VehicleUserScoreListDTO> vehicleUserScoreDTOPageDataVO = PageDataVO.pageInfo(pageNo,pageSize,()->mapper.findyByModelIdAndApproved(modelId,1)); PageDataVO<VehicleUserScoreListDTO> vehicleUserScoreDTOPageDataVO = PageDataVO.pageInfo(pageNo,pageSize,()->mapper.findyByModelIdAndApproved(modelId,1));
List<Integer> userIds = vehicleUserScoreDTOPageDataVO.getData().stream().map(VehicleUserScoreListDTO::getUserId).collect(Collectors.toList()); List<VehicleUserScoreListDTO> dataVOData = vehicleUserScoreDTOPageDataVO.getData();
return null; if (CollectionUtils.isEmpty(dataVOData)){
return pageDataVO;
}
if (log.isDebugEnabled()){
log.debug("根据车型id查找出的评价:【{}】",dataVOData);
}
//设置用户信息
List<Integer> userIds = dataVOData.stream().map(VehicleUserScoreListDTO::getUserId).distinct().collect(Collectors.toList());
List<AppUserVo> appUserVos = userFeign.getByUserIds(userIds).getData();
if (log.isDebugEnabled()){
log.debug("根据用户ids查询出用户信息:【{}】",appUserVos);
}
Map<Integer, AppUserVo> userMap = appUserVos.stream().collect(Collectors.toMap(AppUserVo::getUserid, Function.identity()));
List<VehicleUserScoreVo> vehicleUserScoreVos = dataVOData.stream().map(vehicleUserScoreListDTO -> {
VehicleUserScoreVo vehicleUserScoreVo = new VehicleUserScoreVo();
BeanUtils.copyProperties(vehicleUserScoreListDTO, vehicleUserScoreVo);
vehicleUserScoreVo.setUserName(userMap.get(vehicleUserScoreListDTO.getUserId()).getNickname());
vehicleUserScoreVo.setHeadUrl(userMap.get(vehicleUserScoreListDTO.getUserId()).getHeadimgurl());
return vehicleUserScoreVo;
}).sorted(Comparator.comparing(VehicleUserScoreVo::getCrtTime).reversed()).collect(Collectors.toList());
//组装数据
pageDataVO.setPageNum(vehicleUserScoreDTOPageDataVO.getPageNum());
pageDataVO.setPageSize(vehicleUserScoreDTOPageDataVO.getPageSize());
pageDataVO.setTotalCount(vehicleUserScoreDTOPageDataVO.getTotalCount());
pageDataVO.setTotalPage(vehicleUserScoreDTOPageDataVO.getTotalPage());
pageDataVO.setData(vehicleUserScoreVos);
return pageDataVO;
} }
/** /**
...@@ -51,18 +95,59 @@ public class VehicleUserScoreBiz extends BaseBiz<VehicleUserScoreMapper, Vehicle ...@@ -51,18 +95,59 @@ public class VehicleUserScoreBiz extends BaseBiz<VehicleUserScoreMapper, Vehicle
*/ */
public int saveVehicleUserScore(VehicleUserScoreDTO vehicleUserScoreDTO, AppUserDTO appUserDTO) { public int saveVehicleUserScore(VehicleUserScoreDTO vehicleUserScoreDTO, AppUserDTO appUserDTO) {
if (log.isDebugEnabled()){ if (log.isDebugEnabled()){
log.debug("用户:{},评分的数据:【{}】",appUserDTO.getNickname(),vehicleUserScoreDTO); log.debug("用户:【{}】,评分的数据:【{}】",appUserDTO.getNickname(),vehicleUserScoreDTO);
} }
vehicleUserScoreDTO.setCrtTime(Instant.now().toEpochMilli()); vehicleUserScoreDTO.setCrtTime(Instant.now().toEpochMilli());
List<ScoreTypeDTO> scoretype = vehicleUserScoreDTO.getScoretype(); List<ScoreTypeDTO> scoretype = vehicleUserScoreDTO.getScoretype();
int avgScore =0;
if (CollectionUtils.isNotEmpty(scoretype)) {
//评分明细 //评分明细
vehicleUserScoreDTO.setComment(JSONObject.toJSONString(scoretype)); vehicleUserScoreDTO.setScores(JSONObject.toJSONString(scoretype));
//计算平均分值 //计算平均分值
double avgScore = scoretype.stream().mapToInt(ScoreTypeDTO::getScore).average().getAsDouble(); double avgScored = scoretype.stream().mapToInt(ScoreTypeDTO::getScore).average().getAsDouble();
avgScore = Long.valueOf(Math.round(avgScored)).intValue();
//更改车型的评分
if (0 != avgScore) {
vehicleModelBiz.updateScoreByModelIdAndavgScore(vehicleUserScoreDTO.getModelId(), avgScore);
}
}
VehicleUserScore vehicleUserScore = new VehicleUserScore(); VehicleUserScore vehicleUserScore = new VehicleUserScore();
BeanUtils.copyProperties(vehicleUserScoreDTO,vehicleUserScore); BeanUtils.copyProperties(vehicleUserScoreDTO,vehicleUserScore);
vehicleUserScore.setAveScore(Long.valueOf(Math.round(avgScore)).intValue()); vehicleUserScore.setAveScore(avgScore);
vehicleUserScore.setUserId(appUserDTO.getUserid()); vehicleUserScore.setUserId(appUserDTO.getUserid());
vehicleUserScore.setUpdTime(Instant.now().toEpochMilli());
return mapper.insertSelective(vehicleUserScore); return mapper.insertSelective(vehicleUserScore);
} }
/**
* 根据订单id查询订单评价
* @param orderId
* @return
*/
public VehicleUserScoreVo findVehicleUserScoreDetailByOrderId(Integer orderId) {
VehicleUserScoreVo vehicleUserScoreVo = new VehicleUserScoreVo();
//根据订单id查询
VehicleUserScoreDetailDTO vehicleUserScoreDetailDTO = mapper.findVehicleUserScoreDetailByOrderId(orderId);
if (log.isDebugEnabled()){
log.debug("根据订单id:【{}】查询到的订单评价内容:【{}】",orderId,vehicleUserScoreDetailDTO);
}
BeanUtils.copyProperties(vehicleUserScoreDetailDTO,vehicleUserScoreVo);
//评分明细数据转换
String scores = vehicleUserScoreDetailDTO.getScores();
if (StringUtils.isNotEmpty(scores)){
List<ScoreTypeVo> typeVos = JSONObject.parseObject(scores, new TypeReference<List<ScoreTypeVo>>() {});
vehicleUserScoreVo.setScoreTypeVos(typeVos);
}
//根据用户id查询用户信息
ObjectRestResponse<List<AppUserVo>> appuserResponse = userFeign.getByUserIds(Arrays.asList(vehicleUserScoreDetailDTO.getUserId()));
if (log.isDebugEnabled()){
log.debug("根据用户id:【{}】查询到的用户信息:【{}】",vehicleUserScoreDetailDTO.getUserId(),appuserResponse.getData());
}
AppUserVo appUserVo = appuserResponse.getData().get(0);
vehicleUserScoreVo.setUserName(appUserVo.getNickname());
vehicleUserScoreVo.setHeadUrl(appUserVo.getHeadimgurl());
return vehicleUserScoreVo;
}
} }
\ No newline at end of file
...@@ -3,6 +3,7 @@ package com.xxfc.platform.vehicle.mapper; ...@@ -3,6 +3,7 @@ package com.xxfc.platform.vehicle.mapper;
import com.xxfc.platform.vehicle.entity.VehicleModel; import com.xxfc.platform.vehicle.entity.VehicleModel;
import com.xxfc.platform.vehicle.pojo.VehicleModelQueryCondition; import com.xxfc.platform.vehicle.pojo.VehicleModelQueryCondition;
import com.xxfc.platform.vehicle.pojo.VehicleModelVo; import com.xxfc.platform.vehicle.pojo.VehicleModelVo;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.Mapper; import tk.mybatis.mapper.common.Mapper;
import java.util.List; import java.util.List;
...@@ -18,4 +19,11 @@ public interface VehicleModelMapper extends Mapper<VehicleModel> { ...@@ -18,4 +19,11 @@ public interface VehicleModelMapper extends Mapper<VehicleModel> {
List<VehicleModelVo> findVehicleModelPage(VehicleModelQueryCondition vmqc); List<VehicleModelVo> findVehicleModelPage(VehicleModelQueryCondition vmqc);
/**
* 根据车型id和车型某个订单的评价的平均分值计算
* @param modelId
* @param avgScore
* @return
*/
int updateScoreByModelIdAndavgScore(@Param("modelId") Integer modelId, @Param("avgScore") int avgScore);
} }
package com.xxfc.platform.vehicle.mapper; package com.xxfc.platform.vehicle.mapper;
import com.xxfc.platform.vehicle.entity.VehicleUserScore; import com.xxfc.platform.vehicle.entity.VehicleUserScore;
import com.xxfc.platform.vehicle.pojo.dto.VehicleUserScoreDetailDTO;
import com.xxfc.platform.vehicle.pojo.dto.VehicleUserScoreListDTO; import com.xxfc.platform.vehicle.pojo.dto.VehicleUserScoreListDTO;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
...@@ -25,4 +26,11 @@ public interface VehicleUserScoreMapper extends Mapper<VehicleUserScore> { ...@@ -25,4 +26,11 @@ public interface VehicleUserScoreMapper extends Mapper<VehicleUserScore> {
*/ */
@Select("select `user_id` as `userId`,`comment` as `comment`,`ave_score` as `aveScore`,`is_anony` as `isAnony`,`imgs` as `imgs`,`crt_time` as `crtTime` from `vehicle_user_score` where `model_id`=#{modelId} and `status`=#{status}") @Select("select `user_id` as `userId`,`comment` as `comment`,`ave_score` as `aveScore`,`is_anony` as `isAnony`,`imgs` as `imgs`,`crt_time` as `crtTime` from `vehicle_user_score` where `model_id`=#{modelId} and `status`=#{status}")
List<VehicleUserScoreListDTO> findyByModelIdAndApproved(@Param("modelId") Integer modelId, @Param("status") Integer status); List<VehicleUserScoreListDTO> findyByModelIdAndApproved(@Param("modelId") Integer modelId, @Param("status") Integer status);
/**
* 根据订单查询评价
* @param orderId
* @return
*/
VehicleUserScoreDetailDTO findVehicleUserScoreDetailByOrderId(Integer orderId);
} }
package com.xxfc.platform.vehicle.rest; package com.xxfc.platform.vehicle.rest;
import com.github.wxiaoqi.security.admin.feign.dto.AppUserDTO; import com.github.wxiaoqi.security.admin.feign.dto.AppUserDTO;
import com.github.wxiaoqi.security.common.annotation.BeanValid;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.BaseController; import com.github.wxiaoqi.security.common.rest.BaseController;
import com.github.wxiaoqi.security.common.vo.PageDataVO; import com.github.wxiaoqi.security.common.vo.PageDataVO;
...@@ -23,10 +24,11 @@ public class VehicleUserScoreController extends BaseController<VehicleUserScoreB ...@@ -23,10 +24,11 @@ public class VehicleUserScoreController extends BaseController<VehicleUserScoreB
/** /**
* 保存评论 * 保存评论
* @param vehicleUserScoreDTO * @param vehicleUserScoreDTO
* @param appUserDTO
* @return * @return
*/ */
@PostMapping("/score") @PostMapping("/score")
public ObjectRestResponse<Void> saveVehicleUserScore(@RequestBody VehicleUserScoreDTO vehicleUserScoreDTO, AppUserDTO appUserDTO){ public ObjectRestResponse<Void> saveVehicleUserScore(@RequestBody @BeanValid VehicleUserScoreDTO vehicleUserScoreDTO, AppUserDTO appUserDTO){
int effectRows = getBaseBiz().saveVehicleUserScore(vehicleUserScoreDTO,appUserDTO); int effectRows = getBaseBiz().saveVehicleUserScore(vehicleUserScoreDTO,appUserDTO);
if (effectRows>0){ if (effectRows>0){
return ObjectRestResponse.succ(); return ObjectRestResponse.succ();
...@@ -37,13 +39,26 @@ public class VehicleUserScoreController extends BaseController<VehicleUserScoreB ...@@ -37,13 +39,26 @@ public class VehicleUserScoreController extends BaseController<VehicleUserScoreB
* 根据车型查询评论列表 根据评分时间排序 * 根据车型查询评论列表 根据评分时间排序
* *
* @param modelId * @param modelId
* @param pageNo
* @param pageSize
* @return * @return
*/ */
@GetMapping("/scores") @GetMapping("/app/unauth/scores")
public ObjectRestResponse<PageDataVO<VehicleUserScoreVo>> findVehicleUserScorePageByModelId(@RequestParam("modelId") Integer modelId, public ObjectRestResponse<PageDataVO<VehicleUserScoreVo>> findVehicleUserScorePageByModelId(@RequestParam("modelId") Integer modelId,
@RequestParam("pageNo")Integer pageNo, @RequestParam(value = "pageNo",required = false,defaultValue = "1")Integer pageNo,
@RequestParam("pageSize") Integer pageSize) { @RequestParam(value = "pageSize",required = false,defaultValue = "10") Integer pageSize) {
PageDataVO<VehicleUserScoreVo> pageDataVO = getBaseBiz().findVehicleUserScorePageByModelId(modelId,pageNo,pageSize); PageDataVO<VehicleUserScoreVo> pageDataVO = getBaseBiz().findVehicleUserScorePageByModelId(modelId,pageNo,pageSize);
return ObjectRestResponse.succ(pageDataVO); return ObjectRestResponse.succ(pageDataVO);
} }
/**
* 根据订单id查询评价详情
* @param orderId
* @return
*/
@GetMapping("/score/order/{orderId}")
public ObjectRestResponse findVehicleUserScoreDetailByOrderId(@PathVariable("orderId") Integer orderId){
VehicleUserScoreVo vehicleUserScoreVo = getBaseBiz().findVehicleUserScoreDetailByOrderId(orderId);
return ObjectRestResponse.succ(vehicleUserScoreVo);
}
} }
\ No newline at end of file
...@@ -26,4 +26,8 @@ ...@@ -26,4 +26,8 @@
</if> </if>
ORDER BY vmqc.id ASC ORDER BY vmqc.id ASC
</select> </select>
<update id="updateScoreByModelIdAndavgScore">
update `vehicle_model` set `score`=(`score`+#{avgScore})/2 where `id`=#{modelId}
</update>
</mapper> </mapper>
\ No newline at end of file
...@@ -21,4 +21,9 @@ ...@@ -21,4 +21,9 @@
<result property="isDel" column="is_del"/> <result property="isDel" column="is_del"/>
</resultMap> </resultMap>
<select id="findVehicleUserScoreDetailByOrderId"
resultType="com.xxfc.platform.vehicle.pojo.dto.VehicleUserScoreDetailDTO">
SELECT vus.user_id as `userId`,vus.ave_score as `aveScore`,vus.comment as `comment`, vus.imgs as `imgs`,vus.crt_time as `crtTime`,vus.scores as `scores`,vm.name as `modelName`,vm.keyword as `modelKeyWorld`
FROM `vehicle_user_score` as `vus` left JOIN `vehicle_model` as `vm` on vus.model_id=vm.id WHERE vus.order_id=#{orderId} ;
</select>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment