|
@@ -1,6 +1,7 @@
|
|
|
package com.gis.service.impl;
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.gis.common.constant.ConfigConstant;
|
|
|
import com.gis.common.constant.MsgCode;
|
|
@@ -23,11 +24,13 @@ import com.gis.service.CatalogService;
|
|
|
import com.gis.service.SceneService;
|
|
|
import com.gis.service.WorkService;
|
|
|
import com.gis.tree.CatalogTreeUtil;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.http.HttpResponse;
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
+import org.junit.Test;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -35,6 +38,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.transaction.Transactional;
|
|
|
import java.io.IOException;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
@@ -49,7 +53,7 @@ import java.util.stream.Stream;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
-//@Transactional
|
|
|
+@Transactional
|
|
|
public class WorkServiceImpl extends IBaseServiceImpl<WorkEntity, Long> implements WorkService {
|
|
|
|
|
|
@Autowired
|
|
@@ -122,9 +126,16 @@ public class WorkServiceImpl extends IBaseServiceImpl<WorkEntity, Long> implemen
|
|
|
|
|
|
@Override
|
|
|
public Result<WorkEntity> entityAdd() {
|
|
|
+
|
|
|
+ // 删除无效作品数据
|
|
|
+ delByTime();
|
|
|
+
|
|
|
WorkEntity entity = new WorkEntity();
|
|
|
entity.setUserId(getUserNameForToken());
|
|
|
this.save(entity);
|
|
|
+ Long id = entity.getId();
|
|
|
+ log.info("创建对象完成: {}", id);
|
|
|
+
|
|
|
|
|
|
// 创建someData
|
|
|
// 如基someData作出修改,记得把代码里的someData 跟服务器里的someData都修改
|
|
@@ -143,7 +154,7 @@ public class WorkServiceImpl extends IBaseServiceImpl<WorkEntity, Long> implemen
|
|
|
}
|
|
|
|
|
|
|
|
|
- Long id = entity.getId();
|
|
|
+
|
|
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(content);
|
|
|
jsonObject.put("id", id + "");
|
|
@@ -168,6 +179,26 @@ public class WorkServiceImpl extends IBaseServiceImpl<WorkEntity, Long> implemen
|
|
|
return Result.success(entity);
|
|
|
}
|
|
|
|
|
|
+ // 删除无效作品数据
|
|
|
+ private void delByTime() {
|
|
|
+ // 定时删除空作品数据,周期:一个月清一次
|
|
|
+ if (!redisUtil.hasKey(RedisConstant.WORK_DEL)) {
|
|
|
+
|
|
|
+ String now = LocalDate.now().minusMonths(1).toString();
|
|
|
+ log.info("执行删除 {} 月份之前的空作品数据:{}", now);
|
|
|
+ entityMapper.delByTime(now);
|
|
|
+ redisUtil.set(RedisConstant.WORK_DEL, now, 30, TimeUnit.DAYS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void test1(){
|
|
|
+ LocalDate now = LocalDate.now();
|
|
|
+ log.info("now : {}", now);
|
|
|
+ log.info("now-m : {}", now.minusMonths(3));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public Result remove(Long id) {
|
|
@@ -246,6 +277,8 @@ public class WorkServiceImpl extends IBaseServiceImpl<WorkEntity, Long> implemen
|
|
|
|
|
|
@Override
|
|
|
public WorkEntity findByIdForUpdate(Long id) {
|
|
|
+ // 查询数据之前先清理分页缓存
|
|
|
+ PageHelper.clearPage();
|
|
|
return entityMapper.findByIdForUpdate(id);
|
|
|
}
|
|
|
|
|
@@ -309,7 +342,9 @@ public class WorkServiceImpl extends IBaseServiceImpl<WorkEntity, Long> implemen
|
|
|
entity.setQrCode(sd.getString("qrCode"));
|
|
|
entity.setStatus(sd.getInteger("status"));
|
|
|
entity.setPassword(sd.getString("password"));
|
|
|
- entity.setSceneCodes(sd.getString("scenes"));
|
|
|
+// entity.setSceneCodes(sd.getString("scenes"));
|
|
|
+ String scenes = sd.getString("scenes");
|
|
|
+ entity.setSceneCodes(getSceneCodes(scenes));
|
|
|
// 更新logoQrCode
|
|
|
Boolean logoChange = sd.getBoolean("logoChange");
|
|
|
String logoUrl = sd.getString("logo");
|
|
@@ -330,6 +365,26 @@ public class WorkServiceImpl extends IBaseServiceImpl<WorkEntity, Long> implemen
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 传入参数是一个数组json字符串
|
|
|
+ * @param param
|
|
|
+ */
|
|
|
+ private String getSceneCodes(String param){
|
|
|
+ JSONArray array = JSONArray.parseArray(param);
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ for (Object o : array) {
|
|
|
+ JSONObject parse = JSONObject.parseObject(o.toString());
|
|
|
+ String sceneCode = parse.getString("sceneCode");
|
|
|
+ list.add(sceneCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ String join = StringUtils.join(list, ",");
|
|
|
+
|
|
|
+ return join;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 更新二维码
|
|
|
*/
|
|
|
private Boolean updateQrCode(Long id, String logoUrl) {
|