Kaynağa Gözat

fix(front): 修复题目录入

Go 4 yıl önce
ebeveyn
işleme
67f7da9ad8

+ 1 - 1
front/project/admin/routes/subject/previewDetail/page.js

@@ -68,7 +68,7 @@ export default class extends Page {
         [data.startTime, data.endTime] = data.time;
         let handler;
         data.questionNoIds = this.state.questionNos.map(row => row.id);
-        if (data.id) {
+        if (!data.id) {
           handler = Preview.add(data);
         } else {
           handler = Preview.edit(data);

+ 51 - 35
front/project/admin/routes/subject/question/page.js

@@ -54,10 +54,12 @@ export default class extends Page {
         return result;
       });
     } else {
-      handler = Promise.resolve({ content: { number: 1, type: 'single', typeset: 'one', questions: [], steps: [] }, associationContent: [1], questionNoIds: [1], questionType: 'rc' });
+      handler = Promise.resolve({ content: { number: 1, type: 'single', typeset: 'one', questions: [], steps: [] } });
     }
     handler.then(result => {
       this.uuid[0] = -1;
+      let type = result.content.type || 'single';
+      if (type === 'inline') type = 'single';
       result.content.questions.forEach((row, index) => {
         const keys = [];
         this.uuid[index] = 0;
@@ -65,27 +67,26 @@ export default class extends Page {
           for (; this.uuid[index] < row.select.length; this.uuid[index] += 1) {
             keys.push(this.uuid[index]);
             form.getFieldDecorator(`content.questions[${index}].select[${this.uuid}]`);
-            form.getFieldDecorator(`content.questions[${index}].answer[${this.uuid}]`);
-          }
-          const answerMap = {};
-          row.answer.forEach(r => {
-            answerMap[r] = true;
-          });
-          row.answer = row.select.map(r => answerMap[r] || false);
-        } else if (row.answer && row.answer.length > 0) {
-          for (; this.uuid[index] < row.answer.length; this.uuid[index] += 1) {
-            keys.push(this.uuid);
-            form.getFieldDecorator(`content.questions[${index}].answer[${this.uuid}]`);
+            form.getFieldDecorator(`answer.questions[${index}].${type}[${this.uuid}]`);
           }
         }
         form.getFieldDecorator(`content.questions[${index}].keys`);
         row.keys = keys;
         return row;
       });
-      result.content.steps.forEach((row, index) => {
+      (result.content.steps || []).forEach((row, index) => {
         form.getFieldDecorator(`content.steps[${index}].title`);
         form.getFieldDecorator(`content.steps[${index}].stem`);
       });
+      const { row, col } = result.content.table;
+      for (let i = 0; i < col; i += 1) {
+        console.log(`content.table.header[${i}]`);
+        form.getFieldDecorator(`content.table.header[${i}]`);
+        for (let j = 0; j < row; j += 1) {
+          console.log(`content.table.data[${j}][${i}]`);
+          form.getFieldDecorator(`content.table.data[${j}][${i}]`);
+        }
+      }
 
       form.getFieldDecorator('content.step');
       form.getFieldDecorator('content.number');
@@ -134,6 +135,7 @@ export default class extends Page {
     handler.then(result => {
       this.placeSetting = result;
       this.placeList = result[type] || [];
+      this.setState({ placeList: this.placeList });
     });
   }
 
@@ -164,7 +166,7 @@ export default class extends Page {
           const { questionNos = [] } = this.state;
           questionNos.push(result);
           this.setState({ questionNos });
-          form.setFieldsValue({ moduleStruct: [], questionNo: '' });
+          form.setFieldsValue({ moduleStruct: [], questionNo: '', questionNoIds: questionNos.map(row => row.id) });
           asyncSMessage('保存成功');
         }).catch((e) => {
           if (e.result) form.setFields(formatFormError(data, e.result));
@@ -212,7 +214,11 @@ export default class extends Page {
   addQuestion(index) {
     const { form } = this.props;
     const keys = form.getFieldValue(`content.questions[${index}].keys`) || [];
-    this.uuid[index] += 1;
+    if (!this.uuid[index]) {
+      this.uuid[index] = 1;
+    } else {
+      this.uuid[index] += 1;
+    }
     const nextKeys = keys.concat(this.uuid[index]);
     form.setFieldsValue({
       [`content.questions[${index}].keys`]: nextKeys,
@@ -232,16 +238,16 @@ export default class extends Page {
 
   changeQuestion(index, k, value) {
     const { form } = this.props;
-    let answer = form.getFieldValue(`content.answer[${index}].single`) || [];
+    let answer = form.getFieldValue(`answer.questions[${index}].single`) || [];
     answer = answer.map(() => !value);
     answer[k] = !!value;
-    form.setFieldsValue({ [`content.answer[${index}].single`]: answer });
+    form.setFieldsValue({ [`answer.questions[${index}].single`]: answer });
   }
 
   changeDouble(index, k, o, value) {
     const { form } = this.props;
     const direction = form.getFieldValue(`content.questions[${index}].direction`);
-    let answer = form.getFieldValue(`content.answer[${index}].double`) || [];
+    let answer = form.getFieldValue(`answer.questions[${index}].double`) || [];
     switch (direction) {
       case 'landscape':
         answer[k] = answer[k].map(() => !value);
@@ -257,35 +263,47 @@ export default class extends Page {
         break;
       default:
     }
-    form.setFieldsValue({ [`content.answer[${index}].double`]: answer });
+    form.setFieldsValue({ [`answer.questions[${index}].double`]: answer });
   }
 
   submit() {
     const { form } = this.props;
-    const fields = ['type', 'place', 'difficult', 'content', 'answer', 'stem', 'keyword', 'questionNoIds', 'officialContent', 'qxContent', 'associationContent'];
+    const fields = ['id', 'questionType', 'place', 'difficult', 'content', 'answer', 'stem', 'keyword', 'questionNoIds', 'officialContent', 'qxContent', 'associationContent'];
     form.validateFields(fields, (err) => {
       if (!err) {
         const data = form.getFieldsValue(fields);
         let handler;
         data.associationContent = this.state.associationContentQuestionNos.map(row => row.id);
-        data.description = data.stem.replace(/<[^>]+>/g, '');
-        data.content.questions = data.content.questions.map(row => {
-          row.select = row.select.filter(r => r);
+        data.stem = data.stem || '';
+        data.description = (data.stem || '').replace(/<[^>]+>/g, '');
+        data.qxContent = data.qxContent || '';
+        data.officialContent = data.officialContent || '';
+
+        data.content = data.content || {};
+        data.content.questions = (data.content.questions || []).map(row => {
+          delete row.keys;
+          row.select = (row.select || []).filter(r => r);
           return row;
         });
-        data.answer.questions = data.answer.questions.map(row => {
+        data.answer = data.answer || {};
+        data.answer.questions = (data.answer.questions || []).map(row => {
           if (row.single) row.single = row.single.filter(r => r);
           if (row.double) row.double = row.double.filter(r => r);
           return row;
         });
         data.relationQuestion = this.state.realtionQuestionNos.map(row => row.id);
-        if (data.id) {
+        if (!data.id) {
           handler = Question.add(data);
         } else {
           handler = Question.edit(data);
         }
-        handler.then(() => {
+        handler.then((result) => {
           asyncSMessage('保存成功');
+          if (data.id) {
+            linkTo(`/subject/question/${data.id}`);
+          } else {
+            linkTo(`/subject/question/${result.id}`);
+          }
         }).catch((e) => {
           if (e.result) form.setFields(formatFormError(data, e.result));
         });
@@ -341,11 +359,9 @@ export default class extends Page {
       this.setState({ [targetField]: [] });
       return;
     }
-    console.log(targetField, 'loading');
     this.setState({ [`${targetField}Loading`]: true });
     Question.listNo({ [field]: values }).then(result => {
       const map = getMap(result, 'id');
-      console.log(targetField, 'finish');
       const questionNos = values.map(row => map[row]).filter(row => row);
       this.setState({ [targetField]: questionNos, [`${targetField}Loading`]: false });
     });
@@ -557,7 +573,7 @@ export default class extends Page {
               { required: true, message: '请选择考点' },
             ],
           })(
-            <Select select={this.placeList} placeholder='请选择考点' />,
+            <Select select={this.state.placeList} placeholder='请选择考点' />,
           )}
         </Form.Item>
         <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='难度'>
@@ -691,8 +707,8 @@ export default class extends Page {
                 {getFieldDecorator(`answer.questions[${index}].single[${k}]`, {
                   valuePropName: 'checked',
                 })(
-                  <Checkbox onChange={(value) => {
-                    this.changeQuestion(index, k, value);
+                  <Checkbox onChange={(e) => {
+                    this.changeQuestion(index, k, e.target.checked);
                   }} />,
                 )}
               </Col>
@@ -769,8 +785,8 @@ export default class extends Page {
                 {getFieldDecorator(`answer.questions[${index}].double[${k}][0]`, {
                   valuePropName: 'checked',
                 })(
-                  <Checkbox onChange={(value) => {
-                    this.changeDouble(index, k, 0, value);
+                  <Checkbox onChange={(e) => {
+                    this.changeDouble(index, k, 0, e.target.checkedue);
                   }} />,
                 )}
               </Col>
@@ -778,8 +794,8 @@ export default class extends Page {
                 {getFieldDecorator(`answer.questions[${index}].double[${k}][1]`, {
                   valuePropName: 'checked',
                 })(
-                  <Checkbox onChange={(value) => {
-                    this.changeDouble(index, k, 1, value);
+                  <Checkbox onChange={(e) => {
+                    this.changeDouble(index, k, 1, e.target.checked);
                   }} />,
                 )}
               </Col>

+ 1 - 1
front/project/admin/routes/subject/sentenceArticle/page.js

@@ -78,7 +78,7 @@ export default class extends Page {
         const data = form.getFieldsValue();
         data.isTrail = data.isTrail ? 1 : 0;
         let handler;
-        if (data.id) {
+        if (!data.id) {
           handler = Sentence.editArticle(data);
         } else {
           handler = Sentence.addArticle(data);

+ 1 - 1
front/project/admin/routes/subject/sentenceQuestion/page.js

@@ -59,7 +59,7 @@ export default class extends Page {
         data.isPaper = data.isPaper ? 1 : 0;
         data.question.description = data.question.stem.replace(/<[^>]+>/g, '');
         let handler;
-        if (data.id) {
+        if (!data.id) {
           handler = Sentence.editQuestion(data);
         } else {
           handler = Sentence.addQuestion(data);

+ 3 - 2
front/project/admin/routes/subject/textbookQuestion/page.js

@@ -116,6 +116,7 @@ export default class extends Page {
     return handler.then(result => {
       this.placeSetting = result;
       this.placeList = result[type] || [];
+      this.setState({ placeList: this.placeList });
     });
   }
 
@@ -172,7 +173,7 @@ export default class extends Page {
         const data = form.getFieldsValue();
         [data.startTime, data.endTime] = data.time;
         let handler;
-        if (data.id) {
+        if (!data.id) {
           handler = Textbook.editQuestion(data);
         } else {
           handler = Textbook.addQuestion(data);
@@ -226,7 +227,7 @@ export default class extends Page {
               { required: true, message: '请选择考点' },
             ],
           })(
-            <Select select={this.placeList} placeholder='请选择考点' onChange={(v) => {
+            <Select select={this.state.placeList} placeholder='请选择考点' onChange={(v) => {
               this.refreshPart(v);
             }} />,
           )}

+ 1 - 1
front/src/style/adminLeft.less

@@ -86,7 +86,7 @@ body,
     .left-slider {
       width: 200px;
       background: #fff;
-      overflow-y: 'auto';
+      overflow-y: auto;
       z-index: 10;
 
       .ant-layout-sider-children {

+ 5 - 0
server/gateway-api/src/main/java/com/qxgmat/controller/admin/QuestionController.java

@@ -25,6 +25,8 @@ import com.qxgmat.service.inline.QuestionService;
 import com.qxgmat.service.inline.UserAskQuestionService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.MediaType;
 import org.springframework.validation.annotation.Validated;
@@ -40,6 +42,7 @@ import java.util.List;
 @RequestMapping("/admin/question")
 @Api(tags = "题目接口", description = "题目相关", produces = MediaType.APPLICATION_JSON_VALUE)
 public class QuestionController {
+    private static final Logger logger = LoggerFactory.getLogger(QuestionController.class);
     @Autowired
     private ShiroHelp shiroHelp;
 
@@ -80,7 +83,9 @@ public class QuestionController {
     @RequestMapping(value = "/edit", method = RequestMethod.PUT)
     @ApiOperation(value = "修改题目", httpMethod = "PUT")
     public Response<Boolean> edit(@RequestBody @Validated QuestionDto dto, HttpServletRequest request) {
+        logger.info("dto: {}, {}, {}", dto, dto.getAnswer(), dto.getContent());
         Question entity = Transform.dtoToEntity(dto);
+        logger.info("entity: {}", entity);
         entity = questionService.edit(entity);
         // 更新编号绑定
         questionNoService.bindQuestion(dto.getQuestionNoIds(), entity.getId());

+ 2 - 12
server/gateway-api/src/main/java/com/qxgmat/dto/admin/request/QuestionDto.java

@@ -29,9 +29,9 @@ public class QuestionDto {
 
     private Integer[] questionNoIds;
 
-    private String qxContent;
+    private String qxContent = "";
 
-    private String officialContent;
+    private String officialContent = "";
 
     private Integer[] associationContent;
 
@@ -39,8 +39,6 @@ public class QuestionDto {
 
     private JSONObject answer;
 
-    private JSONObject style;
-
     private int[] relationQuestion;
 
     public Integer getId() {
@@ -99,14 +97,6 @@ public class QuestionDto {
         this.officialContent = officialContent;
     }
 
-    public JSONObject getStyle() {
-        return style;
-    }
-
-    public void setStyle(JSONObject style) {
-        this.style = style;
-    }
-
     public Integer[] getQuestionNoIds() {
         return questionNoIds;
     }

+ 9 - 17
server/gateway-api/src/main/java/com/qxgmat/dto/admin/response/QuestionDetailDto.java

@@ -15,7 +15,7 @@ public class QuestionDetailDto {
 
     private String[] keyword;
 
-    private String type;
+    private String questionType;
 
     private String place;
 
@@ -50,14 +50,6 @@ public class QuestionDetailDto {
         this.stem = stem;
     }
 
-    public String getType() {
-        return type;
-    }
-
-    public void setType(String type) {
-        this.type = type;
-    }
-
     public String getPlace() {
         return place;
     }
@@ -74,14 +66,6 @@ public class QuestionDetailDto {
         this.difficult = difficult;
     }
 
-//    public List<QuestionNoExtendDto> getQuestionNos() {
-//        return questionNos;
-//    }
-//
-//    public void setQuestionNos(List<QuestionNoExtendDto> questionNos) {
-//        this.questionNos = questionNos;
-//    }
-
     public JSONObject getContent() {
         return content;
     }
@@ -137,4 +121,12 @@ public class QuestionDetailDto {
     public void setAnswer(JSONObject answer) {
         this.answer = answer;
     }
+
+    public String getQuestionType() {
+        return questionType;
+    }
+
+    public void setQuestionType(String questionType) {
+        this.questionType = questionType;
+    }
 }

+ 6 - 2
server/gateway-api/src/main/java/com/qxgmat/service/inline/QuestionService.java

@@ -84,11 +84,15 @@ public class QuestionService extends AbstractService {
 
     public Question add(Question question){
         // 按实际更新更改更新时间
-        if (!question.getQxContent().isEmpty()){
+        if (question.getQxContent() != null && !question.getQxContent().isEmpty()){
             question.setQxTime(new Date());
+        }else{
+            question.setQxContent("");
         }
-        if (!question.getOfficialContent().isEmpty()){
+        if (question.getOfficialContent() != null && !question.getOfficialContent().isEmpty()){
             question.setOfficialTime(new Date());
+        }else{
+            question.setOfficialContent("");
         }
         if (question.getAssociationContent().length > 0){
             question.setAssociationTime(new Date());

+ 7 - 0
server/tools/src/main/java/com/nuliji/tools/Transform.java

@@ -1,5 +1,6 @@
 package com.nuliji.tools;
 
+import com.alibaba.fastjson.JSONObject;
 import com.nuliji.tools.annotation.Dto;
 import com.nuliji.tools.exception.SystemException;
 import org.modelmapper.AbstractConverter;
@@ -54,6 +55,12 @@ public class Transform {
             }
         };
         modelMapper.addConverter(longToDate);
+        Converter<JSONObject, JSONObject> jsonObjectConverter = new AbstractConverter<JSONObject, JSONObject>() {
+            protected JSONObject convert(JSONObject source) {
+                return JSONObject.parseObject(source.toJSONString());
+            }
+        };
+        modelMapper.addConverter(jsonObjectConverter);
     }
 
     public static <S, T> T dtoToEntity(S source) {