parent
7f380994a4
commit
e88b3ed481
@ -0,0 +1,142 @@ |
|||||||
|
package com.hai.schedule; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray; |
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import com.hai.common.exception.ErrorCode; |
||||||
|
import com.hai.common.exception.ErrorHelp; |
||||||
|
import com.hai.common.exception.SysCode; |
||||||
|
import com.hai.config.TuanYouConfig; |
||||||
|
import com.hai.entity.HighGasOilPrice; |
||||||
|
import com.hai.entity.HighMerchantStore; |
||||||
|
import com.hai.model.HighMerchantModel; |
||||||
|
import com.hai.model.HighMerchantStoreModel; |
||||||
|
import com.hai.service.HighGasOilPriceService; |
||||||
|
import com.hai.service.HighMerchantService; |
||||||
|
import com.hai.service.HighMerchantStoreService; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.beans.BeanUtils; |
||||||
|
import org.springframework.context.annotation.Configuration; |
||||||
|
import org.springframework.scheduling.annotation.Scheduled; |
||||||
|
|
||||||
|
import javax.annotation.Resource; |
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
@Configuration |
||||||
|
public class HighGasSchedule { |
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(HighGasSchedule.class); |
||||||
|
|
||||||
|
@Resource |
||||||
|
private HighMerchantService highMerchantService; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private HighMerchantStoreService highMerchantStoreService; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private HighGasOilPriceService highGasOilPriceService; |
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 1 * * ?") //每日凌晨1点执行一次
|
||||||
|
public void certification() throws Exception { |
||||||
|
HighMerchantModel merchant = highMerchantService.getMerchantById(39L); |
||||||
|
if (merchant == null) { |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到商户"); |
||||||
|
} |
||||||
|
JSONObject jsonObjectP = TuanYouConfig.queryGasInfoListByPage(1, 1000); |
||||||
|
JSONObject resultObjectP = jsonObjectP.getObject("result", JSONObject.class); |
||||||
|
|
||||||
|
for (int i = 1; i < resultObjectP.getInteger("totalPageNum").intValue();i++) { |
||||||
|
JSONObject jsonObject = TuanYouConfig.queryGasInfoListByPage(i, 1000); |
||||||
|
JSONObject resultObject = jsonObject.getObject("result", JSONObject.class); |
||||||
|
JSONArray jsonArray = resultObject.getJSONArray("gasInfoList"); |
||||||
|
HighMerchantStore highMerchantStore; |
||||||
|
HighGasOilPrice highGasOilPrice; |
||||||
|
for (Object gasObject : jsonArray) { |
||||||
|
JSONObject object = JSONObject.parseObject(JSONObject.toJSONString(gasObject)); |
||||||
|
HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreByKey(object.getString("gasId")); |
||||||
|
if (store != null) { |
||||||
|
store.setType(1); |
||||||
|
store.setMerchantId(merchant.getId()); |
||||||
|
store.setCompanyId(merchant.getCompanyId()); |
||||||
|
store.setStoreKey(object.getString("gasId")); |
||||||
|
store.setStoreName(object.getString("gasName")); |
||||||
|
store.setStoreLogo(object.getString("gasLogoSmall")); |
||||||
|
store.setRegionId(object.getLong("provinceCode")); |
||||||
|
store.setRegionName(object.getString("provinceName")); |
||||||
|
store.setAddress(object.getString("gasAddress")); |
||||||
|
store.setLongitude(object.getString("gasAddressLongitude")); |
||||||
|
store.setLatitude(object.getString("gasAddressLatitude")); |
||||||
|
store.setOperatorId(0L); |
||||||
|
store.setOperatorName("系统创建"); |
||||||
|
store.setUpdateTime(new Date()); |
||||||
|
store.setExt1(object.getString("gasSourceId")); |
||||||
|
highMerchantStoreService.updateMerchantStoreDetail(store); |
||||||
|
|
||||||
|
JSONArray oilPriceList = object.getJSONArray("oilPriceList"); |
||||||
|
for (Object oilPrice : oilPriceList) { |
||||||
|
JSONObject oilPriceObject = JSONObject.parseObject(JSONObject.toJSONString(oilPrice)); |
||||||
|
// 查询门店油号
|
||||||
|
highGasOilPrice = highGasOilPriceService.getGasOilPriceByStoreAndOilNo(store.getId(), oilPriceObject.getInteger("oilNo")); |
||||||
|
if (highGasOilPrice == null) { |
||||||
|
highGasOilPrice.setMerchantStoreId(store.getId()); |
||||||
|
highGasOilPrice.setOilNo(oilPriceObject.getInteger("oilNo")); |
||||||
|
highGasOilPrice.setOilNoName(oilPriceObject.getString("oilNoName")); |
||||||
|
highGasOilPrice.setPriceVip(oilPriceObject.getBigDecimal("priceVip")); |
||||||
|
highGasOilPrice.setPriceGun(oilPriceObject.getBigDecimal("priceGun")); |
||||||
|
highGasOilPrice.setPriceOfficial(oilPriceObject.getBigDecimal("priceOfficial")); |
||||||
|
highGasOilPrice.setOilType(oilPriceObject.getInteger("oilType")); |
||||||
|
highGasOilPrice.setOilTypeName(oilPriceObject.getString("oilTypeName")); |
||||||
|
} else { |
||||||
|
highGasOilPrice.setMerchantStoreId(store.getId()); |
||||||
|
highGasOilPrice.setOilNo(oilPriceObject.getInteger("oilNo")); |
||||||
|
highGasOilPrice.setOilNoName(oilPriceObject.getString("oilNoName")); |
||||||
|
highGasOilPrice.setPriceVip(oilPriceObject.getBigDecimal("priceVip")); |
||||||
|
highGasOilPrice.setPriceGun(oilPriceObject.getBigDecimal("priceGun")); |
||||||
|
highGasOilPrice.setPriceOfficial(oilPriceObject.getBigDecimal("priceOfficial")); |
||||||
|
highGasOilPrice.setOilType(oilPriceObject.getInteger("oilType")); |
||||||
|
highGasOilPrice.setOilTypeName(oilPriceObject.getString("oilTypeName")); |
||||||
|
} |
||||||
|
highGasOilPriceService.editGasOilPrice(highGasOilPrice); |
||||||
|
} |
||||||
|
} else { |
||||||
|
highMerchantStore = new HighMerchantStore(); |
||||||
|
highMerchantStore.setType(1); |
||||||
|
highMerchantStore.setMerchantId(merchant.getId()); |
||||||
|
highMerchantStore.setCompanyId(merchant.getCompanyId()); |
||||||
|
highMerchantStore.setStoreKey(object.getString("gasId")); |
||||||
|
highMerchantStore.setStoreName(object.getString("gasName")); |
||||||
|
highMerchantStore.setStoreLogo(object.getString("gasLogoSmall")); |
||||||
|
highMerchantStore.setRegionId(object.getLong("provinceCode")); |
||||||
|
highMerchantStore.setRegionName(object.getString("provinceName")); |
||||||
|
highMerchantStore.setAddress(object.getString("gasAddress")); |
||||||
|
highMerchantStore.setLongitude(object.getString("gasAddressLongitude")); |
||||||
|
highMerchantStore.setLatitude(object.getString("gasAddressLatitude")); |
||||||
|
highMerchantStore.setStatus(1); |
||||||
|
highMerchantStore.setOperatorId(0L); |
||||||
|
highMerchantStore.setOperatorName("系统创建"); |
||||||
|
highMerchantStore.setCreateTime(new Date()); |
||||||
|
highMerchantStore.setUpdateTime(new Date()); |
||||||
|
highMerchantStore.setExt1(object.getString("gasSourceId")); |
||||||
|
HighMerchantStoreModel merchantStoreModel = new HighMerchantStoreModel(); |
||||||
|
BeanUtils.copyProperties(highMerchantStore, merchantStoreModel); |
||||||
|
highMerchantStoreService.insertMerchantStore(merchantStoreModel); |
||||||
|
|
||||||
|
JSONArray oilPriceList = object.getJSONArray("oilPriceList"); |
||||||
|
for (Object oilPrice : oilPriceList) { |
||||||
|
JSONObject oilPriceObject = JSONObject.parseObject(JSONObject.toJSONString(oilPrice)); |
||||||
|
highGasOilPrice = new HighGasOilPrice(); |
||||||
|
highGasOilPrice.setMerchantStoreId(merchantStoreModel.getId()); |
||||||
|
highGasOilPrice.setOilNo(oilPriceObject.getInteger("oilNo")); |
||||||
|
highGasOilPrice.setOilNoName(oilPriceObject.getString("oilNoName")); |
||||||
|
highGasOilPrice.setPriceVip(oilPriceObject.getBigDecimal("priceVip")); |
||||||
|
highGasOilPrice.setPriceGun(oilPriceObject.getBigDecimal("priceGun")); |
||||||
|
highGasOilPrice.setPriceOfficial(oilPriceObject.getBigDecimal("priceOfficial")); |
||||||
|
highGasOilPrice.setOilType(oilPriceObject.getInteger("oilType")); |
||||||
|
highGasOilPrice.setOilTypeName(oilPriceObject.getString("oilTypeName")); |
||||||
|
highGasOilPriceService.editGasOilPrice(highGasOilPrice); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue