一. 业务与图片关联
图片添加修改-数据库实体类增加字段图片id-------契约平台增加图片id和图片url字段,当查详情时组成图片url返回给前端
SlxfCombatPersonnelService
层
@Override
public TSlxfCombatPersonnel findPersonnel(String s) {
CombatPersonnel one = slxfCombatPersonnelRepository.findOne(s);
TSlxfCombatPersonnel convertor = generalConvertor.convertor(one, TSlxfCombatPersonnel.class);
/*
生成图片url
*/
List<UploaderFile> fileByBusinessType = erticleRepository.findFileByBusinessType(s);
List<CodeRecord> list = CodeInfoUtils.getCodeListByCodeDicId(SysEnum.QQSH.getCode());
if(CollectionUtils.isNotEmpty(fileByBusinessType)){
String url = list.get(0).getValue() + ErticleEnum.URL.getDesc() + fileByBusinessType.get(0).getId();
convertor.setPictureUrl(url);
}
return convertor;
}
@Override
public CombatPersonnel savePersonel(TSlxfCombatPersonnel tSlxfCombatPersonnel) {
List<Map<String,Object>> map = slxfCombatFaculyRepository.findSortNoByCode(tSlxfCombatPersonnel.getDept());
tSlxfCombatPersonnel.setSortNo(Integer.parseInt(map.get(0).get("SORT_NO").toString()));
// 默认排序字段为0
tSlxfCombatPersonnel.setSort(0);
CombatPersonnel convertor = generalConvertor.convertor(tSlxfCombatPersonnel, CombatPersonnel.class);
CombatPersonnel save = slxfCombatPersonnelRepository.save(convertor);
/**
* 将图片与业务关联
*/
//先删除业务与图片的关联,用于编辑操作
erticleRepository.updateDelFile(save.getId());
String pictureId = tSlxfCombatPersonnel.getPictureId();
erticleRepository.updateFile(save.getId(), CombatPersonnelEnum.RYBC_IMG.getCode(),pictureId);
return save;
}
与附件表相关的操作
/**
* 将业务与附件做关联
* @param
*/
@Modifying
@NativeQuery("UPDATE T_UPLOADER_FILE SET BUSINESS_ID = :businessId, BUSINESS_TYPE = :businessType WHERE ID = :fileId")
void updateFile(@Param("businessId") String businessId, @Param("businessType") String businessType, @Param("fileId") String fileId);
/**
* 删除业务与附件的关联
* @param
*/
@Modifying
@NativeQuery("UPDATE T_UPLOADER_FILE SET BUSINESS_ID = '', BUSINESS_TYPE = '' WHERE BUSINESS_ID = :businessId")
void updateDelFile(@Param("businessId") String businessId);
/**
* 根据业务类型获取业务附件
* @return
*/
@NativeQuery(value = "SELECT * from T_UPLOADER_FILE WHERE BUSINESS_ID =:businessId ORDER by GENERATE_TIME ASC")
List<UploaderFile> findFileByBusinessType(@Param("businessId") String businessId);
二. 异常处理
异常信息:
SQLSyntaxErrorException: ORA-01747: user.table.column, table.column 或列说明无效
解决:列名不能用关键字如number,level
异常信息:
MissingServletRequestParameterException: Required String parameter 's' is not present
解决:修改Controller参数名为id
三. 未登录如何测试接口
配置文件中添加,过滤登陆
duceap.security.dcuc.ignorePattern=/js/*|/img/*|/css/*|/dcuclogin/*|/authorizationPage.html|/importAuthorizationFile.html|/license/LicenseManagerServlet|/authorizationFile/|/v2/|/v1/home/|/v1/txry/|/v1/txzb/|/v1/dict/|/api/file/|/v1/
网友评论