jiangping
2023-09-18 74d80f67e70666dbd38b1f0b5e4c0c7772fa5b8c
server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java
@@ -21,6 +21,7 @@
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.context.annotation.Lazy;
@@ -216,29 +217,36 @@
    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
    @Override
    public void updateStatusByIds(List<Integer> idList, Integer status) {
        if (CollectionUtils.isEmpty(idList)){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"商品状态不能为空");
    public void updateStatusByIds(BaseGoods param) {
        if (CollectionUtils.isEmpty(param.getIdList())
                || param.getStatus() == null
               || !(Constants.equalsInteger(param.getStatus(), Constants.ONE)||Constants.equalsInteger(param.getStatus()  ,Constants.ZERO))){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        idList.forEach(s->updateStatusById(s,status));
        param.getIdList().forEach(s->updateStatusById(s,param.getStatus()));
    }
    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
    @Override
    public void updateStatusById(Integer id, Integer status) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if (Objects.isNull(status)){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"商品状态不能为空");
        }
        if (Constants.equalsInteger(status,Constants.ZERO)){
            //如果启用
            BaseGoods baseGoods = new BaseGoods();
            baseGoods.setId(id);
            baseGoods.setEditDate(new Date());
            baseGoods.setEditor(user.getId());
            baseGoods.setStatus(status);
            baseGoodsMapper.updateById(baseGoods);
        }else if (Constants.equalsInteger(status,Constants.ONE)){
            //如果禁用
            BaseGoods baseGoods = new BaseGoods();
            baseGoods.setId(id);
            baseGoods.setEditDate(new Date());
            baseGoods.setEditor(user.getId());
            baseGoods.setStatus(status);
            baseGoodsMapper.updateById(baseGoods);
@@ -246,7 +254,9 @@
            goodsUpdate.lambda()
                        .eq(Goods::getType,Constants.ONE)
                        .eq(Goods::getGoodsId,id)
                        .set(Goods::getStatus,Constants.ONE);
                        .set(Goods::getStatus,Constants.ONE)
                        .set(Goods::getEditor,user.getId())
                        .set(Goods::getEditDate,new Date());
            goodsMapper.update(null,goodsUpdate);
        }
    }
@@ -321,31 +331,30 @@
    @Override
    public PageData<BaseGoods> findPage(PageWrap<BaseGoods> pageWrap) {
        pageWrap.getModel().setIsdeleted(Constants.ZERO);
        IPage<BaseGoods> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<BaseGoods> queryWrapper = new MPJLambdaWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        if (pageWrap.getModel().getId() != null) {
            queryWrapper.like(BaseGoods::getId, pageWrap.getModel().getId());
        }
        if (pageWrap.getModel().getName() != null) {
            queryWrapper.eq(BaseGoods::getName, pageWrap.getModel().getName());
        }
        if (pageWrap.getModel().getStatus() != null) {
            queryWrapper.eq(BaseGoods::getStatus, pageWrap.getModel().getStatus());
        }
        if (pageWrap.getModel().getCategoryId() != null) {
            queryWrapper.eq(BaseGoods::getCategoryId, pageWrap.getModel().getCategoryId());
        }
        if (pageWrap.getModel().getBrandId() != null) {
            queryWrapper.eq(BaseGoods::getBrandId, pageWrap.getModel().getBrandId());
        }
        queryWrapper.leftJoin(Brand.class,Brand::getId,BaseGoods::getBrandId)
                    .leftJoin(BaseCategory.class,BaseCategory::getId,BaseGoods::getBaseDataId)
                    .leftJoin(BaseCategory.class,BaseCategory::getId,BaseGoods::getCategoryId)
                    .selectAll(BaseGoods.class)
                    .selectAs(Brand::getName,BaseGoods::getBrandName)
                    .selectAs(BaseCategory::getSortnum,BaseGoods::getCategoryName);
                    .selectAs(BaseCategory::getName,BaseGoods::getCategoryName)
                    .eq(BaseGoods::getIsdeleted, Constants.ZERO)
                    .like(StringUtils.isNotBlank(pageWrap.getModel().getName()), BaseGoods::getName,pageWrap.getModel().getName())
                    .eq(pageWrap.getModel().getId()!=null,BaseGoods::getId, pageWrap.getModel().getId())
                    .eq(pageWrap.getModel().getCategoryId()!=null,BaseGoods::getCategoryId, pageWrap.getModel().getCategoryId())
                    .eq(pageWrap.getModel().getBrandId()!=null,BaseGoods::getBrandId, pageWrap.getModel().getBrandId())
                    .eq(pageWrap.getModel().getStatus()!=null,BaseGoods::getStatus, pageWrap.getModel().getStatus());
        queryWrapper.orderByDesc(Goods::getId);
        return PageData.from(baseGoodsJoinMapper.selectJoinPage(page,BaseGoods.class,queryWrapper));
        PageData<BaseGoods> pageData =PageData.from(baseGoodsJoinMapper.selectJoinPage(page,BaseGoods.class,queryWrapper));
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode();
        pageData.getRecords().forEach(i->{
            i.setFullImgUrl(prefixUrl + i.getImgurl());
        });
        return pageData;
    }
    @Override