package com.ots.project.exam.controller;
|
|
import com.ots.common.utils.file.FileUploadUtils;
|
import com.ots.common.utils.poi.ExcelUtil;
|
import com.ots.framework.aspectj.lang.annotation.Log;
|
import com.ots.framework.aspectj.lang.enums.BusinessType;
|
import com.ots.framework.config.EssConfig;
|
import com.ots.framework.web.controller.BaseController;
|
import com.ots.framework.web.domain.AjaxResult;
|
import com.ots.framework.web.page.TableDataInfo;
|
import com.ots.project.exam.domain.TLibraryCode;
|
import com.ots.project.exam.service.ITLibraryCodeService;
|
import com.ots.project.tool.CacheServiceFactory;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.ui.ModelMap;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import java.io.IOException;
|
import java.util.List;
|
import java.util.Objects;
|
import java.util.stream.Collectors;
|
|
/**
|
* 报告字典Controller
|
*
|
* @author ots
|
* @date 2020-03-24
|
*/
|
@Controller
|
@Slf4j
|
@RequestMapping("/exam/librarycode")
|
public class TLibraryCodeController extends BaseController {
|
private String prefix = "exam/librarycode";
|
|
@Autowired
|
private ITLibraryCodeService tLibraryCodeService;
|
|
@RequiresPermissions("exam:librarycode:view")
|
@GetMapping()
|
public String librarycode() {
|
return prefix + "/librarycode";
|
}
|
|
/**
|
* 查询报告字典列表
|
*/
|
@RequiresPermissions("exam:librarycode:list")
|
@PostMapping("/list")
|
@ResponseBody
|
public TableDataInfo list(TLibraryCode tLibraryCode) {
|
startPage();
|
List<TLibraryCode> list = tLibraryCodeService.selectTLibraryCodeList(tLibraryCode);
|
// 展示图片
|
for (TLibraryCode tLibraryCodeTemp : list) {
|
if (StringUtils.isNotEmpty(tLibraryCodeTemp.getIcon())) {
|
tLibraryCodeTemp.setIcon(EssConfig.getHttpProfilePath() +"/upload" + tLibraryCodeTemp.getIcon());
|
}
|
}
|
return getDataTable(list);
|
}
|
|
/**
|
* 导出报告字典列表
|
*/
|
@RequiresPermissions("exam:librarycode:export")
|
@PostMapping("/export")
|
@ResponseBody
|
public AjaxResult export(TLibraryCode tLibraryCode) {
|
List<TLibraryCode> list = tLibraryCodeService.selectTLibraryCodeList(tLibraryCode);
|
ExcelUtil<TLibraryCode> util = new ExcelUtil<TLibraryCode>(TLibraryCode.class);
|
return util.exportExcel(list, "librarycode");
|
}
|
|
/**
|
* 新增报告字典
|
*/
|
@GetMapping("/add")
|
public String add() {
|
return prefix + "/add";
|
}
|
|
/**
|
* 新增保存报告字典
|
*/
|
@RequiresPermissions("exam:librarycode:add")
|
@Log(title = "报告字典", businessType = BusinessType.INSERT)
|
@PostMapping("/add")
|
@ResponseBody
|
public AjaxResult addSave(TLibraryCode tLibraryCode) throws IOException {
|
if (Objects.equals(tLibraryCode.getDictType(), "2") && !tLibraryCode.getIconFile().isEmpty()) {
|
String ufi = FileUploadUtils.upload(EssConfig.getUploadPath(), tLibraryCode.getIconFile());
|
tLibraryCode.setIcon(ufi.split("profile/upload")[1]);
|
}
|
AjaxResult result = toAjax(tLibraryCodeService.insertTLibraryCode(tLibraryCode));
|
CacheServiceFactory.getInstance().reLoad();
|
return result;
|
}
|
|
/**
|
* 修改报告字典
|
*/
|
@GetMapping("/edit/{id}")
|
public String edit(@PathVariable("id") Long id, ModelMap mmap) {
|
TLibraryCode tLibraryCode = tLibraryCodeService.selectTLibraryCodeById(id);
|
tLibraryCode.setIcon(EssConfig.getHttpProfilePath() + "/upload" + tLibraryCode.getIcon());
|
mmap.put("tLibraryCode", tLibraryCode);
|
return prefix + "/edit";
|
}
|
|
/**
|
* 修改保存报告字典
|
*/
|
@RequiresPermissions("exam:librarycode:edit")
|
@Log(title = "报告字典", businessType = BusinessType.UPDATE)
|
@PostMapping("/edit")
|
@ResponseBody
|
public AjaxResult editSave(TLibraryCode tLibraryCode) throws IOException {
|
if (Objects.equals(tLibraryCode.getDictType(), "2") && !tLibraryCode.getIconFile().isEmpty()) {
|
String ufi = FileUploadUtils.upload(EssConfig.getUploadPath(), tLibraryCode.getIconFile());
|
tLibraryCode.setIcon(ufi.split("profile/upload")[1]);
|
}
|
|
AjaxResult result = toAjax(tLibraryCodeService.updateTLibraryCode(tLibraryCode));
|
CacheServiceFactory.getInstance().reLoad();
|
return result;
|
}
|
|
/**
|
* 删除报告字典
|
*/
|
@RequiresPermissions("exam:librarycode:remove")
|
@Log(title = "报告字典", businessType = BusinessType.DELETE)
|
@PostMapping("/remove")
|
@ResponseBody
|
public AjaxResult remove(String ids) {
|
return toAjax(tLibraryCodeService.deleteTLibraryCodeByIds(ids));
|
}
|
|
@Log(title = "报告字典导入", businessType = BusinessType.IMPORT)
|
@RequiresPermissions("exam:librarycode:import")
|
@PostMapping("/importData")
|
@ResponseBody
|
public AjaxResult importData(MultipartFile file, boolean updateSupport, String importReportType) throws Exception {
|
if (Objects.isNull(importReportType)) {
|
return AjaxResult.error("报告类型不能为空", null);
|
}
|
ExcelUtil<TLibraryCode> util = new ExcelUtil<>(TLibraryCode.class);
|
List<TLibraryCode> libraryCodes;
|
try {
|
libraryCodes = util.importExcel(file.getInputStream());
|
} catch (NullPointerException npe) {
|
log.error("模板解析错误:{}", npe.getMessage(), npe);
|
return AjaxResult.error("导入数据解析错误,请按模板格式导入!");
|
}
|
libraryCodes.stream().forEach(item -> {
|
item.setReportType(importReportType);
|
});
|
List<TLibraryCode> list = libraryCodes.stream().filter(item -> {
|
return StringUtils.isNotBlank(item.getLibraryCode());
|
}).collect(Collectors.toList());
|
|
String message = tLibraryCodeService.importLibraryCodes(list, updateSupport);
|
CacheServiceFactory.getInstance().reLoad();
|
return AjaxResult.success(message);
|
}
|
|
@RequiresPermissions("exam:librarycode:import")
|
@GetMapping("/importTemplate")
|
@ResponseBody
|
public AjaxResult importTemplate() {
|
ExcelUtil<TLibraryCode> util = new ExcelUtil<>(TLibraryCode.class);
|
AjaxResult result = util.importTemplateExcel("报告字典数据");
|
CacheServiceFactory.getInstance().reLoad();
|
return result;
|
}
|
}
|