|
@@ -0,0 +1,197 @@
|
|
|
+package org.jeecg.modules.system.app.controller;
|
|
|
+
|
|
|
+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.google.gson.JsonObject;
|
|
|
+import com.google.gson.JsonParser;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.common.aspect.annotation.AutoLog;
|
|
|
+import org.jeecg.common.exception.JeecgBootException;
|
|
|
+import org.jeecg.common.system.base.controller.JeecgController;
|
|
|
+import org.jeecg.common.system.query.QueryGenerator;
|
|
|
+import org.jeecg.modules.system.app.entity.AppDevice;
|
|
|
+import org.jeecg.modules.system.app.mapper.AppSiteMapper;
|
|
|
+import org.jeecg.modules.system.app.service.IAppDeviceService;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.servlet.ModelAndView;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.Arrays;
|
|
|
+
|
|
|
+import static org.jeecg.modules.hikiot.HikiotTool.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description: nm_device
|
|
|
+ * @Author: jeecg-boot
|
|
|
+ * @Date: 2025-08-19
|
|
|
+ * @Version: V1.0
|
|
|
+ */
|
|
|
+@Tag(name="nm_device")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/com/AppDevice")
|
|
|
+@Slf4j
|
|
|
+public class AppDeviceController extends JeecgController<AppDevice, IAppDeviceService> {
|
|
|
+ @Resource
|
|
|
+ private IAppDeviceService AppDeviceService;
|
|
|
+ @Resource
|
|
|
+ private AppSiteMapper appSiteMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页列表查询
|
|
|
+ *
|
|
|
+ * @param AppDevice
|
|
|
+ * @param pageNo
|
|
|
+ * @param pageSize
|
|
|
+ * @param req
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ //@AutoLog(value = "nm_device-分页列表查询")
|
|
|
+ @Operation(summary="nm_device-分页列表查询")
|
|
|
+ @GetMapping(value = "/list")
|
|
|
+ public Result<IPage<AppDevice>> queryPageList(AppDevice AppDevice,
|
|
|
+ @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
|
|
+ @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
|
|
+ HttpServletRequest req) {
|
|
|
+
|
|
|
+
|
|
|
+ QueryWrapper<AppDevice> queryWrapper = QueryGenerator.initQueryWrapper(AppDevice, req.getParameterMap());
|
|
|
+ Page<AppDevice> page = new Page<AppDevice>(pageNo, pageSize);
|
|
|
+ IPage<AppDevice> pageList = AppDeviceService.page(page, queryWrapper);
|
|
|
+ pageList.getRecords().forEach(item->{
|
|
|
+ item.setSiteName(appSiteMapper.selectById(item.getSiteId()).getName());
|
|
|
+ });
|
|
|
+ return Result.OK(pageList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加
|
|
|
+ *
|
|
|
+ * @param AppDevice
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "nm_device-添加")
|
|
|
+ @Operation(summary="nm_device-添加")
|
|
|
+ @RequiresPermissions("com:nm_device:add")
|
|
|
+ @PostMapping(value = "/add")
|
|
|
+ @Transactional
|
|
|
+ public Result<String> add(@RequestBody AppDevice AppDevice){
|
|
|
+ AppDeviceService.save(AppDevice);
|
|
|
+ try {
|
|
|
+ if(AppDevice.getDeviceSerial() != null && AppDevice.getValidateCode() != null){
|
|
|
+ String addDevice = addDevice(AppDevice.getDeviceSerial(), AppDevice.getValidateCode());
|
|
|
+ String userWeekPlan = addUserWeekPlan(AppDevice.getDeviceSerial());
|
|
|
+ String userPlanTemplate = addUserPlanTemplate(AppDevice.getDeviceSerial());
|
|
|
+ JsonObject deviceJson = JsonParser.parseString(addDevice).getAsJsonObject();
|
|
|
+ JsonObject userWeekPlanJson = JsonParser.parseString(userWeekPlan).getAsJsonObject();
|
|
|
+ JsonObject userPlanTemplateJson = JsonParser.parseString(userPlanTemplate).getAsJsonObject();
|
|
|
+ if(deviceJson.get("code").getAsInt() == 0
|
|
|
+ && userWeekPlanJson.get("code").getAsInt() == 0
|
|
|
+ && userPlanTemplateJson.get("code").getAsInt() == 0){
|
|
|
+ return Result.OK("添加成功!");
|
|
|
+ }else {
|
|
|
+ return Result.OK("添加失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new JeecgBootException("添加失败!");
|
|
|
+ }
|
|
|
+ return Result.OK("添加成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑
|
|
|
+ *
|
|
|
+ * @param AppDevice
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "nm_device-编辑")
|
|
|
+ @Operation(summary="nm_device-编辑")
|
|
|
+ @RequiresPermissions("com:nm_device:edit")
|
|
|
+ @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
|
|
+ public Result<String> edit(@RequestBody AppDevice AppDevice) {
|
|
|
+ AppDeviceService.updateById(AppDevice);
|
|
|
+ return Result.OK("编辑成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过id删除
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "nm_device-通过id删除")
|
|
|
+ @Operation(summary="nm_device-通过id删除")
|
|
|
+ @RequiresPermissions("com:nm_device:delete")
|
|
|
+ @DeleteMapping(value = "/delete")
|
|
|
+ public Result<String> delete(@RequestParam(name="id",required=true) String id) {
|
|
|
+ AppDeviceService.removeById(id);
|
|
|
+ return Result.OK("删除成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量删除
|
|
|
+ *
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "nm_device-批量删除")
|
|
|
+ @Operation(summary="nm_device-批量删除")
|
|
|
+ @RequiresPermissions("com:nm_device:deleteBatch")
|
|
|
+ @DeleteMapping(value = "/deleteBatch")
|
|
|
+ public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
|
|
+ this.AppDeviceService.removeByIds(Arrays.asList(ids.split(",")));
|
|
|
+ return Result.OK("批量删除成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过id查询
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ //@AutoLog(value = "nm_device-通过id查询")
|
|
|
+ @Operation(summary="nm_device-通过id查询")
|
|
|
+ @GetMapping(value = "/queryById")
|
|
|
+ public Result<AppDevice> queryById(@RequestParam(name="id",required=true) String id) {
|
|
|
+ AppDevice appDevice = AppDeviceService.getById(id);
|
|
|
+ if(appDevice==null) {
|
|
|
+ return Result.error("未找到对应数据");
|
|
|
+ }
|
|
|
+ appDevice.setSiteName(appSiteMapper.selectById(appDevice.getSiteId()).getName());
|
|
|
+ return Result.OK(appDevice);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出excel
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param AppDevice
|
|
|
+ */
|
|
|
+ @RequiresPermissions("com:nm_device:exportXls")
|
|
|
+ @RequestMapping(value = "/exportXls")
|
|
|
+ public ModelAndView exportXls(HttpServletRequest request, AppDevice AppDevice) {
|
|
|
+ return super.exportXls(request, AppDevice, AppDevice.class, "nm_device");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过excel导入数据
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequiresPermissions("com:nm_device:importExcel")
|
|
|
+ @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
|
|
+ public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ return super.importExcel(request, response, AppDevice.class);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|