Browse Source

优化报表误差

java110 2 years ago
parent
commit
4b8e9025dd

+ 31 - 0
java110-bean/src/main/java/com/java110/dto/questionAnswer/QuestionAnswerDto.java

@@ -1,9 +1,11 @@
 package com.java110.dto.questionAnswer;
 
 import com.java110.dto.PageDto;
+import com.java110.dto.questionTitleValue.QuestionTitleValueDto;
 
 import java.io.Serializable;
 import java.util.Date;
+import java.util.List;
 
 /**
  * @ClassName FloorDto
@@ -31,6 +33,11 @@ public class QuestionAnswerDto extends PageDto implements Serializable {
 
     private String statusCd = "0";
 
+    private long voteCount; // 总投票人数
+
+    private long votedCount; // 已投票人数
+
+    private List<QuestionTitleValueDto> titleValues;
 
     public String getQaName() {
         return qaName;
@@ -112,4 +119,28 @@ public class QuestionAnswerDto extends PageDto implements Serializable {
     public void setStatusCd(String statusCd) {
         this.statusCd = statusCd;
     }
+
+    public List<QuestionTitleValueDto> getTitleValues() {
+        return titleValues;
+    }
+
+    public void setTitleValues(List<QuestionTitleValueDto> titleValues) {
+        this.titleValues = titleValues;
+    }
+
+    public long getVoteCount() {
+        return voteCount;
+    }
+
+    public void setVoteCount(long voteCount) {
+        this.voteCount = voteCount;
+    }
+
+    public long getVotedCount() {
+        return votedCount;
+    }
+
+    public void setVotedCount(long votedCount) {
+        this.votedCount = votedCount;
+    }
 }

+ 33 - 0
java110-bean/src/main/java/com/java110/dto/questionTitleValue/QuestionTitleValueDto.java

@@ -4,6 +4,7 @@ import com.java110.dto.PageDto;
 
 import java.io.Serializable;
 import java.util.Date;
+import java.util.List;
 
 /**
  * @ClassName FloorDto
@@ -30,6 +31,12 @@ public class QuestionTitleValueDto extends PageDto implements Serializable {
 
     private String statusCd = "0";
 
+    private String qaId;
+    private String[] qaIds;
+
+    private int personCount;
+
+
 
     public String getScore() {
         return score;
@@ -103,4 +110,30 @@ public class QuestionTitleValueDto extends PageDto implements Serializable {
     public void setTitleIds(String[] titleIds) {
         this.titleIds = titleIds;
     }
+
+    public String getQaId() {
+        return qaId;
+    }
+
+    public void setQaId(String qaId) {
+        this.qaId = qaId;
+    }
+
+    public int getPersonCount() {
+        return personCount;
+    }
+
+    public void setPersonCount(int personCount) {
+        this.personCount = personCount;
+    }
+
+    public String[] getQaIds() {
+        return qaIds;
+    }
+
+    public void setQaIds(String[] qaIds) {
+        this.qaIds = qaIds;
+    }
+
+
 }

+ 104 - 104
java110-db/src/main/resources/mapper/user/QuestionAnswerV1ServiceDaoImplMapper.xml

@@ -5,129 +5,129 @@
 <mapper namespace="questionAnswerV1ServiceDaoImpl">
 
 
-
-
-
     <!-- 保存问卷投票信息 add by wuxw 2018-07-03 -->
     <insert id="saveQuestionAnswerInfo" parameterType="Map">
         insert into question_answer(
-qa_name,qa_type,start_time,remark,end_time,community_id,content,qa_id
-) values (
-#{qaName},#{qaType},#{startTime},#{remark},#{endTime},#{communityId},#{content},#{qaId}
-)
+        qa_name,qa_type,start_time,remark,end_time,community_id,content,qa_id
+        ) values (
+        #{qaName},#{qaType},#{startTime},#{remark},#{endTime},#{communityId},#{content},#{qaId}
+        )
     </insert>
 
 
-
     <!-- 查询问卷投票信息 add by wuxw 2018-07-03 -->
     <select id="getQuestionAnswerInfo" parameterType="Map" resultType="Map">
-        select  t.qa_name,t.qa_name qaName,t.qa_type,t.qa_type qaType,t.start_time,t.start_time startTime,t.remark,t.status_cd,t.status_cd statusCd,t.end_time,t.end_time endTime,t.community_id,t.community_id communityId,t.content,t.qa_id,t.qa_id qaId 
-from question_answer t 
-where 1 =1 
-<if test="qaName !=null and qaName != ''">
-   and t.qa_name= #{qaName}
-</if> 
-<if test="qaType !=null and qaType != ''">
-   and t.qa_type= #{qaType}
-</if> 
-<if test="startTime !=null and startTime != ''">
-   and t.start_time= #{startTime}
-</if> 
-<if test="remark !=null and remark != ''">
-   and t.remark= #{remark}
-</if> 
-<if test="statusCd !=null and statusCd != ''">
-   and t.status_cd= #{statusCd}
-</if> 
-<if test="endTime !=null and endTime != ''">
-   and t.end_time= #{endTime}
-</if> 
-<if test="communityId !=null and communityId != ''">
-   and t.community_id= #{communityId}
-</if> 
-<if test="content !=null and content != ''">
-   and t.content= #{content}
-</if> 
-<if test="qaId !=null and qaId != ''">
-   and t.qa_id= #{qaId}
-</if> 
-order by t.create_time desc
-<if test="page != -1 and page != null ">
-   limit #{page}, #{row}
-</if> 
+        select t.qa_name,t.qa_name qaName,t.qa_type,t.qa_type qaType,t.start_time,t.start_time
+        startTime,t.remark,t.status_cd,t.status_cd statusCd,t.end_time,t.end_time endTime,t.community_id,t.community_id
+        communityId,t.content,t.qa_id,t.qa_id qaId,t.create_time createTime,count(uqa1.user_qa_id) voteCount,count(uqa2.user_qa_id) votedCount
+        from question_answer t
+        left join user_question_answer uqa1 on t.qa_id = uqa1.qa_id and uqa1.status_cd = '0'
+        left join user_question_answer uqa2 on t.qa_id = uqa2.qa_id and uqa2.status_cd = '0' and uqa2.state = '1202'
+        where 1 =1
+        <if test="qaName !=null and qaName != ''">
+            and t.qa_name= #{qaName}
+        </if>
+        <if test="qaType !=null and qaType != ''">
+            and t.qa_type= #{qaType}
+        </if>
+        <if test="startTime !=null and startTime != ''">
+            and t.start_time= #{startTime}
+        </if>
+        <if test="remark !=null and remark != ''">
+            and t.remark= #{remark}
+        </if>
+        <if test="statusCd !=null and statusCd != ''">
+            and t.status_cd= #{statusCd}
+        </if>
+        <if test="endTime !=null and endTime != ''">
+            and t.end_time= #{endTime}
+        </if>
+        <if test="communityId !=null and communityId != ''">
+            and t.community_id= #{communityId}
+        </if>
+        <if test="content !=null and content != ''">
+            and t.content= #{content}
+        </if>
+        <if test="qaId !=null and qaId != ''">
+            and t.qa_id= #{qaId}
+        </if>
+        group by t.qa_name,t.qa_type,t.start_time,t.remark,t.status_cd,t.end_time,t.community_id,t.content,t.qa_id,t.create_time
+        order by t.create_time desc
+        <if test="page != -1 and page != null ">
+            limit #{page}, #{row}
+        </if>
 
     </select>
 
 
-
-
     <!-- 修改问卷投票信息 add by wuxw 2018-07-03 -->
     <update id="updateQuestionAnswerInfo" parameterType="Map">
-        update  question_answer t set t.status_cd = #{statusCd}
-<if test="newBId != null and newBId != ''">
-,t.b_id = #{newBId}
-</if> 
-<if test="qaName !=null and qaName != ''">
-, t.qa_name= #{qaName}
-</if> 
-<if test="qaType !=null and qaType != ''">
-, t.qa_type= #{qaType}
-</if> 
-<if test="startTime !=null and startTime != ''">
-, t.start_time= #{startTime}
-</if> 
-<if test="remark !=null and remark != ''">
-, t.remark= #{remark}
-</if> 
-<if test="endTime !=null and endTime != ''">
-, t.end_time= #{endTime}
-</if> 
-<if test="communityId !=null and communityId != ''">
-, t.community_id= #{communityId}
-</if> 
-<if test="content !=null and content != ''">
-, t.content= #{content}
-</if> 
- where 1=1 <if test="qaId !=null and qaId != ''">
-and t.qa_id= #{qaId}
-</if> 
+        update question_answer t set t.status_cd = #{statusCd}
+        <if test="newBId != null and newBId != ''">
+            ,t.b_id = #{newBId}
+        </if>
+        <if test="qaName !=null and qaName != ''">
+            , t.qa_name= #{qaName}
+        </if>
+        <if test="qaType !=null and qaType != ''">
+            , t.qa_type= #{qaType}
+        </if>
+        <if test="startTime !=null and startTime != ''">
+            , t.start_time= #{startTime}
+        </if>
+        <if test="remark !=null and remark != ''">
+            , t.remark= #{remark}
+        </if>
+        <if test="endTime !=null and endTime != ''">
+            , t.end_time= #{endTime}
+        </if>
+        <if test="communityId !=null and communityId != ''">
+            , t.community_id= #{communityId}
+        </if>
+        <if test="content !=null and content != ''">
+            , t.content= #{content}
+        </if>
+        where 1=1
+        <if test="qaId !=null and qaId != ''">
+            and t.qa_id= #{qaId}
+        </if>
 
     </update>
 
     <!-- 查询问卷投票数量 add by wuxw 2018-07-03 -->
-     <select id="queryQuestionAnswersCount" parameterType="Map" resultType="Map">
-        select  count(1) count 
-from question_answer t 
-where 1 =1 
-<if test="qaName !=null and qaName != ''">
-   and t.qa_name= #{qaName}
-</if> 
-<if test="qaType !=null and qaType != ''">
-   and t.qa_type= #{qaType}
-</if> 
-<if test="startTime !=null and startTime != ''">
-   and t.start_time= #{startTime}
-</if> 
-<if test="remark !=null and remark != ''">
-   and t.remark= #{remark}
-</if> 
-<if test="statusCd !=null and statusCd != ''">
-   and t.status_cd= #{statusCd}
-</if> 
-<if test="endTime !=null and endTime != ''">
-   and t.end_time= #{endTime}
-</if> 
-<if test="communityId !=null and communityId != ''">
-   and t.community_id= #{communityId}
-</if> 
-<if test="content !=null and content != ''">
-   and t.content= #{content}
-</if> 
-<if test="qaId !=null and qaId != ''">
-   and t.qa_id= #{qaId}
-</if> 
+    <select id="queryQuestionAnswersCount" parameterType="Map" resultType="Map">
+        select count(1) count
+        from question_answer t
+        where 1 =1
+        <if test="qaName !=null and qaName != ''">
+            and t.qa_name= #{qaName}
+        </if>
+        <if test="qaType !=null and qaType != ''">
+            and t.qa_type= #{qaType}
+        </if>
+        <if test="startTime !=null and startTime != ''">
+            and t.start_time= #{startTime}
+        </if>
+        <if test="remark !=null and remark != ''">
+            and t.remark= #{remark}
+        </if>
+        <if test="statusCd !=null and statusCd != ''">
+            and t.status_cd= #{statusCd}
+        </if>
+        <if test="endTime !=null and endTime != ''">
+            and t.end_time= #{endTime}
+        </if>
+        <if test="communityId !=null and communityId != ''">
+            and t.community_id= #{communityId}
+        </if>
+        <if test="content !=null and content != ''">
+            and t.content= #{content}
+        </if>
+        <if test="qaId !=null and qaId != ''">
+            and t.qa_id= #{qaId}
+        </if>
 
 
-     </select>
+    </select>
 
 </mapper>

+ 25 - 0
java110-db/src/main/resources/mapper/user/QuestionTitleValueV1ServiceDaoImplMapper.xml

@@ -114,4 +114,29 @@
 
     </select>
 
+    <select id="queryQuestionOwnerTitleValues" parameterType="Map" resultType="Map">
+        select qa.qa_id qaId,t.qa_value qaValue,t.seq,count(1) personCount
+        from question_title_value t
+        inner join question_answer_title_rel qatr on t.title_id = qatr.title_id and qatr.status_cd = '0'
+        inner join question_answer qa on qatr.qa_id = qa.qa_id and qa.status_cd = '0'
+        left join user_question_answer_value uqav on qa.qa_id = uqav.qa_id and t.value_id = uqav.value_id and t.title_id = uqav.title_id and uqav.status_cd = '0'
+        where 1=1
+        and t.community_id = #{communityId}
+        <if test="titleId !=null and titleId != ''">
+            and t.title_id= #{titleId}
+        </if>
+        <if test="statusCd !=null and statusCd != ''">
+            and t.status_cd= #{statusCd}
+        </if>
+        <if test="qaIds !=null">
+            and qa.qa_id in
+            <foreach collection="qaIds" item="item" index="index" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
+        group by qa.qa_id,t.qa_value,t.seq
+        order by t.seq
+
+
+    </select>
 </mapper>

+ 3 - 0
java110-interface/src/main/java/com/java110/intf/user/IQuestionTitleValueV1InnerServiceSMO.java

@@ -65,4 +65,7 @@ public interface IQuestionTitleValueV1InnerServiceSMO {
      */
     @RequestMapping(value = "/queryQuestionTitleValuesCount", method = RequestMethod.POST)
     int queryQuestionTitleValuesCount(@RequestBody QuestionTitleValueDto questionTitleValueDto);
+
+    @RequestMapping(value = "/queryQuestionOwnerTitleValues", method = RequestMethod.POST)
+    List<QuestionTitleValueDto> queryQuestionOwnerTitleValues(@RequestBody QuestionTitleValueDto questionTitleValueDto);
 }

+ 105 - 0
service-user/src/main/java/com/java110/user/cmd/question/ListOwnerVoteCmd.java

@@ -0,0 +1,105 @@
+package com.java110.user.cmd.question;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.annotation.Java110Cmd;
+import com.java110.core.context.ICmdDataFlowContext;
+import com.java110.core.event.cmd.Cmd;
+import com.java110.core.event.cmd.CmdEvent;
+import com.java110.dto.questionAnswer.QuestionAnswerDto;
+import com.java110.dto.questionTitleValue.QuestionTitleValueDto;
+import com.java110.intf.user.IQuestionAnswerV1InnerServiceSMO;
+import com.java110.intf.user.IQuestionTitleV1InnerServiceSMO;
+import com.java110.intf.user.IQuestionTitleValueV1InnerServiceSMO;
+import com.java110.utils.exception.CmdException;
+import com.java110.utils.util.Assert;
+import com.java110.utils.util.BeanConvertUtil;
+import com.java110.vo.ResultVo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 查询业主投票
+ */
+@Java110Cmd(serviceCode = "question.listOwnerVote")
+public class ListOwnerVoteCmd extends Cmd {
+
+    @Autowired
+    private IQuestionAnswerV1InnerServiceSMO questionAnswerV1InnerServiceSMOImpl;
+
+
+    @Autowired
+    private IQuestionTitleV1InnerServiceSMO questionTitleV1InnerServiceSMOImpl;
+
+    @Autowired
+    private IQuestionTitleValueV1InnerServiceSMO questionTitleValueV1InnerServiceSMOImpl;
+
+    @Override
+    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
+        Assert.hasKeyAndValue(reqJson, "communityId", "未包含小区信息");
+    }
+
+    @Override
+    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
+
+        QuestionAnswerDto questionAnswerDto = BeanConvertUtil.covertBean(reqJson, QuestionAnswerDto.class);
+
+        int count = questionAnswerV1InnerServiceSMOImpl.queryQuestionAnswersCount(questionAnswerDto);
+
+        List<QuestionAnswerDto> questionAnswerDtos = null;
+
+        if (count > 0) {
+            questionAnswerDtos = questionAnswerV1InnerServiceSMOImpl.queryQuestionAnswers(questionAnswerDto);
+        } else {
+            questionAnswerDtos = new ArrayList<>();
+        }
+
+        //todo 刷入选项,并且计算投票人数
+        computeQuestionAnswerValue(questionAnswerDtos);
+
+        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) reqJson.getInteger("row")), count, questionAnswerDtos);
+
+        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
+
+        context.setResponseEntity(responseEntity);
+    }
+
+    /**
+     * 计算 投票选项 投票情况
+     *
+     * @param questionAnswerDtos
+     */
+    private void computeQuestionAnswerValue(List<QuestionAnswerDto> questionAnswerDtos) {
+        if (questionAnswerDtos == null || questionAnswerDtos.size() < 1) {
+            return;
+        }
+
+        List<String> qaId = new ArrayList<>();
+        for (QuestionAnswerDto tmpQuestionAnswerDto : questionAnswerDtos) {
+            qaId.add(tmpQuestionAnswerDto.getQaId());
+        }
+
+        QuestionTitleValueDto questionTitleValueDto = new QuestionTitleValueDto();
+        questionTitleValueDto.setQaIds(qaId.toArray(new String[qaId.size()]));
+        questionTitleValueDto.setCommunityId(questionAnswerDtos.get(0).getCommunityId());
+        List<QuestionTitleValueDto> questionTitleValueDtos = questionTitleValueV1InnerServiceSMOImpl.queryQuestionOwnerTitleValues(questionTitleValueDto);
+        if (questionTitleValueDtos == null || questionTitleValueDtos.size() < 1) {
+            return;
+        }
+        List<QuestionTitleValueDto> values = null;
+        for (QuestionAnswerDto tmpQuestionAnswerDto : questionAnswerDtos) {
+            values = new ArrayList<>();
+            for (QuestionTitleValueDto tmpQuestionTitleValueDto : questionTitleValueDtos) {
+                if (!tmpQuestionTitleValueDto.getQaId().equals(tmpQuestionAnswerDto.getQaId())) {
+                    continue;
+                }
+                values.add(tmpQuestionTitleValueDto);
+            }
+            tmpQuestionAnswerDto.setTitleValues(values);
+        }
+    }
+}

+ 1 - 0
service-user/src/main/java/com/java110/user/dao/IQuestionTitleValueV1ServiceDao.java

@@ -70,4 +70,5 @@ public interface IQuestionTitleValueV1ServiceDao {
      */
     int queryQuestionTitleValuesCount(Map info);
 
+    List<Map> queryQuestionOwnerTitleValues(Map info);
 }

+ 9 - 0
service-user/src/main/java/com/java110/user/dao/impl/QuestionTitleValueV1ServiceDaoImpl.java

@@ -108,5 +108,14 @@ public class QuestionTitleValueV1ServiceDaoImpl extends BaseServiceDao implement
         return Integer.parseInt(businessQuestionTitleValueInfos.get(0).get("count").toString());
     }
 
+    @Override
+    public List<Map> queryQuestionOwnerTitleValues(Map info) {
+        logger.debug("查询 queryQuestionOwnerTitleValues 入参 info : {}",info);
+
+        List<Map> infos = sqlSessionTemplate.selectList("questionTitleValueV1ServiceDaoImpl.queryQuestionOwnerTitleValues",info);
+
+        return infos;
+    }
+
 
 }

+ 7 - 0
service-user/src/main/java/com/java110/user/smo/impl/QuestionTitleValueV1InnerServiceSMOImpl.java

@@ -86,4 +86,11 @@ public class QuestionTitleValueV1InnerServiceSMOImpl extends BaseServiceSMO impl
     public int queryQuestionTitleValuesCount(@RequestBody QuestionTitleValueDto questionTitleValueDto) {
         return questionTitleValueV1ServiceDaoImpl.queryQuestionTitleValuesCount(BeanConvertUtil.beanCovertMap(questionTitleValueDto));    }
 
+    @Override
+    public List<QuestionTitleValueDto> queryQuestionOwnerTitleValues(@RequestBody QuestionTitleValueDto questionTitleValueDto) {
+        List<QuestionTitleValueDto> questionTitleValues = BeanConvertUtil.covertBeanList(questionTitleValueV1ServiceDaoImpl.queryQuestionOwnerTitleValues(BeanConvertUtil.beanCovertMap(questionTitleValueDto)), QuestionTitleValueDto.class);
+
+        return questionTitleValues;
+    }
+
 }