java110 лет назад: 2
Родитель
Сommit
0be6cba5d5

+ 82 - 86
java110-db/src/main/resources/mapper/user/QuestionAnswerTitleRelV1ServiceDaoImplMapper.xml

@@ -5,111 +5,107 @@
 <mapper namespace="questionAnswerTitleRelV1ServiceDaoImpl">
 <mapper namespace="questionAnswerTitleRelV1ServiceDaoImpl">
 
 
 
 
-
-
-
     <!-- 保存问卷题目信息 add by wuxw 2018-07-03 -->
     <!-- 保存问卷题目信息 add by wuxw 2018-07-03 -->
     <insert id="saveQuestionAnswerTitleRelInfo" parameterType="Map">
     <insert id="saveQuestionAnswerTitleRelInfo" parameterType="Map">
         insert into question_answer_title_rel(
         insert into question_answer_title_rel(
-score,title_id,qatr_id,community_id,seq,qa_id
-) values (
-#{score},#{titleId},#{qatrId},#{communityId},#{seq},#{qaId}
-)
+        score,title_id,qatr_id,community_id,seq,qa_id
+        ) values (
+        #{score},#{titleId},#{qatrId},#{communityId},#{seq},#{qaId}
+        )
     </insert>
     </insert>
 
 
 
 
-
     <!-- 查询问卷题目信息 add by wuxw 2018-07-03 -->
     <!-- 查询问卷题目信息 add by wuxw 2018-07-03 -->
     <select id="getQuestionAnswerTitleRelInfo" parameterType="Map" resultType="Map">
     <select id="getQuestionAnswerTitleRelInfo" parameterType="Map" resultType="Map">
-        select  t.score,t.title_id,t.title_id titleId,t.qatr_id,t.qatr_id qatrId,t.status_cd,t.status_cd statusCd,t.community_id,t.community_id communityId,t.seq,t.qa_id,t.qa_id qaId 
-from question_answer_title_rel t 
-where 1 =1 
-<if test="score !=null and score != ''">
-   and t.score= #{score}
-</if> 
-<if test="titleId !=null and titleId != ''">
-   and t.title_id= #{titleId}
-</if> 
-<if test="qatrId !=null and qatrId != ''">
-   and t.qatr_id= #{qatrId}
-</if> 
-<if test="statusCd !=null and statusCd != ''">
-   and t.status_cd= #{statusCd}
-</if> 
-<if test="communityId !=null and communityId != ''">
-   and t.community_id= #{communityId}
-</if> 
-<if test="seq !=null and seq != ''">
-   and t.seq= #{seq}
-</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.score,t.title_id,t.title_id titleId,t.qatr_id,t.qatr_id qatrId,t.status_cd,t.status_cd
+        statusCd,t.community_id,t.community_id communityId,t.seq,t.qa_id,t.qa_id qaId
+        from question_answer_title_rel t
+        where 1 =1
+        <if test="score !=null and score != ''">
+            and t.score= #{score}
+        </if>
+        <if test="titleId !=null and titleId != ''">
+            and t.title_id= #{titleId}
+        </if>
+        <if test="qatrId !=null and qatrId != ''">
+            and t.qatr_id= #{qatrId}
+        </if>
+        <if test="statusCd !=null and statusCd != ''">
+            and t.status_cd= #{statusCd}
+        </if>
+        <if test="communityId !=null and communityId != ''">
+            and t.community_id= #{communityId}
+        </if>
+        <if test="seq !=null and seq != ''">
+            and t.seq= #{seq}
+        </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>
     </select>
 
 
 
 
-
-
     <!-- 修改问卷题目信息 add by wuxw 2018-07-03 -->
     <!-- 修改问卷题目信息 add by wuxw 2018-07-03 -->
     <update id="updateQuestionAnswerTitleRelInfo" parameterType="Map">
     <update id="updateQuestionAnswerTitleRelInfo" parameterType="Map">
-        update  question_answer_title_rel t set t.status_cd = #{statusCd}
-<if test="newBId != null and newBId != ''">
-,t.b_id = #{newBId}
-</if> 
-<if test="score !=null and score != ''">
-, t.score= #{score}
-</if> 
-<if test="titleId !=null and titleId != ''">
-, t.title_id= #{titleId}
-</if> 
-<if test="communityId !=null and communityId != ''">
-, t.community_id= #{communityId}
-</if> 
-<if test="seq !=null and seq != ''">
-, t.seq= #{seq}
-</if> 
-<if test="qaId !=null and qaId != ''">
-, t.qa_id= #{qaId}
-</if> 
- where 1=1 <if test="qatrId !=null and qatrId != ''">
-and t.qatr_id= #{qatrId}
-</if> 
+        update question_answer_title_rel t set t.status_cd = #{statusCd}
+        <if test="newBId != null and newBId != ''">
+            ,t.b_id = #{newBId}
+        </if>
+        <if test="score !=null and score != ''">
+            , t.score= #{score}
+        </if>
+        <if test="titleId !=null and titleId != ''">
+            , t.title_id= #{titleId}
+        </if>
+        <if test="seq !=null and seq != ''">
+            , t.seq= #{seq}
+        </if>
+        where 1=1
+        <if test="qatrId !=null and qatrId != ''">
+            and t.qatr_id= #{qatrId}
+        </if>
+        <if test="qaId !=null and qaId != ''">
+            and t.qa_id= #{qaId}
+        </if>
+        <if test="communityId !=null and communityId != ''">
+            and t.community_id= #{communityId}
+        </if>
 
 
     </update>
     </update>
 
 
     <!-- 查询问卷题目数量 add by wuxw 2018-07-03 -->
     <!-- 查询问卷题目数量 add by wuxw 2018-07-03 -->
-     <select id="queryQuestionAnswerTitleRelsCount" parameterType="Map" resultType="Map">
-        select  count(1) count 
-from question_answer_title_rel t 
-where 1 =1 
-<if test="score !=null and score != ''">
-   and t.score= #{score}
-</if> 
-<if test="titleId !=null and titleId != ''">
-   and t.title_id= #{titleId}
-</if> 
-<if test="qatrId !=null and qatrId != ''">
-   and t.qatr_id= #{qatrId}
-</if> 
-<if test="statusCd !=null and statusCd != ''">
-   and t.status_cd= #{statusCd}
-</if> 
-<if test="communityId !=null and communityId != ''">
-   and t.community_id= #{communityId}
-</if> 
-<if test="seq !=null and seq != ''">
-   and t.seq= #{seq}
-</if> 
-<if test="qaId !=null and qaId != ''">
-   and t.qa_id= #{qaId}
-</if> 
+    <select id="queryQuestionAnswerTitleRelsCount" parameterType="Map" resultType="Map">
+        select count(1) count
+        from question_answer_title_rel t
+        where 1 =1
+        <if test="score !=null and score != ''">
+            and t.score= #{score}
+        </if>
+        <if test="titleId !=null and titleId != ''">
+            and t.title_id= #{titleId}
+        </if>
+        <if test="qatrId !=null and qatrId != ''">
+            and t.qatr_id= #{qatrId}
+        </if>
+        <if test="statusCd !=null and statusCd != ''">
+            and t.status_cd= #{statusCd}
+        </if>
+        <if test="communityId !=null and communityId != ''">
+            and t.community_id= #{communityId}
+        </if>
+        <if test="seq !=null and seq != ''">
+            and t.seq= #{seq}
+        </if>
+        <if test="qaId !=null and qaId != ''">
+            and t.qa_id= #{qaId}
+        </if>
 
 
 
 
-     </select>
+    </select>
 
 
 </mapper>
 </mapper>

+ 71 - 5
service-user/src/main/java/com/java110/user/cmd/question/UpdateQuestionAnswerCmd.java

@@ -15,14 +15,22 @@
  */
  */
 package com.java110.user.cmd.question;
 package com.java110.user.cmd.question;
 
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import com.java110.core.annotation.Java110Cmd;
 import com.java110.core.annotation.Java110Cmd;
 import com.java110.core.annotation.Java110Transactional;
 import com.java110.core.annotation.Java110Transactional;
 import com.java110.core.context.ICmdDataFlowContext;
 import com.java110.core.context.ICmdDataFlowContext;
 import com.java110.core.event.cmd.Cmd;
 import com.java110.core.event.cmd.Cmd;
 import com.java110.core.event.cmd.CmdEvent;
 import com.java110.core.event.cmd.CmdEvent;
+import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.dto.questionAnswer.QuestionAnswerDto;
+import com.java110.intf.user.IQuestionAnswerTitleRelV1InnerServiceSMO;
 import com.java110.intf.user.IQuestionAnswerV1InnerServiceSMO;
 import com.java110.intf.user.IQuestionAnswerV1InnerServiceSMO;
+import com.java110.intf.user.IUserQuestionAnswerV1InnerServiceSMO;
 import com.java110.po.questionAnswer.QuestionAnswerPo;
 import com.java110.po.questionAnswer.QuestionAnswerPo;
+import com.java110.po.questionAnswerTitleRel.QuestionAnswerTitleRelPo;
+import com.java110.po.user.UserQuestionAnswerPo;
+import com.java110.user.bmo.question.IQuestionAnswerBMO;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.util.Assert;
 import com.java110.utils.util.Assert;
 import com.java110.utils.util.BeanConvertUtil;
 import com.java110.utils.util.BeanConvertUtil;
@@ -47,14 +55,32 @@ public class UpdateQuestionAnswerCmd extends Cmd {
 
 
     private static Logger logger = LoggerFactory.getLogger(UpdateQuestionAnswerCmd.class);
     private static Logger logger = LoggerFactory.getLogger(UpdateQuestionAnswerCmd.class);
 
 
-
     @Autowired
     @Autowired
     private IQuestionAnswerV1InnerServiceSMO questionAnswerV1InnerServiceSMOImpl;
     private IQuestionAnswerV1InnerServiceSMO questionAnswerV1InnerServiceSMOImpl;
 
 
+    @Autowired
+    private IQuestionAnswerTitleRelV1InnerServiceSMO questionAnswerTitleRelV1InnerServiceSMOImpl;
+
+    @Autowired
+    private IQuestionAnswerBMO questionAnswerBMOImpl;
+
+    @Autowired
+    private IUserQuestionAnswerV1InnerServiceSMO userQuestionAnswerV1InnerServiceSMOImpl;
+
     @Override
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
     public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
-        Assert.hasKeyAndValue(reqJson, "qaId", "qaId不能为空");
-        Assert.hasKeyAndValue(reqJson, "communityId", "communityId不能为空");
+        Assert.hasKeyAndValue(reqJson, "communityId", "请求报文中未包含communityId");
+        Assert.hasKeyAndValue(reqJson, "qaName", "请求报文中未包含投票名称");
+        Assert.hasKeyAndValue(reqJson, "qaId", "请求报文中未包含题目");
+        Assert.hasKeyAndValue(reqJson, "startTime", "未包含开始时间");
+        Assert.hasKeyAndValue(reqJson, "endTime", "未包含结束时间");
+        Assert.hasKeyAndValue(reqJson, "content", "未包含说明");
+        Assert.hasKey(reqJson, "questionTitles", "请求报文中未包含题目");
+
+        JSONArray questionTitles = reqJson.getJSONArray("questionTitles");
+        if (questionTitles == null || questionTitles.size() < 1) {
+            throw new IllegalArgumentException("未包含题目");
+        }
 
 
     }
     }
 
 
@@ -62,13 +88,53 @@ public class UpdateQuestionAnswerCmd extends Cmd {
     @Java110Transactional
     @Java110Transactional
     public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
     public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
 
 
-        QuestionAnswerPo questionAnswerPo = BeanConvertUtil.covertBean(reqJson, QuestionAnswerPo.class);
+        //todo 写入投票信息
+        QuestionAnswerPo questionAnswerPo = new QuestionAnswerPo();
+        questionAnswerPo.setContent(reqJson.getString("content"));
+        questionAnswerPo.setEndTime(reqJson.getString("endTime"));
+        questionAnswerPo.setStartTime(reqJson.getString("startTime"));
+        questionAnswerPo.setQaId(reqJson.getString("qaId"));
+        questionAnswerPo.setQaName(reqJson.getString("qaName"));
+        questionAnswerPo.setCommunityId(reqJson.getString("communityId"));
+        questionAnswerPo.setQaType(QuestionAnswerDto.QA_TYPE_QUESTION);
+        questionAnswerPo.setState(QuestionAnswerDto.STATE_WAIT);
         int flag = questionAnswerV1InnerServiceSMOImpl.updateQuestionAnswer(questionAnswerPo);
         int flag = questionAnswerV1InnerServiceSMOImpl.updateQuestionAnswer(questionAnswerPo);
 
 
         if (flag < 1) {
         if (flag < 1) {
-            throw new CmdException("更新数据失败");
+            throw new CmdException("保存数据失败");
+        }
+        JSONArray questionTitles = reqJson.getJSONArray("questionTitles");
+        QuestionAnswerTitleRelPo questionAnswerTitleRelPo = new QuestionAnswerTitleRelPo();
+        questionAnswerTitleRelPo.setQaId(reqJson.getString("qaId"));
+        questionAnswerTitleRelPo.setCommunityId(reqJson.getString("communityId"));
+        questionAnswerTitleRelV1InnerServiceSMOImpl.deleteQuestionAnswerTitleRel(questionAnswerTitleRelPo);
+        JSONObject title = null;
+        for (int titleIndex = 0; titleIndex < questionTitles.size(); titleIndex++) {
+            title= questionTitles.getJSONObject(titleIndex);
+            questionAnswerTitleRelPo = new QuestionAnswerTitleRelPo();
+            questionAnswerTitleRelPo.setCommunityId(reqJson.getString("communityId"));
+            questionAnswerTitleRelPo.setTitleId(title.getString("titleId"));
+            questionAnswerTitleRelPo.setSeq((titleIndex + 1) + "");
+            questionAnswerTitleRelPo.setScore("0");
+            if(title.containsKey("score")){
+                questionAnswerTitleRelPo.setScore(title.getString("score"));
+            }
+            questionAnswerTitleRelPo.setQaId(questionAnswerPo.getQaId());
+            questionAnswerTitleRelPo.setQatrId(GenerateCodeFactory.getGeneratorId("11"));
+            questionAnswerTitleRelV1InnerServiceSMOImpl.saveQuestionAnswerTitleRel(questionAnswerTitleRelPo);
         }
         }
 
 
+        JSONArray roomIds = reqJson.getJSONArray("roomIds");
+        if(roomIds == null || roomIds.size() < 1){
+            return ;
+        }
+        UserQuestionAnswerPo userQuestionAnswerPo = new UserQuestionAnswerPo();
+        userQuestionAnswerPo.setQaId(reqJson.getString("qaId"));
+        userQuestionAnswerPo.setCommunityId(reqJson.getString("communityId"));
+        userQuestionAnswerV1InnerServiceSMOImpl.deleteUserQuestionAnswer(userQuestionAnswerPo);
+
+        questionAnswerBMOImpl.saveUserQuestionAnswer(questionAnswerPo, reqJson.getJSONArray("roomIds"));
+
         cmdDataFlowContext.setResponseEntity(ResultVo.success());
         cmdDataFlowContext.setResponseEntity(ResultVo.success());
     }
     }
 }
 }