Merge remote-tracking branch 'origin/master'
commit
90d507d83b
@ -0,0 +1,93 @@
|
||||
package com.foreverwin.mesnac.common.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.foreverwin.mesnac.common.enums.HandleEnum;
|
||||
import com.foreverwin.mesnac.common.model.Printer;
|
||||
import com.foreverwin.modular.core.util.CommonMethods;
|
||||
import com.foreverwin.modular.core.util.R;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.foreverwin.mesnac.common.service.PrinterService;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Leon.L
|
||||
* @since 2021-08-11
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/PRINTER")
|
||||
public class PrinterController {
|
||||
|
||||
@Autowired
|
||||
public PrinterService printerService;
|
||||
|
||||
/**
|
||||
* 查询所有数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ResponseBody
|
||||
@GetMapping("")
|
||||
public R getPrinterList(Printer printer){
|
||||
List<Printer> result;
|
||||
try {
|
||||
String site = CommonMethods.getSite();
|
||||
printer.setSite(site);
|
||||
|
||||
QueryWrapper<Printer> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.setEntity(printer);
|
||||
result = printerService.list(queryWrapper);
|
||||
} catch (Exception e) {
|
||||
return R.failed(e.getMessage());
|
||||
}
|
||||
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping("/getPrinter")
|
||||
public R savePrinter(String printer) {
|
||||
Printer result = null;
|
||||
try {
|
||||
String site = CommonMethods.getSite();
|
||||
String handle = HandleEnum.PRINT.getHandle(site, printer);
|
||||
result = printerService.getById(handle);
|
||||
} catch (Exception e) {
|
||||
return R.failed(e.getMessage());
|
||||
}
|
||||
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/savePrinter")
|
||||
public R savePrinter(Printer printer) {
|
||||
try {
|
||||
LocalDateTime nowDate = LocalDateTime.now();
|
||||
String site = CommonMethods.getSite();
|
||||
|
||||
String handle = HandleEnum.PRINT.getHandle(site, printer.getPrinter());
|
||||
Printer printerModel = printerService.getById(handle);
|
||||
if (printerModel == null) {
|
||||
printer.setHandle(handle);
|
||||
printer.setSite(site);
|
||||
printer.setCreatedDateTime(nowDate);
|
||||
printer.setModifiedDateTime(nowDate);
|
||||
printerService.save(printer);
|
||||
} else {
|
||||
printerModel.setDescription(printer.getDescription());
|
||||
printerModel.setModifiedDateTime(nowDate);
|
||||
printerService.updateById(printerModel);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return R.failed(e.getMessage());
|
||||
}
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
}
|
@ -1,130 +0,0 @@
|
||||
package com.foreverwin.mesnac.meapi.controller;
|
||||
|
||||
import com.foreverwin.modular.core.util.R;
|
||||
import com.foreverwin.modular.core.util.FrontPage;
|
||||
import com.foreverwin.modular.core.util.CommonMethods;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.foreverwin.mesnac.meapi.service.PrinterService;
|
||||
import com.foreverwin.mesnac.meapi.model.Printer;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Leon.L
|
||||
* @since 2021-07-22
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/PRINTER")
|
||||
public class PrinterController {
|
||||
|
||||
@Autowired
|
||||
public PrinterService printerService;
|
||||
|
||||
/**
|
||||
* 根据id查询
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@ResponseBody
|
||||
@GetMapping("/{id:.+}")
|
||||
public R getPrinterById(@PathVariable String id) {
|
||||
return R.ok( printerService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ResponseBody
|
||||
@GetMapping("")
|
||||
public R getPrinterList(Printer printer){
|
||||
List<Printer> result;
|
||||
try {
|
||||
String site = CommonMethods.getSite();
|
||||
printer.setSite(site);
|
||||
|
||||
QueryWrapper<Printer> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.setEntity(printer);
|
||||
result = printerService.list(queryWrapper);
|
||||
} catch (Exception e) {
|
||||
return R.failed(e.getMessage());
|
||||
}
|
||||
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询数据
|
||||
*
|
||||
* @param frontPage 分页信息
|
||||
* @return
|
||||
*/
|
||||
@ResponseBody
|
||||
@GetMapping("/page")
|
||||
public R page(FrontPage<Printer> frontPage, Printer printer){
|
||||
IPage result;
|
||||
QueryWrapper<Printer> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.setEntity(printer);
|
||||
if (frontPage.getGlobalQuery() != null && !"".equals(frontPage.getGlobalQuery().trim())) {
|
||||
//TODO modify global query
|
||||
queryWrapper.lambda().and(wrapper -> wrapper
|
||||
.like(Printer::getHandle, frontPage.getGlobalQuery())
|
||||
.or().like(Printer::getSite, frontPage.getGlobalQuery())
|
||||
.or().like(Printer::getPrinter, frontPage.getGlobalQuery())
|
||||
.or().like(Printer::getDescription, frontPage.getGlobalQuery())
|
||||
.or().like(Printer::getEnabled, frontPage.getGlobalQuery())
|
||||
);
|
||||
}
|
||||
result = printerService.page(frontPage.getPagePlus(), queryWrapper);
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* @param printer 传递的实体
|
||||
* @return null 失败 实体成功
|
||||
*/
|
||||
@PostMapping
|
||||
public R save(@RequestBody Printer printer) {
|
||||
return R.ok(printerService.save(printer));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param printer 传递的实体
|
||||
* @return null 失败 实体成功
|
||||
*/
|
||||
@PutMapping
|
||||
public R updateById(@RequestBody Printer printer) {
|
||||
return R.ok(printerService.updateById(printer));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id删除对象
|
||||
* @param id 实体ID
|
||||
* @return 0 失败 1 成功
|
||||
*/
|
||||
@ResponseBody
|
||||
@RequestMapping(method = RequestMethod.DELETE, value = "/{id:.+}")
|
||||
public R removeById(@PathVariable("id") String id){
|
||||
return R.ok(printerService.removeById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除对象
|
||||
* @param ids 实体集合ID
|
||||
* @return 0 失败 1 成功
|
||||
*/
|
||||
@ResponseBody
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/delete-batch")
|
||||
public R removeByIds(List<String> ids){
|
||||
return R.ok(printerService.removeByIds(ids));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue