|
@@ -9,11 +9,14 @@ import com.imed.costaccount.common.exception.CostException;
|
|
|
import com.imed.costaccount.common.util.Result;
|
|
|
import com.imed.costaccount.model.User;
|
|
|
import com.imed.costaccount.service.UserService;
|
|
|
+import com.imed.costaccount.service.impl.DepartmentServiceImpl;
|
|
|
+import com.imed.costaccount.service.impl.ProductServiceImpl;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
@@ -37,12 +40,18 @@ public class ExcelController {
|
|
|
|
|
|
private UserService userService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private DepartmentServiceImpl departmentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductServiceImpl productService;
|
|
|
+
|
|
|
public ExcelController(UserService userService) {
|
|
|
this.userService = userService;
|
|
|
}
|
|
|
|
|
|
@ApiOperation("用户导出模板设置")
|
|
|
- @GetMapping("/getImportUserTemplate")
|
|
|
+ @GetMapping("/getcurrentTemplate")
|
|
|
public void getImportUserTemplate(HttpServletResponse response) throws IOException {
|
|
|
User user = (User) SecurityUtils.getSubject().getPrincipal();
|
|
|
// TODO: 2021/7/26 暂时没有登录
|
|
@@ -89,6 +98,116 @@ public class ExcelController {
|
|
|
throw new CostException(500, "导入失败");
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 科室模板导出功能设置
|
|
|
+ */
|
|
|
+ @ApiOperation("科室导出模板设置")
|
|
|
+ @GetMapping("/getDepartmentTemplate")
|
|
|
+ public void getImportDepartmentTemplate(HttpServletResponse response) throws IOException {
|
|
|
+ User user = (User) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ String uuid = UUID.randomUUID().toString();
|
|
|
+ String url = System.getProperty("java.io.tmpdir") + File.separator + uuid + File.separator + uuid + ".xls";
|
|
|
+ FileUtil.del(FileUtil.file(url));
|
|
|
+
|
|
|
+ ExcelWriter writer = new ExcelWriter(url);
|
|
|
+ // 样式
|
|
|
+ Sheet sheet = writer.getSheet();
|
|
|
+ // 内容
|
|
|
+ writer.merge(0, 1, 0, 2, "为了保证成功导入,请勿修改模板格式", false);
|
|
|
+ writer.passCurrentRow();
|
|
|
+ writer.passCurrentRow();
|
|
|
+ writer.merge(2, 2, 0, 2, "医院科室批量导入", false);
|
|
|
+ writer.passCurrentRow();
|
|
|
+ writer.setColumnWidth(0,20);
|
|
|
+ writer.setColumnWidth(1,15);
|
|
|
+ writer.setColumnWidth(2,15);
|
|
|
+ writer.writeRow(Arrays.asList("院区","科室名称", "科室代码"));
|
|
|
+
|
|
|
+ // 写入响应
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + uuid + ".xls");
|
|
|
+ ServletOutputStream out = null;
|
|
|
+
|
|
|
+ out = response.getOutputStream();
|
|
|
+ writer.flush(out, true);
|
|
|
+ writer.close();
|
|
|
+ IoUtil.close(out);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 批量导入科室信息
|
|
|
+ */
|
|
|
+ @PostMapping("/importDepartment")
|
|
|
+ @ApiOperation("导入科室信息")
|
|
|
+ public Result importDepartment(@RequestParam("file") MultipartFile file){
|
|
|
+ InputStream in;
|
|
|
+ try {
|
|
|
+ in = file.getInputStream();
|
|
|
+ ExcelReader reader = ExcelUtil.getReader(in);
|
|
|
+ List<List<Object>> read = reader.read();
|
|
|
+ log.info("最开始:read={}",read);
|
|
|
+ log.info("-------------------------------------------------------------------");
|
|
|
+ User user = (User) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ Integer hospId = user.getHospId();
|
|
|
+ return departmentService.importDepartment(read, hospId);
|
|
|
+ }catch (IOException e){
|
|
|
+ e.printStackTrace();;
|
|
|
+ throw new CostException(500, "导入失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 收入成本项目批量导入模板
|
|
|
+ */
|
|
|
+ @ApiOperation("收入成本导出模板设置")
|
|
|
+ @GetMapping("/getImportProductTemplate")
|
|
|
+ public void getImportProductTemplate(HttpServletResponse response) throws IOException {
|
|
|
+ User user = (User) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ String uuid = UUID.randomUUID().toString();
|
|
|
+ String url = System.getProperty("java.io.tmpdir") + File.separator + uuid + File.separator + uuid + ".xls";
|
|
|
+ FileUtil.del(FileUtil.file(url));
|
|
|
|
|
|
+ ExcelWriter writer = new ExcelWriter(url);
|
|
|
+ // 样式
|
|
|
+ Sheet sheet = writer.getSheet();
|
|
|
+ // 内容
|
|
|
+ writer.merge(0, 1, 0, 2, "为了保证成功导入,请勿修改模板格式", false);
|
|
|
+ writer.passCurrentRow();
|
|
|
+ writer.passCurrentRow();
|
|
|
+ writer.merge(2, 2, 0, 2, "医院成本收入批量导入", false);
|
|
|
+ writer.passCurrentRow();
|
|
|
+ writer.setColumnWidth(0,20);
|
|
|
+ writer.setColumnWidth(1,15);
|
|
|
+ writer.setColumnWidth(2,15);
|
|
|
+ writer.writeRow(Arrays.asList("院区","成本项目名", "成本项目编号"));
|
|
|
|
|
|
+ // 写入响应
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + uuid + ".xls");
|
|
|
+ ServletOutputStream out = null;
|
|
|
+
|
|
|
+ out = response.getOutputStream();
|
|
|
+ writer.flush(out, true);
|
|
|
+ writer.close();
|
|
|
+ IoUtil.close(out);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 收入成本项目批量导入
|
|
|
+ */
|
|
|
+ @PostMapping("/importProduct")
|
|
|
+ @ApiOperation("批量导入收入成本信息")
|
|
|
+ public Result importProduct(@RequestParam("file") MultipartFile file){
|
|
|
+ InputStream in;
|
|
|
+ try {
|
|
|
+ in = file.getInputStream();
|
|
|
+ ExcelReader reader = ExcelUtil.getReader(in);
|
|
|
+ List<List<Object>> read = reader.read();
|
|
|
+ log.info("最开始:read={}",read);
|
|
|
+ log.info("-------------------------------------------------------------------");
|
|
|
+ User user = (User) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ Integer hospId = user.getHospId();
|
|
|
+ return productService.importProduct(read, hospId);
|
|
|
+ }catch (IOException e){
|
|
|
+ e.printStackTrace();;
|
|
|
+ throw new CostException(500, "导入失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|