Commit 73362b87 authored by linruibiao's avatar linruibiao

接口编写

parent 77f368c9
package com.syc.slm.common.core.constant;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
......@@ -12,7 +13,10 @@ import com.google.gson.GsonBuilder;
**/
public final class SlmConstants {
public static Gson gson = new GsonBuilder().create();
public static Gson gson = new GsonBuilder()
.setDateFormat("yyyy-MM-dd HH:mm:ss").create();
public static Gson gsonLowerCaseWithUnderscores = new GsonBuilder()
.setDateFormat("yyyy-MM-dd HH:mm:ss").setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
/**
* 启用
*/
......
package com.syc.slm.common.core.util;
import com.syc.slm.common.core.constant.SlmConstants;
import com.syc.slm.slmbi.exception.SysException;
import com.syc.slm.slmbi.function.Action0;
......@@ -14,6 +13,10 @@ import java.util.function.Supplier;
* @date : 2021-04-06 09:39
**/
public final class NetResponseUtils {
public static <T> R<T> call(Supplier<T> x) {
try {
return R.ok(x.get());
......
package com.syc.slm.common.core.util;
import java.util.Map;
import com.syc.slm.common.core.constant.SlmConstants;
import com.syc.slm.slmbi.exception.SysException;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import java.lang.reflect.Type;
import java.util.Map;
/**
* slm-bi
......@@ -15,7 +19,7 @@ import org.springframework.web.client.RestTemplate;
* @date : 2021-04-13 10:15
**/
public class RestTemplateUtils {
public final class RestTemplateUtils {
private static final RestTemplate REST_TEMPLATE = new RestTemplate();
......@@ -71,6 +75,32 @@ public class RestTemplateUtils {
return get(url, httpHeaders, responseType, uriVariables);
}
public static <TResult>TResult get(String url, Map<String, String> headerMap, final Type resultType, Map<String, ?> uriVariables) {
try {
ResponseEntity<String> response = get(url, headerMap, String.class, uriVariables);
if(response.getStatusCodeValue()==200){
if(resultType.equals(String.class)) {
return (TResult)response.getBody();
}
return SlmConstants.gson.fromJson(response.getBody(), resultType);
}
}
catch (Exception e) {
e.printStackTrace();
throw new SysException("出错啦,请联系管理员",e.toString());
}
return null;
}
/**
* 带请求头的GET请求调用方式
*
......
package com.syc.slm.slmbi.config;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.syc.slm.common.core.constant.SlmConstants;
import com.syc.slm.common.core.util.ServletUtils;
import com.syc.slm.slmbi.entity.CurrentUser;
import com.syc.slm.slmbi.exception.SysException;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import java.nio.channels.SelectableChannel;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Map;
import java.util.function.Supplier;
/**
......@@ -28,23 +38,44 @@ public class SysMetaObjectHandler implements MetaObjectHandler {
private static final String UPDATE_TIME = "updateTime";
private static final String RECORD_STATUS = "recordStatus";
private CurrentUser userInfo(){
HttpServletRequest request = ServletUtils.getHttpServletRequest();
Map<String, String> headerMap = ServletUtils.getHeaderMap(request);
if(CollectionUtils.isEmpty(headerMap)){
throw new SysException("头部不能为空");
}
String token =headerMap.get("token");
if(StringUtils.isBlank(token)){
throw new SysException("token不能为空");
}
Object currentUser = request.getSession().getAttribute(token);
CurrentUser user =null;
if(ObjectUtils.isNotEmpty(currentUser)){
user= SlmConstants.gson.fromJson(currentUser.toString(),CurrentUser.class);
}
if(ObjectUtils.isEmpty(user)){
throw new SysException("获取不到当前用户");
}
return user;
}
/**
* 插入使用
*/
@Override
public void insertFill(MetaObject metaObject) {
CurrentUser user = userInfo();
fillValue(metaObject,
ID,
() -> (metaObject.getValue(ID) == null ? IdWorker.get32UUID() : metaObject.getValue(ID)));
fillValue(metaObject,
APP_ID,
() -> (metaObject.getValue(APP_ID) == null ? "68d61d7f990e11eb847e88d7f63cc98f" : metaObject.getValue(APP_ID)));
() -> (metaObject.getValue(APP_ID) == null ? user.getAppId() : metaObject.getValue(APP_ID)));
fillValue(metaObject,
CREATOR,
() -> (metaObject.getValue(CREATOR) == null ? "68d61d7f990e11eb847e88d7f63cc98f" : metaObject.getValue(CREATOR)));
() -> (metaObject.getValue(CREATOR) == null ? user.getUid() : metaObject.getValue(CREATOR)));
fillValue(metaObject,
CREATOR_NAME,
() -> (metaObject.getValue(CREATOR_NAME) == null ? "小明" : metaObject.getValue(CREATOR_NAME)));
() -> (metaObject.getValue(CREATOR_NAME) == null ? user.getName() : metaObject.getValue(CREATOR_NAME)));
fillValue(metaObject,
CREATE_TIME,
() -> (metaObject.getValue(CREATE_TIME) == null ? new Date() : metaObject.getValue(CREATE_TIME)));
......@@ -55,8 +86,9 @@ public class SysMetaObjectHandler implements MetaObjectHandler {
@Override
public void updateFill(MetaObject metaObject) {
setFieldValByName(UPDATER, "68d61d7f990e11eb847e88d7f63cc98f", metaObject);
setFieldValByName(UPDATER_NAME, "小明",metaObject);
CurrentUser user = userInfo();
setFieldValByName(UPDATER, user.getUid(), metaObject);
setFieldValByName(UPDATER_NAME, user.getName(),metaObject);
setFieldValByName(UPDATE_TIME, new Date(), metaObject);
}
......
package com.syc.slm.slmbi.controller;
import com.google.common.collect.Maps;
import com.google.gson.reflect.TypeToken;
import com.syc.slm.common.core.constant.SlmConstants;
import com.syc.slm.common.core.util.NetResponseUtils;
import com.syc.slm.common.core.util.R;
import com.syc.slm.common.core.util.RestTemplateUtils;
import com.syc.slm.slmbi.entity.CurrentUser;
import com.syc.slm.slmbi.exception.SysException;
import com.syc.slm.slmbi.function.Action0;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.View;
import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
......@@ -24,19 +34,37 @@ import java.util.function.Supplier;
@Slf4j
public class BaseRestController {
/**
* 用户token
*/
protected String token;
protected String uid;
protected String platformId;
/**
* 用户信息
*/
protected CurrentUser currentUser;
@Value("${dc_client.host}")
protected String dcClientHost;
@Value("${dc_client.interfaces.positionListUrl}")
protected String positionListUrl;
@Value("${dc_client.interfaces.deptListUrl}")
protected String deptListUrl;
@Value("${dc_client.interfaces.getOfficeIds}")
protected String getOfficeIds;
@Value("${dc_client.interfaces.userTree}")
protected String userTree;
@Value("${dc_client.interfaces.variableList}")
protected String variableList;
@Value("${dc_client.interfaces.deviceList}")
protected String deviceList;
@Value("${dc_client.interfaces.deptsRoles}")
protected String deptsRoles;
@ModelAttribute
public void onInit(HttpServletRequest request) {
String uri = request.getRequestURI();
......@@ -51,10 +79,31 @@ public class BaseRestController {
while(headerValues.hasMoreElements()){
headers.put(headerName, headerValues.nextElement());
}
}
token=request.getHeader("token");
log.info("请求头参数--->>>>"+SlmConstants.gson.toJson(headers));
token=request.getHeader("token");
if(StringUtils.isEmpty(token)){
throw new SysException("token不能为空");
}
log.info("获取用户信息");
NativeWebRequest webRequest = new ServletWebRequest(request);
Map<String, String> map = (Map<String, String>) webRequest.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
// Map<String, Object> map = (Map<String, Object>) webRequest.getAttribute(View.PATH_VARIABLES, RequestAttributes.SCOPE_REQUEST);
Map<String,String> heads = Maps.newHashMap();
heads.put("token",token);
Map<String,String> uriVariables =Maps.newHashMap();
uriVariables.put("appId",map.get("appId")+"");
String getUrl =dcClientHost+"/{appId}/users/user-info";
R<Map<String,Object>> result = RestTemplateUtils.get(getUrl, heads, new TypeToken<R<Map<String,Object>>>() {}.getType(), uriVariables);
Map<String,Object> userInfo= result.detach();
currentUser = new CurrentUser();
currentUser.setUid(userInfo.get("uid")+"");
currentUser.setPlatformId(userInfo.get("platform_id")+"");
currentUser.setName(userInfo.get("real_name")+"");
currentUser.setAppId(userInfo.get("app_id")+"");
currentUser.setToken(token);
request.getSession().setAttribute(token, SlmConstants.gson.toJson(currentUser));
}
R<Object> call(Action0 action) {
return NetResponseUtils.call(action);
......
......@@ -34,7 +34,7 @@ public class InstrumentPanelTreeController extends BaseRestController {
@ApiOperation("显示已发布仪表板树==》(刚进入页面)")
@ApiImplicitParam(name = "appId", value = "租户id", required = true, dataTypeClass = String.class)
public R<List<PanelTreeNodeVo>> loadTrees(@PathVariable String appId) {
return call(() -> (treeService.loadTrees(appId)));
return call(() -> (treeService.loadTrees(appId,dcClientHost+deptsRoles,currentUser)));
}
@GetMapping("/search")
......@@ -46,7 +46,7 @@ public class InstrumentPanelTreeController extends BaseRestController {
@ApiImplicitParam(name = "name", value = "分组名称或者仪表板名称", dataTypeClass = String.class)})
public R<List<PanelTreeNodeVo>> loadTrees(@PathVariable String appId,
@RequestParam(value = "name", required = false) String name) {
return call(() -> (treeService.loadTrees(appId, name)));
return call(() -> (treeService.loadTrees(appId, name,dcClientHost+deptsRoles,currentUser)));
}
@GetMapping("/children")
......@@ -60,7 +60,7 @@ public class InstrumentPanelTreeController extends BaseRestController {
public R<List<PanelTreeNodeVo>> children(@PathVariable String appId,
@RequestParam("nodeId") String nodeId,
@RequestParam(value = "name", required = false) String name) {
return call(() -> (treeService.children(nodeId, name)));
return call(() -> (treeService.children(nodeId, name,dcClientHost+deptsRoles,currentUser)));
}
@GetMapping("/children-panel")
......
......@@ -37,7 +37,7 @@ public class TokenController extends BaseRestController{
public R<Map<String,Object>> token(String account,String password,Integer origin){
return call(()->{
Map<String ,Object> maps = Maps.newHashMap();
String uri ="http://apidev.sycdev.com/dc/user/token?account="+account+"&password="+password+"&origin="+origin;
String uri =dcClientHost+"/dc/user/token?account="+account+"&password="+password+"&origin="+origin;
ResponseEntity<Map> post = RestTemplateUtils.post(uri, Map.class);
if(ObjectUtils.isNotEmpty(post)){
Integer code = (int)post.getBody().get("code");
......
......@@ -29,12 +29,10 @@ public class UserController extends BaseRestController{
private UserService userService;
@GetMapping
@ApiOperation("用户查询")
@ApiImplicitParams({@ApiImplicitParam(name = "appId", value = "租户id", required = true,dataTypeClass = String.class),
@ApiImplicitParam(name = "userName", value = "用户名称",dataTypeClass = String.class)})
public R<List<UserTreeVo>> selectUserList(@PathVariable String appId,
@RequestParam(value = "userName", required = false) String userName) {
return call(()->(userService.selectUserList(appId,dcClientHost+userTree,token,userName)));
@ApiOperation("用户查询,左边树调用部门树不要传入部门名称,然后右边用户的搜索在页面匹配就好了,一开始会返回所有部门的用户回去")
@ApiImplicitParams({@ApiImplicitParam(name = "appId", value = "租户id", required = true,dataTypeClass = String.class)})
public R<List<UserTreeVo>> selectUserList(@PathVariable String appId) {
return call(()->(userService.selectUserList(appId,dcClientHost+userTree,token,null)));
}
}
......@@ -4,9 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.collect.Maps;
import com.syc.slm.common.core.util.R;
import com.syc.slm.common.core.util.RestTemplateUtils;
import com.syc.slm.slmbi.dto.HistoryVariableDTO;
import com.syc.slm.slmbi.dto.RealTimeVariableDTO;
import com.syc.slm.slmbi.dto.VariableDTO;
import com.syc.slm.slmbi.dto.*;
import com.syc.slm.slmbi.service.VariableService;
import com.syc.slm.slmbi.vo.*;
import io.swagger.annotations.Api;
......@@ -78,7 +76,7 @@ public class VariableController extends BaseRestController{
@ApiOperation("获取变量列表")
@ApiImplicitParam(name = "appId", value = "租户id", required = true,dataTypeClass = String.class)
public R<IPage<VariableVo>> getVariableList(@PathVariable String appId, VariableDTO variableDTO) {
return call(()->variableService.getVariableList(variableDTO));
return call(()->variableService.getVariableList(variableDTO,appId,token,dcClientHost+variableList));
}
@GetMapping("/real-time")
......@@ -90,7 +88,7 @@ public class VariableController extends BaseRestController{
}
@GetMapping("/source")
@ApiOperation("获取变量来源列表")
@ApiOperation("获取变量来源列表,默认值6")
@ApiImplicitParam(name = "appId", value = "租户id", required = true,dataTypeClass = String.class)
public R<List<VariableSourceVo>> getVariableSourceList(@PathVariable String appId) {
return call(()->variableService.getVariableSourceList());
......@@ -99,8 +97,8 @@ public class VariableController extends BaseRestController{
@GetMapping("/device")
@ApiOperation("获取变量所属设备列表")
@ApiImplicitParam(name = "appId", value = "租户id", required = true,dataTypeClass = String.class)
public R<List<VariableDeviceVo>> getVariableDeviceList(@PathVariable String appId) {
return call(()->(variableService.getVariableDeviceList()));
public R<IPage<VariableDeviceVo>> getVariableDeviceList(@PathVariable String appId, QueryPageDTO query) {
return call(()->(variableService.getVariableDeviceList(token,appId,dcClientHost+deviceList,query)));
}
@GetMapping("/history")
......
......@@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
......@@ -18,18 +19,17 @@ import java.util.Date;
@Data
@EqualsAndHashCode(callSuper = true)
public class QueryInstrumentPanelDTO extends QueryPageDTO {
@ApiModelProperty(value = "仪表板名称")
@ApiModelProperty(value = "仪表板名称,创建人名称,修改人名称")
private String name;
@ApiModelProperty(value = "仪表板归属分组")
private String groupId;
@ApiModelProperty(value = "创建人名称")
private String creatorName;
@ApiModelProperty(value = "修改人名称")
private String updaterName;
@ApiModelProperty(value = "修改时间开始")
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date updateTimeBegin;
@ApiModelProperty(value = "修改时间结束")
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date updateTimeEnd;
@ApiModelProperty(value = "发布状态")
private Integer published;
private String published;
}
......@@ -15,7 +15,7 @@ import lombok.EqualsAndHashCode;
@Data
@ApiModel(value = "变量DTO")
@EqualsAndHashCode(callSuper=false)
public class VariableDTO {
public class VariableDTO extends QueryPageDTO{
@ApiModelProperty(value = "变量来源")
private String sourceId;
@ApiModelProperty(value = "所属设备")
......@@ -24,4 +24,5 @@ public class VariableDTO {
private String variableName;
@ApiModelProperty(value = "描述")
private String description;
}
......@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......@@ -44,6 +45,7 @@ public class BaseEntity<T extends Model<?>> extends Model<T> {
protected String creatorName;
@ApiModelProperty(value = "创建时间")
@TableField(fill = FieldFill.INSERT)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
protected Date createTime;
@ApiModelProperty(value = "修改人主键")
@TableField(fill = FieldFill.UPDATE)
......@@ -53,6 +55,7 @@ public class BaseEntity<T extends Model<?>> extends Model<T> {
protected String updaterName;
@ApiModelProperty(value = "修改时间")
@TableField(fill = FieldFill.UPDATE)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
protected Date updateTime;
@ApiModelProperty(value = "状态")
@TableField(fill = FieldFill.INSERT)
......
......@@ -3,7 +3,8 @@ package com.syc.slm.slmbi.function;
import java.io.Serializable;
/**
* Created by Yeshirow on 2018-01-16.
* @author lin
* @date 2021/4/1
*/
public interface Action1<T> extends Serializable {
void call(T t);
......
......@@ -3,7 +3,8 @@ package com.syc.slm.slmbi.function;
import java.io.Serializable;
/**
* Created by Yeshirow on 2018-01-16.
* @author lin
* @date 2021/4/1
*/
public interface Action2<T1,T2> extends Serializable {
void call(T1 t1, T2 t2);
......
......@@ -2,6 +2,7 @@ package com.syc.slm.slmbi.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.syc.slm.slmbi.dto.InstrumentPanelAssemblyDTO;
import com.syc.slm.slmbi.entity.CurrentUser;
import com.syc.slm.slmbi.entity.InstrumentPanelTree;
import com.syc.slm.slmbi.vo.InstrumentPanelConfigVo;
import com.syc.slm.slmbi.vo.PanelTreeNodeVo;
......@@ -66,14 +67,14 @@ public interface InstrumentPanelTreeService extends IService<InstrumentPanelTree
* @param name
* @return
*/
List<PanelTreeNodeVo> loadTrees(String appId, String name);
List<PanelTreeNodeVo> loadTrees(String appId, String name, String uri,CurrentUser user);
/**
* 加载树
* @param appId
* @return
*/
List<PanelTreeNodeVo> loadTrees(String appId);
List<PanelTreeNodeVo> loadTrees(String appId,String uri,CurrentUser user);
/**
* 加载树节点下一节点
......@@ -81,7 +82,7 @@ public interface InstrumentPanelTreeService extends IService<InstrumentPanelTree
* @param name
* @return
*/
List<PanelTreeNodeVo> children(String groupId, String name);
List<PanelTreeNodeVo> children(String groupId, String name,String uri,CurrentUser user);
/**
* 根据仪表板分组id更新 fullId fullName
......
......@@ -2,6 +2,7 @@ package com.syc.slm.slmbi.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.syc.slm.slmbi.dto.HistoryVariableDTO;
import com.syc.slm.slmbi.dto.QueryPageDTO;
import com.syc.slm.slmbi.dto.RealTimeVariableDTO;
import com.syc.slm.slmbi.dto.VariableDTO;
import com.syc.slm.slmbi.vo.*;
......@@ -22,7 +23,7 @@ public interface VariableService {
* @param variableDTO
* @return
*/
IPage<VariableVo> getVariableList(VariableDTO variableDTO);
IPage<VariableVo> getVariableList(VariableDTO variableDTO,String appId,String token,String uri);
/**
* 获取变量来源
......@@ -32,9 +33,13 @@ public interface VariableService {
/**
* 获取变量所属设备
* @param token
* @param appId
* @param uri
* @param queryPageDTO
* @return
*/
List<VariableDeviceVo> getVariableDeviceList();
IPage<VariableDeviceVo> getVariableDeviceList(String token,String appId,String uri, QueryPageDTO queryPageDTO);
/**
* 获取实时数据
......
package com.syc.slm.slmbi.service.impl;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.google.common.collect.Maps;
import com.google.gson.reflect.TypeToken;
import com.syc.slm.common.core.constant.SlmConstants;
import com.syc.slm.common.core.util.R;
import com.syc.slm.common.core.util.RestTemplateUtils;
import com.syc.slm.slmbi.vo.DeptVo;
import com.syc.slm.slmbi.service.DeptService;
import com.syc.slm.slmbi.vo.PositionVo;
import org.springframework.http.ResponseEntity;
import com.syc.slm.slmbi.vo.DeptVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
......@@ -23,23 +20,21 @@ import java.util.Map;
* @date : 2021-03-25 18:41
**/
@Service
@Slf4j
public class DeptServiceImpl implements DeptService {
@Override
public List<DeptVo> selectPositionList(String uri, String token, String appId, String deptName) {
log.info("部门查询uri:---------------->"+uri);
log.info("部门查询token:---------------->"+token);
Map<String,String> heads = Maps.newHashMap();
heads.put("token",token);
Map<String,String> uriVariables =Maps.newHashMap();
uriVariables.put("deptName",deptName);
uriVariables.put("appId",appId);
R<List<DeptVo>> r = new R<>();
ResponseEntity<String> responseEntity = RestTemplateUtils.get(uri, heads, String.class, uriVariables);
if(ObjectUtils.isNotEmpty(responseEntity)){
String body = responseEntity.getBody();
r= SlmConstants.gson.fromJson(body, new TypeToken<R<List<DeptVo>>>(){}.getType());
}
return r.detach();
R<List<DeptVo>> result = RestTemplateUtils.get(uri, heads, new TypeToken<R<List<DeptVo>>>() {}.getType(), uriVariables);
return result.detach();
}
}
......@@ -12,6 +12,7 @@ import com.syc.slm.common.core.constant.SlmConstants;
import com.syc.slm.slmbi.dao.InstrumentPanelMapper;
import com.syc.slm.slmbi.dto.QueryInstrumentPanelDTO;
import com.syc.slm.slmbi.dto.SaveInstrumentPanelDTO;
import com.syc.slm.slmbi.entity.BaseEntity;
import com.syc.slm.slmbi.entity.InstrumentPanel;
import com.syc.slm.slmbi.entity.InstrumentPanelDraft;
import com.syc.slm.slmbi.entity.InstrumentPanelTree;
......@@ -32,6 +33,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* slm-bi
......@@ -71,15 +73,10 @@ public class InstrumentPanelServiceImpl extends ServiceImpl<InstrumentPanelMappe
where.eq("p.group_id", query.getGroupId());
where.eq("p.record_status", SlmConstants.DATA_VALID);
if (StringUtils.isNotEmpty(query.getName())) {
where.like("p.name", query.getName());
where.and(x->x.like("p.name", query.getName()).or().like("p.creator_name", query.getName()).or().like("p.updater_name", query.getName()));
}
if (StringUtils.isNotEmpty(query.getCreatorName())) {
where.like("p.creator_name", query.getCreatorName());
}
if (StringUtils.isNotEmpty(query.getUpdaterName())) {
where.like("p.updater_name", query.getUpdaterName());
}
if (query.getPublished() != null) {
if (StringUtils.isNotEmpty(query.getPublished())) {
where.eq("p.published", query.getPublished());
}
if (query.getUpdateTimeBegin() != null) {
......@@ -88,7 +85,29 @@ public class InstrumentPanelServiceImpl extends ServiceImpl<InstrumentPanelMappe
if (query.getUpdateTimeEnd() != null) {
where.le("p.update_time", query.getUpdateTimeEnd());
}
return baseMapper.selectInstrumentPanelList(page, where);
IPage<InstrumentPanelVo> response = baseMapper.selectInstrumentPanelList(page, where);
if(ObjectUtils.isNotEmpty(response)){
if(CollectionUtils.isNotEmpty(response.getRecords())){
Set<String> ids = response.getRecords()
.stream()
.filter(x -> "未发布".equals(x.getPublished()))
.map(BaseEntity::getId)
.collect(Collectors.toSet());
if(CollectionUtils.isNotEmpty(ids)){
List<InstrumentPanelDraft> drafts = draftService.getByIds(ids);
if(CollectionUtils.isNotEmpty(drafts)){
Set<String> draftIds = drafts.stream().map(InstrumentPanelDraft::getPanelId).collect(Collectors.toSet());
response.getRecords().forEach(x->{
if(draftIds.contains(x.getId())){
x.setHasWaitPublish("有未发布版本");
}
});
}
}
}
}
return response;
}
@Override
......
......@@ -11,6 +11,8 @@ import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.gson.reflect.TypeToken;
import com.syc.slm.common.core.constant.SlmConstants;
import com.syc.slm.common.core.util.R;
import com.syc.slm.common.core.util.RestTemplateUtils;
import com.syc.slm.slmbi.dao.InstrumentPanelTreeMapper;
import com.syc.slm.slmbi.dto.InstrumentPanelAssemblyDTO;
import com.syc.slm.slmbi.entity.*;
......@@ -18,10 +20,7 @@ import com.syc.slm.slmbi.enums.NodeType;
import com.syc.slm.slmbi.enums.PublishedStatus;
import com.syc.slm.slmbi.exception.SysException;
import com.syc.slm.slmbi.service.*;
import com.syc.slm.slmbi.vo.CustomPermissionVo;
import com.syc.slm.slmbi.vo.InstrumentPanelConfigVo;
import com.syc.slm.slmbi.vo.InstrumentPanelGroupVo;
import com.syc.slm.slmbi.vo.PanelTreeNodeVo;
import com.syc.slm.slmbi.vo.*;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.filefilter.FalseFileFilter;
......@@ -135,14 +134,18 @@ public class InstrumentPanelTreeServiceImpl extends ServiceImpl<InstrumentPanelT
}
@Override
public List<PanelTreeNodeVo> loadTrees(String appId, String name) {
public List<PanelTreeNodeVo> loadTrees(String appId, String name,String uri,CurrentUser user) {
if(StringUtils.isBlank(name)){
return loadTrees(appId);
return loadTrees(appId,uri,user);
}
List<PanelTreeNodeVo> lists = Lists.newArrayList();
String officeIds = null;
String userId = null;
String roleId = null;
R<Map<String, String>> result = setDeptAndRole(user, uri);
Map<String, String> detach = result.detach();
String userId=user.getUid();
String officeIds=detach.get("deptIds");
String roleId=detach.get("roleIds");
LambdaQueryWrapper<InstrumentPanelTree> where = new LambdaQueryWrapper<>();
where.eq(BaseEntity::getAppId, appId);
where.eq(BaseEntity::getRecordStatus, SlmConstants.DATA_VALID);
......@@ -192,11 +195,13 @@ public class InstrumentPanelTreeServiceImpl extends ServiceImpl<InstrumentPanelT
@Override
public List<PanelTreeNodeVo> loadTrees(String appId) {
public List<PanelTreeNodeVo> loadTrees(String appId,String uri,CurrentUser user) {
List<PanelTreeNodeVo> lists = Lists.newArrayList();
String officeIds=null;
String userId=null;
String roleId=null;
R<Map<String, String>> result = setDeptAndRole(user, uri);
Map<String, String> detach = result.detach();
String userId=user.getUid();
String officeIds=detach.get("deptIds");
String roleId=detach.get("roleIds");
LambdaQueryWrapper<InstrumentPanelTree> where = new LambdaQueryWrapper<>();
where.eq(BaseEntity::getAppId, appId);
where.eq(BaseEntity::getRecordStatus, SlmConstants.DATA_VALID);
......@@ -239,7 +244,7 @@ public class InstrumentPanelTreeServiceImpl extends ServiceImpl<InstrumentPanelT
break;
}
num++;
List<PanelTreeNodeVo> childrenNodes = this.children(groupId, null);
List<PanelTreeNodeVo> childrenNodes = this.children(groupId, null,uri,user);
if(CollectionUtils.isEmpty(childrenNodes)){
flag=false;
}
......@@ -267,11 +272,14 @@ public class InstrumentPanelTreeServiceImpl extends ServiceImpl<InstrumentPanelT
@Override
@Transactional(readOnly = true)
public List<PanelTreeNodeVo> children(String groupId, String name) {
public List<PanelTreeNodeVo> children(String groupId, String name,String uri,CurrentUser user) {
List<PanelTreeNodeVo> lists = Lists.newArrayList();
String officeIds = null;
String userId = null;
String roleId = null;
R<Map<String, String>> result = setDeptAndRole(user, uri);
Map<String, String> detach = result.detach();
String userId=user.getUid();
String officeIds=detach.get("deptIds");
String roleId=detach.get("roleIds");
InstrumentPanelTree tree = baseMapper.selectById(groupId);
LambdaQueryWrapper<InstrumentPanelTree> where = new LambdaQueryWrapper<>();
where.likeRight(InstrumentPanelTree::getFullId, tree.getFullId() + ".");
......@@ -404,4 +412,14 @@ public class InstrumentPanelTreeServiceImpl extends ServiceImpl<InstrumentPanelT
return CollectionUtils.isNotEmpty(filteredMaps.values())?SlmConstants.gson.fromJson(SlmConstants.gson.toJson(filteredMaps.values()), new TypeToken<List<PanelTreeNodeVo>>() {}.getType()):
Lists.newArrayList();
}
private R<Map<String,String>> setDeptAndRole(CurrentUser user,String uri){
Map<String,String> heads = Maps.newHashMap();
heads.put("token",user.getToken());
Map<String,String> uriVariables =Maps.newHashMap();
uriVariables.put("appId",user.getAppId());
return RestTemplateUtils.get(uri, heads, new TypeToken<R<Map<String,String>>>() {}.getType(), uriVariables);
}
}
......@@ -33,12 +33,7 @@ public class PositionServiceImpl implements PositionService {
uriVariables.put("positionName",name);
uriVariables.put("appId",appId);
R<List<PositionVo>> r = new R<>();
ResponseEntity<String> responseEntity = RestTemplateUtils.get(uri, heads, String.class, uriVariables);
if(ObjectUtils.isNotEmpty(responseEntity)){
String body = responseEntity.getBody();
r= SlmConstants.gson.fromJson(body,new TypeToken<R<List<PositionVo>>>(){}.getType());
}
return r.detach();
R<List<PositionVo>> result = RestTemplateUtils.get(uri, heads, new TypeToken<R<List<PositionVo>>>() {}.getType(), uriVariables);
return result.detach();
}
}
......@@ -31,13 +31,7 @@ public class UserServiceImpl implements UserService {
Map<String,String> uriVariables =Maps.newHashMap();
uriVariables.put("userName",userName);
uriVariables.put("appId",appId);
R<List<UserTreeVo>> r = new R<>();
ResponseEntity<String> responseEntity = RestTemplateUtils.get(uri, heads, String.class, uriVariables);
if(ObjectUtils.isNotEmpty(responseEntity)){
String body = responseEntity.getBody();
r= SlmConstants.gson.fromJson(body, new TypeToken<R<List<UserTreeVo>>>(){}.getType());
}
return r.detach();
R<List<UserTreeVo>> result = RestTemplateUtils.get(uri, heads, new TypeToken<R<List<UserTreeVo>>>() {}.getType(), uriVariables);
return result.detach();
}
}
package com.syc.slm.slmbi.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gson.reflect.TypeToken;
import com.syc.slm.common.core.constant.SlmConstants;
import com.syc.slm.common.core.util.R;
import com.syc.slm.common.core.util.RestTemplateUtils;
import com.syc.slm.slmbi.dto.HistoryVariableDTO;
import com.syc.slm.slmbi.dto.QueryPageDTO;
import com.syc.slm.slmbi.dto.RealTimeVariableDTO;
import com.syc.slm.slmbi.dto.VariableDTO;
import com.syc.slm.slmbi.service.VariableService;
import com.syc.slm.slmbi.vo.*;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
......@@ -21,18 +31,88 @@ import java.util.Map;
@Service
public class VariableServiceImpl implements VariableService {
@Override
public IPage<VariableVo> getVariableList(VariableDTO variableDTO) {
return null;
public IPage<VariableVo> getVariableList(VariableDTO variableDTO,String appId,String token,String uri) {
IPage<VariableVo> page = new Page<>(variableDTO.getCurrent(),variableDTO.getSize());
Map<String,String> p = Maps.newHashMap();
p.put("appId",appId);
p.put("token",token);
p.put("from",null);
p.put("varType",null);
p.put("type",null);
p.put("equipmentId",null);
p.put("customerId",null);
p.put("name",variableDTO.getVariableName());
p.put("desc",variableDTO.getDescription());
p.put("unit",null);
p.put("keyword",null);
p.put("isCustomer",null);
p.put("current",variableDTO.getCurrent()+"");
p.put("size",variableDTO.getSize()+"");
Map<String,String> heads = Maps.newHashMap();
heads.put("token",token);
R<Map<String, Object>> result = RestTemplateUtils.get(uri, heads, new TypeToken<R<Map<String, Object>>>() {
}.getType(), p);
Map<String, Object> detach = result.detach();
if (CollectionUtils.isNotEmpty(detach)) {
List<VariableVo> vos = SlmConstants.gsonLowerCaseWithUnderscores.fromJson(SlmConstants.gson.toJson(detach.get("datas")),
new TypeToken<List<VariableVo>>() {
}.getType());
page.setTotal((new BigDecimal(detach.get("total") + "")).longValue());
page.setRecords(vos);
}
return page;
}
@Override
public List<VariableSourceVo> getVariableSourceList() {
return null;
List<VariableSourceVo> vos = Lists.newArrayList();
VariableSourceVo vo = new VariableSourceVo();
vo.setSourceId("6");
vo.setSourceName("请选择变量来源");
VariableSourceVo vo1 = new VariableSourceVo();
vo1.setSourceId("1");
vo1.setSourceName("基础采集点");
VariableSourceVo vo2 = new VariableSourceVo();
vo2.setSourceId("4");
vo2.setSourceName("配置变量/dc公式");
vos.add(vo);
vos.add(vo1);
vos.add(vo2);
return vos;
}
@Override
public List<VariableDeviceVo> getVariableDeviceList() {
return null;
public IPage<VariableDeviceVo> getVariableDeviceList(String token,String appId,String uri, QueryPageDTO queryPageDTO) {
IPage<VariableDeviceVo> page = new Page<>(queryPageDTO.getCurrent(), queryPageDTO.getSize());
Map<String, String> p = Maps.newHashMap();
p.put("appId", appId);
p.put("token", token);
p.put("equipment_info_id", null);
p.put("customer_id", null);
p.put("q_name", null);
p.put("search_code", null);
p.put("search_model", null);
p.put("warranty_status", null);
p.put("page_num", queryPageDTO.getCurrent() + "");
p.put("page_size", queryPageDTO.getSize() + "");
Map<String, String> heads = Maps.newHashMap();
heads.put("token", token);
R<Map<String, Object>> result = RestTemplateUtils.get(uri, heads, new TypeToken<R<Map<String, Object>>>() {
}.getType(), p);
Map<String, Object> detach = result.detach();
if (CollectionUtils.isNotEmpty(detach)) {
List<VariableDeviceVo> vos = SlmConstants.gsonLowerCaseWithUnderscores.fromJson(SlmConstants.gson.toJson(detach.get("result")),
new TypeToken<List<VariableDeviceVo>>() {
}.getType());
page.setTotal((new BigDecimal(detach.get("total") + "")).longValue());
page.setRecords(vos);
}
return page;
}
@Override
......
......@@ -19,4 +19,6 @@ import lombok.EqualsAndHashCode;
public class InstrumentPanelVo extends InstrumentPanel {
@ApiModelProperty("分组名称")
private String groupName;
@ApiModelProperty("是否有待发布版本,有值就有,空就没有")
private String hasWaitPublish;
}
......@@ -16,8 +16,25 @@ import lombok.EqualsAndHashCode;
@ApiModel(value = "变量所属设备vo",description = "变量所属设备vo")
@EqualsAndHashCode(callSuper=false)
public class VariableDeviceVo {
@ApiModelProperty(value = "设备Id")
private String deviceId;
@ApiModelProperty(value = "简称")
private String breviaryName;
@ApiModelProperty(value = "质保时间")
private Long warrantyTime;
private String ancestorName;
@ApiModelProperty(value = "设备编号")
private String code;
@ApiModelProperty(value = "质保状态 1保内; 2保外;3未知;")
private String warrantyStatus;
@ApiModelProperty(value = "设备名称")
private String deviceName;
private String name;
private String pline;
@ApiModelProperty(value = "设备Id")
private String id;
@ApiModelProperty(value = "设备位置")
private String position;
@ApiModelProperty(value = "设备Id")
private String modelNo;
}
package com.syc.slm.slmbi.vo;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......@@ -16,22 +17,32 @@ import lombok.EqualsAndHashCode;
@ApiModel(value = "变量vo",description = "变量vo")
@EqualsAndHashCode(callSuper=false)
public class VariableVo {
@ApiModelProperty(value = "变量来源")
private String sourceName;
@ApiModelProperty(value = "变量名称")
private String variableName;
@ApiModelProperty(value = "描述")
private String description;
@ApiModelProperty(value = "所属设备id")
private String equipmentId;
@ApiModelProperty(value = "所属设备名称")
private String equipmentName;
@ApiModelProperty(value = "所属设备编号")
private String equipmentCode;
@ApiModelProperty(value = "数据类型")
private String type;
// @ApiModelProperty(value = "")
private String cusVariableType;
@ApiModelProperty(value = "单位")
private String unit;
@ApiModelProperty(value = "数据类型")
private String dataType;
@ApiModelProperty(value = "变量类型")
private String variableType;
@ApiModelProperty(value = "所属客户")
private String customer;
@ApiModelProperty(value = "所属设备")
private String deviceId;
@ApiModelProperty(value = "设备编号")
private String deviceCode;
private Integer varType;
@ApiModelProperty(value = "变量名称")
private String name;
@ApiModelProperty(value = "来源")
private Integer from;
@ApiModelProperty(value = "变量id")
private String id;
@ApiModelProperty(value = "所属客户名称")
private String customerName;
@ApiModelProperty(value = "所属客户id")
private String customerId;
@ApiModelProperty(value = "描述")
private String desc;
}
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