设备注册模块
diff --git a/src/main/java/com/supwisdom/dlpay/device/bean/DeviceSearchBean.java b/src/main/java/com/supwisdom/dlpay/device/bean/DeviceSearchBean.java
new file mode 100644
index 0000000..a4e6bfa
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/device/bean/DeviceSearchBean.java
@@ -0,0 +1,34 @@
+package com.supwisdom.dlpay.device.bean;
+
+import com.supwisdom.dlpay.system.bean.PageBean;
+
+public class DeviceSearchBean extends PageBean {
+ private Integer id;
+ private String devicename;
+ private String factoryid;
+
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getDevicename() {
+ return devicename;
+ }
+
+ public void setDevicename(String devicename) {
+ this.devicename = devicename;
+ }
+
+ public String getFactoryid() {
+ return factoryid;
+ }
+
+ public void setFactoryid(String factoryid) {
+ this.factoryid = factoryid;
+ }
+}
diff --git a/src/main/java/com/supwisdom/dlpay/device/controller/DeviceController.java b/src/main/java/com/supwisdom/dlpay/device/controller/DeviceController.java
new file mode 100644
index 0000000..1128e8b
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/device/controller/DeviceController.java
@@ -0,0 +1,86 @@
+package com.supwisdom.dlpay.device.controller;
+
+
+import com.google.gson.Gson;
+import com.supwisdom.dlpay.api.bean.JsonResult;
+import com.supwisdom.dlpay.area.bean.AreaSearchBean;
+import com.supwisdom.dlpay.area.domain.TArea;
+import com.supwisdom.dlpay.area.service.AreaService;
+import com.supwisdom.dlpay.device.bean.DeviceSearchBean;
+import com.supwisdom.dlpay.device.domain.TDevice;
+import com.supwisdom.dlpay.device.service.DeviceService;
+import com.supwisdom.dlpay.framework.util.PageResult;
+import com.supwisdom.dlpay.framework.util.WebConstant;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Controller
+@RequestMapping("/device")
+public class DeviceController {
+
+ @Autowired
+ private DeviceService deviceService;
+
+ @RequestMapping("/index")
+ public String indexView(ModelMap model) {
+
+ return "device/index";
+ }
+
+ @RequestMapping("/list")
+ @PreAuthorize("hasPermission('/device/index','')")
+ @ResponseBody
+ public PageResult<TDevice> getDataList(@RequestParam("page") Integer pageNo,
+ @RequestParam("limit") Integer pageSize,
+ @RequestParam(value = "searchkey", required = false) Integer searchKey) {
+ try {
+ if (null == pageNo || pageNo < 1) pageNo = WebConstant.PAGENO_DEFAULT;
+ if (null == pageSize || pageSize < 1) pageSize = WebConstant.PAGESIZE_DEFAULT;
+ DeviceSearchBean searchBean = new DeviceSearchBean();
+ searchBean.setPageNo(pageNo);
+ searchBean.setId(searchKey);
+ searchBean.setPageSize(pageSize);
+ return deviceService.getDeviceByKey(searchBean);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return new PageResult<>(99, "系统查询错误");
+ }
+ }
+
+
+ @GetMapping("/loadadd")
+ @PreAuthorize("hasPermission('/device/loadadd','')")
+ public String loadadd(Model model) {
+ return "device/form";
+ }
+
+ @PostMapping("/add")
+ @PreAuthorize("hasPermission('/device/add','')")
+ @ResponseBody
+ public JsonResult add(@RequestBody TDevice device) {
+ if (device != null) {
+ return deviceService.saveDevice(device);
+ } else {
+ return JsonResult.error("添加失败");
+ }
+ }
+
+ @PostMapping("/updatestate")
+ @PreAuthorize("hasPermission('/device/updatestate','')")
+ @ResponseBody
+ public JsonResult updatestate(@RequestParam("id") Integer id, @RequestParam("state") Integer state) {
+ if (deviceService.updateState(id, state)) {
+ return JsonResult.ok("操作成功");
+ } else {
+ return JsonResult.error("操作失败");
+ }
+ }
+}
diff --git a/src/main/java/com/supwisdom/dlpay/device/controller/DeviceGroupController.java b/src/main/java/com/supwisdom/dlpay/device/controller/DeviceGroupController.java
new file mode 100644
index 0000000..cecb0f7
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/device/controller/DeviceGroupController.java
@@ -0,0 +1,69 @@
+package com.supwisdom.dlpay.device.controller;
+
+
+import com.supwisdom.dlpay.api.bean.JsonResult;
+import com.supwisdom.dlpay.device.bean.DeviceSearchBean;
+import com.supwisdom.dlpay.device.domain.TDevice;
+import com.supwisdom.dlpay.device.service.DeviceService;
+import com.supwisdom.dlpay.framework.util.PageResult;
+import com.supwisdom.dlpay.framework.util.WebConstant;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.*;
+
+@Controller
+@RequestMapping("/devicegroup")
+public class DeviceGroupController {
+
+ @Autowired
+ private DeviceService deviceService;
+
+ @RequestMapping("/index")
+ public String indexView(ModelMap model) {
+
+ return "devicegroup/index";
+ }
+
+ @RequestMapping("/list")
+ @PreAuthorize("hasPermission('/devicegroup/index','')")
+ @ResponseBody
+ public PageResult<TDevice> getDataList(@RequestParam("page") Integer pageNo,
+ @RequestParam("limit") Integer pageSize,
+ @RequestParam(value = "searchkey", required = false) Integer searchKey) {
+ try {
+ if (null == pageNo || pageNo < 1) pageNo = WebConstant.PAGENO_DEFAULT;
+ if (null == pageSize || pageSize < 1) pageSize = WebConstant.PAGESIZE_DEFAULT;
+ DeviceSearchBean searchBean = new DeviceSearchBean();
+ searchBean.setPageNo(pageNo);
+ searchBean.setId(searchKey);
+ searchBean.setPageSize(pageSize);
+ return deviceService.getDeviceByKey(searchBean);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return new PageResult<>(99, "系统查询错误");
+ }
+ }
+
+
+ @GetMapping("/loadadd")
+ @PreAuthorize("hasPermission('/devicegroup/loadadd','')")
+ public String loadadd(Model model) {
+ return "devicegroup/form";
+ }
+
+ @PostMapping("/add")
+ @PreAuthorize("hasPermission('/devicegroup/add','')")
+ @ResponseBody
+ public JsonResult add(@RequestBody TDevice device) {
+ if (device != null) {
+ return deviceService.saveDevice(device);
+ } else {
+ return JsonResult.error("添加失败");
+ }
+ }
+
+
+}
diff --git a/src/main/java/com/supwisdom/dlpay/device/dao/DeviceDao.java b/src/main/java/com/supwisdom/dlpay/device/dao/DeviceDao.java
new file mode 100644
index 0000000..4765033
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/device/dao/DeviceDao.java
@@ -0,0 +1,19 @@
+package com.supwisdom.dlpay.device.dao;
+
+
+import com.supwisdom.dlpay.device.domain.TDevice;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface DeviceDao extends JpaSpecificationExecutor<TDevice>,JpaRepository<TDevice, Integer> {
+
+ Page<TDevice> findAllByIdContaining(Integer id, Pageable pageable);
+
+
+
+ TDevice findByDevicename(String devicename);
+}
diff --git a/src/main/java/com/supwisdom/dlpay/device/dao/DeviceGroupDao.java b/src/main/java/com/supwisdom/dlpay/device/dao/DeviceGroupDao.java
new file mode 100644
index 0000000..2171bbd
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/device/dao/DeviceGroupDao.java
@@ -0,0 +1,7 @@
+package com.supwisdom.dlpay.device.dao;
+
+import com.supwisdom.dlpay.device.domain.TDeviceGroup;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+public interface DeviceGroupDao extends JpaRepository<TDeviceGroup, Integer> {
+}
diff --git a/src/main/java/com/supwisdom/dlpay/device/dao/ShopDeviceDao.java b/src/main/java/com/supwisdom/dlpay/device/dao/ShopDeviceDao.java
new file mode 100644
index 0000000..095a1bf
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/device/dao/ShopDeviceDao.java
@@ -0,0 +1,11 @@
+package com.supwisdom.dlpay.device.dao;
+
+import com.supwisdom.dlpay.device.domain.TShopDevice;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface ShopDeviceDao extends JpaSpecificationExecutor<TShopDevice>, JpaRepository<TShopDevice, Integer> {
+
+}
diff --git a/src/main/java/com/supwisdom/dlpay/device/domain/TDevice.java b/src/main/java/com/supwisdom/dlpay/device/domain/TDevice.java
index f07b454..4f74f73 100644
--- a/src/main/java/com/supwisdom/dlpay/device/domain/TDevice.java
+++ b/src/main/java/com/supwisdom/dlpay/device/domain/TDevice.java
@@ -9,14 +9,17 @@
private Integer id;
private String devicename;
private String devphyid;
- private String termid;
+ // private String termid;
private Integer shopid;
private String factoryid;
- private Integer status;
+ private Integer state;
private String operid;
+ private String devgroupid;
+ private String lastsaved;
+
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_DEVICE")
- @Column(name = "id", unique = true, nullable = false, length = 8)
+ @Column(name = "id", unique = true, nullable = false, length = 9)
public Integer getId() {
return id;
}
@@ -26,7 +29,7 @@
}
- @Column(name = "AREANAME", length = 60)
+ @Column(name = "devicename", length = 60)
public String getDevicename() {
return devicename;
}
@@ -35,7 +38,7 @@
this.devicename = devicename;
}
- @Column(name = "devphyid", length = 20)
+ @Column(name = "devphyid",unique = true, length = 20)
public String getDevphyid() {
return devphyid;
}
@@ -44,14 +47,14 @@
this.devphyid = devphyid;
}
- @Column(name = "termid", length = 20)
+/* @Column(name = "termid", length = 20)
public String getTermid() {
return termid;
}
public void setTermid(String termid) {
this.termid = termid;
- }
+ }*/
@Column(name = "shopid", length = 10)
public Integer getShopid() {
return shopid;
@@ -68,13 +71,13 @@
public void setFactoryid(String factoryid) {
this.factoryid = factoryid;
}
- @Column(name = "status", length = 1)
- public Integer getStatus() {
- return status;
+ @Column(name = "state", length = 1)
+ public Integer getState() {
+ return state;
}
- public void setStatus(Integer status) {
- this.status = status;
+ public void setState(Integer status) {
+ this.state = status;
}
@Column(name = "operid", length = 100)
public String getOperid() {
@@ -84,4 +87,21 @@
public void setOperid(String operid) {
this.operid = operid;
}
+
+ @Column(name = "devgroupid", length = 30)
+ public String getDevgroupid() {
+ return devgroupid;
+ }
+
+ public void setDevgroupid(String devgroupid) {
+ this.devgroupid = devgroupid;
+ }
+ @Column(name = "lastsaved", length = 14)
+ public String getLastsaved() {
+ return lastsaved;
+ }
+
+ public void setLastsaved(String lastsaved) {
+ this.lastsaved = lastsaved;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/supwisdom/dlpay/device/domain/TDeviceGroup.java b/src/main/java/com/supwisdom/dlpay/device/domain/TDeviceGroup.java
new file mode 100644
index 0000000..172ca1f
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/device/domain/TDeviceGroup.java
@@ -0,0 +1,31 @@
+package com.supwisdom.dlpay.device.domain;
+
+
+import javax.persistence.*;
+
+@Entity
+@Table(name = "TB_DEVICEGROUP")
+@SequenceGenerator(name="SEQ_DEVGROUP",sequenceName="SEQ_DEVGROUP",allocationSize=1)
+public class TDeviceGroup {
+ private Integer devgroupid;
+ private String groupname;
+
+ @Id
+ @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_DEVGROUP")
+ @Column(name = "devgroupid", unique = true, nullable = false, length = 8)
+ public Integer getDevgroupid() {
+ return devgroupid;
+ }
+
+ public void setDevgroupid(Integer devgroupid) {
+ this.devgroupid = devgroupid;
+ }
+ @Column(name = "groupname", length = 60)
+ public String getGroupname() {
+ return groupname;
+ }
+
+ public void setGroupname(String groupname) {
+ this.groupname = groupname;
+ }
+}
diff --git a/src/main/java/com/supwisdom/dlpay/device/domain/TShopDevice.java b/src/main/java/com/supwisdom/dlpay/device/domain/TShopDevice.java
new file mode 100644
index 0000000..28980e9
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/device/domain/TShopDevice.java
@@ -0,0 +1,43 @@
+package com.supwisdom.dlpay.device.domain;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "TB_SHOPDEVICE")
+public class TShopDevice {
+
+ private Integer deviceid;
+ private Integer shopid;
+ private String operid;
+
+ @Id
+ @Column(name = "DEVICEID", unique = true, nullable = false, length = 9)
+ public Integer getDeviceid() {
+ return deviceid;
+ }
+
+ public void setDeviceid(Integer deviceid) {
+ this.deviceid = deviceid;
+ }
+
+ @Column(name = "SHOPID", nullable = false, length = 10)
+ public Integer getShopid() {
+ return shopid;
+ }
+
+ public void setShopid(Integer shopid) {
+ this.shopid = shopid;
+ }
+
+ @Column(name = "operid", nullable = false, length = 32)
+ public String getOperid() {
+ return operid;
+ }
+
+ public void setOperid(String operid) {
+ this.operid = operid;
+ }
+}
diff --git a/src/main/java/com/supwisdom/dlpay/device/service/DeviceService.java b/src/main/java/com/supwisdom/dlpay/device/service/DeviceService.java
new file mode 100644
index 0000000..7673b73
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/device/service/DeviceService.java
@@ -0,0 +1,25 @@
+package com.supwisdom.dlpay.device.service;
+
+import com.supwisdom.dlpay.api.bean.JsonResult;
+import com.supwisdom.dlpay.area.bean.AreaSearchBean;
+import com.supwisdom.dlpay.device.bean.DeviceSearchBean;
+import com.supwisdom.dlpay.device.domain.TDevice;
+import com.supwisdom.dlpay.framework.util.PageResult;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+public interface DeviceService {
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class,readOnly = true)
+ PageResult<TDevice> getDeviceByKey(DeviceSearchBean param);
+
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class,readOnly = true)
+ List<TDevice> findAll();
+
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
+ JsonResult saveDevice(TDevice device);
+
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
+ boolean updateState(Integer id,Integer state);
+}
diff --git a/src/main/java/com/supwisdom/dlpay/device/service/impl/DeviceServiceImpl.java b/src/main/java/com/supwisdom/dlpay/device/service/impl/DeviceServiceImpl.java
new file mode 100644
index 0000000..efef7b0
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/device/service/impl/DeviceServiceImpl.java
@@ -0,0 +1,100 @@
+package com.supwisdom.dlpay.device.service.impl;
+
+import com.supwisdom.dlpay.api.bean.JsonResult;
+import com.supwisdom.dlpay.device.bean.DeviceSearchBean;
+import com.supwisdom.dlpay.device.dao.DeviceDao;
+import com.supwisdom.dlpay.device.dao.ShopDeviceDao;
+import com.supwisdom.dlpay.device.domain.TDevice;
+import com.supwisdom.dlpay.device.domain.TShopDevice;
+import com.supwisdom.dlpay.device.service.DeviceService;
+import com.supwisdom.dlpay.framework.domain.TOperator;
+import com.supwisdom.dlpay.framework.security.OperUtil;
+import com.supwisdom.dlpay.framework.util.PageResult;
+import com.supwisdom.dlpay.framework.util.StringUtil;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.stereotype.Service;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.List;
+import java.util.Optional;
+
+@Service
+public class DeviceServiceImpl implements DeviceService {
+ @Autowired
+ private DeviceDao deviceDao;
+ @Autowired
+ private ShopDeviceDao shopDeviceDao;
+
+ /* @Override
+ public PageResult<TDevice> getDeviceByKey(DeviceSearchBean param) {
+ Pageable pageable = PageRequest.of(param.getPageNo() - 1, param.getPageSize()
+ , Sort.by("id"));
+
+ Specification<TDevice> spec = new Specification<TDevice>() { //查询条件构造
+ @Override
+ public Predicate toPredicate(Root<TDevice> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
+ List<Predicate> list = new ArrayList<>();
+
+ if (!StringUtil.isEmpty(param.getDevicename())) {
+ list.add(cb.like(root.get("devicename").as(String.class), "%" + param.getDevicename() + "%"));
+ }
+
+ if (!StringUtil.isEmpty(param.getFactoryid())) {
+ list.add(cb.equal(root.get("factoryid").as(String.class), param.getFactoryid()));
+ }
+ if (!StringUtil.isEmpty(param.getTermid())) {
+ list.add(cb.like(root.get("termid").as(String.class), param.getTermid()));
+ }
+ return cb.and(list.toArray(new Predicate[list.size()]));
+ }
+ };
+
+ return new PageResult<>(deviceDao.findAll(spec, pageable));
+ }*/
+ @Override
+ public PageResult<TDevice> getDeviceByKey(DeviceSearchBean param) {
+ Pageable pageable = PageRequest.of(param.getPageNo() - 1, param.getPageSize()
+ , Sort.by("id"));
+ if (null !=param.getId()) {
+ return new PageResult<>(deviceDao.findAllByIdContaining(param.getId(), pageable));
+ }
+ return new PageResult<>(deviceDao.findAll(pageable));
+ }
+
+
+ @Override
+ public List<TDevice> findAll() {
+ return deviceDao.findAll();
+ }
+
+ @Override
+ public JsonResult saveDevice(TDevice device) {
+ if(null==device.getState()){
+ device.setState(1);
+ }
+ TDevice d=deviceDao.save(device);
+ TShopDevice shopDevice=new TShopDevice();
+ shopDevice.setDeviceid(d.getId());
+ shopDevice.setShopid(d.getShopid());
+ shopDevice.setOperid(OperUtil.getCurrentOperid());
+ shopDeviceDao.save(shopDevice);
+
+ return JsonResult.ok("成功");
+ }
+
+ @Override
+ public boolean updateState(Integer id, Integer state) {
+ Optional<TDevice> temp = deviceDao.findById(id);
+ if (!temp.isPresent()) {
+ return false;
+ }
+ TDevice op = temp.get();
+ op.setState(state);
+ deviceDao.save(op);
+ return true;
+ }
+
+
+}
diff --git a/src/main/resources/templates/device/form.html b/src/main/resources/templates/device/form.html
new file mode 100644
index 0000000..6b5265d
--- /dev/null
+++ b/src/main/resources/templates/device/form.html
@@ -0,0 +1,112 @@
+
+<form id="form" lay-filter="form" class="layui-form model-form">
+ <input name="id" id="id" type="hidden"/>
+ <div class="layui-form-item">
+ <label class="layui-form-label">设备物理ID</label>
+ <div class="layui-input-block">
+ <input name="devphyid" placeholder="不能重复" type="text" class="layui-input" maxlength="20"
+ lay-verify="required|devphyid" required/>
+ </div>
+ </div>
+ <div class="layui-form-item">
+ <label class="layui-form-label">设备厂商</label>
+ <div class="layui-input-block">
+ <select name="factoryid" id="factoryid" lay-verify="required">
+ <option value="XKP">新开普</option>
+ </select>
+ </div>
+ </div>
+
+
+ <div class="layui-form-item">
+ <label class="layui-form-label">所属商户ID</label>
+ <div class="layui-input-block">
+ <input name="shopid" placeholder="请输入" type="text" class="layui-input"/>
+ </div>
+ </div>
+
+ <div class="layui-form-item model-form-footer">
+ <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
+ <button class="layui-btn" lay-filter="form-submit" lay-submit id="submitbtn">保存</button>
+ </div>
+</form>
+
+<script>
+ layui.use(['layer', 'admin', 'form', 'formSelects'], function () {
+ var layer = layui.layer;
+ var admin = layui.admin;
+ var form = layui.form;
+ form.render('select');
+ form.render('radio');
+ /*form.verify({
+ "areaname": function (e) {
+ var msg = "";
+ $.ajax({
+ type: "GET",
+ url: '/area/checkname',
+ async: false,
+ data: {
+ areaname: e,
+ },
+ success: function (result) {
+ if (result.code != 200) {
+ msg = result.msg;
+ }
+ },
+ error: function (error) {
+ msg = "请求服务器校验账号失败";
+ }
+ });
+ }
+ });*/
+
+ var url = '/device/add';
+ // 回显user数据
+ var dev = admin.getTempData('t_dev');
+ if (dev) {
+ $('input[name="id"]').attr('readonly', 'readonly');
+ form.val('form', dev);
+ }
+ /* let fid = admin.getTempData("fid");
+ if (fid) {
+ form.val('form', {"fid": fid});
+ }*/
+ // 表单提交事件
+ form.on('submit(form-submit)', function (data) {
+ layer.load(2);
+ let token = $("meta[name='_csrf_token']").attr("value");
+ debugger
+ $.ajax({
+ type: "POST",
+ dataType: "json",
+ url: url,
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json',
+ 'X-CSRF-TOKEN': token,
+ },
+ data: JSON.stringify(data.field),
+ success: function (result) {
+ layer.closeAll('loading');
+ if (result.code == 200) {
+ layer.msg(result.msg, {icon: 1});
+ admin.finishPopupCenter();
+ } else if (result.code == 401) {
+ layer.msg(result.msg, {icon: 2, time: 1500}, function () {
+ location.replace('/login');
+ }, 1000);
+ return;
+ } else {
+ console.log('err:' + result.code);
+ layer.msg(result.msg, {icon: 2});
+ }
+ },
+ error: function () {
+ layer.closeAll('loading');
+ layer.msg("请求服务器失败!", {icon: 2});
+ }
+ });
+ return false;
+ });
+ });
+</script>
\ No newline at end of file
diff --git a/src/main/resources/templates/device/index.html b/src/main/resources/templates/device/index.html
new file mode 100644
index 0000000..59fe5f8
--- /dev/null
+++ b/src/main/resources/templates/device/index.html
@@ -0,0 +1,144 @@
+<div class="layui-card">
+ <div class="layui-card-header">
+ <h2 class="header-title">设备注册</h2>
+ <span class="layui-breadcrumb pull-right">
+ <a href="#">设备注册</a>
+ <a><cite>设备注册</cite></a>
+ </span>
+ </div>
+ <div class="layui-card-body">
+ <div class="layui-form toolbar">
+ 搜索:
+ <input id="search-value" class="layui-input search-input" type="text" placeholder="输入功能名称"/> 
+ <button id="btn-search" class="layui-btn icon-btn" data-type="search"><i class="layui-icon"></i>搜索
+ </button>
+ <button id="btn-add" class="layui-btn icon-btn" data-type="add"><i class="layui-icon"></i>添加设备</button>
+ </div>
+ <table class="layui-table" id="table" lay-filter="table"></table>
+ </div>
+</div>
+
+<script type="text/html" id="dev-tpl-state">
+ <input type="checkbox" lay-filter="dev-tpl-state" value="{{d.id}}" lay-skin="switch" lay-text="正常|注销"
+ {{d.state=='1'?'checked':''}} />
+</script>
+<script>
+
+ layui.use(['form', 'table', 'layer', 'admin', 'element'], function () {
+ let form = layui.form;
+ let table = layui.table;
+ let admin = layui.admin;
+
+ form.render('select');
+
+ // 渲染表格
+ table.render({
+ elem: '#table',
+ url: '/device/list',
+ page: true,
+ cols: [
+ [
+ {field: 'id', title: '终端编号', sort: true},
+ {field: 'devphyid', sort: true, width: 300, title: '设备物理id'},
+ {field: 'shopid', sort: true, width: 300, title: '商户id'},
+ {field: 'factoryid', sort: true, width: 300, title: '设备厂商'},
+ {field: 'state', title: '状态', sort: true, width: 100, templet: '#dev-tpl-state'},
+ {
+ field: 'id', align: 'center', title: '操作', fixed: 'right', templet: function (item) {
+ return ' <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a> ';
+ }
+ }
+ ]
+ ]
+ });
+ // 搜索按钮点击事件
+ $('#btn-search').click(function () {
+ let key = $('#search-value').val();
+ table.reload('table', {where: {searchkey: key}, page: {curr: 1}});
+ });
+ $('#btn-add').click(function () {
+ showModel();
+ });
+ let showModel = function (data) {
+ let title = data ? '修改设备' : '添加设备';
+ admin.putTempData('t_dev', data);
+ admin.popupCenter({
+ title: title,
+ path: '/device/loadadd',
+ finish: function () {
+ table.reload('table', {});
+ }
+ });
+ };
+
+
+ // 工具条点击事件
+ table.on('tool(table)', function (obj) {
+ let data = obj.data;
+ let layEvent = obj.event;
+ console.log(data);
+ if (layEvent === 'edit') {
+ showModel(data);
+ } else if (layEvent === 'del') {
+ showDelete(data);
+ }
+ });
+ let showDelete = function (data) {
+ layer.confirm('确定要删除吗?', function (i) {
+ layer.close(i);
+ layer.load(2);
+ let token = $("meta[name='_csrf_token']").attr("value");
+ admin.go('/device/delete', {
+ id: data.id,
+ _csrf: token
+ }, function (data) {
+ console.log(data.code);
+ layer.closeAll('loading');
+ if (data.code == 200) {
+ layer.msg(data.msg, {icon: 1});
+ } else if (data.code == 401) {
+ layer.msg(data.msg, {icon: 2, time: 1500}, function () {
+ location.replace('/login');
+ }, 1000);
+ return;
+ } else {
+ layer.msg(data.msg, {icon: 2});
+ }
+ table.reload('table', {});
+ }, function (ret) {
+ console.log(ret);
+ layer.closeAll('loading');
+ layer.msg('请求失败了,请稍后再试', {icon: 2});
+ });
+ });
+ };
+
+ form.on('switch(dev-tpl-state)', function (obj) {
+ layer.load(2);
+ let token = $("meta[name='_csrf_token']").attr("value");
+ admin.go('/device/updatestate', {
+ id: obj.elem.value,
+ _csrf: token,
+ state: obj.elem.checked ? 1 : 0
+ }, function (data) {
+ layer.closeAll('loading');
+ if (data.code == 200) {
+ layer.msg(data.msg, {icon: 1});
+ //table.reload('table-user', {});
+ } else if (data.code == 401) {
+ layer.msg(data.msg, {icon: 2, time: 1500}, function () {
+ location.replace('/login');
+ }, 1000);
+ return;
+ } else {
+ layer.msg(data.msg, {icon: 2});
+ $(obj.elem).prop('checked', !obj.elem.checked);
+ form.render('checkbox');
+ }
+ },function () {
+ layer.closeAll('loading');
+ layer.msg('请求失败了,请稍后再试', {icon: 2});
+ });
+ });
+ });
+</script>