首页上半,
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
package com.chaozhanggui.system.cashierservice.service;
|
||||
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbPlatformDictMapper;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbProductSkuMapper;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbShopInfoMapper;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbPlatformDict;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbProductSku;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.HomeDto;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.HomeUpVO;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.HomeVO;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.UserDutyVo;
|
||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lyf
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class HomePageService {
|
||||
@Resource
|
||||
private TbShopInfoMapper shopInfoMapper;
|
||||
@Resource
|
||||
private TbProductSkuMapper productSkuMapper;
|
||||
@Resource
|
||||
private TbPlatformDictMapper platformDictMapper;
|
||||
|
||||
|
||||
public Result homePage(HomeDto homeDto){
|
||||
int beginNo;
|
||||
if(homeDto.getPage() <=0){
|
||||
beginNo = 0;
|
||||
}else{
|
||||
beginNo = (homeDto.getPage() - 1) * homeDto.getSize();
|
||||
}
|
||||
List<HomeVO> homeVO = shopInfoMapper.selectShopInfo(beginNo,homeDto.getSize());
|
||||
List<Integer> objects = new ArrayList<>();
|
||||
for (HomeVO o :homeVO) {
|
||||
objects.add(o.getProductId());
|
||||
}
|
||||
//原价现价
|
||||
List<TbProductSku> tbProductSkus = productSkuMapper.selectDownSku(objects);
|
||||
//销量
|
||||
List<UserDutyVo> userDutyVos = shopInfoMapper.searchUserDutyDetail(objects);
|
||||
//组装数据
|
||||
for (HomeVO o :homeVO) {
|
||||
for (TbProductSku sku :tbProductSkus) {
|
||||
if (o.getProductId().toString().equals(sku.getProductId())){
|
||||
o.setOriginPrice(sku.getOriginPrice() == null?BigDecimal.ZERO:sku.getOriginPrice());
|
||||
o.setSalePrice(sku.getSalePrice() == null?BigDecimal.ZERO:sku.getSalePrice());
|
||||
}
|
||||
}
|
||||
if (userDutyVos == null){
|
||||
o.setRealSalesNumber(BigDecimal.ZERO);
|
||||
}else {
|
||||
for (UserDutyVo duty : userDutyVos) {
|
||||
if (o.getProductId().equals(duty.getProductId())) {
|
||||
o.setRealSalesNumber(duty.getNumber());
|
||||
}else {
|
||||
o.setRealSalesNumber(BigDecimal.ZERO);
|
||||
}
|
||||
}
|
||||
}
|
||||
//共省金额
|
||||
o.setSave(o.getOriginPrice().subtract(o.getSalePrice()));
|
||||
if (o.getOriginPrice().compareTo(BigDecimal.ZERO) == 0){
|
||||
o.setDiscount(null);
|
||||
}else {
|
||||
o.setDiscount(o.getSalePrice().divide(o.getOriginPrice(), 2, RoundingMode.DOWN).multiply(new BigDecimal("10")));
|
||||
}
|
||||
}
|
||||
return Result.success(CodeEnum.SUCCESS,homeVO);
|
||||
}
|
||||
|
||||
public Result homePageUp(String environment){
|
||||
HomeUpVO homeUpVO = new HomeUpVO();
|
||||
//轮播图
|
||||
List<TbPlatformDict> carouselList = platformDictMapper.queryAllByType("carousel",environment);
|
||||
homeUpVO.setCarousel(carouselList);
|
||||
//金刚区
|
||||
List<TbPlatformDict> districtList = platformDictMapper.queryAllByType("homeDistrict",environment);
|
||||
homeUpVO.setDistrict(districtList);
|
||||
return Result.success(CodeEnum.SUCCESS,homeUpVO);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user