fix bugs
This commit is contained in:
		
							parent
							
								
									61eb8584b9
								
							
						
					
					
						commit
						529ff2d723
					
				@ -17,7 +17,7 @@ public class SwaggerConfig {
 | 
			
		||||
    public Docket api() {
 | 
			
		||||
        return new Docket(DocumentationType.SWAGGER_2)
 | 
			
		||||
                .select()
 | 
			
		||||
                .apis(RequestHandlerSelectors.basePackage("com.progressivecoder.springbootmongodbsampleapp.controllers"))
 | 
			
		||||
                .apis(RequestHandlerSelectors.basePackage("com.example.survey.controller"))
 | 
			
		||||
                .paths(PathSelectors.any())
 | 
			
		||||
                .build();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -36,19 +36,19 @@ public class MetaDataController {
 | 
			
		||||
    public ResultVO listMetaData(
 | 
			
		||||
                                @RequestParam(value = "type",required = false) String type,
 | 
			
		||||
                                @RequestParam(value = "name",required = false) String name,
 | 
			
		||||
                                @RequestParam("currentPage")int currentPage,
 | 
			
		||||
                                @RequestParam(value = "currentPage",defaultValue = "0")int currentPage,
 | 
			
		||||
                                @RequestParam(value = "pageSize",defaultValue = "30")int pageSize){
 | 
			
		||||
 | 
			
		||||
        if (! EnumUtils.isValidEnum(MetaDataTypeEnum.class, type)) {
 | 
			
		||||
            ResultVO resultVO = new ResultVO(ResultEnum.NOT_EXIST_METADATA);
 | 
			
		||||
            resultVO.setMsg("元数据类型不存在");
 | 
			
		||||
            return resultVO;
 | 
			
		||||
        }
 | 
			
		||||
        // if (type != null && (! EnumUtils.isValidEnum(MetaDataTypeEnum.class, type))) {
 | 
			
		||||
        //     ResultVO resultVO = new ResultVO(ResultEnum.NOT_EXIST_METADATA);
 | 
			
		||||
        //     resultVO.setMsg("元数据类型不存在");
 | 
			
		||||
        //     return resultVO;
 | 
			
		||||
        // }
 | 
			
		||||
        Map<String, Object> resultMap = new HashMap<>(16,0.75F);
 | 
			
		||||
        resultMap.put("totalCount", metaDataService.countMetaData(name));
 | 
			
		||||
        resultMap.put("totalCount", metaDataService.countMetaData(name, type));
 | 
			
		||||
        resultMap.put("currentPage", currentPage);
 | 
			
		||||
        resultMap.put("pageSize", pageSize);
 | 
			
		||||
        resultMap.put("data", metaDataService.listMetaDataNameLimit(name, EnumUtils.getEnum(MetaDataTypeEnum.class, type) ,currentPage,pageSize));
 | 
			
		||||
        resultMap.put("data", metaDataService.listMetaDataNameLimit(name, type ,currentPage,pageSize));
 | 
			
		||||
 | 
			
		||||
        ResultVO resultVO = new ResultVO(ResultEnum.SUCCESS);
 | 
			
		||||
        resultVO.setData(resultMap);
 | 
			
		||||
 | 
			
		||||
@ -34,9 +34,9 @@ public class ProjectController {
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/projectList")
 | 
			
		||||
    public ResultVO getProject(@RequestParam(value = "name",required = false) String name,
 | 
			
		||||
                               @RequestParam(value = "date_gt", required = false) long date_gt,
 | 
			
		||||
                               @RequestParam(value = "date_lt", required = false) long date_lt,
 | 
			
		||||
                               @RequestParam(value = "currentPage") int currentPage,
 | 
			
		||||
                               @RequestParam(value = "date_gt", required = false, defaultValue = "0") long date_gt,
 | 
			
		||||
                               @RequestParam(value = "date_lt", required = false, defaultValue = "0") long date_lt,
 | 
			
		||||
                               @RequestParam(value = "currentPage", defaultValue = "0") int currentPage,
 | 
			
		||||
                               @RequestParam(value = "pageSize", defaultValue = "30") int pageSize) {
 | 
			
		||||
        Map<String, Object> resultMap = new HashMap<>(16,0.75F);
 | 
			
		||||
        resultMap.put("totalCount", projectService.countProject(name, date_gt, date_lt));
 | 
			
		||||
 | 
			
		||||
@ -41,7 +41,7 @@ public interface MetaDataDao {
 | 
			
		||||
     * @param pageSize 页大小
 | 
			
		||||
     * @return 元数据
 | 
			
		||||
     */
 | 
			
		||||
    List<MetaData> listMetaDataLimit(String name, MetaDataTypeEnum type,  int offset, int pageSize);
 | 
			
		||||
    List<MetaData> listMetaDataLimit(String name, String type,  int offset, int pageSize);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据元数据名查询数量
 | 
			
		||||
@ -49,7 +49,7 @@ public interface MetaDataDao {
 | 
			
		||||
     * @param name 元数据名
 | 
			
		||||
     * @return 数量
 | 
			
		||||
     */
 | 
			
		||||
    long countMetaData(String name);
 | 
			
		||||
    long countMetaData(String name, String type);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取所有元数据
 | 
			
		||||
 | 
			
		||||
@ -45,7 +45,7 @@ public class MetaDataDaoImpl implements MetaDataDao {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<MetaData> listMetaDataLimit(String name, MetaDataTypeEnum type, int offset, int pageSize) {
 | 
			
		||||
    public List<MetaData> listMetaDataLimit(String name, String type, int offset, int pageSize) {
 | 
			
		||||
        Criteria criteria = new Criteria();
 | 
			
		||||
        if (name != null) {
 | 
			
		||||
            criteria.and("name").regex(name);
 | 
			
		||||
@ -59,11 +59,14 @@ public class MetaDataDaoImpl implements MetaDataDao {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public long countMetaData(String name) {
 | 
			
		||||
    public long countMetaData(String name, String type) {
 | 
			
		||||
        Criteria criteria = new Criteria();
 | 
			
		||||
        if (name != null) {
 | 
			
		||||
            criteria.and("name").regex(name);
 | 
			
		||||
        }
 | 
			
		||||
        if (type != null) {
 | 
			
		||||
            criteria.and("type").is(type);
 | 
			
		||||
        }
 | 
			
		||||
        Query query = new Query(criteria);
 | 
			
		||||
        return mongoTemplate.count(query, MetaData.class);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -15,5 +15,5 @@ import java.util.Map;
 | 
			
		||||
public class CreateMetaDataDTO {
 | 
			
		||||
    private String name;
 | 
			
		||||
    private Map<String,Object> form;
 | 
			
		||||
    private MetaDataTypeEnum type;
 | 
			
		||||
    private String type;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -15,5 +15,5 @@ import java.util.Map;
 | 
			
		||||
public class ModifyMetaDataDTO {
 | 
			
		||||
    private String name;
 | 
			
		||||
    private Map<String,Object> form;
 | 
			
		||||
    private MetaDataTypeEnum type;
 | 
			
		||||
    private String type;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -28,7 +28,7 @@ public interface MetaDataService {
 | 
			
		||||
     * @param pageSize 页大小
 | 
			
		||||
     * @return 元数据名称
 | 
			
		||||
     */
 | 
			
		||||
    List<String> listMetaDataNameLimit(String name, MetaDataTypeEnum type, int currentPage, int pageSize);
 | 
			
		||||
    List<String> listMetaDataNameLimit(String name, String type, int currentPage, int pageSize);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 根据元数据名查询数量
 | 
			
		||||
@ -36,7 +36,7 @@ public interface MetaDataService {
 | 
			
		||||
     * @param name 元数据名
 | 
			
		||||
     * @return 数量
 | 
			
		||||
     */
 | 
			
		||||
    long countMetaData(String name);
 | 
			
		||||
    long countMetaData(String name, String type);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获取所有元数据名字的列表
 | 
			
		||||
@ -63,12 +63,4 @@ public interface MetaDataService {
 | 
			
		||||
     * @param deleteMetaDataDTO 删除信息
 | 
			
		||||
     */
 | 
			
		||||
    void deleteMetaData(DeleteMetaDataDTO deleteMetaDataDTO);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 给元数据绑定模板文件
 | 
			
		||||
     *
 | 
			
		||||
     * @param template 模板文件
 | 
			
		||||
     * @param name 元数据名
 | 
			
		||||
     */
 | 
			
		||||
    void bindWordTemplate(MultipartFile template, String name);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -44,7 +44,7 @@ public class MetaDataServiceImpl implements MetaDataService {
 | 
			
		||||
        MetaData metaData = new MetaData();
 | 
			
		||||
        metaData.setName(createMetaDataDTO.getName());
 | 
			
		||||
        metaData.setForm(createMetaDataDTO.getForm());
 | 
			
		||||
        
 | 
			
		||||
        metaData.setType(createMetaDataDTO.getType());
 | 
			
		||||
        // metaData.setFieldToNameList(createMetaDataDTO.getFieldToNameList());
 | 
			
		||||
        // metaData.setConfig(createMetaDataDTO.getConfig());
 | 
			
		||||
        // metaData.setWordTemplate(createMetaDataDTO.getWordTemplate());
 | 
			
		||||
@ -52,7 +52,7 @@ public class MetaDataServiceImpl implements MetaDataService {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<String> listMetaDataNameLimit(String name, MetaDataTypeEnum type, int currentPage, int pageSize) {
 | 
			
		||||
    public List<String> listMetaDataNameLimit(String name, String type, int currentPage, int pageSize) {
 | 
			
		||||
        List<MetaData> metaDataList = metaDataDao.listMetaDataLimit(name, type, currentPage * pageSize, pageSize);
 | 
			
		||||
        if (metaDataList == null) {
 | 
			
		||||
            return new ArrayList<>();
 | 
			
		||||
@ -63,8 +63,8 @@ public class MetaDataServiceImpl implements MetaDataService {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public long countMetaData(String name) {
 | 
			
		||||
        return metaDataDao.countMetaData(name);
 | 
			
		||||
    public long countMetaData(String name, String type) {
 | 
			
		||||
        return metaDataDao.countMetaData(name, type);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@ -79,6 +79,7 @@ public class MetaDataServiceImpl implements MetaDataService {
 | 
			
		||||
        }
 | 
			
		||||
        MetaData metaData = metaDataDao.selectMetaData(modifyMetaDataDTO.getName());
 | 
			
		||||
        metaData.setForm(modifyMetaDataDTO.getForm());
 | 
			
		||||
        metaData.setType(modifyMetaDataDTO.getType());
 | 
			
		||||
        // metaData.setFieldToNameList(modifyMetaDataDTO.getFieldToNameList());
 | 
			
		||||
        // metaData.setConfig(modifyMetaDataDTO.getConfig());
 | 
			
		||||
        metaDataDao.saveMetaData(metaData);
 | 
			
		||||
@ -95,50 +96,9 @@ public class MetaDataServiceImpl implements MetaDataService {
 | 
			
		||||
    @Override
 | 
			
		||||
    public void deleteMetaData(DeleteMetaDataDTO deleteMetaDataDTO) {
 | 
			
		||||
        if (!metaDataDao.existMetaData(deleteMetaDataDTO.getName())) {
 | 
			
		||||
            throw new MetaDataException(ResultEnum.ALREADY_EXIST_METADATA);
 | 
			
		||||
            throw new MetaDataException(ResultEnum.NOT_EXIST_METADATA);
 | 
			
		||||
        }
 | 
			
		||||
        metaDataDao.deleteMetaData(deleteMetaDataDTO.getName());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void bindWordTemplate(MultipartFile template, String name) {
 | 
			
		||||
        if (!metaDataDao.existMetaData(name)) {
 | 
			
		||||
            throw new MetaDataException(ResultEnum.ALREADY_EXIST_METADATA);
 | 
			
		||||
        }
 | 
			
		||||
        MetaData metaData = metaDataDao.selectMetaData(name);
 | 
			
		||||
 | 
			
		||||
        String filename = template.getOriginalFilename();
 | 
			
		||||
        String suffix = filename.substring(filename.lastIndexOf('.'));
 | 
			
		||||
        String newName = UUID.randomUUID().toString() + suffix;
 | 
			
		||||
        File newFile = new File(path + newName);
 | 
			
		||||
 | 
			
		||||
        OutputStream os = null;
 | 
			
		||||
        InputStream is = null;
 | 
			
		||||
 | 
			
		||||
        try {
 | 
			
		||||
            os = new FileOutputStream(newFile);
 | 
			
		||||
            is = template.getInputStream();
 | 
			
		||||
 | 
			
		||||
            byte[] buffer = new byte[1024];
 | 
			
		||||
            int len;
 | 
			
		||||
            while ((len = is.read(buffer)) != -1) {
 | 
			
		||||
                os.write(buffer, 0, len);
 | 
			
		||||
            }
 | 
			
		||||
        } catch (IOException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        } finally {
 | 
			
		||||
            try {
 | 
			
		||||
                if (os != null) {
 | 
			
		||||
                    os.close();
 | 
			
		||||
                }
 | 
			
		||||
                if (is != null) {
 | 
			
		||||
                    is.close();
 | 
			
		||||
                }
 | 
			
		||||
            } catch (IOException e) {
 | 
			
		||||
                e.printStackTrace();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        // metaData.setWordTemplate(path + newName);
 | 
			
		||||
        metaDataDao.saveMetaData(metaData);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -6,7 +6,7 @@ spring:
 | 
			
		||||
      auto-index-creation: true
 | 
			
		||||
      host: 8.136.133.77
 | 
			
		||||
      port: 27017
 | 
			
		||||
      database: survey
 | 
			
		||||
      database: dev
 | 
			
		||||
      username: cveo
 | 
			
		||||
      password: cveo123456
 | 
			
		||||
      authentication-database: admin
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user