Bladeren bron

设备管理API更新

shudonghui 1 jaar geleden
bovenliggende
commit
743d2a03d4

+ 3 - 3
sop-business/src/main/java/com/qmth/sop/business/bean/result/SysDeviceResult.java

@@ -10,10 +10,10 @@ import java.util.List;
 
 /**
  * <p>
- * 客户表
+ *
  * </p>
  *
- * @author wangliang
+ * @author dhshu
  * @since 2023-08-01
  */
 
@@ -21,7 +21,7 @@ public class SysDeviceResult extends SysDevice implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
-    @ApiModelProperty(value = "客户经理")
+    @ApiModelProperty(value = "设备供应商")
     private String supplier;
 
     public String getSupplier() {

+ 35 - 10
sop-business/src/main/java/com/qmth/sop/business/entity/SysDevice.java

@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 import com.qmth.sop.common.base.BaseEntity;
 import com.qmth.sop.common.enums.DeviceStatusEnum;
+import com.qmth.sop.common.enums.InOutTypeEnum;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
@@ -24,9 +25,9 @@ public class SysDevice extends BaseEntity implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
-    @ApiModelProperty(value = "名称")
-    @NotBlank(message = "名称不能为空")
-    private String name;
+    @ApiModelProperty(value = "设备编号")
+    @NotBlank(message = "设备编号不能为空")
+    private String deviceCode;
 
     @ApiModelProperty(value = "序列号")
     @NotBlank(message = "序列号不能为空")
@@ -36,6 +37,10 @@ public class SysDevice extends BaseEntity implements Serializable {
     @NotBlank(message = "品牌不能为空")
     private String brand;
 
+    @ApiModelProperty(value = "型号")
+    @NotBlank(message = "型号不能为空")
+    private String model;
+
     @ApiModelProperty(value = "购买时间")
     @NotNull(message = "购买时间不能为空")
     private Long buyTime;
@@ -53,6 +58,9 @@ public class SysDevice extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "总扫描量")
     private Long scanCount;
 
+    @ApiModelProperty(value = "出库/入库")
+    private InOutTypeEnum bound;
+
     @ApiModelProperty(value = "是否crm同步,0:否,1:是")
     @NotNull(message = "是否crm同步不能为空")
     private Boolean sync;
@@ -61,13 +69,6 @@ public class SysDevice extends BaseEntity implements Serializable {
     @NotNull(message = "是否启用不能为空")
     private Boolean enable;
 
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
 
     public String getSerialNo() {
         return serialNo;
@@ -140,4 +141,28 @@ public class SysDevice extends BaseEntity implements Serializable {
     public void setEnable(Boolean enable) {
         this.enable = enable;
     }
+
+    public String getDeviceCode() {
+        return deviceCode;
+    }
+
+    public void setDeviceCode(String deviceCode) {
+        this.deviceCode = deviceCode;
+    }
+
+    public String getModel() {
+        return model;
+    }
+
+    public void setModel(String model) {
+        this.model = model;
+    }
+
+    public InOutTypeEnum getBound() {
+        return bound;
+    }
+
+    public void setBound(InOutTypeEnum bound) {
+        this.bound = bound;
+    }
 }

+ 2 - 2
sop-business/src/main/java/com/qmth/sop/business/mapper/SysDeviceMapper.java

@@ -2,10 +2,10 @@ package com.qmth.sop.business.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.qmth.sop.business.bean.result.SysDeviceResult;
 import com.qmth.sop.business.entity.SysDevice;
 import org.apache.ibatis.annotations.Param;
+
 import java.util.Map;
 
 /**
@@ -25,5 +25,5 @@ public interface SysDeviceMapper extends BaseMapper<SysDevice> {
 	 * @return
 	 */
 
-    <T> IPage<SysDeviceResult> query(Page<T> iPage, @Param("query") String query);
+	IPage<SysDeviceResult> query(IPage<Map> iPage,@Param("supplierId")  Long supplierId,@Param("brand")  String brand,@Param("model")  String model,@Param("deviceCode")  String deviceCode,@Param("status")  String status,@Param("bound")  String bound,@Param("enable")  Boolean enable);
 }

+ 12 - 19
sop-business/src/main/java/com/qmth/sop/business/service/SysDeviceService.java

@@ -1,17 +1,19 @@
 package com.qmth.sop.business.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.sop.business.bean.result.SysDeviceResult;
 import com.qmth.sop.business.entity.SysDevice;
+import com.qmth.sop.common.enums.DeviceStatusEnum;
+import com.qmth.sop.common.enums.InOutTypeEnum;
+
 import java.util.Map;
 
 /**
  * 设备配置表 服务类
  *
  * @author: shudonghui
- * @date: 2023-08-02 14:21:11
+ * @date: 2023-08-24 17:32:06
  * @version: 1.0
  * @email: shudonghui@qmth.com.cn
  * @Company: www.qmth.com.cn
@@ -21,32 +23,23 @@ public interface SysDeviceService extends IService<SysDevice>{
     /**
     * 查询列表
     *
-    * @param
+    * @param iPage
     * @return
     */
-    <T> IPage<SysDeviceResult> query(Page<T> tPage, String query);
+    IPage<SysDeviceResult> query(IPage<Map> iPage, Long supplierId, String brand, String model, String deviceCode, DeviceStatusEnum status, InOutTypeEnum bound, Boolean enable);
 
     /**
-    * 新增设备配置表
+    * 新增修改设备配置表
     *
     * @param sysDevice
     */
-    void add(SysDevice sysDevice);
+    Boolean saveSysDevice(SysDevice sysDevice);
 
-    /**
-    * 修改设备配置表
-    *
-    * @param sysDevice
-    */
-    void update(SysDevice sysDevice);
 
-    /**
-    * 删除设备配置表
-    *
-    * @param id
-    */
-    void delete(Long id);
+    boolean disable(long[] ids);
+
+    boolean enable(long[] ids);
 
+    boolean delete(long[] ids);
 
-    void disable(long id);
 }

+ 50 - 32
sop-business/src/main/java/com/qmth/sop/business/service/impl/SysDeviceServiceImpl.java

@@ -1,24 +1,36 @@
 package com.qmth.sop.business.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.boot.api.exception.ApiException;
 import com.qmth.sop.business.bean.result.SysDeviceResult;
 import com.qmth.sop.business.entity.SysDevice;
-import com.qmth.sop.business.entity.SysSupplier;
 import com.qmth.sop.business.entity.SysUser;
 import com.qmth.sop.business.mapper.SysDeviceMapper;
 import com.qmth.sop.business.service.SysDeviceService;
 import com.qmth.sop.common.enums.DeviceStatusEnum;
+import com.qmth.sop.common.enums.ExceptionResultEnum;
+import com.qmth.sop.common.enums.FieldUniqueEnum;
+import com.qmth.sop.common.enums.InOutTypeEnum;
+import com.qmth.sop.common.util.ResultUtil;
 import com.qmth.sop.common.util.ServletUtil;
+import org.springframework.dao.DuplicateKeyException;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
 /**
  * 设备配置表 服务实现.
  *
  * @author: shudonghui
- * @date: 2023-08-02 14:21:11
+ * @date: 2023-08-24 17:32:07
  * @version: 1.0
  * @email: shudonghui@qmth.com.cn
  * @Company: www.qmth.com.cn
@@ -34,55 +46,61 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
      * @return
      */
     @Override
-    public <T> IPage<SysDeviceResult> query(Page<T> iPage, String query) {
-        return this.baseMapper.query(iPage, query);
+    public IPage<SysDeviceResult> query(IPage<Map> iPage, Long supplierId, String brand, String model, String deviceCode, DeviceStatusEnum status, InOutTypeEnum bound, Boolean enable) {
+        return this.baseMapper.query(iPage, supplierId,brand,model,deviceCode,Objects.nonNull(status)?status.name():null,Objects.nonNull(bound)?bound.name():null,enable);
     }
 
     /**
-     * 新增设备配置表
+     * 新增修改设备配置表
      *
      * @param sysDevice
      */
     @Override
     @Transactional
-    public void add(SysDevice sysDevice) {
-        SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
-        sysDevice.setCreateId(sysUser.getId());
-        sysDevice.setCreateTime(System.currentTimeMillis());
-        this.saveOrUpdate(sysDevice);
+    public Boolean saveSysDevice(SysDevice sysDevice) {
+        try {
+            SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
+            if (Objects.isNull(sysDevice.getId())) {// 新增
+                sysDevice.insertInfo(sysUser.getId());
+            } else { // 修改
+                sysDevice.updateInfo(sysUser.getId());
+            }
+            return saveOrUpdate(sysDevice);
+        } catch (Exception e) {
+            if (e instanceof DuplicateKeyException) {
+                String errorColumn = e.getCause().toString();
+                String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
+                throw ExceptionResultEnum.SQL_ERROR.exception("[" + FieldUniqueEnum.convertToTitle(columnStr) + "]数据不允许重复插入");
+            } else if (e instanceof ApiException) {
+                ResultUtil.error((ApiException) e, e.getMessage());
+            } else {
+                ResultUtil.error(e.getMessage());
+            }
+        }
+        return null;
+
     }
 
-    /**
-     * 修改设备配置表
-     *
-     * @param sysDevice
-     */
+
     @Override
     @Transactional
-    public void update(SysDevice sysDevice) {
-        SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
-        sysDevice.setUpdateId(sysUser.getId());
-        sysDevice.setUpdateTime(System.currentTimeMillis());
-        this.saveOrUpdate(sysDevice);
+    public boolean disable(long[] ids) {
+        List<Long> idList = Arrays.stream(ids).boxed().collect(Collectors.toList());
+        return this.update(new UpdateWrapper<SysDevice>().lambda().in(SysDevice::getId, idList).set(SysDevice::getEnable, false));
     }
 
-    /**
-     * 删除设备配置表
-     *
-     * @param id
-     */
     @Override
     @Transactional
-    public void delete(Long id) {
-        this.removeById(id);
+    public boolean enable(long[] ids) {
+        List<Long> idList = Arrays.stream(ids).boxed().collect(Collectors.toList());
+        return this.update(new LambdaUpdateWrapper<SysDevice>().in(SysDevice::getId, idList).set(SysDevice::getEnable, true));
     }
 
     @Override
     @Transactional
-    public void disable(long id) {
-        SysDevice sysDevice= this.getById(id);
-        sysDevice.setEnable(false);
-        this.update(sysDevice);
+    public boolean delete(long[] ids) {
+        List<Long> idList = Arrays.stream(ids).boxed().collect(Collectors.toList());
+        return this.removeByIds(idList);
     }
 
 }

+ 7 - 0
sop-business/src/main/resources/db/log/shudonghui_update_log.sql

@@ -235,3 +235,10 @@ INSERT INTO `sequence` (`name`, `current_value`, `increment`) VALUES ('violation
 UPDATE sys_config
 SET org_id=NULL, config_key='sms.violation.remind.code', config_name='违规提醒通知', config_value='SMS_462805303', remark=NULL, enable=1, sort=1, create_id=1, create_time=NULL, update_id=NULL, update_time=NULL
 WHERE id=31;
+
+
+--2023.8.25
+ALTER TABLE `sys_device`
+    CHANGE COLUMN `name` `device_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '设备编号' AFTER `id`,
+    ADD COLUMN `model` varchar(255) NOT NULL COMMENT '型号' AFTER `brand`,
+    ADD COLUMN `bound` varchar(20) NULL COMMENT '出库/入库' AFTER `scan_count`;

+ 21 - 4
sop-business/src/main/resources/mapper/SysDeviceMapper.xml

@@ -6,11 +6,28 @@
         select a.*,s.name supplier  from sys_device a
         left join sys_supplier s on s.id=a.supplier_id
         <where>
-            <if test="query != null and query != ''">
-                and ( a.name like concat('%', #{query} , '%') or a.serial_no like concat('%', #{query} , '%')
-                or a.brand like concat('%', #{query} , '%') or
-                a.supplier like #{query} or a.buy_time like concat('%', #{query} , '%'))
+            <if test="supplierId != null and supplierId != ''">
+                and a.supplier_id = #{supplierId}
             </if>
+            <if test="brand != null and brand != ''">
+                and a.brand = #{brand}
+            </if>
+            <if test="model != null and model != ''">
+                and a.model = #{model}
+            </if>
+            <if test="deviceCode != null and deviceCode != ''">
+                and a.device_code = #{deviceCode}
+            </if>
+            <if test="status != null and status != ''">
+                and a.status = #{status}
+            </if>
+            <if test="bound != null and bound != ''">
+                and a.bound = #{bound}
+            </if>
+            <if test="enable != null and enable != ''">
+                and a.enable = #{enable}
+            </if>
+
         </where>
         order by a.create_time desc
     </select>

+ 52 - 67
sop-server/src/main/java/com/qmth/sop/server/api/SysDeviceController.java

@@ -1,13 +1,15 @@
 package com.qmth.sop.server.api;
 
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.sop.business.bean.result.SysDeviceResult;
 import com.qmth.sop.business.entity.SysDevice;
 import com.qmth.sop.business.service.SysDeviceService;
 import com.qmth.sop.common.contant.SystemConstant;
+import com.qmth.sop.common.enums.DeviceStatusEnum;
+import com.qmth.sop.common.enums.InOutTypeEnum;
 import com.qmth.sop.common.util.Result;
 import com.qmth.sop.common.util.ResultUtil;
 import io.swagger.annotations.*;
@@ -18,107 +20,90 @@ import javax.annotation.Resource;
 import javax.validation.Valid;
 import javax.validation.constraints.Max;
 import javax.validation.constraints.Min;
-import java.util.Objects;
 
 /**
- * 设备配置表 控制器.
- *
+ * 设备配置表 控制器
+ * 
  * @author: shudonghui
- * @date: 2023-08-02 14:37:23
+ * @date: 2023-08-24 17:32:07
  * @version: 1.0
  * @email: shudonghui@qmth.com.cn
  * @Company: www.qmth.com.cn
  */
 @Api(tags = "设备配置表 Controller")
 @RestController
-@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_DEVICE)
+@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX+"/sys/device")
 public class SysDeviceController {
 
 
     @Resource
     SysDeviceService sysDeviceService;
 
-
+    
     @ApiOperation(value = "设备配置表查询接口")
     @RequestMapping(value = "/query", method = RequestMethod.POST)
-    @ApiResponses({@ApiResponse(code = 200, message = "设备配置表列表信息", response = SysDeviceResult.class)})
+    @ApiResponses({@ApiResponse(code = 200, message = "设备配置表查询结果", response = SysDeviceResult.class)})
     public Result query(
-            @ApiParam(value = "查询条件", required = false) @RequestParam(required = false) String query,
-            @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
-            @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
-        IPage<SysDeviceResult> resultIPage = sysDeviceService.query(new Page<>(pageNumber, pageSize), query);
+                @ApiParam(value = "设备供应商", required = false) @RequestParam(required = false) Long supplierId,
+                @ApiParam(value = "品牌", required = false) @RequestParam(required = false) String brand,
+                @ApiParam(value = "型号", required = false) @RequestParam(required = false) String model,
+                @ApiParam(value = "设备编号", required = false) @RequestParam(required = false) String deviceCode,
+                @ApiParam(value = "运行状态", required = false) @RequestParam(required = false) DeviceStatusEnum status,
+                @ApiParam(value = "出库/入库", required = false) @RequestParam(required = false) InOutTypeEnum bound,
+                @ApiParam(value = "启用/禁用", required = false) @RequestParam(required = false) Boolean enable,
+                @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
+                @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
+        IPage<SysDeviceResult> resultIPage = sysDeviceService.query(new Page<>(pageNumber, pageSize),supplierId,brand,model,deviceCode,status,bound,enable);
 
         return ResultUtil.ok(resultIPage);
     }
 
-
-    @ApiOperation(value = "新增设备配置表接口")
-    @RequestMapping(value = "/add", method = RequestMethod.POST)
-    @ApiResponses({@ApiResponse(code = 200, message = "新增设备配置表信息", response = Object.class)})
-    public Result add(@Valid @ApiParam(value = "设备配置表信息", required = true) @RequestBody(required = true) SysDevice sysDevice, BindingResult bindingResult) throws InterruptedException {
+    
+    @ApiOperation(value = "设备配置表新增修改接口")
+    @RequestMapping(value = "/save", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})
+    public Result save(@Valid @ApiParam(value = "设备配置表信息", required = true) @RequestBody(required = true) SysDevice sysDevice, BindingResult bindingResult) throws InterruptedException {
         if (bindingResult.hasErrors()) {
             return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
         }
-        sysDeviceService.add(sysDevice);
-        return ResultUtil.ok();
+        return ResultUtil.ok(sysDeviceService.saveSysDevice(sysDevice));
     }
 
-
-    @ApiOperation(value = "修改设备配置表接口")
-    @RequestMapping(value = "/update", method = RequestMethod.POST)
-    @ApiResponses({@ApiResponse(code = 200, message = "修改设备配置表信息", response = Object.class)})
-    public Result update(@Valid @ApiParam(value = "设备配置表信息", required = true) @RequestBody(required = true) SysDevice sysDevice, BindingResult bindingResult) throws InterruptedException {
-        if (bindingResult.hasErrors()) {
-            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
-        }
-        sysDeviceService.update(sysDevice);
-        return ResultUtil.ok();
+    
+    @ApiOperation(value = "设备配置表获取单个接口")
+    @RequestMapping(value = "/get", method = RequestMethod.GET)
+    @ApiResponses({@ApiResponse(code = 200, message = "设备配置表信息", response = SysDevice.class)})
+    public Result get(@ApiParam(value = "设备配置表id", required = true) @RequestParam long id) {
+        return ResultUtil.ok(sysDeviceService.getById(id));
     }
 
-
-    @ApiOperation(value = "删除设备配置表接口")
-    @RequestMapping(value = "/delete", method = RequestMethod.POST)
-    @ApiResponses({@ApiResponse(code = 200, message = "删除设备配置表信息", response = Object.class)})
-    public Result delete(@ApiParam(value = "设备配置表信息", required = true) @RequestParam(required = true) long id) {
-        sysDeviceService.delete(id);
-        return ResultUtil.ok();
+    //批量禁用设备
+    
+    @ApiOperation(value = "批量禁用设备接口")
+    @RequestMapping(value = "/disable", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})
+    public Result disable(@ApiParam(value = "设备配置表id", required = true) @RequestParam(required = true) long[] ids) {
+        return ResultUtil.ok(sysDeviceService.disable(ids));
     }
 
-    /*
-     * 设备配置表列表
-     */
-
-    @ApiOperation(value = "设备配置表列表接口")
-    @RequestMapping(value = "/list", method = RequestMethod.POST)
-    @ApiResponses({@ApiResponse(code = 200, message = "设备配置表列表", response = SysDevice.class)})
-    public Result list(@ApiParam(value = "查询条件", required = false) @RequestParam(required = false) Boolean enable) {
-        return ResultUtil.ok(sysDeviceService.list(new QueryWrapper<SysDevice>().lambda().eq(Objects.nonNull(enable), SysDevice::getEnable, enable)));
+    //批量启用设备
+    
+    @ApiOperation(value = "批量启用设备接口")
+    @RequestMapping(value = "/enable", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})
+    public Result enable(@ApiParam(value = "设备配置表id", required = true) @RequestParam(required = true) long[] ids) {
+        return ResultUtil.ok(sysDeviceService.enable(ids));
     }
 
-    /**
-     * 停用设备配置
-     */
-    @ApiOperation(value = "停用设备配置接口")
-    @RequestMapping(value = "/disable", method = RequestMethod.POST)
-    @ApiResponses({@ApiResponse(code = 200, message = "停用设备配置", response = Object.class)})
-    public Result disable(@ApiParam(value = "设备配置表信息", required = true) @RequestParam(required = true) long id) {
-        sysDeviceService.disable(id);
-        return ResultUtil.ok();
+    //批量删除设备
+    
+    @ApiOperation(value = "批量删除设备接口")
+    @RequestMapping(value = "/delete", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})
+    public Result delete(@ApiParam(value = "设备配置表id", required = true) @RequestParam(required = true) long[] ids) {
+        return ResultUtil.ok(sysDeviceService.delete(ids));
     }
 
-    /**
-     * 获取单个
-     *
-     * @param id
-     * @return
-     */
-
-    @ApiOperation(value = "获取单个设备配置接口")
-    @RequestMapping(value = "/get", method = RequestMethod.GET)
-    @ApiResponses({@ApiResponse(code = 200, message = "获取单个设备配置", response = SysDevice.class)})
-    public Result get(@ApiParam(value = "设备配置表id", required = true) @RequestParam(required = true) long id) {
-        return ResultUtil.ok(sysDeviceService.getById(id));
-    }
 
 
 }