Commit 821d102d authored by linruibiao's avatar linruibiao

接口编写

parent d98bdd71
package com.syc.slm.slmbi.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.syc.slm.slmbi.entity.InstrumentPanel;
import javax.servlet.http.HttpServletRequest;
/**
* slm-bi
* 仪表板
*
* @author : lin
* @date : 2021-03-25 16:17
**/
public interface InstrumentPanelInitService extends IService<InstrumentPanel> {
String initOnePanel(String appId, HttpServletRequest request);
}
package com.syc.slm.slmbi.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.google.gson.reflect.TypeToken;
import com.syc.slm.common.core.constant.SlmConstants;
import com.syc.slm.slmbi.dao.InstrumentPanelMapper;
import com.syc.slm.slmbi.dto.*;
import com.syc.slm.slmbi.entity.BaseEntity;
import com.syc.slm.slmbi.entity.CurrentUser;
import com.syc.slm.slmbi.entity.InstrumentPanel;
import com.syc.slm.slmbi.entity.InstrumentPanelGroup;
import com.syc.slm.slmbi.enums.AccessType;
import com.syc.slm.slmbi.service.InstrumentPanelConfigService;
import com.syc.slm.slmbi.service.InstrumentPanelGroupService;
import com.syc.slm.slmbi.service.InstrumentPanelInitService;
import com.syc.slm.slmbi.service.InstrumentPanelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
/**
* slm-bi
* 仪表板
*
* @author : lin
* @date : 2021-03-25 16:17
**/
@Slf4j
@Service
public class InstrumentPanelInitServiceImpl extends ServiceImpl<InstrumentPanelMapper, InstrumentPanel>
implements InstrumentPanelInitService {
@Value("${}")
private String initGroupName;
@Value("${}")
private String initPanelName1;
@Value("${}")
private String initPanelName2;
@Value("${}")
private String initConfig1;
@Value("${}")
private String initConfig2;
@Autowired
private InstrumentPanelConfigService configService;
@Autowired
private InstrumentPanelGroupService panelGroupService;
@Autowired
private InstrumentPanelService panelService;
@Override
@Transactional(rollbackFor = Exception.class)
public String initOnePanel(String appId, HttpServletRequest request) {
CurrentUser currentUser = new CurrentUser();
request.setAttribute(IdWorker.get32UUID(),SlmConstants.gson.toJson(currentUser));
LambdaQueryWrapper<InstrumentPanelGroup> groupWhere = new LambdaQueryWrapper<>();
groupWhere.eq(InstrumentPanelGroup::getName, initGroupName);
groupWhere.eq(BaseEntity::getRecordStatus, SlmConstants.DATA_VALID);
groupWhere.eq(BaseEntity::getAppId, appId);
InstrumentPanelGroup one = panelGroupService.getOne(groupWhere);
if(ObjectUtils.isEmpty(one)){
LambdaQueryWrapper<InstrumentPanelGroup> where = new LambdaQueryWrapper<>();
where.eq(InstrumentPanelGroup::getName, "全部分组");
where.eq(BaseEntity::getRecordStatus, SlmConstants.DATA_VALID);
where.eq(BaseEntity::getAppId, appId);
InstrumentPanelGroup allGroup = panelGroupService.getOne(where);
InstrumentPanelGroupDTO cGroup = new InstrumentPanelGroupDTO();
cGroup.setParentId(allGroup.getId());
cGroup.setName("默认模板");
String groupId = panelGroupService.saveGroup(cGroup, appId);
one= panelGroupService.getById(groupId);
}
LambdaQueryWrapper<InstrumentPanel> where1 = new LambdaQueryWrapper<>();
where1.eq(BaseEntity::getAppId, appId);
where1.eq(InstrumentPanel::getName, initPanelName1);
where1.eq(BaseEntity::getRecordStatus, SlmConstants.DATA_VALID);
InstrumentPanel panel = baseMapper.selectOne(where1);
if(ObjectUtils.isEmpty(panel)){
configService.publish(appId,setConfig(one,appId,initPanelName2,initConfig2));
}
LambdaQueryWrapper<InstrumentPanel> where2 = new LambdaQueryWrapper<>();
where2.eq(BaseEntity::getAppId, appId);
where2.eq(InstrumentPanel::getName, initPanelName2);
where2.eq(BaseEntity::getRecordStatus, SlmConstants.DATA_VALID);
InstrumentPanel panel2 = baseMapper.selectOne(where2);
if(ObjectUtils.isEmpty(panel2)){
configService.publish(appId,setConfig(one,appId,initPanelName2,initConfig2));
}
return null;
}
private InstrumentPanelConfigDTO setConfig(InstrumentPanelGroup one , String appId, String panelName, String panelConfig){
SaveInstrumentPanelDTO panelDto = new SaveInstrumentPanelDTO();
panelDto.setName(panelName);
panelDto.setGroupId(one.getId());
String panelId = panelService.savePanel(appId, panelDto);
InstrumentPanel instrumentPanel = baseMapper.selectById(panelId);
InstrumentPanelConfigDTO config = new InstrumentPanelConfigDTO();
Map<String,Object> map = SlmConstants.gson.fromJson(panelConfig,new TypeToken<Map<String,Object>>(){}.getType());
List<Object> controlList = (List<Object>)map.get("ControlList");
List<InstrumentPanelAssemblyDTO> assemblys = Lists.newArrayList();
for (int i = 0; i < controlList.size(); i++) {
Map<String,Object> controlMap = SlmConstants.gson.fromJson(SlmConstants.gson.toJson(controlList.get(i)),new TypeToken<Map<String,Object>>(){}.getType());
Map<String,String> propertyList = SlmConstants.gson.fromJson(SlmConstants.gson.toJson(controlMap.get("PropertyList")),new TypeToken<Map<String,String>>(){}.getType());
InstrumentPanelAssemblyDTO instrumentPanelAssemblyDTO = new InstrumentPanelAssemblyDTO();
instrumentPanelAssemblyDTO.setKey(i+"");
instrumentPanelAssemblyDTO.setName(propertyList.get("ComName"));
}
config.setAssemblys(assemblys);
config.setConfigDetails(panelConfig);
config.setPanelId(instrumentPanel.getId());
InstrumentPanelPermissionDTO permission = new InstrumentPanelPermissionDTO();
permission.setAccessType(AccessType.PUBLIC.value);
permission.setDescription("系统初始化");
permission.setGroupId(one.getId());
permission.setPanelId(instrumentPanel.getId());
permission.setPanelName(instrumentPanel.getName());
config.setPermission(permission);
return config;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment