Commit 3cac2984edc7599aecaeac792f7a3410b6ffb221

Authored by guzijian
1 parent 6ccc8629

feat: 获取当月评分,和总清运数

trash-garbage/src/main/java/com/trash/garbage/controller/GarbageOrderController.java
... ... @@ -12,6 +12,7 @@ import com.trash.common.utils.StringUtils;
12 12 import com.trash.common.utils.file.FileUploadUtils;
13 13 import com.trash.common.utils.poi.ExcelUtil;
14 14 import com.trash.common.utils.sql.SqlUtil;
  15 +import com.trash.enterprise.domain.TransportationEnterprise;
15 16 import com.trash.framework.config.ServerConfig;
16 17 import com.trash.garbage.custom.BizException;
17 18 import com.trash.garbage.global.Result;
... ... @@ -117,6 +118,13 @@ public class GarbageOrderController {
117 118 return Result.OK(garOrderService.queryOrderWebDetail(id));
118 119 }
119 120  
  121 +
  122 + @GetMapping("/company")
  123 + public Result<?> queryEnterpriseList(TransportationEnterprise enterprise){
  124 + startPage();
  125 + return Result.OK(garOrderService.queryEnterpriseList(enterprise));
  126 + }
  127 +
120 128 protected void startPage() {
121 129 PageDomain pageDomain = TableSupport.buildPageRequest();
122 130 Integer pageNum = pageDomain.getPageNum();
... ...
trash-garbage/src/main/java/com/trash/garbage/mapper/GarOrderEvaluateMapper.java
... ... @@ -2,6 +2,9 @@ package com.trash.garbage.mapper;
2 2  
3 3 import com.trash.garbage.pojo.domain.GarOrderEvaluate;
4 4 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  5 +import org.apache.ibatis.annotations.Param;
  6 +
  7 +import java.util.List;
5 8  
6 9 /**
7 10 * @author 20412
... ... @@ -11,6 +14,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
11 14 */
12 15 public interface GarOrderEvaluateMapper extends BaseMapper<GarOrderEvaluate> {
13 16  
  17 + List<GarOrderEvaluate> queryEvaluateByEnterpriseIds(@Param("list") List<Long> enterpriseIds, @Param("type") Integer value);
14 18 }
15 19  
16 20  
... ...
trash-garbage/src/main/java/com/trash/garbage/mapper/GarOrderMapper.java
... ... @@ -2,6 +2,9 @@ package com.trash.garbage.mapper;
2 2  
3 3 import com.trash.garbage.pojo.domain.GarOrder;
4 4 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  5 +import org.apache.ibatis.annotations.Param;
  6 +
  7 +import java.util.List;
5 8  
6 9 /**
7 10 * @author 20412
... ... @@ -11,6 +14,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
11 14 */
12 15 public interface GarOrderMapper extends BaseMapper<GarOrder> {
13 16  
  17 + List<GarOrder> queryCleanNumberByEnterpriseIds(@Param("list") List<Long> enterpriseIds,@Param("status") Integer value);
14 18 }
15 19  
16 20  
... ...
trash-garbage/src/main/java/com/trash/garbage/pojo/domain/GarOrder.java
... ... @@ -23,6 +23,13 @@ public class GarOrder implements Serializable {
23 23 @TableId
24 24 private String garOrderId;
25 25  
  26 + /**
  27 + * 新增的一列数据 用于存储count字段
  28 + * 注解非常关键
  29 + */
  30 + @TableField(exist = false)
  31 + private Long count;
  32 +
26 33 /**
27 34 * 用户id
28 35 */
... ... @@ -383,7 +390,11 @@ public class GarOrder implements Serializable {
383 390 this.garOrderCarType = garOrderCarType;
384 391 }
385 392  
  393 + public Long getCount() {
  394 + return count;
  395 + }
386 396  
387   -
388   -
  397 + public void setCount(Long count) {
  398 + this.count = count;
  399 + }
389 400 }
390 401 \ No newline at end of file
... ...
trash-garbage/src/main/java/com/trash/garbage/pojo/domain/GarOrderEvaluate.java
1 1 package com.trash.garbage.pojo.domain;
2 2  
  3 +import com.baomidou.mybatisplus.annotation.FieldFill;
3 4 import com.baomidou.mybatisplus.annotation.TableField;
4 5 import com.baomidou.mybatisplus.annotation.TableId;
5 6 import com.baomidou.mybatisplus.annotation.TableName;
... ... @@ -41,24 +42,33 @@ public class GarOrderEvaluate implements Serializable {
41 42 */
42 43 private Integer garEvaluateScore;
43 44  
  45 + /**
  46 + * 评价对象
  47 + */
  48 + private Integer garEvaluateTarget;
  49 +
44 50 /**
45 51 * 修改人
46 52 */
  53 + @TableField(fill = FieldFill.INSERT_UPDATE)
47 54 private String garUpdateBy;
48 55  
49 56 /**
50 57 * 创建人
51 58 */
  59 + @TableField(fill = FieldFill.INSERT)
52 60 private String garCreateBy;
53 61  
54 62 /**
55 63 * 修改时间
56 64 */
  65 + @TableField(fill = FieldFill.INSERT_UPDATE)
57 66 private Date garUpdateTime;
58 67  
59 68 /**
60 69 * 创建时间
61 70 */
  71 + @TableField(fill = FieldFill.INSERT)
62 72 private Date garCreateTime;
63 73  
64 74 /**
... ... @@ -69,6 +79,14 @@ public class GarOrderEvaluate implements Serializable {
69 79 @TableField(exist = false)
70 80 private static final long serialVersionUID = 1L;
71 81  
  82 + public Integer getGarEvaluateTarget() {
  83 + return garEvaluateTarget;
  84 + }
  85 +
  86 + public void setGarEvaluateTarget(Integer garEvaluateTarget) {
  87 + this.garEvaluateTarget = garEvaluateTarget;
  88 + }
  89 +
72 90 public String getGarEvaluateId() {
73 91 return garEvaluateId;
74 92 }
... ...
trash-garbage/src/main/java/com/trash/garbage/pojo/vo/TransportationEnterpriseVo.java 0 → 100644
  1 +package com.trash.garbage.pojo.vo;
  2 +
  3 +import com.trash.enterprise.domain.TransportationEnterprise;
  4 +import lombok.EqualsAndHashCode;
  5 +import lombok.ToString;
  6 +
  7 +@ToString
  8 +@EqualsAndHashCode
  9 +public class TransportationEnterpriseVo extends TransportationEnterprise {
  10 + private Integer score;
  11 +
  12 + private Integer cleanNumber;
  13 +
  14 + public Integer getCleanNumber() {
  15 + return cleanNumber;
  16 + }
  17 +
  18 + public void setCleanNumber(Integer cleanNumber) {
  19 + this.cleanNumber = cleanNumber;
  20 + }
  21 +
  22 + public Integer getScore() {
  23 + return score;
  24 + }
  25 +
  26 + public void setScore(Integer score) {
  27 + this.score = score;
  28 + }
  29 +}
... ...
trash-garbage/src/main/java/com/trash/garbage/service/GarOrderEvaluateService.java
... ... @@ -2,6 +2,9 @@ package com.trash.garbage.service;
2 2  
3 3 import com.trash.garbage.pojo.domain.GarOrderEvaluate;
4 4 import com.baomidou.mybatisplus.extension.service.IService;
  5 +import org.apache.ibatis.annotations.Param;
  6 +
  7 +import java.util.List;
5 8  
6 9 /**
7 10 * @author 20412
... ... @@ -10,4 +13,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
10 13 */
11 14 public interface GarOrderEvaluateService extends IService<GarOrderEvaluate> {
12 15  
  16 + List<GarOrderEvaluate> queryEvaluateByEnterpriseIds( List<Long> enterpriseIds, Integer value);
13 17 }
... ...
trash-garbage/src/main/java/com/trash/garbage/service/GarOrderService.java
... ... @@ -2,6 +2,7 @@ package com.trash.garbage.service;
2 2  
3 3 import com.baomidou.mybatisplus.extension.service.IService;
4 4 import com.github.pagehelper.PageInfo;
  5 +import com.trash.enterprise.domain.TransportationEnterprise;
5 6 import com.trash.garbage.pojo.domain.GarOrder;
6 7 import com.trash.garbage.pojo.dto.*;
7 8 import com.trash.garbage.pojo.vo.OrderDetailVo;
... ... @@ -60,4 +61,6 @@ public interface GarOrderService extends IService&lt;GarOrder&gt; {
60 61 PageInfo queryOrderListByGarOrderPage(OrderWebDto dto);
61 62  
62 63 OrderDetailVo queryOrderWebDetail(String id);
  64 +
  65 + PageInfo queryEnterpriseList(TransportationEnterprise enterprise);
63 66 }
... ...
trash-garbage/src/main/java/com/trash/garbage/service/impl/GarOrderEvaluateServiceImpl.java
1 1 package com.trash.garbage.service.impl;
2 2  
  3 +import cn.hutool.core.collection.CollectionUtil;
3 4 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
4 5 import com.trash.garbage.pojo.domain.GarOrderEvaluate;
5 6 import com.trash.garbage.service.GarOrderEvaluateService;
6 7 import com.trash.garbage.mapper.GarOrderEvaluateMapper;
7 8 import org.springframework.stereotype.Service;
8 9  
  10 +import java.util.ArrayList;
  11 +import java.util.List;
  12 +
9 13 /**
10 14 * @author 20412
11 15 * @description 针对表【gar_order_evaluate(建筑垃圾-派单评分)】的数据库操作Service实现
... ... @@ -15,6 +19,13 @@ import org.springframework.stereotype.Service;
15 19 public class GarOrderEvaluateServiceImpl extends ServiceImpl<GarOrderEvaluateMapper, GarOrderEvaluate>
16 20 implements GarOrderEvaluateService{
17 21  
  22 + @Override
  23 + public List<GarOrderEvaluate> queryEvaluateByEnterpriseIds(List<Long> enterpriseIds, Integer value) {
  24 + if (CollectionUtil.isEmpty(enterpriseIds)){
  25 + return new ArrayList<>();
  26 + }
  27 + return baseMapper.queryEvaluateByEnterpriseIds(enterpriseIds,value);
  28 + }
18 29 }
19 30  
20 31  
... ...
trash-garbage/src/main/java/com/trash/garbage/service/impl/GarOrderServiceImpl.java
1 1 package com.trash.garbage.service.impl;
2 2  
3   -import java.util.ArrayList;
4   -import java.util.Collections;
5   -import java.util.List;
6   -import java.util.Objects;
  3 +import java.util.*;
  4 +import java.util.stream.Collectors;
7 5  
8 6 import com.trash.enterprise.domain.TransportationEnterprise;
9 7 import com.trash.enterprise.service.ITransportationEnterpriseService;
10 8 import com.trash.garbage.pojo.dto.*;
  9 +import com.trash.garbage.pojo.vo.TransportationEnterpriseVo;
11 10 import org.apache.commons.lang3.StringUtils;
12 11 import org.springframework.beans.factory.annotation.Autowired;
13 12 import org.springframework.stereotype.Service;
... ... @@ -50,6 +49,9 @@ public class GarOrderServiceImpl extends ServiceImpl&lt;GarOrderMapper, GarOrder&gt;
50 49 private GarOrderImageService garOrderImageService;
51 50  
52 51 @Autowired
  52 + private ITransportationEnterpriseService transportationEnterpriseService;
  53 +
  54 + @Autowired
53 55 private GarOrderEvaluateService garOrderEvaluateService;
54 56  
55 57 @Autowired
... ... @@ -321,12 +323,67 @@ public class GarOrderServiceImpl extends ServiceImpl&lt;GarOrderMapper, GarOrder&gt;
321 323 return vo;
322 324 }
323 325  
  326 + @Override
  327 + public PageInfo queryEnterpriseList(TransportationEnterprise enterprise) {
  328 + List<TransportationEnterprise> list = transportationEnterpriseService.selectTransportationEnterpriseList(enterprise);
  329 + long total = new PageInfo<>(list).getTotal();
  330 + List<Long> enterpriseIds = list.stream().map(TransportationEnterprise::getId).collect(Collectors.toList());
  331 + List<GarOrder> orderList = baseMapper.queryCleanNumberByEnterpriseIds(enterpriseIds, GlobalStatus.GarOrderStatus.SUCCESS_ORDER.getValue());
  332 + List<GarOrderEvaluate> evaluateList = garOrderEvaluateService.queryEvaluateByEnterpriseIds(enterpriseIds, GlobalStatus.GarOrderStatus.EVALUATE_TYPE_COMPANY.getValue());
  333 + Map<String, List<GarOrderEvaluate>> evaluateMap = new HashMap<>();
  334 + for (GarOrderEvaluate garOrderEvaluate : evaluateList) {
  335 + List<GarOrderEvaluate> evaluate = evaluateMap.get(garOrderEvaluate.getGarCompanyId());
  336 + if (CollectionUtil.isEmpty(evaluate)) {
  337 + evaluateMap.put(garOrderEvaluate.getGarCompanyId(), new ArrayList<>(Arrays.asList(garOrderEvaluate)));
  338 + } else {
  339 + evaluate.add(garOrderEvaluate);
  340 + }
  341 + }
  342 +
  343 + List<TransportationEnterpriseVo> voList = list.stream().map(item -> {
  344 + TransportationEnterpriseVo vo = new TransportationEnterpriseVo();
  345 + BeanUtils.copyProperties(item, vo);
  346 + List<GarOrderEvaluate> evaluate = evaluateMap.get(String.valueOf(item.getId()));
  347 + handleCleanNumber(vo, orderList);
  348 + handleScore(vo, evaluate);
  349 + return vo;
  350 + })
  351 + .collect(Collectors.toList());
  352 + PageInfo<TransportationEnterpriseVo> pageInfo = new PageInfo<>();
  353 + pageInfo.setList(voList);
  354 + pageInfo.setTotal(total);
  355 + return pageInfo;
  356 + }
  357 +
  358 + private void handleCleanNumber(TransportationEnterpriseVo vo, List<GarOrder> orderList) {
  359 + Long cleanNumber = 0L;
  360 + for (GarOrder order : orderList) {
  361 + if (vo.getId().toString().equals(order.getGarOrderCompanyId())) {
  362 + cleanNumber = order.getCount();
  363 + }
  364 + }
  365 + vo.setCleanNumber(cleanNumber.intValue());
  366 + }
  367 +
  368 + private void handleScore(TransportationEnterpriseVo vo, List<GarOrderEvaluate> evaluate) {
  369 + int score = 0;
  370 + if (CollectionUtil.isNotEmpty(evaluate)) {
  371 + for (GarOrderEvaluate orderEvaluate : evaluate) {
  372 + score += orderEvaluate.getGarEvaluateScore();
  373 + }
  374 + vo.setScore(score / evaluate.size());
  375 + } else {
  376 + vo.setScore(score);
  377 + }
  378 + }
  379 +
324 380 private void evaluate(EvaluateDto dto, GarOrder order, GarUser user) {
325 381 GarOrderEvaluate evaluate = new GarOrderEvaluate();
326 382 evaluate.setGarOrderId(order.getGarOrderId());
327 383 evaluate.setGarEvaluateContent(dto.getContent());
328 384 evaluate.setGarEvaluateScore(dto.getScore());
329 385 evaluate.setGarCompanyId(order.getGarOrderCompanyId());
  386 + evaluate.setGarEvaluateTarget(dto.getEvaluateType());
330 387 garOrderEvaluateService.save(evaluate);
331 388 // 修改订单评价状态
332 389 LambdaUpdateWrapper<GarOrder> uw = new LambdaUpdateWrapper<>();
... ...
trash-garbage/src/main/resources/mapper/GarOrderEvaluateMapper.xml
... ... @@ -5,21 +5,35 @@
5 5 <mapper namespace="com.trash.garbage.mapper.GarOrderEvaluateMapper">
6 6  
7 7 <resultMap id="BaseResultMap" type="com.trash.garbage.pojo.domain.GarOrderEvaluate">
8   - <id property="garEvaluateId" column="gar_evaluate_id" jdbcType="VARCHAR"/>
9   - <result property="garEvaluateContent" column="gar_evaluate_content" jdbcType="VARCHAR"/>
10   - <result property="garOrderId" column="gar_order_id" jdbcType="VARCHAR"/>
11   - <result property="garEvaluateScore" column="gar_evaluate_score" jdbcType="TINYINT"/>
12   - <result property="garUpdateBy" column="gar_update_by" jdbcType="VARCHAR"/>
13   - <result property="garCreateBy" column="gar_create_by" jdbcType="VARCHAR"/>
14   - <result property="garUpdateTime" column="gar_update_time" jdbcType="TIMESTAMP"/>
15   - <result property="garCreateTime" column="gar_create_time" jdbcType="TIMESTAMP"/>
16   - <result property="garRemark" column="gar_remark" jdbcType="VARCHAR"/>
17   - <result property="garCompanyId" column="gar_company_id" jdbcType="VARCHAR"/>
  8 + <id property="garEvaluateId" column="gar_evaluate_id" jdbcType="VARCHAR"/>
  9 + <result property="garEvaluateContent" column="gar_evaluate_content" jdbcType="VARCHAR"/>
  10 + <result property="garOrderId" column="gar_order_id" jdbcType="VARCHAR"/>
  11 + <result property="garEvaluateScore" column="gar_evaluate_score" jdbcType="TINYINT"/>
  12 + <result property="garEvaluateTarget" column="gar_evaluate_target" jdbcType="TINYINT"/>
  13 + <result property="garUpdateBy" column="gar_update_by" jdbcType="VARCHAR"/>
  14 + <result property="garCreateBy" column="gar_create_by" jdbcType="VARCHAR"/>
  15 + <result property="garUpdateTime" column="gar_update_time" jdbcType="TIMESTAMP"/>
  16 + <result property="garCreateTime" column="gar_create_time" jdbcType="TIMESTAMP"/>
  17 + <result property="garRemark" column="gar_remark" jdbcType="VARCHAR"/>
  18 + <result property="garCompanyId" column="gar_company_id" jdbcType="VARCHAR"/>
18 19 </resultMap>
19 20  
20 21 <sql id="Base_Column_List">
21   - gar_evaluate_id,gar_evaluate_content,gar_evaluate_score,
  22 + gar_evaluate_id
  23 + ,gar_evaluate_content,gar_evaluate_score,
22 24 gar_update_by,gar_create_by,gar_update_time,
23   - gar_create_time,gar_remark,gar_order_id,gar_company_id
  25 + gar_create_time,gar_remark,gar_order_id,gar_company_id,gar_evaluate_target
24 26 </sql>
  27 + <select id="queryEvaluateByEnterpriseIds" resultType="com.trash.garbage.pojo.domain.GarOrderEvaluate">
  28 + select
  29 + <include refid="Base_Column_List"></include>
  30 + from gar_order_evaluate
  31 + where gar_evaluate_target = #{type}
  32 + and gar_create_time &gt;= date_sub(curdate(), interval 1 month)
  33 + and gar_create_time &lt;= DATE_FORMAT(NOW(),'%Y-%m-%d 23:59:59')
  34 + and gar_company_id in
  35 + <foreach collection="list" item="item" separator="," open="(" close=")">
  36 + #{item}
  37 + </foreach>
  38 + </select>
25 39 </mapper>
... ...
trash-garbage/src/main/resources/mapper/GarOrderMapper.xml
... ... @@ -41,4 +41,14 @@
41 41 gar_create_by,gar_update_by,gar_remark,gar_reason,gar_cancel_flag,
42 42 gar_evaluate_flag,gar_order_car_number,gar_order_car_type,gar_handler_evaluate_flag
43 43 </sql>
  44 + <select id="queryCleanNumberByEnterpriseIds" resultType="com.trash.garbage.pojo.domain.GarOrder">
  45 + select gar_order_company_id, count(gar_order_company_id) as count
  46 + from gar_order
  47 + where gar_order_handler_status = #{status}
  48 + and gar_order_company_id in
  49 + <foreach collection="list" item="item" open="(" separator="," close=")">
  50 + #{item}
  51 + </foreach>
  52 + group by gar_order_company_id
  53 + </select>
44 54 </mapper>
... ...