zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
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
package cn.autoform.web.service.customButton;
 
import cn.autoform.bean.ProcessState;
import cn.autoform.bean.power.AutoPowerButton;
import cn.autoform.bean.power.PowerButton;
import cn.autoform.db.entity.CustomButtonEntity;
import cn.autoform.web.client.FormClient;
import cn.autoform.web.mapper.customButton.CustomButtonMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
@Service
public class CustomButtonService {
    
    @Resource
    CustomButtonMapper customButtonMapper;
    @Autowired
    FormClient formClient;
    
    /**
     * 多条添加按钮方法
     * @param customButtons
     */
    public void addCustomButton(List<CustomButtonEntity> customButtons){    
        List<CustomButtonEntity> custs = new ArrayList<CustomButtonEntity>();
        for(CustomButtonEntity cust : customButtons){
            if(cust.getId()!=null && cust.getId()!=0){
                customButtonMapper.updateCustomButton(cust);
            }else{
                custs.add(cust);
            }
        }
        if(custs.size()>0){
            this.customButtonMapper.addCustomButton(custs);
        }
    }
    /**
     * 查询当前tenantId下所有按钮方法名 
     * @param entity
     * @return
     * @throws Exception 
     */
    public AutoPowerButton selectName(CustomButtonEntity entity, ProcessState state) throws Exception {
        List<CustomButtonEntity> list = customButtonMapper.selectName(entity);
        if("1".equals(entity.getSetting())){
            return new AutoPowerButton(list, new ArrayList<>());
        }
//        if("TJ".equals(entity.getType())){
//            return new AutoPowerButton(list, new ArrayList<>());
//        }
//        if(state == null){
//            return new AutoPowerButton(new ArrayList<>(), new ArrayList<>());
//        }
        PowerButton powerButton =formClient.getAllButton(entity.getFormID(), state);
 
        if(powerButton == null || powerButton.getShow() == null) {
            return new AutoPowerButton(new ArrayList<>(), new ArrayList<>());
        }
 
        return new AutoPowerButton(
                list.stream()
                        .filter(li -> powerButton.getShow().contains(li.getButtonId()) && !powerButton.getHide().contains(li.getButtonId()))
                        .collect(Collectors.toList())
                , new ArrayList<>(powerButton.getHide()));
    }
 
    /**
     * 根据Id逻辑删除
     * 
     */
    public int deleteCustomButton(int id){
        return customButtonMapper.deleteCustomButton(id);
    }
    
    /**
     * 多条修改按钮方法名
     * @param list
     * @return
     */
    public int updateCustomButton(List<CustomButtonEntity> list){
        int count = 0;
        for(CustomButtonEntity cu : list){
            count += customButtonMapper.updateCustomButton(cu);
        }
        return count;
    }
 
    public List<CustomButtonEntity> selectCustomButton(String sourceTenantId, String sourceFormId) {
        CustomButtonEntity customButtonEntity = new CustomButtonEntity();
        customButtonEntity.setTenantID(sourceTenantId);
        customButtonEntity.setFormID(sourceFormId);
        return customButtonMapper.selectName(customButtonEntity);
    }
}