123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492 |
- package com.yihu.jw.controller;/**
- * Created by nature of king on 2018/4/27.
- */
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.sun.org.apache.xpath.internal.operations.Bool;
- import com.yihu.jw.entity.health.bank.ActivityDO;
- import com.yihu.jw.restmodel.web.MixEnvelop;
- import com.yihu.jw.restmodel.web.ObjEnvelop;
- import com.yihu.jw.restmodel.web.PageEnvelop;
- import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
- import com.yihu.jw.rm.health.bank.HealthBankMapping;
- import com.yihu.jw.service.ActivityService;
- import com.yihu.jw.util.date.DateUtil;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import io.swagger.annotations.ApiParam;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.cloud.sleuth.Tracer;
- import org.springframework.web.bind.annotation.*;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- /**
- * @author wangzhinan
- * @create 2018-04-27 14:14
- * @desc 健康活动
- **/
- @RestController
- @RequestMapping(HealthBankMapping.api_health_bank_common)
- @Api(tags = "健康活动相关操作",description = "健康活动相关操作")
- public class ActivityController extends EnvelopRestEndpoint {
- @Autowired
- private ActivityService service;
- @Autowired
- private Tracer tracer;
- /**
- * publish activity
- *
- * @param activity 活动对象
- * @return
- */
- @PostMapping(value = HealthBankMapping.healthBank.createActivity)
- @ApiOperation(value = "发布活动")
- public MixEnvelop<Boolean, Boolean> publishActivity(@ApiParam(name = "activity",value = "健康活动JSON")
- @RequestParam(value = "activity",required = true)String activity,
- @ApiParam(name = "registrationNumber",value = "报名人数")
- @RequestParam(value = "registrationNumber",required = false)String registrationNumber,
- @ApiParam(name = "value1",value = "积分JSON")
- @RequestParam(value = "value1",required = false)String value1,
- @ApiParam(name = "value2",value = "时间规则")
- @RequestParam(value = "value2",required = false)String value2,
- @ApiParam(name = "value3",value = "兑奖规则")
- @RequestParam(value = "value3",required = false)String value3){
- try {
- ActivityDO activityDO = toEntity(activity,ActivityDO.class);
- return service.insert(activityDO,value1,value2,value3,registrationNumber);
- }catch (Exception e){
- e.printStackTrace();
- // tracer.getCurrentSpan().logEvent(e.getMessage());
- return MixEnvelop.getError(e.getMessage());
- }
- }
- /**
- *
- * @param planCode
- * @param patient
- * @param name
- * @param idcard
- * @param hospital
- * @param hospitalName
- * @param templateName
- * @return
- */
- @PostMapping(value = HealthBankMapping.healthBank.createPlanActivity)
- @ApiOperation(value = "发布活动")
- public MixEnvelop<ActivityDO, ActivityDO> publishActivity(@ApiParam(name = "planCode",value = "计划code")
- @RequestParam(value = "planCode",required = true)String planCode,
- @ApiParam(name = "patient",value = "居民code")
- @RequestParam(value = "patient",required = true)String patient,
- @ApiParam(name = "name",value = "居民名字")
- @RequestParam(value = "name",required = true)String name,
- @ApiParam(name = "idcard",value = "身份证")
- @RequestParam(value = "idcard",required = true)String idcard,
- @ApiParam(name = "hospital",value = "社区code")
- @RequestParam(value = "hospital",required = true)String hospital,
- @ApiParam(name = "hospitalName",value = "社区名称")
- @RequestParam(value = "hospitalName",required = true)String hospitalName,
- @ApiParam(name = "templateName",value = "计划模板名称")
- @RequestParam(value = "templateName",required = true)String templateName){
- try {
- return service.createActivity(planCode,patient,name,idcard,hospital,hospitalName,templateName);
- }catch (Exception e){
- e.printStackTrace();
- // tracer.getCurrentSpan().logEvent(e.getMessage());
- return MixEnvelop.getError(e.getMessage());
- }
- }
- /**
- * find health activity
- *
- * @param activity 活动对象
- * @param page 页码
- * @param size 分页大小
- * @return
- */
- @PostMapping(value = HealthBankMapping.healthBank.findActivity)
- @ApiOperation(value = "查看健康活动")
- public MixEnvelop<ActivityDO, ActivityDO> getActivity(@ApiParam(name = "activity",value = "健康活动JSON")
- @RequestParam(value = "activity",required = false)String activity,
- @ApiParam(name = "page", value = "第几页,从1开始")
- @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
- @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
- @RequestParam(value = "size", required = false)Integer size){
- try{
- ActivityDO activityDO = toEntity(activity,ActivityDO.class);
- return service.findByCondition(activityDO,page,size);
- }catch (Exception e){
- e.printStackTrace();
- tracer.getCurrentSpan().logEvent(e.getMessage());
- return MixEnvelop.getError(e.getMessage());
- }
- }
- /**
- * out activity
- *
- * @param activity 活动对象
- * @return
- */
- @PostMapping(value = HealthBankMapping.healthBank.updateActivity)
- @ApiOperation(value = "编辑活动")
- public MixEnvelop<Boolean, Boolean> outActivity(@ApiParam(name = "activity", value = "健康活动JSON")
- @RequestParam(value = "activity", required = true) String activity,
- @ApiParam(name = "registrationNumber",value = "报名人数")
- @RequestParam(value = "registrationNumber",required = false)String registrationNumber,
- @ApiParam(name = "value1", value = "活动币JSON")
- @RequestParam(value = "value1", required = false) String value1,
- @ApiParam(name = "value2", value = "活动时间")
- @RequestParam(value = "value2", required = false) String value2,
- @ApiParam(name = "value3", value = "兑奖设置")
- @RequestParam(value = "value3", required = false) String value3) {
- try {
- ActivityDO activityDO = toEntity(activity, ActivityDO.class);
- return service.update(activityDO,value1,value2,value3,registrationNumber);
- } catch (Exception e) {
- e.printStackTrace();
- tracer.getCurrentSpan().logEvent(e.getMessage());
- return MixEnvelop.getError(e.getMessage());
- }
- }
- /**
- * 查看参与的活动
- *
- * @param activity 活动对象
- * @param page 页码
- * @param size 分页大小
- * @return
- */
- @PostMapping(value = HealthBankMapping.healthBank.selectByPatient)
- @ApiOperation(value = "参与的活动")
- public MixEnvelop<ActivityDO, ActivityDO> selectByPatient(@ApiParam(name = "activity",value = "健康活动JSON")
- @RequestParam(value = "activity",required = false)String activity,
- @ApiParam(name = "page", value = "第几页,从1开始")
- @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
- @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
- @RequestParam(value = "size", required = false)Integer size){
- try{
- ActivityDO activityDO = toEntity(activity,ActivityDO.class);
- return service.selectByPatient(activityDO,page,size);
- }catch (Exception e){
- e.printStackTrace();
- tracer.getCurrentSpan().logEvent(e.getMessage());
- return MixEnvelop.getError(e.getMessage());
- }
- }
- /**
- * 批量删除数据
- *
- * @param ids id集合[""]
- * @return
- */
- @PostMapping(value = HealthBankMapping.healthBank.batchActivity)
- @ApiOperation(value = "批量删除活动")
- public MixEnvelop<Boolean, Boolean> batchDelete(@ApiParam(name="ids",value = "id集合")
- @RequestParam(value = "ids",required = false)String ids){
- try{
- MixEnvelop<Boolean, Boolean> envelop = new MixEnvelop<>();
- JSONArray array = JSONArray.parseArray(ids);
- List<String> activityIds = new ArrayList<>();
- for (int i = 0;i<array.size();i++){
- activityIds.add(array.getString(i));
- }
- service.batchDelete(activityIds);
- envelop.setObj(true);
- return envelop;
- }catch (Exception e){
- e.printStackTrace();
- tracer.getCurrentSpan().logEvent(e.getMessage());
- return MixEnvelop.getError(e.getMessage());
- }
- }
- /**
- * 获取活动排行
- *
- * @param activityId
- * @param patient
- * @param page
- * @param size
- * @return
- */
- @PostMapping(value = HealthBankMapping.healthBank.selectActivityRanking)
- @ApiOperation(value = "获取活动排行")
- public MixEnvelop<JSONObject, JSONObject> selectActivityRanking(@ApiParam(name="activityId",value = "活动id")
- @RequestParam(value = "activityId",required = false)String activityId,
- @ApiParam(name="patient",value = "居民id")
- @RequestParam(value = "patient",required = false)String patient,
- @ApiParam(name = "page", value = "第几页,从1开始")
- @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
- @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
- @RequestParam(value = "size", required = false)Integer size,
- @ApiParam(name="street",value = "街道")
- @RequestParam(value = "street",required = false)String street,
- @ApiParam(name="town",value = "区")
- @RequestParam(value = "town",required = false)String town,
- @ApiParam(name="hospital",value = "社区")
- @RequestParam(value = "hospital",required = false)String hospital){
- try{
- return service.selectActivityRanking(activityId,patient,page,size,street,town,hospital);
- }catch (Exception e){
- e.printStackTrace();
- tracer.getCurrentSpan().logEvent(e.getMessage());
- return MixEnvelop.getError(e.getMessage());
- }
- }
- /**
- * 删除数据
- *
- * @param id 活动id
- * @return
- */
- @PostMapping(value = HealthBankMapping.healthBank.daleteActivity)
- @ApiOperation(value = "删除活动")
- public MixEnvelop<Boolean, Boolean> daleteActivity(@ApiParam(name="id",value = "id集合")
- @RequestParam(value = "id",required = false)String id){
- try{
- MixEnvelop<Boolean, Boolean> envelop = new MixEnvelop<>();
- service.daleteActivity(id);
- envelop.setObj(true);
- return envelop;
- }catch (Exception e){
- e.printStackTrace();
- tracer.getCurrentSpan().logEvent(e.getMessage());
- return MixEnvelop.getError(e.getMessage());
- }
- }
- /**
- * 编辑活动:上下线、推荐
- *
- * @param id
- * @param type
- * @return
- */
- @PostMapping(value = HealthBankMapping.healthBank.editActivity)
- @ApiOperation(value = "编辑活动:上下线、推荐")
- public ObjEnvelop<ActivityDO> editActivity(
- @ApiParam(name = "id", value = "活动id")
- @RequestParam(value = "id", required = true) String id,
- @ApiParam(name = "type", value = "操作类型:上线:0,下线:2,推荐:3,取消推荐:4")
- @RequestParam(value = "type", required = true) String type) {
- try {
- ActivityDO activityDO=service.editActivity(id, type);
- return ObjEnvelop.getSuccess("操作成功!",activityDO);
- } catch (Exception e) {
- e.printStackTrace();
- // tracer.getCurrentSpan().logEvent(e.getMessage());
- return ObjEnvelop.getError(e.getMessage());
- }
- }
- /**
- * 编辑活动:上下线、推荐
- *
- * @param id
- * @return
- */
- @PostMapping(value = HealthBankMapping.healthBank.findActivityById)
- @ApiOperation(value = "根据id获取活动详情+活动规则")
- public ObjEnvelop<JSONObject> findActivityById(
- @ApiParam(name = "id", value = "活动id")
- @RequestParam(value = "id", required = true) String id) {
- try {
- JSONObject activityDO=service.findActivityById(id);
- return ObjEnvelop.getSuccess("获取成功!",activityDO);
- } catch (Exception e) {
- e.printStackTrace();
- tracer.getCurrentSpan().logEvent(e.getMessage());
- return ObjEnvelop.getError("获取失败!"+e.getMessage());
- }
- }
- @PostMapping(value = HealthBankMapping.healthBank.pageActivity)
- @ApiOperation(value = "分页查询活动")
- public PageEnvelop<ActivityDO> pageActivity(@ApiParam(name = "type", value = "活动类型")
- @RequestParam(value = "type", required = false) String type,
- @ApiParam(name = "status", value = "活动状态:1上线,2下线")
- @RequestParam(value = "status", required = false) String status,
- @ApiParam(name = "crowdType", value = "人群类型:1:签约居民、2平台用户")
- @RequestParam(value = "crowdType", required = false) String crowdType,
- @ApiParam(name = "releaseTime", value = "下线开始时间")
- @RequestParam(value = "releaseTime", required = false) String releaseTime,
- @ApiParam(name = "activityOfflineTime", value = "下线结束时间")
- @RequestParam(value = "activityOfflineTime", required = false) String activityOfflineTime,
- @ApiParam(name = "filter", value = "活动名、发布机构、面向范围名称")
- @RequestParam(value = "filter", required = false) String filter,
- @ApiParam(name = "page", value = "第几页,从1开始")
- @RequestParam(value = "page", defaultValue = "1", required = false) Integer page,
- @ApiParam(name = "size", defaultValue = "10", value = ",每页分页大小")
- @RequestParam(value = "size", required = false) Integer size) {
- try{
- JSONObject obj = service.ListActivityDO(type, status,crowdType,releaseTime,activityOfflineTime,filter,page,size);
- // int count = (int) service.getCount(stringBuffer.toString());
- List<ActivityDO> list=(List<ActivityDO>)obj.get("activityDOList");
- int count =obj.getInteger("count");
- return success(list, count, page, size);
- }catch (Exception e){
- e.printStackTrace();
- tracer.getCurrentSpan().logEvent(e.getMessage());
- return PageEnvelop.getError("获取失败"+e.getMessage(),-1);
- }
- }
- /**
- * 编辑活动:上下线、推荐
- *
- * @param type
- * @return
- */
- @PostMapping(value = HealthBankMapping.healthBank.findActivityByType)
- @ApiOperation(value = "获取是否存在在线的竞走活动")
- public ObjEnvelop<Boolean> findActivityByType(
- @ApiParam(name = "type", value = "活动类型")
- @RequestParam(value = "type", required = true) String type) {
- try {
- JSONObject obj=service.findActivityByType(type);
- return ObjEnvelop.getSuccess("获取成功!",obj);
- } catch (Exception e) {
- e.printStackTrace();
- tracer.getCurrentSpan().logEvent(e.getMessage());
- return ObjEnvelop.getError("获取失败!"+e.getMessage());
- }
- }
- /**
- * 获取排序数据
- * @return
- */
- @PostMapping(value = HealthBankMapping.healthBank.selectActivitys)
- @ApiOperation(value = "获取排序数据")
- public MixEnvelop<ActivityDO,ActivityDO> select() {
- try {
- MixEnvelop<ActivityDO,ActivityDO> envelop = new MixEnvelop<>();
- envelop.setDetailModelList(service.select());
- return envelop;
- } catch (Exception e) {
- e.printStackTrace();
- tracer.getCurrentSpan().logEvent(e.getMessage());
- return MixEnvelop.getError(e.getMessage());
- }
- }
- /**
- * 调整顺序
- * @param activitys
- * @return
- */
- @PostMapping(value = HealthBankMapping.healthBank.updateSort)
- @ApiOperation(value = "调整顺序")
- public MixEnvelop updateSort(String activitys) {
- try {
- JSONArray array = JSONArray.parseArray(activitys);
- return service.updateSort(array);
- } catch (Exception e) {
- e.printStackTrace();
- tracer.getCurrentSpan().logEvent(e.getMessage());
- return MixEnvelop.getError(e.getMessage());
- }
- }
- @PostMapping(value = HealthBankMapping.healthBank.selectByUnionId)
- @ApiOperation(value = "查询参与的竟步走活动")
- public MixEnvelop<ActivityDO, ActivityDO> selectActivityRanking(@ApiParam(name="unionId",value = "unionId")
- @RequestParam(value = "unionId",required = true)String unionId,
- @ApiParam(name="patient",value = "居民id")
- @RequestParam(value = "patient",required = false)String patient,
- @ApiParam(name="idCard",value = "身份证")
- @RequestParam(value = "idCard",required = false)String idCard,
- @ApiParam(name = "page", value = "第几页,从1开始")
- @RequestParam(value = "page", defaultValue = "1",required = false)Integer page,
- @ApiParam(name = "size",defaultValue = "10",value = ",每页分页大小")
- @RequestParam(value = "size", required = false)Integer size){
- try{
- return service.selectByUnionId(unionId,patient,idCard,page,size);
- }catch (Exception e){
- e.printStackTrace();
- tracer.getCurrentSpan().logEvent(e.getMessage());
- return MixEnvelop.getError(e.getMessage());
- }
- }
- /**
- * 获取当前居民参加的活动
- * @param unionId
- * @param patient
- * @param idCard
- * @return
- */
- @PostMapping(value = HealthBankMapping.healthBank.selectNowByUnionId)
- @ApiOperation(value = "获取当前居民参加的活动")
- public MixEnvelop<ActivityDO, ActivityDO> selectNowByUnionId(@ApiParam(name="unionId",value = "unionId")
- @RequestParam(value = "unionId",required = true)String unionId,
- @ApiParam(name="patient",value = "居民id")
- @RequestParam(value = "patient",required = false)String patient,
- @ApiParam(name="idCard",value = "身份证")
- @RequestParam(value = "idCard",required = false)String idCard){
- try{
- MixEnvelop<ActivityDO,ActivityDO> envelop = new MixEnvelop<>();
- envelop.setDetailModelList(service.selectNowByUnionId(unionId,patient,idCard));
- return envelop;
- }catch (Exception e){
- e.printStackTrace();
- tracer.getCurrentSpan().logEvent(e.getMessage());
- return MixEnvelop.getError(e.getMessage());
- }
- }
- /**
- * 小程序-居民积分排行
- * @param patients
- * @param taskId
- * @param size
- * @return
- */
- @PostMapping(value = HealthBankMapping.healthBank.selectAppletsRanking)
- @ApiOperation(value = "小程序-居民积分排行")
- public MixEnvelop selectAppletsRanking(@ApiParam(name="flag",value = "居民code列表")
- @RequestParam(value = "flag",required = false)Integer flag,
- @ApiParam(name="flagName",value = "居民code列表")
- @RequestParam(value = "flagName",required = false)String flagName,
- @ApiParam(name="taskId",value = "任务id")
- @RequestParam(value = "taskId",required = true)String taskId,
- @ApiParam(name="size",value = "展示多少列")
- @RequestParam(value = "size",required = true)Integer size,
- @ApiParam(name="patient",value = "居民code")
- @RequestParam(value = "patient",required = true)String patient){
- try{
- MixEnvelop envelop = new MixEnvelop<>();
- envelop.setObj(service.selectAppletsRanking(flag,flagName,taskId,size,patient));
- return envelop;
- }catch (Exception e){
- e.printStackTrace();
- tracer.getCurrentSpan().logEvent(e.getMessage());
- return MixEnvelop.getError(e.getMessage());
- }
- }
- }
|