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);
|
}
|
}
|