From 4fabfe4dbd2eb28d07a4350597d314958cc1c281 Mon Sep 17 00:00:00 2001 From: MrShi <1878285526@qq.com> Date: 星期四, 09 十月 2025 11:16:43 +0800 Subject: [PATCH] 优化 --- server/services/src/main/java/com/doumee/service/business/impl/DiscountServiceImpl.java | 95 ++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 76 insertions(+), 19 deletions(-) diff --git a/server/services/src/main/java/com/doumee/service/business/impl/DiscountServiceImpl.java b/server/services/src/main/java/com/doumee/service/business/impl/DiscountServiceImpl.java index 1a049aa..a8c5a63 100644 --- a/server/services/src/main/java/com/doumee/service/business/impl/DiscountServiceImpl.java +++ b/server/services/src/main/java/com/doumee/service/business/impl/DiscountServiceImpl.java @@ -7,6 +7,7 @@ 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; @@ -29,6 +30,8 @@ import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import java.math.BigDecimal; +import java.text.ParseException; import java.util.Date; import java.util.List; import java.util.Objects; @@ -58,47 +61,58 @@ discount.setIsdeleted(Constants.ZERO); discount.setCreateDate(new Date()); discount.setCreator(userInfo.getId()); + discount.setEditDate(new Date()); + discount.setEditor(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) { + public void vaildReq(Discount discount){ if(Objects.isNull(discount) || StringUtils.isBlank(discount.getName()) || Objects.isNull(discount.getType()) || Objects.isNull(discount.getLimitType()) - || (discount.getLimitTime()==Constants.ONE && Objects.isNull(discount.getLimitTime())) - || Objects.isNull(discount.getPrice()) + || (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()) - || (discount.getUseType()==Constants.ZERO && ( Objects.isNull(discount.getUseStartDate()) || Objects.isNull(discount.getUseEndDate()) )) - || (discount.getUseType()==Constants.ONE && Objects.isNull(discount.getUseDays())) - || (discount.getUseType()==Constants.TWO && ( Objects.isNull(discount.getUseStartDate()) || Objects.isNull(discount.getUseDays()) )) + || (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.SERVER_ERROR); + throw new BusinessException(ResponseStatus.BAD_REQUEST); } if(discount.getStartDate().getTime()>discount.getEndDate().getTime()){ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"閿�鍞椂娈典俊鎭敊璇�"); } //鍥哄畾鏃ユ湡鐢熸晥 - if(discount.getUseType()==Constants.ZERO && - ( discount.getUseStartDate().getTime()>discount.getUseEndDate().getTime() || - discount.getUseStartDate().getTime() < discount.getStartDate().getTime() || - discount.getUseEndDate().getTime() > discount.getEndDate().getTime() - ) ){ + if(Constants.equalsInteger(discount.getUseType(),Constants.ZERO) && + ( discount.getUseStartDate().getTime()>discount.getUseEndDate().getTime()) ){ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"浣跨敤鏃舵淇℃伅閿欒"); } //鎸囧畾鏃ユ湡鐢熸晥 - if(discount.getUseType()==Constants.TWO && + 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(),"浣跨敤鏃舵淇℃伅閿欒"); + } + if(Objects.isNull(discount.getSaleDayLimit())){ + discount.setSaleDayLimit(Constants.ZERO); + } + if(Objects.isNull(discount.getSaleLimit())){ + discount.setSaleLimit(Constants.ZERO); + } + if(Constants.equalsInteger(discount.getUseType(),Constants.TWO)){ + discount.setUseEndDate( DateUtil.StringToDateFormat(DateUtil.getXDaysAfter(discount.getUseStartDate(),discount.getUseDays()),"yyyy-MM-dd")); } } @@ -127,8 +141,6 @@ } - - @Override public void delete(Discount discount) { UpdateWrapper<Discount> deleteWrapper = new UpdateWrapper<>(discount); @@ -145,6 +157,24 @@ @Override public void updateById(Discount discount) { + LoginUserInfo userInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); + if(Objects.isNull(discount) + || StringUtils.isBlank(discount.getId())){ + throw new BusinessException(ResponseStatus.BAD_REQUEST); + } + Discount model = discountMapper.selectById(discount.getId()); + if(Objects.isNull(model)){ + throw new BusinessException(ResponseStatus.DATA_EMPTY); + } + if(!Constants.equalsInteger(model.getStatus(),Constants.ONE)){ + throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鏈鐢ㄦ棤娉曡繘琛屼慨鏀�"); + } + this.vaildReq(discount); + discount.setEditDate(new Date()); + discount.setEditor(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.updateById(discount); } @@ -161,13 +191,18 @@ @Override public Discount findById(String id) { Discount discount = discountJoinMapper.selectOne(new MPJLambdaWrapper<Discount>() + .selectAll(Discount.class) + .select(" s1.realname ",Discount::getCreatorName) + .select(" s2.realname ",Discount::getEditorName) .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) + .leftJoin(" system_user s1 on s1.id = t.creator") + .leftJoin(" system_user s2 on s2.id = t.editor") .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(); @@ -202,11 +237,33 @@ .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); - return PageData.from(discountJoinMapper.selectJoinPage(page, Discount.class,queryWrapper)); + .eq( pageWrap.getModel().getStatus() !=null,BikeRepair::getStatus,pageWrap.getModel().getStatus()) + .apply( Objects.nonNull(modele.getMinShow())," now() BETWEEN t.start_date and ( t.end_date + INTERVAL '1 day' ) ") + ; + queryWrapper.orderByDesc(Discount::getCreateDate); + PageData<Discount> pageData = PageData.from(discountJoinMapper.selectJoinPage(page, Discount.class,queryWrapper)); + for (Discount discount:pageData.getRecords()) { + dealPrice(discount); + } + return pageData; } + + + @Override + public void dealPrice(Discount discount){ + if(Objects.isNull(discount) + || Objects.isNull(discount.getUseDays()) + || 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); -- Gitblit v1.9.3