Blame view

src/main/java/com/huaheng/api/SSP/service/SSPOnlineApiService.java 3.81 KB
游杰 authored
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.huaheng.api.SSP.service;

import com.huaheng.api.SSP.Conversion;
import com.huaheng.api.SSP.domain.SSPOnlineModel;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.IZoneService;
import com.huaheng.pc.general.company.domain.WarehouseCompany;
import com.huaheng.pc.general.company.mapper.WarehouseCompanyMapperAuto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;

@Service
public class SSPOnlineApiService {

    @Resource
    private WarehouseCompanyMapperAuto warehouseCompanyMapperAuto;

    @Autowired
    IZoneService iZoneService;


    //联机信息同步
    @Transactional
    public  AjaxResult SspOnline(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.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());
53
            zone.setWarehouseCode(list.getWarehouseCode());
游杰 authored
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
            Zone rs = iZoneService.selectFirstEntity(zone);
            int result = 0;

                zone.setWarehouseId(list.getWarehouseId());

                zone.setName(som.getCubeName());
                zone.setUserDef1(som.getCubeType());
                zone.setUserDef2(som.getCubeMode());
                if (som.getCubeEnable() == 1) {
                    zone.setEnable(true);
                } else {
                    zone.setEnable(false);
                }
                zone.setWarehouseCode(som.getWarehouseCode());
                zone.setUserDef3(som.getCubeURL());
                Conversion conversion = new Conversion();
                zone.setLastUpdated(conversion.strToDateLong(som.getcDatetime()));
            if (rs == null) {
                result = iZoneService.insert(zone);
                if (result < 1) {
                    return AjaxResult.error("数据新增失败!");
                } else {
                    return AjaxResult.setResultCS(0,"联机心跳同步成功");
                }
            } else {
                zone.setId(rs.getId());
                result = iZoneService.updateByModel(zone);
                if (result < 1){
                    return AjaxResult.error("数据更新失败!");
                }else {
                    return AjaxResult.setResultCS(0,"联机心跳同步更新成功");
                }
            }
        }catch (Exception e){
            throw new ServiceException("钱柜数据录入出现问题,请联系管理员");
        }
    }
}