Commit 24403eed authored by chenzhao's avatar chenzhao

bug 2849 已解决 附件保存到公共附件库

parent 9f417533
......@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yeejoin.amos.boot.biz.common.entity.BaseEntity;
import com.yeejoin.amos.boot.module.common.api.dto.AttachmentDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......@@ -12,6 +13,9 @@ import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 消防员思想谈话记录
*
......@@ -51,6 +55,10 @@ public class FirefightersThought extends BaseEntity {
@ApiModelProperty(value = "附件")
private String enclosure;
@ApiModelProperty(value = "附件")
@TableField(exist = false)
private Map<String, List<AttachmentDto>> attachments;
@ApiModelProperty(value = "更新时间")
@TableField(fill=FieldFill.UPDATE)
private Date updateTime;
......
package com.yeejoin.amos.boot.module.common.biz.controller;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import com.yeejoin.amos.boot.module.common.api.entity.SourceFile;
import com.yeejoin.amos.boot.module.common.biz.service.impl.SourceFileServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.foundation.utils.Bean;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
......@@ -52,6 +53,8 @@ public class FirefightersThoughtController extends BaseController {
FirefightersThoughtServiceImpl iFirefightersThoughtService;
@Autowired
RedisUtils redisUtils;
@Autowired
SourceFileServiceImpl sourceFileService;
@Value("${redis.cache.failure.time}")
private long time;
/**
......@@ -63,10 +66,13 @@ public class FirefightersThoughtController extends BaseController {
@ApiOperation(httpMethod = "POST", value = "新增消防员思想谈话记录", notes = "新增消防员思想谈话记录")
public ResponseModel<FirefightersThought> saveFirefightersThought(HttpServletRequest request, @RequestBody FirefightersThought firefightersThought){
iFirefightersThoughtService.save(firefightersThought);
if (!firefightersThought.getAttachments().isEmpty()){
sourceFileService.saveAttachments(firefightersThought.getSequenceNbr(),firefightersThought.getAttachments());
}
return ResponseHelper.buildResponse(firefightersThought);
}
/**
* 根据id删除
* @param id
......@@ -97,7 +103,12 @@ public class FirefightersThoughtController extends BaseController {
@RequestMapping(value = "/updateById", method = RequestMethod.PUT)
@ApiOperation(httpMethod = "PUT", value = "修改消防员思想谈话记录", notes = "修改消防员思想谈话记录")
public ResponseModel<FirefightersThought> updateByIdFirefightersThought(HttpServletRequest request, @RequestBody FirefightersThought firefightersThought){
if (!firefightersThought.getAttachments().isEmpty()){
sourceFileService.saveAttachments(firefightersThought.getSequenceNbr(),firefightersThought.getAttachments());
}
iFirefightersThoughtService.updateById(firefightersThought);
//删除缓存
redisUtils.del(RedisKey.THOUGHT_ID+firefightersThought.getSequenceNbr());
return ResponseHelper.buildResponse(firefightersThought);
......@@ -116,15 +127,21 @@ public class FirefightersThoughtController extends BaseController {
@ApiOperation(httpMethod = "GET", value = "根据消防员id查询", notes = "根据消防员id查询")
public ResponseModel<Object> selectById(HttpServletRequest request, @PathVariable Long id){
if(redisUtils.hasKey(RedisKey.THOUGHT_ID+id)){
Object obj= redisUtils.get(RedisKey.THOUGHT_ID+id);
return ResponseHelper.buildResponse(obj);
}else{
FirefightersThought firefightersThought= iFirefightersThoughtService.getById(id);
Map<String, Object> mainMap = Bean.BeantoMap(obj);
mainMap.put("attachments", sourceFileService.getAttachments(id));
return ResponseHelper.buildResponse(mainMap);
}else{ FirefightersThought firefightersThought= iFirefightersThoughtService.getById(id);
redisUtils.set(RedisKey.THOUGHT_ID+id, JSON.toJSON(firefightersThought),time);
return ResponseHelper.buildResponse(firefightersThought);
Map<String, Object> mainMap = Bean.BeantoMap(firefightersThought);
mainMap.put("attachments", sourceFileService.getAttachments(id));
return ResponseHelper.buildResponse(mainMap);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment