PointsServiceImpl.java 2.44 KB
package com.huaheng.pc.config.points.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.points.domain.Points;
import com.huaheng.pc.config.points.mapper.PointsMapper;
import org.apache.commons.collections.ListUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


/**
 * 货架 服务层实现
 *
 * @author ricard
 * @date 2019-12-26
 */
@Service
public class PointsServiceImpl extends ServiceImpl<PointsMapper,Points> implements PointsService{

    @Resource
    private PointsMapper pointsMapper;
    @Resource
    private ContainerService containerService;

    @Override
    public int updateAll() {
        return pointsMapper.updateAll();
    }



    @Override
    public AjaxResult detectShelf() {
        //查找为空的货架
        List<Container> containers =containerService.selectListShelf();
        List<String> stringList = new ArrayList<>();
        for(Container item : containers){
            stringList.add(item.getGoodsShelfNo());
        }
        Integer flag = 1;

        //修改空货架状态
        flag = pointsMapper.updateIsEmpty(stringList, QuantityConstant.POINTS_SOME);
        if(flag < 1){
            return AjaxResult.error("修改空货架状态失败");
        }


        //查找所以货架
        LambdaQueryWrapper<Points> pointsLamb = Wrappers.lambdaQuery();
        pointsLamb.eq(Points::getWarehouseCode,ShiroUtils.getWarehouseCode());
        List<Points> pointsList = this.list(pointsLamb);

        //去重
        List<String> list =new ArrayList<>();
        for(Points item : pointsList){
            list.add(item.getGoodsShelfNo());
        }

        List<String> list1 = ListUtils.subtract(list,stringList);

        //修改非空货架
        flag = pointsMapper.updateIsEmpty(list1,QuantityConstant.POINTS_EMPTY);
        if(flag < 1){
            return AjaxResult.error("修改空货架状态失败");
        }

        return AjaxResult.success("成功");
    }

}