|
|
@@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
+import shop.alien.entity.result.R;
|
|
|
import shop.alien.entity.store.PrinterDO;
|
|
|
import shop.alien.entity.store.StoreReceiptTemplateConfig;
|
|
|
import shop.alien.mapper.PrinterMapper;
|
|
|
@@ -171,21 +172,21 @@ public class PrintController {
|
|
|
* 请求体:PrinterDO JSON(至少包含 sn、brand、printerName、storeId)
|
|
|
*/
|
|
|
@PostMapping("/createPrinter")
|
|
|
- public Object createPrinter(@RequestBody PrinterDO body) {
|
|
|
+ public R<PrinterDO> createPrinter(@RequestBody PrinterDO body) {
|
|
|
if (body == null) {
|
|
|
- return "参数不能为空";
|
|
|
+ return R.fail("请求体不能为空");
|
|
|
}
|
|
|
if (body.getSn() == null || body.getSn().trim().isEmpty()) {
|
|
|
- return "sn不能为空";
|
|
|
+ return R.fail("sn不能为空");
|
|
|
}
|
|
|
if (body.getBrand() == null || body.getBrand().trim().isEmpty()) {
|
|
|
- return "brand不能为空";
|
|
|
+ return R.fail("brand不能为空");
|
|
|
}
|
|
|
if (body.getPrinterName() == null || body.getPrinterName().trim().isEmpty()) {
|
|
|
- return "printerName不能为空";
|
|
|
+ return R.fail("printerName不能为空");
|
|
|
}
|
|
|
if (body.getStoreId() == null || body.getStoreId() <= 0) {
|
|
|
- return "storeId必须大于0";
|
|
|
+ return R.fail("storeId必须大于0");
|
|
|
}
|
|
|
// 去重:同门店下 SN 唯一且未删除
|
|
|
Long exists = Long.valueOf(printerMapper.selectCount(
|
|
|
@@ -195,15 +196,18 @@ public class PrintController {
|
|
|
.eq(PrinterDO::getDelFlag, "0")
|
|
|
));
|
|
|
if (exists > 0) {
|
|
|
- return "该门店已存在相同SN的打印机";
|
|
|
+ return R.fail("该门店已存在相同SN的打印机");
|
|
|
}
|
|
|
body.setId(null);
|
|
|
body.setCreateTime(LocalDateTime.now());
|
|
|
if (body.getDelFlag() == null) {
|
|
|
body.setDelFlag("0");
|
|
|
}
|
|
|
- printerMapper.insert(body);
|
|
|
- return body;
|
|
|
+ int a=printerMapper.insert(body);
|
|
|
+ if (a<=0) {
|
|
|
+ return R.fail("添加失败");
|
|
|
+ }
|
|
|
+ return R.data(body);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -221,12 +225,12 @@ public class PrintController {
|
|
|
* 解绑打印机
|
|
|
*/
|
|
|
@PostMapping ("/delete")
|
|
|
- public String delete(@RequestBody PrinterDO body) {
|
|
|
+ public R<String> delete(@RequestBody PrinterDO body) {
|
|
|
PrinterDO printer = new PrinterDO();
|
|
|
printer.setId(body.getId());
|
|
|
printer.setDelFlag("1");
|
|
|
int a =printerMapper.updateById(printer);
|
|
|
- return a>0?"解绑成功":"解绑失败";
|
|
|
+ return a>0?R.success("解绑成功"):R.fail("解绑失败");
|
|
|
}
|
|
|
|
|
|
|