diff --git a/Sqlitedb/training.db b/Sqlitedb/training.db index 5607e4c..1646f25 100644 Binary files a/Sqlitedb/training.db and b/Sqlitedb/training.db differ diff --git a/src/main/java/com/jingcheng/cms/conf/WebMvcConfig.java b/src/main/java/com/jingcheng/cms/conf/WebMvcConfig.java index 21c98e9..e770912 100644 --- a/src/main/java/com/jingcheng/cms/conf/WebMvcConfig.java +++ b/src/main/java/com/jingcheng/cms/conf/WebMvcConfig.java @@ -1,56 +1,77 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014-2016 abel533@gmail.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ -package com.jingcheng.archives.config; +package com.jingcheng.cms.conf; +import com.jingcheng.cms.constants.AppConstant; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.servlet.MultipartConfigFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.StringHttpMessageConverter; -import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; -import java.nio.charset.Charset; -import java.util.List; +import javax.servlet.MultipartConfigElement; /** - * 配置中文支持 - * * @author + * @since 2015-12-19 16:16 */ @Configuration -public class WebMvcConfig extends WebMvcConfigurationSupport { +public class WebMvcConfig extends WebMvcConfigurerAdapter { + @Value("${oss.maxFileSize}") + private String maxFileSize; + @Value("${oss.maxRequestSize}") + private String maxRequestSize; - - //解决跨域问题 @Override - public void addCorsMappings(CorsRegistry registry) { + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/js/**").addResourceLocations("classpath:/js/"); + registry.addResourceHandler("swagger-ui.html") + .addResourceLocations("classpath:/META-INF/resources/"); + registry.addResourceHandler("/webjars/**") + .addResourceLocations("classpath:/META-INF/resources/webjars/"); + registry.addResourceHandler(AppConstant.FILE_MAP) + .addResourceLocations("file:" + AppConstant.FILE_PATH); - registry.addMapping("/**") - .allowedOrigins("*") - .allowCredentials(true) - .allowedMethods("GET", "POST", "DELETE", "PUT") - .maxAge(3600); + super.addResourceHandlers(registry); } - + /** + * 文件上传配置 + * + * @return + */ @Bean - public HttpMessageConverter responseBodyConverter() { - StringHttpMessageConverter converter = new StringHttpMessageConverter( - Charset.forName("UTF-8")); - return converter; + public MultipartConfigElement multipartConfigElement() { + MultipartConfigFactory factory = new MultipartConfigFactory(); + // 单个数据大小 + factory.setMaxFileSize(maxFileSize); + /// 总上传数据大小 + factory.setMaxRequestSize(maxRequestSize); + return factory.createMultipartConfig(); } - @Override - public void configureMessageConverters(List> converters) { - super.configureMessageConverters(converters); - converters.add(responseBodyConverter()); - } - - //WebMvcConfigurer时,将springboot的默认配置覆盖,默认配置中配置过资源解析,所以访问不到swagger - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); - registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); - } } diff --git a/src/main/java/com/jingcheng/cms/controller/EmployeeController.java b/src/main/java/com/jingcheng/cms/controller/EmployeeController.java index 7b56ff2..2f07c4f 100644 --- a/src/main/java/com/jingcheng/cms/controller/EmployeeController.java +++ b/src/main/java/com/jingcheng/cms/controller/EmployeeController.java @@ -3,6 +3,7 @@ package com.jingcheng.cms.controller; import com.alibaba.fastjson.JSONObject; import com.jingcheng.cms.service.EmployeeService; import com.jingcheng.cms.beans.AjaxResult; +import com.jingcheng.cms.util.DateUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -12,6 +13,8 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.IOException; @RestController @RequestMapping("/api/employee") @@ -116,4 +119,32 @@ public class EmployeeController { ajaxResult= employeeService.delEmployee(id); return ajaxResult; } + + /** + * 文件保存本地 + * @param file + * @throws IOException + */ + @RequestMapping(value="/uploadImage", produces = "text/html;charset=UTF-8") + public String uploadImage(MultipartFile file) throws IOException { + if (file.isEmpty()) { + System.out.println("没文件"); + } + //文件名称 + String realFileName = file.getOriginalFilename(); + String path = System.getProperty("user.dir")+ "\\upload\\"; + //检查该路径对应的目录是否存在. 如果不存在则创建目录 + File dir=new File(path); + if (!dir.exists()) { + dir.mkdirs(); + } + String filePath = path + realFileName; + System.out.println("filePath: "+filePath); + //保存文件 + File dest = new File(filePath); + if (!(dest.exists())) { + file.transferTo(dest); + } + return "http://localhost:8888/upload/" + realFileName; + } } diff --git a/src/main/java/com/jingcheng/cms/service/impl/EmployeeServiceImpl.java b/src/main/java/com/jingcheng/cms/service/impl/EmployeeServiceImpl.java index cd201e0..9bbe06e 100644 --- a/src/main/java/com/jingcheng/cms/service/impl/EmployeeServiceImpl.java +++ b/src/main/java/com/jingcheng/cms/service/impl/EmployeeServiceImpl.java @@ -298,6 +298,13 @@ public class EmployeeServiceImpl implements EmployeeService { if (infoSettingValuesFilter.size() > 0) { employee.setPtqId(infoSettingValuesFilter.get(0).getId()); } + } else { + employee.setPtq("无"); + List infoSettingValues = infoSettingValueService.getAllInfoSettingValueBySettingName("专业技术资格"); + List infoSettingValuesFilter = infoSettingValues.stream().filter(item -> item.getSettingValue().equals(employee.getPtq())).collect(Collectors.toList()); + if (infoSettingValuesFilter.size() > 0) { + employee.setPtqId(infoSettingValuesFilter.get(0).getId()); + } } //技能等级 if (StringUtils.isNotEmpty(employee.getSkillLevel())) { @@ -306,6 +313,13 @@ public class EmployeeServiceImpl implements EmployeeService { if (infoSettingValuesFilter.size() > 0) { employee.setSkillLevelId(infoSettingValuesFilter.get(0).getId()); } + } else { + employee.setSkillLevel("无"); + List infoSettingValues = infoSettingValueService.getAllInfoSettingValueBySettingName("技能等级"); + List infoSettingValuesFilter = infoSettingValues.stream().filter(item -> item.getSettingValue().equals(employee.getSkillLevel())).collect(Collectors.toList()); + if (infoSettingValuesFilter.size() > 0) { + employee.setSkillLevelId(infoSettingValuesFilter.get(0).getId()); + } } //学历 if (StringUtils.isNotEmpty(employee.getHighestEducation())) {