Parcourir la source

新增 设备设置记录 服务

hechunping il y a 1 an
Parent
commit
1d793a1823

+ 19 - 0
device-api-cloud/src/main/java/com/xy/feign/DeviceSetRecordsFeign.java

@@ -0,0 +1,19 @@
+package com.xy.feign;
+
+import com.xy.service.DeviceSetRecordsService;
+import com.xy.FeignInterceptor;
+import com.xy.consts.ServiceConsts;
+import org.springframework.cloud.openfeign.FeignClient;
+
+/**
+ * <p>
+ *  feign
+ * </p>
+ *
+ * @author hechunping
+ * @since 2024-04-11
+ */
+@FeignClient(value = ServiceConsts.SERVICE_NAME, configuration = FeignInterceptor.class)
+public interface DeviceSetRecordsFeign extends DeviceSetRecordsService {
+
+}

+ 53 - 0
device-api-service/src/main/java/com/xy/entity/DeviceSetRecords.java

@@ -0,0 +1,53 @@
+package com.xy.entity;
+
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+/**
+ * <p>
+ * 设备设置记录
+ * </p>
+ *
+ * @author hechunping
+ * @since 2024-04-11
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value="DeviceSetRecords对象", description="")
+public class DeviceSetRecords implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.ASSIGN_ID)
+    private Long id;
+
+    @ApiModelProperty(value = "设备ID")
+    private Long deviceId;
+
+    @ApiModelProperty(value = "类型")
+    private String type;
+
+    @ApiModelProperty(value = "设置内容")
+    private String content;
+
+    @ApiModelProperty(value = "创建人")
+    @TableField(fill = FieldFill.INSERT)
+    private Long createUser;
+
+    @ApiModelProperty(value = "创建时间")
+    @TableField(fill = FieldFill.INSERT)
+    private LocalDateTime createTime;
+
+
+}

+ 16 - 0
device-api-service/src/main/java/com/xy/mapper/DeviceSetRecordsMapper.java

@@ -0,0 +1,16 @@
+package com.xy.mapper;
+
+import com.xy.entity.DeviceSetRecords;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author hechunping
+ * @since 2024-04-11
+ */
+public interface DeviceSetRecordsMapper extends BaseMapper<DeviceSetRecords> {
+
+}

+ 15 - 0
device-api-service/src/main/java/com/xy/mapper/mapper/DeviceSetRecordsMapper.xml

@@ -0,0 +1,15 @@
+<?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.xy.mapper.DeviceSetRecordsMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.xy.entity.DeviceSetRecords">
+        <id column="id" property="id" />
+        <result column="device_id" property="deviceId" />
+        <result column="type" property="type" />
+        <result column="content" property="content" />
+        <result column="create_user" property="createUser" />
+        <result column="create_time" property="createTime" />
+    </resultMap>
+
+</mapper>

+ 108 - 0
device-api-service/src/main/java/com/xy/service/DeviceSetRecordsServiceImpl.java

@@ -0,0 +1,108 @@
+package com.xy.service;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.xy.dto.DeviceSetRecordsDto;
+import com.xy.entity.DeviceSetRecords;
+import com.xy.mapper.DeviceSetRecordsMapper;
+import com.xy.utils.Emptys;
+import com.xy.utils.MybatisPlusQuery;
+import com.xy.utils.PageBean;
+import com.xy.utils.R;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static com.xy.utils.Beans.copy;
+import static com.xy.utils.PlusBeans.toIPage;
+import static com.xy.utils.PlusBeans.toPageBean;
+
+
+/**
+ * <p>
+ * 设备设置记录 服务实现类
+ * </p>
+ *
+ * @author hechunping
+ * @since 2024-04-11
+ */
+@Service
+@AllArgsConstructor
+@Api(tags = "设备设置记录")
+public class DeviceSetRecordsServiceImpl extends ServiceImpl<DeviceSetRecordsMapper, DeviceSetRecords> implements DeviceSetRecordsService {
+
+    @PostMapping("lastOne")
+    @ApiOperation("返显最后一条记录")
+    public R lastOne(@RequestBody DeviceSetRecordsDto.LastOneDto dto) {
+        List<DeviceSetRecordsDto.LastOneVo> voList = new ArrayList<>();
+        dto.getTypeList().forEach(type -> {
+            LambdaQueryWrapper<DeviceSetRecords> lqw = new LambdaQueryWrapper<DeviceSetRecords>()
+                    .eq(DeviceSetRecords::getDeviceId, dto.getDeviceId())
+                    .eq(DeviceSetRecords::getType, type)
+                    .orderByDesc(DeviceSetRecords::getCreateTime)
+                    .last("limit 1");
+            DeviceSetRecords one = getOne(lqw);
+            if (Emptys.check(one)) {
+                DeviceSetRecordsDto.LastOneVo vo = new DeviceSetRecordsDto.LastOneVo()
+                        .setType(type)
+                        .setContent(one.getContent());
+                voList.add(vo);
+            }
+
+        });
+        return R.ok(voList);
+    }
+
+
+    @PostMapping("obj")
+    @ApiOperation("对象查询")
+    public R<DeviceSetRecordsDto.Vo> obj(@RequestBody DeviceSetRecordsDto.Vo vo) {
+        DeviceSetRecordsDto.SelectList selectList = copy(DeviceSetRecordsDto.SelectList.class, vo);
+        List<DeviceSetRecordsDto.Vo> list = list(selectList).getData();
+        if (Emptys.check(list)) {
+            return R.ok(list.get(0));
+        }
+        return R.ok();
+    }
+
+    @PostMapping("list")
+    @ApiOperation("集合查询")
+    public R<List<DeviceSetRecordsDto.Vo>> list(@RequestBody DeviceSetRecordsDto.SelectList selectList) {
+        LambdaQueryWrapper<DeviceSetRecords> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(selectList, DeviceSetRecords.class).build();
+        List<DeviceSetRecords> list = list(lambdaQueryWrapper);
+        return R.ok(copy(DeviceSetRecordsDto.Vo.class, list));
+    }
+
+    @PostMapping("page")
+    @ApiOperation("分页查询")
+    public R<PageBean<DeviceSetRecordsDto.Vo>> page(@RequestBody DeviceSetRecordsDto.Page page) {
+        PageBean pageBean = page.getPage();
+        LambdaQueryWrapper<DeviceSetRecords> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(page, DeviceSetRecords.class).build();
+        IPage<DeviceSetRecords> iPage = page(toIPage(pageBean), lambdaQueryWrapper);
+        return R.ok(toPageBean(DeviceSetRecordsDto.Vo.class, iPage));
+    }
+
+    @PostMapping("save")
+    @ApiOperation("添加")
+    public R save(@RequestBody @Validated DeviceSetRecordsDto.Save save) {
+        DeviceSetRecords saveInfo = copy(DeviceSetRecords.class, save);
+        save(saveInfo);
+        return R.ok();
+    }
+
+    @PostMapping("update")
+    @ApiOperation("修改")
+    public R update(@RequestBody @Validated DeviceSetRecordsDto.Update update) {
+        DeviceSetRecords updateInfo = copy(DeviceSetRecords.class, update);
+        updateById(updateInfo);
+        return R.ok();
+    }
+}

+ 95 - 0
device-api/src/main/java/com/xy/dto/DeviceSetRecordsDto.java

@@ -0,0 +1,95 @@
+package com.xy.dto;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.xy.utils.PageBean;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.time.LocalDateTime;
+import java.util.List;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author hechunping
+ * @since 2024-04-11
+ */
+public class DeviceSetRecordsDto {
+
+    @Data
+    @Accessors(chain = true)
+    public static class LastOneVo {
+        @ApiModelProperty(value = "类型")
+        private String type;
+
+        @ApiModelProperty(value = "内容")
+        private String content;
+    }
+
+    @Data
+    @Accessors(chain = true)
+    public static class LastOneDto {
+        @ApiModelProperty(value = "设备ID")
+        private Long deviceId;
+
+        @ApiModelProperty(value = "查询类型列表")
+        private List<String> typeList;
+    }
+
+    @Data
+    @Accessors(chain = true)
+    public static class SelectList extends Vo {
+
+    }
+
+    @Data
+    @Accessors(chain = true)
+    public static class Page extends Vo {
+
+        @ApiModelProperty(value = "分页对象", required = true)
+        private PageBean page;
+
+    }
+
+    @Data
+    @Accessors(chain = true)
+    public static class Save extends Vo {
+
+    }
+
+    @Data
+    @Accessors(chain = true)
+    public static class Update extends Vo {
+
+    }
+
+    @Data
+    @Accessors(chain = true)
+    public static class Vo {
+
+        private Long id;
+
+        @ApiModelProperty(value = "设备ID")
+        private Long deviceId;
+
+        @ApiModelProperty(value = "类型")
+        private String type;
+
+        @ApiModelProperty(value = "设置内容")
+        private String content;
+
+
+        @ApiModelProperty(value = "创建人")
+        private Long createUser;
+
+        @ApiModelProperty(value = "创建时间")
+        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+        private LocalDateTime createTime;
+
+
+    }
+
+}

+ 16 - 0
device-api/src/main/java/com/xy/service/DeviceSetRecordsService.java

@@ -0,0 +1,16 @@
+package com.xy.service;
+
+import com.xy.annotate.RestMappingController;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author hechunping
+ * @since 2024-04-11
+ */
+@RestMappingController("/device-set-records")
+public interface DeviceSetRecordsService {
+
+}