New file |
| | |
| | | package com.panzhihua.applets.api; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.panzhihua.common.controller.BaseController; |
| | | import com.panzhihua.common.listen.ComActSocialWorkerExcelListen; |
| | | import com.panzhihua.common.model.dtos.civil.*; |
| | | import com.panzhihua.common.model.dtos.property.CommonPage; |
| | | import com.panzhihua.common.model.vos.LoginUserInfoVO; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.civil.ComActSocialWorkerDetailsVO; |
| | | import com.panzhihua.common.model.vos.civil.ComActSocialWorkerVO; |
| | | import com.panzhihua.common.service.community.CommunityService; |
| | | import com.panzhihua.common.utlis.ClazzUtils; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | |
| | | import static java.util.Objects.isNull; |
| | | import static java.util.Objects.nonNull; |
| | | |
| | | /** |
| | | * |
| | | * @author cedoo email:cedoo(a)qq.com |
| | | * @version 1.0 |
| | | * @since 1.0 |
| | | * @date 2021-06-03 |
| | | * */ |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping("/comactsocialworker") |
| | | @Api(tags = {"社工"}) |
| | | public class ComActSocialWorkerApi extends BaseController { |
| | | |
| | | @Resource |
| | | private CommunityService communityService; |
| | | |
| | | // @Value("${excel.comactsocialworkerUrl}") |
| | | // private String comactsocialworkerUrl; |
| | | /** |
| | | * 新增社工 |
| | | * @param {classNameFirstLower}AddDTO 添加社工传递对象 |
| | | * @return 新增结果 |
| | | */ |
| | | @PostMapping() |
| | | @ApiOperation(value = "新增社工", response = R.class) |
| | | R add(@Validated @RequestBody ComActSocialWorkerAddDTO comActSocialWorkerAddDTO){ |
| | | ClazzUtils.setIfStringIsEmpty(comActSocialWorkerAddDTO); |
| | | comActSocialWorkerAddDTO.setUserId(getUserId()); |
| | | comActSocialWorkerAddDTO.setCommunityId(getCommunityId()); |
| | | return communityService.addComactsocialworker(comActSocialWorkerAddDTO); |
| | | } |
| | | |
| | | /** |
| | | * 修改 |
| | | * @param comActSocialWorkerEditDTO 修改社工传递对象 |
| | | * @return 修改结果 |
| | | */ |
| | | @PutMapping() |
| | | @ApiOperation(value = "编辑社工", response = R.class) |
| | | R edit(@Validated @RequestBody ComActSocialWorkerEditDTO comActSocialWorkerEditDTO){ |
| | | comActSocialWorkerEditDTO.setUserId(getUserId()); |
| | | return communityService.editComactsocialworker(comActSocialWorkerEditDTO); |
| | | } |
| | | |
| | | /** |
| | | * 分页查找 |
| | | * @param pageComActSocialWorkerDTO 查找社工传递对象 |
| | | * @return 查找结果 |
| | | */ |
| | | @GetMapping() |
| | | @ApiOperation(value = "查询社工", response= ComActSocialWorkerVO.class) |
| | | R query(@Validated @ModelAttribute PageComActSocialWorkerDTO pageComActSocialWorkerDTO){ |
| | | ClazzUtils.setIfStringIsEmpty(pageComActSocialWorkerDTO); |
| | | LoginUserInfoVO loginUserInfoSureNoLogin = this.getLoginUserInfoSureNoLogin(); |
| | | if (nonNull(loginUserInfoSureNoLogin)) { |
| | | pageComActSocialWorkerDTO.setCommunityId(loginUserInfoSureNoLogin.getCommunityId()); |
| | | } else if (isNull(pageComActSocialWorkerDTO.getCommunityId())) { |
| | | return R.fail("缺少社区id"); |
| | | } |
| | | return communityService.queryComactsocialworker(pageComActSocialWorkerDTO); |
| | | } |
| | | |
| | | /** |
| | | * 删除 |
| | | * @param comActSocialWorkerDeleteDTO 删除社工传递对象 |
| | | * @return 删除结果 |
| | | */ |
| | | @DeleteMapping() |
| | | @ApiOperation(value = "删除社工", response = R.class) |
| | | R delete(@Validated @RequestBody ComActSocialWorkerDeleteDTO comActSocialWorkerDeleteDTO){ |
| | | ClazzUtils.setIfStringIsEmpty(comActSocialWorkerDeleteDTO); |
| | | return communityService.deleteComactsocialworker(comActSocialWorkerDeleteDTO); |
| | | } |
| | | |
| | | /** |
| | | * 查询社工详细信息 |
| | | * @param id 社工 id |
| | | * @return 查找结果 |
| | | */ |
| | | @GetMapping("/{id}") |
| | | @ApiOperation(value = "查询社工详细信息") |
| | | R<ComActSocialWorkerVO> details(@PathVariable("id") Long id){ |
| | | return communityService.comActSocialWorkerDetails(id); |
| | | } |
| | | |
| | | /** |
| | | * 导入社工名单 |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "导入社工名单") |
| | | @PostMapping(value = "/import", consumes = "multipart/*", headers = "content-type=multipart/form-data") |
| | | public R downloadTemplate(@RequestParam MultipartFile file, HttpServletRequest request) { |
| | | String fileName = file.getOriginalFilename(); //获取文件名 |
| | | log.info("传入文件名字【{}】",fileName); |
| | | InputStream inputStream = null; |
| | | try { |
| | | inputStream = file.getInputStream(); |
| | | EasyExcel.read(inputStream, ComActSocialWorkerExcelVO.class, new ComActSocialWorkerExcelListen(communityService,this.getCommunityId())).sheet().doRead(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | log.error("导入模板失败【{}】", e.getMessage()); |
| | | return R.fail("信息有误"); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | // @GetMapping("/getTemplate") |
| | | // @ApiOperation("获取模板") |
| | | // public R getTemplate(){ |
| | | // return R.ok(comactsocialworkerUrl); |
| | | // } |
| | | @ApiOperation("根据社工获取活动") |
| | | @PostMapping("/activityList") |
| | | R activityList(@RequestBody CommonPage commonPage){ |
| | | return communityService.activityList(commonPage); |
| | | } |
| | | |
| | | } |