Commit 6dde545c authored by hanfeng's avatar hanfeng

修改官网旅游路线

parent 27ff2b5e
......@@ -31,6 +31,7 @@ import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
/**
* 旅游商品表
......@@ -64,6 +65,7 @@ public class TourGoodBiz extends BaseBiz<TourGoodMapper, TourGood> {
/**
* 查询旅游路线列表
*
* @param page
* @param limit
* @param query
......@@ -73,24 +75,24 @@ public class TourGoodBiz extends BaseBiz<TourGoodMapper, TourGood> {
* @param distance
* @return
*/
public ObjectRestResponse<PageDataVO<TourGood>> getGoodList(int page, int limit , String query , Double latitude, Double longitude, Integer tagId, Double distance){
public ObjectRestResponse<PageDataVO<TourGood>> getGoodList(int page, int limit, String query, Double latitude, Double longitude, Integer tagId, Double distance) {
Map<String, Object> params = initParam(page, limit, query, latitude, longitude, tagId, distance);
PageDataVO<TourGood> dataVO=null;
if(latitude!=null&&latitude>0&&longitude!=null&&longitude>0){
dataVO=PageDataVO.pageInfo(page, limit, ()->mapper.getCoordinateList(params));
}else {
dataVO=PageDataVO.pageInfo(page, limit, ()->mapper.getGoodList(params));
PageDataVO<TourGood> dataVO = null;
if (latitude != null && latitude > 0 && longitude != null && longitude > 0) {
dataVO = PageDataVO.pageInfo(page, limit, () -> mapper.getCoordinateList(params));
} else {
dataVO = PageDataVO.pageInfo(page, limit, () -> mapper.getGoodList(params));
}
return new ObjectRestResponse().status(RestCode.SUCCESS.getStatus()).msg(RestCode.SUCCESS.getMsg()).data(dataVO);
}
private Map<String, Object> initParam(int page, int limit, String query, Double latitude, Double longitude, Integer tagId, Double distance) {
Map<String,Object> params = new HashMap<String,Object>();
params.put("query",query);
params.put("latitude",latitude);
params.put("longitude",longitude);
params.put("tagId",tagId);
params.put("distance",distance);
Map<String, Object> params = new HashMap<String, Object>();
params.put("query", query);
params.put("latitude", latitude);
params.put("longitude", longitude);
params.put("tagId", tagId);
params.put("distance", distance);
return params;
}
......@@ -99,168 +101,168 @@ public class TourGoodBiz extends BaseBiz<TourGoodMapper, TourGood> {
}
//获取商品列表
public PageDataVO<TourGoodVo> getAll(GoodSearchDTO dto){
PageHelper.startPage(dto.getPage(),dto.getLimit());
//获取商品列表
public PageDataVO<TourGoodVo> getAll(GoodSearchDTO dto) {
PageHelper.startPage(dto.getPage(), dto.getLimit());
PageInfo<TourGoodVo> goodPageInfo = new PageInfo<>(mapper.findGoodList(dto));
return PageDataVO.pageInfo(goodPageInfo);
}
//获取商品列表
public ObjectRestResponse goodsEdit(TourGoodDTO dto){
if(dto==null){
return ObjectRestResponse.createFailedResult(ResultCode.NULL_CODE, "参数为空");
}
TourGood good=new TourGood();
public ObjectRestResponse goodsEdit(TourGoodDTO dto) {
if (dto == null) {
return ObjectRestResponse.createFailedResult(ResultCode.NULL_CODE, "参数为空");
}
TourGood good = new TourGood();
try {
Long times=System.currentTimeMillis();
BeanUtils.copyProperties(good,dto);
Integer goodId=good.getId();
Long times = System.currentTimeMillis();
BeanUtils.copyProperties(good, dto);
Integer goodId = good.getId();
good.setUpdTime(times);
if(goodId==null||goodId==0){
if (goodId == null || goodId == 0) {
good.setCrtTime(times);
mapper.insertSelective(good);
goodId=good.getId();
}else {
goodId = good.getId();
} else {
mapper.updateByPrimaryKeySelective(good);
}
if(goodId>0){
List<GoodBannerDTO> bannerList=dto.getBannerDTOS();
if(bannerList.size()>0){
List<Integer> bannerIds=new ArrayList<>();
for (GoodBannerDTO bannerDTO:bannerList){
Integer bannerId=bannerDTO.getId();
TourGoodBanner goodBanner=new TourGoodBanner();
BeanUtils.copyProperties(goodBanner,bannerDTO);
goodBanner.setGoodId(goodId);
if(bannerId==null||bannerId==0){
bannerBiz.insertSelective(goodBanner);
bannerId=goodBanner.getId();
}else {
bannerBiz.updateSelectiveById(goodBanner);
}
bannerIds.add(bannerId);
}
if(bannerIds.size()>0){
bannerBiz.delGoodBanner(goodId,bannerIds);
}
}else{
bannerBiz.delGoodBanner(goodId,null);
}
List<GoodSiteDTO> siteDTOList=dto.getSiteDTOS();
List<Integer> sites=new ArrayList<>();
if(siteDTOList.size()>0){
List<Integer> siteIds=new ArrayList<>();
for (GoodSiteDTO siteDTO:siteDTOList){
Integer siteId=siteDTO.getId();
TourGoodSite site=new TourGoodSite();
BeanUtils.copyProperties(site,siteDTO);
if (goodId > 0) {
List<GoodBannerDTO> bannerList = dto.getBannerDTOS();
if (bannerList.size() > 0) {
List<Integer> bannerIds = new ArrayList<>();
for (GoodBannerDTO bannerDTO : bannerList) {
Integer bannerId = bannerDTO.getId();
TourGoodBanner goodBanner = new TourGoodBanner();
BeanUtils.copyProperties(goodBanner, bannerDTO);
goodBanner.setGoodId(goodId);
if (bannerId == null || bannerId == 0) {
bannerBiz.insertSelective(goodBanner);
bannerId = goodBanner.getId();
} else {
bannerBiz.updateSelectiveById(goodBanner);
}
bannerIds.add(bannerId);
}
if (bannerIds.size() > 0) {
bannerBiz.delGoodBanner(goodId, bannerIds);
}
} else {
bannerBiz.delGoodBanner(goodId, null);
}
List<GoodSiteDTO> siteDTOList = dto.getSiteDTOS();
List<Integer> sites = new ArrayList<>();
if (siteDTOList.size() > 0) {
List<Integer> siteIds = new ArrayList<>();
for (GoodSiteDTO siteDTO : siteDTOList) {
Integer siteId = siteDTO.getId();
TourGoodSite site = new TourGoodSite();
BeanUtils.copyProperties(site, siteDTO);
site.setGoodId(goodId);
if(siteId==null||siteId==0){
if (siteId == null || siteId == 0) {
siteBiz.insertSelective(site);
siteId=site.getId();
}else {
siteId = site.getId();
} else {
siteBiz.updateSelectiveById(site);
}
siteIds.add(siteId);
if(site.getType()==0){
if (site.getType() == 0) {
sites.add(siteId);
}
}
if(siteIds.size()>0){
siteBiz.delGoodSite(goodId,siteIds);
if (siteIds.size() > 0) {
siteBiz.delGoodSite(goodId, siteIds);
}
}
List<GoodTagDTO> tagList=dto.getTagDTOS();
if(tagList.size()>0){
List<Integer> tagIds=new ArrayList<>();
for (GoodTagDTO tagDTO:tagList){
Integer tagId=tagDTO.getTagId();
TourGoodTag tag=new TourGoodTag();
BeanUtils.copyProperties(tag,tagDTO);
List<GoodTagDTO> tagList = dto.getTagDTOS();
if (tagList.size() > 0) {
List<Integer> tagIds = new ArrayList<>();
for (GoodTagDTO tagDTO : tagList) {
Integer tagId = tagDTO.getTagId();
TourGoodTag tag = new TourGoodTag();
BeanUtils.copyProperties(tag, tagDTO);
tag.setGoodId(goodId);
TourGoodTag tag1=tagBiz.selectOne(tag);
if(tag1==null){
TourGoodTag tag1 = tagBiz.selectOne(tag);
if (tag1 == null) {
tagBiz.insertSelective(tag);
tagId=tag.getId();
}else {
tagId = tag.getId();
} else {
/* tag.setId(tag.getId());
tagBiz.updateSelectiveById(tag);*/
tagId=tag1.getId();
tagId = tag1.getId();
}
tagIds.add(tagId);
}
if(tagIds.size()>0){
tagBiz.delGoodTag(goodId,tagIds);
if (tagIds.size() > 0) {
tagBiz.delGoodTag(goodId, tagIds);
}
}else{
tagBiz.delGoodTag(goodId,null);
} else {
tagBiz.delGoodTag(goodId, null);
}
List<GoodSpePriceDTO> priceDTOList=dto.getPriceDTOS();
List<Integer> prices=new ArrayList<>();
if(siteDTOList.size()>0){
for (GoodSpePriceDTO priceDTO:priceDTOList){
Integer priceId=priceDTO.getId();
TourGoodSpePrice spePrice=new TourGoodSpePrice();
BeanUtils.copyProperties(spePrice,priceDTO);
BigDecimal price=good.getPrice();
BigDecimal childPrice=good.getChildPrice();
List<GoodSpePriceDTO> priceDTOList = dto.getPriceDTOS();
List<Integer> prices = new ArrayList<>();
if (siteDTOList.size() > 0) {
for (GoodSpePriceDTO priceDTO : priceDTOList) {
Integer priceId = priceDTO.getId();
TourGoodSpePrice spePrice = new TourGoodSpePrice();
BeanUtils.copyProperties(spePrice, priceDTO);
BigDecimal price = good.getPrice();
BigDecimal childPrice = good.getChildPrice();
spePrice.setPrice(price);
spePrice.setChildPrice(childPrice);
spePrice.setGoodId(goodId);
List<BaseUserMemberLevel> levelsList=userFeign.levels();
if(levelsList.size()>0){
JSONArray array=new JSONArray();
for(BaseUserMemberLevel memberLevel :levelsList){
JSONObject obj=new JSONObject();
Integer level=memberLevel.getLevel();
Integer discount=memberLevel.getDiscount();
BigDecimal price1=price.multiply(new BigDecimal(discount+"")).divide(new BigDecimal("100"))
List<BaseUserMemberLevel> levelsList = userFeign.levels();
if (levelsList.size() > 0) {
JSONArray array = new JSONArray();
for (BaseUserMemberLevel memberLevel : levelsList) {
JSONObject obj = new JSONObject();
Integer level = memberLevel.getLevel();
Integer discount = memberLevel.getDiscount();
BigDecimal price1 = price.multiply(new BigDecimal(discount + "")).divide(new BigDecimal("100"))
.setScale(2, RoundingMode.HALF_UP);
BigDecimal price2=childPrice.multiply(new BigDecimal(discount+"")).divide(new BigDecimal("100"))
BigDecimal price2 = childPrice.multiply(new BigDecimal(discount + "")).divide(new BigDecimal("100"))
.setScale(2, RoundingMode.HALF_UP);
obj.put("level",level);
obj.put("price",price1);
obj.put("childPrice",price2);
obj.put("level", level);
obj.put("price", price1);
obj.put("childPrice", price2);
array.add(obj);
}
if(array.size()>0){
String json=array.toJSONString();
if (array.size() > 0) {
String json = array.toJSONString();
spePrice.setMemberPrice(json);
}
}
if(priceId==null||priceId==0){
if (priceId == null || priceId == 0) {
speBiz.insertSelective(spePrice);
priceId=spePrice.getId();
}else {
priceId = spePrice.getId();
} else {
speBiz.updateSelectiveById(spePrice);
}
prices.add(priceId);
}
if(prices.size()>0){
speBiz.delGoodSpe(goodId,prices);
if (prices.size() > 0) {
speBiz.delGoodSpe(goodId, prices);
}
}
if(sites.size()>0){
List<Integer> vids=new ArrayList<>();
List<TourGoodVerification> verifications=new ArrayList<>();
for (Integer siteId:sites){
if(prices.size()>0){
for(Integer priceId:prices){
TourGoodVerification verification=new TourGoodVerification();
if (sites.size() > 0) {
List<Integer> vids = new ArrayList<>();
List<TourGoodVerification> verifications = new ArrayList<>();
for (Integer siteId : sites) {
if (prices.size() > 0) {
for (Integer priceId : prices) {
TourGoodVerification verification = new TourGoodVerification();
verification.setGoodId(goodId);
verification.setSiteId(siteId);
verification.setSpeId(priceId);
verification.setIsDel(0);
TourGoodVerification verification1=verificationBiz.selectOne(verification);
if(verification1==null){
TourGoodVerification verification1 = verificationBiz.selectOne(verification);
if (verification1 == null) {
verification.setTotalPerson(0);
verification.setVerificationPerson(0);
verification.setStatus(0);
verifications.add(verification);
}else {
} else {
vids.add(verification1.getId());
}
......@@ -269,21 +271,23 @@ public class TourGoodBiz extends BaseBiz<TourGoodMapper, TourGood> {
}
if(vids.size()>0){
verificationBiz.delGoodVerification(goodId,vids);
if (vids.size() > 0) {
verificationBiz.delGoodVerification(goodId, vids);
}
if(verifications.size()>0){
for (TourGoodVerification verif:verifications)
verificationBiz.insertSelective(verif);
if (verifications.size() > 0) {
for (TourGoodVerification verif : verifications)
verificationBiz.insertSelective(verif);
}
}
}
} catch (IllegalAccessException e) {
log.error(e.getMessage(), e);;
log.error(e.getMessage(), e);
;
} catch (InvocationTargetException e) {
log.error(e.getMessage(), e);;
return ObjectRestResponse.createFailedResult(ResultCode.EXCEPTION_CODE, "出现异常");
log.error(e.getMessage(), e);
;
return ObjectRestResponse.createFailedResult(ResultCode.EXCEPTION_CODE, "出现异常");
}
return ObjectRestResponse.succ();
}
......@@ -294,31 +298,33 @@ public class TourGoodBiz extends BaseBiz<TourGoodMapper, TourGood> {
return ObjectRestResponse.createFailedResult(ResultCode.NULL_CODE, "参数为空");
}
try {
TourGood TourGood=new TourGood();
TourGood TourGood = new TourGood();
TourGood.setId(id);
TourGood.setIsDel(1);
updateSelectiveById(TourGood);
return ObjectRestResponse.succ();
} catch (Exception e) {
log.error(e.getMessage(), e);;
log.error(e.getMessage(), e);
;
log.error("---商品详情---id=====" + id + "----异常---msg===" + e.getMessage());
return ObjectRestResponse.createFailedResult(ResultCode.EXCEPTION_CODE, "出现异常");
}
}
//上下架商品
public ObjectRestResponse upStatusById(Integer id,Integer status) {
if (id == null || id == 0||status == null) {
public ObjectRestResponse upStatusById(Integer id, Integer status) {
if (id == null || id == 0 || status == null) {
return ObjectRestResponse.createFailedResult(ResultCode.NULL_CODE, "参数为空");
}
try {
TourGood TourGood=new TourGood();
TourGood TourGood = new TourGood();
TourGood.setId(id);
TourGood.setStatus(status);
updateSelectiveById(TourGood);
return ObjectRestResponse.succ();
} catch (Exception e) {
log.error(e.getMessage(), e);;
log.error(e.getMessage(), e);
;
log.error("---商品详情---id=====" + id + "----异常---msg===" + e.getMessage());
return ObjectRestResponse.createFailedResult(ResultCode.EXCEPTION_CODE, "出现异常");
}
......@@ -326,16 +332,18 @@ public class TourGoodBiz extends BaseBiz<TourGoodMapper, TourGood> {
/**
* 首页旅游列表
*
* @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);
}
/**
* 获取指定数量的随机旅游路线
*
* @return
*/
public ObjectRestResponse findRandomVehicle(Integer number) {
......@@ -343,13 +351,13 @@ public class TourGoodBiz extends BaseBiz<TourGoodMapper, TourGood> {
Map<String, Object> param = new HashMap<>();
List<TourGood> list = mapper.getCoordinateList(param);
Set<TourGood> resultList = new HashSet<>();
if(CollectionUtils.isNotEmpty(list)) {
if(number >= list.size()) {
if (CollectionUtils.isNotEmpty(list)) {
if (number >= list.size()) {
return ObjectRestResponse.succ(list);
}
Set<Integer> set = new HashSet<>();
RandomUtil.randomSet(list.size(), number, set, number);
for(Integer i : set) {
for (Integer i : set) {
resultList.add(list.get(i));
}
}
......@@ -357,22 +365,42 @@ public class TourGoodBiz extends BaseBiz<TourGoodMapper, TourGood> {
}
public List homePageTour(WebsiteQuery query) {
if (Objects.isNull(query)) {
return new ArrayList();
}
setQueryTagIds(query);
if (CollectionUtils.isEmpty(query.getTagIds())) {
setQueryTagIds(query);
}
List<TourGood> list = mapper.getList(query);
return CollectionUtils.isNotEmpty(list)?list:new ArrayList<>();
return handleResultList(list, query);
}
private List handleResultList(List<TourGood> list, WebsiteQuery query) {
int size=0;
if (list != null) {
size = list.size();
}
if (size!= query.getLimit()) {
List<Integer> ids = list.parallelStream().map(TourGood::getId).collect(Collectors.toList());
Example example =new Example(TourGood.class);
example.createCriteria().andNotIn("id",ids).andEqualTo("status",1).andEqualTo("isDel",0);
example.orderBy("rank").asc().orderBy("crtTime").desc();
PageHelper.startPage(1,query.getLimit()-size);
List<TourGood> tourGoods = mapper.selectByExample(example);
list.addAll(tourGoods);
}
return list;
}
private void setQueryTagIds(WebsiteQuery query) {
if (CollectionUtils.isEmpty(query.getTagIds())) {
List<Integer> list=new ArrayList<>();
List<Integer> list = new ArrayList<>();
Integer type = query.getType();
if (type==1) {
if (type == 1) {
if (StringUtils.isNotBlank(popular)) {
String[] popularIds = popular.split(",");
for (String id : popularIds) {
......@@ -381,7 +409,7 @@ public class TourGoodBiz extends BaseBiz<TourGoodMapper, TourGood> {
}
}
if (type==2) {
if (type == 2) {
if (StringUtils.isNotBlank(characteristic)) {
String[] characteristicIds = characteristic.split(",");
for (String id : characteristicIds) {
......@@ -395,7 +423,7 @@ public class TourGoodBiz extends BaseBiz<TourGoodMapper, TourGood> {
public List newTour(Integer limit) {
List list = mapper.newTour(limit);
return CollectionUtils.isNotEmpty(list)?list:new ArrayList<>();
return CollectionUtils.isNotEmpty(list) ? list : new ArrayList<>();
}
}
......
......@@ -14,19 +14,19 @@ import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("website")
@RequestMapping("/website/app/unauth")
@IgnoreClientToken
@IgnoreUserToken
@Api(tags = {"官网"})
public class OfficialWebsiteTourController extends BaseController<TourGoodBiz, TourGood> {
@PostMapping("/app/unauth/tour")
@PostMapping("/tour")
public ObjectRestResponse homePageTour(@RequestBody WebsiteQuery query) throws Exception {
return ObjectRestResponse.succ(baseBiz.homePageTour(query));
}
@GetMapping("/app/unauth/tour/new")
@GetMapping("/tour/new")
public ObjectRestResponse newTour(@RequestParam(value = "limit", defaultValue = "6") Integer limit) {
return ObjectRestResponse.succ(baseBiz.newTour(limit));
}
......
......@@ -123,7 +123,7 @@
ORDER BY g.rank DESC ,g.id DESC
</select>
<select id="getList" resultType="com.github.wxiaoqi.security.common.vo.GoodDataVO">
<select id="getList" resultType="com.xxfc.platform.tour.entity.TourGood">
SELECT
g.id AS `id`,
g. NAME AS `name`,
......
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