101captain
2021-09-22 1775bb71f952106c58657cf02891cbe2a286c8f8
springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/CommunityApi.java
New file
@@ -0,0 +1,254 @@
package com.panzhihua.applets.api;
import java.util.Date;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.alibaba.fastjson.JSONObject;
import com.panzhihua.common.controller.BaseController;
import com.panzhihua.common.model.dtos.community.ComMngCarAppletDTO;
import com.panzhihua.common.model.dtos.community.PageVolunteerDTO;
import com.panzhihua.common.model.vos.LoginUserInfoVO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.*;
import com.panzhihua.common.model.vos.user.SysUserNoticeVO;
import com.panzhihua.common.service.community.CommunityService;
import com.panzhihua.common.service.user.UserService;
import com.panzhihua.common.validated.AddGroup;
import com.panzhihua.common.validated.PageGroup;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
/**
 * @program: springcloud_k8s_panzhihuazhihuishequ
 * @description: 社区服务
 * @author: huang.hongfa weixin hhf9596 qq 959656820
 * @create: 2020-12-10 10:04
 **/
@Slf4j
@RestController
@RequestMapping("/community/")
@Api(tags = {"社区服务"})
public class CommunityApi extends BaseController {
    @Resource
    private CommunityService communityService;
    @Resource
    private UserService userService;
    @ApiOperation(value = "分页查询小区", response = ComMngStructAreaVO.class)
    @PostMapping("pagearea")
    public R pageArea(@RequestBody ComMngStructAreaVO comMngStructAreaVO) {
        return communityService.pageArea(comMngStructAreaVO);
    }
    @ApiOperation(value = "分页获取社区动态", response = ComActDynVO.class)
    @PostMapping("pagedynamic")
    public R pageDynamic(@RequestBody ComActDynVO comActDynVO) {
        LoginUserInfoVO loginUserInfo = this.getLoginUserInfoSureNoLogin();
        if (loginUserInfo != null) {
            comActDynVO.setCommunityId(loginUserInfo.getCommunityId());
        }
        comActDynVO.setIsTopping(null);
        comActDynVO.setStatus(1);
        return communityService.pageDynamic(comActDynVO);
    }
    @ApiOperation(value = "社区动态详情", response = ComActDynVO.class)
    @GetMapping("detaildynamic")
    @ApiImplicitParam(name = "id", value = "社区动态主键", required = true)
    public R detailDynamic(@RequestParam("id") Long id) {
        LoginUserInfoVO loginUserInfo = this.getLoginUserInfoSureNoLogin();
        Long userId = null;
        if (loginUserInfo != null) {
            userId = loginUserInfo.getUserId();
        }
        R r = communityService.detailDynamic(id);
        if (R.isOk(r)) {
            Object data = r.getData();
            ComActDynVO comActDynVO = JSONObject.parseObject(JSONObject.toJSONString(data), ComActDynVO.class);
            if (userId != null) {
                // 增加浏览记录
                R r1 = communityService.addDynamicUser(id, userId);
                if (R.isOk(r1)) {
                    comActDynVO.setIsAdd(1);
                } else {
                    comActDynVO.setIsAdd(0);
                }
            }
            return R.ok(comActDynVO);
        }
        return r;
    }
    @ApiOperation(value = "分页查询社区活动", response = ComActActivityVO.class)
    @PostMapping("pageactivity")
    public R pageActivity(@RequestBody ComActActivityVO comActActivityVO) {
        LoginUserInfoVO loginUserInfo = this.getLoginUserInfoSureNoLogin();
        if (loginUserInfo != null) {
            comActActivityVO.setCommunityId(loginUserInfo.getCommunityId());
        }
        comActActivityVO.setIsApplets(1);
        Integer status = comActActivityVO.getStatus();
        if (null != status && status.intValue() == 4) {
            comActActivityVO.setIsIng(1);
        }
        return communityService.pageActivity(comActActivityVO);
    }
    @ApiOperation(value = "社区活动/志愿者活动详情", response = ComActActivityVO.class)
    @GetMapping("detailactivity")
    @ApiImplicitParam(name = "id", value = "社区活动主键", required = true)
    public R detailActivity(@RequestParam("id") Long id) {
        Long userId = null;
        LoginUserInfoVO loginUserInfo = this.getLoginUserInfoSureNoLogin();
        if (loginUserInfo != null) {
            userId = loginUserInfo.getUserId();
        }
        return communityService.detailActivity(id, userId,null,null);
    }
    @ApiOperation(value = "分页查询活动评价记录", response = ComActActEvaluateVO.class)
    @PostMapping("evaluate/page")
    public R pageActivityEvaluates(@RequestBody ComActActEvaluateVO comActActEvaluateVO) {
        return communityService.pageActivityEvaluates(comActActEvaluateVO);
    }
    @ApiOperation(value = "社区活动/志愿者活动签到")
    @PostMapping("activity/sign-in")
    public R activitySignIn(@RequestBody ComActActRegistVO comActActRegistVO) {
        LoginUserInfoVO loginUserInfo = this.getLoginUserInfo();
        comActActRegistVO.setUserId(loginUserInfo.getUserId());
        comActActRegistVO.setIsVolunteer(loginUserInfo.getIsVolunteer());
        return communityService.activitySignIn(comActActRegistVO);
    }
    @ApiOperation(value = "社区活动/志愿者活动评价")
    @PostMapping("activity/evaluate")
    public R activityEvaluate(@RequestBody ComActActEvaluateVO comActActEvaluateVO) {
        LoginUserInfoVO loginUserInfo = this.getLoginUserInfo();
        comActActEvaluateVO.setUserId(loginUserInfo.getUserId());
        comActActEvaluateVO.setIsVolunteer(loginUserInfo.getIsVolunteer());
        return communityService.activityEvaluate(comActActEvaluateVO);
    }
    @ApiOperation(value = "报名/取消报名社区活动")
    @PutMapping("signactivity")
    public R signActivity(@RequestBody @Validated(AddGroup.class) SignactivityVO signactivityVO) {
        Long userId = this.getUserId();
        Long activityId = signactivityVO.getActivityId();
        Integer isVolunteer = signactivityVO.getIsVolunteer();
        signactivityVO.setUserId(userId);
        R r = communityService.signActivity(signactivityVO);
        if (R.isOk(r) && signactivityVO.getType().intValue() == 1) {
            R r2 = communityService.detailActivity(activityId, userId,null,null);
            ComActActivityVO comActActivityVO =
                JSONObject.parseObject(JSONObject.toJSONString(r2.getData()), ComActActivityVO.class);
            SysUserNoticeVO sysUserNoticeVO = new SysUserNoticeVO();
            sysUserNoticeVO.setUserId(userId);
            sysUserNoticeVO.setType(1);
            sysUserNoticeVO.setTitle("报名成功");
            sysUserNoticeVO.setBusinessType(1);
            sysUserNoticeVO.setBusinessTitle(comActActivityVO.getActivityName());
            Date beginAt = comActActivityVO.getBeginAt();
            sysUserNoticeVO.setBusinessContent(String.format("活动将于%tF %tT  开始,请按时参加", beginAt, beginAt));
            sysUserNoticeVO.setBusinessId(activityId);
            sysUserNoticeVO.setStatus(0);
            sysUserNoticeVO.setActivityType(isVolunteer.intValue() == 1 ? 1 : 2);
            sysUserNoticeVO.setBusinessStatus(2);
            R r1 = userService.addNotice(sysUserNoticeVO);
            if (R.isOk(r1)) {
                log.info("新增用户报名社区活动通知成功【{}】", JSONObject.toJSONString(sysUserNoticeVO));
            }
        }
        return r;
    }
    @ApiOperation(value = "活动人员列表", response = ActivitySignVO.class)
    @ApiImplicitParams({@ApiImplicitParam(name = "type", value = "人员类型 1 普通居民 2 志愿者", required = true),
        @ApiImplicitParam(name = "id", value = "社区活动主键", required = true)})
    @GetMapping("listactivitysign")
    public R listActivitySign(@RequestParam("id") Long id, @RequestParam("type") Integer type) {
        ActivitySignVO activitySignVO = new ActivitySignVO();
        activitySignVO.setActivityId(id);
        if (null == type || 0 == type || type > 2) {
            return R.fail("人员类型错误");
        }
        activitySignVO.setType(type);
        return communityService.listActivitySigns(activitySignVO);
    }
    // @ApiOperation(value = "新增社区动态浏览记录")
    // @PostMapping("dynamicuser")
    // public R addDynamicUser(@RequestBody ComActDynVO comActDynVO){
    // Long id = comActDynVO.getId();
    // if (null==id||id==0) {
    // return R.fail("社区动态不存在");
    // }
    // Long userId = this.getUserId();
    // return communityService.addDynamicUser(id,userId);
    // }
    @ApiOperation(value = "志愿者申请")
    @PostMapping("volunteer")
    public R addVolunteer(@RequestBody @Validated(AddGroup.class) ComMngVolunteerMngVO comMngVolunteerMngVO) {
        comMngVolunteerMngVO.setState(1);
        comMngVolunteerMngVO.setCommunityId(this.getCommunityId());
        comMngVolunteerMngVO.setSubmitUserId(this.getUserId());
        return communityService.addVolunteer(comMngVolunteerMngVO);
    }
    @ApiOperation(value = "分页查询志愿者团队", response = ComMngVolunteerMngVO.class)
    @PostMapping("pagevolunteer")
    public R pageVolunteer(@RequestBody @Validated(PageGroup.class) PageVolunteerDTO pageVolunteerDTO) {
        ComMngVolunteerMngVO comMngVolunteerMngVO = new ComMngVolunteerMngVO();
        LoginUserInfoVO loginUserInfo = this.getLoginUserInfoSureNoLogin();
        if (loginUserInfo != null) {
            comMngVolunteerMngVO.setCommunityId(loginUserInfo.getCommunityId());
        }
        // Long communityId = this.getCommunityId();
        // comMngVolunteerMngVO.setCommunityId(communityId);
        comMngVolunteerMngVO.setPageNum(pageVolunteerDTO.getPageNum());
        comMngVolunteerMngVO.setPageSize(pageVolunteerDTO.getPageSize());
        return communityService.pageVolunteer(comMngVolunteerMngVO);
    }
    @ApiOperation(value = "志愿者详情", response = ComMngVolunteerMngAppletsVO.class)
    @GetMapping("volunteer")
    public R detailVolunteer(@RequestParam("id") Long id) {
        return communityService.detailVolunteer(id);
    }
    @ApiOperation(value = "车辆登记")
    @PostMapping("car/register")
    public R addComMngCar(@Validated(AddGroup.class) @RequestBody ComMngCarAppletDTO comMngCarAppletDTO) {
        LoginUserInfoVO loginUserInfo = this.getLoginUserInfo();
        Long communityId = loginUserInfo.getCommunityId();
        if (null != communityId && 0 != communityId) {
            comMngCarAppletDTO.setCommunityId(communityId);
            comMngCarAppletDTO.setAreaId(loginUserInfo.getAreaId());
            comMngCarAppletDTO.setUserName(loginUserInfo.getName());
            comMngCarAppletDTO.setUserId(loginUserInfo.getUserId());
            comMngCarAppletDTO.setMobile(loginUserInfo.getPhone());
            comMngCarAppletDTO.setSource(1);
        }
        return communityService.addComMngCarApplet(comMngCarAppletDTO);
    }
    @ApiOperation(value = "登记车辆列表", response = ComMngCarVO.class)
    @GetMapping("car/list")
    public R comMngCarList() {
        return communityService.userComMngCarList(this.getUserId());
    }
    @ApiOperation(value = "获取树结构区域信息")
    @GetMapping(value = "arealist")
    public R getAllArea(@ApiParam(name = "城市编码:四川510000",
        required = true) @RequestParam(value = "provinceAdcode") Integer provinceAdcode) {
        return communityService.getCityTreeByProvinceCode(provinceAdcode);
    }
}