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.yihu.jw.entity.health.bank.AccountDO; import com.yihu.jw.entity.health.bank.CreditsDetailDO; import com.yihu.jw.entity.health.bank.TaskPatientDetailDO; import com.yihu.jw.restmodel.web.MixEnvelop; import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint; import com.yihu.jw.rm.health.bank.HealthBankMapping; import com.yihu.jw.service.CreditsDetailService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.sleuth.Tracer; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.List; /** * @author wangzhinan * @create 2018-04-27 16:51 * @desc credits log info **/ @RestController @RequestMapping(HealthBankMapping.api_health_bank_common) @Api(tags = "健康积分相关操作",description = "健康积分相关操作") public class CreditsDetailController extends EnvelopRestEndpoint { @Autowired private Tracer tracer; @Autowired private CreditsDetailService service; /** * 查看积分记录 * * @param creditsDetail 积分对象 * @param page 页码 * @param size 分页大小 * @return */ @PostMapping(value = HealthBankMapping.healthBank.findCreditsLogInfo) @ApiOperation(value = "查看积分记录") public MixEnvelop selectCreditsLogInfo(@ApiParam(name = "creditsDetail",value = "积分记录JSON") @RequestParam(value = "creditsDetail",required = false)String creditsDetail, @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{ CreditsDetailDO creditsDetailDO = toEntity(creditsDetail,CreditsDetailDO.class); return service.findByCondition(creditsDetailDO,page,size); }catch (Exception e){ e.printStackTrace(); tracer.getCurrentSpan().logEvent(e.getMessage()); return MixEnvelop.getError(e.getMessage()); } } /** * 添加积分 * * @param creditsDetail 积分对象 * @return */ @PostMapping(value = HealthBankMapping.healthBank.createCreditsDetail) @ApiOperation(value = "添加积分记录") public MixEnvelop insert(@ApiParam(name = "creditsDetail",value = "积分记录JSON") @RequestParam(value = "creditsDetail",required = true)String creditsDetail){ try { CreditsDetailDO creditsDetailDO = toEntity(creditsDetail,CreditsDetailDO.class); return service.insert(creditsDetailDO); }catch (Exception e){ e.printStackTrace(); tracer.getCurrentSpan().logEvent(e.getMessage()); return MixEnvelop.getError(e.getMessage()); } } /** * 根据活动查找积分 * * @param activityId 活动id * * @param patientId 居民id * * @param page 页码 * * @param size 分页大小 * * @return */ @PostMapping(value = HealthBankMapping.healthBank.selectByActivity) @ApiOperation(value = "根据活动查找积分") public MixEnvelop seletcByActivity(@ApiParam(name = "activityId",value = "活动id") @RequestParam(value = "activityId",required = true)String activityId, @ApiParam(name = "patientId",value = "居民id") @RequestParam(value = "patientId",required = true) String patientId, @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.selectByActivity(activityId,patientId,page,size); }catch (Exception e){ e.printStackTrace(); tracer.getCurrentSpan().logEvent(e.getMessage()); return MixEnvelop.getError(e.getMessage()); } } /** * 查看积分排行 * * @param object {"filter":[""],"page":"","size":""} * @return */ @PostMapping(value = HealthBankMapping.healthBank.selectByRanking) @ApiOperation(value = "查询积分排名") public MixEnvelop selectByRanking(@RequestBody JSONObject object){ try{ JSONArray array = object.getJSONArray("filter"); Integer page = object.getInteger("page"); Integer size = object.getInteger("size"); List patientIds = new ArrayList<>(); for (int i=0;array != null && array.size()!=0&& i selectByActivityRanking(@RequestBody JSONObject object){ try{ JSONArray array = object.getJSONArray("filter"); String activityId = object.getString("activityId"); Integer page = object.getInteger("page"); Integer size = object.getInteger("size"); List ids = new ArrayList<>(); for (int i=0;array != null && array.size()!=0&& i selectByActivityRanking1(@ApiParam(name = "activityId",value = "活动id") @RequestParam(value = "activityId",required = true)String activityId, @ApiParam(name = "patientId",value = "居民id") @RequestParam(value = "patientId",required = true)String patientId, @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.selectByActivityRanking1(activityId,patientId,page,size); }catch (Exception e){ e.printStackTrace(); tracer.getCurrentSpan().logEvent(e.getMessage()); return MixEnvelop.getError(e.getMessage()); } } @PostMapping(value = HealthBankMapping.healthBank.doctorAddIntegrate) @ApiOperation(value = "添加积分记录") public MixEnvelop doctorAddIntegrate(@RequestBody JSONObject object){ try { JSONArray array = object.getJSONArray("patient"); String ruleId = object.getString("ruleId"); String description = object.getString("description"); return service.doctorAddIntegrate(array,ruleId,description); }catch (Exception e){ e.printStackTrace(); tracer.getCurrentSpan().logEvent(e.getMessage()); return MixEnvelop.getError(e.getMessage()); } } /** * 步数获取积分 * * @param creditsDetail 积分对象 * @return */ @PostMapping(value = HealthBankMapping.healthBank.addStepIntegrate) @ApiOperation(value = "步数获取积分") public MixEnvelop addStepIntegrate(@ApiParam(name = "creditsDetail",value = "积分记录JSON") @RequestParam(value = "creditsDetail",required = true)String creditsDetail){ try { CreditsDetailDO creditsDetailDO = toEntity(creditsDetail,CreditsDetailDO.class); return service.stepAddIntegrate(creditsDetailDO); }catch (Exception e){ e.printStackTrace(); tracer.getCurrentSpan().logEvent(e.getMessage()); return MixEnvelop.getError(e.getMessage()); } } @PostMapping(value = HealthBankMapping.healthBank.weekReward) @ApiOperation(value = "周奖励") public MixEnvelop weekReward(@ApiParam(name = "creditsDetail",value = "积分记录JSON") @RequestParam(value = "creditsDetail",required = true)String creditsDetail){ try { CreditsDetailDO creditsDetailDO = toEntity(creditsDetail,CreditsDetailDO.class); return service.weekReward(creditsDetailDO); }catch (Exception e){ e.printStackTrace(); tracer.getCurrentSpan().logEvent(e.getMessage()); return MixEnvelop.getError(e.getMessage()); } } /** * 医生手动减积分 * @param ruleId * @param patientId * @param hospital * @param hospitalName * @param integrate * @param reason * @param doctorId * @return */ @PostMapping(value = HealthBankMapping.healthBank.doctorDescreaseIntegrate) @ApiOperation(value = "医生手动减积分") public MixEnvelop doctorDescreaseIntegrate(@ApiParam(name = "ruleId",value = "规则id") @RequestParam(value = "ruleId",required = false)String ruleId, @ApiParam(name = "patientId",value = "居民id") @RequestParam(value = "patientId",required = false)String patientId, @ApiParam(name = "hospital",value = "机构code") @RequestParam(value = "hospital",required = false)String hospital, @ApiParam(name = "hospitalName",value = "机构名称") @RequestParam(value = "hospitalName",required = false)String hospitalName, @ApiParam(name = "integrate",value = "扣减的积分") @RequestParam(value = "integrate",required = false)Integer integrate, @ApiParam(name = "reason",value = "扣减的原因") @RequestParam(value = "reason",required = false)String reason, @ApiParam(name = "doctorId",value = "医生code") @RequestParam(value = "doctorId",required = false)String doctorId){ try { return service.doctorDescreaseIntegrate(ruleId,patientId,doctorId,hospital,hospitalName,integrate,reason); }catch (Exception e){ e.printStackTrace(); tracer.getCurrentSpan().logEvent(e.getMessage()); return MixEnvelop.getError(e.getMessage()); } } /** * 居民获取积分 * * @param creditsDetail * @return */ @PostMapping(value = HealthBankMapping.healthBank.patientGetInteger) @ApiOperation(value = "居民获取积分") public MixEnvelop patientGetInteger(@ApiParam(name = "creditsDetail",value = "积分记录JSON") @RequestParam(value = "creditsDetail",required = true)String creditsDetail){ try { CreditsDetailDO creditsDetailDO = toEntity(creditsDetail,CreditsDetailDO.class); return service.patientGetInteger(creditsDetailDO); }catch (Exception e){ e.printStackTrace(); tracer.getCurrentSpan().logEvent(e.getMessage()); return MixEnvelop.getError(e.getMessage()); } } /** * 获取当日积分 * * @param patient * @param transactionId * @return */ @PostMapping(value = HealthBankMapping.healthBank.selectByPatientAndDate) @ApiOperation(value = "健康问答--获取当日积分") public MixEnvelop patientGetInteger(@ApiParam(name = "patient",value = "居民code") @RequestParam(value = "patient",required = true)String patient, @ApiParam(name = "transactionId",value = "任务id") @RequestParam(value = "transactionId",required = true)String transactionId){ try { return service.selectByDate(patient,transactionId); }catch (Exception e){ e.printStackTrace(); tracer.getCurrentSpan().logEvent(e.getMessage()); return MixEnvelop.getError(e.getMessage()); } } /** * 分享获取积分 * @param creditsDetail * @return */ @PostMapping(value = HealthBankMapping.healthBank.shareIntegrate) @ApiOperation(value = "分享获取积分") public MixEnvelop shareIntegrate(@ApiParam(name = "creditsDetail",value = "积分记录JSON") @RequestParam(value = "creditsDetail",required = true)String creditsDetail){ try { CreditsDetailDO creditsDetailDO = toEntity(creditsDetail,CreditsDetailDO.class); return service.shareIntegrate(creditsDetailDO); }catch (Exception e){ e.printStackTrace(); tracer.getCurrentSpan().logEvent(e.getMessage()); return MixEnvelop.getError(e.getMessage()); } } }