Просмотр исходного кода

dcs车间单独一个表,不和设备位置公用

hfxc226 2 лет назад
Родитель
Сommit
f2e703e55f

+ 113 - 0
platform-dao/src/main/java/com/platform/dao/dto/remote/RemotePositionDTO.java

@@ -0,0 +1,113 @@
+package com.platform.dao.dto.remote;
+
+import com.platform.common.bean.BaseDTO;
+import com.platform.common.validation.group.UpdateGroup;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import javax.persistence.Transient;
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+/**
+ * @Description 设备位置DTO
+ * @Author liuyu
+ * @Date 2020-04-21 20:52:22
+ * @Version Copyright (c) 2019,北京乾元坤和科技有限公司 All rights reserved.
+ */
+@Data
+@Accessors(chain = true)
+@EqualsAndHashCode(callSuper = true)
+public class RemotePositionDTO extends BaseDTO implements Serializable {
+    /**
+     * opc标识:0否1是
+     */
+    private Integer opcFlag;
+    /**
+     * 车间opc图片
+     */
+    private String opcImg;
+    /**
+     * 防雷标识:0否1是
+     */
+    private Integer lightFlag;
+    /**
+     * 防雷图片
+     */
+    private String lightImg;
+    /**
+     * 区域维修负责人
+     */
+    private String userId;
+    /**
+     * 区域维修负责人
+     */
+    @Transient
+    private String userName;
+    /**
+     * 位置id
+     */
+    @NotNull(groups = {UpdateGroup.class}, message = "ID不能为空")
+    private String id;
+
+    /**
+     * 编码:位号
+     */
+    private String no;
+
+    /**
+     * 父子级编码
+     */
+    private String code;
+
+    /**
+     * 名称
+     */
+    private String name;
+
+    /**
+     * 类型 1:厂区 2:生产线
+     */
+    private Integer type;
+
+    /**
+     * 排序
+     */
+    private Integer sort;
+
+    /**
+     * 上层位置id
+     */
+    private String parentId;
+
+    /**
+     * 备注
+     */
+    private String remark;
+
+    /**
+     * 创建人
+     */
+    private String createdUserId;
+
+    /**
+     * 创建日期
+     */
+    private LocalDateTime createdTime;
+
+    /**
+     * 更新日期
+     */
+    private LocalDateTime updateTime;
+
+    /**
+     * 关键自
+     */
+    private String keyword;
+
+    private String parentCode;
+
+
+}

+ 124 - 0
platform-dao/src/main/java/com/platform/dao/entity/remote/RemotePosition.java

@@ -0,0 +1,124 @@
+package com.platform.dao.entity.remote;
+
+import com.platform.common.bean.DataScope;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+/**
+ * @Description 设备位置实体类
+ * @Author liuyu
+ * @Date 2020-04-21 20:52:22
+ * @Version Copyright (c) 2019,北京乾元坤和科技有限公司 All rights reserved.
+ */
+@Table(name = "t_remote_position")
+@Data
+@Accessors(chain = true)
+public class RemotePosition implements Serializable {
+    /**
+     * opc标识:0否1是
+     */
+    private Integer opcFlag;
+    /**
+     * 车间opc图片
+     */
+    private String opcImg;
+    /**
+     * 防雷标识:0否1是
+     */
+    private Integer lightFlag;
+    /**
+     * 防雷图片
+     */
+    private String lightImg;
+    /**
+     * 区域维修负责人
+     */
+    private String userId;
+    /**
+     * 区域维修负责人
+     */
+    @Transient
+    private String userName;
+    /**
+     * 位置id
+     */
+    @Id
+    private String id;
+    /**
+     * 编码
+     */
+    private String no;
+
+    /**
+     * 父子级编码
+     */
+    private String code;
+
+    /**
+     * 名称
+     */
+    private String name;
+    /**
+     * 类型 1:厂区 2:生产线
+     */
+    private Integer type;
+    /**
+     * 排序
+     */
+    private Integer sort;
+    /**
+     * 是否删除  -1:已删除  0:正常
+     */
+    private Integer delFlag;
+    /**
+     * 上层位置id
+     */
+    private String parentId;
+    /**
+     * 备注
+     */
+    private String remark;
+    /**
+     * 创建人
+     */
+    private String createdUserId;
+    /**
+     * 修改人
+     */
+    private String updateUserId;
+    /**
+     * 创建日期
+     */
+    private LocalDateTime createdTime;
+    /**
+     * 更新日期
+     */
+    private LocalDateTime updateTime;
+    /**
+     * 上层类型名称
+     */
+    @Transient
+    private String parentName;
+    /**
+     * 创建人姓名
+     */
+    @Transient
+    private String createdUserName;
+    /**
+     * 修改人姓名
+     */
+    @Transient
+    private String updateUserName;
+    /**
+     * 数据权限
+     */
+    @Transient
+    private DataScope dataScope;
+
+}

+ 45 - 0
platform-dao/src/main/java/com/platform/dao/mapper/remote/RemotePositionMapper.java

@@ -0,0 +1,45 @@
+package com.platform.dao.mapper.remote;
+
+import com.platform.dao.config.MyMapper;
+import com.platform.dao.dto.remote.RemotePositionDTO;
+import com.platform.dao.entity.remote.RemotePosition;
+import com.platform.dao.vo.remote.RemotePositionVO;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+
+/**
+ * @Description 设备位置 mapper
+ * @Author liuyu
+ * @Date 2020-04-21 20:52:22
+ * @Version Copyright (c) 2019,北京乾元坤和科技有限公司 All rights reserved.
+ */
+@Component
+public interface RemotePositionMapper extends MyMapper<RemotePosition> {
+    /**
+     * 分页查询
+     *
+     * @param dto :
+     * @return :
+     */
+    List<RemotePositionVO> selectVOList(RemotePositionDTO dto);
+
+    /**
+     * 根据主键查询
+     *
+     * @param id :
+     * @return :
+     */
+    RemotePositionVO getById(Object id);
+
+    /**
+     * 根据主键查询名称
+     *
+     * @param object :
+     * @return :
+     */
+    String selectNameById(String object);
+
+    List<RemotePositionVO> selectLongYanList(RemotePositionDTO dto);
+}

+ 23 - 0
platform-dao/src/main/java/com/platform/dao/util/TreeUtil.java

@@ -21,6 +21,7 @@ import com.platform.dao.vo.query.qykh.InformationVO;
 import com.platform.dao.vo.query.qykh.PlanVO;
 import com.platform.dao.vo.query.qykh.ProductVO;
 import com.platform.dao.vo.query.store.StoreVO;
+import com.platform.dao.vo.remote.RemotePositionVO;
 import com.platform.dao.vo.sb.SbPositionVO;
 import com.platform.dao.vo.sb.SbTypeVO;
 import lombok.experimental.UtilityClass;
@@ -388,6 +389,28 @@ public class TreeUtil {
         return TreeUtil.buildByLoop(trees, root);
     }
 
+    /**
+     * 创建设备位置树
+     *
+     * @param types
+     * @param root
+     * @return
+     */
+    public List<CommonTree> buildRemotePositionTreeWithNoParent(List<RemotePositionVO> types, String root) {
+        List<CommonTree> trees = new LinkedList<>();
+        types.forEach(type -> {
+            CommonTree node = new CommonTree();
+            node.setId(type.getId());
+            node.setKey(type.getId());
+            node.setParentId(type.getParentId());
+            node.setTitle(type.getName());
+            node.setImg(type.getOpcImg());
+            node.setValue(type.getId());
+            trees.add(node);
+        });
+        return TreeUtil.buildByLoopWithNoParent(trees, root);
+    }
+
     /**
      * 创建设备位置树
      *

+ 66 - 0
platform-dao/src/main/java/com/platform/dao/vo/export/remote/ExportRemotePositionVO.java

@@ -0,0 +1,66 @@
+package com.platform.dao.vo.export.remote;
+
+import com.platform.office.annotation.Excel;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+
+/**
+ * @Description 设备位置导出VO
+ * @Author liuyu
+ * @Date 2020-04-21 20:52:22
+ * @Version Copyright (c) 2019,北京乾元坤和科技有限公司 All rights reserved.
+ */
+@Data
+@Accessors(chain = true)
+public class ExportRemotePositionVO implements Serializable {
+
+    /**
+     * 位置id
+     */
+    @Excel(name = "位置id", orderNum = "1")
+    private String id;
+
+    /**
+     * 编码
+     */
+    @Excel(name = "编码", orderNum = "2")
+    private String no;
+
+    /**
+     * 编码
+     */
+    private String code;
+
+    /**
+     * 名称
+     */
+    @Excel(name = "名称", orderNum = "3")
+    private String name;
+
+    /**
+     * 类型 1:厂区 2:生产线
+     */
+    @Excel(name = "类型 1:厂区 2:生产线", orderNum = "4")
+    private Integer type;
+
+    /**
+     * 排序
+     */
+    @Excel(name = "排序", orderNum = "5")
+    private Integer sort;
+
+    /**
+     * 上层位置id
+     */
+    @Excel(name = "上层位置id", orderNum = "6")
+    private String parentId;
+
+    /**
+     * 备注
+     */
+    @Excel(name = "备注", orderNum = "7")
+    private String remark;
+
+}

+ 112 - 0
platform-dao/src/main/java/com/platform/dao/vo/remote/RemotePositionVO.java

@@ -0,0 +1,112 @@
+package com.platform.dao.vo.remote;
+
+import com.platform.common.bean.BaseVO;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+/**
+ * @Description
+ * @Author chenli
+ * @Date 2019/8/5
+ * @Version Copyright (c) 2019,北京乾元坤和科技有限公司 All rights reserved.
+ */
+@Data
+@Accessors(chain = true)
+@EqualsAndHashCode(callSuper = true)
+public class RemotePositionVO extends BaseVO implements Serializable {
+    /**
+     * opc标识:0否1是
+     */
+    private Integer opcFlag;
+    /**
+     * 车间opc图片
+     */
+    private String opcImg;
+    /**
+     * 防雷标识:0否1是
+     */
+    private Integer lightFlag;
+    /**
+     * 防雷图片
+     */
+    private String lightImg;
+    /**
+     * 位置id
+     */
+    private String id;
+    /**
+     * 编码
+     */
+    private String no;
+
+    /**
+     * 父子级编码
+     */
+    private String code;
+
+    /**
+     * 名称
+     */
+    private String name;
+    /**
+     * 类型 1:厂区 2:生产线
+     */
+    private Integer type;
+    /**
+     * 排序
+     */
+    private Integer sort;
+    /**
+     * 是否删除  -1:已删除  0:正常
+     */
+    private Integer delFlag;
+    /**
+     * 上层位置id
+     */
+    private String parentId;
+    /**
+     * 区域维修负责人
+     */
+    private String userId;
+    /**
+     * 区域维修负责人
+     */
+    private String userName;
+    /**
+     * 备注
+     */
+    private String remark;
+    /**
+     * 创建人
+     */
+    private String createdUserId;
+    /**
+     * 修改人
+     */
+    private String updateUserId;
+    /**
+     * 创建日期
+     */
+    private LocalDateTime createdTime;
+    /**
+     * 更新日期
+     */
+    private LocalDateTime updateTime;
+    /**
+     * 上层类型名称
+     */
+    private String parentName;
+    /**
+     * 创建人姓名
+     */
+    private String createdUserName;
+    /**
+     * 修改人姓名
+     */
+    private String updateUserName;
+
+}

+ 77 - 0
platform-dao/src/main/resources/mapper/remote/RemotePositionMapper.xml

@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.platform.dao.mapper.remote.RemotePositionMapper">
+    <sql id="Base_Column_List">
+        id, no, name, type, sort, code, user_id, del_flag, parent_id, opc_flag, opc_img, light_flag, light_img, remark, created_user_id, update_user_id,
+        created_time, update_time
+    </sql>
+
+    <sql id="Join_Column">
+        position.id, position.no, position.name, position.code, position.opc_flag, position.light_flag, position.light_img, position.opc_img, position.user_id, position.type, position.sort, position.del_flag, position.parent_id,
+        position.remark, position.created_user_id, position.update_user_id,
+        position.created_time, position.update_time,
+        p.name as parentName, user.real_name as userName
+    </sql>
+
+    <select id="selectVOList" parameterType="com.platform.dao.dto.remote.RemotePositionDTO"
+            resultType="com.platform.dao.vo.remote.RemotePositionVO">
+        select
+        <include refid="Join_Column"/>
+        from t_remote_position position
+        left join t_remote_position p on position.parent_id = p.id
+        left join t_sys_user user on position.user_id = user.user_id
+        where 1=1
+        <if test="keyword != null and keyword != ''">
+            and ( position.name like concat('%',#{keyword},'%') or
+            position.no like concat('%',#{keyword},'%'))
+        </if>
+        <if test="parentId != null and parentId != ''">
+            and position.parent_id = #{parentId}
+        </if>
+        <if test="parentCode != null and parentCode != ''">
+            and position.code like concat(#{parentCode},'%')
+        </if>
+        <if test="opcFlag != null">
+            and position.opc_flag = #{opcFlag}
+        </if>
+        <if test="lightFlag != null">
+            and position.light_flag = #{lightFlag}
+        </if>
+        <if test="userName != null and userName != ''">
+            and ( user.real_name like concat('%',#{userName},'%') or
+            user.username like concat('%',#{userName},'%'))
+        </if>
+    </select>
+
+    <select id="getById" parameterType="java.lang.Object"
+            resultType="com.platform.dao.vo.remote.RemotePositionVO">
+        select
+        <include refid="Join_Column"/>
+        from t_remote_position position
+        left join t_remote_position p on position.parent_id = p.id
+        left join t_sys_user user on position.user_id = user.user_id
+        where position.id = #{id}
+    </select>
+
+    <select id="selectNameById" parameterType="java.lang.Object" resultType="java.lang.String">
+        select name
+        from t_remote_position
+        where id = #{value}
+    </select>
+
+    <select id="selectLongYanList" parameterType="com.platform.dao.dto.remote.RemotePositionDTO"
+            resultType="com.platform.dao.vo.remote.RemotePositionVO">
+    select * from t_remote_position
+    <where>
+        <choose>
+            <when test="parentId != null and parentId != ''">
+                and parent_id = #{parentId}
+            </when>
+            <otherwise>
+                and (parent_id is null or parent_id = '')
+            </otherwise>
+        </choose>
+    </where>
+     order by sort asc
+    </select>
+</mapper>

+ 2 - 10
platform-dao/src/main/resources/mapper/sb/SbInfoMapper.xml

@@ -188,17 +188,15 @@ sb.scrap_user_name,sb.repair_dept_id,sb.sort_num
         from t_sb_info sb
         left join t_sb_type sbType on sb.type_id = sbType.id
         left join t_sb_position position on sb.position_id = position.id
-        left join t_sys_user user2 on sb.repair_user = user2.user_id
-        left join t_sys_user user3 on sb.repair_user_second = user3.user_id
         left join t_sys_dept sdDept on sb.save_dept = sdDept.dept_id
         where
         1 = 1
         <if test="keyword != null and keyword != ''">
             and (
             sb.name like concat('%',#{keyword},'%')
-            or
-            sb.no like concat('%',#{keyword},'%')
+            or sb.no like concat('%',#{keyword},'%')
             or sb.position_no like concat('%',#{keyword},'%')
+            or sb.remark like concat('%',#{keyword},'%')
             )
         </if>
         <if test="name != null and name!=''">
@@ -207,12 +205,6 @@ sb.scrap_user_name,sb.repair_dept_id,sb.sort_num
         <if test="zbh != null and zbh!=''">
             and sb.zbh like concat('%',#{zbh},'%')
         </if>
-        <if test="repairUserName != null and repairUserName!=''">
-            and user2.real_name like concat('%',#{repairUserName},'%')
-        </if>
-        <if test="repairUserSecondName != null and repairUserSecondName!=''">
-            and user3.real_name like concat('%',#{repairUserSecondName},'%')
-        </if>
         <if test="producerName != null and producerName!=''">
             and sb.producer_id like concat('%',#{producerName},'%')
         </if>

+ 174 - 0
platform-rest/src/main/java/com/platform/rest/controller/remote/RemotePositionController.java

@@ -0,0 +1,174 @@
+package com.platform.rest.controller.remote;
+
+import com.platform.common.bean.AbstractPageResultBean;
+import com.platform.common.util.BeanConverterUtil;
+import com.platform.common.util.R;
+import com.platform.common.validation.group.AddGroup;
+import com.platform.common.validation.group.UpdateGroup;
+import com.platform.dao.dto.remote.RemotePositionDTO;
+import com.platform.dao.util.ExcelUtil;
+import com.platform.dao.util.TreeUtil;
+import com.platform.dao.vo.export.remote.ExportRemotePositionVO;
+import com.platform.dao.vo.remote.RemotePositionVO;
+import com.platform.rest.log.annotation.SysLog;
+import com.platform.service.remote.RemotePositionService;
+import lombok.AllArgsConstructor;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+/**
+ * @Description 设备位置 控制器
+ * @Author liuyu
+ * @Date 2020-04-21 20:52:22
+ * @Version Copyright (c) 2019,北京乾元坤和科技有限公司 All rights reserved.
+ */
+@RestController
+@AllArgsConstructor
+@RequestMapping("/remote/positions")
+public class RemotePositionController {
+    
+    private final RemotePositionService sbPositionService;
+
+    /**
+     * 通过id查询单条记录
+     *
+     * @param id 主键
+     * @return R
+     */
+    @GetMapping("/{id}")
+    public R<RemotePositionVO> getById(@PathVariable("id") String id) {
+        return new R<>(sbPositionService.getById(id));
+    }
+
+    /**
+     * 新增记录
+     *
+     * @param sbPositionDTO 设备位置DTO
+     * @return R
+     */
+    @SysLog("新增设备位置")
+    @PostMapping
+    @PreAuthorize("@pms.hasPermission('remote-positions-add')")
+    public R save(@Validated({AddGroup.class}) @RequestBody RemotePositionDTO sbPositionDTO) {
+        return new R<>(sbPositionService.saveModelByDTO(sbPositionDTO));
+    }
+
+    /**
+     * 修改记录
+     *
+     * @param sbPositionDTO 设备位置DTO
+     * @return R
+     */
+    @SysLog("修改设备位置")
+    @PutMapping("/{id}")
+    @PreAuthorize("@pms.hasPermission('remote-positions-edit')")
+    public R update(@PathVariable("id") String id, @Validated({UpdateGroup.class}) @RequestBody RemotePositionDTO sbPositionDTO) {
+        sbPositionService.modModelByDTO(sbPositionDTO);
+        return new R<>();
+    }
+
+    /**
+     * 通过id删除一条记录
+     *
+     * @param id 主键
+     * @return R
+     */
+    @SysLog("删除设备位置")
+    @DeleteMapping("/{id}")
+    @PreAuthorize("@pms.hasPermission('remote-positions-del')")
+    public R removeById(@PathVariable String id) {
+        sbPositionService.deleteByPrimaryKey(id);
+        return new R<>();
+    }
+
+    /**
+     * 批量记录
+     *
+     * @param ids 主键
+     * @return R
+     */
+    @SysLog("批量删除设备位置")
+    @DeleteMapping("")
+    @PreAuthorize("@pms.hasPermission('remote-positions-del')")
+    public R removeIds(@RequestBody List<String> ids) {
+        sbPositionService.batchDelete(ids);
+        return new R<>();
+    }
+
+    /**
+     * 获取分页
+     *
+     * @param pageNum       当前页码
+     * @param pageSize      每页条数
+     * @param sbPositionDTO 设备位置DTO
+     * @return R
+     */
+    @GetMapping("/page")
+    public R<AbstractPageResultBean<RemotePositionVO>> query(RemotePositionDTO sbPositionDTO, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "20") int pageSize) {
+        return new R<>(sbPositionService.selectVOPage(sbPositionDTO, pageNum, pageSize));
+    }
+
+    /**
+     * 获取列表
+     *
+     * @param sbPositionDTO 设备位置DTO
+     * @return R
+     */
+    @GetMapping("")
+    public R query(RemotePositionDTO sbPositionDTO) {
+        return new R<>(sbPositionService.selectVOList(sbPositionDTO));
+    }
+
+    /**
+     * 获取列表
+     *
+     * @param sbPositionDTO 设备位置DTO
+     * @return R
+     */
+    @GetMapping("/longYan")
+    public R queryLongYan(RemotePositionDTO sbPositionDTO) {
+        return new R<>(sbPositionService.selectLongYanList(sbPositionDTO));
+    }
+
+    /**
+     * 设备位置导出
+     *
+     * @param sbPositionDTO 设备位置DTO
+     * @return R
+     */
+    @GetMapping("/export")
+    @SysLog("设备位置导出")
+    @PreAuthorize("@pms.hasPermission('remote-positions-export')")
+    public void export(HttpServletResponse response, RemotePositionDTO sbPositionDTO) {
+        List<RemotePositionVO> list = sbPositionService.selectVOList(sbPositionDTO);
+        ExcelUtil.exportResponseDict(response, ExportRemotePositionVO.class, BeanConverterUtil.copyListProperties(list, ExportRemotePositionVO.class), "设备位置");
+    }
+
+    /**
+     * 获取设备位置树
+     *
+     * @param sbPositionDTO 设备位置DTO
+     * @return R
+     */
+    @GetMapping("tree")
+    public R queryTree(RemotePositionDTO sbPositionDTO) {
+        return new R<>(TreeUtil.buildRemotePositionTreeWithNoParent(sbPositionService.selectVOList(sbPositionDTO), ""));
+    }
+
+    /**
+     * 获取设备树
+     *
+     * @param sbPositionDTO 设备位置DTO
+     * @return R
+     */
+    @GetMapping("/sb/tree")
+    public R queryTreeAll(RemotePositionDTO sbPositionDTO) {
+        return new R<>(sbPositionService.getSbTreeVOList(sbPositionDTO));
+    }
+    
+
+}

+ 61 - 0
platform-service/src/main/java/com/platform/service/remote/RemotePositionService.java

@@ -0,0 +1,61 @@
+package com.platform.service.remote;
+
+import com.platform.dao.bean.MyVOPage;
+import com.platform.dao.dto.remote.RemotePositionDTO;
+import com.platform.dao.entity.remote.RemotePosition;
+import com.platform.dao.pojo.MyCommonTree;
+import com.platform.dao.vo.remote.RemotePositionVO;
+import com.platform.service.base.IBaseService;
+
+import java.util.List;
+
+/**
+ * @Description 设备位置 service
+ * @Author liuyu
+ * @Date 2020-04-21 20:52:22
+ * @Version Copyright (c) 2019,北京乾元坤和科技有限公司 All rights reserved.
+ */
+public interface RemotePositionService extends IBaseService<RemotePosition, RemotePositionDTO> {
+
+    /**
+     * 批量删除
+     *
+     * @param ids :
+     * @return :
+     */
+    int batchDelete(List<String> ids);
+
+    /**
+     * @param model :
+     * @return :
+     */
+    List<MyCommonTree> getSbTreeVOList(RemotePositionDTO model);
+
+    /**
+     * 分页查询
+     *
+     * @param dto :
+     * @return :
+     */
+    List<RemotePositionVO> selectVOList(RemotePositionDTO dto);
+
+    /**
+     * 分页查询
+     *
+     * @param dto      :
+     * @param pageNum  :
+     * @param pageSize :
+     * @return :
+     */
+    MyVOPage<RemotePositionVO> selectVOPage(RemotePositionDTO dto, int pageNum, int pageSize);
+
+    /**
+     * 根据主键查询
+     *
+     * @param id :
+     * @return :
+     */
+    RemotePositionVO getById(Object id);
+
+    List<RemotePositionVO> selectLongYanList(RemotePositionDTO dto);
+}

+ 295 - 0
platform-service/src/main/java/com/platform/service/remote/impl/RemotePositionServiceImpl.java

@@ -0,0 +1,295 @@
+package com.platform.service.remote.impl;
+
+import com.github.pagehelper.PageHelper;
+import com.platform.common.exception.BusinessException;
+import com.platform.common.util.ListUtils;
+import com.platform.common.util.MapUtils;
+import com.platform.common.util.StringUtils;
+import com.platform.dao.bean.MyVOPage;
+import com.platform.dao.dto.remote.RemotePositionDTO;
+import com.platform.dao.dto.sqarepartmanage.SparePartUsedDTO;
+import com.platform.dao.entity.part.PartInfo;
+import com.platform.dao.entity.remote.RemotePosition;
+import com.platform.dao.entity.sb.SbInfo;
+import com.platform.dao.enums.DelFlagEnum;
+import com.platform.dao.enums.IconEnum;
+import com.platform.dao.enums.SbTreeTypeEnum;
+import com.platform.dao.enums.YesNoEnum;
+import com.platform.dao.mapper.part.PartInfoMapper;
+import com.platform.dao.mapper.remote.RemotePositionMapper;
+import com.platform.dao.mapper.sb.SbInfoMapper;
+import com.platform.dao.mapper.sqarepartmanage.SparePartUsedMapper;
+import com.platform.dao.pojo.CommonTreeScopedSlots;
+import com.platform.dao.pojo.MyCommonTree;
+import com.platform.dao.vo.remote.RemotePositionVO;
+import com.platform.dao.vo.spare.SparePartUsedVO;
+import com.platform.service.base.impl.BaseServiceImpl;
+import com.platform.service.remote.RemotePositionService;
+import com.platform.service.util.ExecuteSql;
+import lombok.AllArgsConstructor;
+import org.apache.commons.collections.CollectionUtils;
+import org.springframework.stereotype.Service;
+import tk.mybatis.mapper.weekend.Weekend;
+import tk.mybatis.mapper.weekend.WeekendCriteria;
+
+import java.time.LocalDateTime;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description 设备位置 service 实现类
+ * @Author liuyu
+ * @Date 2020-04-21 20:52:22
+ * @Version Copyright (c) 2019,北京乾元坤和科技有限公司 All rights reserved.
+ */
+@AllArgsConstructor
+@Service("remotePositionService")
+public class RemotePositionServiceImpl extends BaseServiceImpl<RemotePositionMapper, RemotePosition, RemotePositionDTO> implements RemotePositionService {
+
+    private final PartInfoMapper partInfoMapper;
+
+    private final SparePartUsedMapper sparePartUsedMapper;
+
+    private final SbInfoMapper sbInfoMapper;
+
+    @Override
+    public void deleteByPrimaryKey(String id) {
+
+        RemotePosition sbPosition = mapper.selectByPrimaryKey(id);
+        if(sbPosition!=null && sbPosition.getOpcFlag()== YesNoEnum.YES.getValue()){
+            throw new BusinessException("该车间是有工艺流程画面,无法删除");
+        }
+
+        Weekend<SbInfo> weekend2 = new Weekend<>(SbInfo.class);
+        WeekendCriteria<SbInfo, Object> weekendCriteria2 = weekend2.weekendCriteria();
+        weekendCriteria2.andEqualTo(SbInfo::getPositionId, id);
+        List<SbInfo> sbInfoList = sbInfoMapper.selectByExample(weekend2);
+        if(!CollectionUtils.isEmpty(sbInfoList)){
+            throw new BusinessException("该车间下面有设备,无法删除,请先转移设备到其他车间");
+        }
+        sbPosition.setDelFlag(DelFlagEnum.DELETED.getValue());
+        mapper.updateByPrimaryKeySelective(sbPosition);
+    }
+
+    @Override
+    public int batchDelete(List<String> ids) {
+        for(String id:ids){
+            this.deleteByPrimaryKey(id);
+        }
+        return 1;
+    }
+
+    @Override
+    public RemotePosition saveModelByDTO(RemotePositionDTO model) {
+        // 获取父级
+        String parentId = model.getParentId();
+        RemotePosition parent = null;
+        /*if (StringUtils.isNotBlank(parentId)) {
+            parent = mapper.selectByPrimaryKeyForUpdate(parentId);
+            Weekend<RemotePosition> weekendCount = new Weekend<>(RemotePosition.class);
+            WeekendCriteria<RemotePosition, Object> weekendCriteriaCount = weekendCount.weekendCriteria();
+            weekendCriteriaCount.andEqualTo(RemotePosition::getParentId, parentId);
+            int i = mapper.selectCountByExample(weekendCount);
+            String code = IdGeneratorUtils.getStrNum(parent.getCode(), ++i);
+            model.setCode(code);
+        } else {
+            Weekend<RemotePosition> weekendCount = new Weekend<>(RemotePosition.class);
+            WeekendCriteria<RemotePosition, Object> weekendCriteriaCount = weekendCount.weekendCriteria();
+            weekendCriteriaCount.orEqualTo(RemotePosition::getParentId, "");
+            weekendCriteriaCount.orIsNull(RemotePosition::getParentId);
+            int i = mapper.selectCountByExample(weekendCount);
+            String code = IdGeneratorUtils.getStrNum("", ++i);
+            model.setCode(code);
+        }*/
+        Weekend<RemotePosition> weekend = new Weekend<>(RemotePosition.class);
+        WeekendCriteria<RemotePosition, Object> weekendCriteria = weekend.weekendCriteria();
+        weekendCriteria.andEqualTo(RemotePosition::getNo, model.getNo());
+        RemotePosition example = mapper.selectOneByExample(weekend);
+        if(example !=null){
+            throw new BusinessException("位号重复,请重新设置位号");
+        }
+        RemotePosition sbPosition = super.saveModelByDTO(model);
+        if (parent != null) {
+            mapper.updateByPrimaryKeySelective(new RemotePosition().setId(parentId).setUpdateTime(LocalDateTime.now()));
+        }
+        return sbPosition;
+    }
+
+    @Override
+    public void modModelByDTO(RemotePositionDTO model) {
+        Weekend<RemotePosition> weekend = new Weekend<>(RemotePosition.class);
+        WeekendCriteria<RemotePosition, Object> weekendCriteria = weekend.weekendCriteria();
+        weekendCriteria.andEqualTo(RemotePosition::getNo, model.getNo());
+        RemotePosition example = mapper.selectOneByExample(weekend);
+        if(example !=null && !example.getId().equals(model.getId())){
+            throw new BusinessException("位号重复,请重新设置位号");
+        }
+        String parentId = model.getParentId();
+
+        // 之前没有编码,则设置编码
+       /* if(StringUtils.isBlank(model.getCode())){
+            if (StringUtils.isNotBlank(parentId)) {
+                Weekend<RemotePosition> weekendCount = new Weekend<>(RemotePosition.class);
+                WeekendCriteria<RemotePosition, Object> weekendCriteriaCount = weekendCount.weekendCriteria();
+                weekendCriteriaCount.andEqualTo(RemotePosition::getParentId, parentId);
+                int i = mapper.selectCountByExample(weekendCount);
+                String code = IdGeneratorUtils.getStrNum(parent.getCode(), ++i);
+                model.setCode(code);
+            } else {
+                Weekend<RemotePosition> weekendCount = new Weekend<>(RemotePosition.class);
+                WeekendCriteria<RemotePosition, Object> weekendCriteriaCount = weekendCount.weekendCriteria();
+                weekendCriteriaCount.orEqualTo(RemotePosition::getParentId, "");
+                weekendCriteriaCount.orIsNull(RemotePosition::getParentId);
+                int i = mapper.selectCountByExample(weekendCount);
+                String code = IdGeneratorUtils.getStrNum("",i);
+                model.setCode(code);
+            }
+        }else{
+            if (!entity.getParentId().equals(parentId)) {// 更换父级编码
+                if(StringUtils.isBlank(parent.getCode())){
+                    throw new BusinessException("父级区域关联编码未设置,请联系技术,或者修改父级信息,重新保存");
+                }
+                String newCode = parent.getCode() + model.getCode().substring(model.getCode().length()-3);
+                model.setCode(newCode);
+            }
+        }*/
+        super.modModelByDTO(model);
+    }
+
+    @Override
+    public List<RemotePosition> getModelListByDTO(RemotePositionDTO model) {
+        Weekend<RemotePosition> weekend = new Weekend<>(RemotePosition.class);
+        setWeekendCriteria(weekend, model);
+        return mapper.selectByExample(weekend);
+    }
+
+    /**
+     * 设置查询条件
+     */
+    private void setWeekendCriteria(Weekend<RemotePosition> weekend, RemotePositionDTO model) {
+        WeekendCriteria<RemotePosition, Object> weekendCriteria = weekend.weekendCriteria();
+        ExecuteSql.executeNotNull(model.getId(), () -> weekendCriteria.andNotEqualTo(RemotePosition::getId, model.getId()));
+    }
+
+    @Override
+    public List<MyCommonTree> getSbTreeVOList(RemotePositionDTO model) {
+        List<SbInfo> sbInfoList = sbInfoMapper.selectAll();
+        // 查询所有的部位
+        List<PartInfo> partInfoList = partInfoMapper.selectAll();
+        // 查询所有使用备件
+        List<SparePartUsedVO> sparePartUsedList = sparePartUsedMapper.selectVOList(new SparePartUsedDTO());
+        // 查询所有设备位置
+        List<RemotePosition> sbPositions = mapper.selectAll();
+        // 处理设备类型
+        List<MyCommonTree> result = ListUtils.newArrayList();
+        Map<String, MyCommonTree> sbPositionTreeMap = MapUtils.newHashMap();
+        sbPositions.forEach(item -> {
+            MyCommonTree vo = new MyCommonTree();
+            vo.setId(item.getId());
+            vo.setKey(SbTreeTypeEnum.POSITION.getValue() + item.getId());
+            vo.setTitle(item.getName());
+            vo.setParentId(item.getParentId());
+            vo.setScopedSlots(new CommonTreeScopedSlots(IconEnum.POSITION.getValue()));
+            sbPositionTreeMap.put(vo.getId(), vo);
+        });
+        sbPositionTreeMap.forEach((key, item) -> {
+            String parentId = item.getParentId();
+            if (StringUtils.isBlank(parentId)) {
+                result.add(item);
+            } else {
+                MyCommonTree vo = sbPositionTreeMap.get(parentId);
+                if (vo != null) {
+                    vo.add(item);
+                }
+            }
+        });
+        // 处理设备
+        Map<String, MyCommonTree> sbInfoTreeMap = MapUtils.newHashMap();
+        sbInfoList.forEach(item -> {
+            MyCommonTree vo = new MyCommonTree();
+            vo.setId(item.getId());
+            vo.setKey(SbTreeTypeEnum.SB_INFO.getValue() + item.getId());
+            vo.setTitle(item.getName());
+            vo.setParentId(item.getParentId());
+            vo.setScopedSlots(new CommonTreeScopedSlots(IconEnum.SB_INFO.getValue()));
+            sbInfoTreeMap.put(vo.getId(), vo);
+        });
+        sbInfoList.forEach(item -> {
+            MyCommonTree vo = sbInfoTreeMap.get(item.getId());
+            if (StringUtils.isNotBlank(item.getParentId())) {
+                MyCommonTree sbInfoTreeVO = sbInfoTreeMap.get(item.getParentId());
+                sbInfoTreeVO.add(vo);
+            } else {
+                MyCommonTree sbPositionTreeVO = sbPositionTreeMap.get(item.getPositionId());
+                if (sbPositionTreeVO == null) {
+                    result.add(vo);
+                } else {
+                    sbPositionTreeVO.add(vo);
+                }
+            }
+        });
+
+        // 处理所有部位
+        Map<String, MyCommonTree> sbPartTreeMap = MapUtils.newHashMap();
+        partInfoList.forEach(item -> {
+            MyCommonTree vo = new MyCommonTree();
+            vo.setId(item.getId());
+            vo.setKey(SbTreeTypeEnum.PART_INFO.getValue() + item.getId());
+            vo.setTitle(item.getName());
+            vo.setParentId(item.getSbId());
+            vo.setScopedSlots(new CommonTreeScopedSlots(IconEnum.PART_INFO.getValue()));
+            sbPartTreeMap.put(vo.getId(), vo);
+        });
+        partInfoList.forEach(item -> {
+            MyCommonTree sbInfoTreeVO = sbInfoTreeMap.get(item.getSbId());
+            if (sbInfoTreeVO != null) {
+                sbInfoTreeVO.add(sbPartTreeMap.get(item.getId()));
+            }
+        });
+        // 处理所有备件
+        Map<String, MyCommonTree> sparePartUsedTreeMap = MapUtils.newHashMap();
+        sparePartUsedList.forEach(item -> {
+            MyCommonTree vo = new MyCommonTree();
+            vo.setId(item.getId());
+            vo.setKey(SbTreeTypeEnum.SPARE_PART_USED.getValue() + item.getId());
+            vo.setTitle(item.getSpareName());
+            vo.setParentId(item.getSbId());
+            vo.setScopedSlots(new CommonTreeScopedSlots(IconEnum.SPARE_PART_USED.getValue()));
+            sparePartUsedTreeMap.put(vo.getId(), vo);
+        });
+        sparePartUsedList.forEach(item -> {
+            MyCommonTree sbInfoTreeVO = sbPartTreeMap.get(item.getPartId());
+            MyCommonTree vo = sparePartUsedTreeMap.get(item.getId());
+            if (sbInfoTreeVO == null) {
+                sbInfoTreeMap.get(item.getSbId()).getChildren().add(vo);
+            } else {
+                sbInfoTreeVO.add(vo);
+            }
+        });
+
+        return result;
+    }
+
+    @Override
+    public List<RemotePositionVO> selectVOList(RemotePositionDTO model) {
+        return mapper.selectVOList(model);
+    }
+
+    @Override
+    public MyVOPage<RemotePositionVO> selectVOPage(RemotePositionDTO model, int pageNum, int pageSize) {
+        PageHelper.startPage(pageNum, pageSize);
+        return new MyVOPage<>(mapper.selectVOList(model));
+    }
+
+    @Override
+    public RemotePositionVO getById(Object id) {
+        return mapper.getById(id);
+    }
+
+    @Override
+    public List<RemotePositionVO> selectLongYanList(RemotePositionDTO dto) {
+        return mapper.selectLongYanList(dto);
+    }
+
+
+}