SSPOnlineApiService.java 4.91 KB
package com.huaheng.api.SSP.service;

import com.alibaba.fastjson.JSONObject;
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.StringUtils;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.common.utils.http.OkHttpUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.company.mapper.WarehouseCompanyMapperAuto;
import com.huaheng.pc.config.warehouseCompany.domain.WarehouseCompany;
import com.huaheng.pc.config.warehouseCompany.service.WarehouseCompanyService;
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class SSPOnlineApiService {

    private static final Logger logger = LoggerFactory.getLogger(SSPOnlineApiService.class);
    @Resource
    private WarehouseCompanyMapperAuto warehouseCompanyMapperAuto;
    @Resource
    private WarehouseCompanyService warehouseCompanyService;

    @Autowired
    ZoneService zoneService;


    //联机信息同步
    @Transactional
    public  AjaxResult SspOnline(SSPOnlineModel som) {
        String wc = som.getWarehouseCode();
        wc="XZ0001";
        if (StringUtils.isEmpty(wc)){
            return AjaxResult.error("warehouseCode不能为空!!");
        }
//        String str = JSONObject.toJSONString(som);
//        logger.info("=========ssp联机心跳===========" + str);
        LambdaQueryWrapper<WarehouseCompany> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(WarehouseCompany::getWarehouseCode,wc);
        lambdaQueryWrapper.last("limit 1");

        WarehouseCompany list = warehouseCompanyService.getOne(lambdaQueryWrapper);
//        WarehouseCompany warehouseCompany = new WarehouseCompany();
//        warehouseCompany.setWarehouseCode(wc);
//        WarehouseCompany list = warehouseCompanyMapperAuto.selectFirstEntity(warehouseCompany);
        if (list == null) {
            return AjaxResult.error("系统中没有该仓库:" + wc+ "  信息,请先录入仓库信息!");
        } else if (som.getCubeCode()==null||som.getCubeCode()==""){
            return AjaxResult.error("钱柜编码不能为空!!");
        } else if (som.getCubeName()==null||som.getCubeName()==""){
            return AjaxResult.error("钱柜名称不能为空!!");
        } else if (som.getCubeMode()<0||som.getCubeMode()>3){
            return AjaxResult.error("钱柜模式错误!!");
        } else if (som.getcDatetime()==null||som.getcDatetime()==""){
            return AjaxResult.error("交互当前时间不能为空!!");
        } else if (som.getCubeURL()==null||som.getCubeURL()==""){
            return AjaxResult.error("钱柜URL不能为空!!");
        }
//        try {
//            Zone zone = new Zone();
//            zone.setCode(som.getCubeCode());
//            zone.setWarehouseCode(wc);
//            Zone rs = zoneService.list(new LambdaQueryWrapper<Zone>().eq(Zone::getCode,som.getCubeCode()).eq(Zone::getWarehouseCode,wc)).get(0);
//            boolean result;
//
//            zone.setWarehouseId(list.getWarehouseId());
//
//            zone.setName(som.getCubeName());
//            zone.setCubeType(som.getCubeType());
//            zone.setCubeMode(som.getCubeMode());
//            if (som.getCubeEnable() == 1) {
//                zone.setEnable("1");
//            } else {
//                zone.setEnable("0");
//            }
//            zone.setWarehouseCode(som.getWarehouseCode());
//            zone.setUserDef3(som.getCubeURL());
//            Conversion conversion = new Conversion();
//            zone.setLastUpdated(conversion.strToDateLong(som.getcDatetime()));
//            if (rs == null) {
//                result = zoneService.save(zone);
//                if (!result) {
//                    return AjaxResult.error("数据新增失败!");
//                } else {
//                    return AjaxResult.setResultCS(0,"联机心跳同步成功");
//                }
//            } else {
//                zone.setId(rs.getId());
//                boolean flag = zoneService.updateById(zone);
//                if (!flag){
//                    return AjaxResult.error("数据更新失败!");
//                }else {
//                    return AjaxResult.setResultCS(0,"联机心跳同步更新成功");
//                }
//            }
//        }catch (Exception e){
//            throw new ServiceException("钱柜数据录入出现问题,请联系管理员");
//        }
        return AjaxResult.success();
    }
}