lin
2024-02-26 6cf4cea4bd8214245926dab0d081d30fa13ed9f0
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.answerRecord.service.impl;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.common.constant.CommonConstant;
import org.springblade.common.utils.SpringUtils;
import org.springblade.modules.answerRecord.dto.AnswerRecordDTO;
import org.springblade.modules.answerRecord.entity.AnswerRecordEntity;
import org.springblade.modules.answerRecord.mapper.AnswerRecordMapper;
import org.springblade.modules.answerRecord.service.IAnswerRecordService;
import org.springblade.modules.answerRecord.vo.AnswerRecordVO;
import org.springblade.modules.property.entity.PropertyCompanyEntity;
import org.springblade.modules.property.service.IPropertyCompanyService;
import org.springblade.modules.subjectChoices.vo.SubjectChoicesVO;
import org.springblade.modules.subjectOption.vo.SubjectOptionVO;
import org.springframework.stereotype.Service;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
 
/**
 * 答题记录表 服务实现类
 *
 * @author BladeX
 * @since 2024-01-17
 */
@Service
public class AnswerRecordServiceImpl extends ServiceImpl<AnswerRecordMapper, AnswerRecordEntity> implements IAnswerRecordService {
 
    @Override
    public IPage<AnswerRecordVO> selectAnswerRecordPage(IPage<AnswerRecordVO> page, AnswerRecordVO answerRecord) {
        return page.setRecords(baseMapper.selectAnswerRecordPage(page, answerRecord));
    }
 
    /**
     * 查询答题记录表
     *
     * @param id 答题记录表ID
     * @return 答题记录表
     */
    @Override
    public AnswerRecordDTO selectAnswerRecordById(Long id) {
        return this.baseMapper.selectAnswerRecordById(id);
    }
 
    /**
     * 查询答题记录表列表
     *
     * @param answerRecordDTO 答题记录表
     * @return 答题记录表集合
     */
    @Override
    public List<AnswerRecordDTO> selectAnswerRecordList(AnswerRecordDTO answerRecordDTO) {
        return this.baseMapper.selectAnswerRecordList(answerRecordDTO);
    }
 
    @Override
    public Boolean saveAnswer(List<SubjectChoicesVO> subjectChoicesVO) {
        BigDecimal bigDecimal = BigDecimal.valueOf(0);
        List<AnswerRecordEntity> answerRecordEntityList = new ArrayList<>();
        // 遍历题目和选项
        for (SubjectChoicesVO choicesVO : subjectChoicesVO) {
            List<SubjectOptionVO> subjectOptionList = choicesVO.getSubjectOptionList();
            if (choicesVO.getChoicesType().intValue() == 3) {
                bigDecimal = bigDecimal.add(choicesVO.getScore());
            }
            for (SubjectOptionVO subjectOptionVO : subjectOptionList) {
                // 删除掉之前保存的记录
                remove(Wrappers.<AnswerRecordEntity>lambdaQuery()
                    .eq(AnswerRecordEntity::getPropertyId, choicesVO.getPropertyId())
                    .eq(AnswerRecordEntity::getSubjectChoicesId, choicesVO.getId()));
                // 判断选项的id
                if (subjectOptionVO.getId().equals(choicesVO.getChooseId())) {
                    if (CommonConstant.NUMBER_ZERO.equals(choicesVO.getChoicesType().intValue())) {
                        AnswerRecordDTO answerRecordDTO = new AnswerRecordDTO();
                        answerRecordDTO.setPropertyId(choicesVO.getPropertyId());
                        answerRecordDTO.setAnswerOption(subjectOptionVO.getId());
                        answerRecordDTO.setSubjectChoicesId(choicesVO.getId());
                        answerRecordDTO.setSubjectChoicesType(1);
                        answerRecordDTO.setSubjectOptionId(subjectOptionVO.getId());
                        answerRecordEntityList.add(answerRecordDTO);
                        bigDecimal = bigDecimal.add(subjectOptionVO.getScore());
                        break;
                    }
                }
                if (CommonConstant.NUMBER_THREE.equals(choicesVO.getChoicesType().intValue())) {
                    AnswerRecordDTO answerRecordDTO = new AnswerRecordDTO();
                    answerRecordDTO.setPropertyId(choicesVO.getPropertyId());
                    answerRecordDTO.setAnswerOption(subjectOptionVO.getId());
                    answerRecordDTO.setSubjectChoicesId(choicesVO.getId());
                    answerRecordDTO.setAnswer(subjectOptionVO.getNumbers());
                    answerRecordDTO.setSubjectOptionId(subjectOptionVO.getId());
                    answerRecordDTO.setSubjectChoicesType(3);
                    answerRecordEntityList.add(answerRecordDTO);
                    BigDecimal multiply = BigDecimal.valueOf(subjectOptionVO.getNumbers()).multiply(subjectOptionVO.getScore());
                    bigDecimal = bigDecimal.subtract(multiply);
                }
            }
        }
        // 保存得分
        IPropertyCompanyService bean = SpringUtils.getBean(IPropertyCompanyService.class);
        PropertyCompanyEntity one = bean.getOne(Wrappers.<PropertyCompanyEntity>lambdaQuery().eq(PropertyCompanyEntity::getId, subjectChoicesVO.get(0).getPropertyId()));
        if (subjectChoicesVO.get(0).getSubclassName().equals("基础信息")) {
            one.setBaseInfoScore(bigDecimal);
        } else if (subjectChoicesVO.get(0).getSubclassName().equals("经营信息")) {
            one.setOperateinfoScore(bigDecimal);
        } else if (subjectChoicesVO.get(0).getSubclassName().equals("纳税信息")) {
            one.setTaxInfoScore(bigDecimal);
        } else if (subjectChoicesVO.get(0).getSubclassName().equals("党建信息")) {
            one.setPartyBuildingInfoScore(bigDecimal);
            bean.update(Wrappers.<PropertyCompanyEntity>lambdaUpdate().set(PropertyCompanyEntity::getPartyBuildingInfoScore, bigDecimal)
                .eq(PropertyCompanyEntity::getId, subjectChoicesVO.get(0).getPropertyId()));
        } else if (subjectChoicesVO.get(0).getSubclassName().equals("街道社区")) {
            one.setStreetScore(bigDecimal);
        }else if (subjectChoicesVO.get(0).getSubclassName().equals("企业良好行为")) {
            one.setGoodCorporateScore(bigDecimal);
        } else if (subjectChoicesVO.get(0).getSubclassName().equals("项目良好行为")) {
            one.setGoodProjectScore(bigDecimal);
        } else if (subjectChoicesVO.get(0).getSubclassName().equals("违法违规行为惩戒")) {
            one.setLllegalAndIrregularScore(bigDecimal);
        }
        // 计算总分
        BigDecimal add = one.getBaseInfoScore()
            .add(one.getOperateinfoScore())
            .add(one.getOperateinfoScore())
            .add(one.getPartyBuildingInfoScore())
            .add(one.getGoodCorporateScore())
            .add(one.getGoodProjectScore())
            .add(one.getLllegalAndIrregularScore())
            .add(one.getEvaluateScore())
            .add(one.getStreetScore());
        one.setAllScore(getAllScore(add));
        bean.updateById(one);
        return saveBatch(answerRecordEntityList);
    }
 
    /**
     * 判断结果,如果大于100 则设置100 小于/等于0 设置为0
     *
     * @param allScore
     * @return
     */
    private BigDecimal getAllScore(BigDecimal allScore) {
        if (allScore.compareTo(BigDecimal.valueOf(0)) > 100) {
            return BigDecimal.valueOf(100);
        }
        if (allScore.compareTo(BigDecimal.valueOf(0)) > 0) {
            return allScore;
        }
        return BigDecimal.valueOf(0);
    }
 
 
}