package com.panzhihua.applets.api; import com.alibaba.fastjson.JSONObject; import com.panzhihua.common.controller.BaseController; 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.community.ComActSocialOrgVO; import com.panzhihua.common.model.vos.community.ComActVO; import com.panzhihua.common.service.community.CommunityService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import static java.util.Objects.isNull; import static java.util.Objects.nonNull; /** * @author zzj */ @Slf4j @Api(tags = {"社会组织"}) @RestController @RequestMapping("/comActSocialOrg") public class ComActSocialOrgApi extends BaseController { @Resource private CommunityService communityService; /** * 分页查询所有数据 * * @param commonPage 查询实体 * @return 所有数据 */ @ApiOperation(value = "社会组织列表", response = ComActSocialOrgVO.class) @PostMapping("queryAll") public R selectAll(@RequestBody CommonPage commonPage) { LoginUserInfoVO loginUserInfoSureNoLogin = this.getLoginUserInfoSureNoLogin(); if (nonNull(loginUserInfoSureNoLogin)) { commonPage.setCommunityId(loginUserInfoSureNoLogin.getCommunityId()); } else if (isNull(commonPage.getCommunityId())) { return R.fail("缺少社区id"); } R r = communityService.detailCommunity(commonPage.getCommunityId()); if (R.isOk(r)) { ComActVO comActVO = JSONObject.parseObject(JSONObject.toJSONString(r.getData()), ComActVO.class); if (comActVO != null) { commonPage.setStreetId(comActVO.getStreetId()); } } commonPage.setCommunityId(null); return this.communityService.comActSocialOrgSelectAll(commonPage); } /** * 通过主键查询单条数据 * * @param id 主键 * @return 单条数据 */ @ApiOperation("通过主键查询单条数据") @GetMapping("{id}") public R selectOne(@PathVariable("id") Long id){ return this.communityService.comActSocialOrgSelectOne(id); } /** * 新增数据 * * @param comActSocialOrg 实体对象 * @return 新增结果 */ @ApiOperation("新增社会组织") @PostMapping public R insert(@RequestBody ComActSocialOrgVO comActSocialOrg) { comActSocialOrg.setCommunityId(this.getCommunityId()); return this.communityService.comActSocialOrgInsert(comActSocialOrg); } /** * 修改数据 * * @param comActSocialOrg 实体对象 * @return 修改结果 */ @ApiOperation("修改社会组织") @PostMapping("/update") public R update(@RequestBody ComActSocialOrgVO comActSocialOrg) { return this.communityService.comActSocialOrgUpdate(comActSocialOrg); } /** * 删除数据 * * @param id 主键结合 * @return 删除结果 */ @ApiOperation("删除社会组织") @GetMapping("del") public R delete(@RequestParam("id") Long id) { return this.communityService.comActSocialOrgDelete(id); } }