Commit 770bf53b8b8a8fec44e5db489e98f5ee1d599b76
1 parent
8f5c3b7e
iss提交7:
1、添加使用personnel服务的controller,把原来的controller放入legacy包中 2、在dubbo消费者配置文件中配置personnel服务
Showing
3 changed files
with
183 additions
and
4 deletions
src/main/java/com/bsth/controller/schedule/basicinfo/EmployeeController_facade.java
0 → 100644
| 1 | +package com.bsth.controller.schedule.basicinfo; | ||
| 2 | + | ||
| 3 | +import com.alibaba.dubbo.config.annotation.Reference; | ||
| 4 | +import com.bsth.common.ResponseCode; | ||
| 5 | +import com.bsth.control_v2.plan_module.common.dto.baseinfo.PersonnelDto; | ||
| 6 | +import com.bsth.control_v2.plan_module.common.dto.sys.UserDto; | ||
| 7 | +import com.bsth.control_v2.plan_module.common.service.BServiceFacade; | ||
| 8 | +import com.bsth.control_v2.plan_module.common.service.baseinfo.PersonnelServiceFacade; | ||
| 9 | +import com.bsth.controller.schedule.BController_facade; | ||
| 10 | +import com.bsth.service.schedule.EmployeeService; | ||
| 11 | +import com.bsth.service.schedule.utils.DataToolsFile; | ||
| 12 | +import org.apache.commons.lang3.StringUtils; | ||
| 13 | +import org.apache.poi.ss.usermodel.Workbook; | ||
| 14 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 15 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 16 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
| 17 | +import org.springframework.web.bind.annotation.RequestParam; | ||
| 18 | +import org.springframework.web.bind.annotation.RestController; | ||
| 19 | +import org.springframework.web.multipart.MultipartFile; | ||
| 20 | + | ||
| 21 | +import javax.servlet.http.HttpServletResponse; | ||
| 22 | +import java.io.*; | ||
| 23 | +import java.util.*; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * 人员基础信息Controller_facade | ||
| 27 | + */ | ||
| 28 | +@RestController | ||
| 29 | +@RequestMapping("ee") | ||
| 30 | +public class EmployeeController_facade extends BController_facade<Integer, PersonnelDto> { | ||
| 31 | + @Override | ||
| 32 | + public void setCreateUserInfo(PersonnelDto personnelDto, Integer userId, Date createDate) { | ||
| 33 | + UserDto userDto = UserDto.getBuilder() | ||
| 34 | + .setId(userId) | ||
| 35 | + .build(); | ||
| 36 | + personnelDto.setCreateBy(userDto); | ||
| 37 | + personnelDto.setCreateDate(createDate); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + @Override | ||
| 41 | + public void setUpdateUserInfo(PersonnelDto personnelDto, Integer userId, Date updateDate) { | ||
| 42 | + UserDto userDto = UserDto.getBuilder() | ||
| 43 | + .setId(userId) | ||
| 44 | + .build(); | ||
| 45 | + personnelDto.setUpdateBy(userDto); | ||
| 46 | + personnelDto.setUpdateDate(updateDate); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + @Reference | ||
| 50 | + private PersonnelServiceFacade personnelServiceFacade; | ||
| 51 | + @Override | ||
| 52 | + protected BServiceFacade<Integer, PersonnelDto> getBServiceFacade() { | ||
| 53 | + return personnelServiceFacade; | ||
| 54 | + } | ||
| 55 | + @RequestMapping(value = "/validate_gh", method = RequestMethod.GET) | ||
| 56 | + public Map<String, Object> validate_gh(@RequestParam Map<String, Object> param) { | ||
| 57 | + Map<String, Object> rtn = new HashMap<>(); | ||
| 58 | + try { | ||
| 59 | + // 工号验证 | ||
| 60 | + PersonnelDto personnelDto = PersonnelDto.getBuilder() | ||
| 61 | + .setId(param.get("id_eq") == null ? | ||
| 62 | + null : Integer.valueOf(param.get("id_eq").toString())) | ||
| 63 | + .setCompanyCode(param.get("companyCode_eq") == null ? | ||
| 64 | + null : param.get("companyCode_eq").toString()) | ||
| 65 | + .setJobCode(param.get("jobCode_eq") == null ? | ||
| 66 | + null : param.get("jobCode_eq").toString()) | ||
| 67 | + .build(); | ||
| 68 | + this.personnelServiceFacade.validate_gh(personnelDto); | ||
| 69 | + rtn.put("status", ResponseCode.SUCCESS); | ||
| 70 | + } catch (Exception exp) { | ||
| 71 | + rtn.put("status", ResponseCode.ERROR); | ||
| 72 | + rtn.put("msg", exp.getMessage()); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + return rtn; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + //------------------ TODO:导入导出逻辑,之后会服务化 -----------------// | ||
| 79 | + @Autowired | ||
| 80 | + private EmployeeService employeeService; | ||
| 81 | + // 上传excel文件 | ||
| 82 | + @RequestMapping(value = "/uploadFile", method = RequestMethod.POST) | ||
| 83 | + public Map<String, Object> uploadFile(MultipartFile file) { | ||
| 84 | + Map<String, Object> rtn = new HashMap<>(); | ||
| 85 | + try { | ||
| 86 | + DataToolsFile dataToolsFile = employeeService.uploadFile(file.getOriginalFilename(), file.getBytes()); | ||
| 87 | + // excel文件名 | ||
| 88 | + String fileName = dataToolsFile.getFile().getAbsolutePath(); | ||
| 89 | + Workbook wb = dataToolsFile.getFileType().getWorkBook(dataToolsFile.getFile()); | ||
| 90 | + | ||
| 91 | + // excel文件sheet | ||
| 92 | + List<String> sheetnames = new ArrayList<>(); | ||
| 93 | + for (int i = 0; i < wb.getNumberOfSheets(); i ++) { | ||
| 94 | + sheetnames.add(wb.getSheetAt(i).getSheetName()); | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + wb.close(); | ||
| 98 | + | ||
| 99 | + rtn.put("status", ResponseCode.SUCCESS); | ||
| 100 | + rtn.put("filename", fileName); | ||
| 101 | + rtn.put("sheetnames", StringUtils.join(sheetnames, ",")); | ||
| 102 | + } catch (Exception exp) { | ||
| 103 | + exp.printStackTrace(); | ||
| 104 | + rtn.put("status", ResponseCode.ERROR); | ||
| 105 | + rtn.put("msg", exp.getMessage()); | ||
| 106 | + } | ||
| 107 | + return rtn; | ||
| 108 | + } | ||
| 109 | + // 导入excel文件 | ||
| 110 | + @RequestMapping(value = "/importFile", method = RequestMethod.POST) | ||
| 111 | + public Map<String, Object> importFile(@RequestParam Map<String, Object> params) { | ||
| 112 | + Map<String, Object> rtn = new HashMap<>(); | ||
| 113 | + | ||
| 114 | + try { | ||
| 115 | + File file = new File(String.valueOf(params.get("filename"))); | ||
| 116 | + if (!file.exists()) { | ||
| 117 | + throw new Exception("导入文件不存在!"); | ||
| 118 | + } | ||
| 119 | + employeeService.importData(file, params); | ||
| 120 | + | ||
| 121 | + rtn.put("status", ResponseCode.SUCCESS); | ||
| 122 | + rtn.put("msg", "导入文件成功"); | ||
| 123 | + } catch (Exception exp) { | ||
| 124 | + rtn.put("status", ResponseCode.ERROR); | ||
| 125 | + rtn.put("msg", exp.getMessage()); | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + return rtn; | ||
| 129 | + } | ||
| 130 | + // 上传并导入excel文件 | ||
| 131 | + @RequestMapping(value = "/uploadAndImportFile", method = RequestMethod.POST) | ||
| 132 | + public Map<String, Object> uploadAndImportFile(MultipartFile file) { | ||
| 133 | + Map<String, Object> rtn = new HashMap<>(); | ||
| 134 | + | ||
| 135 | + try { | ||
| 136 | + DataToolsFile dataToolsFile = employeeService.uploadFile(file.getOriginalFilename(), file.getBytes()); | ||
| 137 | + Map<String, Object> params = new HashMap<>(); | ||
| 138 | + employeeService.importData(dataToolsFile.getFile(), params); | ||
| 139 | + | ||
| 140 | + rtn.put("status", ResponseCode.SUCCESS); | ||
| 141 | + rtn.put("msg", "上传&导入文件成功"); | ||
| 142 | + } catch (Exception exp) { | ||
| 143 | + exp.printStackTrace(); | ||
| 144 | + rtn.put("status", ResponseCode.ERROR); | ||
| 145 | + rtn.put("msg", exp.getMessage()); | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + return rtn; | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + // 导出数据到xls文件 | ||
| 152 | + @RequestMapping(value = "/exportFile", method = RequestMethod.GET) | ||
| 153 | + public void exportFile(HttpServletResponse response, | ||
| 154 | + @RequestParam Map<String, Object> params) throws Exception { | ||
| 155 | + DataToolsFile dataToolsFile = employeeService.exportData(params); | ||
| 156 | + // 流输出导出文件 | ||
| 157 | + response.setHeader("content-type", "application/octet-stream"); | ||
| 158 | + response.setHeader("Content-Disposition", "attachment; filename=" + dataToolsFile.getFile().getName()); | ||
| 159 | + response.setContentType("application/octet-stream"); | ||
| 160 | + | ||
| 161 | + OutputStream os = response.getOutputStream(); | ||
| 162 | + BufferedOutputStream bos = new BufferedOutputStream(os); | ||
| 163 | + | ||
| 164 | + InputStream is = new FileInputStream(dataToolsFile.getFile()); | ||
| 165 | + BufferedInputStream bis = new BufferedInputStream(is); | ||
| 166 | + | ||
| 167 | + int length = 0; | ||
| 168 | + byte[] temp = new byte[1 * 1024 * 10]; | ||
| 169 | + while ((length = bis.read(temp)) != -1) { | ||
| 170 | + bos.write(temp, 0, length); | ||
| 171 | + } | ||
| 172 | + bos.flush(); | ||
| 173 | + bis.close(); | ||
| 174 | + bos.close(); | ||
| 175 | + is.close(); | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | +} |
src/main/java/com/bsth/controller/schedule/basicinfo/EmployeeController.java renamed to src/main/java/com/bsth/controller/schedule/basicinfo/legacy/EmployeeController.java
| 1 | -package com.bsth.controller.schedule.basicinfo; | 1 | +package com.bsth.controller.schedule.basicinfo.legacy; |
| 2 | 2 | ||
| 3 | import com.bsth.common.ResponseCode; | 3 | import com.bsth.common.ResponseCode; |
| 4 | import com.bsth.controller.schedule.BController; | 4 | import com.bsth.controller.schedule.BController; |
| @@ -9,7 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -9,7 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
| 9 | import org.springframework.web.bind.annotation.RequestMapping; | 9 | import org.springframework.web.bind.annotation.RequestMapping; |
| 10 | import org.springframework.web.bind.annotation.RequestMethod; | 10 | import org.springframework.web.bind.annotation.RequestMethod; |
| 11 | import org.springframework.web.bind.annotation.RequestParam; | 11 | import org.springframework.web.bind.annotation.RequestParam; |
| 12 | -import org.springframework.web.bind.annotation.RestController; | ||
| 13 | 12 | ||
| 14 | import java.util.HashMap; | 13 | import java.util.HashMap; |
| 15 | import java.util.Map; | 14 | import java.util.Map; |
| @@ -17,8 +16,8 @@ import java.util.Map; | @@ -17,8 +16,8 @@ import java.util.Map; | ||
| 17 | /** | 16 | /** |
| 18 | * 人员基础信息Controller | 17 | * 人员基础信息Controller |
| 19 | */ | 18 | */ |
| 20 | -@RestController | ||
| 21 | -@RequestMapping("ee") | 19 | +//@RestController |
| 20 | +//@RequestMapping("ee") | ||
| 22 | public class EmployeeController extends BController<Personnel, Integer> { | 21 | public class EmployeeController extends BController<Personnel, Integer> { |
| 23 | @Autowired | 22 | @Autowired |
| 24 | private EmployeeService employeeService; | 23 | private EmployeeService employeeService; |
src/main/resources/dubbo/applicationContext_dubbo_consumer.xml
| @@ -12,6 +12,8 @@ | @@ -12,6 +12,8 @@ | ||
| 12 | <!-- 注册中心地址 --> | 12 | <!-- 注册中心地址 --> |
| 13 | <dubbo:registry protocol="zookeeper" address="127.0.0.1:2181" check="false" /> | 13 | <dubbo:registry protocol="zookeeper" address="127.0.0.1:2181" check="false" /> |
| 14 | 14 | ||
| 15 | + <!-- 人员信息服务 --> | ||
| 16 | + <dubbo:reference interface="com.bsth.control_v2.plan_module.common.service.baseinfo.PersonnelServiceFacade" id="personnelServiceFacadeImpl" check="false" /> | ||
| 15 | <!-- 车辆信息服务 --> | 17 | <!-- 车辆信息服务 --> |
| 16 | <dubbo:reference interface="com.bsth.control_v2.plan_module.common.service.baseinfo.CarServiceFacade" id="carServiceFacadeImpl" check="false" /> | 18 | <dubbo:reference interface="com.bsth.control_v2.plan_module.common.service.baseinfo.CarServiceFacade" id="carServiceFacadeImpl" check="false" /> |
| 17 | <!-- 车辆设备信息服务 --> | 19 | <!-- 车辆设备信息服务 --> |