LocationUploadApiService.java 5.04 KB
package com.huaheng.api.SSP.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.api.SSP.Conversion;
import com.huaheng.api.SSP.domain.SSPOnlineModel;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.company.mapper.WarehouseCompanyMapperAuto;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.warehouseCompany.domain.WarehouseCompany;
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 *库位基础信息同步Service
 * 目前根据钱柜发送过来的钱柜最大值,自动生成库位。
 */
@Service
public class LocationUploadApiService extends BaseController {

    @Resource
    private WarehouseCompanyMapperAuto warehouseCompanyMapperAuto;

    @Autowired
    ZoneService zoneService;

    @Autowired
    LocationService locationService;


    //库位基础信息同步
    @Transactional
    public  AjaxResult loupd(SSPOnlineModel som) {
        String wc = som.getWarehouseCode();
        if (wc==null||wc==""){
            return AjaxResult.error("warehouseCode不能为空!!");
        }
        WarehouseCompany warehouseCompany = new WarehouseCompany();
        warehouseCompany.setWarehouseCode(wc);
        WarehouseCompany list = warehouseCompanyMapperAuto.selectFirstEntity(warehouseCompany);
        if (list == null) {
            return AjaxResult.error("系统中没有该仓库:" + warehouseCompany.toString() + "  信息,请先录入仓库信息!");
        } else if (som.getCubeCode()==null||som.getCubeCode()==""){
            return AjaxResult.error("钱柜编码不能为空!!");
        } else if (som.getCubeName()==null||som.getCubeName()==""){
            return AjaxResult.error("钱柜名称不能为空!!");
        } else if (som.getcDatetime()==null||som.getcDatetime()==""){
            return AjaxResult.error("交互当前时间不能为空!!");
        } else if (som.getLocationMax()==0||som.getLocationMax()<1){
            return AjaxResult.error("钱柜最大值不能为空或负值!!");
        } else if (som.getCubeURL()==null||som.getCubeURL()==""){
            return AjaxResult.error("钱柜URL不能为空!!");
        }
        try {
            Zone zone = new Zone();
            zone.setCode(som.getCubeCode());
            zone.setWarehouseId(list.getWarehouseId());
            Zone rs = zoneService.list(new LambdaQueryWrapper<Zone>().eq(Zone::getCode,som.getCubeCode()).eq(Zone::getWarehouseId,warehouseCompany.getWarehouseId())).get(0);
            int result = 0;
            zone.setWarehouseId(list.getWarehouseId());
            zone.setName(som.getCubeName());
            zone.setCubeType(som.getCubeType());
            zone.setWarehouseCode(som.getWarehouseCode());
            zone.setCubeURL(som.getCubeURL());
            zone.setLocationMax(som.getLocationMax());
            Conversion conversion = new Conversion();
            zone.setLastUpdated(conversion.strToDateLong(som.getcDatetime()));
            zone.setLastUpdatedBy(ShiroUtils.getLoginName());

            //更新库位
            Location location = new Location();
            for (int i = 1; i <som.getLocationMax()+1 ; i++) {
                location.setWarehouseCode(list.getWarehouseCode());
                location.setIRow(i);
                location.setIColumn(0);location.setILayer(0);location.setIGrid(0);
                location.setLocationType("Q");
                location.setZoneId(rs.getId());
                location.setZoneCode(som.getCubeCode());
                if (locationService.selectFirstEntity(location)==null) {
                    location.setLastUpdatedBy(ShiroUtils.getLoginName());
                    locationService.insertLocation(location);
                }
            }

            if (rs == null) {
                zone.setCreatedBy(ShiroUtils.getLoginName());
                boolean flag = zoneService.save(zone);
                if (!flag) {
                    return AjaxResult.error("数据插入失败!");
                } else {
                    return AjaxResult.setResultCS(0,"库位信息上传成功!");
                }
            } else {
                zone.setId(rs.getId());
                boolean flag2=zoneService.updateById(zone);
                if (!flag2){
                    return AjaxResult.error("数据更新失败!");
                }else {
                    return AjaxResult.setResultCS(0,"库位信息上传更新成功!");
                }
            }
        }catch (Exception e){
            throw new ServiceException("钱柜数据录入出现问题,请联系管理员");
        }
    }
}