diff --git a/fastbee-open-api/src/main/java/com/fastbee/data/controller/aaScreenAgricultural/DeviceBreakdownController.java b/fastbee-open-api/src/main/java/com/fastbee/data/controller/aaScreenAgricultural/DeviceBreakdownController.java new file mode 100644 index 0000000..b9ffd71 --- /dev/null +++ b/fastbee-open-api/src/main/java/com/fastbee/data/controller/aaScreenAgricultural/DeviceBreakdownController.java @@ -0,0 +1,113 @@ +package com.fastbee.data.controller.aaScreenAgricultural; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.fastbee.common.annotation.Log; +import com.fastbee.common.core.controller.BaseController; +import com.fastbee.common.core.domain.AjaxResult; +import com.fastbee.common.enums.BusinessType; +import com.fastbee.breakdown.domain.DeviceBreakdown; +import com.fastbee.breakdown.service.IDeviceBreakdownService; +import com.fastbee.common.utils.poi.ExcelUtil; +import com.fastbee.common.core.page.TableDataInfo; + +/** + * 故障Controller + * + * @author kerwincui + * @date 2024-11-27 + */ +@RestController +@RequestMapping("/breakdown") +@Api(tags = "故障") +public class DeviceBreakdownController extends BaseController +{ + @Autowired + private IDeviceBreakdownService deviceBreakdownService; + +/** + * 查询故障列表 + */ +@GetMapping("/list") +@ApiOperation("查询故障列表") + public TableDataInfo list(DeviceBreakdown deviceBreakdown) + { + startPage(); + List list = deviceBreakdownService.selectDeviceBreakdownList(deviceBreakdown); + return getDataTable(list); + } + + /** + * 导出故障列表 + */ + @ApiOperation("导出故障列表") + @PostMapping("/export") + public void export(HttpServletResponse response, DeviceBreakdown deviceBreakdown) + { + List list = deviceBreakdownService.selectDeviceBreakdownList(deviceBreakdown); + ExcelUtil util = new ExcelUtil(DeviceBreakdown.class); + util.exportExcel(response, list, "故障数据"); + } + + /** + * 获取故障详细信息 + */ + @GetMapping(value = "/{id}") + @ApiOperation("获取故障详细信息") + public AjaxResult getInfo(@PathVariable("id") Long id) + { + return success(deviceBreakdownService.selectDeviceBreakdownById(id)); + } + + /** + * 新增故障 + */ + @PostMapping + @ApiOperation("新增故障") + public AjaxResult add(@RequestBody DeviceBreakdown deviceBreakdown) + { + return toAjax(deviceBreakdownService.insertDeviceBreakdown(deviceBreakdown)); + } + + /** + * 修改故障 + */ + @PutMapping + @ApiOperation("修改故障") + public AjaxResult edit(@RequestBody DeviceBreakdown deviceBreakdown) + { + return toAjax(deviceBreakdownService.updateDeviceBreakdown(deviceBreakdown)); + } + + /** + * 删除故障 + */ + @DeleteMapping("/{ids}") + @ApiOperation("删除故障") + public AjaxResult remove(@PathVariable Long[] ids) + { + return toAjax(deviceBreakdownService.deleteDeviceBreakdownByIds(ids)); + } + /* + * + */ + @GetMapping("/statistics") + @ApiOperation("查询故障列表") + public AjaxResult getFaultStatistics(String TypeValue, String CreateTimeValue) + { + return success(deviceBreakdownService.getFaultStatistics(TypeValue, CreateTimeValue)); + } +} diff --git a/fastbee-service/fastbee-device-service/src/main/java/com/fastbee/breakdown/domain/DeviceBreakdown.java b/fastbee-service/fastbee-device-service/src/main/java/com/fastbee/breakdown/domain/DeviceBreakdown.java new file mode 100644 index 0000000..8fb8544 --- /dev/null +++ b/fastbee-service/fastbee-device-service/src/main/java/com/fastbee/breakdown/domain/DeviceBreakdown.java @@ -0,0 +1,43 @@ +package com.fastbee.breakdown.domain; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.fastbee.common.annotation.Excel; +import com.fastbee.common.core.domain.BaseEntity; + +/** + * 故障对象 iot_device_breakdown + * + * @author kerwincui + * @date 2024-11-27 + */ +@ApiModel(value = "DeviceBreakdown",description = "故障 iot_device_breakdown") +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("iot_device_breakdown") +public class DeviceBreakdown extends BaseEntity + { +private static final long serialVersionUID = 1L; + + /** 主键 */ + private Long id; + + /** 分类 */ + @Excel(name = "分类") + @ApiModelProperty("分类") + private String type; + + /** 故障名 */ + @Excel(name = "故障名") + @ApiModelProperty("故障名") + private String faultName; + + /** 删除标志(0代表存在,2代表删除) */ + private Integer delFlag; + +} diff --git a/fastbee-service/fastbee-device-service/src/main/java/com/fastbee/breakdown/domain/dto/IotDeviceBreakdown.java b/fastbee-service/fastbee-device-service/src/main/java/com/fastbee/breakdown/domain/dto/IotDeviceBreakdown.java new file mode 100644 index 0000000..2ea461f --- /dev/null +++ b/fastbee-service/fastbee-device-service/src/main/java/com/fastbee/breakdown/domain/dto/IotDeviceBreakdown.java @@ -0,0 +1,12 @@ +package com.fastbee.breakdown.domain.dto; + +import lombok.Data; + +@Data +public class IotDeviceBreakdown { + private Long counts; + + private String fault_name; + + private String type; +} diff --git a/fastbee-service/fastbee-device-service/src/main/java/com/fastbee/breakdown/mapper/DeviceBreakdownMapper.java b/fastbee-service/fastbee-device-service/src/main/java/com/fastbee/breakdown/mapper/DeviceBreakdownMapper.java new file mode 100644 index 0000000..c661916 --- /dev/null +++ b/fastbee-service/fastbee-device-service/src/main/java/com/fastbee/breakdown/mapper/DeviceBreakdownMapper.java @@ -0,0 +1,65 @@ +package com.fastbee.breakdown.mapper; + +import java.util.List; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.fastbee.breakdown.domain.DeviceBreakdown; +import org.apache.ibatis.annotations.Mapper; + +/** + * 故障Mapper接口 + * + * @author kerwincui + * @date 2024-11-27 + */ +@Mapper +public interface DeviceBreakdownMapper extends BaseMapper +{ + /** + * 查询故障 + * + * @param id 故障主键 + * @return 故障 + */ + public DeviceBreakdown selectDeviceBreakdownById(Long id); + + /** + * 查询故障列表 + * + * @param deviceBreakdown 故障 + * @return 故障集合 + */ + public List selectDeviceBreakdownList(DeviceBreakdown deviceBreakdown); + + /** + * 新增故障 + * + * @param deviceBreakdown 故障 + * @return 结果 + */ + public int insertDeviceBreakdown(DeviceBreakdown deviceBreakdown); + + /** + * 修改故障 + * + * @param deviceBreakdown 故障 + * @return 结果 + */ + public int updateDeviceBreakdown(DeviceBreakdown deviceBreakdown); + + /** + * 删除故障 + * + * @param id 故障主键 + * @return 结果 + */ + public int deleteDeviceBreakdownById(Long id); + + /** + * 批量删除故障 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteDeviceBreakdownByIds(Long[] ids); +} diff --git a/fastbee-service/fastbee-device-service/src/main/java/com/fastbee/breakdown/service/IDeviceBreakdownService.java b/fastbee-service/fastbee-device-service/src/main/java/com/fastbee/breakdown/service/IDeviceBreakdownService.java new file mode 100644 index 0000000..a096b12 --- /dev/null +++ b/fastbee-service/fastbee-device-service/src/main/java/com/fastbee/breakdown/service/IDeviceBreakdownService.java @@ -0,0 +1,70 @@ +package com.fastbee.breakdown.service; + +import java.util.List; +import com.fastbee.breakdown.domain.dto.IotDeviceBreakdown; +import com.fastbee.breakdown.domain.DeviceBreakdown; + +/** + * 故障Service接口 + * + * @author kerwincui + * @date 2024-11-27 + */ +public interface IDeviceBreakdownService +{ + /** + * 查询故障 + * + * @param id 故障主键 + * @return 故障 + */ + public DeviceBreakdown selectDeviceBreakdownById(Long id); + + /** + * 查询故障列表 + * + * @param deviceBreakdown 故障 + * @return 故障集合 + */ + public List selectDeviceBreakdownList(DeviceBreakdown deviceBreakdown); + + /** + * 新增故障 + * + * @param deviceBreakdown 故障 + * @return 结果 + */ + public int insertDeviceBreakdown(DeviceBreakdown deviceBreakdown); + + /** + * 修改故障 + * + * @param deviceBreakdown 故障 + * @return 结果 + */ + public int updateDeviceBreakdown(DeviceBreakdown deviceBreakdown); + + /** + * 批量删除故障 + * + * @param ids 需要删除的故障主键集合 + * @return 结果 + */ + public int deleteDeviceBreakdownByIds(Long[] ids); + + /** + * 删除故障信息 + * + * @param id 故障主键 + * @return 结果 + */ + public int deleteDeviceBreakdownById(Long id); + + /** + * 统计故障的分组数量 + * @param TypeValue + * @param CreateTimeValue + * @return + */ + public List getFaultStatistics(String TypeValue,String CreateTimeValue); +} diff --git a/fastbee-service/fastbee-device-service/src/main/java/com/fastbee/breakdown/service/impl/DeviceBreakdownServiceImpl.java b/fastbee-service/fastbee-device-service/src/main/java/com/fastbee/breakdown/service/impl/DeviceBreakdownServiceImpl.java new file mode 100644 index 0000000..9fd53db --- /dev/null +++ b/fastbee-service/fastbee-device-service/src/main/java/com/fastbee/breakdown/service/impl/DeviceBreakdownServiceImpl.java @@ -0,0 +1,134 @@ +package com.fastbee.breakdown.service.impl; + +import java.util.ArrayList; +import java.util.List; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.fastbee.breakdown.domain.dto.IotDeviceBreakdown; +import com.fastbee.common.utils.DateUtils; +import lombok.var; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.fastbee.breakdown.mapper.DeviceBreakdownMapper; +import com.fastbee.breakdown.domain.DeviceBreakdown; +import com.fastbee.breakdown.service.IDeviceBreakdownService; + +/** + * 故障Service业务层处理 + * + * @author kerwincui + * @date 2024-11-27 + */ +@Service +public class DeviceBreakdownServiceImpl implements IDeviceBreakdownService +{ + @Autowired + private DeviceBreakdownMapper deviceBreakdownMapper; + + /** + * 查询故障 + * + * @param id 故障主键 + * @return 故障 + */ + @Override + public DeviceBreakdown selectDeviceBreakdownById(Long id) + { + return deviceBreakdownMapper.selectDeviceBreakdownById(id); + } + + /** + * 查询故障列表 + * + * @param deviceBreakdown 故障 + * @return 故障 + */ + @Override + public List selectDeviceBreakdownList(DeviceBreakdown deviceBreakdown) + { + return deviceBreakdownMapper.selectDeviceBreakdownList(deviceBreakdown); + } + + /** + * 新增故障 + * + * @param deviceBreakdown 故障 + * @return 结果 + */ + @Override + public int insertDeviceBreakdown(DeviceBreakdown deviceBreakdown) + { + deviceBreakdown.setCreateTime(DateUtils.getNowDate()); + return deviceBreakdownMapper.insertDeviceBreakdown(deviceBreakdown); + } + + /** + * 修改故障 + * + * @param deviceBreakdown 故障 + * @return 结果 + */ + @Override + public int updateDeviceBreakdown(DeviceBreakdown deviceBreakdown) + { + deviceBreakdown.setUpdateTime(DateUtils.getNowDate()); + return deviceBreakdownMapper.updateDeviceBreakdown(deviceBreakdown); + } + + /** + * 批量删除故障 + * + * @param ids 需要删除的故障主键 + * @return 结果 + */ + @Override + public int deleteDeviceBreakdownByIds(Long[] ids) + { + return deviceBreakdownMapper.deleteDeviceBreakdownByIds(ids); + } + + /** + * 删除故障信息 + * + * @param id 故障主键 + * @return 结果 + */ + @Override + public int deleteDeviceBreakdownById(Long id) + { + return deviceBreakdownMapper.deleteDeviceBreakdownById(id); + } + + /** + * 统计故障的分组数量 + * @param TypeValue + * @param CreateTimeValue + * @return + */ + @Override + public List getFaultStatistics(String TypeValue, String CreateTimeValue){ + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("Type", TypeValue) + .ge("create_time",CreateTimeValue) + .select("count(*) as id", "fault_name", "create_time","Type") + .groupBy("fault_name"); + List breakdown = new ArrayList<>(); + QueryWrapper query = new QueryWrapper<>(); + query.eq("Type",TypeValue); + QueryWrapper queryTime = new QueryWrapper<>(); + queryTime.ge("create_time",CreateTimeValue); + if ((deviceBreakdownMapper.selectCount(query) <=0)||(deviceBreakdownMapper.selectCount(queryTime)<=0)) { + return breakdown; + } + System.err.println(deviceBreakdownMapper.selectList(queryWrapper)); + for (var item : deviceBreakdownMapper.selectList(queryWrapper)) + { + IotDeviceBreakdown breakdownItem = new IotDeviceBreakdown(); + breakdownItem.setCounts(item.getId()); + breakdownItem.setFault_name(item.getFaultName()); + breakdownItem.setType(item.getType()); + breakdown.add(breakdownItem); + } + return breakdown; + } +} diff --git a/fastbee-service/fastbee-device-service/src/main/resources/mapper/DeviceBreakdownMapper.xml b/fastbee-service/fastbee-device-service/src/main/resources/mapper/DeviceBreakdownMapper.xml new file mode 100644 index 0000000..0e9c10f --- /dev/null +++ b/fastbee-service/fastbee-device-service/src/main/resources/mapper/DeviceBreakdownMapper.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + select id, Type, fault_name, update_by, del_flag, create_time, create_by, update_time from iot_device_breakdown + + + + + + + + insert into iot_device_breakdown + + Type, + fault_name, + update_by, + del_flag, + create_time, + create_by, + update_time, + + + #{type}, + #{faultName}, + #{updateBy}, + #{delFlag}, + #{createTime}, + #{createBy}, + #{updateTime}, + + + + + update iot_device_breakdown + + Type = #{type}, + fault_name = #{faultName}, + update_by = #{updateBy}, + del_flag = #{delFlag}, + create_time = #{createTime}, + create_by = #{createBy}, + update_time = #{updateTime}, + + where id = #{id} + + + + delete from iot_device_breakdown where id = #{id} + + + + delete from iot_device_breakdown where id in + + #{id} + + + \ No newline at end of file