Selaa lähdekoodia

开发产品命令表-列表、产品命令表-新增、产品命令表-修改和产品命令表-删除四个接口

james 5 kuukautta sitten
vanhempi
commit
0869e0e7d8

+ 74 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/web/DmpProductCommandController.java

@@ -0,0 +1,74 @@
+package com.usky.iot.controller.web;
+
+
+import com.usky.common.core.bean.ApiResult;
+import com.usky.common.core.bean.CommonPage;
+import com.usky.iot.domain.DmpProductCommand;
+import com.usky.iot.service.DmpProductCommandService;
+import com.usky.iot.service.vo.DmpProductCommandRequestVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * <p>
+ * 产品命令表 前端控制器
+ * </p>
+ *
+ * @author han
+ * @since 2024-10-30
+ */
+@RestController
+@RequestMapping("/dmpProductCommand")
+public class DmpProductCommandController {
+
+    @Autowired
+    private DmpProductCommandService dmpProductCommandService;
+
+    /**
+     * 新增
+     * @param dmpProductCommand
+     * @return
+     */
+    @PostMapping
+    public ApiResult<Void> add(@RequestBody DmpProductCommand dmpProductCommand){
+        dmpProductCommandService.add(dmpProductCommand);
+        return ApiResult.success();
+    }
+
+    /**
+     * 修改
+     * @param dmpProductCommand
+     * @return
+     */
+    @PutMapping
+    public ApiResult<Void> edit(@RequestBody DmpProductCommand dmpProductCommand){
+        dmpProductCommandService.edit(dmpProductCommand);
+        return ApiResult.success();
+    }
+
+
+    /**
+     * 分页
+     * @param requestVO
+     * @return
+     */
+    @PostMapping("/page")
+    public ApiResult<CommonPage<DmpProductCommand>> page(@RequestBody DmpProductCommandRequestVO requestVO)
+    {
+        return ApiResult.success(dmpProductCommandService.page(requestVO));
+    }
+
+
+
+    /**
+     * 删除记录
+     */
+    @DeleteMapping("/{id}")
+    public ApiResult<Void> remove(@PathVariable("id") Integer id)
+    {
+        dmpProductCommandService.remove(id);
+        return ApiResult.success();
+    }
+
+}
+

+ 112 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/domain/DmpProductCommand.java

@@ -0,0 +1,112 @@
+package com.usky.iot.domain;
+
+import java.math.BigDecimal;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.time.LocalDateTime;
+import java.io.Serializable;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * <p>
+ * 产品命令表
+ * </p>
+ *
+ * @author han
+ * @since 2024-10-30
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class DmpProductCommand implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键id
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    /**
+     * 产品编码
+     */
+    private String productCode;
+
+    /**
+     * 命令编码
+     */
+    private String commandCode;
+
+    /**
+     * 命令名称
+     */
+    private String commandName;
+
+    /**
+     * 数据类型(1、状态量 2、模拟量)
+     */
+    private Integer dataType;
+
+    /**
+     * 单位
+     */
+    private String commandUnit;
+
+    /**
+     * 最大值
+     */
+    private BigDecimal maximum;
+
+    /**
+     * 最小值
+     */
+    private BigDecimal minimum;
+
+    /**
+     * 命令字典
+     */
+    private String commandDict;
+
+    /**
+     * 命令描述
+     */
+    private String commandDescribe;
+
+    /**
+     * 备注
+     */
+    private String remark;
+
+    /**
+     * 删除标识;0:未删除,1:已删除
+     */
+    private Integer deleteFlag;
+
+    /**
+     * 创建人
+     */
+    private String createdBy;
+
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createdTime;
+
+    /**
+     * 更新人
+     */
+    private String updatedBy;
+
+    /**
+     * 更新时间
+     */
+    private LocalDateTime updatedTime;
+
+    /**
+     * 租户号
+     */
+    private Integer tenantId;
+
+
+}

+ 16 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/mapper/DmpProductCommandMapper.java

@@ -0,0 +1,16 @@
+package com.usky.iot.mapper;
+
+import com.usky.iot.domain.DmpProductCommand;
+import com.usky.common.mybatis.core.CrudMapper;
+
+/**
+ * <p>
+ * 产品命令表 Mapper 接口
+ * </p>
+ *
+ * @author han
+ * @since 2024-10-30
+ */
+public interface DmpProductCommandMapper extends CrudMapper<DmpProductCommand> {
+
+}

+ 24 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/DmpProductCommandService.java

@@ -0,0 +1,24 @@
+package com.usky.iot.service;
+
+import com.usky.common.core.bean.CommonPage;
+import com.usky.iot.domain.DmpProductCommand;
+import com.usky.common.mybatis.core.CrudService;
+import com.usky.iot.service.vo.DmpProductCommandRequestVO;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+
+/**
+ * <p>
+ * 产品命令表 服务类
+ * </p>
+ *
+ * @author han
+ * @since 2024-10-30
+ */
+public interface DmpProductCommandService extends CrudService<DmpProductCommand> {
+
+    void add(DmpProductCommand dmpProductCommand);
+    void edit(DmpProductCommand dmpProductCommand);
+    CommonPage<DmpProductCommand> page(DmpProductCommandRequestVO requestVO);
+    void remove(Integer id);
+}

+ 89 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/DmpProductCommandServiceImpl.java

@@ -0,0 +1,89 @@
+package com.usky.iot.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.usky.common.core.bean.CommonPage;
+import com.usky.common.core.exception.BusinessException;
+import com.usky.common.security.utils.SecurityUtils;
+import com.usky.iot.domain.DmpProductAttribute;
+import com.usky.iot.domain.DmpProductCommand;
+import com.usky.iot.mapper.DmpProductCommandMapper;
+import com.usky.iot.service.DmpProductCommandService;
+import com.usky.common.mybatis.core.AbstractCrudService;
+import com.usky.iot.service.vo.DmpProductCommandRequestVO;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDateTime;
+import java.util.Date;
+import java.util.Objects;
+import java.util.Optional;
+
+/**
+ * <p>
+ * 产品命令表 服务实现类
+ * </p>
+ *
+ * @author han
+ * @since 2024-10-30
+ */
+@Service
+public class DmpProductCommandServiceImpl extends AbstractCrudService<DmpProductCommandMapper, DmpProductCommand> implements DmpProductCommandService {
+
+    public boolean checkNameUnique(DmpProductCommand dmpProductCommand) {
+        Integer id = null == dmpProductCommand.getId() ? -1 : dmpProductCommand.getId();
+        LambdaQueryWrapper<DmpProductCommand> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.eq(DmpProductCommand::getCommandName,dmpProductCommand.getCommandName())
+                .eq(DmpProductCommand::getTenantId, SecurityUtils.getTenantId())
+                .eq(DmpProductCommand::getDeleteFlag,0);
+        DmpProductCommand one = this.getOne(queryWrapper);
+        return null != one && !Objects.equals(one.getId(), id);
+    }
+
+    @Override
+    public void add(DmpProductCommand dmpProductCommand){
+        if (checkNameUnique(dmpProductCommand)){
+            throw new BusinessException("新增产品命令信息'" + dmpProductCommand.getCommandName() + "'失败,产品命令信息已存在");
+        }
+        dmpProductCommand.setDeleteFlag(0);
+        dmpProductCommand.setCreatedBy(SecurityUtils.getUsername());
+        dmpProductCommand.setCreatedTime(LocalDateTime.now());
+        dmpProductCommand.setTenantId(SecurityUtils.getTenantId());
+        this.save(dmpProductCommand);
+    }
+
+    @Override
+    public void edit(DmpProductCommand dmpProductCommand){
+        dmpProductCommand.setUpdatedBy(SecurityUtils.getUsername());
+        dmpProductCommand.setUpdatedTime(LocalDateTime.now());
+        if (checkNameUnique(dmpProductCommand)){
+            throw new BusinessException("修改产品命令信息'" + dmpProductCommand.getCommandName() + "'失败,产品命令信息已存在");
+        }
+        this.updateById(dmpProductCommand);
+    }
+
+    @Override
+    public CommonPage<DmpProductCommand> page(DmpProductCommandRequestVO requestVO){
+        IPage<DmpProductCommand> page = new Page<>(requestVO.getCurrent(), requestVO.getSize());
+        LambdaQueryWrapper<DmpProductCommand> lambdaQuery = Wrappers.lambdaQuery();
+        lambdaQuery
+                .like(StringUtils.isNotBlank(requestVO.getProductCode()),DmpProductCommand::getProductCode,requestVO.getProductCode())
+                .like(StringUtils.isNotBlank(requestVO.getCommandCode()),DmpProductCommand::getCommandCode,requestVO.getCommandCode())
+                .like(StringUtils.isNotBlank(requestVO.getCommandName()),DmpProductCommand::getCommandName,requestVO.getCommandName())
+                .like(StringUtils.isNotBlank(requestVO.getCommandDescribe()),DmpProductCommand::getCommandDescribe,requestVO.getCommandDescribe())
+                .eq(DmpProductCommand::getTenantId,SecurityUtils.getTenantId())
+                .eq(DmpProductCommand::getDeleteFlag,0);
+        page = this.page(page,lambdaQuery);
+        return new CommonPage<>(page.getRecords(),page.getTotal(),page.getCurrent(),page.getSize());
+    }
+
+    @Override
+    public void remove(Integer id){
+        DmpProductCommand dmpProductCommand = this.getById(id);
+        Optional.ofNullable(dmpProductCommand).orElseThrow(() -> new BusinessException("产品命令信息不存在"));
+        dmpProductCommand.setDeleteFlag(1);
+        this.updateById(dmpProductCommand);
+    }
+}

+ 26 - 0
service-iot/service-iot-biz/src/main/resources/mapper/iot/DmpProductCommandMapper.xml

@@ -0,0 +1,26 @@
+<?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.usky.iot.mapper.DmpProductCommandMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.usky.iot.domain.DmpProductCommand">
+        <id column="id" property="id" />
+        <result column="product_code" property="productCode" />
+        <result column="command_code" property="commandCode" />
+        <result column="command_name" property="commandName" />
+        <result column="data_type" property="dataType" />
+        <result column="command_unit" property="commandUnit" />
+        <result column="maximum" property="maximum" />
+        <result column="minimum" property="minimum" />
+        <result column="command_dict" property="commandDict" />
+        <result column="command_describe" property="commandDescribe" />
+        <result column="remark" property="remark" />
+        <result column="delete_flag" property="deleteFlag" />
+        <result column="created_by" property="createdBy" />
+        <result column="created_time" property="createdTime" />
+        <result column="updated_by" property="updatedBy" />
+        <result column="updated_time" property="updatedTime" />
+        <result column="tenant_id" property="tenantId" />
+    </resultMap>
+
+</mapper>