New file |
| | |
| | | package com.panzhihua.applets.api; |
| | | |
| | | import static java.util.Objects.isNull; |
| | | import static java.util.Objects.nonNull; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.validation.Valid; |
| | | import javax.validation.constraints.NotNull; |
| | | |
| | | import org.hibernate.validator.constraints.Length; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import com.panzhihua.common.constants.HttpStatus; |
| | | import com.panzhihua.common.controller.BaseController; |
| | | import com.panzhihua.common.model.dtos.community.warehouse.ComActWarehouseDonatesDTO; |
| | | import com.panzhihua.common.model.dtos.community.warehouse.PageDonatesDTO; |
| | | import com.panzhihua.common.model.vos.LoginUserInfoVO; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.community.warehouse.ComActWarehouseDonatesVO; |
| | | import com.panzhihua.common.service.community.CommunityService; |
| | | import com.panzhihua.common.validated.AddGroup; |
| | | import com.panzhihua.common.validated.PutGroup; |
| | | |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | /** |
| | | * @title: ComActWarehouseApi |
| | | * @projectName: 成都呐喊信息技术有限公司-智慧社区项目 |
| | | * @description: 爱心义仓捐赠小程序相关接口 |
| | | * @author: hans |
| | | * @date: 2021/10/11 15:45 |
| | | */ |
| | | |
| | | @Slf4j |
| | | @Api(tags = {"爱心义仓捐赠相关"}) |
| | | @RestController |
| | | @RequestMapping("/warehouse/donates") |
| | | public class ComActWarehouseDonatesApi extends BaseController { |
| | | |
| | | @Resource |
| | | private CommunityService communityService; |
| | | |
| | | @ApiOperation(value = "分页查询捐赠物品", response = ComActWarehouseDonatesVO.class) |
| | | @PostMapping("/page") |
| | | public R pageDonates(@RequestBody PageDonatesDTO pageDonatesDTO) { |
| | | LoginUserInfoVO loginUserInfo = getLoginUserInfoSureNoLogin(); |
| | | Integer isWhich = pageDonatesDTO.getIsWhich(); |
| | | if (isNull(isWhich)) { |
| | | return R.fail("缺少isWhich参数"); |
| | | } |
| | | if (isNull(pageDonatesDTO.getCommunityId())) { |
| | | return R.fail("社区id不能为空"); |
| | | } |
| | | if (isNull(loginUserInfo) && isWhich.intValue() != 3) { |
| | | return R.fail(HttpStatus.UNAUTHORIZED, "未登录"); |
| | | } |
| | | if (isWhich.intValue() == 2 && loginUserInfo.getIsCommunityWorker().intValue() != 1) { |
| | | return R.fail("非社区工作人员"); |
| | | } |
| | | if (nonNull(loginUserInfo)) { |
| | | pageDonatesDTO.setUserId(loginUserInfo.getUserId()); |
| | | } |
| | | return communityService.pageDonates(pageDonatesDTO); |
| | | } |
| | | |
| | | @ApiOperation(value = "新增物品捐赠") |
| | | @PostMapping("/add") |
| | | public R addDonates(@RequestBody @Validated(AddGroup.class) ComActWarehouseDonatesDTO comActWarehouseDonatesDTO) { |
| | | LoginUserInfoVO loginUserInfo = getLoginUserInfo(); |
| | | Long userId = loginUserInfo.getUserId(); |
| | | comActWarehouseDonatesDTO.setCommunityId(loginUserInfo.getCommunityId()); |
| | | comActWarehouseDonatesDTO.setRegisterBy(userId); |
| | | comActWarehouseDonatesDTO.setUserId(userId); |
| | | comActWarehouseDonatesDTO.setName(loginUserInfo.getName()); |
| | | comActWarehouseDonatesDTO.setPhone(loginUserInfo.getPhone()); |
| | | return communityService.addDonates(comActWarehouseDonatesDTO); |
| | | } |
| | | |
| | | @ApiOperation(value = "查看物品捐赠详情", response = ComActWarehouseDonatesVO.class) |
| | | @ApiImplicitParam(name = "isWhich", value = "1.个人中心捐赠详情 2.捐赠物品管理详情 3.爱心义仓捐赠列表详情", required = true) |
| | | @GetMapping("/get") |
| | | public R getDonates(@RequestParam("donatesId") Long donatesId, @RequestParam("isWhich") Integer isWhich) { |
| | | LoginUserInfoVO loginUserInfo = getLoginUserInfoSureNoLogin(); |
| | | if (isNull(isWhich)) { |
| | | return R.fail("缺少isWhich参数"); |
| | | } |
| | | if (isNull(loginUserInfo) && isWhich.intValue() != 3) { |
| | | return R.fail(HttpStatus.UNAUTHORIZED, "未登录"); |
| | | } |
| | | if (isWhich.intValue() == 2 && loginUserInfo.getIsCommunityWorker().intValue() != 1) { |
| | | return R.fail("非社区工作人员"); |
| | | } |
| | | Long userId = 0L; |
| | | if (nonNull(loginUserInfo)) { |
| | | userId = loginUserInfo.getUserId(); |
| | | } |
| | | return communityService.getDonates(donatesId, isWhich, userId); |
| | | } |
| | | |
| | | @ApiOperation(value = "捐赠物品签收") |
| | | @PostMapping("/signing") |
| | | public R signingDonates(@RequestBody @Validated(PutGroup.class) ComActWarehouseDonatesDTO comActWarehouseDonatesDTO) { |
| | | LoginUserInfoVO loginUserInfo = getLoginUserInfo(); |
| | | Integer isCommunityWorker = loginUserInfo.getIsCommunityWorker(); |
| | | if (isCommunityWorker.intValue() == 2) { |
| | | return R.fail("非社区工作人员"); |
| | | } |
| | | comActWarehouseDonatesDTO.setSigningBy(loginUserInfo.getUserId()); |
| | | return communityService.signingDonates(comActWarehouseDonatesDTO); |
| | | } |
| | | |
| | | @ApiOperation(value = "用户取消捐赠") |
| | | @GetMapping("/cancel") |
| | | public R cancelDonates(@RequestParam("donatesId") Long donatesId) { |
| | | return communityService.cancelDonates(donatesId, getUserId()); |
| | | } |
| | | } |