wuweihao 4 år sedan
förälder
incheckning
aa6737cb6b

+ 19 - 0
gis_domain/src/main/java/com/gis/domain/dto/AnswerDto.java

@@ -0,0 +1,19 @@
+package com.gis.domain.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import io.swagger.annotations.ApiOperation;
+import lombok.Data;
+
+/**
+ * Created by owen on 2021/8/27 0027 16:44
+ */
+@Data
+public class AnswerDto{
+
+    @ApiModelProperty(value = "题号" )
+    private Integer num;
+
+    @ApiModelProperty(value = "答案" )
+    private String answer;
+
+}

+ 24 - 23
gis_domain/src/main/java/com/gis/domain/dto/CountAnswerDto.java

@@ -3,6 +3,8 @@ package com.gis.domain.dto;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
+import java.util.List;
+
 
 /**
  * Created by owen on 2021/6/24 0024 18:18
@@ -20,29 +22,28 @@ public class CountAnswerDto {
     @ApiModelProperty(value = "手机号" )
     private String phone;
 
-    @ApiModelProperty(value = "题号" )
-    private Integer num;
-
-    @ApiModelProperty(value = "答案数量" )
-    private Double a;
-
-    @ApiModelProperty(value = "答案数量" )
-    private Double b;
-
-    @ApiModelProperty(value = "答案数量" )
-    private Double c;
-
-    @ApiModelProperty(value = "答案数量" )
-    private Double d;
-
-    @ApiModelProperty(value = "答案数量" )
-    private Double e;
-
-    @ApiModelProperty(value = "答案数量" )
-    private Double f;
-
-    @ApiModelProperty(value = "答案数量" )
-    private Double g;
+    private List<AnswerDto> answer;
+
+//    @ApiModelProperty(value = "答案数量" )
+//    private Double a;
+//
+//    @ApiModelProperty(value = "答案数量" )
+//    private Double b;
+//
+//    @ApiModelProperty(value = "答案数量" )
+//    private Double c;
+//
+//    @ApiModelProperty(value = "答案数量" )
+//    private Double d;
+//
+//    @ApiModelProperty(value = "答案数量" )
+//    private Double e;
+//
+//    @ApiModelProperty(value = "答案数量" )
+//    private Double f;
+//
+//    @ApiModelProperty(value = "答案数量" )
+//    private Double g;
 
 
 }

+ 25 - 20
gis_domain/src/main/java/com/gis/domain/po/CountAnswerEntity.java

@@ -30,26 +30,31 @@ public class CountAnswerEntity extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "题号" )
     private Integer num;
 
-    @ApiModelProperty(value = "答案数量" )
-    private Double a;
-
-    @ApiModelProperty(value = "答案数量" )
-    private Double b;
-
-    @ApiModelProperty(value = "答案数量" )
-    private Double c;
-
-    @ApiModelProperty(value = "答案数量" )
-    private Double d;
-
-    @ApiModelProperty(value = "答案数量" )
-    private Double e;
-
-    @ApiModelProperty(value = "答案数量" )
-    private Double f;
-
-    @ApiModelProperty(value = "答案数量" )
-    private Double g;
+    @ApiModelProperty(value = "答案" )
+    private String answer;
+
+
+
+//    @ApiModelProperty(value = "答案数量" )
+//    private Double a;
+//
+//    @ApiModelProperty(value = "答案数量" )
+//    private Double b;
+//
+//    @ApiModelProperty(value = "答案数量" )
+//    private Double c;
+//
+//    @ApiModelProperty(value = "答案数量" )
+//    private Double d;
+//
+//    @ApiModelProperty(value = "答案数量" )
+//    private Double e;
+//
+//    @ApiModelProperty(value = "答案数量" )
+//    private Double f;
+//
+//    @ApiModelProperty(value = "答案数量" )
+//    private Double g;
 
 
 }

+ 26 - 20
gis_domain/src/main/java/com/gis/domain/vo/CountAnswerVo.java

@@ -17,26 +17,32 @@ public class CountAnswerVo {
     @ApiModelProperty(value = "题号" )
     private Integer num;
 
-    @ApiModelProperty(value = "答案数量" )
-    private Double a;
-
-    @ApiModelProperty(value = "答案数量" )
-    private Double b;
-
-    @ApiModelProperty(value = "答案数量" )
-    private Double c;
-
-    @ApiModelProperty(value = "答案数量" )
-    private Double d;
-
-    @ApiModelProperty(value = "答案数量" )
-    private Double e;
-
-    @ApiModelProperty(value = "答案数量" )
-    private Double f;
-
-    @ApiModelProperty(value = "答案数量" )
-    private Double g;
+    @ApiModelProperty(value = "选项" )
+    private String answer;
+
+    @ApiModelProperty(value = "数量" )
+    private Integer count;
+
+//    @ApiModelProperty(value = "答案数量" )
+//    private Double a;
+//
+//    @ApiModelProperty(value = "答案数量" )
+//    private Double b;
+//
+//    @ApiModelProperty(value = "答案数量" )
+//    private Double c;
+//
+//    @ApiModelProperty(value = "答案数量" )
+//    private Double d;
+//
+//    @ApiModelProperty(value = "答案数量" )
+//    private Double e;
+//
+//    @ApiModelProperty(value = "答案数量" )
+//    private Double f;
+//
+//    @ApiModelProperty(value = "答案数量" )
+//    private Double g;
 
     @JSONField(serialize = false)
     private LocalDateTime createTime;

+ 2 - 1
gis_mapper/src/main/java/com/gis/mapper/CountAnswerMapper.java

@@ -15,6 +15,7 @@ import java.util.List;
 @Mapper
 public interface CountAnswerMapper extends IBaseMapper<CountAnswerEntity, Long> {
 
-    @Select("select * from tb_count_answer where is_delete=0 and question_group_id=#{questionGroupId}")
+    @Select("select num, answer, count(answer) as count, create_time from tb_count_answer " +
+            "where is_delete=0 and question_group_id=#{questionGroupId} GROUP BY num, answer")
     List<CountAnswerVo> findByQuestionGroupId(Long questionGroupId);
 }

+ 4 - 0
gis_mapper/src/main/java/com/gis/mapper/QuestionGroupMapper.java

@@ -3,6 +3,7 @@ package com.gis.mapper;
 
 import com.gis.domain.po.QuestionGroupEntity;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.Update;
 import org.springframework.stereotype.Component;
 
@@ -16,4 +17,7 @@ public interface QuestionGroupMapper extends IBaseMapper<QuestionGroupEntity, Lo
 
     @Update("update tb_question_group set display = 1 , update_time = NOW() where is_delete = 0 and id=#{id}")
     void enabledById(Long id);
+
+    @Select("select id from tb_question_group where is_delete=0 and display=1")
+    Long findByIndex();
 }

+ 1 - 1
gis_mapper/src/main/java/com/gis/mapper/provider/GoodsProvider.java

@@ -46,7 +46,7 @@ public class GoodsProvider {
 
         Long goodsAgeId = param.getGoodsAgeId();
         if (goodsAgeId != null){
-            sql.append(" and  age = ").append(goodsAgeId);
+            sql.append(" and  goods_age_id = ").append(goodsAgeId);
         }
 
 

+ 1 - 1
gis_service/src/main/java/com/gis/service/CountAnswerService.java

@@ -14,7 +14,7 @@ import java.util.List;
 public interface CountAnswerService extends IBaseService<CountAnswerEntity, Long> {
 
 
-    Result<CountAnswerEntity> saveEntity(List<CountAnswerDto> param);
+    Result<CountAnswerEntity> saveEntity(CountAnswerDto param);
 
 
     Result findByQuestionGroupId(Long questionGroupId, Integer type);

+ 2 - 0
gis_service/src/main/java/com/gis/service/QuestionGroupService.java

@@ -28,4 +28,6 @@ public interface QuestionGroupService extends IBaseService<QuestionGroupEntity,
 //    Result auditDetail(Long id);
 
     Result updateDisplay(Long id);
+
+    Result questionGroupGetIndexDetail();
 }

+ 72 - 75
gis_service/src/main/java/com/gis/service/impl/CountAnswerServiceImpl.java

@@ -1,7 +1,9 @@
 package com.gis.service.impl;
 
 import cn.hutool.core.util.NumberUtil;
+import com.alibaba.fastjson.JSONObject;
 import com.gis.common.util.Result;
+import com.gis.domain.dto.AnswerDto;
 import com.gis.domain.dto.CountAnswerDto;
 import com.gis.domain.po.CountAnswerEntity;
 import com.gis.domain.po.QuestionGroupEntity;
@@ -16,9 +18,7 @@ import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.text.DecimalFormat;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 
@@ -42,15 +42,25 @@ public class CountAnswerServiceImpl extends IBaseServiceImpl<CountAnswerEntity,
 
 
     @Override
-    public Result<CountAnswerEntity> saveEntity(List<CountAnswerDto> param) {
+    public Result<CountAnswerEntity> saveEntity(CountAnswerDto param) {
 
-        for (CountAnswerDto countAnswerDto : param) {
+        String phone = param.getPhone();
+        Long questionGroupId = param.getQuestionGroupId();
+        String realName = param.getRealName();
+
+        List<AnswerDto> answer = param.getAnswer();
+
+        for (AnswerDto dto: answer) {
             CountAnswerEntity entity  = new CountAnswerEntity();
-            BeanUtils.copyProperties(countAnswerDto, entity);
-            this.save(entity);
-        }
+            entity.setNum(dto.getNum());
+            entity.setAnswer(dto.getAnswer().toUpperCase());
 
+            entity.setQuestionGroupId(questionGroupId);
+            entity.setPhone(phone);
+            entity.setRealName(realName);
 
+            this.save(entity);
+        }
         return Result.success();
 
     }
@@ -60,86 +70,73 @@ public class CountAnswerServiceImpl extends IBaseServiceImpl<CountAnswerEntity,
      * @param type 0:百分比, 1:计数
      * @return
      */
-    @Override
-    public Result findByQuestionGroupId(Long questionGroupId, Integer type) {
-        QuestionGroupEntity groupEntity = questionGroupService.findById(questionGroupId);
-
-        if (groupEntity == null) {
-            return Result.failure(2001, "没有数据");
-        }
+        @Override
+        public Result findByQuestionGroupId(Long questionGroupId, Integer type){
+            QuestionGroupEntity groupEntity = questionGroupService.findById(questionGroupId);
 
-        List<CountAnswerVo> answers = entityMapper.findByQuestionGroupId(questionGroupId);
+            if (groupEntity == null) {
+                return Result.failure(2001, "没有数据");
+            }
 
-        if (answers.size() == 0) {
-            return Result.failure(2001, "没有数据");
-        }
-
-
-        CountAnswerVo vo = answers.get(0);
-        Map<String, Object> result = new HashMap<>();
-        result.put("name", groupEntity.getName());
-        result.put("createTime", vo.getCreateTime());
-
-
-        if (type == 1) {
-            result.put("answer", answers);
-        } else {
-            // 返回百分比
-            answers.forEach(p -> {
+            List<CountAnswerVo> answers = entityMapper.findByQuestionGroupId(questionGroupId);
 
-                // 分母
-                Double a = p.getA()== null ? 0 : p.getA();
-                Double b = p.getB()== null ? 0 : p.getB();
-                Double c = p.getC()== null ? 0 : p.getC();
-                Double d = p.getD()== null ? 0 : p.getD();
-                Double e = p.getE()== null ? 0 : p.getE();
-                Double f = p.getF()== null ? 0 : p.getF();
-                Double g = p.getG()== null ? 0 : p.getG();
-                Double sum = a + b + c + d + e + f + g;
+            if (answers.size() == 0) {
+                return Result.failure(2001, "没有数据");
+            }
 
-//                a = NumberUtil.div(a, sum, 4);
-//                b = NumberUtil.div(b, sum, 4);
-//                c = NumberUtil.div(c, sum, 4);
-//                d = NumberUtil.div(d, sum, 4);
-//                e = NumberUtil.div(e, sum, 4);
-//                f = NumberUtil.div(f, sum, 4);
-//                g = NumberUtil.div(g, sum, 4);
 
-//                p.setA(a == 0 ? null : a);
-//                p.setA(b == 0 ? null : b);
-//                p.setA(c == 0 ? null : c);
-//                p.setA(d == 0 ? null : d);
-//                p.setA(e == 0 ? null : e);
-//                p.setA(f == 0 ? null : f);
-//                p.setA(g == 0 ? null : g);
+            CountAnswerVo vo = answers.get(0);
+            Map<Object, Object> result = new HashMap<>();
+            result.put("name", groupEntity.getName());
+            result.put("createTime", vo.getCreateTime());
 
-//                p.setA(a);
-//                p.setB(b);
-//                p.setC(c);
-//                p.setD(d);
-//                p.setE(e);
-//                p.setF(f);
-//                p.setG(g);
+            Map<String, List<CountAnswerVo> > resCount = new HashMap<>();
 
+            // 去重
+            Set<Integer> nums = answers.stream().map(CountAnswerVo::getNum).collect(Collectors.toSet());
 
+            for (Integer num : nums){
+                List<CountAnswerVo> list = new ArrayList<>();
+                for (CountAnswerVo answer : answers) {
+                    if (num.equals(answer.getNum())){
+                        CountAnswerVo vo1 = new CountAnswerVo();
+                        BeanUtils.copyProperties(answer, vo1);
+                        list.add(vo1);
+                    }
+                }
+                resCount.put(num.toString(), list);
+            }
 
-                p.setA(NumberUtil.div(a, sum, 4));
-                p.setB(NumberUtil.div(b, sum, 4));
-                p.setC(NumberUtil.div(c, sum, 4));
-                p.setD(NumberUtil.div(d, sum, 4));
-                p.setE(NumberUtil.div(e, sum, 4));
-                p.setF(NumberUtil.div(f, sum, 4));
-                p.setG(NumberUtil.div(g, sum, 4));
 
-            });
-
-            result.put("answer", answers);
+            if (type == 1) {
+                result.put("answer", resCount);
 
+            } else {
+                Map<String, Object> percent = percent(resCount);
+                result.put("answer", percent);
+            }
 
+            return Result.success(result);
         }
 
-        return Result.success(result);
-    }
-
 
+        private Map<String , Object> percent(Map<String, List<CountAnswerVo> > resCount){
+
+            Map<String, Object > res = new HashMap<>();
+            for (Map.Entry<String, List<CountAnswerVo>> m : resCount.entrySet()){
+                List<CountAnswerVo> value = m.getValue();
+                // 每个题号回答的总数
+                List<JSONObject> list = new ArrayList<>();
+                long sum = value.stream().mapToInt(CountAnswerVo::getCount).summaryStatistics().getSum();
+                for (CountAnswerVo vo : value) {
+                    JSONObject json = new JSONObject();
+                    json.put("answer", vo.getAnswer());
+                    Integer count = vo.getCount();
+                    json.put("count", NumberUtil.div(count+"", sum+"", 4));
+                    list.add(json);
+                }
+                res.put(m.getKey(), list);
+            }
+            return res;
+        }
 }

+ 10 - 58
gis_service/src/main/java/com/gis/service/impl/QuestionGroupServiceImpl.java

@@ -76,60 +76,12 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
         condition.orderBy("createTime").desc();
 
         PageInfo<QuestionGroupEntity> pageInfo = this.findAll(condition, param.getPageNum(), param.getPageSize());
-//        List<QuestionGroupEntity> list = pageInfo.getList();
-//
-//        List<QuestionGroupEntity> result = new ArrayList<>();
-//
-//        for (QuestionGroupEntity q : list) {
-//            Integer count = getQuesitongCount(q.getId());
-//            q.setQuestionCount(count);
-//            result.add(q);
-//        }
-//
-//        pageInfo.setList(result);
-
         return Result.success(pageInfo);
 
 
     }
 
-//    private Integer getQuesitongCount(Long id){
-//        List<QuestionEntityEntity> answerEntityList = questionEntityService.findByQuestionGroupId(id);
-//        return answerEntityList.size();
-//    }
-
-//    @Override
-//    public Result apply(Long id) {
-//        // 1:审核中
-//        updateStatus(id, 1);
-//        return  Result.success();
-//    }
-
-//    @Override
-//    public Result audit(AuditDto param) {
-//        // 2:审核不通过, 3:审核通过
-//        Integer status = param.getStatus();
-//        if (status == 0) {
-//            // 审核不通过
-//            status = 2;
-//        } else if (status == 1){
-//            // 审核通过
-//            status = 3;
-//        } else {
-//            throw new BaseRuntimeException(MsgCode.e3004, "审核状态非法");
-//        }
-//        Long id = param.getId();
-//        updateStatus(id, status);
-//        // 记录审核日志
-//        auditLogService.saveAuditLog(TypeCode.MODULE_QUESTION_GROUP, id, param.getStatus(), param.getReason());
-//        return Result.success();
-//    }
-
-//    @Override
-//    public Result auditDetail(Long id) {
-//        List<AuditLogEntity> list = auditLogService.findByModuleId(id, TypeCode.MODULE_QUESTION_GROUP);
-//        return Result.success(list);
-//    }
+
 
     @Override
     public Result updateDisplay(Long id) {
@@ -147,16 +99,16 @@ public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEnti
         return Result.success();
     }
 
+    @Override
+    public Result questionGroupGetIndexDetail() {
+
+        Long id = entityMapper.findByIndex();
+        return this.detail(id);
+
+    }
+
+
 
-//    private void updateStatus(Long id, Integer status){
-//        QuestionGroupEntity entity = this.findById(id);
-//        if (entity == null) {
-//            throw new BaseRuntimeException(MsgCode.e3001, "对象不存在");
-//        }
-//        entity.setStatus(status);
-//        entity.setUpdateTime(LocalDateTime.now());
-//        this.update(entity);
-//    }
 
     @Override
     public Result saveEntity(QuestionGroupDto param) {

+ 6 - 6
gis_web/src/main/java/com/gis/web/controller/CountAnswerController.java

@@ -27,12 +27,12 @@ public class CountAnswerController extends BaseController {
     private CountAnswerService entityService;
 
 
-    @WebControllerLog(description = "问卷统计-新增", addDb = true)
-    @ApiOperation("新增")
-    @PostMapping("save")
-    public Result<CountAnswerEntity> save(@Valid @RequestBody List<CountAnswerDto> param) {
-        return entityService.saveEntity(param);
-    }
+//    @WebControllerLog(description = "问卷统计-新增", addDb = true)
+//    @ApiOperation("新增")
+//    @PostMapping("save")
+//    public Result<CountAnswerEntity> save(@Valid @RequestBody List<CountAnswerDto> param) {
+//        return entityService.saveEntity(param);
+//    }
 
 
     @WebControllerLog(description = "问卷统计-详情")

+ 1 - 1
gis_web/src/main/java/com/gis/web/controller/OnlineExhibitionController.java

@@ -41,7 +41,7 @@ public class OnlineExhibitionController extends BaseController {
 //        return entityService.remove(id);
 //    }
 
-    @WebControllerLog(description = "出版书籍-详情")
+    @WebControllerLog(description = "线上展览-详情")
     @ApiOperation(value = "详情")
     @GetMapping("detail/{id}")
     public Result detail(@PathVariable Long id) {

+ 39 - 4
gis_web/src/main/java/com/gis/web/controller/WebController.java

@@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
+import tk.mybatis.mapper.entity.Condition;
 
 import javax.validation.Valid;
 import java.util.List;
@@ -74,6 +75,15 @@ public class WebController {
     @Autowired
     CountAnswerService countAnswerService;
 
+    @Autowired
+    OnlineExhibitionService onlineExhibitionService;
+
+    @Autowired
+    GoodsAgeService goodsAgeService;
+
+    @Autowired
+    GoodsTypeService goodsTypeService;
+
     @ApiOperation("轮播图")
     @PostMapping("slideshow/list")
     public Result<SlideshowEntity> slideshowList() {
@@ -131,6 +141,13 @@ public class WebController {
         return exhibitionService.search(param);
     }
 
+    @ApiOperation(value = "展览-线上展览")
+    @GetMapping("exhibition/online")
+    public Result exhibitionOnline(){
+        OnlineExhibitionEntity entity = onlineExhibitionService.findById(1L);
+        return Result.success(entity);
+    }
+
 
     @ApiOperation(value = "典藏-列表", notes = "类型: 图片:img, 模型:model")
     @PostMapping("goods/list")
@@ -138,6 +155,24 @@ public class WebController {
         return goodsService.search(param);
     }
 
+
+    @ApiOperation("典藏-年代列表")
+    @GetMapping("goods/age/list")
+    public Result<List<GoodsAgeEntity>> ageList() {
+        Condition condition = new Condition(GoodsAgeEntity.class);
+        condition.orderBy("createTime").desc();
+        return Result.success(goodsAgeService.findAll(condition));
+    }
+
+    @ApiOperation("典藏-分类列表")
+    @GetMapping("goods/type/list")
+    public Result<List<GoodsTypeEntity>> typeList() {
+        Condition condition = new Condition(GoodsTypeEntity.class);
+        condition.orderBy("createTime").desc();
+        return Result.success(goodsTypeService.findAll(condition));
+    }
+
+
     @ApiOperation(value = "活动-列表", notes = "type: 类型, online:线上, volunteer:志愿者")
     @PostMapping("activity/list")
     public Result activityList(@RequestBody TypePageDto param){
@@ -146,9 +181,9 @@ public class WebController {
 
 
     @ApiOperation(value = "活动-问卷调查")
-    @PostMapping("questionGroup/detail/{id}")
-    public Result questionGroupDetail(@PathVariable Long id){
-        return questionGroupService.detail(id);
+    @GetMapping("questionGroup/getIndex")
+    public Result questionGroupGetIndexDetail(){
+        return questionGroupService.questionGroupGetIndexDetail();
     }
 
 
@@ -156,7 +191,7 @@ public class WebController {
     @WebControllerLog(description = "活动-问卷提交", addDb = true)
     @ApiOperation("活动-问卷提交")
     @PostMapping("questionGroup/save")
-    public Result<CountAnswerEntity> questionGroupSave(@Valid @RequestBody List<CountAnswerDto> param) {
+    public Result<CountAnswerEntity> questionGroupSave(@Valid @RequestBody CountAnswerDto param) {
         return countAnswerService.saveEntity(param);
     }