|
@@ -1,15 +1,20 @@
|
|
package com.example.opc_da.service.impl;
|
|
package com.example.opc_da.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.extra.servlet.ServletUtil;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.example.opc_common.entity.PrintConfig;
|
|
import com.example.opc_common.entity.PrintConfig;
|
|
import com.example.opc_common.enums.ResultEnum;
|
|
import com.example.opc_common.enums.ResultEnum;
|
|
|
|
+import com.example.opc_common.util.Blank;
|
|
import com.example.opc_common.util.Result;
|
|
import com.example.opc_common.util.Result;
|
|
import com.example.opc_da.dao.PrintDao;
|
|
import com.example.opc_da.dao.PrintDao;
|
|
|
|
+import com.example.opc_da.dao.ReportTableDao;
|
|
import com.example.opc_da.service.PrintService;
|
|
import com.example.opc_da.service.PrintService;
|
|
|
|
+import com.example.opc_da.util.UserUtil;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
@@ -18,9 +23,15 @@ public class PrintServiceImpl implements PrintService {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private PrintDao printDao;
|
|
private PrintDao printDao;
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserUtil userUtil;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ReportTableDao reportTableDao;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Result addPrintConfig(PrintConfig printConfig) {
|
|
public Result addPrintConfig(PrintConfig printConfig) {
|
|
|
|
+ String currentUserId = userUtil.getCurrentUserId();
|
|
|
|
+ printConfig.setUserId(currentUserId);
|
|
if (printDao.addPrintConfig(printConfig) <= 0) {
|
|
if (printDao.addPrintConfig(printConfig) <= 0) {
|
|
return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "新增打印配置失败");
|
|
return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "新增打印配置失败");
|
|
}
|
|
}
|
|
@@ -37,10 +48,11 @@ public class PrintServiceImpl implements PrintService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Result getAllPrintConfig(Integer page, Integer limit) {
|
|
public Result getAllPrintConfig(Integer page, Integer limit) {
|
|
|
|
+ String currentUserId = userUtil.getCurrentUserId();
|
|
JSONObject jsonObject = new JSONObject();
|
|
JSONObject jsonObject = new JSONObject();
|
|
- Long count = printDao.getPrintConfigCount();
|
|
|
|
|
|
+ Long count = printDao.getPrintConfigCount(currentUserId);
|
|
Long startNum = Long.valueOf((page - 1) * limit);
|
|
Long startNum = Long.valueOf((page - 1) * limit);
|
|
- List<PrintConfig> printConfigList = printDao.getAllPrintConfig(startNum, Long.valueOf(limit));
|
|
|
|
|
|
+ List<PrintConfig> printConfigList = printDao.getAllPrintConfig(currentUserId,startNum, Long.valueOf(limit));
|
|
jsonObject.put("count", count);
|
|
jsonObject.put("count", count);
|
|
jsonObject.put("printConfigList", printConfigList);
|
|
jsonObject.put("printConfigList", printConfigList);
|
|
return Result.ok(jsonObject);
|
|
return Result.ok(jsonObject);
|
|
@@ -48,10 +60,23 @@ public class PrintServiceImpl implements PrintService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Result delPrintConfigById(Integer id) {
|
|
public Result delPrintConfigById(Integer id) {
|
|
- int count = 0;
|
|
|
|
- if (count > 0) {
|
|
|
|
- return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此打印配置被配置在打印任务中,不能删除");
|
|
|
|
|
|
+ //int count = 0;
|
|
|
|
+ //获得已配置打印机的报表列表
|
|
|
|
+ List<String> reportTableNameList = reportTableDao.getReportTableNameByPrintConfigId(id);
|
|
|
|
+ if (Blank.isNotEmpty(reportTableNameList)) {
|
|
|
|
+ String message = "此打印配置已被配置在报表【";
|
|
|
|
+ for (int i = 0; i < reportTableNameList.size(); i++) {
|
|
|
|
+ if (i != 0) {
|
|
|
|
+ message += ",";
|
|
|
|
+ }
|
|
|
|
+ message += reportTableNameList.get(i);
|
|
|
|
+ }
|
|
|
|
+ message += "】中,删除失败";
|
|
|
|
+ return Result.no(ResultEnum.OPERATION_ERROR.getRespCode(), message);
|
|
}
|
|
}
|
|
|
|
+// if (count > 0) {
|
|
|
|
+// return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此打印配置被配置在打印任务中,不能删除");
|
|
|
|
+// }
|
|
if (printDao.delPrintConfigById(id) <= 0) {
|
|
if (printDao.delPrintConfigById(id) <= 0) {
|
|
return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "删除打印配置失败");
|
|
return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "删除打印配置失败");
|
|
}
|
|
}
|
|
@@ -63,4 +88,11 @@ public class PrintServiceImpl implements PrintService {
|
|
return Result.ok(printDao.getPrintConfigById(id));
|
|
return Result.ok(printDao.getPrintConfigById(id));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public Result getClientIp(HttpServletRequest request){
|
|
|
|
+ String clientIP = ServletUtil.getClientIP(request, "");
|
|
|
|
+ clientIP = "0:0:0:0:0:0:0:1".equals(clientIP) ? "127.0.0.1" : clientIP;
|
|
|
|
+ return Result.ok(clientIP);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|