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
package org.jeecg.modules.dnc.service.impl;
 
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.dnc.entity.*;
import org.jeecg.modules.dnc.exception.ExceptionCast;
import org.jeecg.modules.dnc.mapper.PartsInfoMapper;
import org.jeecg.modules.dnc.mapper.WorkStepMapper;
import org.jeecg.modules.dnc.response.CommonCode;
import org.jeecg.modules.dnc.response.ProcessInfoCode;
import org.jeecg.modules.dnc.response.ProductInfoCode;
import org.jeecg.modules.dnc.response.UcenterCode;
import org.jeecg.modules.dnc.service.IPartsInfoService;
import org.jeecg.modules.dnc.service.IPermissionStreamService;
import org.jeecg.modules.dnc.service.IWorkStepService;
import org.jeecg.modules.dnc.utils.ValidateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.Collections;
import java.util.List;
 
/**
 * @Description: TODO
 * @Author: zhangherong
 * @Date: Created in 2020/9/20 9:19
 * @Version: 1.0
 * @Modified By:
 */
@Service
public class WorkStepServiceImpl extends ServiceImpl<WorkStepMapper, WorkStep> implements IWorkStepService {
 
    @Autowired
    private IPermissionStreamService permissionStreamService;
 
    @Override
    public List<WorkStep> getByUserPerms(String userId) {
        if(!ValidateUtil.validateString(userId))
            return Collections.emptyList();
        return super.getBaseMapper().getByUserPerms(userId);
    }
 
    /**
     * 根据用户id获取授权的工步信息
     * @param userId
     * @param queryParam 查询条件
     * @return
     */
    @Override
    public List<WorkStep> getByUserPerms(String userId,String queryParam){
        if(!ValidateUtil.validateString(userId))
            return Collections.emptyList();
        if(!ValidateUtil.validateString(queryParam))
            return Collections.emptyList();
        LambdaQueryWrapper<WorkStep> queryWrapper = Wrappers.lambdaQuery();
        if(ValidateUtil.validateString(queryParam)) {
            queryWrapper.and(wrapper->wrapper.like(WorkStep::getStepName, queryParam)
                    .or()
                    .like(WorkStep::getStepName, queryParam));
        }
        queryWrapper.orderByAsc(WorkStep::getCreateTime);
        return super.list(queryWrapper);
    }
 
    /**
     * 新增产品信息
     * @param workStep
     * @return
     */
    @Override
    public boolean addWorkStep(WorkStep workStep){
        if(workStep == null)
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        if(!ValidateUtil.validateString(workStep.getProductId()))
            ExceptionCast.cast(ProcessInfoCode.PROCESS_PRODUCT_NONE);
        if(!ValidateUtil.validateString(workStep.getComponentId()))
            ExceptionCast.cast(ProcessInfoCode.PROCESS_COMPONENT_NONE);
        if(!ValidateUtil.validateString(workStep.getStepName()))
            ExceptionCast.cast(ProcessInfoCode.PROCESS_NAME_NONE);
        if(!ValidateUtil.validateString(workStep.getStepCode()))
            ExceptionCast.cast(ProcessInfoCode.PROCESS_CODE_NONE);
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String userId = user.getId();
        if(!ValidateUtil.validateString(userId))
            ExceptionCast.cast(UcenterCode.UCENTER_ACCOUNT_NOT_EXIST);
        WorkStep en =getByWorkStepNo(workStep.getProcessId(), workStep.getCraftNo());
        if(en != null) {
            ExceptionCast.cast(ProcessInfoCode.WORKSTEP_NOT_EXIST);
        }
        boolean b =super.save(workStep);
        if(!b)
            ExceptionCast.cast(CommonCode.FAIL);
        //添加权限验证
        PermissionStream permissionStream = new PermissionStream();
        permissionStream.setUserId(userId);
        permissionStream.setProductId(workStep.getProductId());
        permissionStream.setComponentId(workStep.getComponentId());
        if (StrUtil.isNotEmpty(workStep.getPartsId())){
            permissionStream.setPartsId(workStep.getPartsId());
        }
        permissionStream.setProcessId(workStep.getProcessId());
        permissionStream.setStepId(workStep.getStepId());
        return permissionStreamService.save(permissionStream);
    }
 
    /**
     * 编辑产品信息
     * @param id
     * @param workStep
     * @return
     */
    @Override
    public boolean editWorkStep(String id ,WorkStep workStep){
        if(!ValidateUtil.validateString(id) || workStep == null)
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        if(!ValidateUtil.validateString(workStep.getStepName()))
            ExceptionCast.cast(ProcessInfoCode.PROCESS_NAME_NONE);
        WorkStep en = super.getById(id);
        if(en == null)
            ExceptionCast.cast(ProcessInfoCode.WORKSTEP_NOT_EXIST);
//        workStep.setStepId(id);
//        workStep.setProductId(null);
//        workStep.setComponentId(null);
//        workStep.setPartsId(null);
//        workStep.setProcessId(null);
//        workStep.setStepName(workStep.getStepName().toUpperCase());
//        workStep.setStepCode(null);
        return super.updateById(workStep);
    }
 
    @Override
    public WorkStep getByWorkStepNo(String processId,String craftNo){
        if(ValidateUtil.validateString(processId)) {
            List<WorkStep> list = super.lambdaQuery().eq(WorkStep::getProcessId, processId).eq(WorkStep::getCraftNo,craftNo).list();
            if(list == null || list.isEmpty())
                return null;
            return list.get(0);
        }
        return null;
 
    }
 
}