whycxzp
2023-05-15 f0c7d8c27776ec430ee0a42b7d07599d8ab389a2
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.mapper.FaultUploadMapper;
import com.whyc.pojo.FaultUpload;
import com.whyc.util.ActionUtil;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
 
@Service
public class FaultUploadService {
 
    @Resource
    private FaultUploadMapper mapper;
 
    public Response add(FaultUpload fault) {
        int userId = ActionUtil.getUser().getUId().intValue();
        Date now = new Date();
        fault.setUploadUserId(userId);
        fault.setCreateTime(now);
        mapper.insert(fault);
        return new Response().setII(1,"上传完成");
    }
 
    public Response updateConfirm(FaultUpload fault) {
        int userId = ActionUtil.getUser().getUId().intValue();
        Date now = new Date();
        fault.setConfirmUserId(userId);
        fault.setConfirmTime(now);
        mapper.updateById(fault);
        return new Response().setII(1,"确认完成");
    }
 
    public Response listPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        int userId = ActionUtil.getUser().getUId().intValue();
        /*QueryWrapper<FaultUpload> query = Wrappers.query();
        query.eq("upload_user_id",userId);
        List<FaultUpload> faultUploads = mapper.selectList(query);*/
        List<FaultUpload> faultUploads = mapper.getList(userId);
        PageInfo<FaultUpload> pageInfo = new PageInfo<>(faultUploads);
        return new Response().set(1,pageInfo);
    }
 
    public Response getTypeNum() {
        int userId = ActionUtil.getUser().getUId().intValue();
        List<FaultUpload> faultUploads = mapper.getList(userId);
        Map<Integer, List<FaultUpload>> typeListMap = faultUploads.stream().collect(Collectors.groupingBy(FaultUpload::getType));
        Map<Integer,Integer> typeMap = new HashMap<>();
        Set<Integer> typeSet = typeListMap.keySet();
        for (Integer type : typeSet) {
            typeMap.put(type,typeListMap.get(type).size());
        }
        return new Response().set(1,typeMap);
 
    }
}