|
@@ -0,0 +1,118 @@
|
|
|
|
+package com.caimei.task;
|
|
|
|
+
|
|
|
|
+import com.caimei.mapper.cmMapper.AuthMapper;
|
|
|
|
+import com.caimei.mapper.ldmMapper.LdmMapper;
|
|
|
|
+import com.caimei.model.po.CmBrandAuthPo;
|
|
|
|
+import com.caimei.model.po.LdmDataPo;
|
|
|
|
+import com.caimei.service.auth.ShopService;
|
|
|
|
+import com.caimei.service.auth.UploadService;
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
|
+import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author Aslee
|
|
|
|
+ */
|
|
|
|
+@Slf4j
|
|
|
|
+@Configuration
|
|
|
|
+@EnableScheduling
|
|
|
|
+@RequiredArgsConstructor
|
|
|
|
+public class LdmTask {
|
|
|
|
+ @Resource
|
|
|
|
+ private AuthMapper authMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private LdmMapper ldmMapper;
|
|
|
|
+
|
|
|
|
+ private UploadService uploadService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ public void setUploadService(UploadService uploadService) {
|
|
|
|
+ this.uploadService = uploadService;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 定时读取ldm数据库机构数据,存入采美数据库中
|
|
|
|
+ */
|
|
|
|
+ @Scheduled(cron = "0 0/5 * * * ?")
|
|
|
|
+ public void readLdmData() {
|
|
|
|
+ AtomicReference<Integer> ldmLatestClubId = new AtomicReference<>(authMapper.getLdmLatestClubId());
|
|
|
|
+ List<LdmDataPo> ldmDataList = ldmMapper.getLdmClubData(ldmLatestClubId.get());
|
|
|
|
+ ldmDataList.forEach(ldmData->{
|
|
|
|
+ ldmLatestClubId.set(ldmData.getId());
|
|
|
|
+ String lngAndLat = ldmData.getLngAndLat();
|
|
|
|
+ if (StringUtils.isNotEmpty(lngAndLat)) {
|
|
|
|
+ String[] split = lngAndLat.split(",");
|
|
|
|
+ BigDecimal lat = new BigDecimal(split[0]);
|
|
|
|
+ BigDecimal lng = new BigDecimal(split[1]);
|
|
|
|
+ ldmData.setLng(lng);
|
|
|
|
+ ldmData.setLat(lat);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String regId1 = ldmData.getRegId1();
|
|
|
|
+ if (StringUtils.isNotEmpty(regId1)) {
|
|
|
|
+ Integer provinceId = authMapper.getProvinceId(regId1);
|
|
|
|
+ ldmData.setProvinceId(provinceId);
|
|
|
|
+ }
|
|
|
|
+ String regId2 = ldmData.getRegId2();
|
|
|
|
+ if (StringUtils.isNotEmpty(regId2)) {
|
|
|
|
+ Integer cityId = authMapper.getCityId(regId2);
|
|
|
|
+ ldmData.setCityId(cityId);
|
|
|
|
+ }
|
|
|
|
+ String regId3 = ldmData.getRegId3();
|
|
|
|
+ if (StringUtils.isNotEmpty(regId3)) {
|
|
|
|
+ Integer townId = authMapper.getTownId(regId3);
|
|
|
|
+ ldmData.setTownId(townId);
|
|
|
|
+ }
|
|
|
|
+ String pic1 = ldmData.getPic1();
|
|
|
|
+ String pic2 = ldmData.getPic2();
|
|
|
|
+ String pic3 = ldmData.getPic3();
|
|
|
|
+ String pic4 = ldmData.getPic4();
|
|
|
|
+ String pic5 = ldmData.getPic5();
|
|
|
|
+ List<String> picList = new ArrayList<>();
|
|
|
|
+ picList.add(pic1);
|
|
|
|
+ picList.add(pic2);
|
|
|
|
+ picList.add(pic3);
|
|
|
|
+ picList.add(pic4);
|
|
|
|
+ picList.add(pic5);
|
|
|
|
+ String logo = null;
|
|
|
|
+ List<String> addPicList = new ArrayList<>();
|
|
|
|
+ for (String pic : picList) {
|
|
|
|
+ if (StringUtils.isNotEmpty(pic)) {
|
|
|
|
+ try {
|
|
|
|
+ String imagePath = "https://wangdian.skinovachina.com" + pic;
|
|
|
|
+ String fileName = imagePath.substring(imagePath.lastIndexOf("/") + 1);
|
|
|
|
+ String imageUrl = uploadService.saveFileByUrl(imagePath, fileName);
|
|
|
|
+ addPicList.add(imageUrl);
|
|
|
|
+ if (null == logo) {
|
|
|
|
+ logo = imageUrl;
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ CmBrandAuthPo authPo = new CmBrandAuthPo();
|
|
|
|
+ BeanUtils.copyProperties(ldmData, authPo);
|
|
|
|
+ authPo.setAuthUserId(10);
|
|
|
|
+ authPo.setCreateBy(10);
|
|
|
|
+ authPo.setLogo(logo);
|
|
|
|
+ authMapper.insertAuth(authPo);
|
|
|
|
+ // 保存轮播图
|
|
|
|
+ if (addPicList.size() > 0) {
|
|
|
|
+ addPicList.forEach(banner -> authMapper.insertBanner(authPo.getId(), banner));
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ authMapper.updateLdmLatestClubId(ldmLatestClubId.get());
|
|
|
|
+ }
|
|
|
|
+}
|