1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.java110.user.bmo.questionAnswerTitleValue.impl;
 
import com.java110.dto.questionAnswerTitleValue.QuestionAnswerTitleValueDto;
import com.java110.intf.user.IQuestionAnswerTitleValueInnerServiceSMO;
import com.java110.user.bmo.questionAnswerTitleValue.IGetQuestionAnswerTitleValueBMO;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
 
@Service("getQuestionAnswerTitleValueBMOImpl")
public class GetQuestionAnswerTitleValueBMOImpl implements IGetQuestionAnswerTitleValueBMO {
 
    @Autowired
    private IQuestionAnswerTitleValueInnerServiceSMO questionAnswerTitleValueInnerServiceSMOImpl;
 
    /**
     * @param questionAnswerTitleValueDto
     * @return 订单服务能够接受的报文
     */
    public ResponseEntity<String> get(QuestionAnswerTitleValueDto questionAnswerTitleValueDto) {
 
 
        int count = questionAnswerTitleValueInnerServiceSMOImpl.queryQuestionAnswerTitleValuesCount(questionAnswerTitleValueDto);
 
        List<QuestionAnswerTitleValueDto> questionAnswerTitleValueDtos = null;
        if (count > 0) {
            questionAnswerTitleValueDtos = questionAnswerTitleValueInnerServiceSMOImpl.queryQuestionAnswerTitleValues(questionAnswerTitleValueDto);
        } else {
            questionAnswerTitleValueDtos = new ArrayList<>();
        }
 
        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) questionAnswerTitleValueDto.getRow()), count, questionAnswerTitleValueDtos);
 
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
 
        return responseEntity;
    }
 
    @Override
    public ResponseEntity<String> queryQuestionAnswerTitleValueResult(QuestionAnswerTitleValueDto questionAnswerTitleValueDto) {
        List<QuestionAnswerTitleValueDto> questionAnswerTitleValueDtos = new ArrayList<>();
        List<QuestionAnswerTitleValueDto> questionAnswerTitleValueResultCountDtos
                = questionAnswerTitleValueInnerServiceSMOImpl.queryQuestionAnswerTitleValueResultCount(questionAnswerTitleValueDto);
        if (questionAnswerTitleValueResultCountDtos != null && questionAnswerTitleValueResultCountDtos.size() > 0) {
            //获取总人数
            BigDecimal allCount = new BigDecimal(questionAnswerTitleValueResultCountDtos.get(0).getAllCount());
            List<QuestionAnswerTitleValueDto> questionAnswerTitleValues
                    = questionAnswerTitleValueInnerServiceSMOImpl.queryQuestionAnswerTitleValueResult(questionAnswerTitleValueDto);
            for (QuestionAnswerTitleValueDto questionAnswerTitleValue : questionAnswerTitleValues) {
                if (allCount.compareTo(BigDecimal.ZERO) == 0) {
                    questionAnswerTitleValue.setPercentage("0.0%");
                } else {
                    //获取选择人数
                    BigDecimal userCount = new BigDecimal(questionAnswerTitleValue.getUserCount());
                    double result = userCount.doubleValue() / allCount.doubleValue();
                    BigDecimal divide = new BigDecimal(result).setScale(4, BigDecimal.ROUND_HALF_UP);
                    BigDecimal percentage = divide.multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
                    questionAnswerTitleValue.setPercentage(percentage + "%");
                }
                questionAnswerTitleValueDtos.add(questionAnswerTitleValue);
            }
        }
        return ResultVo.createResponseEntity(questionAnswerTitleValueDtos);
    }
 
}