| | |
| | | package com.xzx.gc.shop.service; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUnit; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.fasterxml.jackson.databind.DeserializationFeature; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.github.pagehelper.PageHelper; |
| | |
| | | ScoreGoodsImagesMapper scoreGoodsImagesMapper; |
| | | @Resource |
| | | ScoreGoodsStyleMapper scoreGoodsStyleMapper; |
| | | @Resource |
| | | ScoreGoodsSearchMapper scoreGoodsSearchMapper; |
| | | @Resource |
| | | ScoreOrderMapper scoreOrderMapper; |
| | | |
| | | @Autowired |
| | | private MqUtil mqUtil; |
| | |
| | | public Map<String, Object> queryGoodsList(QueryGoodsListDto model) { |
| | | String name = model.getName() == null ? "":model.getName(); |
| | | int delFlag = model.getDelFlag() == null ? 2:model.getDelFlag(); |
| | | int namePx = model.getNamePx() == null ? 7:model.getNamePx(); |
| | | int typePx = model.getTypePx() == null ? 2:model.getTypePx(); |
| | | PageHelper.startPage(model.getPage(), model.getLimit()); |
| | | |
| | | List<QueryGoodsListVo> maps = scoreGoodsMapper.queryGoodsList(name,delFlag); |
| | | List<QueryGoodsListVo> maps = scoreGoodsMapper.queryGoodsList(name,delFlag,model.getIsQg(),model.getIsSale(),namePx,typePx); |
| | | // if(CollUtil.isNotEmpty(maps)){ |
| | | // for(QueryGoodsListVo queryGoodsListVo : maps){ |
| | | // long id = queryGoodsListVo.getId(); |
| | | // Integer stock = scoreGoodsSkuMapper.selectScoreGoodsSkuMapperByGoodId(id); |
| | | // queryGoodsListVo.setStock(stock); |
| | | // } |
| | | // } |
| | | PageInfo pageInfo = new PageInfo(maps); |
| | | int count = Convert.toInt(pageInfo.getTotal()); |
| | | Map<String, Object> map = new HashMap<>(); |
| | |
| | | public void updateGoods(UpdateGoodsDto model) { |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); |
| | | ScoreGoods scoreGoods = objectMapper.convertValue(model, ScoreGoods.class); |
| | | // ScoreGoods scoreGoods = objectMapper.convertValue(model, ScoreGoods.class); |
| | | ScoreGoods scoreGoods = BeanUtil.copyProperties(model, ScoreGoods.class); |
| | | log.info("抢购时间:{}, {}", scoreGoods.getQgStartTime(), scoreGoods.getQgEndTime()); |
| | | scoreGoodsMapper.updateByPrimaryKey(scoreGoods); |
| | | |
| | | //轮播图 |
| | |
| | | if(CollUtil.isNotEmpty(scoreGoodsSkuDtos)){ |
| | | for(ScoreGoodsSkuDto scoreGoodsSkuDto : scoreGoodsSkuDtos){ |
| | | ScoreGoodsSku scoreGoodsSku = objectMapper.convertValue(scoreGoodsSkuDto, ScoreGoodsSku.class); |
| | | scoreGoodsSku.setGoodsId(scoreGoods.getId()); |
| | | scoreGoodsSku.setStyleId(scoreGoodsStyle.getId()); |
| | | scoreGoodsSkuMapper.insertSelective(scoreGoodsSku); |
| | | } |
| | | } |
| | |
| | | |
| | | PageHelper.startPage(xcxGoodsListDto.getPageNo(), xcxGoodsListDto.getPageSize()); |
| | | List<XcxGoodsListVo> data = scoreGoodsMapper.selectXcxGoodsList(xcxGoodsListDto); |
| | | |
| | | if(StrUtil.isNotEmpty(xcxGoodsListDto.getUserId())){ |
| | | if(CollUtil.isNotEmpty(data)){ |
| | | for(XcxGoodsListVo xcxGoodsListVo : data){ |
| | | if(ScoreGoods.ISQG_YES == xcxGoodsListVo.getIsQg()){ |
| | | //抢购时间内,用户购买该商品的数量 |
| | | Integer sumCnt = scoreOrderMapper.selectGoodsQuotaTime(xcxGoodsListDto.getUserId(),xcxGoodsListVo.getId(),xcxGoodsListVo.getQgStartTime(),xcxGoodsListVo.getQgEndTime()); |
| | | xcxGoodsListVo.setAvaQuotaTime( |
| | | ((xcxGoodsListVo.getQuotaTime() == null?0:xcxGoodsListVo.getQuotaTime()) - sumCnt) > 0?((xcxGoodsListVo.getQuotaTime() == null?0:xcxGoodsListVo.getQuotaTime()) - sumCnt):0 |
| | | ); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if(StrUtil.isNotEmpty(xcxGoodsListDto.getName())){ |
| | | Example exampleSearch = new Example(ScoreGoodsSearch.class); |
| | | Example.Criteria criteriaSearch = exampleSearch.createCriteria(); |
| | | criteriaSearch.andEqualTo("contents",xcxGoodsListDto.getName()); |
| | | criteriaSearch.andEqualTo("userId",xcxGoodsListDto.getUserId()); |
| | | List<ScoreGoodsSearch> scoreGoodsSearches = scoreGoodsSearchMapper.selectByExample(exampleSearch); |
| | | if(CollUtil.isEmpty(scoreGoodsSearches)){ |
| | | ScoreGoodsSearch scoreGoodsSearch = new ScoreGoodsSearch(); |
| | | scoreGoodsSearch.setUserId(xcxGoodsListDto.getUserId()); |
| | | scoreGoodsSearch.setContents(xcxGoodsListDto.getName()); |
| | | scoreGoodsSearch.setCreatedTime(new Date()); |
| | | scoreGoodsSearchMapper.insert(scoreGoodsSearch); |
| | | } |
| | | } |
| | | return new PageInfo<>(data); |
| | | } |
| | | |
| | | public XcxGoodsDetailVo findGoodsDetails(Long id) { |
| | | public XcxGoodsDetailVo findGoodsDetails(Long id, String userId) { |
| | | XcxGoodsDetailVo data = scoreGoodsMapper.selectGoodsDetailsById(id); |
| | | data.setQuotaTime(data.getQuotaTime() == null ? 0:data.getQuotaTime()); |
| | | XcxGoodsListDto dto = new XcxGoodsListDto(); |
| | | dto.setId(id); |
| | | List<XcxGoodsListVo> list = scoreGoodsMapper.selectXcxGoodsList(dto); |
| | | |
| | | if(StrUtil.isNotEmpty(userId)){ |
| | | if(CollUtil.isNotEmpty(list)){ |
| | | for(XcxGoodsListVo xcxGoodsListVo : list){ |
| | | if(ScoreGoods.ISQG_YES == xcxGoodsListVo.getIsQg()){ |
| | | //抢购时间内,用户购买该商品的数量 |
| | | Integer sumCnt = scoreOrderMapper.selectGoodsQuotaTime(userId,xcxGoodsListVo.getId(),xcxGoodsListVo.getQgStartTime(),xcxGoodsListVo.getQgEndTime()); |
| | | data.setAvaQuotaTime( |
| | | ((xcxGoodsListVo.getQuotaTime() == null?0:xcxGoodsListVo.getQuotaTime()) - sumCnt) > 0?((xcxGoodsListVo.getQuotaTime() == null?0:xcxGoodsListVo.getQuotaTime()) - sumCnt):0 |
| | | ); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | List<String> images = scoreGoodsImagesMapper.selectScoreGoodsImagesByGoodsId(id); |
| | | data.setImages(images); |
| | | if (CollUtil.isNotEmpty(list)) { |
| | |
| | | } |
| | | return data; |
| | | } |
| | | |
| | | public List<GoodsSearchVo> goodsSearch(GoodsSearchDto goodsSearchDto) { |
| | | return scoreGoodsSearchMapper.goodsSearch(goodsSearchDto); |
| | | } |
| | | |
| | | public void delGoodsSearch(Long id, String userId) { |
| | | Example exampleSearch = new Example(ScoreGoodsSearch.class); |
| | | Example.Criteria criteriaSearch = exampleSearch.createCriteria(); |
| | | criteriaSearch.andEqualTo("id",id); |
| | | criteriaSearch.andEqualTo("userId",userId); |
| | | scoreGoodsSearchMapper.deleteByExample(exampleSearch); |
| | | } |
| | | |
| | | public void delAllSearch(String userId) { |
| | | Example exampleSearch = new Example(ScoreGoodsSearch.class); |
| | | Example.Criteria criteriaSearch = exampleSearch.createCriteria(); |
| | | criteriaSearch.andEqualTo("userId",userId); |
| | | scoreGoodsSearchMapper.deleteByExample(exampleSearch); |
| | | } |
| | | } |