TimeTasksController.java 13 KB
Newer Older
xulihui's avatar
xulihui committed
1 2 3 4
package com.zehong.web.controller.task;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
xulihui's avatar
xulihui committed
5
import com.github.pagehelper.PageHelper;
xulihui's avatar
xulihui committed
6
import com.zehong.common.core.domain.entity.SysUser;
xulihui's avatar
xulihui committed
7 8
import com.zehong.common.core.page.PageDomain;
import com.zehong.common.core.page.TableSupport;
xulihui's avatar
xulihui committed
9 10
import com.zehong.common.core.redis.RedisCache;
import com.zehong.common.exception.CustomException;
xulihui's avatar
xulihui committed
11
import com.zehong.common.utils.DateUtils;
xulihui's avatar
xulihui committed
12 13 14
import com.zehong.common.utils.GovernmentDataCopyUtil;
import com.zehong.common.utils.StringUtils;
import com.zehong.common.utils.http.HttpClientUtils;
xulihui's avatar
xulihui committed
15 16 17
import com.zehong.common.utils.sql.SqlUtil;
import com.zehong.system.domain.TLpgAirChargeFiles;
import com.zehong.system.domain.TLpgGasBottleFiles;
xulihui's avatar
xulihui committed
18 19 20 21
import com.zehong.system.domain.TProAppInforBrowse;
import com.zehong.system.domain.TUserLocation;
import com.zehong.system.domain.vo.ProAppInforBrowseVo;
import com.zehong.system.service.ISysUserService;
xulihui's avatar
xulihui committed
22 23
import com.zehong.system.service.ITLpgAirChargeFilesService;
import com.zehong.system.service.ITLpgGasBottleFilesService;
xulihui's avatar
xulihui committed
24 25 26 27 28
import com.zehong.system.service.ITUserLocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

xulihui's avatar
xulihui committed
29 30
import java.math.BigDecimal;
import java.util.*;
xulihui's avatar
xulihui committed
31 32 33 34 35 36
import java.util.concurrent.TimeUnit;

@Component("timeTasks")
public class TimeTasksController {
    @Value("${wjyhq.apiUrl}")
    private String apiUrl;
xulihui's avatar
xulihui committed
37 38 39 40 41 42 43 44 45 46

    @Value("${wjyhq.authCode}")
    private String authCode;

    @Value("${wjyhq.accessKey}")
    private String accessKey;

    @Value("${wjyhq.secretKey}")
    private String secretKey;

xulihui's avatar
xulihui committed
47 48 49 50 51
    @Autowired
    private RedisCache redisCache;

    @Autowired
    ITUserLocationService tUserLocationService;
xulihui's avatar
xulihui committed
52 53 54 55 56
    @Autowired
    private ITLpgGasBottleFilesService tLpgGasBottleFilesService;
    @Autowired
    private ITLpgAirChargeFilesService tLpgAirChargeFilesService;

xulihui's avatar
xulihui committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
    /**
     * 获取token
     * @return token
     * @throws Exception
     */
    public String getToken()throws Exception{
        String token = redisCache.getCacheObject("yhqToken");
        if(StringUtils.isEmpty(token)){
            token = getNewToken();
        }
        return token;
    }

    /**
     * 刷新token
     * @return token
     * @throws Exception
     */
    public String getNewToken()throws Exception{
        JSONObject param = new JSONObject();
xulihui's avatar
xulihui committed
77 78 79
        param.put("authCode", authCode);
        param.put("accessKey",accessKey);
        param.put("secretKey",secretKey);
xulihui's avatar
xulihui committed
80 81 82
        String result = HttpClientUtils.doPost(apiUrl+"/SyncDataApi/CreateToken",param.toJSONString(),null);
        if(StringUtils.isEmpty(result)) throw new CustomException("获取液化气token接口失败!");
        JSONObject resultJson = JSONObject.parseObject(result);
xulihui's avatar
xulihui committed
83 84 85 86
        redisCache.setCacheObject("yhqToken", resultJson.getJSONObject("result").getString("token"));
        String dateString = resultJson.getJSONObject("result").getString("expdate");
        Date date = DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", dateString);
        redisCache.setCacheObjectExpireAt("yhqToken", date);
xulihui's avatar
xulihui committed
87 88 89 90 91 92 93 94 95
        return  resultJson.getJSONObject("result").getString("token");
    }

    /**
     * 获取钢瓶档案
     * @return token
     * @throws Exception
     */
    public void getArchivesList()throws Exception{
xulihui's avatar
xulihui committed
96
        String token = getToken();
xulihui's avatar
xulihui committed
97
        JSONObject param = new JSONObject();
xulihui's avatar
xulihui committed
98 99 100 101 102 103 104 105 106 107 108
        param.put("maxReturnNum",100);

        PageHelper.startPage(1, 1, "f_gas_bottle_files_id desc");
        List<TLpgGasBottleFiles> selectUpTime = tLpgGasBottleFilesService.selectTLpgGasBottleFilesList(new TLpgGasBottleFiles());
        String lastRowVersion = "0";
        if(selectUpTime!=null && selectUpTime.size()>0){
            lastRowVersion = selectUpTime.get(0).getfRowVersion();
        }
        param.put("lastUpTime","");
        param.put("state",0);
        param.put("lastRowVersion",lastRowVersion);
xulihui's avatar
xulihui committed
109
        Map<String,Object> head = new HashMap<>();
xulihui's avatar
xulihui committed
110
        head.put("authorization","Bearer "+token);
xulihui's avatar
xulihui committed
111 112 113 114
        String result = HttpClientUtils.doPost(apiUrl+"/SyncDataApi/ArchivesList",param.toJSONString(),head);
        if(StringUtils.isEmpty(result)) throw new CustomException("获取钢瓶档案接口失败!");
        JSONObject json = JSONObject.parseObject(result);
        //结果入库
xulihui's avatar
xulihui committed
115 116 117
        if(null != json && "1".equals(json.getString("code")) && null != json.getJSONArray("result")){
            JSONArray data = json.getJSONArray("result");
            //List<TLpgGasBottleFiles> lpgGasBottleFilesList = new ArrayList<>();
xulihui's avatar
xulihui committed
118
            for(int i = 0; i < data.size(); i++){
xulihui's avatar
xulihui committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
                JSONObject jsonObject = data.getJSONObject(i);
                TLpgGasBottleFiles tLpgGasBottleFiles = new TLpgGasBottleFiles();
                tLpgGasBottleFiles.setfRegCode(jsonObject.getString("regCode"));
                tLpgGasBottleFiles.setfEquNo(jsonObject.getString("equNo"));
                tLpgGasBottleFiles.setfEquType(jsonObject.getString("equType"));
                tLpgGasBottleFiles.setfMedium(jsonObject.getString("medium"));
                tLpgGasBottleFiles.setfMakeDate(jsonObject.getDate("makeDate"));
                tLpgGasBottleFiles.setfMakeInfo(jsonObject.getString("makeInfo"));
                tLpgGasBottleFiles.setfSelfId(jsonObject.getString("selfId"));
                String pressure = jsonObject.getString("pressure");
                if (pressure != null && !pressure.isEmpty()) {
                    tLpgGasBottleFiles.setfPressure(new BigDecimal(pressure));
                } else {
                    tLpgGasBottleFiles.setfPressure(new BigDecimal(0));
                }
                String volume = jsonObject.getString("volume");
                if (volume != null && !volume.isEmpty()) {
                    tLpgGasBottleFiles.setfVolume(new BigDecimal(volume));
                } else {
                    tLpgGasBottleFiles.setfVolume(new BigDecimal(0));
                }
                tLpgGasBottleFiles.setfAppId(jsonObject.getString("appId"));
                tLpgGasBottleFiles.setfQRcode(jsonObject.getString("qRcode"));
                tLpgGasBottleFiles.setfBuildUser(jsonObject.getString("buildUser"));
                tLpgGasBottleFiles.setfAddTime(jsonObject.getDate("addtime"));
                tLpgGasBottleFiles.setfOptName(jsonObject.getString("optName"));
                tLpgGasBottleFiles.setfUpTime(jsonObject.getDate("uptime"));
                tLpgGasBottleFiles.setfState(jsonObject.getString("state"));
                tLpgGasBottleFiles.setfUpOptName(jsonObject.getString("upOptName"));
                tLpgGasBottleFiles.setfPChkDate(jsonObject.getDate("pChkDate"));
                tLpgGasBottleFiles.setfNChkDate(jsonObject.getDate("nChkDate"));
                tLpgGasBottleFiles.setfProductDate(jsonObject.getDate("productDate"));
                tLpgGasBottleFiles.setfDiscardDate(jsonObject.getDate("discardDate"));
                tLpgGasBottleFiles.setfSafeJudgeDate(jsonObject.getDate("safeJudgeDate"));
                String gpressure = jsonObject.getString("gpressure");
                if (gpressure != null && !gpressure.isEmpty()) {
                    tLpgGasBottleFiles.setfGPressure(new BigDecimal(gpressure));
                } else {
                    tLpgGasBottleFiles.setfGPressure(new BigDecimal(0));
                }
                String wpressure = jsonObject.getString("wpressure");
                if (wpressure != null && !wpressure.isEmpty()) {
                    tLpgGasBottleFiles.setfWPressure(new BigDecimal(wpressure));
                } else {
                    tLpgGasBottleFiles.setfWPressure(new BigDecimal(0));
                }
                String selfWeight = jsonObject.getString("selfWeight");
                if (selfWeight != null && !selfWeight.isEmpty()) {
                    tLpgGasBottleFiles.setfSelfWeight(new BigDecimal(selfWeight));
                } else {
                    tLpgGasBottleFiles.setfSelfWeight(new BigDecimal(0));
                }
                String thickness = jsonObject.getString("thickness");
                if (thickness != null && !thickness.isEmpty()) {
                    tLpgGasBottleFiles.setfThickness(new BigDecimal(thickness));
                } else {
                    tLpgGasBottleFiles.setfThickness(new BigDecimal(0));
                }
                tLpgGasBottleFiles.setfPermitNo(jsonObject.getString("permitNo"));
                tLpgGasBottleFiles.setfValveName(jsonObject.getString("valveTypeName"));
                tLpgGasBottleFiles.setfPayImage(jsonObject.getString("payImage"));
                tLpgGasBottleFiles.setfBatchImage(jsonObject.getString("batchImage"));
                tLpgGasBottleFiles.setfDeviceImage(jsonObject.getString("deviceImage"));
                tLpgGasBottleFiles.setfCheckImage(jsonObject.getString("checkImage"));
                tLpgGasBottleFiles.setfEquNoImage(jsonObject.getString("equNoImage"));
                tLpgGasBottleFiles.setfSelfIdImage(jsonObject.getString("selfIdImage"));
                tLpgGasBottleFiles.setfBotImage(jsonObject.getString("botImage"));
                tLpgGasBottleFiles.setfBotSpecName(jsonObject.getString("botSpecName"));
                tLpgGasBottleFiles.setfBottleType(jsonObject.getString("bottleType"));
                String inspectedTimes = jsonObject.getString("inspectedTimes");
                if (inspectedTimes != null && !inspectedTimes.isEmpty()) {
                    tLpgGasBottleFiles.setfInspectedTimes(Long.valueOf(inspectedTimes));
                } else {
                    tLpgGasBottleFiles.setfInspectedTimes(0L);
                }
                tLpgGasBottleFiles.setfIsSpecialized(jsonObject.getString("isSpecialized"));
                tLpgGasBottleFiles.setfValveManuFacturer(jsonObject.getString("valveManufacturer"));
                tLpgGasBottleFiles.setfInspectionLabel(jsonObject.getString("inspectionLabel"));
                tLpgGasBottleFiles.setfThirdPartyLabel(jsonObject.getString("thirdPartyLabel"));
                tLpgGasBottleFiles.setfHoleCode(jsonObject.getString("holeCode"));
                tLpgGasBottleFiles.setfBottleStorageType(jsonObject.getString("bottleStorageType"));
                tLpgGasBottleFiles.setfRowVersion(jsonObject.getString("rowVersion"));
                tLpgGasBottleFilesService.insertTLpgGasBottleFiles(tLpgGasBottleFiles);
            }
            if(data.size()==100){
                this.getArchivesList();
            }
        }
    }

    /**
     * 获取充装记录
     * @return token
     * @throws Exception
     */
    public void getFillingData()throws Exception{
        String token = getToken();
        JSONObject param = new JSONObject();
        //Integer pageIndex = 1;
        //Integer startNum = 0;
        Integer tLpgAirChargeFilesTotal = tLpgAirChargeFilesService.selectTLpgAirChargeFilesTotal();
        Integer pageIndex = tLpgAirChargeFilesTotal / 100 + 1;
        Integer startNum = tLpgAirChargeFilesTotal%100;
        param.put("pageIndex",pageIndex);
        param.put("pageSize",100);
        Map<String,Object> head = new HashMap<>();
        head.put("authorization","Bearer "+token);
        String result = HttpClientUtils.doPost(apiUrl+"/SyncDataApi/FillingData",param.toJSONString(),head);
        if(StringUtils.isEmpty(result)) throw new CustomException("获取充装记录接口失败!");
        JSONObject json = JSONObject.parseObject(result);
        //结果入库
        if(null != json && "1".equals(json.getString("code")) && null != json.getJSONArray("result")){
            JSONArray data = json.getJSONArray("result");
            for(int i = startNum; i < data.size(); i++){
                JSONObject jsonObject = data.getJSONObject(i);
                TLpgAirChargeFiles tLpgAirChargeFile = new TLpgAirChargeFiles();
                tLpgAirChargeFile.setfGzId(jsonObject.getLong("gzId"));
                tLpgAirChargeFile.setfStationName(jsonObject.getString("stationName"));
                tLpgAirChargeFile.setfBarCode(jsonObject.getString("barCode"));
                tLpgAirChargeFile.setfVaseCode(jsonObject.getString("vaseCode"));
                tLpgAirChargeFile.setfScaleNum(jsonObject.getString("scaleNum"));
                tLpgAirChargeFile.setfFillStatrTime(jsonObject.getString("fillStatrTime"));
                tLpgAirChargeFile.setfFillEndTime(jsonObject.getString("fillEndTime"));
                tLpgAirChargeFile.setfSetWeight(jsonObject.getString("setWeight"));
                tLpgAirChargeFile.setfWtNet(jsonObject.getString("wtNet"));
                tLpgAirChargeFile.setfSetBottleWeight(jsonObject.getString("setBottleWeight"));
                tLpgAirChargeFile.setfBottleWeight(jsonObject.getString("bottleWeight"));
                tLpgAirChargeFile.setfWtGross(jsonObject.getString("wtGross"));
                tLpgAirChargeFile.setfOprateName(jsonObject.getString("oprateName"));
                tLpgAirChargeFilesService.insertTLpgAirChargeFiles(tLpgAirChargeFile);
            }
            if(data.size()==100){
                this.getFillingData();
xulihui's avatar
xulihui committed
252
            }
xulihui's avatar
xulihui committed
253
            //List<TLpgGasBottleFiles> lpgGasBottleFilesList = new ArrayList<>();
xulihui's avatar
xulihui committed
254 255 256
        }
    }
}