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

import com.aliyun.oss.ServiceException;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.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 org.springframework.transaction.annotation.Transactional;

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


/**
 * 货架 服务层实现
 *
 * @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(ShiroUtils.getWarehouseCode());
        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("成功");
    }
    @Override
    public Points selectEntity(Points points){
        LambdaQueryWrapper<Points> pointsLamb = Wrappers.lambdaQuery();
        pointsLamb.eq(StringUtils.isNotEmpty(points.getGoodsShelfNo()),Points::getGoodsShelfNo,points.getGoodsShelfNo());
        pointsLamb.eq(StringUtils.isNotEmpty(points.getWarehouseCode()),Points::getWarehouseCode,points.getWarehouseCode());
        pointsLamb.eq(StringUtils.isNotNull(points.getIsLocked()),Points::getIsLocked,points.getIsLocked());
        pointsLamb.last("limit 1");
        return this.getOne(pointsLamb);
    }
    @Override
    public Points selectEntityV(Points points){
        LambdaQueryWrapper<Points> pointsLamb = Wrappers.lambdaQuery();
        pointsLamb.eq(StringUtils.isNotEmpty(points.getGoodsShelfNo()),Points::getGoodsShelfNo,points.getGoodsShelfNo());
        pointsLamb.eq(StringUtils.isNotEmpty(points.getWarehouseCode()),Points::getWarehouseCode,points.getWarehouseCode());
        pointsLamb.ge(StringUtils.isNotNull(points.getIsLocked()),Points::getIsLocked,points.getIsLocked());
        pointsLamb.last("limit 1");
        return this.getOne(pointsLamb);
    }

    @Override
    public List<Map<String, Object>> selectShlfno(String warehouseCode) {
        LambdaQueryWrapper<Points> pointsLamb = Wrappers.lambdaQuery();
        pointsLamb.eq(StringUtils.isNotEmpty(warehouseCode),Points::getWarehouseCode,warehouseCode);
        pointsLamb.orderByAsc(Points::getGoodsShelfNo);
        return this.listMaps(pointsLamb);
    }

    @Override
    @Transactional
    public void updateContainerCommon(Integer[] ids,int status){
        for(int a=0;a<ids.length-1;a++){
            Points points=this.getById(ids[a]);
            points.setCommon(status);
            this.updateById(points);
            //修改容器属性
            Container container = new Container();
            container.setGoodsShelfNo(points.getGoodsShelfNo());
            List<Container> containerList = containerService.selectListEntityByEqual(container);
            for (Container item : containerList) {
                item.setCommon(status);
                if (!containerService.updateById(item)) {
                    throw new ServiceException("修改容器属性失败");
                }
            }
        }
    }

}