Commit c8096143 by liangkaiping

copy

parent 695eea91
# research-project 调研
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.yizhi</groupId>
<artifactId>cloud-research</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.yizhi</groupId>
<artifactId>cloud-research-api</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-common-api</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-util</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-orm</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-core</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.yizhi.research.application;
/**
* @Author: shengchenglong
* @Date: 2018/6/11 16:29
*/
public interface ResearchConstant {
/**
* 进行中
*/
Integer STATE_ING = 1;
/**
* 已结束
*/
Integer STATE_FINISHED = 2;
/**
* 已过期
*/
Integer STATE_DATED = 3;
}
package com.yizhi.research.application.eum;
/**
* 是否可以跳题
*
* @Author: shengchenglong
* @Date: 2018/3/14 10:58
*/
public enum Jumpleable {
/**
* 可以
*/
YES(1),
/**
* 不可以
*/
NO(0);
private int value;
private Jumpleable(int value) {
this.value = value;
}
public int getValue() {
return this.value;
}
}
package com.yizhi.research.application.eum;
/**
* 调研问题类型
*
* @Author: shengchenglong
* @Date: 2018/3/14 10:58
*/
public enum QuestionType {
/**
* 单选题
*/
SINGLE_OPTION_QUESTION(1),
/**
* 多选题
*/
MULTIPLE_OPTION_QUESTION(2),
/**
* 问答题
*/
ASK_ANSWER_QUESTION(3),
/**
* 打分题
*/
POINT_QUESTION(4);
private int value;
private QuestionType(int value) {
this.value = value;
}
public int getValue() {
return this.value;
}
}
package com.yizhi.research.application.eum;
/**
* @Author: shengchenglong
* @Date: 2018/3/14 18:35
*/
public enum RemindTimeType {
/**
* 开始时间之前
*/
BEFORE_START(1),
/**
* 结束时间之前
*/
BEFORE_END(2),
/**
* 自定义时间
*/
CUSTOM(3);
private int value;
private RemindTimeType(int value) {
this.value = value;
}
public int getValue() {
return this.value;
}
}
package com.yizhi.research.application.eum;
/**
* 调研状态
*
* @Author: shengchenglong
* @Date: 2018/3/16 17:27
*/
public enum ResearchState {
/**
* 草稿
*/
GRAFT(0),
/**
* 上架
*/
RELEASED(1),
/**
* 下架
*/
NO_RELEASED(2);
private int value;
private ResearchState(int value) {
this.value = value;
}
public int getValue() {
return this.value;
}
}
package com.yizhi.research.application.feign;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.research.application.model.AnswerModel;
import com.yizhi.research.application.vo.StatisticResearchMetadataVo;
import com.yizhi.research.application.vo.api.ViewAnswerVo;
import org.springframework.cloud.openfeign.FeignClient;
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.RequestParam;
import java.util.List;
/**
* @Author: shengchenglong
* @Date: 2018/3/19 10:31
*/
@FeignClient(name = "research", contextId = "ResearchAnswerClient")
public interface ResearchAnswerClient {
/**
* 学员提交调研问卷答案
*
* @param answerModel
* @return
*/
@PostMapping("/researchAnswer/submit")
Integer submitAnswer(@RequestBody AnswerModel answerModel);
/**
* 查看提交的问卷答案
*
* @param researchId
* @param accountId
* @return
*/
@GetMapping("/researchAnswer/view")
ViewAnswerVo viewResearch(@RequestParam("researchId") Long researchId, @RequestParam("accountId") Long accountId);
@GetMapping("/researchAnswer/views")
Page<ViewAnswerVo> viewAnswers(@RequestParam("researchId") Long researchId,
@RequestParam("pageNo") Integer start,
@RequestParam("pageSize") Integer end);
@GetMapping("/researchAnswer/view/list")
List<ViewAnswerVo> viewList(@RequestParam("researchId") Long researchId);
@GetMapping("/researchAnswer/views/list")
List<ViewAnswerVo> viewAnswersList(@RequestParam("researchId") Long researchId,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize);
@GetMapping("/researchAnswer/views/count")
Integer viewAnswersCount(@RequestParam("researchId") Long researchId);
@GetMapping("/researchAnswer/selectLearnRecord")
public List<StatisticResearchMetadataVo> selectLearnRecord(@RequestParam("researchId")Long researchId,
@RequestParam("startDate")String startDate,
@RequestParam("endDate")String endDate);
}
package com.yizhi.research.application.feign;
import com.yizhi.research.application.vo.domain.TrResearchAuthorizeVo;
import com.yizhi.research.application.vo.VisibleRangeExport;
import org.springframework.cloud.openfeign.FeignClient;
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.RequestParam;
import java.util.List;
/**
* @Author: shengchenglong
* @Date: 2018/6/8 13:36
*/
@FeignClient(name = "research", contextId = "ResearchAuthorizeClient")
public interface ResearchAuthorizeClient {
/**
* 查看可见范围
*
* @param researchId
* @return
*/
@GetMapping("/researchAuthorize/researchId/get")
List<TrResearchAuthorizeVo> getResearchAuthorize(@RequestParam("researchId") Long researchId);
@PostMapping("/researchAuthorize/researchId/insert")
Boolean insertResearchAuthorize(@RequestBody List<TrResearchAuthorizeVo> trResearchAuthorizeVos);
/**
* 可见范围导出
* @param assignmentId
* @return
*/
@GetMapping("/researchAuthorize/export/visiblRange")
public VisibleRangeExport exportVisibleRange(@RequestParam(name="researchId",required=true)Long researchId);
}
package com.yizhi.research.application.feign;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.core.application.vo.DroolsVo;
import com.yizhi.research.application.vo.CalendarTaskParamVo;
import com.yizhi.research.application.vo.domain.ResearchVo;
import com.yizhi.research.application.model.CopyResearchModel;
import com.yizhi.research.application.vo.BaseModel;
import com.yizhi.research.application.vo.api.CheckResearchStateVo;
import com.yizhi.research.application.vo.api.PageVo;
import com.yizhi.research.application.vo.api.SearchVo;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.openfeign.FeignClient;
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.RequestParam;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @Author: shengchenglong
* @Date: 2018/3/13 14:26
*/
@FeignClient(name = "research", contextId = "ResearchClient")
public interface ResearchClient {
/**
* 返回插入的调研的 id
*
* @param researchVo
* @return
*/
@PostMapping("/research/insert")
ResearchVo insert(@RequestBody ResearchVo researchVo);
/**
* 分页查询
*
* @param model
* @return
*/
@GetMapping("/research/page/list")
Page<ResearchVo> listPage(@RequestBody BaseModel<Page<ResearchVo>> model);
@GetMapping("/research/page/poolExamList")
Page<Map<String, Object>> getPoolExamList(@RequestParam(value = "name", required = false) String name,
@RequestParam(value = "ids", required = false) List<Long> ids,
@RequestParam(value = "pageNo", required = false) Integer pageNo,
@RequestParam(value = "pageSize", required = false) Integer pageSize);
/**
* 批量删除
*
* @param ids
* @return
*/
@PostMapping("/research/batch/delete")
Integer batchDelete(@RequestBody List<Long> ids);
// /**
// * 上架或下架
// *
// * @param id
// * @param state 1:上架,2:下架
// * @return
// */
// @PostMapping("/research/upOrDown")
// Integer upOrDown(@RequestParam("id") Long id, @RequestParam("state") Integer state);
/**
* 查看一个调研,包含提醒
*
* @param id
* @return
*/
@GetMapping("/research/view")
ResearchVo viewOne(@RequestParam("id") Long id);
/**
* 更新一个调研,包含提醒(删除以前的提醒)
*
* @param researchVo
* @return
*/
@PostMapping("/research/update")
int update(@RequestBody ResearchVo researchVo);
/**
* 上架或下架
*
* @param researchVo
* @return
*/
@PostMapping("/research/release")
ResearchVo upOrDown(@RequestBody ResearchVo researchVo);
/**
* 复制调研
*
* @param model
* @return
*/
@PostMapping("/research/copy")
ResearchVo copy(@RequestBody CopyResearchModel model);
/**
* 学员端分页列表
*
* @param pageVo
* @return
*/
@GetMapping("/research/api/page/list")
Page<ResearchVo> apiListPage(@RequestBody BaseModel<PageVo> model);
/**
* 学员端模糊查询分页列表
*
* @param searchVo
* @return
*/
@GetMapping("/research/api/search/page/list")
Page<ResearchVo> apiSearchPage(@RequestBody SearchVo searchVo);
/**
* 学员端查询我的调研个数
*
* @return
*/
@GetMapping("/research/api/count")
Integer searchUnfinishCount(@RequestBody RequestContext context);
/**
* 检查学员的某个调研的状态
*
* @return
*/
@PostMapping("/research/state/check")
Integer checkResearchState(@RequestBody CheckResearchStateVo checkResearchStateVo);
/**
* 获取管理端报表列表
*
* @param startDate
* @param endDate
* @param kwd
* @param pageSize
* @param pageNo
* @return
*/
@GetMapping("/research/group")
Page<ResearchVo> getResearchList(@RequestParam(name = "startDate", required = false) String startDate, @RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name = "kwd", required = false) String kwd, @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
@RequestParam(name = "pageNo", required = false, defaultValue = "1") Integer pageNo, @RequestParam(name = "orgIds", required = false) List<Long> orgIds,
@RequestParam(name = "companyId", required = true) Long companyId, @RequestParam(name = "siteId", required = true) Long siteId
);
/**
* 某个调研的人员完成情况
*
* @param researchId
* @return
*/
@GetMapping("/research/group/view")
ResearchVo getResearchView(@RequestParam(name = "researchId", required = true) Long researchId);
@GetMapping("/research/by/new/server")
public List<Map<String, Object>> getServerByCompanyIdAndIds(@RequestParam("companyId")Long companyId,@RequestParam(name="ids",required=false)List<Long> ids);
@PostMapping("/research/delete")
public Integer delete(Map map);
@GetMapping("/research/getAllResearch")
public List<ResearchVo> getAllResearch();
@GetMapping("/research/selectRecordMinTime")
public Date selectRecordMinTime();
@GetMapping ("/research/getAllSiteId")
public List<Long> getAllSiteId();
/**
* 根据调研id 返回对应的积分
* @param ids
* @return
*/
@GetMapping("/research/getPointById")
public Integer getPointByIds(@RequestParam(value = "ids",required = false) List<Long> ids);
@PostMapping("/research/getPageToCalendar")
public Page<ResearchVo> getPageToCalendar(@ApiParam("paramVo") @RequestBody CalendarTaskParamVo paramVo);
@GetMapping("/research/getPageByDrools")
Page<DroolsVo> getPageByDrools(@RequestParam("field") String field,
@RequestParam(value = "value", required = false) String value,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize);
}
package com.yizhi.research.application.feign;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.research.application.vo.domain.TrResearchQuestionVo;
import com.yizhi.research.application.model.ModifyQuestionModel;
import com.yizhi.research.application.vo.api.MyQuestion;
import com.yizhi.research.application.vo.api.QuestionJumpVo;
import org.springframework.cloud.openfeign.FeignClient;
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.RequestParam;
import java.util.List;
import java.util.Map;
/**
* @Author: shengchenglong
* @Date: 2018/3/14 15:19
*/
@FeignClient(name = "research", contextId = "ResearchQuestionClient")
public interface ResearchQuestionClient {
/**
* 批量插入问题
*
* @param questions
* @return
*/
@PostMapping("/researchQuestion/batch/insert")
int batchInsert(@RequestBody List<TrResearchQuestionVo> questions);
/**
* 问题更新
*
* @param modifyQuestionModel 删除的序号,所有的问题(包括没变的,新增的,修改的)
* @return
*/
@PostMapping("/researchQuestion/update")
int batchUpdate(@RequestBody ModifyQuestionModel modifyQuestionModel);
/**
* 分页查询 一个调研下面的问题
*
* @param page 只有一个
* @return
*/
@GetMapping("/researchQuestion/page/list")
List<TrResearchQuestionVo> listPage(@RequestBody Page<TrResearchQuestionVo> page);
/**
* 根据调研id查询所有
*
* @param researchId
* @return
*/
@GetMapping("/researchQuestion/list")
List<TrResearchQuestionVo> listAll(@RequestParam("researchId") Long researchId);
/**
* 选择跳题时的问题列表
*
* @param id 需要跳题的问题id
* @return
*/
@GetMapping("/researchQuestion/jump/question/list")
List<TrResearchQuestionVo> listAllForJump(@RequestParam("id") Long id);
/**
* 调研逐题显示下一题或者上一题
*/
@GetMapping("/researchQuestion/last/next")
MyQuestion lastAndNext(
@RequestBody MyQuestion myQuestion
);
@PostMapping("/researchQuestion/jump/question/update")
Integer updateQuestionJump(@RequestBody QuestionJumpVo vo);
@GetMapping("/researchQuestion/option/get")
Map<String,Object> getOptionByQuestionId(@RequestParam("questionId") Long id);
@GetMapping("/researchQuestion/list/all")
List<TrResearchQuestionVo> list(@RequestParam("researchId") Long researchId);
@GetMapping("/researchQuestion/getFinishedAccountIds")
List<Long> getFinishedAccountIds(@RequestParam("researchId") Long researchId,@RequestParam("companyId") Long companyId,@RequestParam("siteId")Long siteId);
}
package com.yizhi.research.application.feign;
import com.yizhi.research.application.vo.domain.TrResearchQuestionOptionVo;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@FeignClient(name = "research", contextId = "ResearchQuestionOptionClient")
public interface ResearchQuestionOptionClient {
/**
* 根据调研id查询所有的选项
* @param researchId
* @return
*/
@GetMapping("/trResearchQuestionOption/all")
List<TrResearchQuestionOptionVo> listOption(@RequestParam("researchId") Long researchId);
}
package com.yizhi.research.application.feign;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.research.application.vo.domain.StatisticsResearchVo;
import com.yizhi.research.application.vo.report.DownloadParamsVoOnTime;
import com.yizhi.util.application.domain.Response;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
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.RequestParam;
import java.util.List;
@FeignClient(name= "research")
public interface ResearchReportClient {
/**
* 异步加载统计
* @param startDate
* @param endDate
* @return
*/
@GetMapping("/statisticsResearch/asynchronous/load/data")
public Response<String> asynchronousResearch(@RequestParam("startDate") String startDate, @RequestParam("endDate") String endDate);
@GetMapping("/statisticsResearch/group")
Page<StatisticsResearchVo> researchGroup(@RequestParam(name = "startDate", required = false) String startDate,
@RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name = "kwd", required = false) String kwd,
@RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
@RequestParam(name = "pageNo", required = false, defaultValue = "1") Integer pageNo,
@RequestParam(name= "companyId" ,required = true) Long companyId,
@RequestParam(name= "orgIds" ,required = false) List<Long> orgIds,
@RequestParam(name= "siteId" ,required = true) Long siteId);
@GetMapping("/statisticsResearch/group/view")
Page<StatisticsResearchVo> researchGroupView(
@RequestParam(name = "startDate", required = false) String startDate,
@RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name= "researchId" ,required = true) Long researchId,
@RequestParam(name = "orgNameorOrgCode" ,required = false) String orgNameorOrgCode,
@RequestParam(name = "accountName" ,required = false )String accountName,
@RequestParam(name= "state" ,required = false) Integer state,
@RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
@RequestParam(name = "pageNo", required = false, defaultValue = "1") Integer pageNo);
@GetMapping("/statisticsResearch/group/view/state/count")
StatisticsResearchVo getCanStateCount(
@RequestParam(name = "startDate", required = false) String startDate,
@RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name= "researchId" ,required = true) Long researchId,
@RequestParam(name = "orgNameorOrgCode" ,required = false) String orgNameorOrgCode,
@RequestParam(name = "accountName" ,required = false )String accountName,
@RequestParam(name= "state" ,required = false) Integer state);
@GetMapping("/statisticsResearch/export/research/accounts")
List<StatisticsResearchVo> researchList(
@RequestParam(name = "startDate", required = false) String startDate,
@RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name= "researchId" ,required = true) Long researchId,
@RequestParam(name = "orgNameorOrgCode" ,required = false) String orgNameorOrgCode,
@RequestParam(name = "accountName" ,required = false )String accountName,
@RequestParam(name= "state" ,required = false) Integer state);
@ApiOperation(value = "下载调研参与人员的统计个数" ,notes = "下载参与人员的统计个数" ,response = StatisticsResearchVo.class)
@GetMapping("/statisticsResearch/export/research/accounts/count")
public Integer researchViewCount(
@RequestParam(name = "startDate", required = false) String startDate,
@RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name= "researchId" ,required = true) Long researchId,
@RequestParam(name = "orgNameorOrgCode" ,required = false) String orgNameorOrgCode,
@RequestParam(name = "accountName" ,required = false )String accountName,
@RequestParam(name= "state" ,required = false) Integer state
);
@ApiOperation(value = "调研参与人员的统计分页列表" ,notes = "调研参与人员的统计分页列表" ,response = StatisticsResearchVo.class)
@GetMapping("/statisticsResearch/group/views")
List<StatisticsResearchVo> researchViews(
@RequestParam(name = "startDate", required = false) String startDate,
@RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name= "researchId" ,required = true) Long researchId,
@RequestParam(name = "orgNameorOrgCode" ,required = false) String orgNameorOrgCode,
@RequestParam(name = "accountName" ,required = false )String accountName,
@RequestParam(name= "state" ,required = false) Integer state,
@RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
@RequestParam(name = "pageNo", required = false, defaultValue = "1") Integer pageNo);
@ApiOperation (value = "导出调研明细", notes = "导出调研明细")
@PostMapping("/statisticsResearch/details/Excel/onTime")
public String reportResearchDetails(@RequestBody DownloadParamsVoOnTime vo);
@ApiOperation (value = "导出调研分析", notes = "导出调研分析")
@PostMapping("/statisticsResearch/analyze/Excel/onTime")
public String reportResearchanalyze(@RequestBody DownloadParamsVoOnTime vo);
}
package com.yizhi.research.application.model;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.research.application.vo.api.AnswerVo;
import lombok.Data;
import java.util.Date;
/**
* @Author: shengchenglong
* @Date: 2018/3/19 11:14
*/
@Data
public class AnswerModel {
private AnswerVo answerVo;
private RequestContext context;
private Date date;
}
package com.yizhi.research.application.model;
import com.yizhi.core.application.context.RequestContext;
import lombok.Data;
import java.util.Date;
/**
* @Author: shengchenglong
* @Date: 2018/3/17 12:16
*/
@Data
public class CopyResearchModel {
private RequestContext requestContext;
private Date date;
private Long researchId;
}
package com.yizhi.research.application.model;
import lombok.Data;
import java.util.List;
/**
* @Author: shengchenglong
* @Date: 2018/5/23 14:16
*/
@Data
public class DataRangeModel {
/**
* 是否管理整个站点
*/
private Boolean admin;
/**
* 所属站点id
*/
private Long siteId;
/**
* 所属部门id
*/
private List<Long> orgIds;
}
package com.yizhi.research.application.model;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.research.application.vo.domain.TrResearchQuestionVo;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* @Author: shengchenglong
* @Date: 2018/3/16 15:43
*/
@Data
public class ModifyQuestionModel {
/**
* 所属调研id
*/
private Long researchId;
/**
* 删除的id集合
*/
private List<Long> deletedIds;
/**
* 新增的问题,修改的问题(修改仅仅涉及序号)
*/
private List<TrResearchQuestionVo> questions;
private RequestContext requestContext;
private Date date;
}
package com.yizhi.research.application.vo;
import com.yizhi.core.application.context.RequestContext;
import lombok.Data;
import java.util.Date;
/**
* @Author: shengchenglong
* @Date: 2018/3/27 15:55
*/
@Data
public class BaseModel<T> {
private RequestContext context;
private Date date;
private T obj;
}
package com.yizhi.research.application.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
@Data
public class CalendarTaskParamVo {
@ApiModelProperty("时间参数")
public Date date;
@ApiModelProperty("业务类型")
public Integer taskType = 0;
@ApiModelProperty("当前页数")
public Integer pageNo;
@ApiModelProperty("页内条数")
public Integer pageSize;
}
package com.yizhi.research.application.vo;
import java.util.Arrays;
import java.util.List;
/**
*
*/
public enum EvenType {
COURSE_UP(1L,Arrays.asList(1,2)),//"课程上架通知"
COURSE_FINISH(2L, Arrays.asList(1,2)),//课程完成通知
ENROLL_START(3L, Arrays.asList(1,3,4,5)),//报名开始
TRAINING_AUDIT_PASS(4L, Arrays.asList(1,3,4,5)),//项目审核通过通知
TRAINING_AUDIT_FAIL(5L, Arrays.asList(1,3,4,5)),//项目审核不通过通知
SIGN_SUCCESS(6L, Arrays.asList(1,3,4,5)),//签到成功通知
TRAINING_FINISH(7L, Arrays.asList(1,3,4,5)),//项目完成通知
ASSIGNMENT_AUDIT_FINISH(8L, Arrays.asList(1,6,7,8)),//作业已被批阅通知
EXAM_AUDIT_FINISH(9L, Arrays.asList(1,9,10,11)),//考试已被批阅通知
POINT_CHANGE(10L, Arrays.asList(1,12,13,14));//积分变动原因
//数据库message表的id
private Long key;
//数据库message_parameter表的field_type
private List<Integer> fieldType;
private EvenType(Long key, List<Integer> fieldType) {
this.key = key;
this.fieldType = fieldType;
}
public Long getKey() {
return key;
}
public List<Integer> getName() {
return fieldType;
}
}
package com.yizhi.research.application.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @Author: shengchenglong
* @Date: 2018/4/11 14:26
*/
@Data
@ApiModel(value = "调研id vo")
public class IdVo {
@ApiModelProperty(value = "调研id")
private Long id;
@ApiModelProperty(value = "积分")
private Integer point;
}
package com.yizhi.research.application.vo;
import com.yizhi.core.application.context.RequestContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* <p>
*
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "MessageRemindVo", description = "各个业务设置提醒时的数据")
public class MessageRemindVo implements Serializable {
private static final long serialVersionUID = -7621642684091133619l;
@ApiModelProperty(value = "提醒id ")
private Long id;
@ApiModelProperty(value = "消息id")
private Long messageId;
@ApiModelProperty(value = "消息类型:1、自定义消息;2、系统消息;3、事件触发消息")
private Integer messageType;
@ApiModelProperty(value = "用户id 主要用于触发消息 个人完成发消息类型")
private Long accountId;
@ApiModelProperty(value = "消息内容(完整版)")
private String messageContext;
@ApiModelProperty(value = "关联模块类型(1:学习计划、2:考试、3:调研、4、投票5:报名、6:作业、7:签到、8:项目、9:直播、10:积分)")
private Integer relationType;
@ApiModelProperty(value = "关联的业务id: 比如调研id")
private Long relationId;
@ApiModelProperty(value = "发送方式:1、站内信;2、短信;3、邮件")
private Integer sendType;
@ApiModelProperty(value = "该业务提醒是被关闭,关闭则为true,默认false")
private Boolean hasDeleted = false;
@ApiModelProperty(value = "该业务提醒是否有变化,有则为true,默认false")
private Boolean isChangge = false;
@ApiModelProperty(value = "专门存放提醒时间设置")
private List<MessageTaskRemindVo> messageTaskRemindVos = new ArrayList<>();
@ApiModelProperty(value = "目前只有培训项目需要,计划同步项目可见范围")
private Boolean visibleRangeUpdate = false;
@ApiModelProperty(value = "指定范围(0:全平台,1:指定用户)")
private Integer visibleRange;
@ApiModelProperty(value = "业务参数对象")
private TaskVo taskVo;
@ApiModelProperty(value = "触发消息专用 发送时间")
private Date sendTime;
@ApiModelProperty(value = "是否设置为上架状态")
private Boolean hasUp = false;
@ApiModelProperty(value = "是否是 修改业务状态 ")
private Boolean taskStatusUpdate = false;
@ApiModelProperty(value = "业务状态 1:才允上架许发送(业务上架)0:不允许发送(业务非上架) 仅针对于系统消息")
private Integer taskStatus;
@ApiModelProperty(value = "上下文 必传,主要需要 siteId companyId accountId accountName 都不能是空")
private RequestContext requestContext;
@ApiModelProperty(value = "调研是否为复制类型")
private Boolean isCopy = false;
@ApiModelProperty(value = "复制调研时,旧的调研id")
private Long oldRelationId;
}
package com.yizhi.research.application.vo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
*
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "MessageTaskRemindVo", description = "各个业务设置提醒时的数据")
public class MessageTaskRemindVo implements Serializable {
@ApiModelProperty(value = "待发消息id")
private Long messageRemindId;
@ApiModelProperty(value = "提醒时间事件类型 1:业务开始时间、 2:业务结束时间、3:自定义时间")
private Integer timeEventType;
@ApiModelProperty(value = "发生时间枚举:1:五分钟前、2:十分钟前、3:三十分钟前、4:一个小时前、5:两个小时前、6:一天前、7:两天前")
private Integer timeType;
@ApiModelProperty(value = "最终发送时间")
private Date sendTime;
}
package com.yizhi.research.application.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
@Data
public class StatisticResearchMetadataVo {
@ApiModelProperty (value = "调研ID")
private Long researchId;
@ApiModelProperty (value = "用户ID")
private Long accountId;
@ApiModelProperty (value = "应参加状态,1应参加 0不应参加(用于统计:应参加人数,MAX取值)")
private Integer canState;
@ApiModelProperty (value = "实际参加状态,1参加 0未参加(用于统计:实参加人数,MAX取值)")
private Integer joinState;
@ApiModelProperty (value = "提交时间")
private Date finishTime;
@ApiModelProperty (value = "调研参加时间")
private Date researchAnswerCreateTime;
@ApiModelProperty (value = "记录统计时间")
private Date recordCreateTime;
}
package com.yizhi.research.application.vo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 消息
* </p>
*
* @author hutao123
* @since 2019-09-09
*/
@Data
@Api(tags = "TaskVo", description = "业务参数对象")
public class TaskVo implements Serializable {
@ApiModelProperty(value = "业务名称")
private String taskName;
@ApiModelProperty(value = "业务开始时间")
private Date taskStratTime;
@ApiModelProperty(value = "业务结束时间")
private Date taskEndTime;
@ApiModelProperty(value = "业务得分")
private Double taskScore;
@ApiModelProperty(value = "业务发生原因(主要用于积分)")
private String reason;
@ApiModelProperty(value = "业务时间(主要用于积分)")
private Date taskTime;
@ApiModelProperty(value = "事件类型")
private EvenType evenType;
}
package com.yizhi.research.application.vo;
import java.util.List;
import com.yizhi.core.application.context.RequestContext;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 2019/09/19
* @author wangfeida
*
*/
@Data
public class VisibleRangeExport {
@ApiModelProperty(name="bizId",value="具体业务id")
private Long bizId;
@ApiModelProperty(name="bizName",value="具体业务名字")
private String bizName;
@ApiModelProperty(name="个人ID集合",value="个人id集合")
private List<Long> accountIds;
@ApiModelProperty(name="组织ID集合",value="组织ID集合")
private List<Long> orgIds;
@ApiModelProperty(name="上下文对象",value="上下文对象")
private RequestContext context;
}
package com.yizhi.research.application.vo.api;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @Author: shengchenglong
* @Date: 2018/3/19 11:06
*/
@Data
@Api(tags = "AnswerQuestionItemVo", description = "每个问题的答案vo")
public class AnswerQuestionItemVo {
@ApiModelProperty(value = "选项id", notes = "单选题和多选题:就是问题的答案;打分题:就是对应的打分项id")
private Long optionId;
@ApiModelProperty(value = "问题答案", notes = "问答题有效,选择题选项允许填空时有效")
private String content;
@ApiModelProperty(value = "选项打分", notes = "打分题有效")
private Integer score;
}
package com.yizhi.research.application.vo.api;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @Author: shengchenglong
* @Date: 2018/3/19 11:03
*/
@Data
@Api(tags = "AnswerQuestionVo", description = "调研问卷答案问题vo")
public class AnswerQuestionVo {
@ApiModelProperty(value = "问题id 新增不穿,更新必传", required = true)
private Long questionId;
@ApiModelProperty(value = "是否是第一题 1是")
private Integer isFrist =0;
@ApiModelProperty(value = "是否是最后一题 1是")
private Integer isLast =0;
@ApiModelProperty(value = "问题类型,1单选题、2多选题、3问答题、4打分题", required = true)
private Integer questionType;
@ApiModelProperty(value = "每个问题的答案vo,多选题和打分题可能会有多个", required = true)
private List<AnswerQuestionItemVo> questionItems;
@ApiModelProperty(value = "回答题目的id")
private Long answerQuestionId;
}
package com.yizhi.research.application.vo.api;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* @Author: shengchenglong
* @Date: 2018/3/19 11:02
*/
@Data
@Api(tags = "AnswerVo", description = "调研问卷答案vo")
public class AnswerVo {
@ApiModelProperty(value = "所属调研id", required = true)
private Long researchId;
@ApiModelProperty(value = "调研终端类型,1微信 2PC 3APP")
private Integer terminalType;
@ApiModelProperty(value = "开始时间", required = true)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date startTime;
@ApiModelProperty(value = "提交时间", required = true)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date submitTime;
@ApiModelProperty(value = "问题集合", required = true)
private List<AnswerQuestionVo> questions;
}
package com.yizhi.research.application.vo.api;
import com.yizhi.core.application.context.RequestContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@Api(tags = "CheckResearchStateVo", description = "检查某个学员的某个调研状态")
public class CheckResearchStateVo {
RequestContext context;
@ApiModelProperty(value = "所属调研id", required = true)
Long researchId;
}
package com.yizhi.research.application.vo.api;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.research.application.vo.domain.TrResearchQuestionVo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
@Data
public class MyQuestion {
@ApiModelProperty(value = "调研id")
private Long researchId;
@ApiModelProperty(value = "跳转的题号")
private Integer num;
@ApiModelProperty(value = "回答调研的开始时间")
private Date startDate;
@ApiModelProperty(value = "回答调研的结束时间")
private Date endDate;
@ApiModelProperty(value = "调研终端类型,1微信 2PC 3APP")
private Integer terminaltype;
@ApiModelProperty(value = "问题对象,下一题时显示给前端", required = true)
private TrResearchQuestionVo question;
private RequestContext context;
@ApiModelProperty(value = "题目")
private AnswerQuestionVo answerQuestionVo;
}
package com.yizhi.research.application.vo.api;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
/**
* @Author: shengchenglong
* @Date: 2018/3/17 16:55
*/
@Data
public class PageVo {
private Long accountId;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date date;
private Integer state;
private Integer pageNo;
private Integer pageSize;
}
package com.yizhi.research.application.vo.api;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.research.application.vo.domain.TrResearchQuestionOptionVo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
public class QuestionJumpVo {
@ApiModelProperty(value = "当前问题id")
private Long questionId;
@ApiModelProperty(value = "问题选项")
private List<TrResearchQuestionOptionVo> options;
@ApiModelProperty(value = "根据指定跳题策略时的题号")
private Integer jumpNo;
@ApiModelProperty(value = "跳题策略类型 1表示根据选项跳题,2表示指定跳题")
private Integer type;
private RequestContext context;
}
package com.yizhi.research.application.vo.api;
import com.yizhi.core.application.context.RequestContext;
import lombok.Data;
/**
* @Author: shengchenglong
* @Date: 2018/3/19 09:47
*/
@Data
public class SearchVo {
private String name;
private RequestContext context;
private Integer pageNo;
private Integer pageSize;
}
package com.yizhi.research.application.vo.api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
/**
* @Author: shengchenglong
* @Date: 2018/5/8 09:57
*/
@ApiModel("查看提交的问卷答案--答案下的问题选项")
@Data
public class ViewAnswerQuestionOptionVo {
@ApiModelProperty(value = "选项ID主键")
private Long id;
@ApiModelProperty(value = "选项排序,不能为空")
private Integer no;
@ApiModelProperty(value = "选项内容,最多支持输入500汉字")
private String content;
@ApiModelProperty(value = "跳题题号(单选题有效),问题设置了跳题才有效,大于当前题号")
private Integer jumpNum;
@ApiModelProperty(value = "是否正确答案(选择题有效),0不是 1是")
private Integer correct;
@ApiModelProperty(value = "是否允许填空")
private Integer editable;
@ApiModelProperty(value = "是否被学员选中")
private Boolean answerChecked = false;
@ApiModelProperty(value = "学员回答的内容", notes = "问答题有效")
private String answerContent;
@ApiModelProperty(value = "学员打分分数", notes = "打分题有效")
private Integer answerScore;
@ApiModelProperty(value = "最大分数",notes = "打分题有效")
private Integer maxScore = 0;
@ApiModelProperty(value = "最小分数",notes = "打分题有效")
private Integer minScore = 0;
@ApiModelProperty(value ="总分", notes = "总分")
private Integer totalSocre = 0;
@ApiModelProperty(value = "选中个数" , notes = "选中个数")
private Integer checkCount = 0;
@ApiModelProperty(value = "是否是其他选项")
private Integer isOther = 0;
}
package com.yizhi.research.application.vo.api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @Author: shengchenglong
* @Date: 2018/5/8 09:43
*/
@ApiModel("查看提交的问卷答案--答案下的问题")
@Data
public class ViewAnswerQuestionVo {
@ApiModelProperty(value = "问题_ID")
private Long id;
@ApiModelProperty(value = "题号")
private Integer no;
@ApiModelProperty(value = "问题类型,1单选题、2多选题、3问答题、4打分题")
private Integer type;
@ApiModelProperty(value = "问题内容")
private String content;
@ApiModelProperty(value = "存放附件路径,附件格式:音频、视频、图片")
private String contentAppendixUrl;
@ApiModelProperty(value = "是否必答,0非必答 1必答,默认0")
private Integer needAnswer;
@ApiModelProperty(value = "多选题:最多选择几项,0不选中 >0选中,默认0")
private Integer maxSelectItem;
@ApiModelProperty(value = "多选题:最少选择几项,0不选中 >0选中,默认0")
private Integer minSelectItem;
@ApiModelProperty(value = "答案下的问题选项集合", notes = "选择题、打分题有效")
private List<ViewAnswerQuestionOptionVo> options;
@ApiModelProperty(value = "问答题的回答内容")
private String answerContent;
@ApiModelProperty(value = "该问题有效回答的个数")
private Integer validCount = 0;
@ApiModelProperty(value = "用户id")
private Long accountId;
}
package com.yizhi.research.application.vo.api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* @Author: shengchenglong
* @Date: 2018/5/8 09:40
*/
@ApiModel("查看提交的问卷答案--答案主体")
@Data
public class ViewAnswerVo {
@ApiModelProperty(value = "答卷ID,主键")
private Long id;
@ApiModelProperty(value = "调研名称")
private String name;
@ApiModelProperty(value = "用户的id")
private Long accountId;
@ApiModelProperty(value = "开始时间,用户进入考试的时间")
private Date startTime;
@ApiModelProperty(value = "提交时间")
private Date submitTime;
@ApiModelProperty(value = "调研用时,分钟")
private Integer duration;
@ApiModelProperty(value = "调研终端类型,1微信 2PC 3APP")
private Integer terminalType;
@ApiModelProperty(value = "答案下的问题集合")
private List<ViewAnswerQuestionVo> answerQuestions;
}
package com.yizhi.research.application.vo.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import com.yizhi.research.application.vo.MessageRemindVo;
import com.yizhi.research.application.vo.manage.RemindVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* <p>
* 调研
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@Data
@Api(tags = "ResearchVo", description = "调研")
@TableName("resarch")
public class ResearchVo {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "调研主键ID,主键")
private Long id;
@ApiModelProperty(value = "培训项目ID")
private Long trainingProjectId;
@ApiModelProperty(value = "调研编码,系统将自动生成调研编码;编码规则,按创建顺序累加,例如DY000001,DY000002")
private String researchNo;
@ApiModelProperty(value = "积分,默认0")
private Integer point;
@ApiModelProperty(value = "提醒设置,0否 1是,默认0")
private Integer remind;
@ApiModelProperty(value = "开启邮件提醒(0:否,1是,默认否)")
private Integer enableMailRemind;
@ApiModelProperty(value = "邮件提醒,模板id")
private Long mailTemplateId;
@ApiModelProperty(value = "开启站内提醒(0:否,1是,默认否)")
private Integer enableAppRemind;
@ApiModelProperty(value = "站内消息提醒模板id")
private Long appTemplateId;
@ApiModelProperty(value = "调研名称")
private String name;
@ApiModelProperty(value = "开始时间")
private Date startTime;
@ApiModelProperty(value = "结束时间")
private Date endTime;
@ApiModelProperty(value = "可见范围,1平台用户可见(企业下所有人员) 2指定学员可见")
private Integer visibleRange;
@ApiModelProperty(value = "调研说明")
private String content;
@ApiModelProperty(value = "调研备注")
private String remark;
@ApiModelProperty(value = "状态,0草稿 1上架 2下架")
private Integer state;
@ApiModelProperty(value = "删除状态:0未删,1已删(默认0)")
private Integer deleted;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "创建人ID")
private Long createById;
@ApiModelProperty(value = "创建人姓名")
private String createByName;
@ApiModelProperty(value = "修改时间")
private Date updateTime;
@ApiModelProperty(value = "修改人ID")
private Long updateById;
@ApiModelProperty(value = "修改人姓名")
private String updateByName;
@ApiModelProperty(value = "下架时间")
private Date unReleaseTime;
@ApiModelProperty(value = "下架人ID")
private Long unReleaseById;
@ApiModelProperty(value = "下架人姓名")
private String unReleaseByName;
@ApiModelProperty(value = "发布时间")
private Date releaseTime;
@ApiModelProperty(value = "发布人ID")
private Long releaseById;
@ApiModelProperty(value = "发布人姓名")
private String releaseByName;
@ApiModelProperty(value = "企业_ID")
private Long companyId;
@ApiModelProperty(value = "部门_ID")
private Long orgId;
@ApiModelProperty(value = "站点_ID")
private Long siteId;
/**
* 该调研可参加人数
*/
@ApiModelProperty(value = "可参加人数")
private Integer count;
/**
* 实际参加人数
*/
@ApiModelProperty(value = "实际参加人数")
private Integer realCount;
/**
* 提醒集合,不持久化
*/
@ApiModelProperty(value = "消息提醒")
private List<TrResearchRemindVo> reminds;
/**
* 关联人员集合
*/
@ApiModelProperty(value = "关联人员")
private List<TrResearchAuthorizeVo> authorizes;
@ApiModelProperty(value = "关联人员id")
private List<Long> relationIds;
/**
* 问题集合,不持久化
*/
@ApiModelProperty(value = "消息提醒")
private List<TrResearchQuestionVo> questions;
@ApiModelProperty(value = "改调研的答卷")
private List<TrResearchAnswerVo> trResearchAnswerVos;
@ApiModelProperty(value = "搜索列表显示状态:1已完成,2进行中,3已过期")
private Integer finishState;
@ApiModelProperty(value = "完成时间")
private Date finishTime;
@ApiModelProperty(value = "提醒vo")
private RemindVo remindVo;
@ApiModelProperty(value = "各个业务设置提醒时的数据")
private MessageRemindVo messageRemindVo;
@ApiModelProperty(value = "关键字,逗号分隔")
private String keywords;
@ApiModelProperty(value = "是否启用在日历任务中显示")
private Integer enableTask;
@ApiModelProperty(value = "调研logo")
private String image;
}
package com.yizhi.research.application.vo.domain;
import com.baomidou.mybatisplus.annotations.TableName;
import io.swagger.annotations.Api;
import lombok.Data;
@Data
@Api(tags = "StatisticsResearchLearnVo", description = "调研明细")
@TableName("statistics_research_learn")
public class StatisticsResearchLearnVo extends StatisticsResearchVo {
private static final long serialVersionUID = -1170397195805248674L;
}
package com.yizhi.research.application.vo.domain;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
@Data
@Api(tags = "StatisticsResearchVo", description = "")
@TableName("statistics_research")
public class StatisticsResearchVo {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键")
private Long id;
@ApiModelProperty(value = "调研ID")
private Long researchId;
@ApiModelProperty(value = "调研编码")
private String researchNo;
@ApiModelProperty(value = "调研名称")
private String researchName;
@ApiModelProperty(value = "调研开始时间")
private Date researchStartTime;
@ApiModelProperty(value = "调研结束时间")
private Date researchEndTime;
@ApiModelProperty(value = "创建调研的企业ID")
private Long researchCompanyId;
@ApiModelProperty(value = "创建调研的站点ID")
private Long researchSiteId;
@ApiModelProperty(value = "创建调研的组织ID")
private Long researchOrgId;
@ApiModelProperty(value = "调研创建时间")
private Date researchCreateTime;
@ApiModelProperty(value = "用户ID")
private Long accountId;
@ApiModelProperty(value = "用户名")
private String accountName;
@ApiModelProperty(value = "用户姓名")
private String accountFullName;
@ApiModelProperty(value = "用户状态")
private Integer accountState;
@ApiModelProperty(value = "工号")
private String accountWorkNum;
@ApiModelProperty(value = "学员企业ID")
private Long accountCompanyId;
@ApiModelProperty(value = "学员企业ID")
private Long accountSiteId;
@ApiModelProperty(value = "学员组织ID")
private Long accountOrgId;
@ApiModelProperty(value = "所在部门")
private String orgName;
@ApiModelProperty(value = "部门所有父节点名称")
private String orgParentNames;
@ApiModelProperty(value = "应参加状态,1应参加 0不应参加(用于统计:应参加人数,MAX取值)")
private Integer canState;
@ApiModelProperty(value = "应参加人数")
private Integer canStateCount;
@ApiModelProperty(value = "实际参加状态,1参加 0未参加(用于统计:实参加人数,MAX取值)")
private Integer joinState;
@ApiModelProperty(value = "实际参加人数")
private Integer joinStateCount;
@ApiModelProperty(value = "调研完成时间")
private Date finishTime;
@ApiModelProperty(value = "调研序号")
private Integer index;
}
package com.yizhi.research.application.vo.domain;
import java.io.Serializable;
import java.util.Date;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import lombok.Data;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
/**
* <p>
* 答案选项
* </p>
*
* @author shengchenglong123
* @since 2018-03-19
*/
@Data
@Api(tags = "TrResearchQuestionResult", description = "答案选项")
@TableName("tr_research_answer_question_result")
public class TrResearchAnswerQuestionResultVo extends Model<TrResearchAnswerQuestionResultVo> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "答案ID,主键")
private Long id;
@ApiModelProperty(value = "冗余调研id")
private Long researchId;
@ApiModelProperty(value = "冗余answerId")
private Long answerId;
@ApiModelProperty(value = "答案题目_ID,外键")
private Long answerQuestionId;
@ApiModelProperty(value = "问题类型,1单选题、2多选题、3问答题、4打分题")
private Integer questionType;
@ApiModelProperty(value = "单选题和多选题,存放问题选中选项的ID")
private Long optionId;
@ApiModelProperty(value = "问答题,存放回答内容(question_type=3)")
private String content;
@ApiModelProperty(value = "打分题,学员给的分值")
private Integer score;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "创建人ID")
private Long createById;
@ApiModelProperty(value = "创建人姓名")
private String createByName;
@ApiModelProperty(value = "修改时间")
private Date updateTime;
@ApiModelProperty(value = "修改人ID")
private Long updateById;
@ApiModelProperty(value = "修改人姓名")
private String updateByName;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.research.application.vo.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* <p>
* 答案题目
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@Data
@Api(tags = "TrResearchAnswerQuestionVo", description = "答案题目")
@TableName("tr_research_answer_question")
public class TrResearchAnswerQuestionVo extends Model<TrResearchAnswerQuestionVo> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "答卷题目ID,主键")
private Long id;
@ApiModelProperty(value = "冗余调研id")
private Long researchId;
@ApiModelProperty(value = "答卷_ID,外键")
private Long answerId;
@ApiModelProperty(value = "问题_ID,外键")
private Long questionId;
@ApiModelProperty(value = "学员_ID")
private Long accountId;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "创建人ID")
private Long createById;
@ApiModelProperty(value = "创建人姓名")
private String createByName;
@ApiModelProperty(value = "修改时间")
private Date updateTime;
@ApiModelProperty(value = "修改人ID")
private Long updateById;
@ApiModelProperty(value = "修改人姓名")
private String updateByName;
@ApiModelProperty(value = "问题答案集合,不持久化")
private List<TrResearchAnswerQuestionResultVo> questionResults;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.research.application.vo.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* <p>
* 答卷
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@Data
@Api(tags = "TrResearchAnswerVo", description = "答卷")
@TableName("tr_research_answer")
public class TrResearchAnswerVo extends Model<TrResearchAnswerVo> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "答卷ID,主键")
private Long id;
@ApiModelProperty(value = "调研主键_ID,外键")
private Long researchId;
@ApiModelProperty(value = "调研名称")
private String name;
@ApiModelProperty(value = "学员_ID")
private Long accountId;
@ApiModelProperty(value = "开始时间,用户进入考试的时间")
private Date startTime;
@ApiModelProperty(value = "提交时间")
private Date submitTime;
@ApiModelProperty(value = "调研用时,分钟")
private Integer duration;
@ApiModelProperty(value = "调研终端类型,1微信 2PC 3APP")
private Integer terminalType;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "创建人ID")
private Long createById;
@ApiModelProperty(value = "创建人姓名")
private String createByName;
@ApiModelProperty(value = "修改时间")
private Date updateTime;
@ApiModelProperty(value = "修改人ID")
private Long updateById;
@ApiModelProperty(value = "修改人姓名")
private String updateByName;
@ApiModelProperty(value = "企业_ID")
private Long companyId;
@ApiModelProperty(value = "部门_ID")
private Long orgId;
@ApiModelProperty(value = "站点_ID")
private Long siteId;
@ApiModelProperty(value = "是否完成 1:已完成(默认) 0:未完成 2:已删除")
private Integer finish;
@ApiModelProperty(value = "该调研答卷下关联的问题,不持久化")
private List<TrResearchAnswerQuestionVo> answerQuestions;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.research.application.vo.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableLogic;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 调研用户范围
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@Data
@Api(tags = "TrResearchAuthorizeVo", description = "调研用户范围")
@TableName("tr_research_authorize")
public class TrResearchAuthorizeVo extends Model<TrResearchAuthorizeVo> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键")
private Long id;
@ApiModelProperty(value = "调研主键_ID,外键")
private Long researchId;
@ApiModelProperty(value = "1. 部门,2.用户,3.用户组")
private Integer type;
@ApiModelProperty(value = "关联id,类型由type判定")
private Long relationId;
@ApiModelProperty(value = "所属站点id")
private Long siteId;
@ApiModelProperty(value = "状态,0删除 1有效(默认有效)")
private Integer state;
@ApiModelProperty(value = "关联人员名称")
private String name;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "创建人ID")
private Long createById;
@ApiModelProperty(value = "创建人姓名")
private String createByName;
@ApiModelProperty(value = "修改时间")
private Date updateTime;
@ApiModelProperty(value = "修改人ID")
private Long updateById;
@ApiModelProperty(value = "修改人姓名")
private String updateByName;
@ApiModelProperty(value = "用户名")
private String fullName;
@ApiModelProperty(value = "工号")
private String workNum;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.research.application.vo.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 只对题型是:单选题、多选题和打分题
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@Data
@Api(tags = "TrResearchQuestionOptionVo", description = "只对题型是:单选题、多选题和打分题")
@TableName("tr_reseach_question_option")
public class TrResearchQuestionOptionVo extends Model<TrResearchQuestionOptionVo> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "选项ID主键")
private Long id;
@ApiModelProperty(value = "所属调研,冗余字段")
private Long researchId;
@ApiModelProperty(value = "问题主键_ID,外键")
private Long questionId;
@ApiModelProperty(value = "问题类型,1单选题、2多选题、3问答题、4打分题")
private Integer questionType;
@ApiModelProperty(value = "选项排序,不能为空")
private Integer no;
@ApiModelProperty(value = "允许填空,对单选和多选有效,0不允许 1允许,默认0")
private Integer editable;
@ApiModelProperty(value = "是否是必填 0 不是 1是")
private Integer required;
@ApiModelProperty(value = "是否是其他选项 0不是 1 是")
private Integer isOther;
@ApiModelProperty(value = "选项内容,最多支持输入500汉字")
private String content;
@ApiModelProperty(value = "最低分值(打分题有效),只对打分题有效")
private Integer minScore;
@ApiModelProperty(value = "最高分值(打分题有效),只对打分题有效")
private Integer maxScore;
@ApiModelProperty(value = "跳题题号(单选题有效),问题设置了跳题才有效,大于当前题号")
private Integer jumpNum;
@ApiModelProperty(value = "指定跳题时才有效,越过的题号")
private Integer[] jumpedNums;
@ApiModelProperty(value = "是否正确答案(选择题有效),0不是 1是默认不是")
private Integer correct;
@ApiModelProperty(value = "是否删除(0:未删,1:已删)")
private Integer deleted;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "创建人ID")
private Long createById;
@ApiModelProperty(value = "创建人姓名")
private String createByName;
@ApiModelProperty(value = "修改时间")
private Date updateTime;
@ApiModelProperty(value = "修改人ID")
private Long updateById;
@ApiModelProperty(value = "修改人姓名")
private String updateByName;
@ApiModelProperty(value = "是否被选中 1选中,0没有选中")
private Integer check = 0;
@ApiModelProperty(value = "问答题 回答内容")
private String answerContent;
@ApiModelProperty(value = "打分题 分数")
private Integer answerScore;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.research.application.vo.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import com.yizhi.research.application.vo.manage.OtherOptionVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* <p>
* 问题
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@Data
@Api(tags = "TrResearchQuestionVo", description = "问题")
@TableName("tr_research_question")
public class TrResearchQuestionVo extends Model<TrResearchQuestionVo> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "问题主键ID,主键")
private Long id;
@ApiModelProperty(value = "调研主键_ID,外键")
private Long researchId;
@ApiModelProperty(value = "问题类型,1单选题、2多选题、3问答题、4打分题")
private Integer type;
@ApiModelProperty(value = "问题内容")
private String content;
@ApiModelProperty(value = "是否是重新进入 1是")
private Integer isFrist =0;
@ApiModelProperty(value = "是否是最后一题 1是")
private Integer isLast =0;
@ApiModelProperty(value = "调研说明,只有第一题有")
private String remark;
@ApiModelProperty(value = "存放附件路径,附件格式:音频、视频、图片")
private String contentAppendixUrl;
@ApiModelProperty(value = "是否必答,0非必答 1必答,默认0")
private Integer needAnswer;
@ApiModelProperty(value = "多选题:最多选择几项,0不选中 >0选中,默认0")
private Integer maxSelectItem;
@ApiModelProperty(value = "多选题:最少选择几项,0不选中 >0选中,默认0")
private Integer minSelectItem;
@ApiModelProperty(value = "最低分值(打分题有效),只对打分题有效")
private Integer minScore;
@ApiModelProperty(value = "最高分值(打分题有效),只对打分题有效")
private Integer maxScore;
@ApiModelProperty(value = "题号,不能为空")
private Integer no;
@ApiModelProperty(value = "是否跳题(单选题需要),0不支持 1支持,默认0(需求改变,这个字段无意义)")
private Integer jumpable;
@ApiModelProperty(value = "问题跳题的类型,1表示根据选项跳题,2表示指定跳题")
private Integer jumpType;
@ApiModelProperty(value = "跳转的题目题号,指定跳题时才有效")
private Integer jumpNum;
@ApiModelProperty(value = "指定跳题时才有效,越过的题号")
private Integer[] jumpedNums;
@ApiModelProperty(value = "上一题的题号")
private Integer lastNo;
@ApiModelProperty(value = "是否删除(0:未删,1:已删)")
private Integer deleted;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "创建人ID")
private Long createById;
@ApiModelProperty(value = "创建人姓名")
private String createByName;
@ApiModelProperty(value = "修改时间")
private Date updateTime;
@ApiModelProperty(value = "修改人ID")
private Long updateById;
@ApiModelProperty(value = "修改人姓名")
private String updateByName;
@ApiModelProperty(value = "企业_ID")
private Long companyId;
@ApiModelProperty(value = "部门_ID")
private Long orgId;
@ApiModelProperty(value = "站点_ID")
private Long siteId;
/**
* 选择题,打分题 选项,不持久化
*/
private List<TrResearchQuestionOptionVo> options;
@ApiModelProperty("是否有题目的跳题是该题目 0没有 1有")
private Integer has;
private OtherOptionVo otherOptionVo;
private Integer hasOther = 0;
@ApiModelProperty(value = "其他选项input框是否必填")
private Integer required = 0;
@ApiModelProperty(value = "调研名称")
private String researchName;
@ApiModelProperty(value = "调研开始时间")
private String startTime;
@ApiModelProperty(value = "调研结束时间")
private String endTime;
@ApiModelProperty(value = "调研说明")
private String researchContent;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.research.application.vo.domain;
import java.io.Serializable;
import java.util.Date;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import lombok.Data;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
/**
* <p>
* 提醒时间
* </p>
*
* @author shengchenglong123
* @since 2018-03-14
*/
@Data
@Api(tags = "TrResearchRemindVo", description = "提醒时间")
@TableName("tr_research_remind")
public class TrResearchRemindVo extends Model<TrResearchRemindVo> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键id")
private Long id;
@ApiModelProperty(value = "关联调研id")
private Long researchId;
@ApiModelProperty(value = "1:开始之前,2:开始之后,3:自定义时间")
private Integer type;
@ApiModelProperty(value = "type=1或type=2:相差秒数")
private Long seconds;
@ApiModelProperty(value = "是否删除(0:未删,1:已删)")
private Integer deleted;
@ApiModelProperty(value = "提醒时间")
private Date time;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "创建人ID")
private Long createById;
@ApiModelProperty(value = "创建人姓名")
private String createByName;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.research.application.vo.manage;
import com.baomidou.mybatisplus.annotations.TableField;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class OtherOptionVo {
@ApiModelProperty(value = "其它选项的id")
private Long id;
@ApiModelProperty(value = "选项内容")
private String content;
@ApiModelProperty(value = "题号")
private Integer no;
@ApiModelProperty(value = "是否是必填 0 不是 1是")
private Integer required;
@ApiModelProperty(value = "允许填空,对单选和多选有效,0不允许 1允许,默认0")
private Integer editable;
@ApiModelProperty(value = "跳题题号")
private Integer jumpNum;
}
package com.yizhi.research.application.vo.manage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @Author: shengchenglong
* @Date: 2018/3/15 11:10
*/
@Data
@Api(tags = "QuestionEditVo", description = "调研问题修改vo")
public class QuestionEditVo {
@ApiModelProperty(value = "所属调研id")
private Long researchId;
@ApiModelProperty(value = "要删除的调研问题的id集合")
private List<Long> deleteIds;
@ApiModelProperty(value = "问题集合", notes = "在编辑时(要么新增,要么只改序号):序号改变的,必传id,no两个字段;新增的,id必定不能传")
private List<QuestionVo> questions;
}
package com.yizhi.research.application.vo.manage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 选择题选项vo,包括单选、多选
*
* @Author: shengchenglong
* @Date: 2018/3/14 09:34
*/
@Data
@Api(tags = "QuestionOptionVo", description = "选择题选项vo,包括单选、多选\n打分题vo")
public class QuestionOptionVo {
@ApiModelProperty(value = "id", notes = "修改时传")
private Long id;
@ApiModelProperty(value = "所有题型有效:选项号,不能为空", required = true)
private Integer no;
@ApiModelProperty(value = "单选和多选有效:允许填空,0不允许 1允许,默认0")
private Integer editable;
@ApiModelProperty(value = "单选和多选有效:0不是,1是,默认不是")
private Integer correct;
@ApiModelProperty(value = "单选题有效:跳题题号,问题设置了跳题才有效,大于当前题号")
private Integer jumpNum;
@ApiModelProperty(value = "选项内容,最多支持输入500汉字")
private String content;
@ApiModelProperty(value = "打分题有效:最高分值")
private Integer maxScore;
@ApiModelProperty(value = "打分题有效:最低分值")
private Integer minScore;
@ApiModelProperty(value = "是否是必填 0 不是 1是")
private Integer required;
@ApiModelProperty(value = "是否是其它选项 0 不是 1是")
private Integer isOther;
}
package com.yizhi.research.application.vo.manage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* @Author: shengchenglong
* @Date: 2018/3/14 09:51
*/
@Data
@Api(tags = "QuestionVo", description = "调研问题vo,包括所有题型")
public class QuestionVo {
@ApiModelProperty(value = "问题id,若是修改,必传;新增的问题,不能传值")
private Long id;
// *************************问题通用属性 开始**********************************
@ApiModelProperty(value = "所属调研id", required = true)
private Long reseachId;
@ApiModelProperty(value = "问题类型,1单选题、2多选题、3问答题、打分题", required = true)
private Integer type;
@ApiModelProperty(value = "所有题型有效:题号,不能为空", required = true)
private Integer no;
@ApiModelProperty(value = "所有题型有效:问题内容")
private String content;
@ApiModelProperty(value = "所有题型有效:存放附件路径,附件格式:音频、视频、图片")
private String contentAppendixUrl;
@ApiModelProperty(value = "所有题型有效:是否必答,0非必答 1必答,默认0")
private Integer needAnswer;
// **************************问题通用属性 结束************************************
// **************************选择题属性 开始************************************
@ApiModelProperty(value = "多选题有效:最多选择几项,0不选中 >0选中,默认0")
private Integer maxSelectItem;
@ApiModelProperty(value = "多选题有效:最少选择几项,0不选中 >0选中,默认0")
private Integer minSelectItem;
// 单选题属性
@ApiModelProperty(value = "单选题有效:是否跳题,0不支持 1支持,默认0")
private Integer jumpable;
// **************************选择题属性 结束************************************
// **************************打分题属性 开始************************************
@ApiModelProperty(value = "打分题有效:最高分值")
private Integer maxScore;
@ApiModelProperty(value = "打分题有效:最低分值")
private Integer minScore;
// **************************打分题属性 结束************************************
@ApiModelProperty(value = "选择题和打分题有效:问题选项")
private List<QuestionOptionVo> questionOptions = new ArrayList<>();
@ApiModelProperty(value = "问题跳题的类型,1表示根据选项跳题,2表示指定跳题")
private Integer jumpType;
@ApiModelProperty(value = "跳转的题目题号,指定跳题时才有效")
private Integer jumpNum;
@ApiModelProperty(value = "其他选项,单独拿出来")
private OtherOptionVo otherOption;
@ApiModelProperty(value = "是否有其他")
private Integer hasOther;
}
package com.yizhi.research.application.vo.manage;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @Author: shengchenglong
* @Date: 2018/3/14 17:15
*/
@Data
@Api(tags = "RemindVo", description = "提醒时间vo(修改时未改的字段勿传值也勿传空字符串)")
public class RemindTimeVo {
@ApiModelProperty(value = "提醒时间id(仅update时可传)")
private Long id;
@ApiModelProperty(value = "1:开始之前,2:开始之后,3:自定义时间")
private Integer type;
@ApiModelProperty(value = "开始之前或开始之后:相差秒数")
private Integer seconds;
@ApiModelProperty(value = "自定义时间:确定时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date time;
}
package com.yizhi.research.application.vo.manage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @Author: shengchenglong
* @Date: 2018/3/14 17:05
*/
@Data
@Api(tags = "RemindVo", description = "提醒vo")
public class RemindVo {
@ApiModelProperty(value = "开启邮件提醒(0:否,1:是)", required = true)
private Integer enableMail;
@ApiModelProperty(value = "开启站内消息提醒(0:否,1:是)", required = true)
private Integer enableApp;
@ApiModelProperty(value = "邮件模板id")
private Long mailTemplateId;
@ApiModelProperty(value = "站内消息模板id")
private Long appTemplateId;
@ApiModelProperty(value = "提醒内容")
private String content;
@ApiModelProperty(value = "提醒时间集合")
private List<RemindTimeVo> remindTimes;
}
package com.yizhi.research.application.vo.manage;
import java.util.Date;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yizhi.research.application.vo.MessageRemindVo;
import com.yizhi.research.application.vo.domain.TrResearchAuthorizeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 保存resrarch vo
*
* @Author: shengchenglong
* @Date: 2018/3/13 11:06
*/
@Data
@Api(tags = "ResearchVo", description = "后台保存调研vo(修改时未改的字段勿传值也勿传空字符串)")
public class ResearchVo {
@ApiModelProperty(value = "调研id(仅update时可传)")
private Long id;
@ApiModelProperty(value = "调研名称")
private String name;
@ApiModelProperty(value = "调研开始时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date startTime;
@ApiModelProperty(value = "调研结束时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date endTime;
@ApiModelProperty(value = "可见范围,1平台用户可见(企业下所有人员) 2指定学员可见")
private Integer visibleRange;
@ApiModelProperty(value = "调研说明")
private String content;
@ApiModelProperty(value = "调研备注")
private String remark;
@ApiModelProperty(value="调研指定的人员(仅当visibleRange=2时可传)")
private List<TrResearchAuthorizeVo> trResearchAuthorize;
@ApiModelProperty(value = "提醒vo")
private RemindVo remindVo;
@ApiModelProperty(value = "是否有提醒")
private Integer remind;
@ApiModelProperty(value = "积分,默认0")
private Integer point;
@ApiModelProperty(value = "各个业务设置提醒时的数据")
private MessageRemindVo messageRemindVo;
private String keywords;
@ApiModelProperty(value = "调研logo")
private String image;
@ApiModelProperty(value = "是否启用在日历任务中显示")
private Integer enableTask;
}
package com.yizhi.research.application.vo.report;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.research.application.vo.domain.TrResearchQuestionVo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@Data
public class DownloadParamsVoOnTime {
@ApiModelProperty(value = "调研ID")
private Long researchId;
@ApiModelProperty(value = "调研名字")
private String resesrchName;
@ApiModelProperty(value = "上下文")
private RequestContext context;
@ApiModelProperty(value = "开始时间(调研时间)")
private String startTime;
@ApiModelProperty(value = "结束时间(调研时间)")
private String endTime;
@ApiModelProperty(value = "部门关键字或者部门编码")
private String orgNameorOrgCode;
@ApiModelProperty(value = "用户关键字")
private String accountName;
@ApiModelProperty(value = "参加状态")
private Integer joinState;
@ApiModelProperty(value = "任务名称")
private String taskName;
@ApiModelProperty(value = "任务序号")
private String serialNo;
@ApiModelProperty(value = "任务id")
private Long taskId;
@ApiModelProperty(value = "调研问题集合")
private List<TrResearchQuestionVo> trResearchQuestionVos = new ArrayList<>();
}
package com.yizhi.research.application.vo.report;
import com.yizhi.research.application.vo.api.ViewAnswerQuestionVo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
public class ReportResearchAnalyze {
@ApiModelProperty(value= "调研id")
private Long researchId;
@ApiModelProperty(value= "题目总数")
private Integer questionCount = 0;
@ApiModelProperty(value= "提交问卷份数")
private Integer submitCount = 0;
@ApiModelProperty(value= "可参加人数")
private Integer joinCount = 0;
@ApiModelProperty(value= "实际参加人数")
private Integer realJoinCount = 0;
@ApiModelProperty(value= "题目以及选项")
private List<ViewAnswerQuestionVo> viewAnswerQuestionVOs;
}
package com.yizhi.research.application.vo.report;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* 调研查看
* @author mei
*
*/
@Data
public class ResearchGroupViewVo {
@ApiModelProperty(value= "用户id")
private Long accountId;
@ApiModelProperty(value = "用户名")
private String accountName;
@ApiModelProperty(value = "姓名")
private String accountFullName;
@ApiModelProperty(value = "所在部门")
private String orgName;
@ApiModelProperty(value="所在部门父类")
private String orgParentNames;
@ApiModelProperty(value = "是否参加 1:表示已经参加 0:表示未参加")
private Integer joinState=0;
@ApiModelProperty(value = "提交时间")
private Date finishTime;
@ApiModelProperty(value = "用户状态")
private Integer accountState;
@ApiModelProperty(value = "序号")
private Integer index;
}
package com.yizhi.research.application.vo.report;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* 调研统计
* @author mei
*
*/
@Data
public class ResearchGroupVo {
@ApiModelProperty(value = "调研ID")
private Long researchId;
@ApiModelProperty(value = "序号")
private Integer index;
@ApiModelProperty(value = "调研名称")
private String researchName ;
@ApiModelProperty(value = "开始时间(调研时间)")
private Date researchStartTime;
@ApiModelProperty(value = "结束时间(调研时间)")
private Date researchEndTime;
@ApiModelProperty(value = "可参加人数(空返回0)")
private Integer canStateCount = 0;
@ApiModelProperty(value = "实际参加人数(空返回0)")
private Integer joinStateCount = 0;
@ApiModelProperty(value = "用户状态")
private Integer accountState;
@ApiModelProperty(value = "管理员类别")
private Integer rangeType;
}
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<parent>
<groupId>com.yizhi</groupId>
<artifactId>cloud-research</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.yizhi</groupId>
<artifactId>cloud-research-service</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-common-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-util</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-orm</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-core</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-research-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-newMessage-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-system-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- deploy 时跳过该模块 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
package com.yizhi.research.application;
import org.apache.commons.collections.CollectionUtils;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.ParameterMapping;
import org.apache.ibatis.plugin.*;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.type.TypeHandlerRegistry;
import java.text.DateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.regex.Matcher;
@Intercepts({
@Signature(type = Executor.class, method = "update", args = {
MappedStatement.class, Object.class}),
@Signature(type = Executor.class, method = "query", args = {
MappedStatement.class, Object.class, RowBounds.class,
ResultHandler.class})})
@SuppressWarnings({"unchecked", "rawtypes"})
public class MybatisInterceptor implements Interceptor {
@Override
public Object intercept(Invocation invocation) throws Throwable {
try {
MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0]; // 获取xml中的一个select/update/insert/delete节点,主要描述的是一条SQL语句
Object parameter = null;
// 获取参数,if语句成立,表示sql语句有参数,参数格式是map形式
if (invocation.getArgs().length > 1) {
parameter = invocation.getArgs()[1];
System.out.println("parameter = " + parameter);
}
String sqlId = mappedStatement.getId(); // 获取到节点的id,即sql语句的id
System.out.println("sqlId = " + sqlId);
BoundSql boundSql = mappedStatement.getBoundSql(parameter); // BoundSql就是封装myBatis最终产生的sql类
Configuration configuration = mappedStatement.getConfiguration(); // 获取节点的配置
String sql = getSql(configuration, boundSql, sqlId); // 获取到最终的sql语句
System.out.println("sql = " + sql);
//log.debug(sql);
} catch (Exception e) {
// log.error(e.getMessage(), e);
}
return invocation.proceed(); // 执行完上面的任务后,不改变原有的sql执行过程
}
// 封装了一下sql语句,使得结果返回完整xml路径下的sql语句节点id + sql语句
public static String getSql(Configuration configuration, BoundSql boundSql, String sqlId) {
String sql = showSql(configuration, boundSql);
StringBuilder str = new StringBuilder(100);
str.append(sqlId);
str.append(":");
str.append(sql);
return str.toString();
}
/*<br> *如果参数是String,则添加单引号, 如果是日期,则转换为时间格式器并加单引号; 对参数是null和不是null的情况作了处理<br>  */
private static String getParameterValue(Object obj) {
String value = null;
if (obj instanceof String) {
value = "'" + obj.toString() + "'";
} else if (obj instanceof Date) {
DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.CHINA);
value = "'" + formatter.format(new Date()) + "'";
} else {
if (obj != null) {
value = obj.toString();
} else {
value = "";
}
}
return value;
}
// 进行?的替换
public static String showSql(Configuration configuration, BoundSql boundSql) {
Object parameterObject = boundSql.getParameterObject(); // 获取参数
List<ParameterMapping> parameterMappings = boundSql
.getParameterMappings();
String sql = boundSql.getSql().replaceAll("[\\s]+", " "); // sql语句中多个空格都用一个空格代替
if (CollectionUtils.isNotEmpty(parameterMappings) && parameterObject != null) {
TypeHandlerRegistry typeHandlerRegistry = configuration.getTypeHandlerRegistry(); // 获取类型处理器注册器,类型处理器的功能是进行java类型和数据库类型的转换<br>       // 如果根据parameterObject.getClass()可以找到对应的类型,则替换
if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) {
sql = sql.replaceFirst("\\?", Matcher.quoteReplacement(getParameterValue(parameterObject)));
} else {
MetaObject metaObject = configuration.newMetaObject(parameterObject);// MetaObject主要是封装了originalObject对象,提供了get和set的方法用于获取和设置originalObject的属性值,主要支持对JavaBean、Collection、Map三种类型对象的操作
for (ParameterMapping parameterMapping : parameterMappings) {
String propertyName = parameterMapping.getProperty();
if (metaObject.hasGetter(propertyName)) {
Object obj = metaObject.getValue(propertyName);
sql = sql.replaceFirst("\\?", Matcher.quoteReplacement(getParameterValue(obj)));
} else if (boundSql.hasAdditionalParameter(propertyName)) {
Object obj = boundSql.getAdditionalParameter(propertyName); // 该分支是动态sql
sql = sql.replaceFirst("\\?", Matcher.quoteReplacement(getParameterValue(obj)));
} else {
sql = sql.replaceFirst("\\?", "缺失");
}//打印出缺失,提醒该参数缺失并防止错位
}
}
}
return sql;
}
@Override
public Object plugin(Object target) {
return Plugin.wrap(target, this);
}
@Override
public void setProperties(Properties properties) {
}
}
\ No newline at end of file
package com.yizhi.research.application;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(basePackages = {"com.yizhi"})
@ComponentScan(basePackages = {"com.yizhi"})
public class ResearchApplication {
public static void main(String[] args) {
SpringApplication.run(ResearchApplication.class, args);
}
}
package com.yizhi.research.application;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("考试-调研")
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.fulan.application"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("调研")
//版本
.version("1.0")
.build();
}
}
package com.yizhi.research.application.controller;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.core.application.vo.DroolsVo;
import com.yizhi.research.application.mapper.ResearchMapper;
import com.yizhi.research.application.model.CopyResearchModel;
import com.yizhi.research.application.service.IResearchService;
import com.yizhi.research.application.vo.BaseModel;
import com.yizhi.research.application.vo.CalendarTaskParamVo;
import com.yizhi.research.application.vo.api.CheckResearchStateVo;
import com.yizhi.research.application.vo.api.PageVo;
import com.yizhi.research.application.vo.api.SearchVo;
import com.yizhi.research.application.vo.domain.*;
import com.yizhi.util.application.beanutil.BeanCopyListUtil;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import java.util.*;
/**
* <p>
* 调研 前端控制器
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@RestController
@RequestMapping("/research")
public class ResearchController {
@Autowired
private IResearchService researchService;
@Autowired
private ResearchMapper researchMapper;
/**
* 新增调研接口
*
* @return
*/
@PostMapping("/insert")
public Research insert(@RequestBody ResearchVo research) {
Research research1=new Research();
BeanUtils.copyProperties(research,research1);
List<TrResearchRemindVo> list=research.getReminds();
List<TrResearchRemind> list1=new ArrayList<>();
if (CollectionUtil.isNotEmpty(list)) {
list1 = BeanCopyListUtil.copyListProperties(list, TrResearchRemind::new);
}
List<TrResearchAuthorizeVo> list2 = research.getAuthorizes();
List<TrResearchAuthorize> list3 = new ArrayList<>();
if (CollectionUtil.isNotEmpty(list2)) {
list3 = BeanCopyListUtil.copyListProperties(list2, TrResearchAuthorize::new);
}
List<TrResearchQuestionVo> list4 = research.getQuestions();
List<TrResearchQuestion> list5 = new ArrayList<>();
if (CollectionUtil.isNotEmpty(list4)) {
list5 = BeanCopyListUtil.copyListProperties(list4, TrResearchQuestion::new);
}
List<TrResearchAnswerVo> list6 = research.getTrResearchAnswerVos();
List<TrResearchAnswer> list7 = new ArrayList();
if (CollectionUtil.isNotEmpty(list6)) {
list7 = BeanCopyListUtil.copyListProperties(list6, TrResearchAnswer::new);
}
research1.setReminds(list1);
research1.setAuthorizes(list3);
research1.setQuestions(list5);
research1.setTrResearchAnswers(list7);
return researchService.insertResearch(research1);
}
/**
* 查看调研接口
*
* @return
*/
@GetMapping("/view")
public Research viewOne(@RequestParam("id") Long id) {
Research research = researchService.viewOne(id);
return research;
}
/**
* 分页列表
*
* @return
*/
@GetMapping("/page/list")
public Page<Research> listPage(@RequestBody BaseModel<Page<Research>> model) {
Page<Research> page = model.getObj();
RequestContext context = model.getContext();
Map map = page.getCondition();
Integer pageNo = page.getCurrent();
Integer pageSize = page.getSize();
return researchService.listPage(map, context, pageNo, pageSize);
}
@GetMapping("/page/poolExamList")
public Page<Map<String, Object>> getPoolExamList(@RequestParam(value = "name", required = false) String name,
@RequestParam(value = "ids", required = false) List<Long> ids,
@RequestParam(value = "pageNo", required = false) Integer pageNo,
@RequestParam(value = "pageSize", required = false) Integer pageSize) {
return researchService.getPoolExamList(name, ids, pageNo, pageSize);
}
/**
* 批量删除
*
* @return
*/
@PostMapping("/batch/delete")
public int batchDelete(@RequestBody List<Long> ids) {
return researchService.batchDelete(ids);
}
/**
* 更新一个调研,包含提醒(删除以前的提醒)
*
* @param research
* @return
*/
@PostMapping("/update")
public int update(@RequestBody ResearchVo research) {
Research research1=new Research();
BeanUtils.copyProperties(research,research1);
List<TrResearchRemindVo> list=research.getReminds();
List<TrResearchRemind> list1=new ArrayList<>();
if (CollectionUtil.isNotEmpty(list)) {
list1 = BeanCopyListUtil.copyListProperties(list, TrResearchRemind::new);
}
List<TrResearchAuthorizeVo> list2 = research.getAuthorizes();
List<TrResearchAuthorize> list3 = new ArrayList<>();
if (CollectionUtil.isNotEmpty(list2)) {
list3 = BeanCopyListUtil.copyListProperties(list2, TrResearchAuthorize::new);
}
List<TrResearchQuestionVo> list4 = research.getQuestions();
List<TrResearchQuestion> list5 = new ArrayList<>();
if (CollectionUtil.isNotEmpty(list4)) {
list5 = BeanCopyListUtil.copyListProperties(list4, TrResearchQuestion::new);
}
List<TrResearchAnswerVo> list6 = research.getTrResearchAnswerVos();
List<TrResearchAnswer> list7 = new ArrayList();
if (CollectionUtil.isNotEmpty(list6)) {
list7 = BeanCopyListUtil.copyListProperties(list6, TrResearchAnswer::new);
}
research1.setReminds(list1);
research1.setAuthorizes(list3);
research1.setQuestions(list5);
research1.setTrResearchAnswers(list7);
return researchService.update(research1);
}
/**
* 上架 或 下架
*
* @param research
* @return
*/
@PostMapping("/release")
public Research upOrDown(@RequestBody ResearchVo research) throws Exception {
Research research1=new Research();
BeanUtils.copyProperties(research,research1);
List<TrResearchRemindVo> list=research.getReminds();
List<TrResearchRemind> list1=new ArrayList<>();
if (CollectionUtil.isNotEmpty(list)) {
list1 = BeanCopyListUtil.copyListProperties(list, TrResearchRemind::new);
}
List<TrResearchAuthorizeVo> list2 = research.getAuthorizes();
List<TrResearchAuthorize> list3 = new ArrayList<>();
if (CollectionUtil.isNotEmpty(list2)) {
list3 = BeanCopyListUtil.copyListProperties(list2, TrResearchAuthorize::new);
}
List<TrResearchQuestionVo> list4 = research.getQuestions();
List<TrResearchQuestion> list5 = new ArrayList<>();
if (CollectionUtil.isNotEmpty(list4)) {
list5 = BeanCopyListUtil.copyListProperties(list4, TrResearchQuestion::new);
}
List<TrResearchAnswerVo> list6 = research.getTrResearchAnswerVos();
List<TrResearchAnswer> list7 = new ArrayList();
if (CollectionUtil.isNotEmpty(list6)) {
list7 = BeanCopyListUtil.copyListProperties(list6, TrResearchAnswer::new);
}
research1.setReminds(list1);
research1.setAuthorizes(list3);
research1.setQuestions(list5);
research1.setTrResearchAnswers(list7);
return researchService.upOrDown(research1);
}
/**
* 复制调研
*
* @param model
* @return
*/
@PostMapping("/copy")
public Research copyResearch(@RequestBody CopyResearchModel model) throws Exception {
return researchService.copyResearch(model.getResearchId(), model.getRequestContext(), model.getDate());
}
/**
* 学员端分页列表
*
* @param model
* @return
*/
@GetMapping("api/page/list")
public Page<Research> apiListPage(@RequestBody BaseModel<PageVo> model) {
return researchService.apiListPage(model);
}
/**
* 学员端模糊查询分页列表
*
* @param searchVo
* @return
*/
@GetMapping("api/search/page/list")
public Page<Research> apiSearchPage(@RequestBody SearchVo searchVo) {
String name = searchVo.getName();
RequestContext context = searchVo.getContext();
int pageNo = searchVo.getPageNo();
int pageSize = searchVo.getPageSize();
return researchService.apiSearchPage(name, context, pageNo, pageSize);
}
/**
* 我的调研进行中的个数
*
* @param context
* @return
*/
@GetMapping("/api/count")
public Integer searchUnfinishCount(@RequestBody RequestContext context) {
return researchService.searchUnfinishCount(context);
}
/**
* 我的调研状态检查
*
* @param checkResearchStateVo
* @return
*/
@PostMapping("/state/check")
Integer checkResearchState(@RequestBody CheckResearchStateVo checkResearchStateVo) {
return researchService.checkResearchState
(checkResearchStateVo.getResearchId(), checkResearchStateVo.getContext());
}
/**
* 调研报表列表
*
* @param startDate
* @param endDate
* @param kwd
* @param pageSize
* @param pageNo
* @param orgIds
* @param companyId
* @param siteId
* @return
*/
@GetMapping("/group")
public Page<Research> getResearchList(@RequestParam(name = "startDate", required = false) String startDate, @RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name = "kwd", required = false) String kwd, @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
@RequestParam(name = "pageNo", required = false, defaultValue = "1") Integer pageNo, @RequestParam(name = "orgIds", required = false) List<Long> orgIds,
@RequestParam(name = "companyId", required = true) Long companyId, @RequestParam(name = "siteId", required = true) Long siteId
) {
return researchService.getResearchList(startDate, endDate, kwd, pageSize, pageNo, orgIds, companyId, siteId);
}
/**
* 某个调研的人员完成情况
*
* @param researchId
* @return
*/
@GetMapping("/group/view")
public Research getResearchView(@RequestParam(name = "researchId", required = true) Long researchId) {
return researchService.getResearchView(researchId);
}
@GetMapping(value="/by/new/server")
public List<Map<String, Object>> getServerByCompanyIdAndIds(@RequestParam("companyId")Long companyId,@RequestParam(value="ids",required=false)List<Long> ids){
return researchService.getServerByCompanyIdAndIds(companyId, ids);
}
/**
* @param researchId
* @return
*/
@PostMapping("/delete")
public Integer delete(@RequestBody Map map) {
Long researchId = new Long(map.get("researchId").toString()) ;
Research research = researchService.selectById(researchId);
if (null == research) {
// throw new BizException("4000", "数据不存在,无法删除!"); 如果直接抛出异常会导致fein接口404
return -1;
}
if (null != research.getTrainingProjectId()) {
// throw new BizException("4000", "已关联培训项目,无法删除!");
return -2;
}
if (research.getState() == 1) {
// throw new BizException("4000", "上架状态,无法删除!");
return -3;
}
Research r = new Research();
r.setId(researchId);
r.setDeleted(1);
return (researchService.updateById(r) == true ? 1 : 0);
}
@GetMapping ("/getAllResearch")
public List<Research> getAllResearch() {
return researchMapper.getAllResearchs();
}
@GetMapping ("/selectRecordMinTime")
public Date selectRecordMinTime() {
return researchMapper.selectRecordMinTime();
}
@GetMapping ("/getAllSiteId")
public List<Long> getAllSiteId() {
List<Research> lists = researchMapper.getAllResearchs();
Set<Long> sets = new HashSet<>();
List<Long> allSiteIds = new ArrayList<>();
lists.forEach(a -> {
if (a.getSiteId() != null) {
sets.add(a.getSiteId());
}
});
allSiteIds.addAll(sets);
return allSiteIds;
}
@GetMapping("/getPointById")
public Integer getPointByIds(@RequestParam(value = "ids",required = false) List<Long> ids) {
if (CollectionUtils.isEmpty(ids)) {
return null;
}
EntityWrapper wrapper = new EntityWrapper();
wrapper.setSqlSelect("point");
wrapper.in("id", ids);
List<Research> list = this.researchMapper.selectList(wrapper);
Integer pointTotal = 0;
if (!CollectionUtils.isEmpty(list)) {
for (Research research : list) {
Integer point = research.getPoint();
point = (point == null ? 0 : point);
pointTotal = pointTotal + point;
}
}
return pointTotal;
}
@PostMapping("/getPageToCalendar")
public Page<Research> getPageToCalendar(@ApiParam("paramVo") @RequestBody CalendarTaskParamVo paramVo){
Page<Research> page = new Page(paramVo.getPageNo(), paramVo.getPageSize());
return researchService.getPageToCalendar(paramVo.getDate(),page);
}
@GetMapping("/getPageByDrools")
Page<DroolsVo> getPageByDrools(@RequestParam("field") String field,
@RequestParam(value = "value", required = false) String value,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize) {
Page<DroolsVo> page = new Page<>(pageNo, pageSize);
return researchService.getPageByDrools(field, value, page);
}
}
package com.yizhi.research.application.controller;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.research.application.download.DownloadResearchAnalyze;
import com.yizhi.research.application.download.DownloadResearchAnalyze1;
import com.yizhi.research.application.download.DownloadResearchDetails;
import com.yizhi.research.application.service.StatisticsResearchService;
import com.yizhi.research.application.vo.domain.StatisticsResearch;
import com.yizhi.research.application.vo.report.DownloadParamsVoOnTime;
import com.yizhi.util.application.domain.Response;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/statisticsResearch")
public class StatisticsResearchController {
@Autowired
private StatisticsResearchRun statisticsResearchRun;
@Autowired
private StatisticsResearchService statisticsResearchService;
@Autowired
private DownloadResearchDetails downloadResearchDetails;
@Autowired
private DownloadResearchAnalyze downloadResearchAnalyze;
@Autowired
private DownloadResearchAnalyze1 downloadResearchAnalyze1;
private Logger LOGGER = LoggerFactory.getLogger(StatisticsResearchController.class);
@GetMapping("/asynchronous/load/data")
public Response<String> asynchronousResearch(@RequestParam("startDate") String startDate, @RequestParam("endDate") String endDate){
Map<String,Object> map=new HashMap<String,Object>();
map.put("startDate", startDate);
map.put("endDate", endDate);
statisticsResearchRun.execute(map,true);
return Response.ok();
}
@ApiOperation(value = "调研统计", notes = "调研统计", response = StatisticsResearch.class)
@GetMapping("/group")
public Page<StatisticsResearch> researchGroup(@RequestParam(name = "startDate", required = false) String startDate,
@RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name = "kwd", required = false) String kwd,
@RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
@RequestParam(name = "pageNo", required = false, defaultValue = "1") Integer pageNo,
@RequestParam(name= "companyId" ,required = true) Long companyId,
@RequestParam(name= "orgIds" ,required = false) List<Long> orgIds,
@RequestParam(name= "siteId" ,required = true) Long siteId){
return statisticsResearchService.researchGroup(startDate,endDate,kwd,pageSize,pageNo,companyId,orgIds,siteId);
}
@ApiOperation(value = "调研参与人员的统计" ,notes = "调研参与人员的统计" ,response =StatisticsResearch.class)
@GetMapping("/group/view")
public Page<StatisticsResearch> researchGroupView(
@RequestParam(name = "startDate", required = false) String startDate,
@RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name= "researchId" ,required = true) Long researchId,
@RequestParam(name = "orgNameorOrgCode" ,required = false) String orgNameorOrgCode,
@RequestParam(name = "accountName" ,required = false )String accountName,
@RequestParam(name= "state" ,required = false) Integer state,
@RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
@RequestParam(name = "pageNo", required = false, defaultValue = "1") Integer pageNo){
return statisticsResearchService.selectResearchView(researchId,startDate,endDate,orgNameorOrgCode,accountName,state,pageNo,pageSize);
}
@GetMapping("/group/view/state/count")
public StatisticsResearch getCanStateCount(
@RequestParam(name = "startDate", required = false) String startDate,
@RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name= "researchId" ,required = true) Long researchId,
@RequestParam(name = "orgNameorOrgCode" ,required = false) String orgNameorOrgCode,
@RequestParam(name = "accountName" ,required = false )String accountName,
@RequestParam(name= "state" ,required = false) Integer state
){
return statisticsResearchService.selectJoinCount(researchId,startDate,endDate,orgNameorOrgCode,accountName,state);
}
@ApiOperation(value = "下载调研参与人员的统计" ,notes = "下载参与人员的统计" ,response =StatisticsResearch.class)
@GetMapping("/export/research/accounts")
public List<StatisticsResearch> researchList(
@RequestParam(name = "startDate", required = false) String startDate,
@RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name= "researchId" ,required = true) Long researchId,
@RequestParam(name = "orgNameorOrgCode" ,required = false) String orgNameorOrgCode,
@RequestParam(name = "accountName" ,required = false )String accountName,
@RequestParam(name= "state" ,required = false) Integer state){
return statisticsResearchService.researchViewList(researchId,orgNameorOrgCode,accountName,state,startDate,endDate);
}
@ApiOperation(value = "下载调研参与人员的统计个数" ,notes = "下载参与人员的统计个数" ,response =StatisticsResearch.class)
@GetMapping("/export/research/accounts/count")
public Integer researchViewCount(
@RequestParam(name = "startDate", required = false) String startDate,
@RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name= "researchId" ,required = true) Long researchId,
@RequestParam(name = "orgNameorOrgCode" ,required = false) String orgNameorOrgCode,
@RequestParam(name = "accountName" ,required = false )String accountName,
@RequestParam(name= "state" ,required = false) Integer state
){
return statisticsResearchService.selectResearchViewCount(researchId,startDate,endDate,orgNameorOrgCode,accountName,state) ;
}
@ApiOperation(value = "调研参与人员的统计" ,notes = "调研参与人员的统计" ,response =StatisticsResearch.class)
@GetMapping("/group/views")
public List<StatisticsResearch> researchViews(
@RequestParam(name = "startDate", required = false) String startDate,
@RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name= "researchId" ,required = true) Long researchId,
@RequestParam(name = "orgNameorOrgCode" ,required = false) String orgNameorOrgCode,
@RequestParam(name = "accountName" ,required = false )String accountName,
@RequestParam(name= "state" ,required = false) Integer state,
@RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
@RequestParam(name = "pageNo", required = false, defaultValue = "1") Integer pageNo){
return statisticsResearchService.researchViews(researchId,startDate,endDate,orgNameorOrgCode,accountName,state,pageNo,pageSize);
}
@ApiOperation (value = "实时导出调研明细", notes = "导出调研明细")
@PostMapping("/details/Excel/onTime")
public String reportResearchDetails(@RequestBody DownloadParamsVoOnTime vo) {
try {
downloadResearchDetails.execute(vo, true);
return "任务名称:" + vo.getTaskName() + ",任务序号:" + vo.getSerialNo();
} catch (Exception e) {
LOGGER.error("", e);
return null;
}
}
@ApiOperation (value = "实时导出调研分析统计", notes = "导出调研分析统计")
@PostMapping ("/analyze/Excel/onTime")
public String reportResearchanalyze(@RequestBody DownloadParamsVoOnTime vo) {
try {
downloadResearchAnalyze1.execute(vo, true);
// downloadResearchAnalyze.execute(vo, true);
return "任务名称:" + vo.getTaskName() + ",任务序号:" + vo.getSerialNo();
} catch (Exception e) {
LOGGER.error("", e);
return null;
}
}
}
package com.yizhi.research.application.controller;
import java.util.Map;
import com.yizhi.core.application.file.task.AbstractDefaultTask;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSON;
@Component
public class StatisticsResearchRun extends AbstractDefaultTask<String,Map<String,Object>> {
@Override
protected String execute(Map<String, Object> map) {
return null;
}
// private Logger logger = LoggerFactory.getLogger(StatisticsResearchRun.class);
//
// @Autowired
// private StatisticsResearchMapper statisticsResearchMapper;
//
// @Autowired
// private StatisticsResearchService statisticsResearchService;
//
// @Autowired
// IdGenerator idGenerator;
//
// @Autowired
// private ReportClient reportClient;
//
// private int pageNo = 1;
//
// private int pageSize = 50;
//
// /**
// * 缓存学员学习信息
// */
// private final Map<String, Map<Long, StatisticsResearch>> accountMap = new HashMap<String, Map<Long, StatisticsResearch>>();
//
// @Override
// public String execute(Map<String, Object> map) {
//
// Date startRunDate = new Date();
//
// SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");
//
// Long taskId = idGenerator.generate();
// TaskContext taskContext = new TaskContext(taskId, formatDate.format(startRunDate) + " 在线调研报表分析", 999L, startRunDate);
// working(taskContext);
//
// String startDate = null;
// String endDate = null;
// Date dCurDate = null;
//
// if(map != null){
// startDate = (String) map.get("startDate");
// endDate = (String) map.get("endDate");
// }
//
// if (startDate == null || "".equals(startDate)) {
// Date middleMaxTime = statisticsResearchMapper.selectMaxDate();
// if (middleMaxTime != null) {
// dCurDate = addDay(middleMaxTime, 1);
// startDate = formatDate.format(dCurDate);
// } else {
// Date recordMinTime = statisticsResearchMapper.selectRecordMinTime();
// startDate = formatDate.format(recordMinTime);
// }
// }
// if (endDate == null || "".equals(endDate)) {
// dCurDate = addDay(new Date(), -1);
// endDate = formatDate.format(dCurDate);
// }
//
// Long day = 0L;
// Date beginDate = null;
// try {
// beginDate = formatDate.parse(startDate);
// Date end = formatDate.parse(endDate);
// day = (end.getTime() - beginDate.getTime()) / (24 * 60 * 60 * 1000);
// } catch (ParseException e1) {
// return null;
// }
//
// List<StatisticsResearch> insertList = new ArrayList<StatisticsResearch>();
//
// // 获得所有的调研(条件:未上架/已上架,没有被删除的调研)
// List<Research> getAllResearch = statisticsResearchMapper.getAllResearchs(startDate, endDate);
//
//
// //指定范围可见的调研人员的IdList
// List<Long> listAccountIdRange = new ArrayList<>();
//
// // 先删除这天的记录再添加,防止一天添加多次记录
// for (int d = 0; d <= day; d++) {
// String currentDate = startDate;
// if (d > 0) {
// dCurDate = addDay(beginDate, d);
// currentDate = formatDate.format(dCurDate);
// }
// statisticsResearchMapper.deleteRecordeByDate(currentDate);
// }
//
// taskDetail(taskId, "***** 调研统计开始 *****");
//
// String rangeKey = "";
// List<StatisticsResearchLearn> accountLearnIds = null;
//
// boolean isOk = true;
// String curResearchName = "";
// Long curResearchId = 0L;
//
// try{
// // 按调研遍历学员学习记录
// for (Research research : getAllResearch) {
// // 判断调研在所有日期中是否有学习记录,没有就添加一条空的学习记录
// Long researchId = research.getId();
// String researchName = research.getName();
// curResearchId = researchId;
// curResearchName = researchName;
//
// Long examSiteId = research.getSiteId(); // 调研的站点ID
// Integer scope = research.getVisibleRange(); // 可见范围 1 平台用户 2
// // 指定范围
// if (scope != null && scope == 2) { // 如果是指定范围 不是根据站点Id找人
// listAccountIdRange = statisticsResearchMapper.getAllRelationId(researchId);
// if (null == listAccountIdRange) {
// taskDetail(taskId, researchName + "(" + researchId + ")" + " 未设置指定范围,请确认是否为该调研设置的范围,无法统计数据");
// rangeKey = "";
// } else {
// rangeKey = examSiteId.toString() + listAccountIdRange.toString();
// }
// examSiteId = null;
// } else {
// listAccountIdRange = null;
// if (examSiteId != null) {
// rangeKey = examSiteId.toString();
// } else {
// rangeKey = "";
// taskDetail(taskId,
// researchName + "(" + researchId + ")" + " 全平台可见为空:(" + examSiteId + ") 请确认数据,无法统计数据");
// }
// }
// if ("".equals(rangeKey)) {
// continue;
// }
//
// // 从缓存中获取用户,没有找到再请求system查询
// Map<Long, StatisticsResearch> resultccountMap = accountMap.get(rangeKey);
// if (resultccountMap == null) {
// resultccountMap = new HashMap<Long, StatisticsResearch>();
// getReportAccountRespVO(research.getSiteId(), listAccountIdRange, pageNo, pageSize, null, resultccountMap,
// rangeKey, taskId, researchName + "(" + researchId + ")");
// if (resultccountMap.size() == 0) {
// if (examSiteId == null) {
// taskDetail(taskId, researchName + "(" + researchId + ")" + " 没有查找到该站点(" + research.getSiteId() + ")下" + "指定范围IDs:("
// + listAccountIdRange.toString() + ") 的学员信息,无法统计数据");
// } else {
// taskDetail(taskId, researchName + "(" + researchId + ")" + " 没有查找到全平台:(" + examSiteId
// + ") 的学员信息,无法统计数据");
// }
// continue;
// }
// }
// if (resultccountMap != null) {
// // 添加应参加学员信息
// insertEmptyResearchLearn(resultccountMap, research, insertList, taskId);
// }
//
// // 循环统计每天的学习记录
// for (int d = 0; d <= day; d++) {
// String currentDate = startDate;
// if(d > 0){
// dCurDate = addDay(beginDate, d);
// currentDate = formatDate.format(dCurDate);
// }
//
// // 批量添加当前日期学习记录
// accountLearnIds = statisticsResearchService.insertAccountLearn(researchId, currentDate);
// // 没有学习记录,跳转
// if (accountLearnIds == null || accountLearnIds.size() == 0) {
// continue;
// }
// }
// }
// } catch(Exception e){
// e.printStackTrace();
// isOk = false;
// taskDetail(taskId, "统计调研 " + curResearchName + "(" + curResearchId + ")异常:" + e.getMessage());
// }
//
// try{
// //添加调研,先删除后添加信息
// statisticsResearchMapper.deleteStatisticsResearchToGroupFind();
// statisticsResearchMapper.insertStatisticsResearchToGroupFind();
//
// //添加学员,先删除后添加信息
// statisticsResearchMapper.deleteStatisticsResearchToAccountGroupFind();
// statisticsResearchMapper.insertStatisticsResearchToAccountGroupFind();
//
// } catch(Exception e){
// logger.info("***** 添加数据到按部门统计表错误 *****");
// taskDetail(taskId, "添加数据到中间表异常:" + e.getMessage());
// isOk = false;
// }
//
// accountMap.clear();
//
// Date endRunDate = new Date();
//
// String con = "调研报表分析完成耗时 :" + (endRunDate.getTime() - startRunDate.getTime()) / 1000 + "秒";
// taskDetail(taskId, con);
// if(isOk){
// success(taskContext, con);
// } else {
// fail(taskContext, con + ",执行过程中有错误");
// }
//
// return "ok";
// }
//
// /**
// * 创建和获取学员学习对象,缓存全平台可见的学员对象
// *
// * @param siteId 站点ID,为空不缓存学员信息
// * @param orgIdsAndAccountIds 指定范围可见ID集合
// * @param pageNo 页码
// * @param pageSize 页数
// * @param resultAccountIds 保存当前查询的学员IDs,每次会清空集合中的记录
// * @param resultccountMap 保存当前查询的学员信息,每次会清空集合中的记录
// * @return 当前查询的学员IDs
// */
// private StatisticsResearch getReportAccountRespVO(Long siteId, List<Long> orgIdsAndAccountIds, Integer pageNo, Integer pageSize,
// Long findAccountId, Map<Long, StatisticsResearch> resultccountMap, String rangeKey, Long taskId, String taskCon) {
// return null;
// }
////
//// //查找指定的人
//// StatisticsResearch learnStu = null;
////
//// // 获取用户信息
////// ReportRangeAccountReqVO rrarv = new ReportRangeAccountReqVO();
////// rrarv.setSiteId(siteId);
////// rrarv.setPageNo(pageNo);
////// rrarv.setOrgIdsAndAccountIds(orgIdsAndAccountIds);
////// rrarv.setPageSize(pageSize);
//// PageInfo<ReportAccountRespVO> page = null;
////// try{
////// page = reportClient.getRangeAccounts(rrarv);
//// if(page == null || page.getRecords() == null){
//// return null;
//// }
//// learnStu = initStatisticsResearchMetadatas(page.getRecords(), findAccountId, resultccountMap, rangeKey, taskId, taskCon);
////
//// if(taskCon.indexOf("中国书法创作实践") >=0){
//// logger.info("mmm:1页" + page.getRecords().toString());
//// taskDetail(taskId, "mmm:1页" + page.getRecords().toString());
//// }
////
//// String msg = " 调研:"+ taskCon;
//// if(orgIdsAndAccountIds == null){
//// msg += "全平台,第1页:siteId:" + siteId + " (总页数:" +page.getPageTotal() + "),查询人数:" + page.getRecords().size() + " 缓存人数:" + resultccountMap.size();
//// } else {
//// msg += "指定范围,第1页:siteId:" + siteId + " (总页数:" +page.getPageTotal() + "),查询人数:" + page.getRecords().size() + " 缓存人数:" + resultccountMap.size();
//// }
//// taskDetail(taskId, msg);
////
////// //分页查询查找所有人
////// int pageTotal = page.getPageTotal();
////// for (int i = 2; i <= pageTotal; i++) {
////// rrarv.setSiteId(siteId);
////// rrarv.setPageNo(i);
////// rrarv.setOrgIdsAndAccountIds(orgIdsAndAccountIds);
////// rrarv.setPageSize(pageSize);
////// page = reportClient.getRangeAccounts(rrarv);
////// if(page != null && page.getRecords().size() > 0){
////// if(taskCon.indexOf("中国书法创作实践") >=0){
////// logger.info("mmm:" + i + "页" + page.getRecords().toString());
////// taskDetail(taskId, "mmm:" + i + "页" + page.getRecords().toString());
////// }
////// if(learnStu == null){
////// learnStu = initStatisticsResearchMetadatas(page.getRecords(), findAccountId, resultccountMap, rangeKey, taskId, taskCon);
////// } else {
////// initStatisticsResearchMetadatas(page.getRecords(), null, resultccountMap, rangeKey, taskId, taskCon);
////// }
////// msg = " 调研:"+ taskCon;
////// if(orgIdsAndAccountIds == null){
////// msg += "全平台,第" + i +"页:siteId:" + siteId + " (总页数:" +page.getPageTotal() + "),查询人数:" + page.getRecords().size() + " 缓存人数:" + resultccountMap.size();
////// } else {
////// msg += "指定范围,第" + i + "页:siteId:" + siteId + " (总页数:" +page.getPageTotal() + "),查询人数:" + page.getRecords().size() + " 缓存人数:" + resultccountMap.size();
////// }
////// taskDetail(taskId, msg);
////// }
////// }
////// } catch(Exception e){
////// e.printStackTrace();
////// if(siteId == null){
////// taskDetail(taskId, "获取" + taskCon + "的指定范围Ids:(" + orgIdsAndAccountIds + ") system服务不可用,:" + e.getMessage());
////// } else {
////// taskDetail(taskId, "获取" + taskCon + "的全平台:(" + siteId + ") system服务不可用,:" + e.getMessage());
////// }
//////
////// return null;
////// }
////
//// return learnStu;
//// }
//
// /**
// * 创建和获取学员学习对象
// *
// * @param siteId 站点ID,为空不缓存学员信息
// * @param listReportAccountRespVO 查询出的学员
// * @param resultAccountIds 保存当前查询的学员IDs,每次会清空集合中的记录
// * @param resultccountMap 保存当前查询的学员信息,每次会清空集合中的记录
// * @return 当前查询的学员IDs
// */
// private StatisticsResearch initStatisticsResearchMetadatas(List<ReportAccountRespVO> listReportAccountRespVO, Long findAccountId,
// Map<Long, StatisticsResearch> resultccountMap, String rangeKey, Long taskId, String taskCon) {
//
// //查找指定的人
// StatisticsResearch learnStu = null;
//
// // 初始化学员学习信息
// for (ReportAccountRespVO item : listReportAccountRespVO) {
// Long accountId = item.getUserId();
// StatisticsResearch stu = null;
// if(accountMap.get(rangeKey) != null){
// stu = accountMap.get(rangeKey).get(accountId);
// } else {
// accountMap.put(rangeKey, resultccountMap);
// }
//
// if(stu == null){
// stu = new StatisticsResearch();
// stu.setId(null);
// stu.setAccountId(accountId);
// stu.setAccountState(item.getStatus());
// stu.setAccountWorkNum(item.getWorkNum());
// stu.setAccountName(item.getUserName());
// stu.setAccountFullName(item.getUserFullName());
// stu.setOrgName(item.getOrgName());
// stu.setAccountOrgId(item.getOrgId());
// String orgParentNames = null;
// if (item.getParentOrgNames() != null) {
// for (String orgName : item.getParentOrgNames()) {
// if (orgParentNames == null) {
// orgParentNames = orgName;
// } else {
// orgParentNames += "/" + orgName;
// }
// }
// stu.setOrgParentNames(orgParentNames);
// }
//
// // 设置实际参加状态,用于实际人数的统计
// stu.setCanState(1);
// //设置已参加状态为0(未参加)
// stu.setJoinState(0);
// resultccountMap.put(accountId, stu);
// if(taskCon.indexOf("中国书法创作实践") >=0){
// taskDetail(taskId, "mcz新增人员信息:" + stu.toString());
// }
// } else {
// if(taskCon.indexOf("中国书法创作实践") >=0){
// taskDetail(taskId, "mcz已存在人员信息:" + stu.toString());
// }
// }
// if(findAccountId != null && findAccountId.compareTo(accountId) == 0){
// learnStu = stu;
// }
// }
// return learnStu;
// }
//
// @SuppressWarnings("static-access")
// private Date addDay(Date date, int num) {
// Calendar calendar = new GregorianCalendar();
// calendar.setTime(date);
// calendar.add(calendar.DATE, num);
// date = calendar.getTime();
// return date;
// }
//
// /**
// * 测试数据
// * @param pageNo
// * @param pageSize
// * @return
// */
// private PageInfo<ReportAccountRespVO> getTestData(int pageNo, int pageSize){
// List<ReportAccountRespVO> l = new ArrayList<ReportAccountRespVO>();
// ReportAccountRespVO x = new ReportAccountRespVO();
// x.setUserId(1016273921890463744L);
// x.setOrgName("xxxx");
// l.add(x);
//
// x = new ReportAccountRespVO();
// x.setOrgName("xxxx");
// x.setUserId(81754L);
// l.add(x);
//
// /*x = new ReportAccountRespVO();
// x.setUserId(989311074940907520L);
// l.add(x);
// x = new ReportAccountRespVO();
// x.setUserId(1004566068968501248L);
// l.add(x);
// x = new ReportAccountRespVO();
// x.setUserId(1004591602767192064L);
// l.add(x);
// x = new ReportAccountRespVO();
// x.setUserId(1004594320063819776L);
// l.add(x);
// x = new ReportAccountRespVO();
// x.setUserId(1006492895324151808L);
// l.add(x);
// x = new ReportAccountRespVO();
// x.setUserId(1006492995672875008L);l.add(x);
// x = new ReportAccountRespVO();
// x.setUserId(1006733944520974336L);l.add(x);
// x = new ReportAccountRespVO();
// x.setUserId(1006734302269939712L);l.add(x);
// x = new ReportAccountRespVO();
// x.setUserId(1006734588979978240L);l.add(x);
// x = new ReportAccountRespVO();
// x.setUserId(1006734878378565632L);l.add(x);
// x = new ReportAccountRespVO();
// x.setUserId(1011930094964150272L);l.add(x);
// x = new ReportAccountRespVO();
// x.setUserId(1011929942455062528L);l.add(x);
// x = new ReportAccountRespVO();
// x.setUserId(1011925785505533952L);l.add(x);*/
//
// //模拟分页
// int startIndex = (pageNo - 1) * pageSize;
// int endIndex = pageSize + startIndex;
// int total = l.size();
// endIndex = endIndex > total ? total : endIndex;
// List<ReportAccountRespVO> dataCharts = new ArrayList<ReportAccountRespVO>();
// for (; startIndex < endIndex; startIndex++) {
// dataCharts.add(l.get(startIndex));
// }
//
// PageInfo<ReportAccountRespVO> page = new PageInfo<ReportAccountRespVO>();
// page.setRecords(dataCharts);
// page.setPageTotal(l.size());
//
// return page;
// }
//
// public void clearInfo(StatisticsResearch stu){
// stu.setJoinState(null);
// stu.setResearchId(null);
// stu.setResearchNo(null);
// stu.setResearchName(null);
// stu.setResearchCreateTime(null);
// stu.setResearchStartTime(null);
// stu.setResearchEndTime(null);
// stu.setResearchCompanyId(null);
// stu.setResearchSiteId(null);
// stu.setResearchOrgId(null);
// stu.setFinishTime(null);
// stu.setAccountCompanyId(null);
// stu.setAccountSiteId(null);
// stu.setAccountOrgId(null);
// }
//
// private void insertEmptyResearchLearn(Map<Long, StatisticsResearch> resultccountMap, Research research,
// List<StatisticsResearch> insertList, Long taskId){
// if(insertList != null){
// insertList.clear();
// }
//
// //获取该调研的学员信息
// Map<Long, Long> stuMap = statisticsResearchMapper.selectAccountLearnByResearchId(research.getId());
//
// Iterator<StatisticsResearch> statResearchs = resultccountMap.values().iterator();
// StatisticsResearch statCourse;
// while (statResearchs.hasNext()){
// //更新调研信息
// statCourse = statResearchs.next();
// statCourse.setJoinState(0);
// statCourse.setResearchId(research.getId());
// statCourse.setResearchNo(research.getResearchNo());
// statCourse.setResearchName(research.getName());
// statCourse.setResearchCreateTime(research.getCreateTime());
// statCourse.setResearchStartTime(research.getStartTime());
// statCourse.setResearchEndTime(research.getEndTime());
// statCourse.setResearchCompanyId(research.getCompanyId());
// statCourse.setResearchSiteId(research.getSiteId());
// statCourse.setResearchOrgId(research.getOrgId());
//
// if(stuMap == null){
// insertList.add(statCourse);
// } else {
// if(stuMap.get(statCourse.getAccountId()) == null){
// insertList.add(statCourse);
// }
// }
// }
// //批量插入
// if(!CollectionUtils.isEmpty(insertList)) {
// try{
// statisticsResearchService.insertBatch(insertList);
// taskDetail(taskId, "批量添加成功" + research.getName() + "(" + research.getId() + ")"+ "实际添加人数:" + insertList.size() + " 总人数:" + resultccountMap.size());
// } catch(Exception e){
// logger.info("***insert data*********" + JSON.toJSONString(insertList));
// e.printStackTrace();
// taskDetail(taskId, "批量添加" + research.getName() + "(" + research.getId() + ")"+ "数据错误:" + e.getMessage());
// }
// }
// }
}
package com.yizhi.research.application.controller;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.research.application.mapper.TrResearchAnswerMapper;
import com.yizhi.research.application.model.AnswerModel;
import com.yizhi.research.application.service.ITrResearchAnswerService;
import com.yizhi.research.application.vo.StatisticResearchMetadataVo;
import com.yizhi.research.application.vo.api.ViewAnswerVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* <p>
* 答卷 前端控制器
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@RestController
@RequestMapping("/researchAnswer")
public class TrResearchAnswerController {
@Autowired
private ITrResearchAnswerService researchAnswerService;
@Autowired
private TrResearchAnswerMapper trResearchAnswerMapper;
/**
* 学员提交答案
* @param answerModel
* @return
* @throws Exception
*/
@PostMapping("/submit")
public Integer submitAnswer(@RequestBody AnswerModel answerModel) throws Exception {
return researchAnswerService.submitAnswer(answerModel);
}
@GetMapping("/view")
public ViewAnswerVo viewResearch(@RequestParam("researchId") Long researchId, @RequestParam("accountId") Long accountId) {
return researchAnswerService.apiViewAnswer(researchId, accountId);
}
/**
* 查看调研下所有的答卷
* @param researchId
* @param
* @return
*/
@GetMapping("/views")
public Page<ViewAnswerVo> viewAnswers(@RequestParam("researchId") Long researchId,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize){
return researchAnswerService.apiViewAnswers(researchId,pageNo,pageSize);
}
@GetMapping("/views/list")
public List<ViewAnswerVo> viewAnswersList(@RequestParam("researchId") Long researchId,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize){
return researchAnswerService.viewAnswerVoList(researchId,pageNo,pageSize);
}
@GetMapping("/views/count")
public Integer viewAnswersCount(@RequestParam("researchId") Long researchId){
return researchAnswerService.apiViewAnswersCount(researchId);
}
@GetMapping("/view/list")
public List<ViewAnswerVo> viewList(@RequestParam("researchId") Long researchId){
return researchAnswerService.viewList(researchId);
}
/**
* 根据调研answer的创建时间、调研id、已完成状态查询,
* @param researchId
* @param currentDate
* @return
*/
@GetMapping("/selectLearnRecord")
public List<StatisticResearchMetadataVo> selectLearnRecord(@RequestParam("researchId")Long researchId,
@RequestParam("startDate")String startDate,
@RequestParam("endDate")String endDate){
return trResearchAnswerMapper.selectLearnRecord(researchId,startDate,endDate);
}
}
package com.yizhi.research.application.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
/**
* <p>
* 答案题目 前端控制器
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@Controller
@RequestMapping("/trResearchAnswerQuestion")
public class TrResearchAnswerQuestionController {
}
package com.yizhi.research.application.controller;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.yizhi.research.application.service.IResearchService;
import com.yizhi.research.application.service.ITrResearchAuthorizeService;
import com.yizhi.research.application.vo.VisibleRangeExport;
import com.yizhi.research.application.vo.domain.TrResearchAuthorize;
import com.yizhi.research.application.vo.domain.TrResearchAuthorizeVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
/**
* <p>
* 调研用户范围 前端控制器
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@RestController
@RequestMapping("/researchAuthorize")
public class TrResearchAuthorizeController {
@Autowired
private ITrResearchAuthorizeService iTrResearchAuthorizeService;
@Autowired
private IResearchService researchService;
@GetMapping("/researchId/get")
public List<TrResearchAuthorize> getResearchAuthorize(@RequestParam("researchId") Long researchId) {
TrResearchAuthorize example = new TrResearchAuthorize();
example.setResearchId(researchId);
return example.selectList(new EntityWrapper(example));
}
@PostMapping("/researchId/insert")
public Boolean insertResearchAuthorize(@RequestBody List<TrResearchAuthorizeVo> trResearchAuthorizes){
List<TrResearchAuthorize> list=new ArrayList<>();
for (TrResearchAuthorizeVo trv:trResearchAuthorizes
) {
TrResearchAuthorize t=new TrResearchAuthorize();
BeanUtils.copyProperties(trv,t);
list.add(t);
}
return iTrResearchAuthorizeService.insertAll(list);
}
@ApiOperation(value="可见范围导出",notes="可见范围导出")
@GetMapping("/export/visiblRange")
public VisibleRangeExport vsibleRangeExport(@ApiParam(value="researchId",name="调研的Id",required=true) @RequestParam(name="researchId",required=true) Long researchId) {
return researchService.vsibleRangeExport(researchId);
}
}
package com.yizhi.research.application.controller;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.research.application.model.ModifyQuestionModel;
import com.yizhi.research.application.service.ITrResearchQuestionOptionService;
import com.yizhi.research.application.service.ITrResearchQuestionService;
import com.yizhi.research.application.vo.api.MyQuestion;
import com.yizhi.research.application.vo.api.QuestionJumpVo;
import com.yizhi.research.application.vo.domain.TrResearchQuestion;
import com.yizhi.research.application.vo.domain.TrResearchQuestionOption;
import com.yizhi.research.application.vo.domain.TrResearchQuestionOptionVo;
import com.yizhi.research.application.vo.domain.TrResearchQuestionVo;
import org.apache.poi.ss.formula.functions.T;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* <p>
* 问题 前端控制器
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@RestController
@RequestMapping("/researchQuestion")
public class TrResearchQuestionController {
private static final Logger LOGGER = LoggerFactory.getLogger(TrResearchQuestionController.class);
@Autowired
private ITrResearchQuestionService researchQuestionService;
@Autowired
private ITrResearchQuestionOptionService researchQuestionOptionServiceService;
/**
* 批量插入问题
*
* @param questions
* @return
*/
@PostMapping("/batch/insert")
public int batchInsert(@RequestBody List<TrResearchQuestionVo> questions) {
if (CollectionUtils.isEmpty(questions)) {
return 0;
}
List<TrResearchQuestion> list=new ArrayList<>();
for (TrResearchQuestionVo trqv:questions
) {
TrResearchQuestion tr=new TrResearchQuestion();
BeanUtils.copyProperties(trqv,tr);
List<TrResearchQuestionOptionVo> list1=trqv.getOptions();
List<TrResearchQuestionOption> list2=new ArrayList<>();
if (!CollectionUtils.isEmpty(list1)) {
for (TrResearchQuestionOptionVo j : list1
) {
TrResearchQuestionOption trr = new TrResearchQuestionOption();
BeanUtils.copyProperties(j, trr);
list2.add(trr);
}
}
tr.setOptions(list2);
list.add(tr);
}
return researchQuestionService.batchInsert(list);
}
/**
* 问题更新
* deletedIds: 删除的问题的id集合
* questions: 新增的问题,修改的问题(修改仅仅涉及序号)
*
* @param model
* @return
*/
@PostMapping("/update")
public int batchUpdate(@RequestBody ModifyQuestionModel model) throws Exception {
return researchQuestionService.batchUpdate(model);
}
/**
* 分页查询 一个调研下面的问题
*
* @param page 只有一个
* @return
*/
@GetMapping("/page/list")
public List<TrResearchQuestion> listPage(@RequestBody Page<TrResearchQuestion> page) {
Map<String, Object> map = page.getCondition();
map.put("pageNo", page.getCurrent());
map.put("pageSize", page.getSize());
return researchQuestionService.listPage(map);
}
/**
* 根据调研id查询所有
*
* @param researchId
* @return
*/
@GetMapping("/list")
public List<TrResearchQuestion> listAll(@RequestParam("researchId") Long researchId) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("researchId", researchId);
return researchQuestionService.listPage(map);
}
@GetMapping("/list/all")
public List<TrResearchQuestion> list(@RequestParam("researchId") Long researchId) {
return researchQuestionService.listAll(researchId);
}
/**
* 选择跳题时的问题列表
*
* @param id 需要跳题的问题id
* @return
*/
@GetMapping("/jump/question/list")
public List<TrResearchQuestion> listAllForJump(@RequestParam("id") Long id) {
return researchQuestionService.listAllForJump(id);
}
/**
* 调研逐题显示下一题或者上一题
*/
@GetMapping("/last/next")
public MyQuestion lastAndNext(
@RequestBody MyQuestion myQuestion
) {
return researchQuestionService.lastAndNext(myQuestion);
}
@PostMapping("/jump/question/update")
Integer updateQuestionJump(@RequestBody QuestionJumpVo vo) {
return researchQuestionService.updateQuestionJump(vo);
}
@GetMapping("/option/get")
Map<String, Object> getOptionByQuestionId(@RequestParam("questionId") Long id) {
return researchQuestionOptionServiceService.getOptionByQuestionId(id);
}
/**
* 查找调研完成学员id
*
* @param researchId
* @param companyId
* @param siteId
* @return
*/
@GetMapping("/getFinishedAccountIds")
List<Long> getFinishedAccountIds(@RequestParam("researchId") Long researchId,
@RequestParam("companyId") Long companyId,
@RequestParam("siteId") Long siteId) {
return researchQuestionService.getFinishedAccountIds(researchId, companyId, siteId);
}
}
package com.yizhi.research.application.controller;
import com.yizhi.research.application.service.ITrResearchQuestionOptionService;
import com.yizhi.research.application.vo.domain.TrResearchQuestionOption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
/**
* <p>
* 只对题型是:单选题、多选题和打分题 前端控制器
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@RestController
@RequestMapping("/trResearchQuestionOption")
public class TrResearchQuestionOptionController {
@Autowired
ITrResearchQuestionOptionService iTrResearchQuestionOptionService;
@GetMapping("/all")
public List<TrResearchQuestionOption> listAll(@RequestParam("researchId") Long researchId) {
return iTrResearchQuestionOptionService.listAll(researchId);
}
@GetMapping("/option/get")
public Map<String,Object> getOptionByQuestionId(@RequestParam("questionId") Long id){
return iTrResearchQuestionOptionService.getOptionByQuestionId(id);
}
}
package com.yizhi.research.application.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 答案选项 前端控制器
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@RestController
@RequestMapping("/trResearchQuestionResult")
public class TrResearchQuestionResultController {
}
package com.yizhi.research.application.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
/**
* <p>
* 前端控制器
* </p>
*
* @author shengchenglong123
* @since 2018-03-14
*/
@Controller
@RequestMapping("/trResearchRemind")
public class TrResearchRemindController {
}
package com.yizhi.research.application.download;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.core.application.context.TaskContext;
import com.yizhi.core.application.file.constant.FileConstant;
import com.yizhi.core.application.file.task.AbstractDefaultTask;
import com.yizhi.core.application.file.util.OssUpload;
import com.yizhi.research.application.mapper.TrResearchAnswerMapper;
import com.yizhi.research.application.service.IResearchService;
import com.yizhi.research.application.service.ITrResearchAnswerService;
import com.yizhi.research.application.service.ITrResearchQuestionOptionService;
import com.yizhi.research.application.service.ITrResearchQuestionService;
import com.yizhi.research.application.util.WorkUtil;
import com.yizhi.research.application.vo.api.ViewAnswerQuestionOptionVo;
import com.yizhi.research.application.vo.api.ViewAnswerQuestionVo;
import com.yizhi.research.application.vo.api.ViewAnswerVo;
import com.yizhi.research.application.vo.domain.TrResearchAuthorize;
import com.yizhi.research.application.vo.domain.TrResearchQuestion;
import com.yizhi.research.application.vo.domain.TrResearchQuestionOption;
import com.yizhi.research.application.vo.report.DownloadParamsVoOnTime;
import com.yizhi.research.application.vo.report.ReportResearchAnalyze;
import com.yizhi.research.application.vo.report.ResearchGroupViewVo;
import com.yizhi.system.application.constant.AuthzConstant;
import com.yizhi.system.application.system.remote.AccountClient;
import com.yizhi.system.application.system.remote.ReportClient;
import com.yizhi.system.application.vo.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileOutputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import static java.math.BigDecimal.ROUND_HALF_DOWN;
@Component
public class DownloadResearchAnalyze extends AbstractDefaultTask<String, DownloadParamsVoOnTime> {
private static final Logger logger = LoggerFactory.getLogger(DownloadResearchAnalyze.class);
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
@Autowired
private WorkUtil workUtil;
@Autowired
private ITrResearchQuestionService researchQuestionService;
@Autowired
ITrResearchQuestionOptionService iTrResearchQuestionOptionService;
@Autowired
private ITrResearchAnswerService researchAnswerService;
@Autowired
private TrResearchAnswerMapper trResearchAnswerMapper;
@Autowired
private ReportClient reportClient;
@Autowired
private IResearchService researchService;
@Autowired
private AccountClient accountClient;
@Override
protected String execute(DownloadParamsVoOnTime vo) {
Long researchId = vo.getResearchId();
String researchName = vo.getResesrchName();
RequestContext context = vo.getContext();
String taskName = vo.getTaskName();
String serialNo = vo.getSerialNo();
Long taskId = vo.getTaskId();
Long siteId = context.getSiteId();
Date submitTime = new Date();
TaskContext taskContext = new TaskContext(taskId, serialNo, taskName, context.getAccountId(), submitTime, context.getSiteId(), context.getCompanyId());
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
working(taskContext);
Integer pageNo = 1;
Integer pageSize = 20;
List<ViewAnswerVo> viewAnswerVos = new ArrayList<ViewAnswerVo>();
List<ViewAnswerVo> viewAnswerVos1;
//获取问题列表
Map<String, Object> map = new HashMap<String, Object>();
map.put("researchId", researchId);
List<TrResearchQuestion> trResearchQuestions = researchQuestionService.listPage(map);
if (trResearchQuestions == null) {
trResearchQuestions = new ArrayList<>();
}
//获取问题选项列表
List<TrResearchQuestionOption> trResearchQuestionOptions = iTrResearchQuestionOptionService.listAll(researchId);
if (trResearchQuestionOptions == null) {
trResearchQuestionOptions = new ArrayList<>();
}
//获取回答记录数
Integer total = researchAnswerService.apiViewAnswersCount(researchId);
//获取回答记录
viewAnswerVos1 = researchAnswerService.viewAnswerVoList(researchId, 1, Integer.MAX_VALUE);
viewAnswerVos.addAll(viewAnswerVos1);
List<Long> accountIds = new ArrayList<>();
// //这里主要获取问答题需要的字段数据 name、submitTime
List<ResearchGroupViewVo> researchGroupViewVos = trResearchAnswerMapper.queryAnswerRecord(researchId, siteId);
if (CollectionUtils.isNotEmpty(researchGroupViewVos)) {
for (ResearchGroupViewVo groupViewVo : researchGroupViewVos) {
accountIds.add(groupViewVo.getAccountId());
}
List<AccountVO> accountVOs = accountClient.idsGet(accountIds);
//获取 《accountId,name》Map集合
Map<Long, String> accountMap = new HashMap<>();
//实时取用户名
accountVOs.forEach(accountVo -> {
if (!accountMap.containsKey(accountVo.getId())) {
accountMap.put(accountVo.getId(), accountVo.getName());
}
});
for (ResearchGroupViewVo groupViewVo : researchGroupViewVos) {
groupViewVo.setAccountName(accountMap.get(groupViewVo.getAccountId()));
}
}
String upLoadUrl = null;
String requestPath = FileConstant.SAVE_PATH;
// String requestPath = "/Users/dingxiaowei/aaa";
// String requestPath = "E\\";
File fileDir = new File(requestPath);
if (!fileDir.exists()) {
fileDir.mkdir();
}
XSSFWorkbook workbook = new XSSFWorkbook();
//创建单元格格式
XSSFCellStyle style = workbook.createCellStyle();
style.setAlignment(HorizontalAlignment.LEFT);//创建居左格式
Cell cell;
String sheetName = workUtil.chechPattonPattern(researchName + "调研分析表");
XSSFSheet sheet = workbook.createSheet(sheetName);
//创建第一行
XSSFRow row = sheet.createRow((int) 0);
cell = row.createCell((short) 0);
cell.setCellValue(researchName);
//创建第二行
row = sheet.createRow((int) 1);
cell = row.createCell((short) 0);
String deadline = format.format(submitTime);
cell.setCellValue("统计周期:" + "截止" + deadline);
//获取实际参加人数
Integer realJoinNum = total;
Integer canjoinNum = 0;
//获取可参加人数
canjoinNum = queryCanJoinNum(researchId, context);
ReportResearchAnalyze reportResearchAnalyze = new ReportResearchAnalyze();
reportResearchAnalyze.setJoinCount(canjoinNum == null ? 0 : canjoinNum);
reportResearchAnalyze.setRealJoinCount(realJoinNum == null ? 0 : realJoinNum);
reportResearchAnalyze.setSubmitCount(realJoinNum == null ? 0 : realJoinNum);
reportResearchAnalyze.setQuestionCount(trResearchQuestions.size());
//创建第三行
row = sheet.createRow((int) 2);
row.createCell((short) 0).setCellValue("题目总数:" + reportResearchAnalyze.getQuestionCount());
row.createCell((short) 1).setCellValue("提交问卷份数:" + reportResearchAnalyze.getSubmitCount());
row.createCell((short) 2).setCellValue("可参加人数:" + reportResearchAnalyze.getJoinCount());
row.createCell((short) 3).setCellValue("实际参加人数:" + reportResearchAnalyze.getRealJoinCount());
try {
//获取 用户id对应的用户答题记录
Map<Long, ResearchGroupViewVo> statisticsResearchMap = new HashMap<Long, ResearchGroupViewVo>();
for (ResearchGroupViewVo researchGroupViewVo : researchGroupViewVos) {
if (researchGroupViewVo == null) {
continue;
}
statisticsResearchMap.put(researchGroupViewVo.getAccountId(), researchGroupViewVo);
}
int index = 3;
List<ViewAnswerQuestionVo> answerQuestions;
List<ViewAnswerQuestionOptionVo> viewAnswerQuestionOptionVos;
Map<Long, Integer> viewAnswerVoMap = new HashMap<Long, Integer>();
Map<Long, List<ViewAnswerQuestionVo>> accountMap = new HashMap<Long, List<ViewAnswerQuestionVo>>();
List<ViewAnswerQuestionVo> voList = new ArrayList<ViewAnswerQuestionVo>();
Map<Long, Integer> viewAnswerQuestionOptionVoMap = new HashMap<Long, Integer>();
Map<Long, ViewAnswerQuestionOptionVo> optionVoMap = new HashMap<Long, ViewAnswerQuestionOptionVo>();
//以分数位置为key,分数为value
Map<Integer, Integer> scoreIndexMap = new HashMap<>();
Integer scoreTem = 10;
Integer indexTem = 1;
for (indexTem = 1; indexTem <= 11; indexTem++) {
scoreIndexMap.put(indexTem,scoreTem);
scoreTem--;
}
//以选项id为key value 是 以分数为key,选择的人数为value
Map<Long, Map<Integer, Integer>> optionMap1 = new HashMap<>();
Long questionId;
Long accountId;
ResearchGroupViewVo researchGroupViewVo;
ViewAnswerQuestionOptionVo questionOptionVo;
for (ViewAnswerVo viewAnswerVo : viewAnswerVos) {
researchGroupViewVo = statisticsResearchMap.get(viewAnswerVo.getAccountId());
if (researchGroupViewVo == null) {
continue;
}
answerQuestions = viewAnswerVo.getAnswerQuestions();
if (answerQuestions == null) {
continue;
}
for (ViewAnswerQuestionVo viewAnswerQuestionVo : answerQuestions) {
questionId = viewAnswerQuestionVo.getId();
Integer validCount = 0;//表示该问题有效填写的个数
boolean preCheck = false;
if (viewAnswerQuestionVo.getType() == 3) {//问答题
viewAnswerQuestionVo.setAccountId(viewAnswerVo.getAccountId());
if (viewAnswerQuestionVo.getAnswerContent() != null) {
voList.add(viewAnswerQuestionVo);
accountMap.put(questionId, voList);
preCheck = true;
}
} else {
viewAnswerQuestionOptionVos = viewAnswerQuestionVo.getOptions();
for (ViewAnswerQuestionOptionVo viewAnswerQuestionOptionVo : viewAnswerQuestionOptionVos) {
Integer count;
Long optionId = viewAnswerQuestionOptionVo.getId();
//单选题或者多选题
if (viewAnswerQuestionVo.getType() == 1 || viewAnswerQuestionVo.getType() == 2) {
if (viewAnswerQuestionOptionVo.getAnswerChecked()) {
preCheck = true;
count = viewAnswerQuestionOptionVoMap.get(viewAnswerQuestionOptionVo.getId());
if (count == null) {
count = 1;
} else {
count++;
}
viewAnswerQuestionOptionVoMap.put(viewAnswerQuestionOptionVo.getId(), count);
//viewAnswerQuestionOptionVo.setCheckedCount(checkCount);
}
} else {//打分题
Integer answerScore = viewAnswerQuestionOptionVo.getAnswerScore();
Integer totalSocre;
if (answerScore != null) {
if (!optionMap1.containsKey(optionId)) {
Map<Integer, Integer> scoreMap = new HashMap<>();
scoreMap.put(answerScore, 1);
optionMap1.put(optionId, scoreMap);
} else {
Map<Integer, Integer> scoreMap = optionMap1.get(optionId);
if (!scoreMap.containsKey(answerScore)) {
scoreMap.put(answerScore, 1);
} else {
Integer selectNum = scoreMap.get(answerScore);
scoreMap.put(answerScore, (selectNum + 1));
}
optionMap1.put(optionId, scoreMap);
}
preCheck = true;
questionOptionVo = optionVoMap.get(viewAnswerQuestionOptionVo.getId());
if (questionOptionVo == null) {
questionOptionVo = new ViewAnswerQuestionOptionVo();
questionOptionVo.setAnswerScore(answerScore);
questionOptionVo.setCheckCount(1);
questionOptionVo.setMinScore(answerScore);
questionOptionVo.setMaxScore(answerScore);
questionOptionVo.setTotalSocre(answerScore);
optionVoMap.put(viewAnswerQuestionOptionVo.getId(), questionOptionVo);
} else {
count = questionOptionVo.getCheckCount();
questionOptionVo.setCheckCount(++count);
if (answerScore > questionOptionVo.getMaxScore()) {
questionOptionVo.setMaxScore(answerScore);
}
if (answerScore < questionOptionVo.getMinScore()) {
questionOptionVo.setMinScore(answerScore);
}
totalSocre = questionOptionVo.getTotalSocre();
totalSocre += answerScore;
questionOptionVo.setTotalSocre(totalSocre);
}
}
}
}
}
if (preCheck) {
validCount = viewAnswerVoMap.get(questionId);
if (validCount == null) {
validCount = 1;
} else {
validCount += 1;
}
viewAnswerVoMap.put(questionId, validCount);
}
}
}
List<TrResearchQuestionOption> optionList;
Map<Long, List<TrResearchQuestionOption>> optionMap = new HashMap<Long, List<TrResearchQuestionOption>>();
Long questionsId;
for (TrResearchQuestionOption trResearchQuestionOption : trResearchQuestionOptions) {
questionsId = trResearchQuestionOption.getQuestionId();
optionList = optionMap.get(questionsId);
if (optionList != null) {
optionList.add(trResearchQuestionOption);
} else {
optionList = new ArrayList<TrResearchQuestionOption>();
optionList.add(trResearchQuestionOption);
}
optionMap.put(questionsId, optionList);
}
//答卷的问题
BigDecimal d;
BigDecimal dou;
BigDecimal b = new BigDecimal(100);
int s = 0;
//第四行组装数据开始
for (TrResearchQuestion trResearchQuestion : trResearchQuestions) {
row = sheet.createRow((int) index);
index++;
cell = row.createCell((short) 0);
if (trResearchQuestion.getContent() != null && trResearchQuestion.getNo() != null && trResearchQuestion.getType() == 1) {
cell.setCellValue(trResearchQuestion.getNo() + "、" + "(单选题)" + trResearchQuestion.getContent());
}
if (trResearchQuestion.getContent() != null && trResearchQuestion.getNo() != null && trResearchQuestion.getType() == 2) {
cell.setCellValue(trResearchQuestion.getNo() + "、" + "(多选题)" + trResearchQuestion.getContent());
}
if (trResearchQuestion.getContent() != null && trResearchQuestion.getNo() != null && trResearchQuestion.getType() == 3) {
cell.setCellValue(trResearchQuestion.getNo() + "、" + "(问答题)" + trResearchQuestion.getContent());
}
if (trResearchQuestion.getContent() != null && trResearchQuestion.getNo() != null && trResearchQuestion.getType() == 4) {
cell.setCellValue(trResearchQuestion.getNo() + "、" + "(打分题)" + trResearchQuestion.getContent());
}
questionId = trResearchQuestion.getId();
Integer valid = viewAnswerVoMap.get(questionId);
if (valid == null) {
valid = 0;
}
//单选
if (trResearchQuestion.getType() == 1 || trResearchQuestion.getType() == 2) {
row.createCell((short) 1).setCellValue("有效填写:" + valid);
row = sheet.createRow((int) index);
index++;
row.createCell((short) 0).setCellValue("选项");
row.createCell((short) 1).setCellValue("小计");
row.createCell((short) 2).setCellValue("比例");
optionList = optionMap.get(questionId);
Integer totalCount = 0;
if (optionList != null) {
for (TrResearchQuestionOption trResearchQuestionOption : optionList) {
Integer i = viewAnswerQuestionOptionVoMap.get(trResearchQuestionOption.getId());
if (i == null) {
i = 0;
}
totalCount += i;
}
for (TrResearchQuestionOption trResearchQuestionOption : optionList) {
Integer i = viewAnswerQuestionOptionVoMap.get(trResearchQuestionOption.getId());
if (i == null) {
i = 0;
}
row = sheet.createRow((int) index);
index++;
cell = row.createCell((short) 0);
if (trResearchQuestionOption.getContent() != null) {
cell.setCellValue(trResearchQuestionOption.getContent());
}
row.createCell((short) 1).setCellValue(i);
d = new BigDecimal((double) i).multiply(b);
dou = new BigDecimal((double) totalCount);
cell = row.createCell((short) 2);
if (d.compareTo(BigDecimal.ZERO) == 0 || dou.compareTo(BigDecimal.ZERO) == 0) {
cell.setCellValue("0%");
} else {
cell.setCellValue(d.divide(dou, 0, ROUND_HALF_DOWN) + "%");
}
}
}
//问答题
} else if (trResearchQuestion.getType() == 3) {
voList = accountMap.get(questionId);
if (voList == null) {
continue;
}
for (ViewAnswerQuestionVo viewAnswerQuestionVo : voList) {
int i = 0;
accountId = viewAnswerQuestionVo.getAccountId();
researchGroupViewVo = statisticsResearchMap.get(accountId);
row = sheet.createRow((int) index);
index++;
cell = row.createCell((short) 0);
if (researchGroupViewVo.getAccountName() != null) {
cell.setCellValue(researchGroupViewVo.getAccountName());
}
cell = row.createCell((short) 1);
if (researchGroupViewVo.getFinishTime() != null) {
cell.setCellValue(sdf.format(researchGroupViewVo.getFinishTime()));
}
cell = row.createCell((short) 2);
if (viewAnswerQuestionVo.getAnswerContent() != null) {
cell.setCellValue(viewAnswerQuestionVo.getAnswerContent());
}
}
} else {
//打分题
row.createCell((short) 1).setCellValue("有效填写:" + valid);
row = sheet.createRow((int) index);
index++;
row.createCell((short) 0).setCellValue("打分项");
row.createCell((short) 1).setCellValue("10");
row.createCell((short) 2).setCellValue("9");
row.createCell((short) 3).setCellValue("8");
row.createCell((short) 4).setCellValue("7");
row.createCell((short) 5).setCellValue("6");
row.createCell((short) 6).setCellValue("5");
row.createCell((short) 7).setCellValue("4");
row.createCell((short) 8).setCellValue("3");
row.createCell((short) 9).setCellValue("2");
row.createCell((short) 10).setCellValue("1");
row.createCell((short) 11).setCellValue("0");
row.createCell((short) 12).setCellValue("参与人数");
row.createCell((short) 13).setCellValue("最高分");
row.createCell((short) 14).setCellValue("最低分");
row.createCell((short) 15).setCellValue("总分");
row.createCell((short) 16).setCellValue("平均分");
if (trResearchQuestionOptions == null) {
continue;
}
for (TrResearchQuestionOption trResearchQuestionOption : trResearchQuestionOptions) {
if (trResearchQuestionOption.getQuestionId().equals(questionId)) {
row = sheet.createRow(index);
index++;
cell = row.createCell((short) 0);
if (trResearchQuestionOption.getContent() != null) {
cell.setCellValue(trResearchQuestionOption.getContent());
}
questionOptionVo = optionVoMap.get(trResearchQuestionOption.getId());
if (questionOptionVo == null) {
continue;
}
//给选了那个分数的单元格赋值
Integer i = 1;
Long optionId = trResearchQuestionOption.getId();
for (i = 1; i <= 11; i++) {
Map<Integer, Integer> scoreMap = optionMap1.get(optionId);
if (scoreMap == null) {
continue;
}
Integer score = scoreIndexMap.get(i);
Integer selectNum = scoreMap.get(score);
if (selectNum != null) {
cell = row.createCell(i);
cell.setCellValue(selectNum);
}
}
// int i = questionOptionVo.getAnswerScore();
// for (int j = 0; j < 11; j++) {
// row.createCell((short) (11 - j));
// if (i == j) {
// cell = row.getCell((short) (11 - j));
// if (questionOptionVo.getCheckCount() != null) {
// cell.setCellValue(questionOptionVo.getCheckCount());
// }
// }
// }
d = new BigDecimal(questionOptionVo.getTotalSocre());
dou = new BigDecimal(questionOptionVo.getCheckCount());
cell = row.createCell((short) 12);
if (questionOptionVo.getCheckCount() != null) {
cell.setCellValue(questionOptionVo.getCheckCount());
}
cell = row.createCell((short) 13);
if (questionOptionVo.getMaxScore() != null) {
cell.setCellValue(questionOptionVo.getMaxScore());
}
cell = row.createCell((short) 14);
if (questionOptionVo.getMinScore() != null) {
cell.setCellValue(questionOptionVo.getMinScore());
}
cell = row.createCell((short) 15);
if (questionOptionVo.getTotalSocre() != null) {
cell.setCellValue(questionOptionVo.getTotalSocre());
}
cell = row.createCell((short) 16);
if (d.compareTo(BigDecimal.ZERO) == 0 || dou.compareTo(BigDecimal.ZERO) == 0) {
cell.setCellValue("0");
} else {
cell.setCellValue(d.divide(dou, 2, ROUND_HALF_DOWN) + "");
}
}
}
}
s++;
// taskDetail(taskContext.getTaskId(), research.getName() + "导出数据第" + s + "行成功");
}
//导出
StringBuffer fileNameSb = new StringBuffer().append(researchName + "分析统计_" + sdf.format(submitTime)).append(".xlsx");
String fileName = fileNameSb.toString();
String path = new StringBuffer().append(requestPath).append(fileNameSb).toString();
FileOutputStream os = null;
File file = null;
try {
os = new FileOutputStream(path);
workbook.write(os);
//阿里云返回url
upLoadUrl = OssUpload.upload(path, fileName);
file = new File(path);
success(taskContext, "成功", upLoadUrl);
} catch (Exception e1) {
e1.printStackTrace();
fail(taskContext, "写入过程中发生错误");
logger.error("写入数据到Excel的过程中或者上传到阿里云中发生错误");
} finally {
if (os != null) {
os.close();
}
if (workbook != null) {
workbook.close();
}
if (file != null) {
file.delete();
}
}
} catch (Exception e) {
e.printStackTrace();
fail(taskContext, researchName + "导出过程中发生错误,请查看日志");
logger.error("创建Excel的过程中发生错误");
}
return upLoadUrl;
}
private Integer queryCanJoinNum(Long researchId, RequestContext context) {
Integer canJoinNum = 0;
//"可见范围,1平台用户可见(企业下所有人员) 2指定学员可见"
Integer visibRange = researchService.selectById(researchId).getVisibleRange();
List<Long> accountIds = new ArrayList<>();
List<Long> orgIds = new ArrayList<>();
// 如果是调研指定范围
if (visibRange == 2) {
TrResearchAuthorize example = new TrResearchAuthorize();
example.setResearchId(researchId);
List<TrResearchAuthorize> authorizes = example.selectList(new EntityWrapper(example));
if (CollectionUtils.isNotEmpty(authorizes)) {
for (TrResearchAuthorize authorize : authorizes) {
if (authorize.getType().equals(1)) {
orgIds.add(authorize.getRelationId());
} else {
accountIds.add(authorize.getRelationId());
}
}
//获取调研可见范围内的用户数据
List<ReportAccountRespVO> queryAccountList = queryConditionalAccount(context, orgIds, accountIds);
canJoinNum = queryAccountList == null ? 0 : queryAccountList.size();
// List<Long> accountIdList = new ArrayList<>();
// //获取全平台或者管辖区人员数据
// List<ReportAccountRespVO> manageAccountList = queryAccountList(context, orgIds, accountIds);
//
// if (CollectionUtils.isNotEmpty(queryAccountList)) {
// if (CollectionUtils.isNotEmpty(manageAccountList)) {
// for (ReportAccountRespVO vo : queryAccountList) {
// for (ReportAccountRespVO manageVo : manageAccountList) {
// if (manageVo.equals(vo.getUserId())) {
// accountIdList.add(vo.getUserId());
// }
// }
// }
// canJoinNum = accountIdList.size();
// }
// }
}
} else {
//获取全平台或者管辖区人员数据 orgids,accountIds 都是空的
List<ReportAccountRespVO> queryAccountList = queryAccountList(context, orgIds, accountIds);
canJoinNum = queryAccountList.size();
}
return canJoinNum;
}
//获取全平台或者管辖区人员数据
private List<ReportAccountRespVO> queryAccountList(RequestContext context, List<Long> orgIds, List<Long> accountIds) {
List<ReportAccountRespVO> queryAccountList = new ArrayList<>();
if (context.isAdmin()) {
//全平台的用户数据
queryAccountList = queryConditionalAccount(context, new ArrayList<>(), new ArrayList<>());
} else {
HQAccountInManageParam hp = new HQAccountInManageParam();
hp.setAccountId(context.getAccountId());
hp.setSiteId(context.getSiteId());
hp.setModuleType(AuthzConstant.moduleType.statistics_research);
ReportAccountRespInManageVO vo = reportClient.getRangeAccountsInManage(hp);
queryAccountList = vo.getList();
if (CollectionUtils.isEmpty(queryAccountList)) {
queryAccountList = new ArrayList<>();
}
}
return queryAccountList;
}
//查询指定范围内的人
private List<ReportAccountRespVO> queryConditionalAccount(RequestContext context, List<Long> orgIds, List<Long> accountIds) {
ReportRangeAccountReqVO rrarv = new ReportRangeAccountReqVO();
rrarv.setSiteId(context.getSiteId());
rrarv.setOrgIds(orgIds);
rrarv.setAccountIds(accountIds);
List<ReportAccountRespVO> queryAccountList = reportClient.getRangeAccounts(rrarv);
if (CollectionUtils.isEmpty(queryAccountList)) {
queryAccountList = new ArrayList<>();
}
return queryAccountList;
}
}
package com.yizhi.research.application.download;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.core.application.context.TaskContext;
import com.yizhi.core.application.file.constant.FileConstant;
import com.yizhi.core.application.file.task.AbstractDefaultTask;
import com.yizhi.core.application.file.util.OssUpload;
import com.yizhi.research.application.mapper.TrResearchAnswerMapper;
import com.yizhi.research.application.mapper.TrResearchAnswerQuestionMapper;
import com.yizhi.research.application.mapper.TrResearchAnswerQuestionResultMapper;
import com.yizhi.research.application.mapper.TrResearchQuestionMapper;
import com.yizhi.research.application.util.WorkUtil;
import com.yizhi.research.application.service.*;
import com.yizhi.research.application.vo.domain.*;
import com.yizhi.research.application.vo.report.DownloadParamsVoOnTime;
import com.yizhi.research.application.vo.report.ReportResearchAnalyze;
import com.yizhi.research.application.vo.report.ResearchGroupViewVo;
import com.yizhi.system.application.constant.AuthzConstant;
import com.yizhi.system.application.system.remote.AccountClient;
import com.yizhi.system.application.system.remote.ReportClient;
import com.yizhi.system.application.vo.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileOutputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import static com.yizhi.core.application.log.TaskLogEvent.working;
import static java.math.BigDecimal.ROUND_HALF_DOWN;
@Component
public class DownloadResearchAnalyze1 extends AbstractDefaultTask<String, DownloadParamsVoOnTime> {
private static final Logger logger = LoggerFactory.getLogger(DownloadResearchAnalyze1.class);
private SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
private SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Autowired
private WorkUtil workUtil;
@Autowired
private ITrResearchQuestionService researchQuestionService;
@Autowired
ITrResearchQuestionOptionService iTrResearchQuestionOptionService;
@Autowired
private ITrResearchAnswerService researchAnswerService;
@Autowired
private TrResearchAnswerMapper trResearchAnswerMapper;
@Autowired
private ReportClient reportClient;
@Autowired
private IResearchService researchService;
@Autowired
private AccountClient accountClient;
@Autowired
private TrResearchQuestionMapper researchQuestionMapper;
@Autowired
private TrResearchAnswerQuestionMapper researchAnswerQuestionMapper;
@Autowired
private TrResearchAnswerQuestionResultMapper researchQuestionResultMapper;
@Autowired
private ITrResearchAnswerQuestionService trResearchAnswerQuestionService;
@Override
protected String execute(DownloadParamsVoOnTime vo) {
Long s12 = System.currentTimeMillis();
Long researchId = vo.getResearchId();
String researchName = vo.getResesrchName();
RequestContext context = vo.getContext();
String taskName = vo.getTaskName();
String serialNo = vo.getSerialNo();
Long taskId = vo.getTaskId();
Long siteId = context.getSiteId();
Date submitTime = new Date();
TaskContext taskContext = new TaskContext(taskId, serialNo, taskName, context.getAccountId(), submitTime, context.getSiteId(), context.getCompanyId());
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
working(taskContext);
// 根据researchId查询该调研所有问题集合
TrResearchQuestion question = new TrResearchQuestion();
question.setDeleted(0);
question.setResearchId(researchId);
EntityWrapper<TrResearchQuestion> questionEW = new EntityWrapper<>(question);
questionEW.orderBy("no", true);
List<TrResearchQuestion> questions = researchQuestionMapper.selectList(questionEW);
//获取问题选项列表
List<TrResearchQuestionOption> trResearchQuestionOptions = iTrResearchQuestionOptionService.listAll(researchId);
if (trResearchQuestionOptions == null) {
trResearchQuestionOptions = new ArrayList<>();
}
// 以问题id为key,问题选项为value的map
Map<Long, List<TrResearchQuestionOption>> questionOptionMap = new HashMap<>();
for (TrResearchQuestionOption option : trResearchQuestionOptions) {
if (!questionOptionMap.containsKey(option.getQuestionId())) {
List<TrResearchQuestionOption> list = new ArrayList<>();
list.add(option);
questionOptionMap.put(option.getQuestionId(), list);
} else {
questionOptionMap.get(option.getQuestionId()).add(option);
}
}
// 根据调研id、用户id,查出答卷与问题关联关系的集合
TrResearchAnswerQuestion answerQuestion = new TrResearchAnswerQuestion();
answerQuestion.setResearchId(researchId);
EntityWrapper<TrResearchAnswerQuestion> answerQuestionEW = new EntityWrapper<TrResearchAnswerQuestion>(answerQuestion);
List<TrResearchAnswerQuestion> answerQuestions = researchAnswerQuestionMapper.selectList(answerQuestionEW);
// 以问题id为key,问题答卷关联ids为value的map
Map<Long, List<Long>> answerQuestionMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(answerQuestions)) {
answerQuestions.forEach(a -> {
if (!answerQuestionMap.containsKey(a.getQuestionId())) {
List<Long> answerQuestionIds = new ArrayList<>();
answerQuestionIds.add(a.getId());
answerQuestionMap.put(a.getQuestionId(), answerQuestionIds);
} else {
answerQuestionMap.get(a.getQuestionId()).add(a.getId());
}
});
}
// 根据答卷id,查出该学员的问题答案集合
TrResearchAnswerQuestionResult questionResult = new TrResearchAnswerQuestionResult();
questionResult.setResearchId(researchId);
List<TrResearchAnswerQuestionResult> questionResults = researchQuestionResultMapper.selectList(new EntityWrapper<TrResearchAnswerQuestionResult>(questionResult));
Map<Long, List<TrResearchAnswerQuestionResult>> answerResultMap = new HashMap<>();
// 以问题答卷关联id为key,问题答案为value的 map
if (!org.springframework.util.CollectionUtils.isEmpty(questionResults)) {
for (TrResearchAnswerQuestionResult result : questionResults) {
if (answerResultMap.get(result.getAnswerQuestionId()) == null) {
List<TrResearchAnswerQuestionResult> list = new ArrayList<>();
list.add(result);
answerResultMap.put(result.getAnswerQuestionId(), list);
} else {
answerResultMap.get(result.getAnswerQuestionId()).add(result);
}
}
}
//以分数为key,分数位置为value
Map<Integer, Integer> scoreIndexMap = new HashMap<>();
Integer scoreTem = 10;
Integer indexTem = 1;
for (indexTem = 1; indexTem <= 11; indexTem++) {
scoreIndexMap.put(scoreTem, indexTem);
scoreTem--;
}
// //这里主要获取问答题需要的字段数据 name、submitTime
List<ResearchGroupViewVo> researchGroupViewVos = trResearchAnswerMapper.queryAnswerRecord(researchId, siteId);
researchGroupViewVos = fillGroupViewVo(researchGroupViewVos);
//组装 以用户id为key ,用户答题主体记录为value的map
Map<Long, ResearchGroupViewVo> statisticsResearchMap = new HashMap<Long, ResearchGroupViewVo>();
for (ResearchGroupViewVo researchGroupViewVo : researchGroupViewVos) {
if (researchGroupViewVo == null) {
continue;
}
statisticsResearchMap.put(researchGroupViewVo.getAccountId(), researchGroupViewVo);
}
String upLoadUrl = null;
String requestPath = FileConstant.SAVE_PATH;
// String requestPath = "E\\";
File fileDir = new File(requestPath);
if (!fileDir.exists()) {
fileDir.mkdir();
}
XSSFWorkbook workbook = new XSSFWorkbook();
//创建单元格格式
XSSFCellStyle style = workbook.createCellStyle();
style.setAlignment(HorizontalAlignment.LEFT);//创建居左格式
Cell cell;
String sheetName = workUtil.chechPattonPattern(researchName + "调研分析表");
XSSFSheet sheet = workbook.createSheet(sheetName);
//创建第一行
XSSFRow row = sheet.createRow((int) 0);
cell = row.createCell(0);
cell.setCellValue(researchName);
//创建第二行
row = sheet.createRow((int) 1);
cell = row.createCell(0);
String deadline = format.format(submitTime);
cell.setCellValue("统计周期:" + "截止" + deadline);
//获取实际参加人数
Integer realJoinNum = (researchGroupViewVos == null ? 0 : researchGroupViewVos.size());
Integer canjoinNum = 0;
//获取可参加人数
canjoinNum = queryCanJoinNum(researchId, context);
ReportResearchAnalyze reportResearchAnalyze = new ReportResearchAnalyze();
reportResearchAnalyze.setJoinCount(canjoinNum == null ? 0 : canjoinNum);
reportResearchAnalyze.setRealJoinCount(realJoinNum);
reportResearchAnalyze.setSubmitCount(realJoinNum);
reportResearchAnalyze.setQuestionCount(questions == null ? 0 : questions.size());
//创建第三行
row = sheet.createRow((int) 2);
row.createCell(0).setCellValue("题目总数:" + reportResearchAnalyze.getQuestionCount());
row.createCell(1).setCellValue("提交问卷份数:" + reportResearchAnalyze.getSubmitCount());
row.createCell(2).setCellValue("可参加人数:" + reportResearchAnalyze.getJoinCount());
row.createCell(3).setCellValue("实际参加人数:" + reportResearchAnalyze.getRealJoinCount());
try {
// //答卷的问题
BigDecimal dou;
BigDecimal b = new BigDecimal(100);
int s = 0;
//第四行组装数据开始
int index = 3;
Long questionId = null;
if (CollectionUtils.isNotEmpty(questions)) {
for (TrResearchQuestion trResearchQuestion : questions) {
row = sheet.createRow((int) index);
index++;
String typeName = null;
switch (trResearchQuestion.getType()) {
case 1:
typeName = "、" + "(单选题)";
break;
case 2:
typeName = "、" + "(多选题)";
break;
case 3:
typeName = "、" + "(问答题)";
break;
case 4:
typeName = "、" + "(打分题)";
break;
}
//每道题的题目
row.createCell(0).setCellValue(trResearchQuestion.getNo() + typeName + trResearchQuestion.getContent());
questionId = trResearchQuestion.getId();
List<Long> answerQuestionIds = answerQuestionMap.get(questionId);
Integer valid = answerQuestionIds == null ? 0 : answerQuestionIds.size();
//选则题
if (trResearchQuestion.getType() == 1 || trResearchQuestion.getType() == 2) {
row.createCell(1).setCellValue("有效填写:" + valid);
row = sheet.createRow((int) index);
row.createCell(0).setCellValue("选项");
row.createCell(1).setCellValue("小计");
row.createCell(2).setCellValue("比例");
index++;//行索引
List<TrResearchQuestionOption> optionList = questionOptionMap.get(questionId);
if (CollectionUtils.isNotEmpty(optionList)) {
for (TrResearchQuestionOption option : optionList) {
row = sheet.createRow((int) index);
//填写选项内容
row.createCell(0).setCellValue(option.getContent());
index++;
//获取单选题类型该问题 答题了的选项总数
Integer totalCount1 = 0;
//获取多选题选题类型该问题 答题了的选项总数
Integer totalCount2 = 0;
//每个选项被选了的数目
Integer checkCount = 0;
if (CollectionUtils.isNotEmpty(answerQuestionIds)) {
for (Long a : answerQuestionIds) {
List<TrResearchAnswerQuestionResult> results = answerResultMap.get(a);
if (CollectionUtils.isNotEmpty(results)) {
for (TrResearchAnswerQuestionResult result : results) {
Integer type = result.getQuestionType();
if (type == 1 && result.getOptionId() != null) {
++totalCount1;
} else if (type == 2 && result.getOptionId() != null) {
++totalCount2;
}
if (type == 1 || type == 2) {
if (option.getId().equals(result.getOptionId())) {
++checkCount;
}
}
}
}
}
}
//填写小计数据
row.createCell(1).setCellValue(checkCount);
//填写比例值
cell = row.createCell(2);
if (checkCount == 0) {
cell.setCellValue("0%");
} else {
BigDecimal checkNum = new BigDecimal(checkCount);
BigDecimal totalNum = new BigDecimal(1);
if (trResearchQuestion.getType() == 1) {
totalNum = new BigDecimal(totalCount1);
} else if (trResearchQuestion.getType() == 2) {
totalNum = new BigDecimal(totalCount2);
}
BigDecimal tem = new BigDecimal(100);
cell.setCellValue((checkNum.multiply(tem).divide(totalNum, 2, ROUND_HALF_DOWN)) + "%");
}
}
}
//问答题
} else if (trResearchQuestion.getType() == 3) {
for (ResearchGroupViewVo groupViewVo : researchGroupViewVos) {
row = sheet.createRow((int) index);
index++;
//填写答题人的用户名
String accountName = groupViewVo.getAccountName();
row.createCell(0).setCellValue(accountName == null ? "" : accountName);
//填写完成时间
Date date = groupViewVo.getFinishTime();
row.createCell(1).setCellValue(sdf1.format(date == null ? 0 : date));
//填写回答内容
if (CollectionUtils.isNotEmpty(answerQuestionIds)) {
TrResearchAnswerQuestion tem = new TrResearchAnswerQuestion();
tem.setAccountId(groupViewVo.getAccountId());
tem.setQuestionId(questionId);
tem.setResearchId(researchId);
tem = this.trResearchAnswerQuestionService.selectOne(new EntityWrapper<>(tem));
if (tem != null) {
List<TrResearchAnswerQuestionResult> results = answerResultMap.get(tem.getId());
TrResearchAnswerQuestionResult result = results.get(0);
String content = result.getContent();
row.createCell(2).setCellValue(content == null ? "" : content);
}
}
}
} else {
//打分题
row.createCell(1).setCellValue("有效填写:" + valid);
row = sheet.createRow((int) index);
index++;
row.createCell(0).setCellValue("打分项");
row.createCell(1).setCellValue("10");
row.createCell(2).setCellValue("9");
row.createCell(3).setCellValue("8");
row.createCell(4).setCellValue("7");
row.createCell(5).setCellValue("6");
row.createCell(6).setCellValue("5");
row.createCell(7).setCellValue("4");
row.createCell(8).setCellValue("3");
row.createCell(9).setCellValue("2");
row.createCell(10).setCellValue("1");
row.createCell(11).setCellValue("0");
row.createCell(12).setCellValue("参与人数");
row.createCell(13).setCellValue("最高分");
row.createCell(14).setCellValue("最低分");
row.createCell(15).setCellValue("总分");
row.createCell(16).setCellValue("平均分");
//取出该问题的选项集合
List<TrResearchQuestionOption> options = questionOptionMap.get(questionId);
if (options == null) {
continue;
}
for (TrResearchQuestionOption option : options) {
row = sheet.createRow(index);
index++;
//填写选项内容
row.createCell(0).setCellValue(option.getContent() == null ? "" : option.getContent());
List<Long> answerQuestionIds1 = answerQuestionMap.get(questionId);
if (answerQuestionIds1 == null) {
continue;
}
Integer joinNum = 0;
Integer maxScore = 0;
Integer minScore = 0;
Integer totalScore = 0;
String avgScore = "";
//计数
Integer num = 1;
//以分数为key,选择人数为value
Map<Integer, Integer> scoreMap = new HashMap<>();
for (Long id : answerQuestionIds1) {
List<TrResearchAnswerQuestionResult> results = answerResultMap.get(id);
if (results == null) {
continue;
}
for (TrResearchAnswerQuestionResult result : results) {
if (result.getQuestionType() == 4) {
if (result.getOptionId().equals(option.getId())) {
Integer score = result.getScore();
joinNum = num;
totalScore = totalScore + score;
BigDecimal a = new BigDecimal(totalScore);
BigDecimal c = new BigDecimal(joinNum);
avgScore = a.divide(c, 2, ROUND_HALF_DOWN).toString();
BigDecimal avg = new BigDecimal(avgScore);
if (score > maxScore) {
maxScore = score;
}
if (score < minScore) {
minScore = score;
}
num++;
if (!scoreMap.containsKey(score)) {
scoreMap.put(score, 1);
} else {
Integer tem = scoreMap.get(score);
scoreMap.put(score, (tem + 1));
}
}
}
}
}
Integer tem = 10;
for (; tem >= 0; tem--) {
//获取选择了该分数的参与人数
Integer theOptionJoinNum = scoreMap.get(tem);
if (theOptionJoinNum == null) {
continue;
}
//获取该分数的位置
Integer scoreIndex = scoreIndexMap.get(tem);
//填写选择了该分数的人数
row.createCell(scoreIndex).setCellValue(theOptionJoinNum);
}
//填写参与人数
row.createCell(12).setCellValue(joinNum);
//填写最高分
row.createCell(13).setCellValue(maxScore);
//填写最低分
row.createCell(14).setCellValue(minScore);
//填写总分
row.createCell(15).setCellValue(totalScore);
//填写平均分
row.createCell(16).setCellValue(avgScore);
}
}
}
}
//导出
StringBuffer fileNameSb = new StringBuffer().append(researchName + "分析统计_" + sdf.format(submitTime)).append(".xlsx");
String fileName = fileNameSb.toString();
String path = new StringBuffer().append(requestPath).append(fileNameSb).toString();
FileOutputStream os = null;
File file = null;
try {
os = new FileOutputStream(path);
workbook.write(os);
//阿里云返回url
upLoadUrl = OssUpload.upload(path, fileName);
file = new File(path);
success(taskContext, "成功", upLoadUrl);
} catch (Exception e1) {
e1.printStackTrace();
fail(taskContext, "写入过程中发生错误");
logger.error("写入数据到Excel的过程中或者上传到阿里云中发生错误");
} finally {
if (os != null) {
os.close();
}
if (workbook != null) {
workbook.close();
}
if (file != null) {
file.delete();
}
}
} catch (
Exception e) {
e.printStackTrace();
fail(taskContext, researchName + "导出过程中发生错误,请查看日志");
logger.error("创建Excel的过程中发生错误");
}
System.out.println("系统运行啦" + (System.currentTimeMillis() - s12));
return upLoadUrl;
}
private Integer queryCanJoinNum(Long researchId, RequestContext context) {
Integer canJoinNum = 0;
//"可见范围,1平台用户可见(企业下所有人员) 2指定学员可见"
Integer visibRange = researchService.selectById(researchId).getVisibleRange();
List<Long> accountIds = new ArrayList<>();
List<Long> orgIds = new ArrayList<>();
// 如果是调研指定范围
if (visibRange == 2) {
TrResearchAuthorize example = new TrResearchAuthorize();
example.setResearchId(researchId);
List<TrResearchAuthorize> authorizes = example.selectList(new EntityWrapper(example));
if (CollectionUtils.isNotEmpty(authorizes)) {
for (TrResearchAuthorize authorize : authorizes) {
if (authorize.getType().equals(1)) {
orgIds.add(authorize.getRelationId());
} else {
accountIds.add(authorize.getRelationId());
}
}
//获取调研可见范围内的用户数据
List<ReportAccountRespVO> queryAccountList = queryConditionalAccount(context, orgIds, accountIds);
List<Long> accountIdList = new ArrayList<>();
//获取全平台或者管辖区人员数据
List<ReportAccountRespVO> manageAccountList = queryAccountList(context, orgIds, accountIds);
if (CollectionUtils.isNotEmpty(queryAccountList)) {
if (CollectionUtils.isNotEmpty(manageAccountList)) {
for (ReportAccountRespVO vo : queryAccountList) {
for (ReportAccountRespVO manageVo : manageAccountList) {
if (manageVo.equals(vo.getUserId())) {
accountIdList.add(vo.getUserId());
}
}
}
canJoinNum = accountIdList.size();
}
}
}
} else {
//获取全平台或者管辖区人员数据 orgids,accountIds 都是空的
List<ReportAccountRespVO> queryAccountList = queryAccountList(context, orgIds, accountIds);
canJoinNum = queryAccountList.size();
}
return canJoinNum;
}
private List<ResearchGroupViewVo> fillGroupViewVo(List<ResearchGroupViewVo> researchGroupViewVos) {
List<Long> accountIds = new ArrayList<>();
if (CollectionUtils.isNotEmpty(researchGroupViewVos)) {
for (ResearchGroupViewVo groupViewVo : researchGroupViewVos) {
accountIds.add(groupViewVo.getAccountId());
}
List<AccountVO> accountVOs = accountClient.idsGet(accountIds);
//获取 《accountId,name》Map集合
Map<Long, String> accountMap = new HashMap<>();
//实时取用户名
accountVOs.forEach(accountVo -> {
if (!accountMap.containsKey(accountVo.getId())) {
accountMap.put(accountVo.getId(), accountVo.getName());
}
});
for (ResearchGroupViewVo groupViewVo : researchGroupViewVos) {
groupViewVo.setAccountName(accountMap.get(groupViewVo.getAccountId()));
}
return researchGroupViewVos;
}
return new ArrayList<>();
}
//获取全平台或者管辖区人员数据
private List<ReportAccountRespVO> queryAccountList(RequestContext context, List<Long> orgIds, List<Long> accountIds) {
List<ReportAccountRespVO> queryAccountList = new ArrayList<>();
if (context.isAdmin()) {
//全平台的用户数据
queryAccountList = queryConditionalAccount(context, new ArrayList<>(), new ArrayList<>());
} else {
HQAccountInManageParam hp = new HQAccountInManageParam();
hp.setAccountId(context.getAccountId());
hp.setSiteId(context.getSiteId());
hp.setModuleType(AuthzConstant.moduleType.statistics_research);
ReportAccountRespInManageVO vo = reportClient.getRangeAccountsInManage(hp);
queryAccountList = vo.getList();
if (CollectionUtils.isEmpty(queryAccountList)) {
queryAccountList = new ArrayList<>();
}
}
return queryAccountList;
}
//查询指定范围内的人
private List<ReportAccountRespVO> queryConditionalAccount(RequestContext context, List<Long> orgIds, List<Long> accountIds) {
ReportRangeAccountReqVO rrarv = new ReportRangeAccountReqVO();
rrarv.setSiteId(context.getSiteId());
rrarv.setOrgIds(orgIds);
rrarv.setAccountIds(accountIds);
List<ReportAccountRespVO> queryAccountList = reportClient.getRangeAccounts(rrarv);
if (CollectionUtils.isEmpty(queryAccountList)) {
queryAccountList = new ArrayList<>();
}
return queryAccountList;
}
}
package com.yizhi.research.application.download;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.core.application.context.TaskContext;
import com.yizhi.core.application.file.constant.FileConstant;
import com.yizhi.core.application.file.task.AbstractDefaultTask;
import com.yizhi.core.application.file.util.OssUpload;
import com.yizhi.research.application.mapper.TrResearchAnswerMapper;
import com.yizhi.research.application.service.IResearchService;
import com.yizhi.research.application.service.ITrResearchAnswerService;
import com.yizhi.research.application.service.ITrResearchQuestionService;
import com.yizhi.research.application.util.WorkUtil;
import com.yizhi.research.application.vo.api.ViewAnswerQuestionOptionVo;
import com.yizhi.research.application.vo.api.ViewAnswerQuestionVo;
import com.yizhi.research.application.vo.api.ViewAnswerVo;
import com.yizhi.research.application.vo.domain.TrResearchAuthorize;
import com.yizhi.research.application.vo.domain.TrResearchQuestion;
import com.yizhi.research.application.vo.domain.TrResearchQuestionOption;
import com.yizhi.research.application.vo.report.DownloadParamsVoOnTime;
import com.yizhi.research.application.vo.report.ResearchGroupViewVo;
import com.yizhi.system.application.constant.AuthzConstant;
import com.yizhi.system.application.system.remote.ReportClient;
import com.yizhi.system.application.vo.HQAccountInManageParam;
import com.yizhi.system.application.vo.ReportAccountRespInManageVO;
import com.yizhi.system.application.vo.ReportAccountRespVO;
import com.yizhi.system.application.vo.ReportRangeAccountReqVO;
import org.apache.commons.collections.CollectionUtils;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
@Component
public class DownloadResearchDetails extends AbstractDefaultTask<String, DownloadParamsVoOnTime> {
private static final Logger logger = LoggerFactory.getLogger(DownloadResearchDetails.class);
@Autowired
private ReportClient reportClient;
@Autowired
private ITrResearchAnswerService researchAnswerService;
@Autowired
private TrResearchAnswerMapper trResearchAnswerMapper;
@Autowired
private ITrResearchQuestionService researchQuestionService;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
@Autowired
private WorkUtil workUtil;
@Autowired
private IResearchService researchService;
@Override
protected String execute(DownloadParamsVoOnTime vo) {
String upLoadUrl = null;
String requestPath = FileConstant.SAVE_PATH;
// String requestPath = "/Users/dingxiaowei/aaa";
// String requestPath = "E\\";
File fileDir = new File(requestPath);
if (!fileDir.exists()) {
fileDir.mkdir();
}
Long researchId = vo.getResearchId();
String researchName = vo.getResesrchName();
RequestContext context = vo.getContext();
String taskName = vo.getTaskName();
String serialNo = vo.getSerialNo();
Long taskId = vo.getTaskId();
Date submitTime = new Date();
Long accountId = context.getAccountId();
TaskContext taskContext = new TaskContext(taskId, serialNo, taskName, accountId, submitTime, context.getSiteId(), context.getCompanyId());
working(taskContext);
List<ViewAnswerVo> viewAnswerVos = new ArrayList<>();
List<ViewAnswerVo> viewAnswerVos1;
List<ResearchGroupViewVo> researchGroupViewVos = null;
try {
//获取回答记录
viewAnswerVos1 = researchAnswerService.viewAnswerVoList(researchId, 1, Integer.MAX_VALUE);
viewAnswerVos.addAll(viewAnswerVos1);
//学员答卷map 《学员id,答卷记录》
Map<Long, ResearchGroupViewVo> accountIdRecordMap = new HashMap<>();
researchGroupViewVos = new ArrayList<>();
List<ResearchGroupViewVo> joinAccounts = new ArrayList<>();
List<ResearchGroupViewVo> noJoinAccounts = new ArrayList<>();
// //这里主要获取学员回答记录
List<ResearchGroupViewVo> answerRecords = trResearchAnswerMapper.queryAnswerRecord(researchId, context.getSiteId());
if (CollectionUtils.isNotEmpty(answerRecords)) {
answerRecords.forEach(a -> {
if (!accountIdRecordMap.containsKey(a.getAccountId())) {
accountIdRecordMap.put(a.getAccountId(), a);
}
});
}
//获取要参加的人员信息
List<ReportAccountRespVO> accountList = queryCanJoinAccount(researchId, context);
if (CollectionUtils.isNotEmpty(accountList)) {
for (ReportAccountRespVO account : accountList) {
//组装下面Excel需要的数据
ResearchGroupViewVo cellValue = new ResearchGroupViewVo();
cellValue.setAccountId(account.getUserId());
cellValue.setAccountName(account.getUserName());
cellValue.setAccountFullName(account.getUserFullName());
cellValue.setOrgName(account.getOrgName());
if (accountIdRecordMap.containsKey(account.getUserId())) {
ResearchGroupViewVo tem = accountIdRecordMap.get(account.getUserId());
cellValue.setFinishTime(tem.getFinishTime());
cellValue.setJoinState(1);
joinAccounts.add(cellValue);
} else {
cellValue.setJoinState(0);
noJoinAccounts.add(cellValue);
}
}
//为了保证参加啦的人顺序排在前面
researchGroupViewVos.addAll(joinAccounts);
researchGroupViewVos.addAll(noJoinAccounts);
}
} catch (Exception e) {
e.printStackTrace();
fail(taskContext, researchName + "获取数据过程中出现错误,请查看日志");
logger.error("获取数据过程中出现错误");
}
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
//excel生成:excel-sheet-row-cell
XSSFWorkbook workbook = new XSSFWorkbook();
//创建单元格格式
XSSFCellStyle style = workbook.createCellStyle();
style.setAlignment(HorizontalAlignment.LEFT);//创建居左格式
String sheetName = workUtil.chechPattonPattern(researchName + "_" + dateFormat.format(submitTime));
XSSFSheet sheet = workbook.createSheet(sheetName);
XSSFRow row;
XSSFCell cell;
//创建第三行列名
row = sheet.createRow((int) 2);
cell = row.createCell((short) 0);
cell.setCellValue("用户名");
cell = row.createCell((short) 1);
cell.setCellValue("姓名");
cell = row.createCell((short) 2);
cell.setCellValue("是否完成");
cell = row.createCell((short) 3);
cell.setCellValue("提交时间");
//确定提交时间的位置
int cellSize = 3;
//第一个问题的位置
int index = 4;
//获取问题及其选项
if (CollectionUtils.isNotEmpty(viewAnswerVos)) {
}
List<TrResearchQuestion> trResearchQuestions = researchQuestionService.listAll(researchId);
if (CollectionUtils.isEmpty(trResearchQuestions)) {
trResearchQuestions = new ArrayList<>();
}
cellSize += trResearchQuestions.size();
List<TrResearchQuestionOption> trResearchQuestionOptions;
//储存 一个问题对应的位置,下面就可以直接通过问题id定位位置。
Map<Long, Integer> locationMap = new HashMap<Long, Integer>();
//储存 一个问题选项对应的位置,下面就可以直接通过问题选项id定位位置。
Map<Long, Integer> optionLocationMap = new HashMap<Long, Integer>();
for (TrResearchQuestion trResearchQuestion : trResearchQuestions) {
cell = row.createCell((short) index);
if (null != trResearchQuestion.getId()) {
locationMap.put(trResearchQuestion.getId(), index);
}
index++;
if (trResearchQuestion.getContent() != null) {
cell.setCellValue(trResearchQuestion.getContent());
}
trResearchQuestionOptions = trResearchQuestion.getOptions();
if (trResearchQuestionOptions == null) {
continue;
}
if (trResearchQuestion.getType() == 4) {
for (TrResearchQuestionOption trResearchQuestionOption : trResearchQuestionOptions) {
cell = row.createCell((short) index);
if (trResearchQuestionOption.getContent() != null) {
cell.setCellValue(trResearchQuestionOption.getContent());
}
if (null != trResearchQuestionOption.getId()) {
optionLocationMap.put(trResearchQuestionOption.getId(), index);
}
index++;
}
cellSize += trResearchQuestionOptions.size();
}
}
cell = row.createCell((short) cellSize + 1);
cell.setCellValue("所在部门");
// 在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short,
// 创建第1行
row = sheet.createRow((int) 0);
//合并单元格
CellRangeAddress cra = new CellRangeAddress(0, 0, 0, cellSize); // 起始行, 终止行, 起始列, 终止列
sheet.addMergedRegion(cra);
//合并前6列当做第0行的第0列
cell = row.createCell((short) 0);
cell.setCellValue(researchName + "调研明细表");
cell.setCellStyle(style);
//创建第2行
row = sheet.createRow((int) 1);
CellRangeAddress cra1 = new CellRangeAddress(1, 1, 0, cellSize); // 起始行, 终止行, 起始列, 终止列
sheet.addMergedRegion(cra1);
cell = row.createCell((short) 0);
String deadline = format.format(submitTime);
cell.setCellValue("统计周期:" + "截止" + deadline);
cell.setCellStyle(style);
//答卷
ViewAnswerVo viewAnswerVo;
//答卷的问题
ViewAnswerQuestionVo viewAnswerQuestionVo;
//答卷下问题选项
ViewAnswerQuestionOptionVo viewAnswerQuestionOptionVo;
//这些实体的列表
List<ViewAnswerQuestionVo> viewAnswerQuestionVos;
List<ViewAnswerQuestionOptionVo> viewAnswerQuestionOptionVos;
Map<Long, ViewAnswerVo> viewAnswerVoMap = new HashMap<Long, ViewAnswerVo>();
String[] parentNames;
Long questionId;
Long optionId;
int location;
//把accountId和提交的答案关联
for (ViewAnswerVo viewAnswerVo1 : viewAnswerVos) {
viewAnswerVoMap.put(viewAnswerVo1.getAccountId(), viewAnswerVo1);
}
int s = 0;
//遍历中间表
//代表第四行 开始填写数据
Integer i = 3;
for (ResearchGroupViewVo groupViewVo : researchGroupViewVos) {
row = sheet.createRow(i);
i++;
cell = row.createCell((short) 0);
if (groupViewVo.getAccountName() != null) {
cell.setCellValue(groupViewVo.getAccountName());
}
cell = row.createCell((short) 1);
if (groupViewVo.getAccountFullName() != null) {
cell.setCellValue(groupViewVo.getAccountFullName());
}
cell = row.createCell((short) 2);
if (groupViewVo.getJoinState() == 1) {
cell.setCellValue("是");
} else {
cell.setCellValue("否");
}
cell = row.createCell((short) 3);
if (groupViewVo.getFinishTime() != null) {
cell.setCellValue(format.format(groupViewVo.getFinishTime()));
} else {
cell.setCellValue("--");
}
//用户没有参加,给所有的问题答案表格 赋值“--”
if (groupViewVo.getJoinState().equals(0)) {
//所在部门前面一个cell的位置
Integer cellMax = cellSize;
for (int o = 4; o <= cellMax; o++) {
cell = row.createCell((short) o);
cell.setCellValue("--");
}
} else {
viewAnswerVo = viewAnswerVoMap.get(groupViewVo.getAccountId());
viewAnswerQuestionVos = viewAnswerVo.getAnswerQuestions();
if (viewAnswerQuestionVos == null) {
viewAnswerQuestionVos = new ArrayList<>();
continue;
}
//如果参加了,自然会给相应cell赋值
// 查询考卷的问题
for (int j = 0; j < viewAnswerQuestionVos.size(); j++) {
viewAnswerQuestionVo = viewAnswerQuestionVos.get(j);
questionId = viewAnswerQuestionVo.getId();
if (null != locationMap.get(questionId)) {
//获取该问题对应的位置
location = locationMap.get(questionId);
} else {
continue;
}
Integer num = null;
// 对获取的答卷的问题和答案进行组装
for (TrResearchQuestion question : trResearchQuestions) {
if (question.getId().equals(viewAnswerQuestionVo.getId())) {
if (num == null) {
num = question.getJumpNum();
if (viewAnswerQuestionVo.getType() == 4) {
row.createCell((short) location);
}
if (viewAnswerQuestionVo.getType() == 3) {
cell = row.createCell(location);
if (viewAnswerQuestionVo.getAnswerContent() != null) {
cell.setCellValue(viewAnswerQuestionVo.getAnswerContent());
}
}
viewAnswerQuestionOptionVos = viewAnswerQuestionVo.getOptions();
if (viewAnswerQuestionOptionVos == null) {
continue;
}
for (int k = 0; k < viewAnswerQuestionOptionVos.size(); k++) {
viewAnswerQuestionOptionVo = viewAnswerQuestionOptionVos.get(k);
//问题类型
Integer questionType = viewAnswerQuestionVo.getType();
//选项名称
String optionContent = viewAnswerQuestionOptionVo.getContent();
//问答题回答内容或者其他选项回答内容
String answerContent = viewAnswerQuestionOptionVo.getAnswerContent();
//该选项是否被选中
Boolean checked = viewAnswerQuestionOptionVo.getAnswerChecked();
if (questionType == 1 && checked) {
cell = row.createCell((short) location);
if (optionContent != null) {
//如果有其他选项,则也赋值
if (answerContent != null && !answerContent.trim().equals("")) {
optionContent = optionContent + "--" + answerContent;
}
cell.setCellValue(optionContent);
}
num = viewAnswerQuestionOptionVo.getJumpNum();
} else if (questionType == 2 && checked) {
if (row.getCell(location) != null) {
cell = row.getCell(location);
if (optionContent != null) {
cell.setCellValue(cell.getStringCellValue() + "、" + optionContent);
}
} else {
cell = row.createCell(location);
if (optionContent != null) {
if (answerContent != null && !answerContent.trim().equals("")) {
optionContent = optionContent + "--" + answerContent;
}
cell.setCellValue(optionContent);
}
}
} else {
optionId = viewAnswerQuestionOptionVo.getId();
if (optionLocationMap.get(optionId) != null) {
location = optionLocationMap.get(optionId);
} else {
continue;
}
cell = row.createCell(location);
if (viewAnswerQuestionOptionVo.getAnswerScore() != null) {
cell.setCellValue(viewAnswerQuestionOptionVo.getAnswerScore());
}
}
}
// 判断当前题目是不是上一题所跳的题
} else if (num != null && question.getNo().equals(num)) {
num = question.getJumpNum();
if (viewAnswerQuestionVo.getType() == 4) {
row.createCell((short) location);
}
if (viewAnswerQuestionVo.getType() == 3) {
cell = row.createCell(location);
if (viewAnswerQuestionVo.getAnswerContent() != null) {
cell.setCellValue(viewAnswerQuestionVo.getAnswerContent());
}
}
viewAnswerQuestionOptionVos = viewAnswerQuestionVo.getOptions();
if (viewAnswerQuestionOptionVos == null) {
continue;
}
for (int k = 0; k < viewAnswerQuestionOptionVos.size(); k++) {
viewAnswerQuestionOptionVo = viewAnswerQuestionOptionVos.get(k);
//问题类型
Integer questionType = viewAnswerQuestionVo.getType();
//选项名称
String optionContent = viewAnswerQuestionOptionVo.getContent();
//问答题回答内容或者其他选项回答内容
String answerContent = viewAnswerQuestionOptionVo.getAnswerContent();
//该选项是否被选中
Boolean checked = viewAnswerQuestionOptionVo.getAnswerChecked();
if (questionType == 1 && checked) {
cell = row.createCell((short) location);
if (optionContent != null) {
//如果有其他选项,则也赋值
if (answerContent != null && !answerContent.trim().equals("")) {
optionContent = optionContent + "--" + answerContent;
}
cell.setCellValue(optionContent);
}
num = viewAnswerQuestionOptionVo.getJumpNum();
} else if (questionType == 2 && checked) {
if (row.getCell(location) != null) {
cell = row.getCell(location);
if (optionContent != null) {
cell.setCellValue(cell.getStringCellValue() + "、" + optionContent);
}
} else {
cell = row.createCell(location);
if (optionContent != null) {
if (answerContent != null && !answerContent.trim().equals("")) {
optionContent = optionContent + "--" + answerContent;
}
cell.setCellValue(optionContent);
}
}
} else {
optionId = viewAnswerQuestionOptionVo.getId();
if (optionLocationMap.get(optionId) != null) {
location = optionLocationMap.get(optionId);
} else {
continue;
}
cell = row.createCell(location);
if (viewAnswerQuestionOptionVo.getAnswerScore() != null) {
cell.setCellValue(viewAnswerQuestionOptionVo.getAnswerScore());
}
}
}
}
}
}
}
}
//给部门名称赋值
int location1 = cellSize + 1;
if (groupViewVo.getOrgName() != null) {
cell = row.createCell((short) location1);
cell.setCellValue(groupViewVo.getOrgName());
} else {
row.createCell((short) location1);
}
s++;
// taskDetail(taskContext.getTaskId(), research.getName() + "导出数据第" + s + "行成功");
}
//导出
StringBuffer fileNameSb = new StringBuffer().append(researchName + "结果明细表-" + dateFormat.format(submitTime)).append(".xlsx");
String fileName = fileNameSb.toString();
String path = new StringBuffer().append(requestPath).append(fileNameSb).toString();
FileOutputStream os = null;
File file = null;
try {
os = new FileOutputStream(path);
workbook.write(os);
//阿里云返回url
upLoadUrl = OssUpload.upload(path, fileName);
// file = new File(path);
file = new File("E\\");
success(taskContext, "成功", upLoadUrl);
} catch (Exception e1) {
e1.printStackTrace();
fail(taskContext, "写入过程中发生错误");
logger.error("写入数据到Excel的过程中或者上传到阿里云中发生错误");
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (workbook != null) {
try {
workbook.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (file != null) {
file.delete();
}
}
} catch (Exception e) {
e.printStackTrace();
fail(taskContext, researchName + "导出过程中发生错误,请查看日志");
logger.error("创建Excel的过程中发生错误");
}
return upLoadUrl;
}
private List<ReportAccountRespVO> queryCanJoinAccount(Long researchId, RequestContext context) {
List<ReportAccountRespVO> sanmeAccountList = new ArrayList<>();
Integer canJoinNum = 0;
//"可见范围,1平台用户可见(企业下所有人员) 2指定学员可见"
Integer visibRange = researchService.selectById(researchId).getVisibleRange();
List<Long> accountIds = new ArrayList<>();
List<Long> orgIds = new ArrayList<>();
// 如果是调研指定范围
if (visibRange == 2) {
TrResearchAuthorize example = new TrResearchAuthorize();
example.setResearchId(researchId);
List<TrResearchAuthorize> authorizes = example.selectList(new EntityWrapper(example));
if (CollectionUtils.isNotEmpty(authorizes)) {
for (TrResearchAuthorize authorize : authorizes) {
if (authorize.getType().equals(1)) {
orgIds.add(authorize.getRelationId());
} else {
accountIds.add(authorize.getRelationId());
}
}
//获取调研可见范围内的accountIds
List<ReportAccountRespVO> queryAccountList = queryConditionalAccount(context, orgIds, accountIds);
sanmeAccountList.addAll(queryAccountList);
// //获取全平台或者管辖区人员数据
// List<ReportAccountRespVO> manageAccountList = queryAccountList(context, orgIds, accountIds);
//
// if (CollectionUtils.isNotEmpty(queryAccountList)) {
// if (CollectionUtils.isNotEmpty(manageAccountList)) {
// for (ReportAccountRespVO vo : queryAccountList) {
// for (ReportAccountRespVO manageVo : manageAccountList) {
// if (manageVo.equals(vo.getUserId())) {
// sanmeAccountList.add(vo);
// }
// }
// }
// }
// }
}
} else {
//获取全平台或者管辖区人员数据 orgids,accountIds 都是空的
sanmeAccountList = queryAccountList(context, orgIds, accountIds);
}
return sanmeAccountList;
}
//获取全平台或者管辖区人员数据
private List<ReportAccountRespVO> queryAccountList(RequestContext context, List<Long> orgIds, List<Long> accountIds) {
List<ReportAccountRespVO> queryAccountList = new ArrayList<>();
if (context.isAdmin()) {
//获取全平台的用户数据
queryAccountList = queryConditionalAccount(context, new ArrayList<>(), new ArrayList<>());
} else {
HQAccountInManageParam hp = new HQAccountInManageParam();
hp.setAccountId(context.getAccountId());
hp.setSiteId(context.getSiteId());
hp.setModuleType(AuthzConstant.moduleType.statistics_research);
ReportAccountRespInManageVO vo = reportClient.getRangeAccountsInManage(hp);
if (null != vo) {
queryAccountList = vo.getList();
if (CollectionUtils.isEmpty(queryAccountList)) {
queryAccountList = new ArrayList<>();
}
}
}
return queryAccountList;
}
//查询指定范围内的人
private List<ReportAccountRespVO> queryConditionalAccount(RequestContext context, List<Long> orgIds, List<Long> accountIds) {
ReportRangeAccountReqVO rrarv = new ReportRangeAccountReqVO();
rrarv.setSiteId(context.getSiteId());
rrarv.setOrgIds(orgIds);
rrarv.setAccountIds(accountIds);
List<ReportAccountRespVO> queryAccountList = reportClient.getRangeAccounts(rrarv);
if (CollectionUtils.isEmpty(queryAccountList)) {
queryAccountList = new ArrayList<>();
}
return queryAccountList;
}
}
package com.yizhi.research.application.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.research.application.model.DataRangeModel;
import com.yizhi.research.application.vo.domain.Research;
import com.yizhi.research.application.vo.domain.TrResearchAuthorize;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.session.RowBounds;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
* <p>
* 调研 Mapper 接口
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
public interface ResearchMapper extends BaseMapper<Research> {
/**
* 后台管理分页列表
*
* @param state
* @param name
* @param rowBounds
* @return
*/
List<Research> listPage(@Param("date") String date, @Param("state") Integer state, @Param("name") String name, @Param("range") DataRangeModel dataRangeModel, RowBounds rowBounds);
Integer listPageCount(@Param("date") String date,@Param("state") Integer state, @Param("name") String name, @Param("range") DataRangeModel dataRangeModel);
/**
* 查询所有
*
* @return
*/
int selectAllCount(@Param("siteId") Long siteId);
/**
* 批量删除(仅能删除草稿状态)
*
* @param ids
* @return
*/
int batchDelete(@Param("ids") List<Long> ids);
/**
* 学员端调研列表
*
* @param idsInRange 可见范围内的调研id集合
* @param now 当前时间
* @return
*/
List<Research> apiListResearch(@Param("idsInRange") List<Long> idsInRange, @Param("accountId") Long accountId,
@Param("siteId") Long siteId, @Param("now") Date now, @Param("state") Integer state,
RowBounds rowBounds);
/**
* 分页模糊查询
*
* @param idsInRange 可见范围内的调研id集合
* @param name
* @param rowBounds
* @return
*/
List<Research> apiSearchPage(@Param("siteId") Long siteId, @Param("name") String name,@Param("accountId") Long accountId,
@Param("now") Date date,@Param("idsInRange") List<Long> idsInRange, RowBounds rowBounds);
/**
* 查询所有进行中的我的调研
*/
Integer apiCountResearch(@Param("idsInRange") List<Long> idsInRange, @Param("accountId") Long accountId,
@Param("siteId") Long siteId, @Param("now") Date now);
int selectListCount(@Param("idsInRange") List<Long> idsInRange, @Param("accountId") Long accountId,
@Param("siteId") Long siteId, @Param("now") Date now, @Param("state") Integer state);
LinkedList<Research> selectRealJoin(@Param("researchIds") List<Long> researchIds);
LinkedList<TrResearchAuthorize> selectRelationIds(@Param("researchIds") List<Long> researchIds);
List<Research> selectResearchPage(
@Param("startDate")String startDate, @Param("endDate")String endDate,
@Param("kwd")String kwd,@Param("orgIds")List<Long> orgIds, @Param("companyId")Long companyId,
@Param("siteId") Long siteId,RowBounds rowBounds);
Integer selectResearchCount(@Param("startDate")String startDate, @Param("endDate")String endDate,
@Param("kwd")String kwd,@Param("orgIds")List<Long> orgIds, @Param("companyId")Long companyId,
@Param("siteId") Long siteId);
List<Map<String, Object>> getPoolExamList(@Param("name") String name, @Param("ids") List<Long> ids,
@Param("companyId") Long companyId,@Param("siteId") Long siteId,
@Param("orgIds") List<Long> orgIds, Page<Map<String, Object>> page);
@Select("select * from research where id = #{id} and deleted =0 ")
Research selectStateOne(@Param("id") Long id);
List<Research> getAllResearchs();
Date selectRecordMinTime();
List<Long> getIdsByDate(@Param("date") Date date,@Param("siteId") Long siteId);
List<Research> getPageToCalendar(@Param("finishTrIds") List<Long> finishTrIds, @Param("trIds") List<Long> trIds, @Param("date") Date date, @Param("siteId") Long siteId, Page<Research> page);
Integer getPageToCalendarNum(@Param("finishTrIds") List<Long> finishTrIds, @Param("trIds") List<Long> trIds, @Param("date") Date date, @Param("siteId") Long siteId);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yizhi.research.application.mapper.ResearchMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.yizhi.research.application.vo.domain.Research">
<id column="tb_id" property="id"/>
<result column="tb_training_project_id" property="trainingProjectId"/>
<result column="tb_research_no" property="researchNo"/>
<result column="tb_point" property="point"/>
<result column="tb_remind" property="remind"/>
<result column="tb_enable_mail_remind" property="enableMailRemind"/>
<result column="tb_mail_template_id" property="mailTemplateId"/>
<result column="tb_enable_app_remind" property="enableAppRemind"/>
<result column="tb_app_template_id" property="appTemplateId"/>
<result column="tb_name" property="name"/>
<result column="tb_start_time" property="startTime"/>
<result column="tb_end_time" property="endTime"/>
<result column="tb_visible_range" property="visibleRange"/>
<result column="tb_content" property="content"/>
<result column="tb_state" property="state"/>
<result column="tb_deleted" property="deleted"/>
<result column="tb_create_time" property="createTime"/>
<result column="tb_create_by_id" property="createById"/>
<result column="tb_create_by_name" property="createByName"/>
<result column="tb_update_time" property="updateTime"/>
<result column="tb_update_by_id" property="updateById"/>
<result column="tb_update_by_name" property="updateByName"/>
<result column="tb_un_release_time" property="unReleaseTime"/>
<result column="tb_un_release_by_id" property="unReleaseById"/>
<result column="tb_un_release_by_name" property="unReleaseByName"/>
<result column="tb_release_time" property="releaseTime"/>
<result column="tb_release_by_id" property="releaseById"/>
<result column="tb_release_by_name" property="releaseByName"/>
<result column="tb_company_id" property="companyId"/>
<result column="tb_org_id" property="orgId"/>
<result column="tb_site_id" property="siteId"/>
<result column="tb_keywords" property="keywords"/>
<result column="tb_enable_task" property="enableTask" />
<result column="tb_image" property="image" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
tb.id AS tb_id
,tb.training_project_id as tb_training_project_id
,tb.research_no AS tb_research_no
,tb.point AS tb_point
,tb.remind AS tb_remind
,tb.enable_mail_remind AS tb_enable_mail_remind
,tb.mail_template_id AS tb_mail_template_id
,tb.enable_app_remind AS tb_enable_app_remind
,tb.app_template_id AS tb_app_template_id
,tb.name AS tb_name
,tb.start_time AS tb_start_time
,tb.end_time AS tb_end_time
,tb.visible_range AS tb_visible_range
,tb.content AS tb_content
,tb.state AS tb_state
,tb.deleted AS tb_deleted
,tb.create_time AS tb_create_time
,tb.create_by_id AS tb_create_by_id
,tb.create_by_name AS tb_create_by_name
,tb.update_time AS tb_update_time
,tb.update_by_id AS tb_update_by_id
,tb.update_by_name AS tb_update_by_name
,tb.un_release_time AS tb_un_release_time
,tb.un_release_by_id AS tb_un_release_by_id
,tb.un_release_by_name AS tb_un_release_by_name
,tb.release_time AS tb_release_time
,tb.release_by_id AS tb_release_by_id
,tb.release_by_name AS tb_release_by_name
,tb.company_id AS tb_company_id
,tb.org_id AS tb_org_id
,tb.site_id AS tb_site_id
,tb.keywords AS tb_keywords
,tb.image AS tb_image
</sql>
<!--查询所有-->
<select id="selectAllCount" resultType="java.lang.Integer">
select count(`id`)
from research
where site_id = #{siteId}
</select>
<update id="batchDelete">
update research set
deleted = 1
<where>
id in
<foreach collection="ids" close=")" open="(" item="item" separator=",">
#{item}
</foreach>
and state = 0
</where>
</update>
<!-- 1. 已完成 -->
<!-- 1.1 结束时间小于当前时间 -->
<!-- 1.2 结束时间大于当前时间,交过答案 -->
<!-- 2. 进行中 结束时间大于当前时间 and 没有交过答案 -->
<select id="apiListResearch" resultType="com.yizhi.research.application.vo.domain.Research">
<if test="state == 1">
select *
from (select answer.submit_time as submitTime,
tb.id AS id
,answer.submit_time as finishTime
,tb.research_no AS researchNo
,tb.name AS name
,tb.start_time AS startTime
,tb.end_time AS endTime
,tb.visible_range AS visibleRange
,tb.content AS content
,tb.state AS state
,tb.deleted AS deleted
,tb.company_id AS companyId
,tb.org_id AS orgId
,tb.site_id AS siteId
from research tb
left join tr_research_answer answer on answer.research_id = tb.id and answer.account_id = #{accountId}
where
-- 状态、站点
tb.state = 1 and tb.deleted = 0 and tb.site_id = #{siteId}
-- 可见范围
and (tb.visible_range = 1
<if test="idsInRange != null and idsInRange.size > 0">
or (tb.visible_range = 2 and tb.id in
(<foreach collection="idsInRange" separator="," item="id">#{id}</foreach>))
</if>
)
-- 已完成条件过滤
and <![CDATA[ tb.end_time > #{now} ]]> and answer.id is not null and answer.finish = 1
group by tb.id
)t
order by t.submitTime desc
</if>
<if test="state == 2">
select
answer.submit_time as submitTime,
tb.id AS id
,answer.submit_time as finishTime
,tb.research_no AS researchNo
,tb.name AS name
,tb.start_time AS startTime
,tb.end_time AS endTime
,tb.visible_range AS visibleRange
,tb.content AS content
,tb.state AS state
,tb.deleted AS deleted
,tb.company_id AS companyId
,tb.org_id AS orgId
,tb.site_id AS siteId
from research tb
left join tr_research_answer answer on answer.research_id = tb.id and answer.account_id = #{accountId}
where
-- 状态、站点
tb.state = 1 and tb.deleted = 0 and tb.site_id = #{siteId}
-- 可见范围
and (tb.visible_range = 1
<if test="idsInRange != null and idsInRange.size > 0">
or (tb.visible_range = 2 and tb.id in
(<foreach collection="idsInRange" separator="," item="id">#{id}</foreach>))
</if>
)
-- 进行中条件过滤
and <![CDATA[ tb.end_time > #{now} ]]>and <![CDATA[ tb.start_time < #{now} ]]> and ( answer.id is null or
answer.finish = 0)
group by tb.id
order by tb.end_time
</if>
</select>
<!-- 查询进行中的我的调研 -->
<select id="apiCountResearch" resultType="Integer">
select count(*) from(
select
<include refid="Base_Column_List"/>
from research tb
left join tr_research_answer answer on answer.research_id = tb.id and answer.account_id = #{accountId}
where
-- 状态、站点
tb.state = 1 and tb.deleted = 0 and tb.site_id = #{siteId}
-- 可见范围
and (tb.visible_range = 1
<if test="idsInRange != null and idsInRange.size > 0">
or (tb.visible_range = 2 and tb.id in
(<foreach collection="idsInRange" separator="," item="id">#{id}</foreach>))
</if>
)
-- 进行中条件过滤
and <![CDATA[ tb.end_time > #{now} ]]>and <![CDATA[ tb.start_time < #{now} ]]> and( answer.id is null or
answer.finish = 0)
group by tb.id
)r
</select>
<!-- 搜索调研 -->
<select id="apiSearchPage" resultType="com.yizhi.research.application.vo.domain.Research">
select * from(
select (case when answer.submit_time>0 then 1 else 0 end) as finishState,tb.id AS id
,answer.submit_time as finishTime,count(answer.id) as realCount
,tb.research_no AS researchNo
,tb.name AS name
,tb.start_time AS startTime
,tb.end_time AS endTime
,tb.visible_range AS visibleRange
,tb.content AS content
,tb.state AS state
,tb.deleted AS deleted
,tb.company_id AS companyId
,tb.org_id AS orgId
,tb.site_id AS siteId
from research tb left join tr_research_answer answer on tb.id=answer.research_id
where
tb.site_id = #{siteId}
and tb.deleted = 0
and tb.state = 1
and <![CDATA[ tb.end_time > #{now} ]]>
and <![CDATA[ tb.start_time < #{now} ]]>
and tb.name like concat('%', #{name}, '%')
and (tb.visible_range = 1
<if test="idsInRange != null and idsInRange.size > 0">
or (tb.visible_range = 2 and tb.id in
(<foreach collection="idsInRange" separator="," item="id">#{id}</foreach>))
</if>
)
group by tb.id
)t
order by t.finishState,t.endTime
</select>
<!-- 后台管理分页列表 -->
<select id="listPage" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from research tb
<where>
tb.site_id = #{range.siteId} and tb.deleted = 0
<if test="date !=null and date !='' ">
AND #{date}> tb.start_time AND tb.end_time > #{date}
</if>
<if test="state != null">
and tb.state = #{state}
</if>
<if test="name != null">
and (tb.name like concat('%', #{name}, '%') or tb.keywords like concat('%', #{name}, '%') )
</if>
<!--
<if test="range.admin == false and range.orgIds != null and range.orgIds.size > 0">
and tb.org_id in
(<foreach collection="range.orgIds" item="item" separator=",">#{item}</foreach>)
</if>
-->
and tb.deleted = 0
</where>
order by tb.create_time desc
</select>
<select id="listPageCount" resultType="java.lang.Integer">
select count(id)
from research tb
<where>
tb.site_id = #{range.siteId}
<if test="date !=null and date !='' ">
AND #{date}> tb.start_time AND tb.end_time > #{date}
</if>
<if test="state != null">
and tb.state = #{state}
</if>
<if test="name != null">
and (tb.name like concat('%', #{name}, '%') or tb.keywords like concat('%', #{name}, '%') )
</if>
<!--
<if test="range.admin == false and range.orgIds != null and range.orgIds.size > 0">
and tb.org_id in
(<foreach collection="range.orgIds" item="item" separator=",">#{item}</foreach>)
</if>
-->
and tb.deleted = 0
</where>
order by tb.create_time desc
</select>
<select id="selectListCount" resultType="Integer">
select count(*) from(
<if test="state == 1">
select *
from (select answer.submit_time as submitTime,
tb.id AS id
,answer.submit_time as finishTime
,tb.research_no AS researchNo
,tb.name AS name
,tb.start_time AS startTime
,tb.end_time AS endTime
,tb.visible_range AS visibleRange
,tb.content AS content
,tb.state AS state
,tb.deleted AS deleted
,tb.company_id AS companyId
,tb.org_id AS orgId
,tb.site_id AS siteId
from research tb
left join tr_research_answer answer on answer.research_id = tb.id and answer.account_id = #{accountId}
where
-- 状态、站点
tb.state = 1 and tb.deleted = 0 and tb.site_id = #{siteId}
-- 可见范围
and (tb.visible_range = 1
<if test="idsInRange != null and idsInRange.size > 0">
or (tb.visible_range = 2 and tb.id in
(<foreach collection="idsInRange" separator="," item="id">#{id}</foreach>))
</if>
)
-- 已完成条件过滤
and <![CDATA[ tb.end_time > #{now} ]]> and answer.id is not null and answer.finish = 1
group by tb.id
)t
order by t.submitTime desc
</if>
<if test="state == 2">
select
answer.submit_time as submitTime,
tb.id AS id
,answer.submit_time as finishTime
,tb.research_no AS researchNo
,tb.name AS name
,tb.start_time AS startTime
,tb.end_time AS endTime
,tb.visible_range AS visibleRange
,tb.content AS content
,tb.state AS state
,tb.deleted AS deleted
,tb.company_id AS companyId
,tb.org_id AS orgId
,tb.site_id AS siteId
from research tb
left join tr_research_answer answer on answer.research_id = tb.id and answer.account_id = #{accountId}
where
-- 状态、站点
tb.state = 1 and tb.deleted = 0 and tb.site_id = #{siteId}
-- 可见范围
and (tb.visible_range = 1
<if test="idsInRange != null and idsInRange.size > 0">
or (tb.visible_range = 2 and tb.id in
(<foreach collection="idsInRange" separator="," item="id">#{id}</foreach>))
</if>
)
-- 进行中条件过滤
and <![CDATA[ tb.end_time > #{now} ]]>and <![CDATA[ tb.start_time < #{now} ]]> and ( answer.id is null or
answer.finish = 0)
group by tb.id
order by tb.end_time
</if>
)ttt
</select>
<select id="selectRealJoin" resultType="com.yizhi.research.application.vo.domain.Research">
SELECT count(answer.id) AS realCount, research_id AS id FROM tr_research_answer AS answer
right join research re on re.id=answer.research_id
WHERE answer.research_id IN (<foreach collection="researchIds" separator="," item="id">#{id}</foreach>) GROUP BY
answer.research_id
</select>
<select id="selectRelationIds" resultType="com.yizhi.research.application.vo.domain.TrResearchAuthorize">
select au.relation_id AS relationId,au.research_id as researchId
from tr_research_authorize as au
where au.state = 1 and au.research_id in (<foreach collection="researchIds" separator="," item="id">#{id}</foreach>)
</select>
<select id="selectResearchPage" resultType="com.yizhi.research.application.vo.domain.Research">
select id,start_time as startTime, visible_range as visibleRange,end_time as endTime,name from research
where site_id=#{siteId} and company_id=#{companyId}
<if test="startDate !=null">and <![CDATA[ start_time > #{startDate} ]]> </if>
<if test="endDate !=null">and <![CDATA[ end_time < #{endDate} ]]> </if>
<if test="kwd !=null">and name like concat('%',#{kwd},'%')</if>
<if test="orgIds !=null">and org_id in (<foreach collection="orgIds" separator="," item="id">#{id}</foreach>)
</if>
ORDER BY create_time DESC
</select>
<select id="selectResearchCount" resultType="Integer">
SELECT count(*) FROM (
select id,start_time as startTime, visible_range as visibleRange,end_time as endTime,name from research
where site_id=#{siteId} and company_id=#{companyId}
<if test="startDate !=null">and <![CDATA[ start_time > #{startDate} ]]> </if>
<if test="endDate !=null">and <![CDATA[ end_time < #{endDate} ]]> </if>
<if test="kwd !=null">and name like concat('%',#{kwd},'%')</if>
<if test="orgIds !=null">and org_id in (<foreach collection="orgIds" separator="," item="id">#{id}</foreach>)
</if>
) t
</select>
<select id="getPoolExamList" resultType="java.util.HashMap">
select r.id,r.`name`,r.start_time as startTime,r.end_time as endTime,r.release_time as upTime
FROM research r
where 1=1
<if test="ids!=null and ids.size()>0">
AND r.id not in
<foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test="name!=null and name != ''">
AND r.name LIKE CONCAT('%', #{name}, '%')
</if>
<!--
<if test="orgIds!=null and orgIds.size()>0">
AND r.org_id in
<foreach collection="orgIds" index="index" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
-->
AND r.company_id = #{companyId}
AND r.site_id = #{siteId}
AND r.state in(1,2)
order by create_time desc
</select>
<select id="getAllResearchs" resultType="com.yizhi.research.application.vo.domain.Research">
SELECT *
FROM research a
WHERE a.state != 0
</select>
<select id="selectRecordMinTime" resultType="java.util.Date">
select min(create_time) from research WHERE state != 0
</select>
<select id="getIdsByDate" resultType="Long">
select id
from research c
where 1=1
and c.state = 1
and c.enable_task = 1
and c.deleted = 0
AND c.`site_id` = #{siteId}
AND <![CDATA[ DATE_FORMAT(c.start_time, '%Y-%m-%d') <= DATE_FORMAT(#{date}, '%Y-%m-%d') ]]>
AND <![CDATA[ DATE_FORMAT(c.end_time, '%Y-%m-%d') >= DATE_FORMAT(#{date}, '%Y-%m-%d') ]]>
</select>
<select id="getPageToCalendar" resultMap="BaseResultMap">
select id as tb_id,
name as tb_name,
start_time as tb_start_time,
end_time as tb_end_time
from research c
where 1=1
<if test="finishTrIds != null and finishTrIds.size() > 0">
and c.id not in (<foreach collection="finishTrIds" item="id" separator=",">#{id}</foreach>)
</if>
and (c.visible_range = 1
<if test="trIds != null and trIds.size() > 0">
or c.id in (<foreach collection="trIds" item="item" separator=",">#{item}</foreach>)
</if>)
and c.state = 1
and c.enable_task = 1
AND c.`site_id` = #{siteId}
and c.deleted = 0
AND <![CDATA[ DATE_FORMAT(c.start_time, '%Y-%m-%d') <= DATE_FORMAT(#{date}, '%Y-%m-%d') ]]>
AND <![CDATA[ DATE_FORMAT(c.end_time, '%Y-%m-%d') >= DATE_FORMAT(#{date}, '%Y-%m-%d') ]]>
order by start_time desc,end_time desc
</select>
<select id="getPageToCalendarNum" resultType="Integer">
select count(1)
from research c
where 1=1
<if test="finishTrIds != null and finishTrIds.size() > 0">
and c.id not in (<foreach collection="finishTrIds" item="id" separator=",">#{id}</foreach>)
</if>
and (c.visible_range = 1
<if test="trIds != null and trIds.size() > 0">
or c.id in (<foreach collection="trIds" item="item" separator=",">#{item}</foreach>)
</if>)
and c.state = 1
and c.enable_task = 1
AND c.`site_id` = #{siteId}
and c.deleted = 0
AND <![CDATA[ DATE_FORMAT(c.start_time, '%Y-%m-%d') <= DATE_FORMAT(#{date}, '%Y-%m-%d') ]]>
AND <![CDATA[ DATE_FORMAT(c.end_time, '%Y-%m-%d') >= DATE_FORMAT(#{date}, '%Y-%m-%d') ]]>
</select>
</mapper>
package com.yizhi.research.application.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.yizhi.research.application.vo.domain.StatisticsResearchLearn;
public interface StatisticsResearchLearnMapper extends BaseMapper<StatisticsResearchLearn> {
}
package com.yizhi.research.application.mapper;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.yizhi.research.application.vo.domain.Research;
import com.yizhi.research.application.vo.domain.StatisticsResearch;
import com.yizhi.research.application.vo.domain.StatisticsResearchLearn;
import com.yizhi.research.application.vo.domain.TrResearchAnswer;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.plugins.Page;
public interface StatisticsResearchMapper extends BaseMapper<StatisticsResearch> {
/**
* 报表得到所有的指定范围人员
*
* @return
*/
List<Long> getAllRelationId(@Param("researchId") Long researchId);
List<TrResearchAnswer> selectRealJoin(@Param("researchId") Long researchId, @Param("accountIds") List<Long> accountIds,
@Param("startDate") String startDate);
List<StatisticsResearch> selectResearchView(
@Param("researchId") Long researchId,
@Param("startDate") String startDate,
@Param("endDate") String endDate,
@Param("orgNameorOrgCode") String orgNameorOrgCode,
@Param("accountName") String accountName,
@Param("joinState") Integer joinState,
Page<StatisticsResearch> page);
Integer selectResearchViewCount(@Param("researchId") Long researchId,
@Param("startDate") String startDate,
@Param("endDate") String endDate,
@Param("orgNameorOrgCode") String orgNameorOrgCode,
@Param("accountName") String accountName,
@Param("joinState") Integer joinState);
StatisticsResearch selectJoinCount(@Param("researchId") Long researchId,
@Param("startDate") String startDate,
@Param("endDate") String endDate,
@Param("orgNameorOrgCode") String orgNameorOrgCode,
@Param("accountName") String accountName,
@Param("joinState") Integer joinState);
List<StatisticsResearch> selectStatisticsResearchPage(@Param("startDate") String startDate,
@Param("endDate") String endDate,
@Param("kwd") String kwd,
@Param("companyId") Long companyId,
@Param("orgIds")List<Long> orgIds,
@Param("siteId") Long siteId,
RowBounds rowBounds);
Integer selectStatisticsResearchCount(@Param("startDate") String startDate,
@Param("endDate") String endDate,
@Param("kwd") String kwd,
@Param("companyId") Long companyId,
@Param("orgIds") List<Long> orgIds,
@Param("siteId") Long siteId);
List<StatisticsResearch> selectResearchViewList(@Param("researchId") Long researchId,
@Param("orgNameorOrgCode") String orgNameorOrgCode,
@Param("accountName") String accountName,
@Param("joinState") Integer joinState,
@Param("startDate")String startDate,
@Param("endDate")String endDate);
Date selectMaxDate();
Date selectRecordMinTime();
List<Research> getAllResearchs(@Param("startDate") String startDate, @Param("endDate") String endDate);
void deleteRecordeByDate(@Param("currentDate") String currentDate);
/**
* 批量插入调研
* @param researchId 调研ID
* @param currentDate 调研日期
* @return
*/
int insertAccountLearn(@Param("researchId")Long researchId, @Param("currentDate")String currentDate);
/**
* 获取添加的调研信息
* @param researchId 调研ID
* @param currentDate 调研日期
* @return 返回调研的学生ID集合
*/
@MapKey("account_id")
List<StatisticsResearchLearn> selectAccountLearn(@Param("researchId")Long researchId, @Param("currentDate")String currentDate);
List<Long> selectAccountLearnList(@Param("paramMap") Map<String, Object> paramMap, Page<Long> page);
/**
* 查找学员有没有调研
* @param courseId
* @param accountId
* @return
*/
Integer selectEmptyCourseAccountLearnCount(@Param("researchId") Long researchId, @Param("accountId") Long accountId);
/**
* 删除没有学习记录的学员信息
*/
void deleteEmptyAccountLearn();
/**
* 查找该调研有没有人参加了
* @param researchId
* @return
*/
Integer selectEmptyCourseLearnCount(@Param("researchId")Long researchId);
/**
* 查找学员有没有学了该调研
* @param researchId
* @param accountId
* @return
*/
@MapKey("accountId")
Map<Long, Long> selectAccountLearnByResearchId(@Param("researchId") Long researchId);
/**
* 按部门纬度统计数据量会很大,影响效率.对其进行拆分,按部门统计从此表中查询
*/
void insertStatisticsResearchToGroupFind();
void deleteStatisticsResearchToGroupFind();
/**
* 调研信息直接从statistics_research_metadata表中查询效率很慢,对其进行拆分.按调研和用户统计的查询条件从此获取
*/
void insertStatisticsResearchToAccountGroupFind();
void deleteStatisticsResearchToAccountGroupFind();
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yizhi.research.application.mapper.StatisticsResearchMapper">
<select id="getAllRelationId" resultType="java.lang.Long">
select relation_id from cloud_research.tr_research_authorize where research_id=#{researchId} and status = 1
</select>
<select id="selectRealJoin" resultType="com.yizhi.research.application.vo.domain.TrResearchAnswer">
select account_id as accountId,submit_time as submitTime from tr_research_answer
where research_id=#{researchId}
<if test="accountIds!=null and accountIds.size()>0">
and account_id in
<foreach collection="accountIds" item="accountId" index="index" open="(" close=")" separator=",">
#{accountId}
</foreach>
</if>
and <![CDATA[ DATE_FORMAT(create_time,'%Y-%m-%d')=DATE_FORMAT(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]>
group by account_id,research_id
</select>
<select id="selectResearchView" resultType="com.yizhi.research.application.vo.domain.StatisticsResearch">
SELECT a.research_id as researchId ,a.research_name as researchName, a.research_start_time as researchStartTime,
a.research_end_time as researchEndTime,a.research_create_time as researchCreateTime,
a.account_id as accountId, a.account_name as accountName,a.account_state as accountState,a.org_name as orgName,
a.account_fullname as accountFullName, a.org_parent_names as orgParentNames,b.research_answer_create_time as finishTime,
IFNULL(b.join_state,0) AS joinState
FROM statistics_research_metadata a
LEFT JOIN statistics_research_learn_metadata b ON a.research_id=b.research_id AND a.account_id=b.account_id
<if test="startDate !=null"> and <![CDATA[ DATE_FORMAT(a.research_start_time,'%Y-%m-%d')<=DATE_FORMAT(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]> </if>
<if test="endDate !=null"> and <![CDATA[ DATE_FORMAT(a.research_end_time,'%Y-%m-%d')>=DATE_FORMAT(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]> </if>
WHERE a.research_id =#{researchId}
<if test="orgNameorOrgCode !=null"> and a.org_name like concat('%',#{orgNameorOrgCode},'%')</if>
<if test="accountName !=null"> and (a.account_name like concat('%',#{accountName},'%')
or a.account_fullname like concat('%',#{accountName},'%'))
</if>
<if test="startDate !=null"> and <![CDATA[ DATE_FORMAT(a.research_start_time,'%Y-%m-%d')<=DATE_FORMAT(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]> </if>
<if test="endDate !=null"> and <![CDATA[ DATE_FORMAT(a.research_end_time,'%Y-%m-%d')>=DATE_FORMAT(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]> </if>
<if test="joinState !=null"> AND IFNULL(b.join_state,0)=#{joinState} </if>
GROUP BY a.account_id,a.research_id
ORDER BY joinState DESC,finishTime DESC,accountId
</select>
<select id="selectResearchViewCount" resultType="java.lang.Integer">
SELECT COUNT(DISTINCT a.account_id)
FROM statistics_research_metadata a
LEFT JOIN statistics_research_learn_metadata b ON a.research_id = b.research_id AND a.account_id = b.account_id
<if test="startDate !=null"> and <![CDATA[ DATE_FORMAT(a.research_start_time,'%Y-%m-%d')<=DATE_FORMAT(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]> </if>
<if test="endDate !=null"> and <![CDATA[ DATE_FORMAT(a.research_end_time,'%Y-%m-%d')>=DATE_FORMAT(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]> </if>
WHERE a.research_id =#{researchId}
<if test="joinState !=null"> AND IFNULL(b.join_state,0)=#{joinState} </if>
<if test="orgNameorOrgCode !=null"> and a.org_name like concat('%',#{orgNameorOrgCode},'%')</if>
<if test="accountName !=null"> and (a.account_name like concat('%',#{accountName},'%')
or a.account_fullname like concat('%',#{accountName},'%'))</if>
<if test="startDate !=null"> and <![CDATA[ DATE_FORMAT(a.research_start_time,'%Y-%m-%d')<=DATE_FORMAT(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]> </if>
<if test="endDate !=null"> and <![CDATA[ DATE_FORMAT(a.research_end_time,'%Y-%m-%d')>=DATE_FORMAT(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]> </if>
</select>
<select id="selectStatisticsResearchPage" resultType="com.yizhi.research.application.vo.domain.StatisticsResearch">
SELECT a.research_id AS researchId,
a.research_start_time AS researchStartTime,
a.research_end_time AS researchEndTime,
a.research_name AS researchName,
b.canStateCount,
COUNT(DISTINCT c.account_id) AS joinStateCount
FROM statistics_research_metadata_research_group_find a
LEFT JOIN ( SELECT research_id,count(*) AS canStateCount
FROM statistics_research_metadata
GROUP BY research_id) b ON a.research_id=b.research_id
LEFT JOIN statistics_research_learn_metadata c ON a.research_id=c.research_id
<!--不在可见范围里的 -->
-- and c.account_id in
-- (SELECT account_id from statistics_research_metadata where research_id = a.research_id)
<if test="startDate !=null"> and <![CDATA[ DATE_FORMAT(a.research_start_time,'%Y-%m-%d')<=DATE_FORMAT(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]> </if>
<if test="endDate !=null"> and <![CDATA[ DATE_FORMAT(a.research_end_time,'%Y-%m-%d')>=DATE_FORMAT(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]> </if>
WHERE a.company_id=#{companyId}
<if test="orgIds != null">and a.org_id in (<foreach collection="orgIds" separator="," item="orgId">#{orgId}</foreach>)</if> and a.site_id=#{siteId}
<if test="kwd !=null"> and a.research_name like concat('%',#{kwd},'%')</if>
<if test="startDate !=null"> and <![CDATA[ DATE_FORMAT(a.research_start_time,'%Y-%m-%d')<=DATE_FORMAT(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]> </if>
<if test="endDate !=null"> and <![CDATA[ DATE_FORMAT(a.research_end_time,'%Y-%m-%d')>=DATE_FORMAT(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]> </if>
GROUP BY a.company_id,a.org_id,a.site_id,a.research_id
ORDER BY a.research_create_time DESC
</select>
<select id="selectJoinCount" resultType="com.yizhi.research.application.vo.domain.StatisticsResearch">
SELECT
COUNT(DISTINCT a.account_id) AS canStateCount,
COUNT(DISTINCT b.account_id) AS joinStateCount
FROM statistics_research_metadata a
LEFT JOIN statistics_research_learn_metadata b ON a.research_id = b.research_id AND a.account_id = b.account_id
WHERE a.research_id =#{researchId}
<if test="orgNameorOrgCode !=null"> and a.org_name like concat('%',#{orgNameorOrgCode},'%')</if>
<if test="accountName !=null"> and (a.account_name like concat('%',#{accountName},'%')
or a.account_fullname like concat('%',#{accountName},'%'))</if>
<if test="startDate !=null"> and <![CDATA[ DATE_FORMAT(a.research_start_time,'%Y-%m-%d')<=DATE_FORMAT(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]> </if>
<if test="endDate !=null"> and <![CDATA[ DATE_FORMAT(a.research_end_time,'%Y-%m-%d')>=DATE_FORMAT(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]> </if>
</select>
<select id="selectStatisticsResearchCount" resultType="java.lang.Integer">
SELECT COUNT(a.research_id)
FROM statistics_research_metadata_research_group_find a
WHERE a.company_id=#{companyId}
<if test="orgIds != null">and a.org_id in (<foreach collection="orgIds" separator="," item="orgId">#{orgId}</foreach>)</if> and a.site_id=#{siteId}
<if test="kwd !=null"> and a.research_name like concat('%',#{kwd},'%')</if>
<if test="startDate !=null"> and <![CDATA[ DATE_FORMAT(a.research_start_time,'%Y-%m-%d')<=DATE_FORMAT(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]> </if>
<if test="endDate !=null"> and <![CDATA[ DATE_FORMAT(a.research_end_time,'%Y-%m-%d')>=DATE_FORMAT(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]> </if>
</select>
<select id="selectResearchViewList" resultType="com.yizhi.research.application.vo.domain.StatisticsResearch">
SELECT a.research_id as researchId ,a.research_name as researchName, a.research_start_time as researchStartTime,
a.research_end_time as researchEndTime,a.research_create_time as researchCreateTime,
a.can_state as canState,IFNULL(b.join_state,0) as joinState,
a.account_id as accountId, a.account_name as accountName,a.org_name as orgName,
a.account_fullname as accountFullName, a.org_parent_names as orgParentNames,a.finish_time as finishTime
FROM statistics_research_metadata a
LEFT JOIN statistics_research_learn_metadata b ON a.research_id=b.research_id AND a.account_id=b.account_id
<if test="startDate !=null"> and <![CDATA[ DATE_FORMAT(a.research_start_time,'%Y-%m-%d')<=DATE_FORMAT(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]> </if>
<if test="endDate !=null"> and <![CDATA[ DATE_FORMAT(a.research_end_time,'%Y-%m-%d')>=DATE_FORMAT(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]> </if>
WHERE a.research_id =#{researchId}
<if test="orgNameorOrgCode !=null"> and a.org_name like concat('%',#{orgNameorOrgCode},'%')</if>
<if test="accountName !=null"> and (a.account_name like concat('%',#{accountName},'%')
or a.account_fullname like concat('%',#{accountName},'%'))
</if>
<if test="startDate !=null"> and <![CDATA[ DATE_FORMAT(a.research_start_time,'%Y-%m-%d')<=DATE_FORMAT(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]> </if>
<if test="endDate !=null"> and <![CDATA[ DATE_FORMAT(a.research_end_time,'%Y-%m-%d')>=DATE_FORMAT(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]> </if>
<if test="joinState !=null"> AND IFNULL(b.join_state,0)=#{joinState} </if>
GROUP BY a.account_id,a.research_id
ORDER BY a.research_create_time
</select>
<select id="selectMaxDate" resultType="java.util.Date">
SELECT <![CDATA[ MAX(DATE_FORMAT(research_answer_create_time,'%Y-%m-%d')) ]]> FROM statistics_research_learn_metadata
</select>
<select id="selectRecordMinTime" resultType="java.util.Date">
select min(create_time) from research WHERE state != 0
</select>
<select id="getAllResearchs" resultType="com.yizhi.research.application.vo.domain.Research">
SELECT *
FROM research a
WHERE
DATE_FORMAT(a.start_time, '%Y-%m-%d')&lt;=DATE_FORMAT(#{endDate}, '%Y-%m-%d') AND
DATE_FORMAT(a.end_time, '%Y-%m-%d')>=DATE_FORMAT(#{startDate}, '%Y-%m-%d') AND a.state != 0
</select>
<delete id="deleteRecordeByDate">
DELETE statistics_research_metadata WHERE <![CDATA[ date_format(research_answer_create_time,'%Y-%m-%d')=date_format(#{currentDate},'%Y-%m-%d') ]]>
</delete>
<!-- 批量插入调研答卷记录 -->
<insert id="insertAccountLearn">
INSERT statistics_research_learn_metadata(research_id,account_id,can_state,join_state,finish_time,research_answer_create_time)
SELECT b.id,a.account_id,1,1,MIN(a.submit_time),MIN(a.create_time)
FROM tr_research_answer a
LEFT JOIN research b ON a.research_id=b.id
WHERE a.research_id=b.id AND a.research_id=#{researchId} AND
DATE_FORMAT(a.create_time,'%Y-%m-%d')=DATE_FORMAT(#{currentDate},'%Y-%m-%d')
and a.finish = 1
GROUP BY a.account_id,DATE_FORMAT(a.create_time,'%Y-%m-%d'),a.research_id
</insert>
<select id="selectAccountLearn" resultType="com.yizhi.research.application.vo.domain.StatisticsResearchLearn">
SELECT account_id,id
FROM statistics_research_learn_metadata
WHERE research_id=#{researchId} AND DATE_FORMAT(research_answer_create_time,'%Y-%m-%d')=DATE_FORMAT(#{currentDate},'%Y-%m-%d')
</select>
<select id="selectEmptyCourseAccountLearnCount" resultType="java.lang.Integer">
SELECT COUNT(id)
FROM statistics_research_metadata
WHERE research_id=#{researchId} AND account_id=#{accountId} LIMIT 0,1
</select>
<delete id="deleteEmptyAccountLearn">
DELETE a
FROM statistics_research_metadata a,statistics_research_metadata b
WHERE b.research_answer_create_time IS NOT NULL AND a.research_answer_create_time IS NULL AND b.account_id IS NOT NULL AND a.account_id = b.account_id
AND a.research_id=b.research_id
</delete>
<select id="selectEmptyCourseLearnCount" resultType="java.lang.Integer">
SELECT COUNT(research_id)
FROM statistics_research_metadata
WHERE research_id=#{researchId} LIMIT 0,1
</select>
<select id="selectAccountLearnByResearchId" resultType="java.util.Map">
SELECT account_id AS accountId
FROM statistics_research_metadata
WHERE research_id=#{researchId}
</select>
<delete id="deleteStatisticsResearchToGroupFind">
DELETE FROM statistics_research_metadata_research_group_find;
</delete>
<!-- 调研信息直接从statistics_research_metadata表中查询效率很慢,对其进行拆分.按调研统计的查询条件从此表获取 -->
<insert id="insertStatisticsResearchToGroupFind">
INSERT INTO statistics_research_metadata_research_group_find(research_id,research_no,research_name,research_create_time,research_start_time,research_end_time,
org_id,site_id,company_id)
SELECT research_id,research_no,research_name,research_create_time,research_start_time,research_end_time,research_org_id,research_site_id,research_company_id
FROM statistics_research_metadata
GROUP BY research_id,research_org_id,research_site_id,research_company_id
</insert>
<delete id="deleteStatisticsResearchToAccountGroupFind">
DELETE FROM statistics_research_metadata_account_group_find;
</delete>
<!-- 学员信息直接从statistics_research_metadata表中查询效率很慢,对其进行拆分.按用户统计的查询条件从此表获取 -->
<insert id="insertStatisticsResearchToAccountGroupFind">
INSERT INTO statistics_research_metadata_account_group_find(org_id,site_id,company_id,account_id,account_work_num,account_name,account_fullname,org_name,org_parent_names,
account_state,account_org_id,account_site_id,account_company_id)
SELECT a.research_org_id,a.research_site_id,a.research_company_id,a.account_id,a.account_work_num,a.account_name,a.account_fullname,a.org_name,a.org_parent_names,
a.account_state,a.account_org_id,a.account_site_id,a.account_company_id
FROM statistics_research_metadata a
GROUP BY a.account_id,a.research_org_id,a.research_site_id,a.research_company_id
</insert>
</mapper>
package com.yizhi.research.application.mapper;
import java.util.Date;
import java.util.List;
import com.yizhi.research.application.vo.StatisticResearchMetadataVo;
import com.yizhi.research.application.vo.domain.TrResearchAnswer;
import com.yizhi.research.application.vo.report.ResearchGroupViewVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
/**
* <p>
* 答卷 Mapper 接口
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
public interface TrResearchAnswerMapper extends BaseMapper<TrResearchAnswer> {
/**
* 检查某个学员的某个调研的状态
*/
Integer checkResearchAnswer
(@Param("visibleRange") Integer visibleRange, @Param("accountId") Long accountId,@Param("researchId") Long researchId, @Param("relationIds") List<Long> relationsId,@Param("date") Date date);
Integer checkResearchAnswerState
(@Param("visibleRange") Integer visibleRange,@Param("accountId") Long accountId, @Param("researchId") Long researchId, @Param("relationIds") List<Long> relationsId,@Param("date") Date date);
/*
* 根据调研id查询完成的个数
* */
Integer selectFinishCount(@Param("researchId") Long researchId);
@Update("update tr_research_answer set finish = 2 where research_id = #{researchId} and account_id = #{accountId}")
void deleteAnswer(@Param("researchId") Long researchId,@Param("accountId")Long accountId);
/**
* 根据调研answer的创建时间、调研id、已完成状态查询,
* @param researchId
* @param currentDate
* @return
*/
List<StatisticResearchMetadataVo> selectLearnRecord(@Param("researchId") Long researchId, @Param("startDate") String startDate, @Param("endDate") String endDate);
/**
* 实时查询答卷
*
* @param researchId
* @return
*/
List<ResearchGroupViewVo> queryAnswerRecord(@Param("researchId") Long researchId, @Param("siteId")Long siteId);
List<Long> getFinshIdsByIds(@Param("ids")List<Long> ids, @Param("accountId")Long accountId,@Param("siteId") Long siteId);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yizhi.research.application.mapper.TrResearchAnswerMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.yizhi.research.application.vo.domain.TrResearchAnswer">
<id column="tb_id" property="id" />
<result column="tb_research_id" property="researchId" />
<result column="tb_name" property="name" />
<result column="tb_account_id" property="accountId" />
<result column="tb_start_time" property="startTime" />
<result column="tb_submit_time" property="submitTime" />
<result column="tb_duration" property="duration" />
<result column="tb_terminal_type" property="terminalType" />
<result column="tb_create_time" property="createTime" />
<result column="tb_create_by_id" property="createById" />
<result column="tb_create_by_name" property="createByName" />
<result column="tb_update_time" property="updateTime" />
<result column="tb_update_by_id" property="updateById" />
<result column="tb_update_by_name" property="updateByName" />
<result column="tb_company_id" property="companyId" />
<result column="tb_org_id" property="orgId" />
<result column="tb_site_id" property="siteId" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
tb.id AS tb_id
,tb.research_id AS tb_research_id
,tb.name AS tb_name
,tb.account_id AS tb_account_id
,tb.start_time AS tb_start_time
,tb.submit_time AS tb_submit_time
,tb.duration AS tb_duration
,tb.terminal_type AS tb_terminal_type
,tb.create_time AS tb_create_time
,tb.create_by_id AS tb_create_by_id
,tb.create_by_name AS tb_create_by_name
,tb.update_time AS tb_update_time
,tb.update_by_id AS tb_update_by_id
,tb.update_by_name AS tb_update_by_name
,tb.company_id AS tb_company_id
,tb.org_id AS tb_org_id
,tb.site_id AS tb_site_id
</sql>
<select id="checkResearchAnswer" resultType="Integer">
select count(*) from (
select re.start_time from research re
left join tr_research_answer answer on re.id=answer.research_id
inner join cloud_research.tr_research_authorize as authorize
on re.id = authorize.research_id and authorize.state = 1
where answer.research_id=#{researchId} and answer.finish=1
and <![CDATA[ re.end_time > #{date} ]]>and <![CDATA[ re.start_time < #{date} ]]>
and answer.id is null and answer.account_id = #{accountId}
<if test="visibleRange==2 and relationIds != null and relationIds.size > 0" >
and authorize.relation_id in
<foreach collection="relationIds" separator="," item="id" close=")" open="(">
#{id}
</foreach>
</if>
)t
</select>
<select id="checkResearchAnswerState" resultType="Integer">
select count(*) from (
select re.start_time from research re
left join tr_research_answer answer on re.id=answer.research_id
inner join cloud_research.tr_research_authorize as authorize
on re.id = authorize.research_id and authorize.state = 1
where answer.research_id=#{researchId} and answer.finish=1
and <![CDATA[ re.end_time < #{date} ]]>
and answer.id is null
<if test="visibleRange==2 and relationIds != null and relationIds.size > 0" >
and authorize.relation_id in
<foreach collection="relationIds" separator="," item="id" close=")" open="(">
#{id}
</foreach>
</if>
)t
</select>
<select id="selectFinishCount" resultType="Integer">
select count(*) from tr_research_answer where research_id=#{researchId} and finish = 1
</select>
<select id="selectLearnRecord" resultType="com.yizhi.research.application.vo.StatisticResearchMetadataVo">
SELECT b.id as researchId ,a.account_id as accountId ,1 as canState,1 as joinState ,MIN(a.submit_time) as finishTime,MIN(a.create_time) as researchAnswerCreateTime
FROM tr_research_answer a
LEFT JOIN research b ON a.research_id=b.id
WHERE a.research_id=b.id AND a.research_id=#{researchId} AND
<![CDATA[ DATE_FORMAT(a.submit_time, '%Y-%m-%d')>=DATE_FORMAT(#{startDate}, '%Y-%m-%d')]]>
AND
<![CDATA[ DATE_FORMAT(a.submit_time, '%Y-%m-%d')<=DATE_FORMAT(#{endDate}, '%Y-%m-%d')]]>
and a.finish = 1
GROUP BY a.account_id,DATE_FORMAT(a.create_time,'%Y-%m-%d'),a.research_id
</select>
<select id="queryAnswerRecord" resultType="com.yizhi.research.application.vo.report.ResearchGroupViewVo">
SELECT a.account_id as accountId ,a.submit_time as finishTime FROM tr_research_answer a
where a.finish = 1 and a.research_id = #{researchId} and a.site_id = #{siteId}
order by a.submit_time DESC
</select>
<select id="getFinshIdsByIds" resultType="java.lang.Long">
SELECT research_id FROM tr_research_answer c
where
c.account_id = #{accountId}
and c.site_id = #{siteId}
and c.finish = 1
<if test="ids != null and ids.size() > 0">
and c.research_id in (<foreach collection="ids" item="item" separator=",">#{item}</foreach>)
</if>
</select>
</mapper>
package com.yizhi.research.application.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.yizhi.research.application.vo.domain.TrResearchAnswerQuestion;
import com.yizhi.research.application.vo.domain.TrResearchQuestion;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* <p>
* 答案题目 Mapper 接口
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
public interface TrResearchAnswerQuestionMapper extends BaseMapper<TrResearchAnswerQuestion> {
/**
* 批量插入
*
* @param list
* @return
*/
int batchInsert(@Param("list") List<TrResearchAnswerQuestion> list);
@Select("select * from tr_research_question where id in (select question_id from tr_research_answer_question " +
" where research_id = #{researchId} and account_id =#{accountId})")
List<TrResearchQuestion> selectListByAnswer(@Param("researchId") Long researchId, @Param("accountId")Long accountId);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yizhi.research.application.mapper.TrResearchAnswerQuestionMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.yizhi.research.application.vo.domain.TrResearchAnswerQuestion">
<id column="tb_id" property="id" />
<result column="tb_research_id" property="researchId" />
<result column="tb_answer_id" property="answerId" />
<result column="tb_question_id" property="questionId" />
<result column="tb_account_id" property="accountId" />
<result column="tb_create_time" property="createTime" />
<result column="tb_create_by_id" property="createById" />
<result column="tb_create_by_name" property="createByName" />
<result column="tb_update_time" property="updateTime" />
<result column="tb_update_by_id" property="updateById" />
<result column="tb_update_by_name" property="updateByName" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
tb.id AS tb_id
,tb.research_id AS tb_research_id
,tb.answer_id AS tb_answer_id
,tb.question_id AS tb_question_id
,tb.account_id AS tb_account_id
,tb.create_time AS tb_create_time
,tb.create_by_id AS tb_create_by_id
,tb.create_by_name AS tb_create_by_name
,tb.update_time AS tb_update_time
,tb.update_by_id AS tb_update_by_id
,tb.update_by_name AS tb_update_by_name
</sql>
<insert id="batchInsert">
insert into tr_research_answer_question
(id
,research_id
,answer_id
,question_id
,account_id
,create_time
,create_by_id
,create_by_name
,update_time
,update_by_id
,update_by_name)
values
<foreach collection="list" item="item" separator=",">
(#{item.id},
#{item.researchId},#{item.answerId},#{item.questionId},#{item.accountId},#{item.createTime},#{item.createById},
#{item.createByName},#{item.updateTime},#{item.updateById},#{item.updateByName})
</foreach>
</insert>
</mapper>
package com.yizhi.research.application.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.yizhi.research.application.vo.domain.TrResearchAnswerQuestionResult;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* <p>
* 答案选项 Mapper 接口
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
public interface TrResearchAnswerQuestionResultMapper extends BaseMapper<TrResearchAnswerQuestionResult> {
/**
* 批量插入
*
* @param list
* @return
*/
int batchInsert(@Param("list") List<TrResearchAnswerQuestionResult> list);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yizhi.research.application.mapper.TrResearchAnswerQuestionResultMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.yizhi.research.application.vo.domain.TrResearchAnswerQuestionResult">
<id column="tb_id" property="id" />
<result column="tb_research_id" property="researchId" />
<result column="tb_answer_id" property="answerId" />
<result column="tb_answer_question_id" property="answerQuestionId" />
<result column="tb_question_type" property="questionType" />
<result column="tb_option_id" property="optionId" />
<result column="tb_content" property="content" />
<result column="tb_score" property="score" />
<result column="tb_create_time" property="createTime" />
<result column="tb_create_by_id" property="createById" />
<result column="tb_create_by_name" property="createByName" />
<result column="tb_update_time" property="updateTime" />
<result column="tb_update_by_id" property="updateById" />
<result column="tb_update_by_name" property="updateByName" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
tb.id AS tb_id
,tb.research_id AS tb_research_id
,tb.answer_id AS tb_answer_id
,tb.answer_question_id AS tb_answer_question_id
,tb.question_type AS tb_question_type
,tb.option_id AS tb_option_id
,tb.content AS tb_content
,tb.score AS tb_score
,tb.create_time AS tb_create_time
,tb.create_by_id AS tb_create_by_id
,tb.create_by_name AS tb_create_by_name
,tb.update_time AS tb_update_time
,tb.update_by_id AS tb_update_by_id
,tb.update_by_name AS tb_update_by_name
</sql>
<insert id="batchInsert">
insert into tr_research_answer_question_result
(id
,research_id
,answer_id
,answer_question_id
,question_type
,option_id
,content
,score
,create_time
,create_by_id
,create_by_name
,update_time
,update_by_id
,update_by_name)
values
<foreach collection="list" separator="," item="item">
(#{item.id},#{item.researchId},#{item.answerId},#{item.answerQuestionId},#{item.questionType},#{item.optionId},
#{item.content},#{item.score},#{item.createTime},#{item.createById},
#{item.createByName},#{item.updateTime},#{item.updateById},#{item.updateByName})
</foreach>
</insert>
</mapper>
package com.yizhi.research.application.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.yizhi.research.application.vo.domain.TrResearchAuthorize;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* <p>
* 调研用户范围 Mapper 接口
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
public interface TrResearchAuthorizeMapper extends BaseMapper<TrResearchAuthorize> {
/**
* 查询指定范围内的可见调研id
*
* @param relationIds
* @return
*/
List<Long> getResearchIdsInRange(@Param("relationIds") List<Long> relationIds);
int batchInsert(@Param("list") List<TrResearchAuthorize> researchAuthorizes);
void deleteByResearchId(@Param("researchId") Long researchId);
List<Long> getUsefulIds(@Param("ids") List<Long> ids,@Param("relationIds") List<Long> relationIds,@Param("siteId") Long siteId);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yizhi.research.application.mapper.TrResearchAuthorizeMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.yizhi.research.application.vo.domain.TrResearchAuthorize">
<id column="tb_id" property="id" />
<result column="tb_research_id" property="researchId" />
<result column="tb_type" property="type" />
<result column="tb_relation_id" property="relationId" />
<result column="tb_state" property="state" />
<result column="tb_create_time" property="createTime" />
<result column="tb_create_by_id" property="createById" />
<result column="tb_create_by_name" property="createByName" />
<result column="tb_update_time" property="updateTime" />
<result column="tb_update_by_id" property="updateById" />
<result column="tb_update_by_name" property="updateByName" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
tb.id AS tb_id
,tb.research_id AS tb_research_id
,tb.type AS tb_type
,tb.relation_id AS tb_relation_id
,tb.state AS tb_state
,tb.create_time AS tb_create_time
,tb.create_by_id AS tb_create_by_id
,tb.create_by_name AS tb_create_by_name
,tb.update_time AS tb_update_time
,tb.update_by_id AS tb_update_by_id
,tb.update_by_name AS tb_update_by_name
</sql>
<select id="getResearchIdsInRange" resultType="java.lang.Long">
SELECT tb.research_id
FROM tr_research_authorize tb
WHERE
tb.state = 1
AND relation_id in
(<foreach collection="relationIds" item="item" separator=",">#{item}</foreach>)
</select>
<insert id="batchInsert">
insert into tr_research_authorize
(id
,name
,research_id
,type
,relation_id
,site_id
,state
,create_by_id
,create_time
,create_by_name)
values
<foreach collection="list" separator="," item="item">
<if test="item != null">
(#{item.id},#{item.name},#{item.researchId},#{item.type},#{item.relationId},#{item.siteId},#{item.state},
#{item.createById},#{item.createTime},#{item.createByName})
</if>
</foreach>
</insert>
<!-- <delete id="deleteByResearchId">-->
<!-- delete from tr_research_authorize where research_id=#{researchId}-->
<!-- </delete>-->
<update id="deleteByResearchId">
update tr_research_authorize set state = 0 where research_id=#{researchId}
</update>
<select id="getUsefulIds" resultType="java.lang.Long">
<if test="relationIds != null">
select research_id
from tr_research_authorize
<where>
deleted = 0
and site_id = #{siteId}
and relation_id in
<foreach collection="relationIds" open="(" close=")" item="item" separator=",">
#{item}
</foreach>
<if test="ids != null and ids.size()>0">
and research_id in <foreach collection="ids" open="(" close=")" item="id" separator=","> #{id} </foreach>
</if>
</where>
</if>
</select>
</mapper>
package com.yizhi.research.application.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.yizhi.research.application.vo.domain.TrResearchQuestion;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.Date;
import java.util.List;
import java.util.Set;
/**
* <p>
* 问题 Mapper 接口
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
public interface TrResearchQuestionMapper extends BaseMapper<TrResearchQuestion> {
/**
* 批量插入问题
*
* @param questions
* @return
*/
int batchInsert(@Param("list") List<TrResearchQuestion> questions);
/**
* 批量删除
*
* @param researchIds 所属调研id
* @return
*/
int batchDeleteByResearchId(@Param("ids") List<Long> researchIds);
/**
* 批量删除
*
* @param ids 主键id
* @return
*/
int batchDeleteById(@Param("ids") List<Long> ids);
/**
* 通过id跟新序号
*
* @return
*/
int updateNoById(@Param("id") Long id, @Param("jumpNo") Integer jumpNo);
int updateNo(@Param("id") Long id, @Param("jumpNo") Integer jumpNo);
/**
* 选择跳题时的问题列表
*
* @param no
* @param researchId
* @return
*/
List<TrResearchQuestion> listAllForJump(@Param("no") Integer no, @Param("researchId") Long researchId);
/*@Update("update tr_research_question set jump_type = #{type} " +
"<if test = 'jumpNo != null'>and jump_num = #{jumpNo} </if>" +
"and and update_by_id = #{upDateById} and update_by_name = #{upDateByName} and " +
"update_time = #{upDateTime} where id = #{questionId}")
int updateQuestionJump(
@Param("type") Integer type,@Param("jumpNo") Integer jumpNo,@Param("questionId") Long id,
@Param("upDateById") Long upDateById, @Param("upDateByName")String upDateByName,
@Param("upDateTime")Date upDateTime);*/
@Select("select no from tr_research_question where id = (select question_id from " +
"tr_research_question_option where id = #{optionId})")
Integer selectByOptionId(@Param("optionId") Long optionId);
@Select("select * from tr_research_question where no = #{oldLastNo} and research_id = #{researchId}")
TrResearchQuestion selectOneByNo(@Param("oldLastNo") Integer oldLastNo, @Param("researchId") Long researchId);
List<Long> getFinishedAccountIds(@Param("researchId") Long researchId, @Param("companyId") Long companyId, @Param("siteId") Long siteId);
/* List<Long> selectQuestion(@Param("startNo") Integer startNo,@Param("endNo") Integer endNo,@Param("researchId") Long researchId);*/
@Update("update tr_research_question set no = no-1 where id in " +
"(<foreach collection=\"accountIds\" item=\"accountId\" index=\"index\" open=\"(\" close=\")\" separator=\",\">\n" +
" #{accountId}\n" +
" </foreach>)")
void updateNos(@Param("ids") Set<Long> ids);
void updateJumpNum(@Param("ids") List<Long> ids);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yizhi.research.application.mapper.TrResearchQuestionMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.yizhi.research.application.vo.domain.TrResearchQuestion">
<id column="tb_id" property="id" />
<result column="tb_research_id" property="researchId" />
<result column="tb_type" property="type" />
<result column="tb_content" property="content" />
<result column="tb_content_appendix_url" property="contentAppendixUrl" />
<result column="tb_need_answer" property="needAnswer" />
<result column="tb_max_select_item" property="maxSelectItem" />
<result column="tb_min_select_item" property="minSelectItem" />
<result column="tb_min_score" property="minScore" />
<result column="tb_max_score" property="maxScore" />
<result column="tb_no" property="no" />
<result column="tb_jumpable" property="jumpable" />
<result column="tb_deleted" property="deleted" />
<result column="tb_create_time" property="createTime" />
<result column="tb_create_by_id" property="createById" />
<result column="tb_create_by_name" property="createByName" />
<result column="tb_update_time" property="updateTime" />
<result column="tb_update_by_id" property="updateById" />
<result column="tb_update_by_name" property="updateByName" />
<result column="tb_company_id" property="companyId" />
<result column="tb_org_id" property="orgId" />
<result column="tb_site_id" property="siteId" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
tb.id AS tb_id
,tb.research_id AS tb_research_id
,tb.type AS tb_type
,tb.content AS tb_content
,tb.content_appendix_url AS tb_content_appendix_url
,tb.need_answer AS tb_need_answer
,tb.max_select_item AS tb_max_select_item
,tb.min_select_item AS tb_min_select_item
,tb.min_score AS tb_min_score
,tb.max_score AS tb_max_score
,tb.no AS tb_no
,tb.jumpable AS tb_jumpable
,tb.deleted AS tb_deleted
,tb.create_time AS tb_create_time
,tb.create_by_id AS tb_create_by_id
,tb.create_by_name AS tb_create_by_name
,tb.update_time AS tb_update_time
,tb.update_by_id AS tb_update_by_id
,tb.update_by_name AS tb_update_by_name
,tb.company_id AS tb_company_id
,tb.org_id AS tb_org_id
,tb.site_id AS tb_site_id
</sql>
<insert id="batchInsert">
insert into tr_research_question
(id
,research_id
,`type`
,content
,content_appendix_url
,need_answer
,max_select_item
,min_select_item
,min_score
,max_score
,`no`
,`jump_type`
,`jump_num`
,jumpable
,deleted
,create_time
,create_by_id
,create_by_name
,update_time
,update_by_id
,update_by_name
,company_id
,org_id
,site_id)
values
<foreach collection="list" separator="," item="item">
<if test="item != null">
(#{item.id},#{item.researchId},#{item.type},#{item.content},#{item.contentAppendixUrl},
#{item.needAnswer},#{item.maxSelectItem},#{item.minSelectItem},#{item.minScore},#{item.maxScore},
#{item.no},#{item.jumpType},#{item.jumpNum},#{item.jumpable},#{item.deleted},#{item.createTime},#{item.createById},#{item.createByName},
#{item.updateTime},#{item.updateById},#{item.updateByName},#{item.companyId},#{item.orgId},#{item.siteId})
</if>
</foreach>
</insert>
<!-- 批量删除(根据调研id) -->
<update id="batchDeleteByResearchId">
update tr_research_question set
deleted = 1
<where>
research_id in
<foreach collection="ids" separator="," open="(" close=")" item="item">
#{item}
</foreach>
</where>
</update>
<!-- 批量删除(根据调研id) -->
<update id="batchDeleteById">
update tr_research_question set
deleted = 1
<where>
id in
<foreach collection="ids" separator="," open="(" close=")" item="item">
#{item}
</foreach>
</where>
</update>
<update id="updateNoById">
update tr_research_question set jump_num = -1 , jump_type=2 where id = #{id}
</update>
<update id="updateNo">
update tr_research_question_option set jump_num = -1 where id = #{id}
</update>
<!-- 选择跳题时的问题列表 -->
<select id="listAllForJump" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/>
from tr_research_question tb
where
tb.research_id = #{researchId}
and
<![CDATA[ tb.`no` > #{no} ]]>
and tb.deleted = 0
order by no asc
</select>
<select id="getFinishedAccountIds" resultType="java.lang.Long">
SELECT account_id
FROM tr_research_answer
WHERE research_id = #{researchId}
<if test="companyId!=null">
AND company_id=#{companyId}
</if>
<if test="siteId!=null">
AND site_id=#{siteId}
</if>
AND finish = 1
GROUP BY account_id
</select>
<update id="updateNos">
update tr_research_question set no = no-1 where id in
<foreach collection="ids" item="id" index="index" open="(" close=")" separator=",">
#{id}
</foreach>
</update>
<update id="updateJumpNum">
update tr_research_question set jump_num = jump_num-1 where id in
<foreach collection="ids" item="id" index="index" open="(" close=")" separator=",">
#{id}
</foreach>
</update>
</mapper>
package com.yizhi.research.application.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.yizhi.research.application.vo.domain.TrResearchQuestionOption;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.Date;
import java.util.List;
/**
* <p>
* 只对题型是:单选题、多选题和打分题 Mapper 接口
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
public interface TrResearchQuestionOptionMapper extends BaseMapper<TrResearchQuestionOption> {
/**
* 批量插入问题项
*
* @param questions
* @return
*/
int batchInsert(@Param("list") List<TrResearchQuestionOption> questions);
/**
* 批量删除
*
* @param ids
* @return
*/
int batchDelete(@Param("ids") List<Long> ids, @Param("updateTime") Date updateTime, @Param("updateById") Long updateById, @Param("updateByName") String updateByName);
/**
* 查询问题选项
*
* @param questionId
* @return
*/
@Select("select * from tr_research_question_option where question_id = #{questionId} and deleted = 0 order by no asc")
List<TrResearchQuestionOption> listAllByQuestionId(@Param("questionId") Long questionId);
@Select("select * from tr_research_question_option where research_id = #{researchId} and deleted = 0")
List<TrResearchQuestionOption> listAllByResearchId(@Param("researchId") Long libraryId);
@Select("select * from tr_research_question_option where id in (select option_id from tr_research_answer_question_result" +
" where answer_id = #{answerId})")
List<TrResearchQuestionOption> selectByAnswer(Long answerId);
void updateJumpNum(@Param("ids") List<Long> ids);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yizhi.research.application.mapper.TrResearchQuestionOptionMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.yizhi.research.application.vo.domain.TrResearchQuestionOption">
<id column="tb_id" property="id"/>
<result column="tb_research_id" property="researchId"/>
<result column="tb_question_id" property="questionId"/>
<result column="tb_question_type" property="questionType"/>
<result column="tb_no" property="no"/>
<result column="tb_editable" property="editable"/>
<result column="tb_content" property="content"/>
<result column="tb_min_score" property="minScore" />
<result column="tb_max_score" property="maxScore" />
<result column="tb_jump_num" property="jumpNum"/>
<result column="tb_correct" property="correct"/>
<result column="tb_deleted" property="deleted"/>
<result column="tb_create_time" property="createTime"/>
<result column="tb_create_by_id" property="createById"/>
<result column="tb_create_by_name" property="createByName"/>
<result column="tb_update_time" property="updateTime"/>
<result column="tb_update_by_id" property="updateById"/>
<result column="tb_update_by_name" property="updateByName"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
tb.id AS tb_id
,tb.research_id AS tb_research_id
,tb.question_id AS tb_question_id
,tb.question_type AS tb_question_type
,tb.no AS tb_no
,tb.editable AS tb_editable
,tb.content AS tb_content
,tb.min_score AS tb_min_score
,tb.max_score AS tb_max_score
,tb.jump_num AS tb_jump_num
,tb.correct AS tb_correct
,tb.deleted AS tb_deleted
,tb.create_time AS tb_create_time
,tb.create_by_id AS tb_create_by_id
,tb.create_by_name AS tb_create_by_name
,tb.update_time AS tb_update_time
,tb.update_by_id AS tb_update_by_id
,tb.update_by_name AS tb_update_by_name
</sql>
<insert id="batchInsert">
insert into tr_research_question_option
(id
,research_id
,question_id
,question_type
,`no`
,editable
,content
,min_score
,max_score
,jump_num
,correct
,deleted
,create_time
,create_by_id
,create_by_name
,update_time
,update_by_id
,update_by_name
,isOther
,required)
values
<foreach collection="list" separator="," item="item">
<if test="item != null">
(#{item.id},
#{item.researchId},
#{item.questionId},
#{item.questionType},
#{item.no},
#{item.editable},
#{item.content},
#{item.minScore},
#{item.maxScore},
#{item.jumpNum},
#{item.correct},
#{item.deleted},
#{item.createTime},
#{item.createById},
#{item.createByName},
#{item.updateTime},
#{item.updateById},
#{item.updateByName},
#{item.isOther},
#{item.required})
</if>
</foreach>
</insert>
<!-- 批量删除 -->
<update id="batchDelete">
update tr_research_question_option set
deleted = 1,
update_time = #{updateTime},
update_by_id = #{updateById},
update_by_name = #{updateByName}
<where>
id in
<foreach collection="ids" separator="," open="(" close=")" item="item">
#{item}
</foreach>
</where>
</update>
<update id="updateJumpNum">
update tr_research_question_option set jump_num = jump_num-1 where id in
<foreach collection="ids" item="id" index="index" open="(" close=")" separator=",">
#{id}
</foreach>
</update>
</mapper>
package com.yizhi.research.application.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.yizhi.research.application.vo.domain.TrResearchRemind;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* <p>
* Mapper 接口
* </p>
*
* @author shengchenglong123
* @since 2018-03-14
*/
public interface TrResearchRemindMapper extends BaseMapper<TrResearchRemind> {
/**
* 批量增加
*
* @param researchReminds
* @return
*/
int batchInsert(@Param("list") List<TrResearchRemind> researchReminds);
/**
* 根据调研id,批量逻辑删除
*
* @param researchId
* @return
*/
int deleteByResearchId(@Param("researchId") Long researchId);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yizhi.research.application.mapper.TrResearchRemindMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.yizhi.research.application.vo.domain.TrResearchRemind">
<id column="tb_id" property="id" />
<result column="tb_research_id" property="researchId" />
<result column="tb_type" property="type" />
<result column="tb_seconds" property="seconds" />
<result column="tb_time" property="time" />
<result column="tb_deleted" property="deleted" />
<result column="tb_create_time" property="createTime" />
<result column="tb_create_by_id" property="createById" />
<result column="tb_create_by_name" property="createByName" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
tb.id AS tb_id
,tb.research_id AS tb_research_id
,tb.type AS tb_type
,tb.seconds AS tb_seconds
,tb.time AS tb_time
,tb.deleted AS tb_deleted
,tb.create_time AS tb_create_time
,tb.create_by_id AS tb_create_by_id
,tb.create_by_name AS tb_create_by_name
</sql>
<insert id="batchInsert">
insert into tr_research_remind
(id
,research_id
,`type`
,seconds
,`time`
,deleted
,create_time
,create_by_id
,create_by_name)
values
<foreach collection="list" separator="," item="item">
<if test="item != null">
(#{item.id},#{item.researchId},#{item.type},#{item.seconds},#{item.time},#{item.deleted},
#{item.createTime},#{item.createById},#{item.createByName})
</if>
</foreach>
</insert>
<update id="deleteByResearchId">
<if test="researchId != null">
update tr_research_remind set
deleted = 1
<where>
research_id = #{researchId}
</where>
</if>
</update>
</mapper>
package com.yizhi.research.application.service;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.IService;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.core.application.vo.DroolsVo;
import com.yizhi.research.application.vo.BaseModel;
import com.yizhi.research.application.vo.VisibleRangeExport;
import com.yizhi.research.application.vo.api.PageVo;
import com.yizhi.research.application.vo.domain.Research;
import io.swagger.annotations.ApiParam;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.springframework.web.bind.annotation.RequestParam;
/**
* <p>
* 调研 服务类
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
public interface IResearchService extends IService<Research> {
/**
* 保存 Research 实体
*
* @return
*/
Research insertResearch(Research research);
/**
* 列表分页
*
* @param page
* @return
*/
Page<Research> listPage(Map map, RequestContext requestContext, Integer pageNo, Integer pageSize);
/**
* 批量删除(仅能删除草稿状态)
* 连带删除 调研问题,调研问题选项
*
* @param ids id集合
* @return
*/
int batchDelete(List<Long> ids);
/**
* 更新调研
*
* @param research
* @return
*/
int update(Research research);
/**
* 查询一个
* 组装reminds
*
* @param id
* @return
*/
Research viewOne(Long id);
/**
* 发布调研,并返回
*
* @param research
* @return
*/
Research upOrDown(Research research) throws Exception;
/**
* 复制调研
*
* @param id
* @return
*/
Research copyResearch(Long id, RequestContext context, Date date) throws Exception;
// ********************************学员端接口*****************************************
/**
* 学员端调研列表
*
* @param accountId
* @param date
* @param state 1 已完成,2 进行中
* @param pageNo
* @param pageSize
* @return
*/
// Page<Research> apiListPage(Long accountId, Date date, Integer state, int pageNo, int pageSize);
Page<Research> apiListPage(BaseModel<PageVo> model);
/**
* 分页模糊查询
*
* @param context
* @param pageNo
* @param pageSize
* @return
*/
Page<Research> apiSearchPage(String name, RequestContext context, int pageNo, int pageSize);
/**
* 查询我的调研进行中的个数
*/
Integer searchUnfinishCount(RequestContext context);
/**
* 检查学员某个调研的状态
*/
Integer checkResearchState(Long researchId,RequestContext context);
Page<Research> getResearchList(String startDate, String endDate, String kwd,Integer pageSize, Integer pageNo,List<Long> orgIds, Long companyId, Long siteId);
Research getResearchView(Long researchId);
/**
* 范围人员导出 管理端-------2018/09/19
* @param assignmentId
* @return
*/
public VisibleRangeExport vsibleRangeExport(Long researchId);
Page<Map<String, Object>> getPoolExamList(String name, List<Long> ids, Integer pageNo, Integer pageSize);
List<Map<String, Object>> getServerByCompanyIdAndIds(Long companyId,List<Long> ids);
Page<Research> getPageToCalendar(Date date, Page<Research> page);
Page<DroolsVo> getPageByDrools(String field, String value, Page<DroolsVo> page);
}
package com.yizhi.research.application.service;
import com.baomidou.mybatisplus.service.IService;
import com.yizhi.research.application.vo.domain.TrResearchAnswerQuestionResult;
/**
* <p>
* 答案选项 服务类
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
public interface ITrResearchAnswerQuestionResultService extends IService<TrResearchAnswerQuestionResult> {
}
package com.yizhi.research.application.service;
import com.baomidou.mybatisplus.service.IService;
import com.yizhi.research.application.vo.domain.TrResearchAnswerQuestion;
/**
* <p>
* 答案题目 服务类
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
public interface ITrResearchAnswerQuestionService extends IService<TrResearchAnswerQuestion> {
}
package com.yizhi.research.application.service;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.IService;
import com.yizhi.research.application.model.AnswerModel;
import com.yizhi.research.application.vo.api.ViewAnswerVo;
import com.yizhi.research.application.vo.domain.TrResearchAnswer;
import java.util.List;
/**
* <p>
* 答卷 服务类
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
public interface ITrResearchAnswerService extends IService<TrResearchAnswer> {
/**
* 学员提交答案
*
* @param answerModel
* @return
*/
int submitAnswer(AnswerModel answerModel) throws Exception;
/**
* 学员端查看问卷答案
*
* @param researchId
* @param accountId
* @return
*/
ViewAnswerVo apiViewAnswer(Long researchId, Long accountId);
Page<ViewAnswerVo> apiViewAnswers(Long researchId, Integer pageNo, Integer pageSize);
List<ViewAnswerVo> viewList(Long researchId);
Integer apiViewAnswersCount(Long researchId);
List<ViewAnswerVo> viewAnswerVoList(Long researchId,Integer pageNo,Integer pageSize);
}
package com.yizhi.research.application.service;
import com.baomidou.mybatisplus.service.IService;
import com.yizhi.research.application.vo.domain.TrResearchAuthorize;
import java.util.List;
/**
* <p>
* 调研用户范围 服务类
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
public interface ITrResearchAuthorizeService extends IService<TrResearchAuthorize> {
Boolean insertAll(List<TrResearchAuthorize> trResearchAuthorizes);
List<TrResearchAuthorize> listTrResearchAuthorize(Long researchId);
}
package com.yizhi.research.application.service;
import com.baomidou.mybatisplus.service.IService;
import com.yizhi.research.application.vo.domain.TrResearchQuestionOption;
import java.util.List;
import java.util.Map;
/**
* <p>
* 只对题型是:单选题、多选题和打分题 服务类
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
public interface ITrResearchQuestionOptionService extends IService<TrResearchQuestionOption> {
List<TrResearchQuestionOption> listAll(Long researchId);
Map<String,Object> getOptionByQuestionId(Long id);
}
package com.yizhi.research.application.service;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.IService;
import com.yizhi.research.application.model.ModifyQuestionModel;
import com.yizhi.research.application.vo.api.MyQuestion;
import com.yizhi.research.application.vo.api.QuestionJumpVo;
import com.yizhi.research.application.vo.domain.TrResearchQuestion;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
import java.util.Map;
/**
* <p>
* 问题 服务类
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
public interface ITrResearchQuestionService extends IService<TrResearchQuestion> {
/**
* 批量插入问题 (包含问题选项)
*
* @param researchQuestions
* @return
*/
int batchInsert(List<TrResearchQuestion> researchQuestions);
/**
* 更新问题
*
* @param modifyQuestionModel
* @return
*/
int batchUpdate(ModifyQuestionModel modifyQuestionModel) throws Exception;
/**
* 分页查询调研问题
*
* @param map
* @return
*/
List<TrResearchQuestion> listPage(Map<String, Object> map);
/**
* 查询所有的
*
* @param researchId 所属调研id
* @return
*/
List<TrResearchQuestion> listAll(Long researchId);
/**
* 选择跳题时的问题列表
*
* @param questionId 需要跳题的问题id
* @return
*/
List<TrResearchQuestion> listAllForJump(Long questionId);
MyQuestion lastAndNext(MyQuestion myQuestion);
/**
* 修改问题跳题规则
* @param vo
* @return
*/
Integer updateQuestionJump(QuestionJumpVo vo);
List<Long> getFinishedAccountIds(Long researchId, Long companyId, Long siteId);
}
package com.yizhi.research.application.service;
import com.baomidou.mybatisplus.service.IService;
import com.yizhi.research.application.vo.domain.TrResearchRemind;
/**
* <p>
* 服务类
* </p>
*
* @author shengchenglong123
* @since 2018-03-14
*/
public interface ITrResearchRemindService extends IService<TrResearchRemind> {
}
package com.yizhi.research.application.service;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.IService;
import com.yizhi.research.application.vo.domain.StatisticsResearch;
import com.yizhi.research.application.vo.domain.StatisticsResearchLearn;
public interface StatisticsResearchService extends IService<StatisticsResearch> {
Page<StatisticsResearch> researchGroup(String startDate, String endDate, String kwd, Integer pageSize, Integer pageNo,
Long companyId, List<Long> orgIds, Long siteId);
Page<StatisticsResearch> selectResearchView(Long researchId,String startDate, String endDate, String orgNameorOrgCode, String accountName, Integer joinState,
Integer pageNo,Integer pageSize);
Integer selectResearchViewCount(Long researchId,String startDate, String endDate, String orgNameorOrgCode, String accountName, Integer joinState);
StatisticsResearch selectJoinCount(Long researchId,String startDate, String endDate, String orgNameorOrgCode, String accountName, Integer joinState
);
List<StatisticsResearch> researchViews(
Long researchId,String startDate, String endDate, String orgNameorOrgCode, String accountName, Integer joinState,
Integer pageNo,Integer pageSize
);
List<StatisticsResearch> researchViewList(Long researchId, String orgNameorOrgCode, String accountName, Integer joinState,String startDate,String endDate);
/**
* 查询统计调研信息,分页查询
* @param paramMap
* @param pageNo
* @param pageSize
* @return
*/
Page<Long> selectAccountLearnList(Map<String, Object> paramMap, int pageNo, int pageSize);
/**
* 批量插入学习记录
* @param researchId 调研ID
* @param curDate 调研日期
* @return 返回调研的学生ID集合
*/
List<StatisticsResearchLearn> insertAccountLearn(Long researchId, String curDate);
}
package com.yizhi.research.application.service.impl;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.yizhi.application.orm.hierarchicalauthorization.HQueryUtil;
import com.yizhi.application.orm.id.IdGenerator;
import com.yizhi.core.application.context.ContextHolder;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.core.application.enums.TaskParamsEnums;
import com.yizhi.core.application.task.AbstractTaskHandler;
import com.yizhi.core.application.task.TaskExecutor;
import com.yizhi.core.application.vo.DroolsVo;
import com.yizhi.research.application.ResearchConstant;
import com.yizhi.research.application.eum.ResearchState;
import com.yizhi.research.application.model.DataRangeModel;
import com.yizhi.research.application.util.ResearchEvenSendMessage;
import com.yizhi.research.application.mapper.*;
import com.yizhi.research.application.service.IResearchService;
import com.yizhi.research.application.service.ITrResearchAuthorizeService;
import com.yizhi.research.application.vo.BaseModel;
import com.yizhi.research.application.vo.MessageRemindVo;
import com.yizhi.research.application.vo.VisibleRangeExport;
import com.yizhi.research.application.vo.api.PageVo;
import com.yizhi.research.application.vo.domain.*;
import com.yizhi.util.application.clazz.ClassUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.apache.ibatis.session.RowBounds;
/**
* <p>
* 调研 服务实现类
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@Service
@Transactional
public class ResearchServiceImpl extends ServiceImpl<ResearchMapper, Research> implements IResearchService {
@Autowired
private IdGenerator idGenerator;
@Autowired
private ResearchMapper researchMapper;
@Autowired
private TrResearchRemindMapper researchRemindMapper;
@Autowired
private TrResearchQuestionMapper researchQuestionMapper;
@Autowired
private TrResearchQuestionOptionMapper researchQuestionOptionMapper;
@Autowired
private TrResearchAuthorizeMapper researchAuthorizeMapper;
@Autowired
private TrResearchAnswerMapper researchAnswerMapper;
@Autowired
private TrResearchAuthorizeMapper trResearchAuthorizeMapper;
@Autowired
private ITrResearchAuthorizeService researchAuthorizeService;
@Autowired
private TaskExecutor taskExecutor;
@Autowired
private ResearchEvenSendMessage researchEvenSendMessage;
private final static Logger LOG = LoggerFactory.getLogger(ResearchServiceImpl.class);
@Override
public Research insertResearch(Research research) {
research.setId(idGenerator.generate());
research.setResearchNo(getResearchNo(research.getSiteId()));
int num = researchMapper.insert(research);
RequestContext context = ContextHolder.get();
//设置关联人员
List<TrResearchAuthorize> researchAuthorizes = research.getAuthorizes();
if (!CollectionUtils.isEmpty(researchAuthorizes)) {
for (TrResearchAuthorize authorize : researchAuthorizes) {
authorize.setId(idGenerator.generate());
authorize.setResearchId(research.getId());
}
researchAuthorizeMapper.batchInsert(researchAuthorizes);
}
LOG.info("是否开启提醒:" + research.getRemind());
LOG.info("参数:" + JSON.toJSONString(research));
if (num == 1 && research.getRemind() == 1) {
// 设置提醒
try {
//发消息告知提醒有变化
taskExecutor.asynExecute(new AbstractTaskHandler() {
@Override
public void handle() {
researchEvenSendMessage.systemSendMessage(research, research.getMessageRemindVo(), context);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
return research;
}
@Override
public Page<Research> listPage(Map map, RequestContext context, Integer pageNo, Integer pageSize) {
HQueryUtil.startHQ(Research.class);
Integer state = null;
String name = null;
if (!StringUtils.isEmpty(map.get("state"))) {
state = (Integer) map.get("state");
}
if (!StringUtils.isEmpty(map.get("name"))) {
name = (String) map.get("name");
}
//为过滤过期调研准备
String date=null;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if(null!=map.get("currentTime")){
date = map.get("currentTime").toString();
Long s =Long.valueOf(date);
date = simpleDateFormat.format(s);
}
// 数据隔离
DataRangeModel dataRangeModel = new DataRangeModel();
dataRangeModel.setSiteId(context.getSiteId());
if (context.isAdmin()) {
dataRangeModel.setAdmin(true);
} else {
dataRangeModel.setAdmin(false);
dataRangeModel.setOrgIds(context.getOrgIds());
}
Page<Research> page = new Page<>(pageNo, pageSize);
page.setTotal(researchMapper.listPageCount(date,state, name, dataRangeModel));
page.setRecords(researchMapper.listPage(date,state, name, dataRangeModel, new RowBounds(page.getOffset(), page.getLimit())));
return page;
}
@Override
public int batchDelete(List<Long> ids) {
int num = researchMapper.batchDelete(ids);
if (num != ids.size()) {
throw new RuntimeException("处理异常:调研 删除数目 与 传入调研id集合长度对不上,事务回滚!!");
}
researchQuestionMapper.batchDeleteByResearchId(ids);
researchQuestionOptionMapper.batchDelete(ids, null, null, null);
return num;
}
@Override
public int update(Research research) {
int num = 0;
try {
num = researchMapper.updateById(research);
} catch (Exception e) {
e.printStackTrace();
}
if (num != 1) {
throw new RuntimeException("处理异常:调研 更新失败,事务回滚!!");
}
//更新关联人员
List<TrResearchAuthorize> authorizes = research.getAuthorizes();
if (!CollectionUtils.isEmpty(authorizes)) {
researchAuthorizeMapper.deleteByResearchId(research.getId());
for (TrResearchAuthorize authorize : authorizes) {
authorize.setId(idGenerator.generate());
authorize.setResearchId(research.getId());
}
researchAuthorizeMapper.batchInsert(authorizes);
}
LOG.info("是否开启提醒:" + research.getRemind());
RequestContext context = ContextHolder.get();
if (num > 0) {
Research research1 = this.selectById(research.getId());
// 设置提醒
try {
//发消息告知提醒有变化
taskExecutor.asynExecute(new AbstractTaskHandler() {
@Override
public void handle() {
researchEvenSendMessage.systemSendMessage(research1, research.getMessageRemindVo(),context);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
return num;
}
@Override
public Research viewOne(Long id) {
Research research = researchMapper.selectById(id);
if (research != null) {
// 查出调研提醒
if (research.getRemind() == 1 || research.getEnableAppRemind() == 1 || research.getEnableMailRemind() == 1) {
TrResearchRemind trResearchRemind = new TrResearchRemind();
trResearchRemind.setResearchId(id);
trResearchRemind.setDeleted(0);
research.setReminds(researchRemindMapper.selectList(new EntityWrapper<TrResearchRemind>(trResearchRemind)));
}
//查看关联人员
TrResearchAuthorize authorize = new TrResearchAuthorize();
authorize.setResearchId(id);
research.setAuthorizes(researchAuthorizeMapper.selectList(new EntityWrapper<TrResearchAuthorize>(authorize)));
}
return research;
}
@Override
public Research upOrDown(Research research) throws Exception {
// 如果是上架,需要判断是否有题目
if (research.getState().equals(ResearchState.RELEASED.getValue())) {
TrResearchQuestion question = new TrResearchQuestion();
question.setResearchId(research.getId());
question.setDeleted(0);
if (researchQuestionMapper.selectCount(new EntityWrapper<>(question)) < 1) {
throw new Exception("该调研下没有创建题目,上架失败!");
}
}
if (researchMapper.updateById(research) > 0) {
research = this.selectById(research.getId());
RequestContext context = ContextHolder.get();
if (research.getRemind() == 1){
try {
//发消息告知业务状态有变化
MessageRemindVo remindVo = new MessageRemindVo();
remindVo.setTaskStatusUpdate(true);
Research finalResearch = research;
taskExecutor.asynExecute(new AbstractTaskHandler() {
@Override
public void handle() {
researchEvenSendMessage.systemSendMessage(finalResearch,remindVo, context);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
return researchMapper.selectById(research.getId());
}
@Transactional
@Override
public Research copyResearch(Long id, RequestContext context, Date date) throws Exception {
// 查询之前的
Research origResearch = researchMapper.selectStateOne(id);
TrResearchQuestion questionExample = new TrResearchQuestion();
questionExample.setDeleted(0);
questionExample.setResearchId(id);
List<TrResearchQuestion> origQuestions = researchQuestionMapper.selectList(new EntityWrapper<TrResearchQuestion>(questionExample));
TrResearchQuestionOption optionExample = new TrResearchQuestionOption();
optionExample.setDeleted(0);
optionExample.setResearchId(id);
List<TrResearchQuestionOption> origOptions = researchQuestionOptionMapper.selectList(new EntityWrapper<TrResearchQuestionOption>(optionExample));
if (null == origResearch) {
throw new Exception("id: " + id + " 的调研不存在!!");
}
origResearch.setId(idGenerator.generate());
origResearch.setName(origResearch.getName() + "【复制件】");
// origResearch.setRemind(null);
origResearch.setUnReleaseTime(null);
origResearch.setUnReleaseByName(null);
origResearch.setUnReleaseById(null);
origResearch.setEnableMailRemind(null);
origResearch.setEnableAppRemind(null);
origResearch.setState(ResearchState.GRAFT.getValue());
origResearch.setReleaseById(null);
origResearch.setReleaseByName(null);
origResearch.setReleaseTime(null);
origResearch.setSiteId(context.getSiteId());
origResearch.setCompanyId(context.getCompanyId());
origResearch.setOrgId(context.getOrgId());
origResearch.setResearchNo(getResearchNo(context.getSiteId()));
// origResearch.setVisibleRange(null);
// origResearch.setStartTime(null);
// origResearch.setEndTime(null);
origResearch.setCreateByName(context.getAccountName());
origResearch.setCreateById(context.getAccountId());
origResearch.setCreateTime(date);
origResearch.setUpdateTime(null);
origResearch.setUpdateByName(null);
origResearch.setUpdateById(null);
//复制人员
Long oldId;
TrResearchAuthorize authorize = new TrResearchAuthorize();
authorize.setResearchId(id);
List<TrResearchAuthorize> authorizes = null;
try{
authorizes = trResearchAuthorizeMapper.selectList(new EntityWrapper<>(authorize));
if(!CollectionUtils.isEmpty(authorizes)) {
for (TrResearchAuthorize researchAuthorize : authorizes) {
researchAuthorize.setId(idGenerator.generate());
researchAuthorize.setResearchId(origResearch.getId());
researchAuthorize.setCreateById(context.getAccountId());
researchAuthorize.setCreateByName(context.getAccountName());
researchAuthorize.setCreateTime(date);
researchAuthorize.setSiteId(context.getSiteId());
researchAuthorize.setUpdateByName(null);
researchAuthorize.setUpdateById(null);
researchAuthorize.setUpdateTime(null);
}
researchAuthorizeMapper.batchInsert(authorizes);
}
}catch (Exception e){
e.printStackTrace();
LOG.error("赋值人员出错-------",e);
}
// 将之前的id对应起来,方便下面组装问题选项
Map<Long, Long> origNowQuestionIdMap = new HashMap<>();
if (!CollectionUtils.isEmpty(origQuestions)) {
Long nowId = null;
for (TrResearchQuestion question : origQuestions) {
nowId = idGenerator.generate();
// 将之前的id对应起来,方便下面组装问题选项
origNowQuestionIdMap.put(question.getId(), nowId);
question.setId(nowId);
question.setSiteId(context.getSiteId());
question.setCompanyId(context.getCompanyId());
question.setOrgId(context.getOrgId());
question.setCreateByName(context.getAccountName());
question.setCreateTime(date);
question.setCreateById(context.getAccountId());
question.setResearchId(origResearch.getId());
question.setUpdateByName(null);
question.setUpdateById(null);
question.setUpdateTime(null);
}
researchQuestionMapper.batchInsert(origQuestions);
}
if (!CollectionUtils.isEmpty(origOptions)) {
for (TrResearchQuestionOption option : origOptions) {
option.setQuestionId(origNowQuestionIdMap.get(option.getQuestionId()));
option.setResearchId(origResearch.getId());
option.setCreateTime(date);
option.setCreateByName(context.getAccountName());
option.setCreateById(context.getAccountId());
option.setUpdateByName(null);
option.setUpdateTime(null);
option.setUpdateById(null);
option.setId(idGenerator.generate());
}
researchQuestionOptionMapper.batchInsert(origOptions);
}
// if (researchMapper.insert(origResearch) > 0) {
// LOG.info("是否开启提醒:" + origResearch.getRemind());
// if (origResearch.getRemind() == 1) {
// // 设置提醒
// try {
// MessageRemindVo vo = new MessageRemindVo();
// vo.setIsCopy(true);
// vo.setOldRelationId(id);
//
// //发消息告知提醒有变化
// taskExecutor.asynExecute(new AbstractTaskHandler() {
// @Override
// public void handle() {
// researchEvenSendMessage.systemSendMessage(origResearch, vo, ContextHolder.get());
// }
// });
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// }
researchMapper.insert(origResearch);
return origResearch;
}
/**
* 查看已完成和未完成的调研列表
*/
@Override
public Page<Research> apiListPage(BaseModel<PageVo> model) {
PageVo pageVo = model.getObj();
Page<Research> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());
RequestContext context = model.getContext();
// 查出指定学员可见的调研id
List<Long> researchIdsInRange = null;
if (!CollectionUtils.isEmpty(context.getRelationIds())) {
researchIdsInRange = researchAuthorizeMapper.getResearchIdsInRange(context.getRelationIds());
}
List<Research> records = researchMapper.apiListResearch(researchIdsInRange, context.getAccountId(),
context.getSiteId(), model.getDate(), pageVo.getState(), new RowBounds(page.getOffset(), page.getLimit()));
// 如果是已完成:还要判断是否过期
if (pageVo.getState().equals(1)) {
if (!CollectionUtils.isEmpty(records)) {
Map<Long, Research> map = new LinkedHashMap<>();
for (Research r : records) {
map.put(r.getId(), r);
}
TrResearchAnswer answer = new TrResearchAnswer();
answer.setAccountId(context.getAccountId());
EntityWrapper<TrResearchAnswer> ew = new EntityWrapper<>(answer);
ew.in("research_id", map.keySet());
List<TrResearchAnswer> answers = researchAnswerMapper.selectList(ew);
if (!CollectionUtils.isEmpty(answers)) {
for (TrResearchAnswer a : answers) {
// 有答案,已完成
if (null != map.get(a.getResearchId())) {
map.get(a.getResearchId()).setFinishState(ResearchConstant.STATE_FINISHED);
map.get(a.getResearchId()).setFinishTime(a.getSubmitTime());
}
// 已过期
else {
map.get(a.getResearchId()).setFinishState(ResearchConstant.STATE_DATED);
}
}
}
}
}
page.setRecords(records);
int count = 0;
count = researchMapper.selectListCount(researchIdsInRange, context.getAccountId(),
context.getSiteId(), model.getDate(), pageVo.getState());
if (count < 0) {
count = 0;
}
page.setTotal(count);
return page;
}
@Override
public Page<Research> apiSearchPage(String name, RequestContext context, int pageNo, int pageSize) {
Page<Research> page = new Page<>(pageNo, pageSize);
// 查出指定学员可见的调研id
List<Long> researchIdsInRange = null;
if (!CollectionUtils.isEmpty(context.getRelationIds())) {
researchIdsInRange = researchAuthorizeMapper.getResearchIdsInRange(context.getRelationIds());
}
List<Research> records = researchMapper.apiSearchPage(context.getSiteId(), name, context.getAccountId(),
new Date(), researchIdsInRange, new RowBounds(page.getOffset(), page.getLimit()));
page.setRecords(records);
return page;
}
/**
* 获得一个序号
*
* @return
*/
private String getResearchNo(Long siteId) {
int count = researchMapper.selectAllCount(siteId);
count++;
//得到一个NumberFormat的实例
NumberFormat nf = NumberFormat.getInstance();
//设置是否使用分组
nf.setGroupingUsed(false);
//设置最大整数位数
nf.setMaximumIntegerDigits(6);
//设置最小整数位数
nf.setMinimumIntegerDigits(6);
return "DY" + nf.format(count);
}
@Override
public Integer searchUnfinishCount(RequestContext context) {
// 查出指定学员可见的调研id
List<Long> researchIdsInRange = null;
if (!CollectionUtils.isEmpty(context.getRelationIds())) {
researchIdsInRange = researchAuthorizeMapper.getResearchIdsInRange(context.getRelationIds());
}
Integer i = researchMapper.apiCountResearch(researchIdsInRange, context.getAccountId(), context.getSiteId(), new Date());
return i;
}
@Override
public Integer checkResearchState(Long researchId, RequestContext context) {
List<Long> relationIds = context.getRelationIds();
if (null == relationIds) {
relationIds = new ArrayList<Long>();
relationIds.add(context.getAccountId());
}
Date date = new Date();
//根据researchId查询出人员范围
Research research = new Research();
research.setId(researchId);
Integer visibleRange = researchMapper.selectOne(research).getVisibleRange();
//根据
//1.先判断有答案的,肯定是已完成的 1
TrResearchAnswer answer = new TrResearchAnswer();
answer.setAccountId(context.getAccountId());
answer.setResearchId(researchId);
answer.setFinish(1);
EntityWrapper<TrResearchAnswer> wrapper = new EntityWrapper<>(answer);
List<TrResearchAnswer> list = researchAnswerMapper.selectList(wrapper);
if (list.size() > 0) {
return 1;
}
//2.没有答案:时间还没到结束时间,进行中 2
Integer num = 0;
try {
num = researchAnswerMapper.checkResearchAnswer(visibleRange,context.getAccountId(), researchId, relationIds, date);
} catch (Exception e) {
e.printStackTrace();
}
if (num == 0) {
return 2;
}
//3.没有答案:时间>结束时间,过期 3
num = researchAnswerMapper.checkResearchAnswerState(visibleRange, context.getAccountId(),researchId, relationIds, date);
if (num == 0) {
return 3;
}
//4.这些情况都没有,无效的
return 4;
}
@Override
public Page<Research> getResearchList(String startDate, String endDate, String kwd, Integer pageSize, Integer pageNo, List<Long> orgIds, Long companyId, Long siteId) {
List<Research> researchList;
Page<Research> page = new Page<Research>(pageNo, pageSize);
RowBounds researchRowBounds = new RowBounds(page.getOffset(), page.getLimit());
/*if (companyId != null) {
research.setCompanyId(companyId); /
}/ 根据公司id查找
research.setSiteId(siteId);
EntityWrapper<Research> wrapper = new EntityWrapper<Research>(research);
if(null != kwd){
wrapper.like("name",kwd);
}
if(!CollectionUtils.isEmpty(orgIds)){
wrapper.in("org_id",orgIds);
}*/
researchList = researchMapper.selectResearchPage(startDate, endDate, kwd, orgIds, companyId, siteId, researchRowBounds);
if (CollectionUtils.isEmpty(researchList)) {
return null;
}
selectRealCount(researchList);
installRelationIds(researchList);
page.setTotal(researchMapper.selectResearchCount(startDate, endDate, kwd, orgIds, companyId, siteId));
page.setRecords(researchList);
return page;
}
//设置实际参加人数
public void selectRealCount(List<Research> list) {
if (list.size() == 0) {
return;
}
List<Long> researchIds = new ArrayList<Long>();
for (Research research : list) {
researchIds.add(research.getId());
}
if (list != null && list.size() > 0) {
LinkedList<Research> realJoin = researchMapper.selectRealJoin(researchIds);
Iterator<Research> it;
for (Research research : list) {
it = realJoin.iterator();
Research re;
while (it.hasNext()) {
re = it.next();
if (research.getId().equals(re.getId())) {
Integer realCount = re.getRealCount();
if (realCount == null) {
realCount = 0;
}
research.setRealCount(realCount);
}
}
}
}
}
//设置每个调研关联的人员
public void installRelationIds(List<Research> list) {
if (list.size() == 0) {
return;
}
List<Long> researchIds = new ArrayList<Long>();
for (Research research : list) {
researchIds.add(research.getId());
}
LinkedList<TrResearchAuthorize> authorizes;
if (list != null && list.size() > 0) {
authorizes = researchMapper.selectRelationIds(researchIds);
/*Map<Long,List<Long>> map=new HashMap<Long,List<Long>>();
for(Research research : relevance){
if(map.containsKey(research.getId())){
map.get(research.getId()).add(research.getRelationIds());
}else{
List<Long> longs= new LinkedList<>();
longs.add(research.getRelationIds());
map.put(research.getId(),longs);
}
}
Set<Long> set=map.keySet();*/
Iterator<TrResearchAuthorize> it;
TrResearchAuthorize authorize;
for (Research research : list) {
List<Long> longs;
Integer visibleRange = research.getVisibleRange();
if (visibleRange == null) {
visibleRange = 1;
}
if (visibleRange == 2) {
longs = new ArrayList<Long>();
it = authorizes.iterator();
while (it.hasNext()) {
authorize = it.next();
if (research.getId().equals(authorize.getResearchId())) {
Long l = authorize.getRelationId();
longs.add(l);
}
}
research.setRelationIds(longs);
}
}
}
}
@Override
public Research getResearchView(Long researchId) {
Map<Research, List<TrResearchAnswer>> map = new HashMap<Research, List<TrResearchAnswer>>();
Research research = new Research();
research.setId(researchId);
research = researchMapper.selectOne(research);
List<Long> relationIds = new LinkedList<>();
if (research == null) {
return null;
}
List<Long> researchIds = new LinkedList<Long>();
researchIds.add(researchId);
TrResearchAnswer trResearchAnswer = new TrResearchAnswer();
trResearchAnswer.setResearchId(researchId);
EntityWrapper<TrResearchAnswer> entityWrapper = new EntityWrapper<TrResearchAnswer>(trResearchAnswer);
List<TrResearchAnswer> list = researchAnswerMapper.selectList(entityWrapper);
if (research.getVisibleRange() == 2) {
List<TrResearchAuthorize> trResearchAuthorizes = researchMapper.selectRelationIds(researchIds);
for (TrResearchAuthorize trResearchAuthorize : trResearchAuthorizes) {
relationIds.add(trResearchAuthorize.getRelationId());
}
research.setRelationIds(relationIds);
}
research.setTrResearchAnswers(list);
return research;
}
@Override
public VisibleRangeExport vsibleRangeExport(Long researchId) {// TODO Auto-generated method stub
VisibleRangeExport visibleRangeExport = new VisibleRangeExport();
List<Long> accountIds = new ArrayList<Long>();
List<Long> orgIds = new ArrayList<Long>();
Research research = researchMapper.selectById(researchId);
if (research != null) {
visibleRangeExport.setBizId(research.getId());
visibleRangeExport.setBizName(research.getName());
}
List<TrResearchAuthorize> listStudent = researchAuthorizeService.listTrResearchAuthorize(researchId);
if (listStudent != null && listStudent.size() > 0) {
TrResearchAuthorize researchAuthorize = null;
for (int i = 0; i < listStudent.size(); i++) {
researchAuthorize = listStudent.get(i);
if (researchAuthorize != null && researchAuthorize.getType() != null) {
if (researchAuthorize.getType() == 2) {
accountIds.add(researchAuthorize.getRelationId());
}
if (researchAuthorize.getType() == 1) {
orgIds.add(researchAuthorize.getRelationId());
}
}
visibleRangeExport.setAccountIds(accountIds);
visibleRangeExport.setOrgIds(orgIds);
}
}
return visibleRangeExport;
}
@Override
public Page<Map<String, Object>> getPoolExamList(String name, List<Long> ids, Integer pageNo, Integer pageSize) {
HQueryUtil.startHQ(Research.class);
RequestContext res = ContextHolder.get();
Long companyId = res.getCompanyId();
Long siteId = res.getSiteId();
List<Long> orgIds = null;
Page<Map<String, Object>> page = new Page<>(pageNo, pageSize);
List<Map<String, Object>> list = new ArrayList<>();
if (!res.isAdmin() && !CollectionUtils.isEmpty(res.getOrgIds())) {
orgIds = res.getOrgIds();
}
String name1 = null;
if (!StringUtils.isEmpty(name)){
name1= name.trim();
}
list = researchMapper.getPoolExamList(name1, ids, companyId, siteId, orgIds, page);
if (!CollectionUtils.isEmpty(list)){
page.setRecords(list);
}
return page;
}
@Override
public List<Map<String, Object>> getServerByCompanyIdAndIds(Long companyId, List<Long> ids) {
// TODO Auto-generated method stub
List<Map<String, Object>> listMap=null;
//查询
Research research=new Research();
research.setCompanyId(companyId);
EntityWrapper<Research> wrapper=new EntityWrapper<Research>(research);
if(!CollectionUtils.isEmpty(ids)) {
wrapper.in("id", ids);
}
List<Research> listResearch=this.selectList(wrapper);
//循环组装到输出对象
Map<String, Object> map=null;
if(!CollectionUtils.isEmpty(listResearch)) {
listMap=new ArrayList<Map<String, Object>>();
for (Research c:listResearch) {
map=new HashMap<String, Object>();
map.put("catalog", 2);
map.put("id", c.getId());
map.put("name", c.getName());
map.put("logo_url", "");
listMap.add(map);
}
}
return listMap;
}
@Override
public Page<Research> getPageToCalendar(Date date, Page<Research> page) {
RequestContext context = ContextHolder.get();
//获取当天的调研ids
List<Long> ids = researchMapper.getIdsByDate(date, context.getSiteId());
if (CollectionUtils.isEmpty(ids)){
return page;
}
//根据可见范围获取调研ids
List<Long> trIds = trResearchAuthorizeMapper.getUsefulIds(ids,context.getRelationIds(), context.getSiteId());
//获取已完成的调研ids
List<Long> finishTrIds = researchAnswerMapper.getFinshIdsByIds(ids,context.getAccountId(),context.getSiteId());
page.setRecords(researchMapper.getPageToCalendar(finishTrIds, trIds, date, context.getSiteId(), page));
page.setTotal(researchMapper.getPageToCalendarNum(finishTrIds, trIds, date, context.getSiteId()));
return page;
}
@Override
public Page<DroolsVo> getPageByDrools(String field, String value, Page<DroolsVo> page) {
if (StringUtils.isEmpty(field)) {
LOG.info("列名不能为空!");
return page;
}
if (field.equalsIgnoreCase(TaskParamsEnums.NAME.getCode())) {
return getPage(field, value, page);
} else if (field.equalsIgnoreCase(TaskParamsEnums.KEYWORD.getCode())) {
field = "keywords";
return getPage(field, value, page);
}
return page;
}
public Page getPage(String field, String value, Page<DroolsVo> page) {
RequestContext requestContext = ContextHolder.get();
Long siteId = requestContext.getSiteId();
Long companyId = requestContext.getCompanyId();
Research research = new Research();
research.setSiteId(siteId);
research.setCompanyId(companyId);
research.setState(1);
research.setDeleted(0);
EntityWrapper wrapper = new EntityWrapper(research);
wrapper.setSqlSelect("distinct(" + field + "),"+"id ")
.isNotNull(field)
.like(field, value)
.addFilter(field+"!=''")
.orderBy("create_time", false);
String upperField = ClassUtil.getFieldName(field);
List<DroolsVo> voList = null;
List<Research> list = this.baseMapper.selectPage(page, wrapper);
if (!org.springframework.util.CollectionUtils.isEmpty(list)) {
voList = new ArrayList<>(list.size());
for (Research a : list) {
DroolsVo vo = new DroolsVo();
vo.setTaskId(a.getId());
vo.setTaskFieldValue(ClassUtil.invokeMethod(a, upperField));
vo.setTaskParamsType(field);
voList.add(vo);
}
page.setRecords(voList);
}
return page;
}
}
package com.yizhi.research.application.service.impl;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yizhi.research.application.mapper.StatisticsResearchMapper;
import com.yizhi.research.application.service.StatisticsResearchService;
import com.yizhi.research.application.vo.domain.StatisticsResearch;
import com.yizhi.research.application.vo.domain.StatisticsResearchLearn;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.plugins.Page;
@Service
@Transactional
public class StatisticsResearchServiceImpl extends ServiceImpl<StatisticsResearchMapper, StatisticsResearch> implements StatisticsResearchService {
@Autowired
private StatisticsResearchMapper statisticsResearchMapper;
@Override
public Page<StatisticsResearch> researchGroup(String startDate, String endDate, String kwd, Integer pageSize, Integer pageNo, Long companyId, List<Long> orgIds, Long siteId) {
Page<StatisticsResearch> page=new Page<>(pageNo,pageSize);
if(kwd == null || kwd .equals("")){
kwd = null;
}
List<StatisticsResearch> statisticsResearches=statisticsResearchMapper.selectStatisticsResearchPage(startDate,endDate,kwd,companyId,orgIds,siteId,new RowBounds(page.getOffset(),page.getLimit()));
page.setRecords(statisticsResearches);
Integer count=statisticsResearchMapper.selectStatisticsResearchCount(startDate,endDate,kwd,companyId,orgIds,siteId);
for(int i = 0 ; i < statisticsResearches.size(); i ++){
if(statisticsResearches.get(i) != null ) {
statisticsResearches.get(i).setIndex((pageNo - 1) * pageSize + i + 1);
}
}
page.setTotal(count);
return page;
}
public Page<StatisticsResearch> selectResearchView(Long researchId,String startDate, String endDate, String orgNameorOrgCode, String accountName, Integer joinState,
Integer pageNo,Integer pageSize){
Page<StatisticsResearch> page=new Page<>(pageNo,pageSize);
if(accountName == null || accountName.equals("")){
accountName = null;
}
if(orgNameorOrgCode == null ||orgNameorOrgCode.equals("")){
orgNameorOrgCode = null;
}
List<StatisticsResearch> statisticsResearches=statisticsResearchMapper.selectResearchView(researchId,startDate,endDate,
orgNameorOrgCode,accountName,joinState, page);
/*Integer count=statisticsResearchMapper.selectResearchViewCount(researchId,startDate,endDate,orgNameorOrgCode,accountName,joinState);
page.setTotal(count);*/
page.setRecords(statisticsResearches);
return page;
}
public Integer selectResearchViewCount(Long researchId,String startDate, String endDate, String orgNameorOrgCode, String accountName, Integer joinState){
if(accountName == null || accountName.equals("")){
accountName = null;
}
if(orgNameorOrgCode == null ||orgNameorOrgCode.equals("")){
orgNameorOrgCode = null;
}
return statisticsResearchMapper.selectResearchViewCount(researchId,startDate,endDate,orgNameorOrgCode,accountName,joinState);
}
public StatisticsResearch selectJoinCount(Long researchId,String startDate, String endDate, String orgNameorOrgCode, String accountName, Integer joinState
){
if(accountName == null || accountName.equals("")){
accountName = null;
}
if(orgNameorOrgCode == null ||orgNameorOrgCode.equals("")){
orgNameorOrgCode = null;
}
return statisticsResearchMapper.selectJoinCount(researchId,startDate,endDate,orgNameorOrgCode,accountName,joinState);
}
public List<StatisticsResearch> researchViews(
Long researchId,String startDate, String endDate, String orgNameorOrgCode, String accountName, Integer joinState,
Integer pageSize,Integer pageNo
){
if(accountName == null || accountName.equals("")){
accountName = null;
}
if(orgNameorOrgCode == null ||orgNameorOrgCode.equals("")){
orgNameorOrgCode = null;
}
Page<StatisticsResearch> page=new Page<>(pageNo,pageSize);
return statisticsResearchMapper.selectResearchView(researchId,startDate,endDate,orgNameorOrgCode,accountName,joinState, page);
}
public List<StatisticsResearch> researchViewList(Long researchId, String orgNameorOrgCode, String accountName, Integer joinState,String startDate,String endDate ){
if(accountName == null || accountName.equals("")){
accountName = null;
}
if(orgNameorOrgCode == null ||orgNameorOrgCode.equals("")){
orgNameorOrgCode = null;
}
return statisticsResearchMapper.selectResearchViewList(researchId,orgNameorOrgCode,accountName,joinState,startDate,endDate);
}
@Override
public List<StatisticsResearchLearn> insertAccountLearn(Long researchId, String curDate) {
int count = statisticsResearchMapper.insertAccountLearn(researchId, curDate);
if(count == 0){
return null;
}
return statisticsResearchMapper.selectAccountLearn(researchId, curDate);
}
@Override
public Page<Long> selectAccountLearnList(Map<String, Object> paramMap, int pageNo, int pageSize) {
Page<Long> page = new Page<Long>(pageNo, pageSize);
List<Long> ids = statisticsResearchMapper.selectAccountLearnList(paramMap, page);
page.setRecords(ids);
return page;
}
}
package com.yizhi.research.application.service.impl;
import com.yizhi.research.application.mapper.TrResearchAnswerQuestionMapper;
import com.yizhi.research.application.service.ITrResearchAnswerQuestionService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yizhi.research.application.vo.domain.TrResearchAnswerQuestion;
import org.springframework.stereotype.Service;
/**
* <p>
* 答案题目 服务实现类
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@Service
public class TrResearchAnswerQuestionServiceImpl extends ServiceImpl<TrResearchAnswerQuestionMapper, TrResearchAnswerQuestion> implements ITrResearchAnswerQuestionService {
}
package com.yizhi.research.application.service.impl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yizhi.application.orm.id.IdGenerator;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.core.application.event.EventWrapper;
import com.yizhi.core.application.publish.CloudEventPublisher;
import com.yizhi.core.application.task.AbstractTaskHandler;
import com.yizhi.core.application.task.TaskExecutor;
import com.yizhi.research.application.eum.QuestionType;
import com.yizhi.research.application.model.AnswerModel;
import com.yizhi.research.application.service.ITrResearchAnswerService;
import com.yizhi.research.application.service.ITrResearchQuestionService;
import com.yizhi.research.application.mapper.*;
import com.yizhi.research.application.vo.api.*;
import com.yizhi.research.application.vo.domain.*;
import com.yizhi.util.application.constant.QueueConstant;
import com.yizhi.util.application.constant.TpActivityType;
import com.yizhi.util.application.event.TrainingProjectEvent;
import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.*;
/**
* <p>
* 答卷 服务实现类
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@Service
@Transactional
public class TrResearchAnswerServiceImpl extends ServiceImpl<TrResearchAnswerMapper, TrResearchAnswer> implements ITrResearchAnswerService {
private static final Logger LOGGER = LoggerFactory.getLogger(TrResearchAnswerServiceImpl.class);
@Autowired
private IdGenerator idGenerator;
@Autowired
private TrResearchQuestionMapper researchQuestionMapper;
@Autowired
private TrResearchAnswerMapper researchAnswerMapper;
@Autowired
private TrResearchAnswerQuestionMapper researchAnswerQuestionMapper;
@Autowired
private TrResearchAnswerQuestionResultMapper researchQuestionResultMapper;
@Autowired
private TrResearchQuestionOptionMapper researchQuestionOptionMapper;
@Autowired
private ITrResearchQuestionService trResearchQuestionService;
@Autowired
private TaskExecutor taskExecutor;
@Autowired
private CloudEventPublisher cloudEventPublisher;
@Override
public int submitAnswer(AnswerModel answerModel) throws Exception {
RequestContext context = answerModel.getContext();
Long accountId = context.getAccountId();
Long companyId = context.getCompanyId();
Long orgId = context.getOrgId() == null ? Long.valueOf(0L) : context.getOrgId();
Long siteId = context.getSiteId() == null ? Long.valueOf(0L) : context.getSiteId();
String accountName = context.getAccountName();
Date now = answerModel.getDate();
int num;
// 答案vo
AnswerVo answerVo = answerModel.getAnswerVo();
TrResearchAnswer answer = buildAnswer(answerVo, accountId, companyId, accountName, siteId, orgId, now);
//查询该调研所有的问题
TrResearchQuestion question = new TrResearchQuestion();
question.setResearchId(answerVo.getResearchId());
question.setDeleted(0);
List<TrResearchQuestion> questions = researchQuestionMapper.selectList(new EntityWrapper<TrResearchQuestion>(question));
Map<Long, TrResearchQuestion> questionMap = new HashMap<Long, TrResearchQuestion>();
if (!CollectionUtils.isEmpty(questions)) {
for (TrResearchQuestion q : questions) {
if (questionMap.get(q.getId()) == null) {
questionMap.put(q.getId(), q);
}
}
}
//查询该调研下所有问题的其他选项
TrResearchQuestionOption option = new TrResearchQuestionOption();
option.setResearchId(answerVo.getResearchId());
option.setIsOther(1);
option.setDeleted(0);
option.setRequired(1);
List<TrResearchQuestionOption> options = researchQuestionOptionMapper.selectList(new EntityWrapper<TrResearchQuestionOption>(option));
Map<Long, TrResearchQuestionOption> optionMap = new HashMap<Long, TrResearchQuestionOption>();
for (TrResearchQuestionOption o : options) {
if (optionMap.get(o.getId()) == null) {
optionMap.put(o.getId(), o);
}
}
// 答案问题vo
List<AnswerQuestionVo> questionVos = answerVo.getQuestions();
// 答案选项,答案内容,答案打分等
List<TrResearchAnswerQuestionResult> questionResults = new ArrayList<>();
List<TrResearchAnswerQuestion> answerQuestions = buildAnswerQuestion(questionVos, answer, accountId, accountName, now, questionResults);
Map<Long, List<TrResearchAnswerQuestionResult>> questionItemMap = new HashMap<Long, List<TrResearchAnswerQuestionResult>>();
List<TrResearchAnswerQuestionResult> questionResultList;
for (TrResearchAnswerQuestionResult result : questionResults) {
questionResultList = questionItemMap.get(result.getAnswerQuestionId());
if (questionResultList == null) {
questionResultList = new ArrayList<TrResearchAnswerQuestionResult>();
questionResultList.add(result);
} else {
questionResultList.add(result);
}
questionItemMap.put(result.getAnswerQuestionId(), questionResultList);
}
TrResearchQuestion q;
TrResearchQuestionOption o;
for (TrResearchAnswerQuestion answerQuestion : answerQuestions) {
questionResultList = questionItemMap.get(answerQuestion.getId());
// //是否超过五个字的检查
// if (!CollectionUtils.isEmpty(questionResultList)) {
// for (TrResearchAnswerQuestionResult result : questionResultList) {
// if (result != null && result.getContent() != null && result.getContent(),size() <=5 ) {
// return -3;
// }
// }
// }
//必答题的检查
int flag = 1;//需要回答
q = questionMap.get(answerQuestion.getQuestionId());
int need = q.getNeedAnswer();
if (need == 1) {
if (CollectionUtils.isEmpty(questionResultList)) {
return -2;
} else {
for (TrResearchAnswerQuestionResult result : questionResultList) {
if (result.getOptionId() != null || (result.getContent() != null && result.getContent() != "") || result.getScore() != null) {
flag = 0;
}
}
if (flag == 1) {
return -2;
}
}
}
if (!CollectionUtils.isEmpty(questionResultList)) {
for (TrResearchAnswerQuestionResult result : questionResultList) {
flag = 1;
o = optionMap.get(result.getOptionId());
if (o == null || (o != null && result.getContent() != null && result.getContent() != "")) {
flag = 0;
}
}
if (flag == 1) {
return -2;
}
}
}
//根据调研以及accountId查询是否提交过
TrResearchAnswer reAnswer = new TrResearchAnswer();
reAnswer.setAccountId(accountId);
reAnswer.setResearchId(answerVo.getResearchId());
reAnswer.setFinish(1);
EntityWrapper<TrResearchAnswer> wrapper = new EntityWrapper<TrResearchAnswer>(reAnswer);
int size = researchAnswerMapper.selectList(wrapper).size();
if (size > 0) {
num = -111;
} else {
reAnswer.setFinish(0);
wrapper = new EntityWrapper<>(reAnswer);
int s = researchAnswerMapper.selectList(wrapper).size();
if (s > 0) {
researchAnswerMapper.delete(wrapper);
}
num = researchAnswerMapper.insert(answer);
researchAnswerQuestionMapper.batchInsert(answerQuestions);
if (!CollectionUtils.isEmpty(questionResults)) {
researchQuestionResultMapper.batchInsert(questionResults);
}
}
// 向培训项目发送消息,告知业务已经完成
EventWrapper<TrainingProjectEvent> eventWrapper = new EventWrapper<TrainingProjectEvent>(answer.getResearchId(), TrainingProjectEvent.getInstance(answer.getResearchId(), TpActivityType.TYPE_RESEARCH, accountId, now, context.getSiteId()));
LOGGER.info("向培训项目发送消息,告知业务已经完成:{}", eventWrapper);
taskExecutor.asynExecute(new AbstractTaskHandler() {
@Override
public void handle() {
try {
cloudEventPublisher.publish(QueueConstant.TRAINING_PROJECT_EVENT_QUEUE, eventWrapper);
} catch (Exception e) {
e.printStackTrace();
}
}
});
return num;
}
/**
* 学员查看已完成的调研内容
*/
@Override
public ViewAnswerVo apiViewAnswer(Long researchId, Long accountId) {
// 查出答案主体
List<TrResearchAnswer> answers = new LinkedList<TrResearchAnswer>();
TrResearchAnswer answer = new TrResearchAnswer();
answer.setResearchId(researchId);
answer.setAccountId(accountId);
answer.setFinish(1);
EntityWrapper<TrResearchAnswer> wrapper = new EntityWrapper<TrResearchAnswer>(answer);
answers = researchAnswerMapper.selectList(wrapper);
if (answers.size() > 0) {
answer = answers.get(0);
// 组装答案主体vo
ViewAnswerVo answerVo = new ViewAnswerVo();
answerVo.setAccountId(answer.getAccountId());
answerVo.setId(answer.getId());
answerVo.setDuration(answer.getDuration());
answerVo.setName(answer.getName());
answerVo.setStartTime(answer.getStartTime());
answerVo.setSubmitTime(answer.getSubmitTime());
answerVo.setTerminalType(answer.getTerminalType());
answerVo.setAnswerQuestions(new ArrayList<>());
// 查出根据这个researchId查询到的问题
TrResearchQuestion question = new TrResearchQuestion();
question.setDeleted(0);
question.setResearchId(researchId);
EntityWrapper<TrResearchQuestion> questionEW = new EntityWrapper<>(question);
questionEW.orderBy("no", true);
List<TrResearchQuestion> questions = researchQuestionMapper.selectList(questionEW);
// 查出根据答卷id查到的问题
TrResearchAnswerQuestion answerQuestion = new TrResearchAnswerQuestion();
answerQuestion.setResearchId(researchId);
answerQuestion.setAnswerId(answer.getId());
answerQuestion.setAccountId(accountId);
EntityWrapper<TrResearchAnswerQuestion> answerQuestionEW = new EntityWrapper<TrResearchAnswerQuestion>(answerQuestion);
List<TrResearchAnswerQuestion> answerQuestions = researchAnswerQuestionMapper.selectList(answerQuestionEW);
// 查出关联问题选项等
TrResearchQuestionOption questionOption = new TrResearchQuestionOption();
questionOption.setResearchId(researchId);
questionOption.setDeleted(0);
EntityWrapper<TrResearchQuestionOption> optionEW = new EntityWrapper<>(questionOption);
List<TrResearchQuestionOption> questionOptions = researchQuestionOptionMapper.selectList(optionEW);
// 查出学员的答案选项
TrResearchAnswerQuestionResult questionResult = new TrResearchAnswerQuestionResult();
questionResult.setAnswerId(answer.getId());
List<TrResearchAnswerQuestionResult> questionResults = researchQuestionResultMapper.selectList(new EntityWrapper<TrResearchAnswerQuestionResult>(questionResult));
// 如果 问题主体集合不为空 and 回答问题不为空 and 学员回答记录不为空
if (!CollectionUtils.isEmpty(questions) && !CollectionUtils.isEmpty(answerQuestions) && !CollectionUtils.isEmpty(questionResults)) {
// 以问题id为key,问题答案为value的map
Map<Long, List<TrResearchQuestionOption>> questionOptionMap = new HashMap<>();
//questionOptions:关联的问题选项调研id查询出来的)
for (TrResearchQuestionOption option : questionOptions) {
//当map中没有这个题目时,将该题目关联的选项全部添加进这个map
if (questionOptionMap.get(option.getQuestionId()) == null) {
List<TrResearchQuestionOption> list = new ArrayList<>();
list.add(option);
questionOptionMap.put(option.getQuestionId(), list);
} else {
questionOptionMap.get(option.getQuestionId()).add(option);
}
}
// 以问题id为key,问题答案为value的map(answerId查出来的)
Map<Long, List<TrResearchAnswerQuestionResult>> answerResultMap = new HashMap<>();
for (TrResearchAnswerQuestionResult result : questionResults) {
if (answerResultMap.get(result.getAnswerQuestionId()) == null) {
List<TrResearchAnswerQuestionResult> list = new ArrayList<>();
list.add(result);
answerResultMap.put(result.getAnswerQuestionId(), list);
} else {
answerResultMap.get(result.getAnswerQuestionId()).add(result);
}
}
List<TrResearchQuestionOption> optionList = null;
List<TrResearchAnswerQuestionResult> resultList = null;
TrResearchAnswerQuestion raq = null;
List<TrResearchQuestion> questionToReMove = new ArrayList<>(50);
//questions:根据researchId 查到的所有问题
for (TrResearchQuestion q : questions) {
/*questionToReMove.addAll(removeByQuestion(questions,q));*/
ViewAnswerQuestionVo questionVo = new ViewAnswerQuestionVo();
questionVo.setContent(q.getContent());
questionVo.setContentAppendixUrl(q.getContentAppendixUrl());
questionVo.setId(q.getId());
questionVo.setMaxSelectItem(q.getMaxSelectItem());
questionVo.setMinSelectItem(q.getMinSelectItem());
questionVo.setNeedAnswer(q.getNeedAnswer());
questionVo.setNo(q.getNo());
questionVo.setType(q.getType());
questionVo.setOptions(new ArrayList<>());
//answerQuestions 是这个人这个调研的所有问题
// 拿到关联的答案问题
for (TrResearchAnswerQuestion aq : answerQuestions) {
raq = null;
if (questionVo.getId().equals(aq.getQuestionId())) {
//判断根据调研id和answerId查询出来的问题是同一个问题,从而可以比较学员选中的答案。
raq = aq;
break;
}
}
// 判定学员是否回答了这个
if (null != raq) {
// 拿取问题下的选项
optionList = questionOptionMap.get(q.getId());
if (!CollectionUtils.isEmpty(optionList)) {
// 处理 选择题
//1.如果是单选题或者是多选题,学员选项TrResearchAnswerQuestionResult中有OptionId记录正确的选项id
if (q.getType().equals(QuestionType.SINGLE_OPTION_QUESTION.getValue())
|| q.getType().equals(QuestionType.MULTIPLE_OPTION_QUESTION.getValue())) {
//遍历循环根据researchId查询出来的选项
for (TrResearchQuestionOption o : optionList) {
ViewAnswerQuestionOptionVo optionVo = new ViewAnswerQuestionOptionVo();
optionVo.setIsOther(o.getIsOther());
optionVo.setContent(o.getContent());
optionVo.setEditable(o.getEditable());
optionVo.setCorrect(o.getCorrect());
optionVo.setId(o.getId());
optionVo.setJumpNum(o.getJumpNum());
optionVo.setNo(o.getNo());
//获得学员回答该题目的选项
resultList = answerResultMap.get(raq.getId());
if (!CollectionUtils.isEmpty(resultList)) {
//遍历这些选项
for (TrResearchAnswerQuestionResult r : resultList) {
if (null != r.getOptionId()) {
optionVo.setAnswerChecked(r.getOptionId().equals(optionVo.getId()));
optionVo.setAnswerContent(r.getContent());
if (optionVo.getAnswerChecked()) {
//questionToReMove.addAll(removeByQuestion(questions,optionVo.getJumpNum()));
break;
}
}
}
}
questionVo.getOptions().add(optionVo);
}
}
// 处理 打分题
if (q.getType().equals(QuestionType.POINT_QUESTION.getValue())) {
for (TrResearchQuestionOption o : optionList) {
//循环调研的选项
ViewAnswerQuestionOptionVo optionVo = new ViewAnswerQuestionOptionVo();
optionVo.setContent(o.getContent());
optionVo.setId(o.getId());
optionVo.setNo(o.getNo());
optionVo.setMaxScore(o.getMaxScore());
optionVo.setMinScore(o.getMinScore());
// 获取分数
resultList = answerResultMap.get(raq.getId());
if (!CollectionUtils.isEmpty(resultList)) {
for (TrResearchAnswerQuestionResult r : resultList) {
if (optionVo.getId().equals(r.getOptionId())) {
optionVo.setAnswerScore(r.getScore());
break;
}
}
}
questionVo.getOptions().add(optionVo);
}
}
}
// 处理 问答题
if (q.getType().equals(QuestionType.ASK_ANSWER_QUESTION.getValue())) {
resultList = answerResultMap.get(raq.getId());
if (!CollectionUtils.isEmpty(resultList)) {
questionVo.setAnswerContent(resultList.get(0).getContent());
}
}
answerVo.getAnswerQuestions().add(questionVo);
}
}
List<ViewAnswerQuestionVo> questionVos = answerVo.getAnswerQuestions();
List<ViewAnswerQuestionVo> questionVoList = new ArrayList<>(50);
if (!CollectionUtils.isEmpty(questionVos)) {
for (ViewAnswerQuestionVo vo : questionVos) {
for (TrResearchQuestion q : questionToReMove) {
if (q.getId().equals(vo.getId())) {
questionVoList.add(vo);
}
}
}
}
questionVos.removeAll(questionVoList);
answerVo.setAnswerQuestions(questionVos);
}
return answerVo;
}
return null;
}
public Page<ViewAnswerVo> apiViewAnswers(Long researchId, Integer pageNo, Integer pageSize) {
Page<TrResearchAnswer> page = new Page<TrResearchAnswer>(pageNo, pageSize);
// 查出答案主体
RowBounds rowBounds = new RowBounds(page.getOffset(), page.getLimit());
TrResearchAnswer answer = new TrResearchAnswer();
answer.setResearchId(researchId);
answer.setFinish(1);
EntityWrapper<TrResearchAnswer> wrapper = new EntityWrapper<TrResearchAnswer>(answer);
List<TrResearchAnswer> answers = researchAnswerMapper.selectPage(rowBounds, wrapper);
int total = researchAnswerMapper.selectFinishCount(researchId);
List<ViewAnswerVo> viewAnswerVos = new ArrayList<ViewAnswerVo>();
ViewAnswerVo answerVo;
for (TrResearchAnswer trResearchAnswer : answers) {
// 组装答案主体vo
answerVo = new ViewAnswerVo();
answerVo.setAccountId(trResearchAnswer.getAccountId());
answerVo.setId(trResearchAnswer.getId());
answerVo.setDuration(trResearchAnswer.getDuration());
answerVo.setName(trResearchAnswer.getName());
answerVo.setStartTime(trResearchAnswer.getStartTime());
answerVo.setSubmitTime(trResearchAnswer.getSubmitTime());
answerVo.setTerminalType(trResearchAnswer.getTerminalType());
answerVo.setAnswerQuestions(new ArrayList<>());
// 查出根据这个researchId查询到的问题
TrResearchQuestion question = new TrResearchQuestion();
question.setDeleted(0);
question.setResearchId(researchId);
EntityWrapper<TrResearchQuestion> questionEW = new EntityWrapper<>(question);
questionEW.orderBy("no", true);
List<TrResearchQuestion> questions = researchQuestionMapper.selectList(questionEW);
// 查出根据答卷id查到的问题
TrResearchAnswerQuestion answerQuestion = new TrResearchAnswerQuestion();
answerQuestion.setResearchId(researchId);
answerQuestion.setAnswerId(answer.getId());
answerQuestion.setAccountId(trResearchAnswer.getAccountId());
EntityWrapper<TrResearchAnswerQuestion> answerQuestionEW = new EntityWrapper<TrResearchAnswerQuestion>(answerQuestion);
List<TrResearchAnswerQuestion> answerQuestions = researchAnswerQuestionMapper.selectList(answerQuestionEW);
// 查出关联问题选项等
TrResearchQuestionOption questionOption = new TrResearchQuestionOption();
questionOption.setResearchId(researchId);
questionOption.setDeleted(0);
EntityWrapper<TrResearchQuestionOption> optionEW = new EntityWrapper<>(questionOption);
optionEW.orderBy("no", true);
List<TrResearchQuestionOption> questionOptions = researchQuestionOptionMapper.selectList(optionEW);
// 查出学员的答案选项
TrResearchAnswerQuestionResult questionResult = new TrResearchAnswerQuestionResult();
questionResult.setAnswerId(answer.getId());
List<TrResearchAnswerQuestionResult> questionResults = researchQuestionResultMapper.selectList(new EntityWrapper<TrResearchAnswerQuestionResult>(questionResult));
// 如果 问题主体集合不为空 and 回答问题不为空 and 学员回答记录不为空
if (!CollectionUtils.isEmpty(questions) && !CollectionUtils.isEmpty(answerQuestions) && !CollectionUtils.isEmpty(questionResults)) {
/*for(TrResearchQuestion q : questions){
getNo(q);
}*/
// 以问题id为key,问题答案为value的map
Map<Long, List<TrResearchQuestionOption>> questionOptionMap = new HashMap<>();
//questionOptions:关联的问题选项(调研id查询出来的)
for (TrResearchQuestionOption option : questionOptions) {
//当map中没有这个题目时,将该题目关联的选项全部添加进这个map
if (questionOptionMap.get(option.getQuestionId()) == null) {
List<TrResearchQuestionOption> list = new ArrayList<>();
list.add(option);
questionOptionMap.put(option.getQuestionId(), list);
} else {
questionOptionMap.get(option.getQuestionId()).add(option);
}
}
// 以问题id为key,问题答案为value的map(answerId查出来的)
Map<Long, List<TrResearchAnswerQuestionResult>> answerResultMap = new HashMap<>();
for (TrResearchAnswerQuestionResult result : questionResults) {
if (answerResultMap.get(result.getAnswerQuestionId()) == null) {
List<TrResearchAnswerQuestionResult> list = new ArrayList<>();
list.add(result);
answerResultMap.put(result.getAnswerQuestionId(), list);
} else {
answerResultMap.get(result.getAnswerQuestionId()).add(result);
}
}
List<TrResearchQuestionOption> optionList = null;
List<TrResearchAnswerQuestionResult> resultList = null;
TrResearchAnswerQuestion raq = null;
List<TrResearchQuestion> questionToReMove = new ArrayList<>(50);
//questions:根据researchId 查到的所有问题
for (TrResearchQuestion q : questions) {
/*questionToReMove.addAll(removeByQuestion(questions,q));*/
ViewAnswerQuestionVo questionVo = new ViewAnswerQuestionVo();
questionVo.setContent(q.getContent());
questionVo.setContentAppendixUrl(q.getContentAppendixUrl());
questionVo.setId(q.getId());
questionVo.setMaxSelectItem(q.getMaxSelectItem());
questionVo.setMinSelectItem(q.getMinSelectItem());
questionVo.setNeedAnswer(q.getNeedAnswer());
questionVo.setNo(q.getNo());
questionVo.setType(q.getType());
questionVo.setOptions(new ArrayList<>());
//answerQuestions 是这个人这个调研的所有问题
// 拿到关联的答案问题
for (TrResearchAnswerQuestion aq : answerQuestions) {
raq = null;
if (questionVo.getId().equals(aq.getQuestionId())) {
//判断根据调研id和answerId查询出来的问题是同一个问题,从而可以比较学员选中的答案。
raq = aq;
break;
}
}
// 判定学员是否回答了这个
if (null != raq) {
// 拿取问题下的选项
optionList = questionOptionMap.get(q.getId());
if (!CollectionUtils.isEmpty(optionList)) {
// 处理 选择题
//1.如果是单选题或者是多选题,学员选项TrResearchAnswerQuestionResult中有OptionId记录正确的选项id
if (q.getType().equals(QuestionType.SINGLE_OPTION_QUESTION.getValue())
|| q.getType().equals(QuestionType.MULTIPLE_OPTION_QUESTION.getValue())) {
//遍历循环根据researchId查询出来的选项
for (TrResearchQuestionOption o : optionList) {
ViewAnswerQuestionOptionVo optionVo = new ViewAnswerQuestionOptionVo();
optionVo.setContent(o.getContent());
optionVo.setCorrect(o.getCorrect());
optionVo.setId(o.getId());
optionVo.setJumpNum(o.getJumpNum());
optionVo.setNo(o.getNo());
//获得学员回答该题目的选项
resultList = answerResultMap.get(raq.getId());
if (!CollectionUtils.isEmpty(resultList)) {
//遍历这些选项
for (TrResearchAnswerQuestionResult r : resultList) {
if (null != r.getOptionId()) {
optionVo.setAnswerChecked(r.getOptionId().equals(optionVo.getId()));
optionVo.setAnswerContent(r.getContent());
if (optionVo.getAnswerChecked()) {
//questionToReMove.addAll(removeByQuestion(questions,optionVo.getJumpNum()));
break;
}
}
}
}
questionVo.getOptions().add(optionVo);
}
}
// 处理 打分题
if (q.getType().equals(QuestionType.POINT_QUESTION.getValue())) {
for (TrResearchQuestionOption o : optionList) {
//循环调研的选项
ViewAnswerQuestionOptionVo optionVo = new ViewAnswerQuestionOptionVo();
optionVo.setContent(o.getContent());
optionVo.setId(o.getId());
optionVo.setNo(o.getNo());
optionVo.setMaxScore(o.getMaxScore());
optionVo.setMinScore(o.getMinScore());
// 获取分数
resultList = answerResultMap.get(raq.getId());
if (!CollectionUtils.isEmpty(resultList)) {
for (TrResearchAnswerQuestionResult r : resultList) {
if (optionVo.getId().equals(r.getOptionId())) {
optionVo.setAnswerScore(r.getScore());
break;
}
}
}
questionVo.getOptions().add(optionVo);
}
}
}
// 处理 问答题
if (q.getType().equals(QuestionType.ASK_ANSWER_QUESTION.getValue())) {
resultList = answerResultMap.get(raq.getId());
if (!CollectionUtils.isEmpty(resultList)) {
questionVo.setAnswerContent(resultList.get(0).getContent());
}
}
answerVo.getAnswerQuestions().add(questionVo);
}
}
List<ViewAnswerQuestionVo> questionVos = answerVo.getAnswerQuestions();
List<ViewAnswerQuestionVo> questionVoList = new ArrayList<>(50);
if (!CollectionUtils.isEmpty(questionVos)) {
for (ViewAnswerQuestionVo vo : questionVos) {
for (TrResearchQuestion q : questionToReMove) {
if (q.getId().equals(vo.getId())) {
questionVoList.add(vo);
}
}
}
}
questionVos.removeAll(questionVoList);
answerVo.setAnswerQuestions(questionVos);
}
viewAnswerVos.add(answerVo);
}
Page<ViewAnswerVo> viewAnswerVoPage = new Page<>(pageNo, pageSize);
viewAnswerVoPage.setRecords(viewAnswerVos);
viewAnswerVoPage.setTotal(total);
return viewAnswerVoPage;
}
public Integer apiViewAnswersCount(Long researchId) {
return researchAnswerMapper.selectFinishCount(researchId);
}
public List<ViewAnswerVo> viewAnswerVoList(Long researchId, Integer pageNo, Integer pageSize) {
Page<TrResearchAnswer> page = new Page<TrResearchAnswer>(pageNo, pageSize);
// 查出所有用户的答卷主体集合
RowBounds rowBounds = new RowBounds(page.getOffset(), page.getLimit());
TrResearchAnswer answer = new TrResearchAnswer();
answer.setResearchId(researchId);
answer.setFinish(1);
EntityWrapper<TrResearchAnswer> wrapper = new EntityWrapper<TrResearchAnswer>(answer);
List<String> stringList = new ArrayList<>();
stringList.add("submit_time");
stringList.add("id");
wrapper.orderDesc(stringList);
List<TrResearchAnswer> answers = researchAnswerMapper.selectPage(rowBounds, wrapper);
if (CollectionUtils.isEmpty(answers)) {
return new ArrayList<>();
}
// 根据researchId查询该调研所有问题集合
TrResearchQuestion question = new TrResearchQuestion();
question.setDeleted(0);
question.setResearchId(researchId);
EntityWrapper<TrResearchQuestion> questionEW = new EntityWrapper<>(question);
questionEW.orderBy("no", true);
List<TrResearchQuestion> questions = researchQuestionMapper.selectList(questionEW);
// 根据researchId查询该调研所有问题选项集合
TrResearchQuestionOption questionOption = new TrResearchQuestionOption();
questionOption.setResearchId(researchId);
questionOption.setDeleted(0);
EntityWrapper<TrResearchQuestionOption> optionEW = new EntityWrapper<>(questionOption);
optionEW.orderBy("no", true);
List<TrResearchQuestionOption> questionOptions = researchQuestionOptionMapper.selectList(optionEW);
// 以问题id为key,问题选项为value的map
Map<Long, List<TrResearchQuestionOption>> questionOptionMap = new HashMap<>();
for (TrResearchQuestionOption option : questionOptions) {
if (questionOptionMap.get(option.getQuestionId()) == null) {
List<TrResearchQuestionOption> list = new ArrayList<>();
list.add(option);
questionOptionMap.put(option.getQuestionId(), list);
} else {
questionOptionMap.get(option.getQuestionId()).add(option);
}
}
//开始组装数据
List<ViewAnswerVo> viewAnswerVos = new ArrayList<ViewAnswerVo>();
ViewAnswerVo answerVo = null;
for (TrResearchAnswer trResearchAnswer : answers) {
// 根据调研id、用户id,查出答卷与问题关联关系的集合
TrResearchAnswerQuestion answerQuestion = new TrResearchAnswerQuestion();
answerQuestion.setResearchId(researchId);
answerQuestion.setAnswerId(trResearchAnswer.getId());
answerQuestion.setAccountId(trResearchAnswer.getAccountId());
EntityWrapper<TrResearchAnswerQuestion> answerQuestionEW = new EntityWrapper<TrResearchAnswerQuestion>(answerQuestion);
List<TrResearchAnswerQuestion> answerQuestions = researchAnswerQuestionMapper.selectList(answerQuestionEW);
// 根据答卷id,查出该学员的问题答案集合
TrResearchAnswerQuestionResult questionResult = new TrResearchAnswerQuestionResult();
questionResult.setAnswerId(trResearchAnswer.getId());
List<TrResearchAnswerQuestionResult> questionResults = researchQuestionResultMapper.selectList(new EntityWrapper<TrResearchAnswerQuestionResult>(questionResult));
Map<Long, List<TrResearchAnswerQuestionResult>> answerResultMap = new HashMap<>();
// 以问题答卷关联id为key,问题答案为value的 map
if (!CollectionUtils.isEmpty(questionResults)) {
for (TrResearchAnswerQuestionResult result : questionResults) {
if (answerResultMap.get(result.getAnswerQuestionId()) == null) {
List<TrResearchAnswerQuestionResult> list = new ArrayList<>();
list.add(result);
answerResultMap.put(result.getAnswerQuestionId(), list);
} else {
answerResultMap.get(result.getAnswerQuestionId()).add(result);
}
}
}
// 组装答案主体vo
answerVo = fillAnswerVo(answerVo, trResearchAnswer);
// 如果 问题主体集合不为空 and 回答问题不为空 and 学员回答记录不为空
if (!CollectionUtils.isEmpty(questions) && !CollectionUtils.isEmpty(answerQuestions)) {
//遍历所有问题
for (TrResearchQuestion q : questions) {
ViewAnswerQuestionVo questionVo = null;
//在answerVo里面组装问题questionVo
//q: 问题
//answerQuestions : 该调研该用户的答卷与问题关联关系的集合
//questionOptionMap: 以问题id为key,问题选项为value的map
//answerResultMap : 以问题答卷关联id为key,问题答案为value的 map
answerVo = fillQuestionVo(answerVo, questionVo, q, answerQuestions, questionOptionMap, answerResultMap);
}
}
viewAnswerVos.add(answerVo);
}
return viewAnswerVos;
}
private ViewAnswerVo fillAnswerVo(ViewAnswerVo answerVo, TrResearchAnswer trResearchAnswer) {
answerVo = new ViewAnswerVo();
answerVo.setAccountId(trResearchAnswer.getAccountId());
answerVo.setId(trResearchAnswer.getId());
answerVo.setDuration(trResearchAnswer.getDuration());
answerVo.setName(trResearchAnswer.getName());
answerVo.setStartTime(trResearchAnswer.getStartTime());
answerVo.setSubmitTime(trResearchAnswer.getSubmitTime());
answerVo.setTerminalType(trResearchAnswer.getTerminalType());
answerVo.setAnswerQuestions(new ArrayList<>());
return answerVo;
}
/**
*
//
* @param answerVo 在answerVo里面组装问题questionVo
* @param questionVo
* @param q 问题
* @param answerQuestions 该调研该用户的答卷与问题关联关系的集合
* @param questionOptionMap 以问题id为key,问题选项为value的map
* @param answerResultMap 以问题答卷关联id为key,问题答案为value的 map
* @return
*/
private ViewAnswerVo fillQuestionVo(ViewAnswerVo answerVo, ViewAnswerQuestionVo questionVo, TrResearchQuestion q, List<TrResearchAnswerQuestion> answerQuestions,
Map<Long, List<TrResearchQuestionOption>> questionOptionMap, Map<Long, List<TrResearchAnswerQuestionResult>> answerResultMap) {
TrResearchAnswerQuestion raq = null;
questionVo = new ViewAnswerQuestionVo();
questionVo.setContent(q.getContent());
questionVo.setContentAppendixUrl(q.getContentAppendixUrl());
questionVo.setId(q.getId());
questionVo.setMaxSelectItem(q.getMaxSelectItem());
questionVo.setMinSelectItem(q.getMinSelectItem());
questionVo.setNeedAnswer(q.getNeedAnswer());
questionVo.setNo(q.getNo());
questionVo.setType(q.getType());
questionVo.setOptions(new ArrayList<>());
//answerQuestions 是这个人这个调研的所有答卷问题关联记录集合
for (TrResearchAnswerQuestion aq : answerQuestions) {
raq = null;
if (q.getId().equals(aq.getQuestionId())) {
//通过比较答卷记录的问题id与调研问题id是否相等,判断该用户是否回答了该道题
raq = aq;
break;
}
}
// 判定学员是否回答了这个
if (null != raq) {
// 拿取问题下的选项
List<TrResearchQuestionOption> optionList = questionOptionMap.get(q.getId());
if (!CollectionUtils.isEmpty(optionList)) {
//在questionVo 里面组装optionVo
questionVo = fillOptionVo(questionVo, raq, q, optionList, questionOptionMap, answerResultMap);
} else {
// 处理 问答题
if (q.getType().equals(QuestionType.ASK_ANSWER_QUESTION.getValue())) {
List<TrResearchAnswerQuestionResult> resultList = answerResultMap.get(raq.getId());
if (!CollectionUtils.isEmpty(resultList)) {
questionVo.setAnswerContent(resultList.get(0).getContent());
}
}
}
}
answerVo.getAnswerQuestions().add(questionVo);
return answerVo;
}
/**
*
* @param questionVo
* @param raq 答卷问题关联记录
* @param q 问题
* @param optionList 选项列表
* @param questionOptionMap 以问题id为key,问题选项为value的map
* @param answerResultMap 以问题答卷关联id为key,问题答案为value的 map
* @return
*/
private ViewAnswerQuestionVo fillOptionVo(ViewAnswerQuestionVo questionVo, TrResearchAnswerQuestion raq, TrResearchQuestion q,
List<TrResearchQuestionOption> optionList, Map<Long, List<TrResearchQuestionOption>> questionOptionMap,
Map<Long, List<TrResearchAnswerQuestionResult>> answerResultMap) {
// 处理 选择题
//1.如果是单选题或者是多选题,学员选项TrResearchAnswerQuestionResult中有OptionId记录正确的选项id
if (q.getType().equals(QuestionType.SINGLE_OPTION_QUESTION.getValue())
|| q.getType().equals(QuestionType.MULTIPLE_OPTION_QUESTION.getValue())) {
//遍历循环根据researchId查询出来的选项
for (TrResearchQuestionOption o : optionList) {
ViewAnswerQuestionOptionVo optionVo = new ViewAnswerQuestionOptionVo();
optionVo.setContent(o.getContent());
optionVo.setCorrect(o.getCorrect());
optionVo.setId(o.getId());
optionVo.setJumpNum(o.getJumpNum());
optionVo.setNo(o.getNo());
//获得该问题该用户的答案
List<TrResearchAnswerQuestionResult> resultList = answerResultMap.get(raq.getId());
if (!CollectionUtils.isEmpty(resultList)) {
//遍历这些选项
for (TrResearchAnswerQuestionResult r : resultList) {
if (null != r.getOptionId()) {
optionVo.setAnswerChecked(r.getOptionId().equals(optionVo.getId()));
optionVo.setAnswerContent(r.getContent());
if (optionVo.getAnswerChecked()) {
break;
}
}
}
}
questionVo.getOptions().add(optionVo);
}
}
// 处理 打分题
if (q.getType().equals(QuestionType.POINT_QUESTION.getValue())) {
for (TrResearchQuestionOption o : optionList) {
//循环调研的选项
ViewAnswerQuestionOptionVo optionVo = new ViewAnswerQuestionOptionVo();
optionVo.setContent(o.getContent());
optionVo.setId(o.getId());
optionVo.setNo(o.getNo());
optionVo.setMaxScore(o.getMaxScore());
optionVo.setMinScore(o.getMinScore());
// 获取分数
List<TrResearchAnswerQuestionResult> resultList = answerResultMap.get(raq.getId());
if (!CollectionUtils.isEmpty(resultList)) {
for (TrResearchAnswerQuestionResult r : resultList) {
if (optionVo.getId().equals(r.getOptionId())) {
optionVo.setAnswerScore(r.getScore());
break;
}
}
}
questionVo.getOptions().add(optionVo);
}
}
return questionVo;
}
@Override
public List<ViewAnswerVo> viewList(Long researchId) {
TrResearchAnswer answer = new TrResearchAnswer();
answer.setResearchId(researchId);
answer.setFinish(1);
EntityWrapper<TrResearchAnswer> wrapper = new EntityWrapper<TrResearchAnswer>(answer);
List<TrResearchAnswer> answers = researchAnswerMapper.selectList(wrapper);
List<ViewAnswerVo> viewAnswerVos = new ArrayList<ViewAnswerVo>();
ViewAnswerVo answerVo;
for (TrResearchAnswer trResearchAnswer : answers) {
// 组装答案主体vo
answerVo = new ViewAnswerVo();
answerVo.setAccountId(trResearchAnswer.getAccountId());
answerVo.setId(trResearchAnswer.getId());
answerVo.setDuration(trResearchAnswer.getDuration());
answerVo.setName(trResearchAnswer.getName());
answerVo.setStartTime(trResearchAnswer.getStartTime());
answerVo.setSubmitTime(trResearchAnswer.getSubmitTime());
answerVo.setTerminalType(trResearchAnswer.getTerminalType());
answerVo.setAnswerQuestions(new ArrayList<>());
// 查出根据这个researchId查询到的问题
TrResearchQuestion question = new TrResearchQuestion();
question.setDeleted(0);
question.setResearchId(researchId);
EntityWrapper<TrResearchQuestion> questionEW = new EntityWrapper<>(question);
questionEW.orderBy("no", true);
List<TrResearchQuestion> questions = researchQuestionMapper.selectList(questionEW);
// 查出根据答卷id查到的问题
TrResearchAnswerQuestion answerQuestion = new TrResearchAnswerQuestion();
answerQuestion.setResearchId(researchId);
answerQuestion.setAnswerId(answer.getId());
answerQuestion.setAccountId(trResearchAnswer.getAccountId());
EntityWrapper<TrResearchAnswerQuestion> answerQuestionEW = new EntityWrapper<TrResearchAnswerQuestion>(answerQuestion);
List<TrResearchAnswerQuestion> answerQuestions = researchAnswerQuestionMapper.selectList(answerQuestionEW);
// 查出关联问题选项等
TrResearchQuestionOption questionOption = new TrResearchQuestionOption();
questionOption.setResearchId(researchId);
questionOption.setDeleted(0);
EntityWrapper<TrResearchQuestionOption> optionEW = new EntityWrapper<>(questionOption);
optionEW.orderBy("no", true);
List<TrResearchQuestionOption> questionOptions = researchQuestionOptionMapper.selectList(optionEW);
// 查出学员的答案选项
TrResearchAnswerQuestionResult questionResult = new TrResearchAnswerQuestionResult();
questionResult.setAnswerId(answer.getId());
List<TrResearchAnswerQuestionResult> questionResults = researchQuestionResultMapper.selectList(new EntityWrapper<TrResearchAnswerQuestionResult>(questionResult));
// 如果 问题主体集合不为空 and 回答问题不为空 and 学员回答记录不为空
if (!CollectionUtils.isEmpty(questions) && !CollectionUtils.isEmpty(answerQuestions) && !CollectionUtils.isEmpty(questionResults)) {
/* for(TrResearchQuestion q : questions){
getNo(q);
}*/
// 以问题id为key,问题答案为value的map
Map<Long, List<TrResearchQuestionOption>> questionOptionMap = new HashMap<>();
//questionOptions:关联的问题选项(调研id查询出来的)
for (TrResearchQuestionOption option : questionOptions) {
//当map中没有这个题目时,将该题目关联的选项全部添加进这个map
if (questionOptionMap.get(option.getQuestionId()) == null) {
List<TrResearchQuestionOption> list = new ArrayList<>();
list.add(option);
questionOptionMap.put(option.getQuestionId(), list);
} else {
questionOptionMap.get(option.getQuestionId()).add(option);
}
}
// 以问题id为key,问题答案为value的map(answerId查出来的)
Map<Long, List<TrResearchAnswerQuestionResult>> answerResultMap = new HashMap<>();
for (TrResearchAnswerQuestionResult result : questionResults) {
if (answerResultMap.get(result.getAnswerQuestionId()) == null) {
List<TrResearchAnswerQuestionResult> list = new ArrayList<>();
list.add(result);
answerResultMap.put(result.getAnswerQuestionId(), list);
} else {
answerResultMap.get(result.getAnswerQuestionId()).add(result);
}
}
List<TrResearchQuestionOption> optionList = null;
List<TrResearchAnswerQuestionResult> resultList = null;
TrResearchAnswerQuestion raq = null;
//questions:根据researchId 查到的所有问题
List<TrResearchQuestion> questionToReMove = new ArrayList<>(50);
for (TrResearchQuestion q : questions) {
/*questionToReMove.addAll(removeByQuestion(questions,q));*/
ViewAnswerQuestionVo questionVo = new ViewAnswerQuestionVo();
questionVo.setContent(q.getContent());
questionVo.setContentAppendixUrl(q.getContentAppendixUrl());
questionVo.setId(q.getId());
questionVo.setMaxSelectItem(q.getMaxSelectItem());
questionVo.setMinSelectItem(q.getMinSelectItem());
questionVo.setNeedAnswer(q.getNeedAnswer());
questionVo.setNo(q.getNo());
questionVo.setType(q.getType());
questionVo.setOptions(new ArrayList<>());
//answerQuestions 是这个人这个调研的所有问题
// 拿到关联的答案问题
for (TrResearchAnswerQuestion aq : answerQuestions) {
raq = null;
if (questionVo.getId().equals(aq.getQuestionId())) {
//判断根据调研id和answerId查询出来的问题是同一个问题,从而可以比较学员选中的答案。
raq = aq;
break;
}
}
// 判定学员是否回答了这个
if (null != raq) {
// 拿取问题下的选项
optionList = questionOptionMap.get(q.getId());
if (!CollectionUtils.isEmpty(optionList)) {
// 处理 选择题
//1.如果是单选题或者是多选题,学员选项TrResearchAnswerQuestionResult中有OptionId记录正确的选项id
if (q.getType().equals(QuestionType.SINGLE_OPTION_QUESTION.getValue())
|| q.getType().equals(QuestionType.MULTIPLE_OPTION_QUESTION.getValue())) {
//遍历循环根据researchId查询出来的选项
for (TrResearchQuestionOption o : optionList) {
ViewAnswerQuestionOptionVo optionVo = new ViewAnswerQuestionOptionVo();
optionVo.setContent(o.getContent());
optionVo.setCorrect(o.getCorrect());
optionVo.setId(o.getId());
optionVo.setJumpNum(o.getJumpNum());
optionVo.setNo(o.getNo());
//获得学员回答该题目的选项
resultList = answerResultMap.get(raq.getId());
if (!CollectionUtils.isEmpty(resultList)) {
//遍历这些选项
for (TrResearchAnswerQuestionResult r : resultList) {
if (null != r.getOptionId()) {
optionVo.setAnswerChecked(r.getOptionId().equals(optionVo.getId()));
optionVo.setAnswerContent(r.getContent());
if (optionVo.getAnswerChecked()) {
// questionToReMove.addAll(removeByQuestion(questions,optionVo.getJumpNum()));
break;
}
}
}
}
questionVo.getOptions().add(optionVo);
}
}
// 处理 打分题
if (q.getType().equals(QuestionType.POINT_QUESTION.getValue())) {
for (TrResearchQuestionOption o : optionList) {
//循环调研的选项
ViewAnswerQuestionOptionVo optionVo = new ViewAnswerQuestionOptionVo();
optionVo.setContent(o.getContent());
optionVo.setId(o.getId());
optionVo.setNo(o.getNo());
optionVo.setMaxScore(o.getMaxScore());
optionVo.setMinScore(o.getMinScore());
// 获取分数
resultList = answerResultMap.get(raq.getId());
if (!CollectionUtils.isEmpty(resultList)) {
for (TrResearchAnswerQuestionResult r : resultList) {
if (optionVo.getId().equals(r.getOptionId())) {
optionVo.setAnswerScore(r.getScore());
break;
}
}
}
questionVo.getOptions().add(optionVo);
}
}
}
// 处理 问答题
if (q.getType().equals(QuestionType.ASK_ANSWER_QUESTION.getValue())) {
resultList = answerResultMap.get(raq.getId());
if (!CollectionUtils.isEmpty(resultList)) {
questionVo.setAnswerContent(resultList.get(0).getContent());
}
}
answerVo.getAnswerQuestions().add(questionVo);
}
}
List<ViewAnswerQuestionVo> questionVos = answerVo.getAnswerQuestions();
List<ViewAnswerQuestionVo> questionVoList = new ArrayList<>(50);
if (!CollectionUtils.isEmpty(questionVos)) {
for (ViewAnswerQuestionVo vo : questionVos) {
for (TrResearchQuestion q : questionToReMove) {
if (q.getId().equals(vo.getId())) {
questionVoList.add(vo);
}
}
}
}
questionVos.removeAll(questionVoList);
answerVo.setAnswerQuestions(questionVos);
}
viewAnswerVos.add(answerVo);
}
return viewAnswerVos;
}
/**
* 组装TrResearchAnswer
*
* @param answerVo
* @param accountId
* @param companyId
* @param accountName
* @param siteId
* @param orgId
* @param now
* @return
*/
private TrResearchAnswer buildAnswer(AnswerVo answerVo, Long accountId, Long companyId, String accountName, Long siteId, Long orgId, Date now) {
TrResearchAnswer answer = new TrResearchAnswer();
answer.setId(idGenerator.generate());
answer.setAccountId(accountId);
answer.setCompanyId(companyId);
answer.setSiteId(siteId);
answer.setCreateById(accountId);
answer.setCreateByName(accountName);
answer.setCreateTime(now);
answer.setOrgId(orgId);
answer.setFinish(1);
// answer.setName(answerVo.getResearchName());
answer.setResearchId(answerVo.getResearchId());
answer.setTerminalType(answerVo.getTerminalType());
answer.setStartTime(answerVo.getStartTime());
answer.setSubmitTime(now);
answer.setDuration(((int) (answerVo.getSubmitTime().getTime() - answerVo.getStartTime().getTime())) / 1000);
return answer;
}
/**
* 组装答卷问题集合
*
* @param questionVos
* @param answer
* @param accountId
* @param accountName
* @param now
* @return
*/
private List<TrResearchAnswerQuestion> buildAnswerQuestion(List<AnswerQuestionVo> questionVos, TrResearchAnswer answer, Long accountId, String accountName, Date now, List<TrResearchAnswerQuestionResult> questionResults) throws Exception {
List<TrResearchAnswerQuestion> answerQuestionList = null;
if (!CollectionUtils.isEmpty(questionVos)) {
answerQuestionList = new ArrayList<>();
for (AnswerQuestionVo questionVo : questionVos) {
TrResearchAnswerQuestion answerQuestion = new TrResearchAnswerQuestion();
answerQuestion.setId(idGenerator.generate());
answerQuestion.setAnswerId(answer.getId());
answerQuestion.setAccountId(accountId);
answerQuestion.setCreateById(accountId);
answerQuestion.setCreateByName(accountName);
answerQuestion.setCreateTime(now);
answerQuestion.setQuestionId(questionVo.getQuestionId());
answerQuestion.setResearchId(answer.getResearchId());
List<AnswerQuestionItemVo> questionItemVos = questionVo.getQuestionItems();
if (!CollectionUtils.isEmpty(questionItemVos)) {
for (AnswerQuestionItemVo itemVo : questionItemVos) {
TrResearchAnswerQuestionResult result = new TrResearchAnswerQuestionResult();
result.setId(idGenerator.generate());
result.setResearchId(answerQuestion.getResearchId());
result.setAnswerId(answer.getId());
result.setAnswerQuestionId(answerQuestion.getId());
result.setCreateById(accountId);
result.setCreateByName(accountName);
result.setCreateTime(now);
result.setQuestionType(questionVo.getQuestionType());
// 如果是单选题或多选题
if (result.getQuestionType() == QuestionType.SINGLE_OPTION_QUESTION.getValue()
|| result.getQuestionType() == QuestionType.MULTIPLE_OPTION_QUESTION.getValue()) {
result.setOptionId(itemVo.getOptionId());
// 如果有填空
if (!StringUtils.isEmpty(itemVo.getContent())) {
result.setContent(itemVo.getContent());
}
}
// 如果是问答题
else if (result.getQuestionType() == QuestionType.ASK_ANSWER_QUESTION.getValue()) {
result.setContent(itemVo.getContent());
}
// 如果是打分题
else if (result.getQuestionType() == QuestionType.POINT_QUESTION.getValue()) {
result.setOptionId(itemVo.getOptionId());
result.setScore(itemVo.getScore());
} else {
throw new Exception("未知的问题类型,请检查问题类型是否合规!!");
}
// 添加到待入库集合
questionResults.add(result);
}
}
answerQuestionList.add(answerQuestion);
}
}
return answerQuestionList;
}
/**
*
* @param questionList 当前问题列表
* @param researchQuestion 当前问题
* @return 根据问题的跳题策略返回的问题列表
*/
/* public List<TrResearchQuestion> removeByQuestion(List<TrResearchQuestion> questionList,TrResearchQuestion researchQuestion){
List<TrResearchQuestion> questionList1=new ArrayList<TrResearchQuestion>(50);
if(researchQuestion.getJumpType() == 2 && researchQuestion.getJumpNum()!=null){
for(TrResearchQuestion q : questionList){
//去除根据指定跳题规则跳过的题目
if(q.getNo()< researchQuestion.getJumpNum()){
questionList1.add(q);
}
}
}
return questionList1;
}*/
/* public List<TrResearchQuestion> removeByQuestion(List<TrResearchQuestion> questionList,Integer jumpNum){
List<TrResearchQuestion> questionList1=new ArrayList<TrResearchQuestion>(50);
if(jumpNum != null){
for(TrResearchQuestion q : questionList) {
if(q.getNo() < jumpNum){
questionList1.add(q);
}
}
}
return questionList1;
}*/
/**
* 获取指定跳题默认下一题的题号
* @param
* @return
*/
/*public void getNo(TrResearchQuestion researchQuestion) {
List<TrResearchQuestion> questions = trResearchQuestionService.listAllForJump(researchQuestion.getId());
Map<String, Object> map = new HashMap<>(4);
map.put("question_id", researchQuestion.getId());
map.put("deleted", 0);
List<TrResearchQuestionOption> options = researchQuestionOptionMapper.selectByMap(map);
if(!CollectionUtils.isEmpty(questions)){
for (TrResearchQuestion question : questions) {
if ((question.getJumpType() == null || question.getJumpType() == 2) && (question.getJumpNum() == null || question.getJumpNum() == -1)) {
if (researchQuestion.getNo() < question.getNo()) {
researchQuestion.setNo(question.getNo());
}
}
if ((question.getJumpType() == null || question.getJumpType() == 1) && !CollectionUtils.isEmpty(options)) {
for (TrResearchQuestionOption option : options) {
if (option.getJumpNum() == null || option.getJumpNum() == -1) {
if (researchQuestion.getNo() < question.getNo()) {
option.setJumpNum(question.getNo());
}
}
}
}
}
}
}*/
}
package com.yizhi.research.application.service.impl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yizhi.application.orm.id.IdGenerator;
import com.yizhi.research.application.mapper.TrResearchAuthorizeMapper;
import com.yizhi.research.application.service.ITrResearchAuthorizeService;
import com.yizhi.research.application.vo.domain.TrResearchAuthorize;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.List;
/**
* <p>
* 调研用户范围 服务实现类
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@Service
public class TrResearchAuthorizeServiceImpl extends ServiceImpl<TrResearchAuthorizeMapper, TrResearchAuthorize> implements ITrResearchAuthorizeService {
private Logger logger = LoggerFactory.getLogger(TrResearchAuthorizeServiceImpl.class);
@Autowired
private IdGenerator idGenerator;
@Override
@Transactional
public Boolean insertAll(List<TrResearchAuthorize> trResearchAuthorizes) {
if (!CollectionUtils.isEmpty(trResearchAuthorizes)) {
Long researchId = trResearchAuthorizes.get(0).getResearchId();
TrResearchAuthorize trResearchAuthorize = new TrResearchAuthorize();
trResearchAuthorize.setResearchId(researchId);
trResearchAuthorize.setState(1);
EntityWrapper<TrResearchAuthorize> entityWrapper = new EntityWrapper<>(trResearchAuthorize);
this.baseMapper.delete(entityWrapper);
for (TrResearchAuthorize trResearchAuthorize1 : trResearchAuthorizes) {
trResearchAuthorize1.setId(idGenerator.generate());
}
return this.insertBatch(trResearchAuthorizes);
} else {
logger.error("列表为空");
return Boolean.FALSE;
}
}
@Override
public List<TrResearchAuthorize> listTrResearchAuthorize(Long researchId) {
// TODO Auto-generated method stub
TrResearchAuthorize researchAuthorize = new TrResearchAuthorize();
researchAuthorize.setResearchId(researchId);
researchAuthorize.setState(1);//有效
EntityWrapper<TrResearchAuthorize> wrapper=new EntityWrapper<TrResearchAuthorize>(researchAuthorize);
return this.selectList(wrapper);
}
}
package com.yizhi.research.application.service.impl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.yizhi.research.application.mapper.TrResearchQuestionOptionMapper;
import com.yizhi.research.application.service.ITrResearchQuestionOptionService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yizhi.research.application.vo.domain.TrResearchQuestionOption;
import com.yizhi.research.application.vo.manage.OtherOptionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* <p>
* 只对题型是:单选题、多选题和打分题 服务实现类
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@Service
public class TrResearchQuestionOptionServiceImpl extends ServiceImpl<TrResearchQuestionOptionMapper, TrResearchQuestionOption> implements ITrResearchQuestionOptionService {
@Autowired
private TrResearchQuestionOptionMapper trResearchQuestionOptionMapper;
@Override
public List<TrResearchQuestionOption> listAll(Long researchId) {
return trResearchQuestionOptionMapper.listAllByResearchId(researchId);
}
@Override
public Map<String,Object> getOptionByQuestionId(Long id) {
Map<String,Object> map = new HashMap<String, Object>(4);
map.put("question_id",id);
List<TrResearchQuestionOption> options = trResearchQuestionOptionMapper.selectByMap(map);
OtherOptionVo otherOptionVo = null;
List<TrResearchQuestionOption> op = new ArrayList<>(50);
for(TrResearchQuestionOption option :options){
if(option.getJumpNum() == null || option.getJumpNum() == -1){
option.setJumpNum(null);
}
if(option.getIsOther() != null && option.getIsOther() == 1){
op.add(option);
otherOptionVo = new OtherOptionVo();
otherOptionVo.setRequired(option.getRequired());
otherOptionVo.setNo(option.getNo());
otherOptionVo.setJumpNum(option.getJumpNum());
otherOptionVo.setEditable(option.getEditable());
otherOptionVo.setContent(option.getContent());
otherOptionVo.setId(option.getId());
}
}
options.removeAll(op);
map.put("options",options);
map.put("otherOption",otherOptionVo);
return map;
}
}
package com.yizhi.research.application.service.impl;
import com.yizhi.research.application.mapper.TrResearchAnswerQuestionResultMapper;
import com.yizhi.research.application.service.ITrResearchAnswerQuestionResultService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yizhi.research.application.vo.domain.TrResearchAnswerQuestionResult;
import org.springframework.stereotype.Service;
/**
* <p>
* 答案选项 服务实现类
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@Service
public class TrResearchQuestionResultServiceImpl extends ServiceImpl<TrResearchAnswerQuestionResultMapper, TrResearchAnswerQuestionResult> implements ITrResearchAnswerQuestionResultService {
}
package com.yizhi.research.application.service.impl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yizhi.application.orm.id.IdGenerator;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.core.application.event.EventWrapper;
import com.yizhi.core.application.publish.CloudEventPublisher;
import com.yizhi.core.application.task.AbstractTaskHandler;
import com.yizhi.core.application.task.TaskExecutor;
import com.yizhi.research.application.mapper.*;
import com.yizhi.research.application.model.ModifyQuestionModel;
import com.yizhi.research.application.service.ITrResearchQuestionService;
import com.yizhi.research.application.vo.api.AnswerQuestionItemVo;
import com.yizhi.research.application.vo.api.AnswerQuestionVo;
import com.yizhi.research.application.vo.api.MyQuestion;
import com.yizhi.research.application.vo.api.QuestionJumpVo;
import com.yizhi.research.application.vo.domain.*;
import com.yizhi.research.application.vo.manage.OtherOptionVo;
import com.yizhi.util.application.constant.QueueConstant;
import com.yizhi.util.application.constant.TpActivityType;
import com.yizhi.util.application.event.TrainingProjectEvent;
import org.apache.poi.ss.formula.functions.T;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* <p>
* 问题 服务实现类
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@Service
@Transactional
public class TrResearchQuestionServiceImpl extends ServiceImpl<TrResearchQuestionMapper, TrResearchQuestion> implements ITrResearchQuestionService {
@Autowired
private IdGenerator idGenerator;
@Autowired
private TrResearchQuestionMapper researchQuestionMapper;
@Autowired
private TrResearchQuestionOptionMapper researchQuestionOptionMapper;
@Autowired
private TrResearchAnswerMapper trResearchAnswerMapper;
@Autowired
private TrResearchAnswerQuestionMapper trResearchAnswerQuestionMapper;
@Autowired
private ResearchMapper researchMapper;
@Autowired
private TrResearchAnswerQuestionResultMapper trResearchAnswerQuestionResultMapper;
@Autowired
private TaskExecutor taskExecutor;
@Autowired
private CloudEventPublisher cloudEventPublisher;
private static final Logger LOG = LoggerFactory.getLogger(TrResearchQuestionServiceImpl.class);
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Override
public int batchInsert(List<TrResearchQuestion> researchQuestions) {
boolean hasOptions = false;
Map<String, Object> map = new HashMap<String, Object>(4);
List<TrResearchQuestionOption> optionListToInsert = new ArrayList<>();
Integer size = 0;
if (researchQuestions != null) {
TrResearchQuestion rq = researchQuestions.get(0);
if (rq != null) {
Long researchId = rq.getResearchId();
map.put("research_id", researchId);
List<TrResearchQuestion> questions = researchQuestionMapper.selectByMap(map);
size = getMaxNo(questions);
}
} else {
return -1;
}
// 给问题id赋值
for (TrResearchQuestion question : researchQuestions) {
question.setJumpType(2);
question.setId(idGenerator.generate());
question.setDeleted(0);
question.setNo(++size);
// 给问题选项id赋值
List<TrResearchQuestionOption> optionList = question.getOptions();
if (!CollectionUtils.isEmpty(optionList)) {
hasOptions = true;
for (TrResearchQuestionOption option : optionList) {
option.setId(idGenerator.generate());
option.setQuestionId(question.getId());
option.setResearchId(question.getResearchId());
optionListToInsert.add(option);
}
}
}
int num = researchQuestionMapper.batchInsert(researchQuestions);
if (num > 0 && hasOptions) {
researchQuestionOptionMapper.batchInsert(optionListToInsert);
}
return num;
}
@Override
public int batchUpdate(ModifyQuestionModel modifyQuestionModel) throws Exception {
int result = 0;
boolean hasOptions = false;
boolean needChangeNo = false;
TrResearchQuestion questions;
// 删除的
List<Long> ids = modifyQuestionModel.getDeletedIds();
Map<String, Object> map = new HashMap<>(4);
map.put("research_id", modifyQuestionModel.getResearchId());
map.put("deleted", 0);
List<TrResearchQuestion> qs = researchQuestionMapper.selectByMap(map);
TrResearchQuestion q;
QuestionJumpVo vo;
List<Integer> deleteQuestionNo=new ArrayList<Integer>();
if (!CollectionUtils.isEmpty(ids)) {
for (Long id : ids) {
q = researchQuestionMapper.selectById(id);
deleteQuestionNo.add(q.getNo());
for (TrResearchQuestion question : qs) {
List<TrResearchQuestionOption> options = researchQuestionOptionMapper.listAllByQuestionId(question.getId());
if (!CollectionUtils.isEmpty(options)) {
for (TrResearchQuestionOption option : options) {
if (option.getJumpNum() != null && option.getJumpNum().equals(q.getNo())) {
researchQuestionMapper.updateNo(option.getId(), null);
}
}
}
if (question.getJumpType() != null && question.getJumpType() == 2 && q.getNo().equals(question.getJumpNum()) && !question.getId().equals(q.getId())) {
//删除的问题关联跳题
researchQuestionMapper.updateNoById(question.getId(), null);
}
}
}
try {
TrResearchQuestion question = new TrResearchQuestion();
question.setDeleted(0);
question.setResearchId(modifyQuestionModel.getResearchId());
List<TrResearchQuestion> questionList = researchQuestionMapper.selectList(new EntityWrapper<>(question));
TrResearchQuestionOption option = new TrResearchQuestionOption();
option.setDeleted(0);
option.setResearchId(modifyQuestionModel.getResearchId());
List<TrResearchQuestionOption> options = researchQuestionOptionMapper.selectList(new EntityWrapper<>(option));
Map<Long, Integer> optionToQuestion = new HashMap<Long, Integer>();
for (TrResearchQuestionOption o : options) {
TrResearchQuestion question1 = researchQuestionMapper.selectById(o.getQuestionId());
optionToQuestion.put(o.getId(), question1.getNo());
}
//获取选项跳向当前题号的题目
Map<Integer, List<Long>> noToOption = getNoToOptions(options, questionList);
Set<Integer> nos = noToOption.keySet();
//获取当前题号和题目的对应关系
Map<Integer, Long> old = getCurrentQuestion(questionList);
Set<Long> updateQuestions;
//获取题目跳向当前题号的题目
Map<Integer, List<Long>> noToQuestion = getNoToQuestions(questionList);
Set<Integer> ss = noToQuestion.keySet();
List<Long> questionIds;
List<Long> optionIds;
for (Integer no : deleteQuestionNo) {
updateQuestions = new HashSet<>();
for (TrResearchQuestion s : questionList) {
if (no < s.getNo()) {
questionIds = new ArrayList<>();
for(Integer i : ss){
List<Long> questionId = noToQuestion.get(s.getNo());
if(i>=s.getNo() && questionId!=null){
questionIds.addAll(questionId);
}
}
updateQuestions.add(old.get(s.getNo()));
//将这些question 的jumpNum减一
if(!CollectionUtils.isEmpty(questionIds)) {
researchQuestionMapper.updateJumpNum(questionIds);
}
optionIds = new ArrayList<>();
for(Integer i :nos){
List<Long> optionId = noToOption.get(s.getNo());
if(i>=s.getNo() &&optionId!=null){
optionIds.addAll(optionId);
}
}
if(!CollectionUtils.isEmpty(optionIds)) {
researchQuestionOptionMapper.updateJumpNum(optionIds);
}
}
}
//将这questionId的no减一
if(!CollectionUtils.isEmpty(updateQuestions)) {
researchQuestionMapper.updateNos(updateQuestions);
}
}
}catch (Exception e){
System.out.println("删除题目出错");
e.printStackTrace();
LOG.error("",e);
}
}
if (!CollectionUtils.isEmpty(ids)) {
result = researchQuestionMapper.batchDeleteById(ids);
if (result != ids.size()) {
throw new Exception("处理异常:删除的调研问题数目 和 传入的id集合长度 对不上,事务回滚!!");
}
// 删除下面选项
for (Long questionId : ids) {
questions = researchQuestionMapper.selectById(questionId);
if (questions.getType() == 3) {
continue;
}
TrResearchQuestionOption example = new TrResearchQuestionOption();
example.setQuestionId(questionId);
example.setDeleted(0);
List<TrResearchQuestionOption> optionsToDelete = researchQuestionOptionMapper.selectList(new EntityWrapper<TrResearchQuestionOption>(example));
List<Long> optionsToDeleteIds = new ArrayList<Long>();
for (TrResearchQuestionOption option : optionsToDelete) {
optionsToDeleteIds.add(option.getId());
}
if (!CollectionUtils.isEmpty(optionsToDeleteIds)) {
researchQuestionOptionMapper.batchDelete(optionsToDeleteIds, modifyQuestionModel.getDate(), modifyQuestionModel.getRequestContext().getAccountId(), modifyQuestionModel.getRequestContext().getAccountName());
}
}
return result;
// reBuildNo(modifyQuestionModel.getResearchId());
}
// 修改的(包括新增的),参数
List<TrResearchQuestionVo> researchQuestions = modifyQuestionModel.getQuestions();
List<TrResearchQuestion> researchQuestionss = new ArrayList<>();
if (!CollectionUtils.isEmpty(researchQuestions)){
for (TrResearchQuestionVo v:researchQuestions
) {
TrResearchQuestion t=new TrResearchQuestion();
BeanUtils.copyProperties(v,t);
List<TrResearchQuestionOption> list=new ArrayList<>();
if (!CollectionUtils.isEmpty(v.getOptions())){
for (TrResearchQuestionOptionVo tv:v.getOptions()) {
TrResearchQuestionOption to= new TrResearchQuestionOption();
BeanUtils.copyProperties(tv,to);
list.add(to);
}
}
t.setOptions(list);
researchQuestionss.add(t);
}
}
// 将要新增的问题
List<TrResearchQuestion> newQuestions = new ArrayList<>();
// 将要修改的问题
List<TrResearchQuestion> modifyQuestions = new ArrayList<>();
// 将要新增的问题option(修改其实就是删除以前的)
List<TrResearchQuestionOption> newOptions = new ArrayList<>();
// 将要删除选项的问题的id集合
List<Long> questionIdsToDeleteOption = new ArrayList<>();
if (!CollectionUtils.isEmpty(researchQuestions)) {
for (TrResearchQuestion question : researchQuestionss) {
// 新增的
if (null == question.getId()) {
question.setDeleted(0);
question.setId(idGenerator.generate());
}
// 修改的问题
if (question.getId() != null) {
needChangeNo = true;
modifyQuestions.add(question);
questionIdsToDeleteOption.add(question.getId());
}
// 给问题选项id赋值
List<TrResearchQuestionOption> optionList = question.getOptions();
if (!CollectionUtils.isEmpty(optionList)) {
hasOptions = true;
for (TrResearchQuestionOption option : optionList) {
option.setId(idGenerator.generate());
option.setQuestionId(question.getId());
option.setResearchId(question.getResearchId());
newOptions.add(option);
}
}
newQuestions.add(question);
// LOG.info("==========看有没有传值选项list=======:"+question.getOptions().toString());
// LOG.info("=================:"+newOptions.toString());
}
}
// 删除旧选项
EntityWrapper<TrResearchQuestionOption> ew = new EntityWrapper<>();
if (!CollectionUtils.isEmpty(questionIdsToDeleteOption)) {
ew.in("question_id", questionIdsToDeleteOption);
if (!CollectionUtils.isEmpty(newOptions)){
researchQuestionOptionMapper.delete(ew);
}
}
if (!CollectionUtils.isEmpty(newQuestions) && !needChangeNo) {
result += researchQuestionMapper.batchInsert(newQuestions);
}
if (!CollectionUtils.isEmpty(newOptions)) {
researchQuestionOptionMapper.batchInsert(newOptions);
}
if (!CollectionUtils.isEmpty(modifyQuestions) && needChangeNo) {
for (TrResearchQuestion question : modifyQuestions) {
result += researchQuestionMapper.updateById(question);
}
}
// if (needChangeNo) {
// reBuildNo(modifyQuestionModel.getResearchId());
// }
return result;
}
@Override
public List<TrResearchQuestion> listPage(Map<String, Object> map) {
Long researchId = (Long) map.get("researchId");
TrResearchQuestion example = new TrResearchQuestion();
example.setResearchId(researchId);
example.setDeleted(0);
EntityWrapper<TrResearchQuestion> ew = new EntityWrapper<>(example);
ew.orderBy("no", true);
List<TrResearchQuestion> records = researchQuestionMapper.selectList(ew);
OtherOptionVo otherOptionVo = null;
// 组装问题选项
if (!CollectionUtils.isEmpty(records)) {
Integer maxNo = getMaxNo(researchId);
for (TrResearchQuestion question : records) {
Integer has = checkJump(question.getId(), example.getResearchId());
question.setHas(has);
if (question.getJumpType() == 2 && (question.getJumpNum() == null || question.getJumpNum() == -1)) {
question.setJumpNum(null);
}
//调研按选项跳题后,选项按顺序填写(jumpNum = -1时,相当于null)
if (question.getJumpType() == 1 && (question.getJumpNum() == null || question.getJumpNum() == -1)){
question.setJumpNum(null);
}
if (question.getNo().equals(maxNo)) {
question.setIsLast(1);
}
List<TrResearchQuestionOption> options = researchQuestionOptionMapper.listAllByQuestionId(question.getId());
if (options != null) {
for (TrResearchQuestionOption option : options) {
if (question.getJumpType() == 1 && (option.getJumpNum() == null || -1 == option.getJumpNum())) {
option.setJumpNum(null);
}
if (option.getIsOther() != null && option.getIsOther() == 1) {
question.setHasOther(1);
options.remove(option);
otherOptionVo = new OtherOptionVo();
otherOptionVo.setId(option.getId());
otherOptionVo.setJumpNum(option.getJumpNum());
otherOptionVo.setContent(option.getContent());
otherOptionVo.setEditable(option.getEditable());
otherOptionVo.setNo(option.getNo());
otherOptionVo.setRequired(option.getRequired());
question.setOtherOptionVo(otherOptionVo);
break;
}
}
}
question.setOptions(options);
}
}
return records;
}
@Override
public List<TrResearchQuestion> listAll(Long researchId) {
TrResearchQuestion question = new TrResearchQuestion();
question.setResearchId(researchId);
question.setDeleted(0);
EntityWrapper<TrResearchQuestion> ew = new EntityWrapper<>(question);
ew.orderBy("no", true);
List<TrResearchQuestion> questionList = researchQuestionMapper.selectList(ew);
TrResearchQuestionOption option = new TrResearchQuestionOption();
option.setDeleted(0);
option.setResearchId(researchId);
EntityWrapper<TrResearchQuestionOption> ew1 = new EntityWrapper<>(option);
List<TrResearchQuestionOption> optionList = researchQuestionOptionMapper.selectList(ew1);
Research research = researchMapper.selectById(researchId);
// 组装 question questionOption
Map<Long, TrResearchQuestion> map = new HashMap<>();
for (TrResearchQuestion item : questionList) {
item.setResearchName(research.getName());
item.setResearchContent(research.getContent());
if (research.getStartTime() != null) {
item.setStartTime(dateFormat.format(research.getStartTime()));
}
if (research.getEndTime() != null) {
item.setEndTime(dateFormat.format(research.getEndTime()));
}
map.put(item.getId(), item);
// 设置跳过的题号\
if (item.getJumpType() == 2 && item.getJumpNum() != null && item.getJumpNum() != -1) {
item.setJumpedNums(buildJumpedNums(item.getNo(), item.getJumpNum()));
}
}
for (TrResearchQuestionOption item : optionList) {
if (map.get(item.getQuestionId()) != null) {
if (CollectionUtils.isEmpty(map.get(item.getQuestionId()).getOptions())) {
map.get(item.getQuestionId()).setOptions(new ArrayList<TrResearchQuestionOption>());
}
map.get(item.getQuestionId()).getOptions().add(item);
}
// 设置跳过的题号
if (item.getJumpNum() != null && item.getJumpNum() != -1) {
item.setJumpedNums(buildJumpedNums(map.get(item.getQuestionId()).getNo(), item.getJumpNum()));
}
}
return questionList;
}
@Override
public List<TrResearchQuestion> listAllForJump(Long questionId) {
TrResearchQuestion trResearchQuestion = researchQuestionMapper.selectById(questionId);
if (trResearchQuestion != null) {
return researchQuestionMapper.listAllForJump(trResearchQuestion.getNo(), trResearchQuestion.getResearchId());
}
return null;
}
/**
* 重置题号
*
* @param
*/
// private void reBuildNo(Long researchId) {
// // 按题号顺序查出所有未删除的
// TrResearchQuestion researchQuestion = new TrResearchQuestion();
// researchQuestion.setResearchId(researchId);
// researchQuestion.setDeleted(0);
// EntityWrapper<TrResearchQuestion> ew = new EntityWrapper(researchQuestion);
// ew.orderBy("no", true);
// List<TrResearchQuestion> allQuestions = researchQuestionMapper.selectList(ew);
//
// if (!CollectionUtils.isEmpty(allQuestions)) {
// for (int i = 0; i < allQuestions.size(); i++) {
// TrResearchQuestion temp = new TrResearchQuestion();
// temp.setId(allQuestions.get(i).getId());
// temp.setNo(i + 1);
// researchQuestionMapper.updateById(temp);
// }
// }
// }
@Transactional
@Override
public MyQuestion lastAndNext(MyQuestion myQuestion) {
RequestContext context = myQuestion.getContext();
Research research = researchMapper.selectById(myQuestion.getResearchId());
Map<String, Object> map = new HashMap<String, Object>();
//返回给前端的题目
TrResearchQuestion trResearchQuestion = new TrResearchQuestion();
TrResearchAnswer trResearchAnswer = null;
AnswerQuestionVo answerQuestionVo = myQuestion.getAnswerQuestionVo();
Integer isFrist = 0;
try {
//第一次答题没有answerQuestionVo,删除记录
if (answerQuestionVo == null) {
isFrist = 1;
trResearchAnswerMapper.deleteAnswer(myQuestion.getResearchId(), context.getAccountId());
Map<String, Object> deleteQuestionMap = new HashMap<String, Object>(4);
deleteQuestionMap.put("account_id", context.getAccountId());
deleteQuestionMap.put("research_id", myQuestion.getResearchId());
trResearchAnswerQuestionMapper.deleteByMap(deleteQuestionMap);
}
//先根据调研id以及用户id 查询是否有回答记录,如果没有就添加一条记录
trResearchAnswer = new TrResearchAnswer();
trResearchAnswer.setResearchId(myQuestion.getResearchId());
trResearchAnswer.setAccountId(context.getAccountId());
trResearchAnswer.setFinish(0);
trResearchAnswer = trResearchAnswerMapper.selectOne(trResearchAnswer);
} catch (Exception e) {
LOG.error("查询answer表记录出错", e);
return null;
}
try {
if (trResearchAnswer == null) {
trResearchAnswer = new TrResearchAnswer();
trResearchAnswer.setResearchId(myQuestion.getResearchId());
trResearchAnswer.setId(idGenerator.generate());
trResearchAnswer.setName(research.getName());
trResearchAnswer.setAccountId(context.getAccountId());
trResearchAnswer.setStartTime(myQuestion.getStartDate());
trResearchAnswer.setTerminalType(myQuestion.getTerminaltype());
trResearchAnswer.setCompanyId(context.getCompanyId());
trResearchAnswer.setSiteId(context.getSiteId());
trResearchAnswer.setOrgId(context.getOrgId());
trResearchAnswer.setCreateById(context.getAccountId());
trResearchAnswer.setCreateTime(new Date());
trResearchAnswer.setCreateByName(context.getAccountName());
trResearchAnswerMapper.insert(trResearchAnswer);
}
} catch (Exception e) {
e.printStackTrace();
LOG.error("插入TrResearchAnswer记录报错------------", e);
return null;
}
/* //当前题目的题号
Integer nextNo = 0;
//上一题和首次不需要删除旧的答案
if(myQuestion.getNum() == null &&myQuestion.getAnswerQuestionVo()!= null && 1 != myQuestion.getAnswerQuestionVo().getIsLast()){
nextNo = getNextNo(answerQuestionVo);
Integer nowNo = researchQuestionMapper.selectById(myQuestion.getAnswerQuestionVo().getQuestionId()).getNo();
//判断以前的答案中是否有下一题是该题目
Integer lastNo = getlastNo(myQuestion.getResearchId(), nextNo, context.getAccountId());
TrResearchQuestion re = researchQuestionMapper.selectOneByNo(lastNo, myQuestion.getResearchId());
if ( lastNo != 0 && !lastNo.equals(nowNo)) {
//满足条件删除
TrResearchAnswerQuestion answerQuestion = new TrResearchAnswerQuestion();
answerQuestion.setAccountId(context.getAccountId());
answerQuestion.setQuestionId(re.getId());
EntityWrapper<TrResearchAnswerQuestion> wrapper = new EntityWrapper<TrResearchAnswerQuestion>(answerQuestion);
answerQuestion = trResearchAnswerQuestionMapper.selectOne(answerQuestion);
if(answerQuestion != null) {
trResearchAnswerQuestionMapper.delete(wrapper);
Map<String, Object> op = new HashMap<String, Object>(3);
op.put("answer_question_id", answerQuestion.getId());
trResearchAnswerQuestionResultMapper.deleteByMap(op);
}
}
}*/
//无论下一题或者提交都需要保存当前题目的答案,第一次,上一题进入则跳过
if (answerQuestionVo != null && answerQuestionVo.getQuestionItems() != null) {
Long questionId = answerQuestionVo.getQuestionId();
TrResearchQuestion question = researchQuestionMapper.selectById(questionId);
TrResearchAnswerQuestion trResearchAnswerQuestion = new TrResearchAnswerQuestion();
try {
trResearchAnswerQuestion.setResearchId(myQuestion.getResearchId());
trResearchAnswerQuestion.setQuestionId(questionId);
trResearchAnswerQuestion.setAccountId(context.getAccountId());
trResearchAnswerQuestion = trResearchAnswerQuestionMapper.selectOne(trResearchAnswerQuestion);
//1.插入tr_research_answer_question
if (trResearchAnswerQuestion == null) {
trResearchAnswerQuestion = new TrResearchAnswerQuestion();
trResearchAnswerQuestion.setResearchId(myQuestion.getResearchId());
trResearchAnswerQuestion.setQuestionId(questionId);
trResearchAnswerQuestion.setAccountId(context.getAccountId());
trResearchAnswerQuestion.setId(idGenerator.generate());
trResearchAnswerQuestion.setAnswerId(trResearchAnswer.getId());
trResearchAnswerQuestion.setCreateById(context.getAccountId());
trResearchAnswerQuestion.setCreateByName(context.getAccountName());
trResearchAnswerQuestion.setCreateTime(new Date());
trResearchAnswerQuestionMapper.insert(trResearchAnswerQuestion);
} else {
//2.更新
trResearchAnswerQuestion.setUpdateById(context.getAccountId());
trResearchAnswerQuestion.setUpdateByName(context.getAccountName());
trResearchAnswerQuestion.setUpdateTime(new Date());
trResearchAnswerQuestionMapper.updateById(trResearchAnswerQuestion);
}
} catch (Exception e) {
e.printStackTrace();
LOG.error("更新或者插入TrResearchAnswerQuestion出错------------", e);
return null;
}
try {
List<AnswerQuestionItemVo> itemVos = answerQuestionVo.getQuestionItems();
if (!CollectionUtils.isEmpty(itemVos)) {
List<TrResearchAnswerQuestionResult> trResearchAnswerQuestionResults = new ArrayList<TrResearchAnswerQuestionResult>();
TrResearchAnswerQuestionResult result;
map.put("answer_question_id", trResearchAnswerQuestion.getId());
trResearchAnswerQuestionResultMapper.deleteByMap(map);
for (AnswerQuestionItemVo itemVo : itemVos) {
result = new TrResearchAnswerQuestionResult();
result.setId(idGenerator.generate());
result.setAnswerQuestionId(trResearchAnswerQuestion.getId());
result.setAnswerId(trResearchAnswer.getId());
result.setQuestionType(question.getType());
result.setContent(itemVo.getContent());
result.setOptionId(itemVo.getOptionId());
result.setScore(itemVo.getScore());
result.setResearchId(myQuestion.getResearchId());
result.setCreateById(context.getAccountId());
result.setCreateByName(context.getAccountName());
result.setCreateTime(new Date());
trResearchAnswerQuestionResults.add(result);
}
if (!CollectionUtils.isEmpty(trResearchAnswerQuestionResults)) {
trResearchAnswerQuestionResultMapper.batchInsert(trResearchAnswerQuestionResults);
}
}
} catch (Exception e) {
e.printStackTrace();
LOG.error("更新或者插入tr_research_answer_question_result出错------", e);
return null;
}
//提交
try {
//肯定存在trResearchAnswer, 更新
if (answerQuestionVo.getIsLast() == 1) {
trResearchAnswer.setFinish(1);
trResearchAnswer.setSubmitTime(new Date());
//trResearchAnswer.setSubmitTime(myQuestion.getEndDate());
//trResearchAnswer.setDuration(((int) (myQuestion.getEndDate().getTime() - trResearchAnswer.getStartTime().getTime())) / 1000);
trResearchAnswerMapper.updateById(trResearchAnswer);
// 向培训项目发送消息,告知业务已经完成
EventWrapper<TrainingProjectEvent> eventWrapper = new EventWrapper<TrainingProjectEvent>(myQuestion.getResearchId(), TrainingProjectEvent.getInstance(myQuestion.getResearchId(), TpActivityType.TYPE_RESEARCH, context.getAccountId(), new Date(), context.getSiteId()));
LOG.info("向培训项目发送消息,告知业务已经完成:{}", eventWrapper);
taskExecutor.asynExecute(new AbstractTaskHandler() {
@Override
public void handle() {
try {
cloudEventPublisher.publish(QueueConstant.TRAINING_PROJECT_EVENT_QUEUE, eventWrapper);
} catch (Exception e) {
e.printStackTrace();
}
}
});
return myQuestion;
}
} catch (Exception e) {
e.printStackTrace();
LOG.error("提交调研出错-----------", e);
return null;
}
}
try {
//返回问题给前端,根据问题编号
trResearchQuestion = new TrResearchQuestion();
if (answerQuestionVo == null) {
trResearchQuestion.setNo(getMinNo(myQuestion.getResearchId()));
} else {
//返回下一题
if (myQuestion.getNum() == null) {
trResearchQuestion.setNo(getNextNo(answerQuestionVo));
} else {
trResearchQuestion.setNo(myQuestion.getNum());
}
}
trResearchQuestion.setDeleted(0);
trResearchQuestion.setResearchId(myQuestion.getResearchId());
trResearchQuestion = researchQuestionMapper.selectOne(trResearchQuestion);
if (trResearchQuestion == null) {
LOG.info("没有找到下一个或上一个题目-------------");
return null;
}
/*trResearchQuestion.setLastNo(getlastNo(trResearchQuestion.getResearchId(),trResearchQuestion.getNo(),context.getAccountId()));*/
trResearchQuestion.setIsFrist(isFrist);
Integer minNo = getMinNo(myQuestion.getResearchId());
if (minNo != null && trResearchQuestion.getNo().equals(minNo)) {
trResearchQuestion.setRemark(research.getContent());
}
if (getMaxNo(myQuestion.getResearchId()) != null && trResearchQuestion.getNo().equals(getMaxNo(myQuestion.getResearchId()))) {
trResearchQuestion.setIsLast(1);
}
TrResearchQuestionOption option = new TrResearchQuestionOption();
option.setQuestionId(trResearchQuestion.getId());
option.setDeleted(0);
List<TrResearchQuestionOption> options = researchQuestionOptionMapper.selectList(new EntityWrapper<TrResearchQuestionOption>(option));
if (!CollectionUtils.isEmpty(options)) {
for (TrResearchQuestionOption option1 : options) {
if (option1.getIsOther() != null && option1.getIsOther() == 1 && option1.getRequired() != null && option1.getRequired() == 1) {
trResearchQuestion.setRequired(1);
}
}
}
trResearchQuestion.setOptions(options);
myQuestion = new MyQuestion();
//返回题目中,学员可能回答过
TrResearchAnswerQuestion trResearchAnswerQuestion = new TrResearchAnswerQuestion();
trResearchAnswerQuestion.setQuestionId(trResearchQuestion.getId());
trResearchAnswerQuestion.setAccountId(context.getAccountId());
trResearchAnswerQuestion = trResearchAnswerQuestionMapper.selectOne(trResearchAnswerQuestion);
List<TrResearchQuestionOption> answerOptions = new ArrayList<>();
if (trResearchAnswerQuestion != null) {
answerQuestionVo = new AnswerQuestionVo();
answerQuestionVo.setAnswerQuestionId(trResearchAnswerQuestion.getId());
answerQuestionVo.setQuestionId(trResearchQuestion.getId());
answerQuestionVo.setQuestionType(trResearchQuestion.getType());
map = new HashMap<String, Object>(6);
map.put("answer_question_id", trResearchAnswerQuestion.getId());
List<TrResearchAnswerQuestionResult> trResearchAnswerQuestionResults = trResearchAnswerQuestionResultMapper.selectByMap(map);
if (!CollectionUtils.isEmpty(options)) {
for (TrResearchQuestionOption option1 : options) {
if (!CollectionUtils.isEmpty(trResearchAnswerQuestionResults)) {
for (TrResearchAnswerQuestionResult result : trResearchAnswerQuestionResults) {
//单选多选打分
if (option1.getId().equals(result.getOptionId())) {
option1.setCheck(1);
option1.setAnswerScore(result.getScore());
option1.setAnswerContent(result.getContent());
break;
}
}
}
answerOptions.add(option1);
}
} else {
TrResearchQuestionOption answer = new TrResearchQuestionOption();
if (!CollectionUtils.isEmpty(trResearchAnswerQuestionResults)) {
answer.setAnswerContent(trResearchAnswerQuestionResults.get(0).getContent());
}
answerOptions.add(answer);
}
}
if (!CollectionUtils.isEmpty(answerOptions)) {
trResearchQuestion.setOptions(answerOptions);
}
TrResearchQuestionVo trResearchQuestionVo=new TrResearchQuestionVo();
BeanUtils.copyProperties(trResearchQuestion,trResearchQuestionVo);
myQuestion.setQuestion(trResearchQuestionVo);
return myQuestion;
} catch (Exception e) {
e.printStackTrace();
LOG.error("返回试题过程中发生错误--------", e);
return null;
}
}
@Override
public Integer updateQuestionJump(QuestionJumpVo vo) {
RequestContext context = vo.getContext();
List<TrResearchQuestionOptionVo> options = vo.getOptions();
Long questionId = vo.getQuestionId();
Integer jumpNo = vo.getJumpNo();
Integer type = vo.getType();
Date date = new Date();
Integer num = 0;
try {
if (type == 1 && !CollectionUtils.isEmpty(options)) {
for (TrResearchQuestionOptionVo option : options) {
if (option.getJumpNum() == null) {
option.setJumpNum(-1);
}
option.setUpdateById(context.getAccountId());
option.setUpdateByName(context.getAccountName());
option.setUpdateTime(date);
TrResearchQuestionOption p=new TrResearchQuestionOption();
BeanUtils.copyProperties(option,p);
researchQuestionOptionMapper.updateById(p);
}
}
TrResearchQuestion question = new TrResearchQuestion();
question.setId(questionId);
if (type == 2 && jumpNo == null) {
question.setJumpNum(-1);
} else {
question.setJumpNum(jumpNo);
}
question.setJumpType(type);
question.setUpdateById(context.getAccountId());
question.setUpdateByName(context.getAccountName());
question.setUpdateTime(date);
num = researchQuestionMapper.updateById(question);
} catch (Exception e) {
e.printStackTrace();
LOG.error("更新跳题策略失败", e);
}
return num;
}
@Override
public List<Long> getFinishedAccountIds(Long researchId, Long companyId, Long siteId) {
return researchQuestionMapper.getFinishedAccountIds(researchId, companyId, siteId);
}
public Integer checkJump(Long id, Long researchId) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("research_id", researchId);
map.put("deleted", 0);
TrResearchQuestion researchQuestion = researchQuestionMapper.selectById(id);
List<TrResearchQuestion> questions = researchQuestionMapper.selectByMap(map);
List<TrResearchQuestionOption> options = researchQuestionOptionMapper.selectByMap(map);
TrResearchQuestion q;
if (researchQuestion != null && !CollectionUtils.isEmpty(questions)) {
for (TrResearchQuestion question : questions) {
if (question.getJumpType() == 2 && question.getJumpNum() != null && question.getJumpNum().equals(researchQuestion.getNo()) && !question.getId().equals(id)) {
return 1;
}
}
if (!CollectionUtils.isEmpty(options)) {
for (TrResearchQuestionOption option : options) {
q = researchQuestionMapper.selectById(option.getQuestionId());
if (q.getJumpType() == 1 && option.getJumpNum() != null && option.getJumpNum().equals(researchQuestion.getNo())) {
return 1;
}
}
}
}
return 0;
}
public Integer getNextNo(AnswerQuestionVo answerQuestionVo) {
Long questionId = answerQuestionVo.getQuestionId();
TrResearchQuestion question = researchQuestionMapper.selectById(questionId);
if (question.getJumpType() != null) {
if (question.getJumpType() == 2 && question.getJumpNum() != null && question.getJumpNum() != -1) {
return question.getJumpNum();
} else {
List<AnswerQuestionItemVo> vo = answerQuestionVo.getQuestionItems();
if (!CollectionUtils.isEmpty(vo)) {
for (AnswerQuestionItemVo item : vo) {
if (item.getOptionId() != null) {
TrResearchQuestionOption option = researchQuestionOptionMapper.selectById(item.getOptionId());
if (option.getJumpNum() != null && option.getJumpNum() != -1) {
return option.getJumpNum();
}
}
}
}
}
}
TrResearchQuestion q = new TrResearchQuestion();
q.setResearchId(question.getResearchId());
q.setDeleted(0);
EntityWrapper<TrResearchQuestion> wrapper = new EntityWrapper<TrResearchQuestion>(q);
wrapper.orderBy("no", true);
List<TrResearchQuestion> questions = researchQuestionMapper.selectList(wrapper);
for (TrResearchQuestion question1 : questions) {
if (question1.getNo() > question.getNo()) {
return question1.getNo();
}
}
return question.getNo();
}
public Integer getMinNo(Long researchId) {
TrResearchQuestion question = new TrResearchQuestion();
question.setResearchId(researchId);
question.setDeleted(0);
EntityWrapper<TrResearchQuestion> wrapper = new EntityWrapper<TrResearchQuestion>(question);
wrapper.orderBy("no", true);
List<TrResearchQuestion> questions = researchQuestionMapper.selectList(wrapper);
if (!CollectionUtils.isEmpty(questions)) {
question = questions.get(0);
return question.getNo();
}
return null;
}
public Integer getMaxNo(Long researchId) {
TrResearchQuestion question = new TrResearchQuestion();
question.setResearchId(researchId);
question.setDeleted(0);
EntityWrapper<TrResearchQuestion> wrapper = new EntityWrapper<TrResearchQuestion>(question);
wrapper.orderBy("no", true);
List<TrResearchQuestion> questions = researchQuestionMapper.selectList(wrapper);
if (!CollectionUtils.isEmpty(questions)) {
Integer index = questions.size() - 1;
question = questions.get(index);
return question.getNo();
}
return null;
}
/*public Integer getlastNo(Long researchId,Integer no,Long accountId){
List<TrResearchQuestion> questions = trResearchAnswerQuestionMapper.selectListByAnswer(researchId,accountId);
if(!CollectionUtils.isEmpty(questions)){
for(TrResearchQuestion question : questions){
if(question.getJumpType() != null &&question.getJumpType()==2 && question.getJumpNum()!= null && question.getJumpNum() .equals(no)){
return question.getNo();
}
}
}
TrResearchAnswer answer = new TrResearchAnswer();
answer.setResearchId(researchId);
answer.setAccountId(accountId);
answer.setFinish(0);
answer = trResearchAnswerMapper.selectOne(answer);
if(answer == null){
return 0;
}
List<TrResearchQuestionOption> options = researchQuestionOptionMapper.selectByAnswer(answer.getId());
if(!CollectionUtils.isEmpty(options)){
for(TrResearchQuestionOption option :options){
if(option.getJumpNum()!=null && option.getJumpNum() .equals(no)){
return researchQuestionMapper.selectByOptionId(option.getId());
}
}
}
TrResearchQuestion question = new TrResearchQuestion();
question.setResearchId(researchId);
question.setDeleted(0);
EntityWrapper<TrResearchQuestion> wrapper = new EntityWrapper<TrResearchQuestion>(question);
wrapper.orderBy("no",false);
List<TrResearchQuestion> questionList = researchQuestionMapper.selectList(wrapper);
if(!CollectionUtils.isEmpty(questionList)){
for(TrResearchQuestion question1 :questionList){
if(question1.getNo()<no){
return question1.getNo();
}
}
}
return 0;
}*/
/*public void deleteAnswer(Integer startNo , Integer endNo, Long accountId, Long researchId){
List<Long> questionIds = researchQuestionMapper.selectQuestion(startNo,endNo,researchId);
List<Long> answerQuestionId = trResearchAnswerQuestionMapper.selectAnswerQuestionId(startNo,endNo,accountId);
}*/
private Integer[] buildJumpedNums(Integer current, Integer dest) {
if (null == current || null == dest) {
return null;
}
if (current > dest) {
int temp = dest;
dest = current;
current = temp;
}
Integer[] arrs = new Integer[dest - current - 1];
for (int i = 1; i + current < dest; i++) {
arrs[i - 1] = current + i;
}
System.out.println(Arrays.toString(arrs));
return arrs;
}
private Integer getMaxNo(List<TrResearchQuestion> questions) {
if (CollectionUtils.isEmpty(questions)) {
return 0;
} else {
int maxNo = 0;
TrResearchQuestion question;
for (int i = 0; i < questions.size(); i++) {
question = questions.get(i);
if (question != null && question.getDeleted() == 0 && maxNo < question.getNo()) {
maxNo = question.getNo();
}
}
return maxNo;
}
}
//获取当前题号和题目的对应关系
public Map<Integer,Long> getCurrentQuestion(List<TrResearchQuestion> questions){
Map<Integer ,Long> noToQuestion = new HashMap<Integer, Long>();
for(TrResearchQuestion question :questions){
noToQuestion.put(question.getNo(),question.getId());
}
return noToQuestion;
}
//获取题目跳向当前题号的题目
public Map<Integer,List<Long>> getNoToQuestions(List<TrResearchQuestion> questions){
Map<Integer,List<Long>> noToQuestions =new HashMap<Integer, List<Long>>();
Integer no ;
List<Long> questionIds;
for(TrResearchQuestion question :questions){
no = question.getNo();
for(TrResearchQuestion q : questions){
if((q.getJumpType() == 2 && no.equals(q.getJumpNum()))){
if(noToQuestions.get(no) == null){
questionIds = new ArrayList<Long>();
}else{
questionIds = noToQuestions.get(no);
}
questionIds.add(q.getId());
noToQuestions.put(no,questionIds);
}
}
}
return noToQuestions;
}
//获取选项跳向当前题号的题目
public Map<Integer,List<Long>> getNoToOptions(List<TrResearchQuestionOption> options,List<TrResearchQuestion> questions){
Map<Integer,List<Long>> noToOptions = new HashMap<Integer, List<Long>>();
Integer no;
List<Long> optionIds;
// Integer qno;
for(TrResearchQuestion question :questions) {
no = question.getNo();
for(TrResearchQuestionOption option : options){
// qno = optionToQuestion.get(option.getId());
if(no.equals(option.getJumpNum())){
if(noToOptions.get(no) == null){
optionIds = new ArrayList<Long>();
}else{
optionIds = noToOptions.get(no);
}
optionIds.add(option.getId());
noToOptions.put(no,optionIds);
}
}
}
return noToOptions;
}
}
package com.yizhi.research.application.service.impl;
import com.yizhi.research.application.mapper.TrResearchRemindMapper;
import com.yizhi.research.application.service.ITrResearchRemindService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yizhi.research.application.vo.domain.TrResearchRemind;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author shengchenglong123
* @since 2018-03-14
*/
@Service
public class TrResearchRemindServiceImpl extends ServiceImpl<TrResearchRemindMapper, TrResearchRemind> implements ITrResearchRemindService {
}
package com.yizhi.research.application.util;
import com.alibaba.fastjson.JSON;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.core.application.event.EventWrapper;
import com.yizhi.core.application.publish.CloudEventPublisher;
import com.yizhi.message.application.constans.Constans;
import com.yizhi.message.application.enums.RelationType;
import com.yizhi.research.application.eum.ResearchState;
import com.yizhi.research.application.vo.EvenType;
import com.yizhi.message.application.vo.MessageRemindVo;
import com.yizhi.message.application.vo.TaskVo;
import com.yizhi.research.application.vo.MessageTaskRemindVo;
import com.yizhi.research.application.vo.domain.Research;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
public class ResearchEvenSendMessage {
@Autowired
private CloudEventPublisher cloudEventPublisher;
private Logger logger = LoggerFactory.getLogger(ResearchEvenSendMessage.class);
/**
* 触发事件,根据可见范围发消息
*
* @param research 业务参数对象
* @param accountId 用户id为空
*/
public void evenSendMessage(Research research, Long accountId, EvenType evenType) {
if (research != null) {
TaskVo taskVo = new TaskVo();
taskVo.setTaskName(research.getName());
MessageRemindVo vo = new MessageRemindVo();
vo.setVisibleRange(research.getVisibleRange());
vo.setMessageId(evenType.getKey());
vo.setMessageType(3);
vo.setRelationId(research.getId());
vo.setRelationType(RelationType.DY.getKey());
vo.setSendType(1);
vo.setTaskVo(taskVo);
//定时任务默认五分钟执行一次 这里默认6分钟
vo.setSendTime(DateUtils.addMinutes(new Date(), 6));
if (accountId != null) {
vo.setAccountId(accountId);
}
RequestContext requestContext = new RequestContext();
requestContext.setCompanyId(research.getCompanyId());
requestContext.setSiteId(research.getSiteId());
requestContext.setAccountId(research.getCreateById());
requestContext.setAccountName(research.getCreateByName());
vo.setRequestContext(requestContext);
try {
//临时取消触发功能
// cloudEventPublisher.publish(Constans.MESSAGE_QUEUE, new EventWrapper<MessageRemindVo>(null, vo));
} catch (Exception e) {
e.printStackTrace();
logger.error("发送消息失败=====================", e);
}
}
}
/**
* 系统模板,发消息
*
* @param research 业务参数对象
*/
public void systemSendMessage(Research research, com.yizhi.research.application.vo.MessageRemindVo remindVo, RequestContext context) {
MessageRemindVo vo = new MessageRemindVo();
//共用参数
vo.setRelationType(RelationType.DY.getKey());
if (context == null) {
context = new RequestContext();
context.setCompanyId(research.getCompanyId());
context.setSiteId(research.getSiteId());
context.setAccountName(research.getCreateByName());
context.setAccountId(research.getCreateById());
}
vo.setRequestContext(context);
vo.setRelationId(research.getId());
vo.setMessageType(2);
if (remindVo != null) {
logger.info("messageRemindVo:" + JSON.toJSONString(remindVo));
}else {
logger.info("未设置各个业务的提醒服务");
}
if (null != remindVo && null != remindVo.getIsCopy() && remindVo.getIsCopy()) {
vo.setIsCopy(remindVo.getIsCopy());
vo.setOldRelationId(remindVo.getOldRelationId());
cloudEventPublisher.publish(Constans.MESSAGE_QUEUE, new EventWrapper<MessageRemindVo>(null, vo));
logger.error("发送复制消息成功=====================");
return;
}
if (vo.getMessageType() == null || vo.getRelationId() == null || vo.getRelationType() == null) {
logger.info("messageType:" + remindVo.getMessageType() + "||" + "RelationId:" + remindVo.getRelationId()
+ "||" + "RelationType:" + remindVo.getRelationType());
logger.info("相关参数缺失!!");
return;
}
if (null != remindVo.getHasDeleted() && remindVo.getHasDeleted()) {
vo.setHasDeleted(remindVo.getHasDeleted());
cloudEventPublisher.publish(Constans.MESSAGE_QUEUE, new EventWrapper<MessageRemindVo>(null, vo));
logger.error("发送删除消息成功=====================");
} else {
//修改调研的状态
if (remindVo.getTaskStatusUpdate()) {
//1 为消息业务可发送状态 0 则不行
vo.setTaskStatusUpdate(true);
vo.setTaskStatus(research.getState() == ResearchState.RELEASED.getValue() ? 1 : 0);
cloudEventPublisher.publish(Constans.MESSAGE_QUEUE, new EventWrapper<MessageRemindVo>(null, vo));
logger.info("发送修改业务状态消息成功=====================");
return;
}
if (research != null) {
if (!CollectionUtils.isEmpty(remindVo.getMessageTaskRemindVos())) {
TaskVo taskVo = new TaskVo();
taskVo.setTaskName(research.getName());
taskVo.setTaskStratTime(research.getStartTime());
taskVo.setTaskEndTime(research.getEndTime());
vo.setMessageId(remindVo.getMessageId());
vo.setIsChangge(remindVo.getIsChangge());
List<MessageTaskRemindVo> m= remindVo.getMessageTaskRemindVos();
List<com.yizhi.message.application.vo.MessageTaskRemindVo> m2=new ArrayList<>();
for (MessageTaskRemindVo m1:m
) {
com.yizhi.message.application.vo.MessageTaskRemindVo mx=new com.yizhi.message.application.vo.MessageTaskRemindVo();
BeanUtils.copyProperties(m1,mx);
m2.add(mx);
}
vo.setMessageTaskRemindVos(m2);
vo.setSendType(remindVo.getSendType());
vo.setVisibleRange(research.getVisibleRange());
vo.setTaskStatus(research.getState() == ResearchState.RELEASED.getValue() ? 1 : 0);
vo.setTaskVo(taskVo);
try {
if (vo.getMessageId() == null || vo.getSendType() == null || vo.getVisibleRange() == null) {
logger.info("messageID:" + remindVo.getMessageId() + "||" + "sendType:" + remindVo.getSendType()
+ "||" + "VisibleRange:" + remindVo.getVisibleRange());
logger.info("相关参数缺失!!!!!");
return;
}
cloudEventPublisher.publish(Constans.MESSAGE_QUEUE, new EventWrapper<MessageRemindVo>(null, vo));
logger.info("发送消息成功=====================");
} catch (Exception e) {
e.printStackTrace();
logger.error("发送消息失败=====================", e);
}
}
}
}
}
}
package com.yizhi.research.application.util;
import org.springframework.stereotype.Component;
@Component
public class WorkUtil {
/**
* 使sheet名字符合规则
* @param sheetName
* @return
*/
public String chechPattonPattern(String sheetName){
if (sheetName.contains("/")||sheetName.contains("\\")||sheetName.contains("?")||sheetName.contains("*")
||sheetName.contains("[")||sheetName.contains("]")||sheetName.contains(":")){
sheetName = sheetName.replace("?","_").replace("/","_")
.replace("\\","_").replace("*","_")
.replace("[","_").replace("]","_")
.replace(":","_");
}
return sheetName;
}
}
package com.yizhi.research.application.vo.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import com.yizhi.research.application.vo.MessageRemindVo;
import com.yizhi.research.application.vo.manage.RemindVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* <p>
* 调研
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@Data
@Api(tags = "Research", description = "调研")
@TableName("research")
public class Research extends Model<Research> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "调研主键ID,主键")
@TableId("id")
private Long id;
@ApiModelProperty(value = "培训项目ID")
@TableField("training_project_id")
private Long trainingProjectId;
@ApiModelProperty(value = "调研编码,系统将自动生成调研编码;编码规则,按创建顺序累加,例如DY000001,DY000002")
@TableField("research_no")
private String researchNo;
@ApiModelProperty(value = "积分,默认0")
@TableField("point")
private Integer point;
@ApiModelProperty(value = "提醒设置,0否 1是,默认0")
@TableField("remind")
private Integer remind;
@ApiModelProperty(value = "开启邮件提醒(0:否,1是,默认否)")
@TableField("enable_mail_remind")
private Integer enableMailRemind;
@ApiModelProperty(value = "邮件提醒,模板id")
@TableField("mail_template_id")
private Long mailTemplateId;
@ApiModelProperty(value = "开启站内提醒(0:否,1是,默认否)")
@TableField("enable_app_remind")
private Integer enableAppRemind;
@ApiModelProperty(value = "站内消息提醒模板id")
@TableField("app_template_id")
private Long appTemplateId;
@ApiModelProperty(value = "调研名称")
@TableField("name")
private String name;
@ApiModelProperty(value = "开始时间")
@TableField("start_time")
private Date startTime;
@ApiModelProperty(value = "结束时间")
@TableField("end_time")
private Date endTime;
@ApiModelProperty(value = "可见范围,1平台用户可见(企业下所有人员) 2指定学员可见")
@TableField("visible_range")
private Integer visibleRange;
@ApiModelProperty(value = "调研说明")
@TableField("content")
private String content;
@ApiModelProperty(value = "调研备注")
@TableField("remark")
private String remark;
@ApiModelProperty(value = "状态,0草稿 1上架 2下架")
@TableField("state")
private Integer state;
@ApiModelProperty(value = "删除状态:0未删,1已删(默认0)")
@TableField("deleted")
private Integer deleted;
@ApiModelProperty(value = "创建时间")
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
@ApiModelProperty(value = "创建人ID")
@TableField(value = "create_by_id", fill = FieldFill.INSERT)
private Long createById;
@ApiModelProperty(value = "创建人姓名")
@TableField(value = "create_by_name", fill = FieldFill.INSERT)
private String createByName;
@ApiModelProperty(value = "修改时间")
@TableField(value = "update_time", fill = FieldFill.INSERT)
private Date updateTime;
@ApiModelProperty(value = "修改人ID")
@TableField(value = "update_by_id", fill = FieldFill.INSERT)
private Long updateById;
@ApiModelProperty(value = "修改人姓名")
@TableField(value = "update_by_name", fill = FieldFill.INSERT)
private String updateByName;
@ApiModelProperty(value = "下架时间")
@TableField("un_release_time")
private Date unReleaseTime;
@ApiModelProperty(value = "下架人ID")
@TableField("un_release_by_id")
private Long unReleaseById;
@ApiModelProperty(value = "下架人姓名")
@TableField("un_release_by_name")
private String unReleaseByName;
@ApiModelProperty(value = "发布时间")
@TableField("release_time")
private Date releaseTime;
@ApiModelProperty(value = "发布人ID")
@TableField("release_by_id")
private Long releaseById;
@ApiModelProperty(value = "发布人姓名")
@TableField("release_by_name")
private String releaseByName;
@ApiModelProperty(value = "企业_ID")
@TableField("company_id")
private Long companyId;
@ApiModelProperty(value = "部门_ID")
@TableField("org_id")
private Long orgId;
@ApiModelProperty(value = "站点_ID")
@TableField("site_id")
private Long siteId;
/**
* 该调研可参加人数
*/
@ApiModelProperty(value = "可参加人数")
@TableField(exist = false)
private Integer count;
/**
* 实际参加人数
*/
@ApiModelProperty(value = "实际参加人数")
@TableField(exist = false)
private Integer realCount;
/**
* 提醒集合,不持久化
*/
@ApiModelProperty(value = "消息提醒")
@TableField(exist = false)
private List<TrResearchRemind> reminds;
/**
* 关联人员集合
*/
@ApiModelProperty(value = "关联人员")
@TableField(exist = false)
private List<TrResearchAuthorize> authorizes;
@ApiModelProperty(value = "关联人员id")
@TableField(exist = false)
private List<Long> relationIds;
/**
* 问题集合,不持久化
*/
@ApiModelProperty(value = "消息提醒")
@TableField(exist = false)
private List<TrResearchQuestion> questions;
@ApiModelProperty(value = "改调研的答卷")
@TableField(exist = false)
private List<TrResearchAnswer> trResearchAnswers;
@ApiModelProperty(value = "搜索列表显示状态:1已完成,2进行中,3已过期")
@TableField(exist = false)
private Integer finishState;
@ApiModelProperty(value = "完成时间")
@TableField(exist = false)
private Date finishTime;
@ApiModelProperty(value = "各个业务设置提醒时的数据")
@TableField(exist = false)
private MessageRemindVo messageRemindVo;
@ApiModelProperty(value = "关键字,逗号分隔")
@TableField("keywords")
private String keywords;
@ApiModelProperty(value = "提醒vo")
@TableField(exist = false)
private RemindVo remindVo;
@ApiModelProperty(value = "是否启用在日历任务中显示")
@TableField("enable_task")
private Integer enableTask;
@ApiModelProperty(value = "调研logo")
private String image;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.research.application.vo.domain;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
@Data
@Api(tags = "StatisticsResearch", description = "")
@TableName("statistics_research_metadata")
public class StatisticsResearch {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键")
@TableId(value="id", type= IdType.AUTO)
private Long id;
@ApiModelProperty(value = "调研ID")
@TableField("research_id")
private Long researchId;
@ApiModelProperty(value = "调研编码")
@TableField("research_no")
private String researchNo;
@ApiModelProperty(value = "调研名称")
@TableField("research_name")
private String researchName;
@ApiModelProperty(value = "调研开始时间")
@TableField("research_start_time")
private Date researchStartTime;
@ApiModelProperty(value = "调研结束时间")
@TableField("research_end_time")
private Date researchEndTime;
@ApiModelProperty(value = "创建调研的企业ID")
@TableField("research_company_id")
private Long researchCompanyId;
@ApiModelProperty(value = "创建调研的站点ID")
@TableField("research_site_id")
private Long researchSiteId;
@ApiModelProperty(value = "创建调研的组织ID")
@TableField("research_org_id")
private Long researchOrgId;
@ApiModelProperty(value = "调研创建时间")
@TableField("research_create_time")
private Date researchCreateTime;
@ApiModelProperty(value = "用户ID")
@TableField("account_id")
private Long accountId;
@ApiModelProperty(value = "用户名")
@TableField("account_name")
private String accountName;
@ApiModelProperty(value = "用户姓名")
@TableField("account_fullname")
private String accountFullName;
@ApiModelProperty(value = "用户状态")
@TableField("account_state")
private Integer accountState;
@ApiModelProperty(value = "工号")
@TableField("account_work_num")
private String accountWorkNum;
@ApiModelProperty(value = "学员企业ID")
@TableField("account_company_id")
private Long accountCompanyId;
@ApiModelProperty(value = "学员企业ID")
@TableField("account_site_id")
private Long accountSiteId;
@ApiModelProperty(value = "学员组织ID")
@TableField("account_org_id")
private Long accountOrgId;
@ApiModelProperty(value = "所在部门")
@TableField("org_name")
private String orgName;
@ApiModelProperty(value = "部门所有父节点名称")
@TableField("org_parent_names")
private String orgParentNames;
@ApiModelProperty(value = "应参加状态,1应参加 0不应参加(用于统计:应参加人数,MAX取值)")
@TableField("can_state")
private Integer canState;
@ApiModelProperty(value = "应参加人数")
@TableField(exist = false)
private Integer canStateCount;
@ApiModelProperty(value = "实际参加状态,1参加 0未参加(用于统计:实参加人数,MAX取值)")
@TableField("join_state")
private Integer joinState;
@ApiModelProperty(value = "实际参加人数")
@TableField(exist = false)
private Integer joinStateCount;
@ApiModelProperty(value = "调研完成时间")
@TableField(exist = false)
private Date finishTime;
@ApiModelProperty(value = "调研序号")
@TableField(exist = false)
private Integer index;
}
package com.yizhi.research.application.vo.domain;
import com.baomidou.mybatisplus.annotations.TableName;
import io.swagger.annotations.Api;
import lombok.Data;
@Data
@Api(tags = "StatisticsResearchLearn", description = "调研明细")
@TableName("statistics_research_learn_metadata")
public class StatisticsResearchLearn extends StatisticsResearch{
private static final long serialVersionUID = -1170397195805248674L;
}
package com.yizhi.research.application.vo.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* <p>
* 答卷
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@Data
@Api(tags = "TrResearchAnswer", description = "答卷")
@TableName("tr_research_answer")
public class TrResearchAnswer extends Model<TrResearchAnswer> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "答卷ID,主键")
@TableId("id")
private Long id;
@ApiModelProperty(value = "调研主键_ID,外键")
@TableField("research_id")
private Long researchId;
@ApiModelProperty(value = "调研名称")
@TableField("name")
private String name;
@ApiModelProperty(value = "学员_ID")
@TableField("account_id")
private Long accountId;
@ApiModelProperty(value = "开始时间,用户进入考试的时间")
@TableField("start_time")
private Date startTime;
@ApiModelProperty(value = "提交时间")
@TableField("submit_time")
private Date submitTime;
@ApiModelProperty(value = "调研用时,分钟")
@TableField("duration")
private Integer duration;
@ApiModelProperty(value = "调研终端类型,1微信 2PC 3APP")
@TableField("terminal_type")
private Integer terminalType;
@ApiModelProperty(value = "创建时间")
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
@ApiModelProperty(value = "创建人ID")
@TableField(value = "create_by_id", fill = FieldFill.INSERT)
private Long createById;
@ApiModelProperty(value = "创建人姓名")
@TableField(value = "create_by_name", fill = FieldFill.INSERT)
private String createByName;
@ApiModelProperty(value = "修改时间")
@TableField(value = "update_time", fill = FieldFill.INSERT)
private Date updateTime;
@ApiModelProperty(value = "修改人ID")
@TableField(value = "update_by_id", fill = FieldFill.INSERT)
private Long updateById;
@ApiModelProperty(value = "修改人姓名")
@TableField(value = "update_by_name", fill = FieldFill.INSERT)
private String updateByName;
@ApiModelProperty(value = "企业_ID")
@TableField("company_id")
private Long companyId;
@ApiModelProperty(value = "部门_ID")
@TableField("org_id")
private Long orgId;
@ApiModelProperty(value = "站点_ID")
@TableField("site_id")
private Long siteId;
@ApiModelProperty(value = "是否完成 1:已完成(默认) 0:未完成 2:已删除")
@TableField("finish")
private Integer finish;
@ApiModelProperty(value = "该调研答卷下关联的问题,不持久化")
@TableField(exist = false)
private List<TrResearchAnswerQuestion> answerQuestions;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.research.application.vo.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* <p>
* 答案题目
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@Data
@Api(tags = "TrResearchAnswerQuestion", description = "答案题目")
@TableName("tr_research_answer_question")
public class TrResearchAnswerQuestion extends Model<TrResearchAnswerQuestion> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "答卷题目ID,主键")
@TableId("id")
private Long id;
@ApiModelProperty(value = "冗余调研id")
@TableId("research_id")
private Long researchId;
@ApiModelProperty(value = "答卷_ID,外键")
@TableField("answer_id")
private Long answerId;
@ApiModelProperty(value = "问题_ID,外键")
@TableField("question_id")
private Long questionId;
@ApiModelProperty(value = "学员_ID")
@TableField("account_id")
private Long accountId;
@ApiModelProperty(value = "创建时间")
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
@ApiModelProperty(value = "创建人ID")
@TableField(value = "create_by_id", fill = FieldFill.INSERT)
private Long createById;
@ApiModelProperty(value = "创建人姓名")
@TableField(value = "create_by_name", fill = FieldFill.INSERT)
private String createByName;
@ApiModelProperty(value = "修改时间")
@TableField(value = "update_time", fill = FieldFill.INSERT)
private Date updateTime;
@ApiModelProperty(value = "修改人ID")
@TableField(value = "update_by_id", fill = FieldFill.INSERT)
private Long updateById;
@ApiModelProperty(value = "修改人姓名")
@TableField(value = "update_by_name", fill = FieldFill.INSERT)
private String updateByName;
@ApiModelProperty(value = "问题答案集合,不持久化")
@TableField(exist = false)
private List<TrResearchAnswerQuestionResult> questionResults;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.research.application.vo.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 答案选项
* </p>
*
* @author shengchenglong123
* @since 2018-03-19
*/
@Data
@Api(tags = "TrResearchQuestionResult", description = "答案选项")
@TableName("tr_research_answer_question_result")
public class TrResearchAnswerQuestionResult extends Model<TrResearchAnswerQuestionResult> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "答案ID,主键")
@TableId("id")
private Long id;
@ApiModelProperty(value = "冗余调研id")
@TableField("research_id")
private Long researchId;
@ApiModelProperty(value = "冗余answerId")
@TableField("answer_id")
private Long answerId;
@ApiModelProperty(value = "答案题目_ID,外键")
@TableField("answer_question_id")
private Long answerQuestionId;
@ApiModelProperty(value = "问题类型,1单选题、2多选题、3问答题、4打分题")
@TableField("question_type")
private Integer questionType;
@ApiModelProperty(value = "单选题和多选题,存放问题选中选项的ID")
@TableField("option_id")
private Long optionId;
@ApiModelProperty(value = "问答题,存放回答内容(question_type=3)")
@TableField("content")
private String content;
@ApiModelProperty(value = "打分题,学员给的分值")
@TableField("score")
private Integer score;
@ApiModelProperty(value = "创建时间")
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
@ApiModelProperty(value = "创建人ID")
@TableField(value = "create_by_id", fill = FieldFill.INSERT)
private Long createById;
@ApiModelProperty(value = "创建人姓名")
@TableField(value = "create_by_name", fill = FieldFill.INSERT)
private String createByName;
@ApiModelProperty(value = "修改时间")
@TableField(value = "update_time", fill = FieldFill.INSERT)
private Date updateTime;
@ApiModelProperty(value = "修改人ID")
@TableField(value = "update_by_id", fill = FieldFill.INSERT)
private Long updateById;
@ApiModelProperty(value = "修改人姓名")
@TableField(value = "update_by_name", fill = FieldFill.INSERT)
private String updateByName;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.research.application.vo.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableLogic;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 调研用户范围
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@Data
@Api(tags = "TrResearchAuthorize", description = "调研用户范围")
@TableName("tr_research_authorize")
public class TrResearchAuthorize extends Model<TrResearchAuthorize> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键")
@TableId("id")
private Long id;
@ApiModelProperty(value = "调研主键_ID,外键")
@TableField("research_id")
private Long researchId;
@ApiModelProperty(value = "1. 部门,2.用户,3.用户组")
@TableField("type")
private Integer type;
@ApiModelProperty(value = "关联id,类型由type判定")
@TableField("relation_id")
private Long relationId;
@ApiModelProperty(value = "所属站点id")
@TableField("site_id")
private Long siteId;
@ApiModelProperty(value = "状态,0删除 1有效(默认有效)")
@TableLogic
private Integer state;
@ApiModelProperty(value = "关联人员名称")
@TableField(value = "name")
private String name;
@ApiModelProperty(value = "创建时间")
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
@ApiModelProperty(value = "创建人ID")
@TableField(value = "create_by_id", fill = FieldFill.INSERT)
private Long createById;
@ApiModelProperty(value = "创建人姓名")
@TableField(value = "create_by_name", fill = FieldFill.INSERT)
private String createByName;
@ApiModelProperty(value = "修改时间")
@TableField(value = "update_time", fill = FieldFill.INSERT)
private Date updateTime;
@ApiModelProperty(value = "修改人ID")
@TableField(value = "update_by_id", fill = FieldFill.INSERT)
private Long updateById;
@ApiModelProperty(value = "修改人姓名")
@TableField(value = "update_by_name", fill = FieldFill.INSERT)
private String updateByName;
@ApiModelProperty(value = "用户名")
@TableField(exist = false)
private String fullName;
@ApiModelProperty(value = "工号")
@TableField(exist = false)
private String workNum;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.research.application.vo.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import com.yizhi.research.application.vo.manage.OtherOptionVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* <p>
* 问题
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@Data
@Api(tags = "TrResearchQuestion", description = "问题")
@TableName("tr_research_question")
public class TrResearchQuestion extends Model<TrResearchQuestion> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "问题主键ID,主键")
@TableId("id")
private Long id;
@ApiModelProperty(value = "调研主键_ID,外键")
@TableField("research_id")
private Long researchId;
@ApiModelProperty(value = "问题类型,1单选题、2多选题、3问答题、4打分题")
@TableField("type")
private Integer type;
@ApiModelProperty(value = "问题内容")
@TableField("content")
private String content;
@ApiModelProperty(value = "是否是重新进入 1是")
@TableField( exist = false)
private Integer isFrist =0;
@ApiModelProperty(value = "是否是最后一题 1是")
@TableField(exist = false)
private Integer isLast =0;
@ApiModelProperty(value = "调研说明,只有第一题有")
@TableField(exist = false)
private String remark;
@ApiModelProperty(value = "存放附件路径,附件格式:音频、视频、图片")
@TableField("content_appendix_url")
private String contentAppendixUrl;
@ApiModelProperty(value = "是否必答,0非必答 1必答,默认0")
@TableField("need_answer")
private Integer needAnswer;
@ApiModelProperty(value = "多选题:最多选择几项,0不选中 >0选中,默认0")
@TableField("max_select_item")
private Integer maxSelectItem;
@ApiModelProperty(value = "多选题:最少选择几项,0不选中 >0选中,默认0")
@TableField("min_select_item")
private Integer minSelectItem;
@ApiModelProperty(value = "最低分值(打分题有效),只对打分题有效")
@TableField("min_score")
private Integer minScore;
@ApiModelProperty(value = "最高分值(打分题有效),只对打分题有效")
@TableField("max_score")
private Integer maxScore;
@ApiModelProperty(value = "题号,不能为空")
@TableField("no")
private Integer no;
@ApiModelProperty(value = "是否跳题(单选题需要),0不支持 1支持,默认0(需求改变,这个字段无意义)")
@TableField("jumpable")
private Integer jumpable;
@ApiModelProperty(value = "问题跳题的类型,1表示根据选项跳题,2表示指定跳题")
@TableField("jump_type")
private Integer jumpType;
@ApiModelProperty(value = "跳转的题目题号,指定跳题时才有效")
@TableField("jump_num")
private Integer jumpNum;
@ApiModelProperty(value = "指定跳题时才有效,越过的题号")
@TableField(exist = false)
private Integer[] jumpedNums;
@ApiModelProperty(value = "上一题的题号")
@TableField(exist = false)
private Integer lastNo;
@ApiModelProperty(value = "是否删除(0:未删,1:已删)")
@TableField("deleted")
private Integer deleted;
@ApiModelProperty(value = "创建时间")
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
@ApiModelProperty(value = "创建人ID")
@TableField(value = "create_by_id", fill = FieldFill.INSERT)
private Long createById;
@ApiModelProperty(value = "创建人姓名")
@TableField(value = "create_by_name", fill = FieldFill.INSERT)
private String createByName;
@ApiModelProperty(value = "修改时间")
@TableField(value = "update_time", fill = FieldFill.INSERT)
private Date updateTime;
@ApiModelProperty(value = "修改人ID")
@TableField(value = "update_by_id", fill = FieldFill.INSERT)
private Long updateById;
@ApiModelProperty(value = "修改人姓名")
@TableField(value = "update_by_name", fill = FieldFill.INSERT)
private String updateByName;
@ApiModelProperty(value = "企业_ID")
@TableField("company_id")
private Long companyId;
@ApiModelProperty(value = "部门_ID")
@TableField("org_id")
private Long orgId;
@ApiModelProperty(value = "站点_ID")
@TableField("site_id")
private Long siteId;
/**
* 选择题,打分题 选项,不持久化
*/
@TableField(exist = false)
private List<TrResearchQuestionOption> options;
@ApiModelProperty("是否有题目的跳题是该题目 0没有 1有")
@TableField(exist = false)
private Integer has;
@TableField(exist = false)
private OtherOptionVo otherOptionVo;
@TableField(exist = false)
private Integer hasOther = 0;
@ApiModelProperty(value = "其他选项input框是否必填")
@TableField(exist = false)
private Integer required = 0;
@ApiModelProperty(value = "调研名称")
@TableField(exist = false)
private String researchName;
@ApiModelProperty(value = "调研开始时间")
@TableField(exist = false)
private String startTime;
@ApiModelProperty(value = "调研结束时间")
@TableField(exist = false)
private String endTime;
@ApiModelProperty(value = "调研说明")
@TableField(exist = false)
private String researchContent;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.research.application.vo.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 只对题型是:单选题、多选题和打分题
* </p>
*
* @author shengchenglong
* @since 2018-03-12
*/
@Data
@Api(tags = "TrResearchQuestionOption", description = "只对题型是:单选题、多选题和打分题")
@TableName("tr_research_question_option")
public class TrResearchQuestionOption extends Model<TrResearchQuestionOption> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "选项ID主键")
@TableId("id")
private Long id;
@ApiModelProperty(value = "所属调研,冗余字段")
@TableField("research_id")
private Long researchId;
@ApiModelProperty(value = "问题主键_ID,外键")
@TableField("question_id")
private Long questionId;
@ApiModelProperty(value = "问题类型,1单选题、2多选题、3问答题、4打分题")
@TableField("question_type")
private Integer questionType;
@ApiModelProperty(value = "选项排序,不能为空")
@TableField("no")
private Integer no;
@ApiModelProperty(value = "允许填空,对单选和多选有效,0不允许 1允许,默认0")
@TableField("editable")
private Integer editable;
@ApiModelProperty(value = "是否是必填 0 不是 1是")
@TableField("required")
private Integer required;
@ApiModelProperty(value = "是否是其他选项 0不是 1 是")
@TableField("isOther")
private Integer isOther;
@ApiModelProperty(value = "选项内容,最多支持输入500汉字")
@TableField("content")
private String content;
@ApiModelProperty(value = "最低分值(打分题有效),只对打分题有效")
@TableField("min_score")
private Integer minScore;
@ApiModelProperty(value = "最高分值(打分题有效),只对打分题有效")
@TableField("max_score")
private Integer maxScore;
@ApiModelProperty(value = "跳题题号(单选题有效),问题设置了跳题才有效,大于当前题号")
@TableField("jump_num")
private Integer jumpNum;
@ApiModelProperty(value = "指定跳题时才有效,越过的题号")
@TableField(exist = false)
private Integer[] jumpedNums;
@ApiModelProperty(value = "是否正确答案(选择题有效),0不是 1是默认不是")
@TableField("correct")
private Integer correct;
@ApiModelProperty(value = "是否删除(0:未删,1:已删)")
@TableField("deleted")
private Integer deleted;
@ApiModelProperty(value = "创建时间")
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
@ApiModelProperty(value = "创建人ID")
@TableField(value = "create_by_id", fill = FieldFill.INSERT)
private Long createById;
@ApiModelProperty(value = "创建人姓名")
@TableField(value = "create_by_name", fill = FieldFill.INSERT)
private String createByName;
@ApiModelProperty(value = "修改时间")
@TableField(value = "update_time", fill = FieldFill.INSERT)
private Date updateTime;
@ApiModelProperty(value = "修改人ID")
@TableField(value = "update_by_id", fill = FieldFill.INSERT)
private Long updateById;
@ApiModelProperty(value = "修改人姓名")
@TableField(value = "update_by_name", fill = FieldFill.INSERT)
private String updateByName;
@ApiModelProperty(value = "是否被选中 1选中,0没有选中")
@TableField(exist = false)
private Integer check = 0;
@ApiModelProperty(value = "问答题 回答内容")
@TableField(exist = false)
private String answerContent;
@ApiModelProperty(value = "打分题 分数")
@TableField(exist = false)
private Integer answerScore;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.research.application.vo.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 提醒时间
* </p>
*
* @author shengchenglong123
* @since 2018-03-14
*/
@Data
@Api(tags = "TrResearchRemind", description = "提醒时间")
@TableName("tr_research_remind")
public class TrResearchRemind extends Model<TrResearchRemind> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键id")
@TableId("id")
private Long id;
@ApiModelProperty(value = "关联调研id")
@TableField("research_id")
private Long researchId;
@ApiModelProperty(value = "1:开始之前,2:开始之后,3:自定义时间")
@TableField("type")
private Integer type;
@ApiModelProperty(value = "type=1或type=2:相差秒数")
@TableField("seconds")
private Long seconds;
@ApiModelProperty(value = "是否删除(0:未删,1:已删)")
@TableField("deleted")
private Integer deleted;
@ApiModelProperty(value = "提醒时间")
@TableField("time")
private Date time;
@ApiModelProperty(value = "创建时间")
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
@ApiModelProperty(value = "创建人ID")
@TableField(value = "create_by_id", fill = FieldFill.INSERT)
private Long createById;
@ApiModelProperty(value = "创建人姓名")
@TableField(value = "create_by_name", fill = FieldFill.INSERT)
private String createByName;
@Override
protected Serializable pkVal() {
return this.id;
}
}
server.port=34003
spring.application.name=research
ACTIVE=${spring.profiles.active}
spring.profiles.active=sit
# nacos
spring.cloud.nacos.config.shared-dataids=common-${spring.profiles.active}.properties
spring.cloud.nacos.config.namespace=${spring.profiles.active}
spring.cloud.nacos.config.prefix=${spring.application.name}
spring.cloud.nacos.config.file-extension=properties
spring.cloud.nacos.config.server-addr=192.168.1.13:3333,192.168.1.24:4444,192.168.1.38:5555
\ No newline at end of file
package com.yizhi.research.application;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}
package com.yizhi.research.application;
import com.yizhi.research.application.service.IResearchService;
import com.yizhi.research.application.service.ITrResearchQuestionService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
/**
* @Author: shengchenglong
* @Date: 2018/4/16 14:32
*/
@SpringBootTest
@RunWith(SpringRunner.class)
public class ResearchTest {
@Autowired
private IResearchService researchService;
@Autowired
private ITrResearchQuestionService researchQuestionService;
@Test
public void test() {
// BaseModel<PageVo> model = new BaseModel<>();
// PageVo v = new PageVo();
// v.setState(1);
// v.setPageSize(10);
// v.setPageNo(1);
// v.setDate(new Date());
//
// RequestContext rc = new RequestContext();
// rc.setSiteId(1L);
// rc.setOrgId(21L);
// rc.setAccountId(21L);
// rc.setCompanyId(973114334463066112L);
//
// model.setContext(rc);
// model.setObj(v);
// model.setDate(new Date());986484201379811328
//
// researchService.apiListPage(model);
List list = researchQuestionService.listAllForJump(986484201379811328L);
System.out.println(list.size());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.yizhi</groupId>
<artifactId>wmy-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath/>
</parent>
<groupId>com.yizhi</groupId>
<artifactId>cloud-research</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>cloud-research-api</module>
<module>cloud-research-service</module>
</modules>
<packaging>pom</packaging>
<repositories>
<repository>
<id>wmy4.0</id>
<url>http://mvn.km365.pw/nexus/content/groups/wmy4.0-group/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment