package com.ruoyi.web.controller.api;
|
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
import cn.hutool.json.JSONObject;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.basic.PageInfo;
|
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.exception.ServiceException;
|
import com.ruoyi.common.enums.BusinessType;
|
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.WebUtils;
|
import com.ruoyi.system.export.LargeSocialWorkerImport;
|
import com.ruoyi.system.model.TLargeSocialWorker;
|
import com.ruoyi.system.query.TLargeSocialWorkerQuery;
|
import com.ruoyi.system.service.TLargeSocialWorkerService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.poi.ss.usermodel.Workbook;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.StringUtils;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import javax.servlet.ServletOutputStream;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.IOException;
|
import java.io.InputStream;
|
import java.net.URLEncoder;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* <p>
|
* 大屏-社会工作者 前端控制器
|
* </p>
|
*
|
* @author xiaochen
|
* @since 2025-11-11
|
*/
|
@Slf4j
|
@Api(tags = "大屏-社会工作者")
|
@RestController
|
@RequestMapping("/t-large-social-worker")
|
public class TLargeSocialWorkerController {
|
|
private final TLargeSocialWorkerService largeSocialWorkerService;
|
@Autowired
|
public TLargeSocialWorkerController(TLargeSocialWorkerService largeSocialWorkerService) {
|
this.largeSocialWorkerService = largeSocialWorkerService;
|
}
|
|
/**
|
* 获取社会工作者管理列表
|
*/
|
@ApiOperation(value = "获取社会工作者分页列表")
|
@PostMapping(value = "/pageList")
|
public R<PageInfo<TLargeSocialWorker>> pageList(@RequestBody TLargeSocialWorkerQuery query) {
|
return R.ok(largeSocialWorkerService.pageList(query));
|
}
|
/**
|
* 获取社会工作者管理列表
|
*/
|
@ApiOperation(value = "获取社会工作者分页列表-大屏使用")
|
@PostMapping(value = "/pageListLarge")
|
public R<PageInfo<TLargeSocialWorker>> pageListLarge(@RequestBody TLargeSocialWorkerQuery query) {
|
return R.ok(largeSocialWorkerService.pageList(query));
|
}
|
|
/**
|
* 获取社会工作者管理列表
|
*/
|
@ApiOperation(value = "获取社会工作者列表")
|
@PostMapping(value = "/list")
|
public R<List<TLargeSocialWorker>> list() {
|
return R.ok(largeSocialWorkerService.list(Wrappers.lambdaQuery(TLargeSocialWorker.class).orderByDesc(TLargeSocialWorker::getCreateTime)));
|
}
|
|
/**
|
* 添加社会工作者管理
|
*/
|
@Log(title = "社会工作者信息-新增社会工作者", businessType = BusinessType.INSERT)
|
@ApiOperation(value = "添加社会工作者")
|
@PostMapping(value = "/add")
|
public R<Boolean> add(@Validated @RequestBody TLargeSocialWorker dto) {
|
return R.ok(largeSocialWorkerService.save(dto));
|
}
|
|
/**
|
* 修改社会工作者
|
*/
|
@Log(title = "社会工作者信息-修改社会工作者", businessType = BusinessType.UPDATE)
|
@ApiOperation(value = "修改社会工作者")
|
@PostMapping(value = "/update")
|
public R<Boolean> update(@Validated @RequestBody TLargeSocialWorker dto) {
|
return R.ok(largeSocialWorkerService.updateById(dto));
|
}
|
|
/**
|
* 查看社会工作者详情
|
*/
|
@ApiOperation(value = "查看社会工作者详情")
|
@GetMapping(value = "/getDetailById")
|
public R<TLargeSocialWorker> getDetailById(@RequestParam String id) {
|
return R.ok(largeSocialWorkerService.getById(id));
|
}
|
|
/**
|
* 删除社会工作者
|
*/
|
@Log(title = "社会工作者信息-删除社会工作者", businessType = BusinessType.DELETE)
|
@ApiOperation(value = "删除社会工作者")
|
@DeleteMapping(value = "/deleteById")
|
public R<Boolean> deleteById(@RequestParam String id) {
|
return R.ok(largeSocialWorkerService.removeById(id));
|
}
|
|
/**
|
* 批量删除社会工作者
|
*/
|
@Log(title = "社会工作者信息-删除社会工作者", businessType = BusinessType.DELETE)
|
@ApiOperation(value = "批量删除社会工作者")
|
@DeleteMapping(value = "/deleteByIds")
|
public R<Boolean> deleteByIds(@RequestBody List<String> ids) {
|
return R.ok(largeSocialWorkerService.removeByIds(ids));
|
}
|
|
@ApiOperation(value = "社会工作者信息导入模板下载")
|
@GetMapping("/import-template")
|
public void importTemplate() {
|
List<LargeSocialWorkerImport> largeLargeSocialWorkerImports = new ArrayList<>();
|
LargeSocialWorkerImport largeLargeSocialWorkerImport = new LargeSocialWorkerImport();
|
largeLargeSocialWorkerImports.add(largeLargeSocialWorkerImport);
|
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), LargeSocialWorkerImport.class, largeLargeSocialWorkerImports);
|
HttpServletResponse response = WebUtils.response();
|
ServletOutputStream outputStream = null;
|
try {
|
String fileName = URLEncoder.encode("社会工作者信息导入模板.xls", "utf-8");
|
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
|
response.setHeader("content-Type", "application/vnd.ms-excel");
|
response.setHeader("Pragma", "no-cache");
|
response.setHeader("Cache-Control", "no-cache");
|
outputStream = response.getOutputStream();
|
workbook.write(outputStream);
|
} catch (IOException e) {
|
e.printStackTrace();
|
System.out.println("社会工作者信息导入模板下载失败!");
|
} finally {
|
try {
|
outputStream.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
@Log(title = "社会工作者信息-社会工作者信息导入", businessType = BusinessType.INSERT)
|
@ApiOperation(value = "社会工作者信息导入")
|
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
|
@PostMapping("/import")
|
public R<String> importInfo(@RequestPart("file") MultipartFile file) {
|
List<TLargeSocialWorker> largeSocialWorkers = new ArrayList<>();
|
ImportParams params = new ImportParams();
|
params.setHeadRows(1); //表头行数
|
InputStream inputStream = null;
|
List<LargeSocialWorkerImport> largeSocialWorkerImports;
|
try {
|
inputStream = file.getInputStream();
|
largeSocialWorkerImports = ExcelImportUtil.importExcel(inputStream,
|
LargeSocialWorkerImport.class, params);
|
} catch (Exception e) {
|
e.printStackTrace();
|
log.error("社会工作者信息导入失败:{}", e.getMessage());
|
throw new ServiceException("社会工作者信息导入失败!");
|
} finally {
|
try {
|
inputStream.close();
|
} catch (IOException e) {
|
throw new ServiceException(e.getMessage());
|
}
|
}
|
if (CollectionUtils.isEmpty(largeSocialWorkerImports)) {
|
throw new ServiceException("社会工作者信息数据为空!");
|
}
|
JSONObject result = new JSONObject();
|
int i = 1;
|
for (LargeSocialWorkerImport largeSocialWorkerImport : largeSocialWorkerImports) {
|
if (!StringUtils.hasLength(largeSocialWorkerImport.getUserName())){
|
result.append("第"+i+"行:[", "姓名"+"]不能为空");
|
continue;
|
}
|
if (!StringUtils.hasLength(largeSocialWorkerImport.getUserSexStr())){
|
result.append("第"+i+"行:[", "性别"+"]不能为空");
|
continue;
|
}
|
if (!StringUtils.hasLength(largeSocialWorkerImport.getBirthDateStr())){
|
result.append("第"+i+"行:[", "出生日期"+"]不能为空");
|
continue;
|
}
|
if (!StringUtils.hasLength(largeSocialWorkerImport.getEducationalLevel())){
|
result.append("第"+i+"行:[", "文化程度"+"]不能为空");
|
continue;
|
}
|
if (!StringUtils.hasLength(largeSocialWorkerImport.getPoliticalStatus())){
|
result.append("第"+i+"行:[", "政治面貌"+"]不能为空");
|
continue;
|
}
|
if (!StringUtils.hasLength(largeSocialWorkerImport.getContactNumber())){
|
result.append("第"+i+"行:[", "联系电话"+"]不能为空");
|
continue;
|
}
|
if (largeSocialWorkerImport.getContactNumber().matches("^1[3-9]\\\\d{9}$")){
|
result.append("第"+i+"行:[", "联系电话"+"]格式不正确");
|
continue;
|
}
|
if (!StringUtils.hasLength(largeSocialWorkerImport.getEmployerPosition())){
|
result.append("第"+i+"行:[", "工作单位及职务"+"]不能为空");
|
continue;
|
}
|
if (!StringUtils.hasLength(largeSocialWorkerImport.getQualificationLevelStr())){
|
result.append("第"+i+"行:[", "职业资格等级"+"]不能为空");
|
continue;
|
}
|
TLargeSocialWorker largeSocialWorker = new TLargeSocialWorker();
|
BeanUtils.copyProperties(largeSocialWorkerImport, largeSocialWorker);
|
|
switch (largeSocialWorkerImport.getUserSexStr()){
|
case "男":
|
largeSocialWorker.setUserSex(1);
|
break;
|
case "女":
|
largeSocialWorker.setUserSex(2);
|
break;
|
default:
|
result.append("第"+i+"行:[", "性别"+"]格式错误");
|
continue;
|
}
|
|
switch (largeSocialWorkerImport.getQualificationLevelStr()){
|
case "助理社会工作师(初级)":
|
largeSocialWorker.setQualificationLevel(1);
|
break;
|
case "社会工作师(中级)":
|
largeSocialWorker.setQualificationLevel(2);
|
break;
|
case "高级社会工作师(高级)":
|
largeSocialWorker.setQualificationLevel(3);
|
break;
|
default:
|
result.append("第"+i+"行:[", "职业资格等级"+"]格式错误");
|
continue;
|
}
|
try{
|
largeSocialWorker.setBirthDate(DateUtils.stringToLocalDate(largeSocialWorkerImport.getBirthDateStr()));
|
}catch (Exception e){
|
result.append("第"+i+"行:[", "出生日期"+"]格式错误");
|
continue;
|
}
|
largeSocialWorkers.add(largeSocialWorker);
|
i++;
|
}
|
largeSocialWorkerService.saveBatch(largeSocialWorkers);
|
if(!result.isEmpty()){
|
return R.fail(result.toString());
|
}
|
return R.ok();
|
}
|
|
}
|