jiaosong
2023-08-18 6e7c27daee1d3ea051177bae04d64237e03e2e5a
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
package doumeemes.service.ext.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import doumeemes.core.constants.ResponseStatus;
import doumeemes.core.exception.BusinessException;
import doumeemes.core.model.LoginUserInfo;
import doumeemes.core.model.PageData;
import doumeemes.core.model.PageWrap;
import doumeemes.core.utils.Constants;
import doumeemes.core.utils.DateUtil;
import doumeemes.core.utils.redis.RedisUtil;
import doumeemes.dao.business.WOutboundMapper;
import doumeemes.dao.business.WTransferMapper;
import doumeemes.dao.business.WorkorderMapper;
import doumeemes.dao.business.dto.statistics.StatisticsPlanDataModel;
import doumeemes.dao.business.dto.statistics.Unqualified7DayModel;
import doumeemes.dao.business.dto.statistics.UserProduceTopModel;
import doumeemes.dao.business.model.*;
import doumeemes.dao.ext.*;
import doumeemes.dao.ext.dto.QueryBarcodeParamExtDTO;
import doumeemes.dao.ext.dto.QueryCompanyExtDTO;
import doumeemes.dao.ext.dto.QueryWorkPlansDTO;
import doumeemes.dao.ext.dto.QueryWorkorderRecordExtDTO;
import doumeemes.dao.ext.vo.BarcodeParamContent;
import doumeemes.dao.ext.vo.BarcodeParamExtListVO;
import doumeemes.dao.ext.vo.CompanyExtListVO;
import doumeemes.dao.ext.vo.DepartmentExtListVO;
import doumeemes.service.ext.BarcodeParamExtService;
import doumeemes.service.ext.DepartmentExtService;
import doumeemes.service.ext.StatisticsService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
/**
 * 二维码设置Service实现
 * @author 江蹄蹄
 * @date 2022/04/20 11:01
 */
@Service
public class StatisticsServiceImpl implements StatisticsService {
 
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
    @Autowired
    private WorkPlansExtMapper workPlansExtMapper;
    @Autowired
    private WorkorderRecordExtMapper workorderRecordExtMapper;
    @Autowired
    private DepartmentExtService departmentExtService;
 
    @Override
    public StatisticsPlanDataModel getPlansData(Integer companyId, Integer departId) {
        DepartmentExtListVO department =   departmentExtService.getModelById(companyId,departId);
        if(department == null || Constants.equalsInteger(department.getDeleted(), Constants.ONE)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,企业或者部门信息不合法,如有疑问,请联系系统管理员");
        }
        QueryWorkPlansDTO workPlans = new QueryWorkPlansDTO();
        workPlans.setRootDepartId(department.getRootId());
        workPlans.setDepartId(departId);
        //查询统计结果
        StatisticsPlanDataModel model = workPlansExtMapper.getPlansStaticticsData(workPlans);
        model.setUnqualifiedNum(new BigDecimal(0));
        if(model.getDoneNUm() !=null && model.getDoneNUm().compareTo(new BigDecimal(0)) != 0){
            //不良品率
            model.setUnqualifiedRate(model.getUnqualifiedNum().divide(model.getDoneNUm(),4).multiply(new BigDecimal(100)));
        }
        return  model;
    }
    @Override
    public List<UserProduceTopModel> getUserProduceTopData(Integer companyId, Integer departId) {
        DepartmentExtListVO department =   departmentExtService.getModelById(companyId,departId);
        if(department == null || Constants.equalsInteger(department.getDeleted(), Constants.ONE)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,企业或者部门信息不合法,如有疑问,请联系系统管理员");
        }
        QueryWorkorderRecordExtDTO param = new QueryWorkorderRecordExtDTO();
        param.setRootDepartId(department.getRootId());
        param.setDepartId(departId);
        //查询统计结果
        List<UserProduceTopModel> model = workorderRecordExtMapper.getUserProduceTopData(param);
 
        return  model;
    }
    @Override
    public List<Unqualified7DayModel> getUnqualified7DayData(Integer companyId, Integer departId) {
        DepartmentExtListVO department =   departmentExtService.getModelById(companyId,departId);
        if(department == null || Constants.equalsInteger(department.getDeleted(), Constants.ONE)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,企业或者部门信息不合法,如有疑问,请联系系统管理员");
        }
        QueryWorkorderRecordExtDTO param = new QueryWorkorderRecordExtDTO();
        param.setRootDepartId(department.getRootId());
        param.setDepartId(departId);
        //查询统计结果
        List<Unqualified7DayModel> model = workorderRecordExtMapper.getUnqualified7DayData(param);
        List<Unqualified7DayModel> result = new ArrayList<>();
        Date date = DateUtil.getCurrentDate();
        for (int i = 0; i < 7; i++) {
            Date td = DateUtil.addDaysToDate(date, 7-i);
            Unqualified7DayModel m = getReusltModelByDate(td,model);
            if(m == null){
                m = new Unqualified7DayModel();
                m.setCreateTime(td);
                m.setUnqualifiedNum(new BigDecimal(0));
            }
            result.add(m);
        }
 
        return  model;
    }
 
    private Unqualified7DayModel getReusltModelByDate(Date td, List<Unqualified7DayModel> model ) {
        if(model !=null){
            for(Unqualified7DayModel m : model){
                if(StringUtils.equals(DateUtil.getShortTime(td),DateUtil.getShortTime(m.getCreateTime()))){
                    return m;
                }
            }
        }
        return null;
    }
 
}