Commit 17d65ad5 authored by 陈祥烨's avatar 陈祥烨

工具类创建

parent edf63ce7
......@@ -8,7 +8,6 @@ import com.yeejoin.amos.api.tool.face.model.TplVoModel;
import com.yeejoin.amos.api.tool.face.service.TplService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
......@@ -54,7 +53,7 @@ public class TplResource {
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@PutMapping(value = "/{sequenceNbr}")
@ApiOperation(httpMethod = "PUT", value = "根据sequenceNbr更新", notes = "根据sequenceNbr更新")
public ResponseModel<TplModel> updateBySequenceNbrTpl(@RequestBody TplVoModel tplVoModel, @PathVariable(value = "sequenceNbr") Long sequenceNbr) {
public ResponseModel<TplModel> updateBySequenceNbrTpl(@RequestBody TplVoModel tplVoModel, @PathVariable(value = "sequenceNbr") Long sequenceNbr) throws NoSuchFieldException, IllegalAccessException {
tplVoModel.setSequenceNbr(sequenceNbr);
tplVoModel.setDisplayName(tplVoModel.getComName());
TplModel tplModel = new TplModel();
......
......@@ -2,6 +2,7 @@ package com.yeejoin.amos.api.tool.face.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.yeejoin.amos.api.tool.face.util.PicUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......
......@@ -7,6 +7,7 @@ import com.yeejoin.amos.api.tool.face.model.TplModel;
import com.yeejoin.amos.api.tool.face.model.TplVoModel;
import com.yeejoin.amos.api.tool.face.orm.dao.TplMapper;
import com.yeejoin.amos.api.tool.face.orm.entity.Tpl;
import com.yeejoin.amos.api.tool.face.util.PicUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -56,14 +57,16 @@ public class TplService extends BaseService<TplModel, Tpl, TplMapper> {
/**
* TplVoModel转化TplModel
*/
public TplModel convertModel(TplVoModel tplVoModel, TplModel tplModel) {
public TplModel convertModel(TplVoModel tplVoModel, TplModel tplModel) throws NoSuchFieldException, IllegalAccessException {
BeanUtils.copyProperties(tplVoModel, tplModel, "thumbs", "sketches", "contentStr");
//判定thumbs为空
if (tplVoModel.getThumbs().size() != 0)
tplModel.setThumb(tplVoModel.getThumbs().get(0).getUrl());
//判定sketch为空
tplModel.setThumb(PicUtil.objectListToUrl(tplVoModel.getThumbs()));
// tplModel.setThumb(tplVoModel.getThumbs().get(0).getUrl());
// 判定sketch为空
if (tplVoModel.getSketches().size() != 0)
tplModel.setSketch(tplVoModel.getSketches().get(0).getUrl());
tplModel.setSketch(PicUtil.objectListToUrl(tplVoModel.getSketches()));
// tplModel.setSketch(tplVoModel.getSketches().get(0).getUrl());
tplModel.setContent(JSON.parseObject(tplVoModel.getContentStr()));
return tplModel;
}
......@@ -98,9 +101,10 @@ public class TplService extends BaseService<TplModel, Tpl, TplMapper> {
TplVoModel tplVoModel = new TplVoModel();
BeanUtils.copyProperties(tplModel, tplVoModel);
if(tplModel.getSketch() != null)
tplVoModel.setSketches(urlToPicModel(tplModel.getSketch()));
tplVoModel.setSketches(this.urlToPicModel(tplModel.getSketch()));
if (tplModel.getThumb() != null)
tplVoModel.setThumbs(urlToPicModel(tplModel.getThumb()));
tplVoModel.setThumbs(this.urlToPicModel(tplModel.getThumb()));
System.out.println(tplVoModel.getThumbs());
return tplVoModel;
}
......
package com.yeejoin.amos.api.tool.face.util;
import java.lang.reflect.Field;
import java.util.List;
public class PicUtil {
public static <Object> String objectListToUrl(List<Object> objectList) throws IllegalAccessException, NoSuchFieldException {
if (objectList.isEmpty()) {
return null;
}
System.out.println(objectList.get(0));
Class<?> cla = objectList.get(0).getClass();
Field field = cla.getDeclaredField("url");
field.setAccessible(true);
return field.get(objectList.get(0)).toString();
}
// public static List<Object> urlToObjectList(String url){
// List<Object> picUtils = new ArrayList<>();
// String uid= (int)((Math.random()*9+1)*100000)+"";
// PicUtil picUtil = new PicUtil("", uid, url, "done");
// picUtils.add(picUtil);
// return picUtils;
// }
}
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