| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.core.constants.Constants; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.model.LoginUserInfo; |
| | | import com.doumee.core.model.PageData; |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.dao.business.DiscountMapper; |
| | | import com.doumee.dao.business.join.BikeRepairJoinMapper; |
| | | import com.doumee.dao.business.join.DiscountJoinMapper; |
| | | import com.doumee.dao.business.model.BaseParam; |
| | | import com.doumee.dao.business.model.BikeRepair; |
| | | import com.doumee.dao.business.model.Discount; |
| | | import com.doumee.dao.business.model.Member; |
| | | import com.doumee.dao.business.web.request.BikeRepairDTO; |
| | | import com.doumee.dao.system.model.SystemUser; |
| | | import com.doumee.service.business.DiscountService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * 骑行套餐信息表Service实现 |
| | |
| | | @Autowired |
| | | private DiscountMapper discountMapper; |
| | | |
| | | @Autowired |
| | | private DiscountJoinMapper discountJoinMapper; |
| | | |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | |
| | | @Override |
| | | public String create(Discount discount) { |
| | | LoginUserInfo userInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | this.vaildReq(discount); |
| | | discount.setStatus(Constants.ZERO); |
| | | discount.setIsdeleted(Constants.ZERO); |
| | | discount.setCreateDate(new Date()); |
| | | discount.setCreator(userInfo.getId()); |
| | | if(Constants.equalsInteger(discount.getUseType(),Constants.ZERO)){ |
| | | discount.setUseDays((int) (DateUtil.getBetweenDays(DateUtil.dateToString(discount.getUseStartDate(),"yyyy-MM-dd"),DateUtil.dateToString(discount.getUseEndDate(),"yyyy-MM-dd")))); |
| | | } |
| | | discountMapper.insert(discount); |
| | | return discount.getId(); |
| | | } |
| | | |
| | | |
| | | public void vaildReq(Discount discount) { |
| | | if(Objects.isNull(discount) |
| | | || StringUtils.isBlank(discount.getName()) |
| | | || Objects.isNull(discount.getType()) |
| | | || Objects.isNull(discount.getLimitType()) |
| | | || (Constants.equalsInteger(discount.getLimitTime(),Constants.ONE) && (Objects.isNull(discount.getLimitTime()) || discount.getLimitTime() > 1440)) |
| | | || Objects.isNull(discount.getPrice()) || discount.getPrice().compareTo(BigDecimal.ZERO) <= Constants.ZERO |
| | | || Objects.isNull(discount.getChannel()) |
| | | || Objects.isNull(discount.getStartDate()) |
| | | || Objects.isNull(discount.getEndDate()) |
| | | || Objects.isNull(discount.getUseType()) |
| | | || (Constants.equalsInteger(discount.getUseType(),Constants.ZERO) && ( Objects.isNull(discount.getUseStartDate()) || Objects.isNull(discount.getUseEndDate()) )) |
| | | || (Constants.equalsInteger(discount.getUseType(),Constants.ONE) && Objects.isNull(discount.getUseDays())) |
| | | || (Constants.equalsInteger(discount.getUseType(),Constants.TWO) && ( Objects.isNull(discount.getUseStartDate()) || Objects.isNull(discount.getUseDays()) )) |
| | | || (Objects.isNull(discount.getUseHoliday()) || Objects.isNull(discount.getUseWorkday()) ) |
| | | || (Objects.isNull(discount.getIsbike()) || Objects.isNull(discount.getIselecbike()) ) |
| | | ){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | if(discount.getStartDate().getTime()>discount.getEndDate().getTime()){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"销售时段信息错误"); |
| | | } |
| | | //固定日期生效 |
| | | if(Constants.equalsInteger(discount.getUseType(),Constants.ZERO) && |
| | | ( discount.getUseStartDate().getTime()>discount.getUseEndDate().getTime()) ){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"使用时段信息错误"); |
| | | } |
| | | |
| | | //指定日期生效 |
| | | if(Constants.equalsInteger(discount.getUseType(),Constants.TWO) && |
| | | ( discount.getUseStartDate().getTime()<discount.getStartDate().getTime() || |
| | | discount.getUseStartDate().getTime() > discount.getEndDate().getTime() |
| | | ) ){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"使用时段信息错误"); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void deleteById(String id) { |
| | | discountMapper.deleteById(id); |
| | | Discount discount = discountMapper.selectById(id); |
| | | if(Objects.isNull(discount)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | if(Constants.equalsInteger(discount.getStatus(),Constants.ZERO)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非禁用数据,无法进行删除"); |
| | | } |
| | | discountMapper.update(null,new UpdateWrapper<Discount>().lambda().set(Discount::getIsdeleted,Constants.ONE).eq(Discount::getId,discount.getId())); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void updStatus(Discount discount) { |
| | | if(Objects.isNull(discount) |
| | | || StringUtils.isBlank(discount.getId()) |
| | | || Objects.isNull(discount.getStatus())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | discountMapper.update(null,new UpdateWrapper<Discount>().lambda().set(Discount::getStatus,discount.getStatus()).eq(Discount::getId,discount.getId())); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void delete(Discount discount) { |
| | |
| | | |
| | | @Override |
| | | public Discount findById(String id) { |
| | | return discountMapper.selectById(id); |
| | | Discount discount = discountJoinMapper.selectOne(new MPJLambdaWrapper<Discount>() |
| | | .selectAll(Discount.class) |
| | | .select(" (select count(1) from goodsorder g where g.obj_type = 0 and g.obj_id = t.id and g.pay_status = 1 ) ",Discount::getSaleNum) |
| | | .leftJoin(SystemUser.class,SystemUser::getId,Discount::getCreator) |
| | | .eq(Discount::getId,id) |
| | | ); |
| | | if(Objects.isNull(discount)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | this.dealPrice(discount); |
| | | if(StringUtils.isNotBlank(discount.getImgurl())){ |
| | | String path =systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FILE_DIR).getCode()+ |
| | | systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.DISCOUNT).getCode(); |
| | | discount.setFullImgUrl(path + discount.getImgurl()); |
| | | } |
| | | return discount; |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | public PageData<Discount> findPage(PageWrap<Discount> pageWrap) { |
| | | IPage<Discount> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); |
| | | QueryWrapper<Discount> queryWrapper = new QueryWrapper<>(); |
| | | MPJLambdaWrapper<Discount> queryWrapper = new MPJLambdaWrapper<>(); |
| | | Utils.MP.blankToNull(pageWrap.getModel()); |
| | | if (pageWrap.getModel().getId() != null) { |
| | | queryWrapper.lambda().eq(Discount::getId, pageWrap.getModel().getId()); |
| | | Discount modele = pageWrap.getModel(); |
| | | queryWrapper.selectAll(Discount.class) |
| | | .select(" (select count(1) from goodsorder g where g.obj_type = 0 and g.obj_id = t.id and g.pay_status = 1 ) ",Discount::getSaleNum) |
| | | .leftJoin(SystemUser.class,SystemUser::getId,Discount::getCreator) |
| | | .like(StringUtils.isNotEmpty(pageWrap.getModel().getName()),Discount::getName,pageWrap.getModel().getName()) |
| | | .eq(Objects.nonNull(modele.getStatus()),Discount::getStatus, modele.getStatus()) |
| | | .eq(Objects.nonNull(modele.getBikeOrElec()) && Constants.equalsInteger(modele.getBikeOrElec(),Constants.ONE),Discount::getIsbike, Constants.ONE) |
| | | .eq(Objects.nonNull(modele.getBikeOrElec()) && Constants.equalsInteger(modele.getBikeOrElec(),Constants.TWO),Discount::getIselecbike, Constants.ONE) |
| | | .eq(Discount::getIsdeleted, Constants.ZERO) |
| | | .eq( pageWrap.getModel().getStatus() !=null,BikeRepair::getStatus,pageWrap.getModel().getStatus()); |
| | | queryWrapper.orderByDesc(Discount::getCreateDate); |
| | | PageData<Discount> pageData = PageData.from(discountJoinMapper.selectJoinPage(page, Discount.class,queryWrapper)); |
| | | for (Discount discount:pageData.getRecords()) { |
| | | dealPrice(discount); |
| | | } |
| | | if (pageWrap.getModel().getCreateDate() != null) { |
| | | queryWrapper.lambda().ge(Discount::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate())); |
| | | queryWrapper.lambda().le(Discount::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate())); |
| | | } |
| | | if (pageWrap.getModel().getCreator() != null) { |
| | | queryWrapper.lambda().eq(Discount::getCreator, pageWrap.getModel().getCreator()); |
| | | } |
| | | if (pageWrap.getModel().getEditDate() != null) { |
| | | queryWrapper.lambda().ge(Discount::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate())); |
| | | queryWrapper.lambda().le(Discount::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate())); |
| | | } |
| | | if (pageWrap.getModel().getEditor() != null) { |
| | | queryWrapper.lambda().eq(Discount::getEditor, pageWrap.getModel().getEditor()); |
| | | } |
| | | if (pageWrap.getModel().getIsdeleted() != null) { |
| | | queryWrapper.lambda().eq(Discount::getIsdeleted, pageWrap.getModel().getIsdeleted()); |
| | | } |
| | | if (pageWrap.getModel().getInfo() != null) { |
| | | queryWrapper.lambda().eq(Discount::getInfo, pageWrap.getModel().getInfo()); |
| | | } |
| | | if (pageWrap.getModel().getName() != null) { |
| | | queryWrapper.lambda().eq(Discount::getName, pageWrap.getModel().getName()); |
| | | } |
| | | if (pageWrap.getModel().getType() != null) { |
| | | queryWrapper.lambda().eq(Discount::getType, pageWrap.getModel().getType()); |
| | | } |
| | | if (pageWrap.getModel().getLimitType() != null) { |
| | | queryWrapper.lambda().eq(Discount::getLimitType, pageWrap.getModel().getLimitType()); |
| | | } |
| | | if (pageWrap.getModel().getLimitTime() != null) { |
| | | queryWrapper.lambda().eq(Discount::getLimitTime, pageWrap.getModel().getLimitTime()); |
| | | } |
| | | if (pageWrap.getModel().getPrice() != null) { |
| | | queryWrapper.lambda().eq(Discount::getPrice, pageWrap.getModel().getPrice()); |
| | | } |
| | | if (pageWrap.getModel().getLinePrice() != null) { |
| | | queryWrapper.lambda().eq(Discount::getLinePrice, pageWrap.getModel().getLinePrice()); |
| | | } |
| | | if (pageWrap.getModel().getChannel() != null) { |
| | | queryWrapper.lambda().eq(Discount::getChannel, pageWrap.getModel().getChannel()); |
| | | } |
| | | if (pageWrap.getModel().getImgurl() != null) { |
| | | queryWrapper.lambda().eq(Discount::getImgurl, pageWrap.getModel().getImgurl()); |
| | | } |
| | | if (pageWrap.getModel().getDescs() != null) { |
| | | queryWrapper.lambda().eq(Discount::getDescs, pageWrap.getModel().getDescs()); |
| | | } |
| | | if (pageWrap.getModel().getContent() != null) { |
| | | queryWrapper.lambda().eq(Discount::getContent, pageWrap.getModel().getContent()); |
| | | } |
| | | if (pageWrap.getModel().getStartDate() != null) { |
| | | queryWrapper.lambda().ge(Discount::getStartDate, Utils.Date.getStart(pageWrap.getModel().getStartDate())); |
| | | queryWrapper.lambda().le(Discount::getStartDate, Utils.Date.getEnd(pageWrap.getModel().getStartDate())); |
| | | } |
| | | if (pageWrap.getModel().getEndDate() != null) { |
| | | queryWrapper.lambda().ge(Discount::getEndDate, Utils.Date.getStart(pageWrap.getModel().getEndDate())); |
| | | queryWrapper.lambda().le(Discount::getEndDate, Utils.Date.getEnd(pageWrap.getModel().getEndDate())); |
| | | } |
| | | if (pageWrap.getModel().getUseType() != null) { |
| | | queryWrapper.lambda().eq(Discount::getUseType, pageWrap.getModel().getUseType()); |
| | | } |
| | | if (pageWrap.getModel().getUseStartDate() != null) { |
| | | queryWrapper.lambda().ge(Discount::getUseStartDate, Utils.Date.getStart(pageWrap.getModel().getUseStartDate())); |
| | | queryWrapper.lambda().le(Discount::getUseStartDate, Utils.Date.getEnd(pageWrap.getModel().getUseStartDate())); |
| | | } |
| | | if (pageWrap.getModel().getUseEndDate() != null) { |
| | | queryWrapper.lambda().ge(Discount::getUseEndDate, Utils.Date.getStart(pageWrap.getModel().getUseEndDate())); |
| | | queryWrapper.lambda().le(Discount::getUseEndDate, Utils.Date.getEnd(pageWrap.getModel().getUseEndDate())); |
| | | } |
| | | if (pageWrap.getModel().getUseDays() != null) { |
| | | queryWrapper.lambda().eq(Discount::getUseDays, pageWrap.getModel().getUseDays()); |
| | | } |
| | | if (pageWrap.getModel().getUseHoliday() != null) { |
| | | queryWrapper.lambda().eq(Discount::getUseHoliday, pageWrap.getModel().getUseHoliday()); |
| | | } |
| | | if (pageWrap.getModel().getUseWorkday() != null) { |
| | | queryWrapper.lambda().eq(Discount::getUseWorkday, pageWrap.getModel().getUseWorkday()); |
| | | } |
| | | if (pageWrap.getModel().getSaleLimit() != null) { |
| | | queryWrapper.lambda().eq(Discount::getSaleLimit, pageWrap.getModel().getSaleLimit()); |
| | | } |
| | | if (pageWrap.getModel().getSaleDayLimit() != null) { |
| | | queryWrapper.lambda().eq(Discount::getSaleDayLimit, pageWrap.getModel().getSaleDayLimit()); |
| | | } |
| | | if (pageWrap.getModel().getStatus() != null) { |
| | | queryWrapper.lambda().eq(Discount::getStatus, pageWrap.getModel().getStatus()); |
| | | } |
| | | if (pageWrap.getModel().getIsbike() != null) { |
| | | queryWrapper.lambda().eq(Discount::getIsbike, pageWrap.getModel().getIsbike()); |
| | | } |
| | | if (pageWrap.getModel().getIselecbike() != null) { |
| | | queryWrapper.lambda().eq(Discount::getIselecbike, pageWrap.getModel().getIselecbike()); |
| | | } |
| | | for(PageWrap.SortData sortData: pageWrap.getSorts()) { |
| | | if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { |
| | | queryWrapper.orderByDesc(sortData.getProperty()); |
| | | } else { |
| | | queryWrapper.orderByAsc(sortData.getProperty()); |
| | | } |
| | | } |
| | | return PageData.from(discountMapper.selectPage(page, queryWrapper)); |
| | | return pageData; |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public void dealPrice(Discount discount){ |
| | | if(Objects.isNull(discount) |
| | | || Objects.isNull(discount.getUseEndDate()) |
| | | || Objects.isNull(discount.getUseStartDate()) |
| | | || Objects.isNull(discount.getPrice()) |
| | | || discount.getPrice().compareTo(BigDecimal.ZERO)==0 |
| | | ){ |
| | | discount.setDayPrice(BigDecimal.ZERO); |
| | | return; |
| | | } |
| | | discount.setDayPrice(discount.getPrice().divide(new BigDecimal(Long.toString(discount.getUseDays())),2)); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public long count(Discount discount) { |
| | | QueryWrapper<Discount> wrapper = new QueryWrapper<>(discount); |