| | |
| | | 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.WebUtils; |
| | | import com.ruoyi.system.export.LargeOrganizationImport; |
| | | import com.ruoyi.system.export.MerchantImport; |
| | | import com.ruoyi.system.model.TLargeOrganization; |
| | | import com.ruoyi.system.model.TMerchant; |
| | | import com.ruoyi.system.model.TMerchantType; |
| | | import com.ruoyi.system.query.TLargeOrganizationQuery; |
| | | import com.ruoyi.system.service.TLargeOrganizationService; |
| | | 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; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @author xiaochen |
| | | * @since 2025-11-11 |
| | | */ |
| | | @Slf4j |
| | | @Api(tags = "大屏-社会组织") |
| | | @RestController |
| | | @RequestMapping("/t-large-organization") |
| | |
| | | public R<Boolean> deleteByIds(@RequestBody List<String> ids) { |
| | | return R.ok(largeOrganizationService.removeByIds(ids)); |
| | | } |
| | | |
| | | @ApiOperation(value = "社会组织导入模板下载") |
| | | @GetMapping("/import-template") |
| | | public void importTemplate() { |
| | | List<LargeOrganizationImport> largeOrganizationImports = new ArrayList<>(); |
| | | LargeOrganizationImport largeOrganizationImport = new LargeOrganizationImport(); |
| | | largeOrganizationImports.add(largeOrganizationImport); |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), LargeOrganizationImport.class, largeOrganizationImports); |
| | | 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<TLargeOrganization> largeOrganizations = new ArrayList<>(); |
| | | ImportParams params = new ImportParams(); |
| | | params.setHeadRows(1); //表头行数 |
| | | InputStream inputStream = null; |
| | | List<LargeOrganizationImport> largeOrganizationImports; |
| | | try { |
| | | inputStream = file.getInputStream(); |
| | | largeOrganizationImports = ExcelImportUtil.importExcel(inputStream, |
| | | LargeOrganizationImport.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(largeOrganizationImports)) { |
| | | throw new ServiceException("社会组织数据为空!"); |
| | | } |
| | | JSONObject result = new JSONObject(); |
| | | int i = 1; |
| | | for (LargeOrganizationImport largeOrganizationImport : largeOrganizationImports) { |
| | | if (!StringUtils.hasLength(largeOrganizationImport.getOrganizationName())){ |
| | | result.append("第"+i+"行:[", "组织名称"+"]不能为空"); |
| | | continue; |
| | | } |
| | | if (!StringUtils.hasLength(largeOrganizationImport.getOrganizationPerson())){ |
| | | result.append("第"+i+"行:[", "组织负责人"+"]不能为空"); |
| | | continue; |
| | | } |
| | | if (!StringUtils.hasLength(largeOrganizationImport.getAddress())){ |
| | | result.append("第"+i+"行:[", "地址"+"]不能为空"); |
| | | continue; |
| | | } |
| | | if (!StringUtils.hasLength(largeOrganizationImport.getContactNumber())){ |
| | | result.append("第"+i+"行:[", "联系电话"+"]不能为空"); |
| | | continue; |
| | | } |
| | | if (largeOrganizationImport.getContactNumber().matches("^1[3-9]\\\\d{9}$")){ |
| | | result.append("第"+i+"行:[", "联系电话"+"]格式不正确"); |
| | | continue; |
| | | } |
| | | if (!StringUtils.hasLength(largeOrganizationImport.getBusinessScope())){ |
| | | result.append("第"+i+"行:[", "业务范围"+"]不能为空"); |
| | | continue; |
| | | } |
| | | TLargeOrganization largeOrganization = new TLargeOrganization(); |
| | | BeanUtils.copyProperties(largeOrganizationImport, largeOrganization); |
| | | largeOrganizations.add(largeOrganization); |
| | | i++; |
| | | } |
| | | largeOrganizationService.saveBatch(largeOrganizations); |
| | | if(!result.isEmpty()){ |
| | | return R.fail(result.toString()); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | } |
| | | |