| | |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.net.URLEncoder; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Comparator; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.panzhihua.common.constants.Constants; |
| | | import com.panzhihua.common.enums.*; |
| | | import com.panzhihua.common.listen.ComElderAuthRecordImportExcelListen; |
| | | import com.panzhihua.common.listen.ComMngPopulationDrugExcelListen; |
| | | import com.panzhihua.common.model.dtos.community.*; |
| | | import com.panzhihua.common.model.vos.community.*; |
| | | import com.panzhihua.common.service.community.CommunityService; |
| | | import com.panzhihua.common.utlis.*; |
| | | import com.panzhihua.community_backstage.excel.CustomSheetWriteHandler; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.redis.core.StringRedisTemplate; |
| | | import org.springframework.data.redis.core.ValueOperations; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.panzhihua.common.controller.BaseController; |
| | | import com.panzhihua.common.model.dtos.community.EldersAuthAddDTO; |
| | | import com.panzhihua.common.model.dtos.community.EldersAuthFeedbackAddDTO; |
| | | import com.panzhihua.common.model.dtos.community.ExcelElderAuthDTO; |
| | | import com.panzhihua.common.model.dtos.community.PageEldersAuthDTO; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.community.EldersAuthDetailsVO; |
| | | import com.panzhihua.common.model.vos.community.EldersAuthVO; |
| | | import com.panzhihua.common.service.community.CommunityService; |
| | | import com.panzhihua.common.utlis.ClazzUtils; |
| | | import com.panzhihua.common.utlis.SFTPUtil; |
| | | |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | /** |
| | | * |
| | |
| | | |
| | | @Resource |
| | | private CommunityService communityService; |
| | | |
| | | @Resource |
| | | private StringRedisTemplate stringRedisTemplate; |
| | | |
| | | @Value("${excel.elderimporturl}") |
| | | private Object elderimporturl; |
| | |
| | | return R.ok(elderimporturl); |
| | | } |
| | | |
| | | |
| | | //2021-8-30 身份认证改版(高龄老人认证管理)接口 |
| | | /** |
| | | * 分页查询高龄老人认证记录 pageElderAuthRecords 分页查询高龄老人认证记录 |
| | | * @param pageElderAuthRecordsDTO 查询参数 |
| | | * @return R 查询结果 |
| | | * @author txb |
| | | * @date 2021/9/02 11:03 |
| | | */ |
| | | @ApiOperation(value = "高龄认证-分页查询高龄老人认证记录", response = ComElderAuthRecordVO.class) |
| | | @PostMapping("/authRecords/page") |
| | | public R pageElderAuthRecords(@RequestBody PageElderAuthRecordsDTO pageElderAuthRecordsDTO) { |
| | | Long communityId = this.getLoginUserInfo().getCommunityId(); |
| | | pageElderAuthRecordsDTO.setCommunityId(communityId); |
| | | return communityService.pageElderAuthRecords(pageElderAuthRecordsDTO); |
| | | } |
| | | |
| | | /** |
| | | * 根据高龄认证记录id查询详情 detailElderAuthRecords 根据高龄认证记录id查询详情 |
| | | * @param authRecordId 高龄认证记录id |
| | | * @return R 查询结果 |
| | | * @author txb |
| | | * @date 2021/9/02 11:03 |
| | | */ |
| | | @ApiOperation(value = "高龄认证-根据高龄认证记录id查询详情", response = ComElderAuthRecordVO.class) |
| | | @GetMapping("/authRecords/detail") |
| | | public R detailElderAuthRecords(@RequestParam(value = "authRecordId") Long authRecordId) { |
| | | return communityService.detailElderAuthRecords(authRecordId); |
| | | } |
| | | |
| | | /** |
| | | * 高龄认证审核 examineElderAuthRecords 高龄认证审核 |
| | | * @param comElderAuthRecordVO 高龄认证审核参数 |
| | | * @return R 查询结果 |
| | | * @author txb |
| | | * @date 2021/9/02 11:03 |
| | | */ |
| | | @ApiOperation(value = "高龄认证-高龄认证审核") |
| | | @PostMapping("/authRecords/examine") |
| | | public R examineElderAuthRecords(@RequestBody ComElderAuthRecordVO comElderAuthRecordVO) { |
| | | return communityService.examineElderAuthRecords(comElderAuthRecordVO); |
| | | } |
| | | |
| | | /** |
| | | * 高龄认证标记 examineElderAuthRecords 高龄认证标记 |
| | | * @param comElderAuthRecordVO 高龄认证标记参数 |
| | | * @return R 查询结果 |
| | | * @author txb |
| | | * @date 2021/9/02 11:03 |
| | | */ |
| | | @ApiOperation(value = "高龄认证-高龄认证标记") |
| | | @PostMapping("/authRecords/sign") |
| | | public R signElderAuthRecords(@RequestBody ComElderAuthRecordVO comElderAuthRecordVO) { |
| | | return communityService.signElderAuthRecords(comElderAuthRecordVO); |
| | | } |
| | | |
| | | /** |
| | | * 高龄认证导出 exportElderAuthRecords 高龄认证导出 |
| | | * @param ids 高龄认证记录id集合 |
| | | * @return R 导出结果 |
| | | * @author txb |
| | | * @date 2021/9/02 11:03 |
| | | */ |
| | | @ApiOperation(value = "高龄认证-高龄认证导出") |
| | | @PostMapping("/authRecords/export") |
| | | public R exportElderAuthRecords(@RequestBody List<Long> ids) { |
| | | // List<ComMngPopulationMistakeExcelVO> list = JSON.parseArray(mistakes,ComMngPopulationMistakeExcelVO.class); |
| | | // 生成动态模板excel通过ftp工具上传到主节点,然后返回模板下载地址 |
| | | String ftpUrl = "/mnt/data/web/excel/"; |
| | | String nowDate = DateUtils.getCurrentDateString(); |
| | | String name = "高龄认证导出数据" + nowDate + ".xlsx"; |
| | | try { |
| | | SFTPUtil sftp = new SFTPUtil(userName, password, host, port); |
| | | sftp.login(); |
| | | boolean existDir = sftp.isExistDir(ftpUrl + name); |
| | | if (!existDir) { |
| | | String property = System.getProperty("user.dir"); |
| | | String fileName = property + File.separator + name; |
| | | // 这里 需要指定写用哪个class去写 |
| | | ExcelWriter excelWriter = null; |
| | | InputStream inputStream = null; |
| | | try { |
| | | R r = communityService.getElderAuthRecordsByIds(ids); |
| | | List<ComElderAuthRecordExcleVO> list = new ArrayList<>(); |
| | | if (R.isOk(r)) { |
| | | list = JSONArray.parseArray(JSONArray.toJSONString(r.getData()), ComElderAuthRecordExcleVO.class); |
| | | } |
| | | excelWriter = EasyExcel.write(fileName, ComElderAuthRecordVO.class) |
| | | .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) |
| | | .registerWriteHandler(new CustomSheetWriteHandler()).build(); |
| | | WriteSheet writeSheet = EasyExcel.writerSheet("高龄认证导出数据").build(); |
| | | excelWriter.write(list, writeSheet); |
| | | excelWriter.finish(); |
| | | File file = new File(fileName); |
| | | inputStream = new FileInputStream(file); |
| | | sftp.uploadMore(ftpUrl, name, inputStream); |
| | | sftp.logout(); |
| | | inputStream.close(); |
| | | String absolutePath = file.getAbsolutePath(); |
| | | boolean delete = file.delete(); |
| | | log.info("删除excel【{}】结果【{}】", absolutePath, delete); |
| | | } finally { |
| | | // 千万别忘记finish 会帮忙关闭流 |
| | | if (inputStream != null) { |
| | | inputStream.close(); |
| | | } |
| | | if (excelWriter != null) { |
| | | excelWriter.finish(); |
| | | } |
| | | } |
| | | } |
| | | return R.ok(excelUrl + name); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("文件传输失败【{}】", e.getMessage()); |
| | | return R.fail(); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "高龄认证-下载模板-线下认证居民导入") |
| | | @GetMapping("/authRecords/uderLine/export") |
| | | public R exportUnderLineElderAuthRecords() { |
| | | // 生成动态模板excel通过ftp工具上传到主节点,然后返回模板下载地址 |
| | | String ftpUrl = "/mnt/data/web/excel/"; |
| | | String name = "线下认证居民导入模板.xlsx"; |
| | | try { |
| | | SFTPUtil sftp = new SFTPUtil(userName, password, host, port); |
| | | sftp.login(); |
| | | boolean existDir = sftp.isExistDir(ftpUrl + name); |
| | | if (!existDir) { |
| | | String property = System.getProperty("user.dir"); |
| | | String fileName = property + File.separator + name; |
| | | // 这里 需要指定写用哪个class去写 |
| | | ExcelWriter excelWriter = null; |
| | | InputStream inputStream = null; |
| | | try { |
| | | List<List<String>> list = new ArrayList<>(); |
| | | list = headDataFilling(); |
| | | EasyExcel.write(fileName).head(list).sheet("线下认证居民导入模板").doWrite(null); |
| | | File file = new File(fileName); |
| | | inputStream = new FileInputStream(file); |
| | | sftp.uploadMore(ftpUrl, name, inputStream); |
| | | sftp.logout(); |
| | | inputStream.close(); |
| | | String absolutePath = file.getAbsolutePath(); |
| | | boolean delete = file.delete(); |
| | | log.info("删除excel【{}】结果【{}】", absolutePath, delete); |
| | | } finally { |
| | | // 千万别忘记finish 会帮忙关闭流 |
| | | if (inputStream != null) { |
| | | inputStream.close(); |
| | | } |
| | | } |
| | | } |
| | | return R.ok(excelUrl + name); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("文件传输失败【{}】", e.getMessage()); |
| | | return R.fail(); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "高龄认证-excel导入线下认证居民") |
| | | @PostMapping(value = "/authRecords/uderLine/import", consumes = "multipart/*", headers = "content-type=multipart/form-date") |
| | | public R importDrug(@RequestParam MultipartFile file, HttpServletRequest request) { |
| | | // 获取文件名 |
| | | String fileName = file.getOriginalFilename(); |
| | | log.info("传入文件名字【{}】", fileName); |
| | | InputStream inputStream = null; |
| | | try { |
| | | inputStream = file.getInputStream(); |
| | | ComElderAuthRecordImportExcelListen comElderAuthRecordImportExcelListen = new ComElderAuthRecordImportExcelListen( |
| | | communityService, this.getCommunityId(), this.getLoginUserInfo().getUserId(), stringRedisTemplate); |
| | | EasyExcel.read(inputStream, null, comElderAuthRecordImportExcelListen).sheet().doRead(); |
| | | } catch (IOException e) { |
| | | log.error("导入模板失败【{}】", e.getMessage()); |
| | | e.printStackTrace(); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | private List<List<String>> headDataFilling() { |
| | | List<List<String>> list = new ArrayList<List<String>>(); |
| | | List<String> head0 = new ArrayList<String>(); |
| | | head0.add("认证姓名"); |
| | | List<String> head1 = new ArrayList<String>(); |
| | | head1.add("认证身份证号码"); |
| | | List<String> head2 = new ArrayList<String>(); |
| | | head2.add("联系电话"); |
| | | List<String> head3 = new ArrayList<String>(); |
| | | head3.add("现居住地址"); |
| | | List<String> head4 = new ArrayList<String>(); |
| | | head4.add("认证时间"); |
| | | List<String> head5 = new ArrayList<String>(); |
| | | head5.add("健在(是/否)"); |
| | | |
| | | list.add(head0); |
| | | list.add(head1); |
| | | list.add(head2); |
| | | list.add(head3); |
| | | list.add(head4); |
| | | list.add(head5); |
| | | return list; |
| | | } |
| | | } |