Commit 815f37b4 by 111-PC\111

[+]swagger添加以及图片功能模块

1 parent 4f2b2053
...@@ -57,5 +57,11 @@ ...@@ -57,5 +57,11 @@
<version>${druid.version}</version> <version>${druid.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>rest-admin-swagger2</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file \ No newline at end of file
...@@ -18,7 +18,7 @@ import tk.mybatis.spring.annotation.MapperScan; ...@@ -18,7 +18,7 @@ import tk.mybatis.spring.annotation.MapperScan;
* @Copyright Copyright (c) 2015 * @Copyright Copyright (c) 2015
*/ */
@Slf4j @Slf4j
@SpringBootApplication @SpringBootApplication(scanBasePackages = {"com.glsx"})
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableTransactionManagement @EnableTransactionManagement
@ServletComponentScan @ServletComponentScan
......
package com.glsx.smart.controller; package com.glsx.smart.controller;
import com.glsx.smart.dao.entity.SmartSysFile; import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.core.web.R;
import com.glsx.smart.pojo.FileDTO;
import com.glsx.smart.service.SmartSysFileService; import com.glsx.smart.service.SmartSysFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/** /**
* <p>Description: * <p>Description:
...@@ -20,20 +26,38 @@ import org.springframework.web.multipart.MultipartFile; ...@@ -20,20 +26,38 @@ import org.springframework.web.multipart.MultipartFile;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/sysFile") @RequestMapping("/sysFile")
@Api(value = "图片管理", tags = {"图片管理"})
public class SysFileController { public class SysFileController {
@Autowired @Autowired
private SmartSysFileService sysFileService; private SmartSysFileService sysFileService;
@RequestMapping(value = "/uploadFile", method = {RequestMethod.POST}) @RequestMapping(value = "/findAll", method = {RequestMethod.GET})
public void uploadFile(@RequestPart(name = "file") MultipartFile file) { @ApiOperation(value = "查询图片")
public R findAll(@RequestParam("type") String type) {
List<FileDTO> fileDTOS = sysFileService.findByType(type);
return R.ok(JSONObject.toJSONString(fileDTOS));
}
@RequestMapping(value = "/saveFile", method = {RequestMethod.POST})
@ApiOperation(value = "保存图片")
public R saveFile(@RequestBody List<FileDTO> files) {
try {
sysFileService.saveFile(files);
} catch (Exception e) {
return R.error();
}
return R.ok();
} }
@RequestMapping(value = "/updateFile", method = {RequestMethod.POST}) @RequestMapping(value = "/updateFile", method = {RequestMethod.POST})
public void updateFile(SmartSysFile sysFile) { @ApiOperation(value = "更新图片")
// 实现流程: public R updateFile(@RequestBody FileDTO fileDTO) {
// 1、根据 sysFile.id 获取数据库原来的文件记录; try {
// 2、删除对应 url 的文件; sysFileService.updateFile(fileDTO);
// 3、更新传来的文件信息到数据库中。 } catch (Exception e) {
return R.error();
}
return R.ok();
} }
} }
...@@ -24,4 +24,6 @@ public interface SmartSysFileMapper extends tk.mybatis.mapper.common.Mapper<Smar ...@@ -24,4 +24,6 @@ public interface SmartSysFileMapper extends tk.mybatis.mapper.common.Mapper<Smar
int updateBatchSelective(List<SmartSysFile> list); int updateBatchSelective(List<SmartSysFile> list);
int batchInsert(@Param("list") List<SmartSysFile> list); int batchInsert(@Param("list") List<SmartSysFile> list);
List<SmartSysFile> findByType(String type);
} }
package com.glsx.smart.service; package com.glsx.smart.service;
import java.util.List; import java.util.List;
import com.glsx.smart.dao.entity.SmartSysFile; import com.glsx.smart.dao.entity.SmartSysFile;
import com.glsx.smart.pojo.FileDTO;
import org.springframework.web.multipart.MultipartFile;
/** /**
* <p>Description: * <p>Description:
...@@ -12,20 +15,12 @@ import com.glsx.smart.dao.entity.SmartSysFile; ...@@ -12,20 +15,12 @@ import com.glsx.smart.dao.entity.SmartSysFile;
*/ */
public interface SmartSysFileService { public interface SmartSysFileService {
int deleteByPrimaryKey(Long id);
int insertOrUpdate(SmartSysFile record); int insertOrUpdate(SmartSysFile record);
int insertSelective(SmartSysFile record); List<FileDTO> findByType(String type);
List<SmartSysFile> selectByExample(SmartSysFile example);
SmartSysFile selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(SmartSysFile record);
int updateBatchSelective(List<SmartSysFile> list);
int batchInsert(List<SmartSysFile> list); void saveFile(List<FileDTO> files);
void updateFile(FileDTO fileDTO);
} }
package com.glsx.smart.service.impl; package com.glsx.smart.service.impl;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import com.glsx.smart.dao.entity.SmartSysFile; import com.glsx.smart.dao.entity.SmartSysFile;
import com.glsx.smart.dao.mapper.SmartSysFileMapper; import com.glsx.smart.dao.mapper.SmartSysFileMapper;
import com.glsx.smart.exception.BusinessException; import com.glsx.smart.exception.BusinessException;
import com.glsx.smart.exception.ResultEnum; import com.glsx.smart.exception.ResultEnum;
import com.glsx.smart.pojo.FileDTO;
import com.glsx.smart.service.SmartSysFileService; import com.glsx.smart.service.SmartSysFileService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
/** /**
* <p>Description: * <p>Description:
...@@ -24,11 +30,6 @@ public class SmartSysFileServiceImpl implements SmartSysFileService { ...@@ -24,11 +30,6 @@ public class SmartSysFileServiceImpl implements SmartSysFileService {
private SmartSysFileMapper smartSysFileMapper; private SmartSysFileMapper smartSysFileMapper;
@Override @Override
public int deleteByPrimaryKey(Long id) {
return smartSysFileMapper.deleteByPrimaryKey(id);
}
@Override
public int insertOrUpdate(SmartSysFile sysFile) { public int insertOrUpdate(SmartSysFile sysFile) {
if (sysFile.getId() == null) { if (sysFile.getId() == null) {
return smartSysFileMapper.insertSelective(sysFile); return smartSysFileMapper.insertSelective(sysFile);
...@@ -43,34 +44,51 @@ public class SmartSysFileServiceImpl implements SmartSysFileService { ...@@ -43,34 +44,51 @@ public class SmartSysFileServiceImpl implements SmartSysFileService {
} }
} }
/**
* 查询图标列表
*
* @param type 文件类型
* @return
*/
@Override @Override
public int insertSelective(SmartSysFile record) { public List<FileDTO> findByType(String type) {
return smartSysFileMapper.insertSelective(record); List<SmartSysFile> list=smartSysFileMapper.findByType(type);
} List<FileDTO> fileDTOS = list.stream().map(index -> {
FileDTO fileDTO = new FileDTO();
@Override BeanUtils.copyProperties(index, fileDTO);
public List<SmartSysFile> selectByExample(SmartSysFile example) { return fileDTO;
return smartSysFileMapper.select(example); }).collect(Collectors.toList());
} return fileDTOS;
@Override
public SmartSysFile selectByPrimaryKey(Long id) {
return smartSysFileMapper.selectByPrimaryKey(id);
}
@Override
public int updateByPrimaryKeySelective(SmartSysFile record) {
return smartSysFileMapper.updateByPrimaryKeySelective(record);
} }
/**
* 保存图标
*
* @param files 文件集合
*/
@Override @Override
public int updateBatchSelective(List<SmartSysFile> list) { public void saveFile(List<FileDTO> files) {
return smartSysFileMapper.updateBatchSelective(list); List<SmartSysFile> list = files.stream().map(index -> {
SmartSysFile fileDTO = new SmartSysFile();
fileDTO.setCreateTime(new Date());
BeanUtils.copyProperties(index, fileDTO);
return fileDTO;
}).collect(Collectors.toList());
list.forEach(index->{
insertOrUpdate(index);
});
} }
/**
* 更新图标
*
* @param fileDTO 文件
*/
@Override @Override
public int batchInsert(List<SmartSysFile> list) { public void updateFile(FileDTO fileDTO) {
return smartSysFileMapper.batchInsert(list); SmartSysFile smartSysFile=new SmartSysFile();
BeanUtils.copyProperties(fileDTO,smartSysFile);
insertOrUpdate(smartSysFile);
} }
} }
...@@ -84,6 +84,12 @@ ...@@ -84,6 +84,12 @@
#{item.id,jdbcType=BIGINT} #{item.id,jdbcType=BIGINT}
</foreach> </foreach>
</update> </update>
<select id="findByType" resultType="com.glsx.smart.dao.entity.SmartSysFile">
SELECT * FROM smart_sys_file
<if test="type != null">
WHERE TYPE=#{TYPE}
</if>
</select>
<insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" <insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map"
useGeneratedKeys="true"> useGeneratedKeys="true">
<!--@mbg.generated--> <!--@mbg.generated-->
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!