From 63e2aacfa532af19562b9fc598ede69a1d1839eb Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Wed, 15 Jun 2022 17:22:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bweb/controller/HighDeviceController.java | 34 ++++++++++++------- .../java/com/hai/config/SpPrinterConfig.java | 4 +-- .../com/hai/enum_type/DeviceTypeEnum.java | 4 +-- .../com/hai/service/HighDeviceService.java | 7 ++++ .../service/impl/HighDeviceServiceImpl.java | 17 +++++++--- 5 files changed, 46 insertions(+), 20 deletions(-) diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighDeviceController.java b/hai-bweb/src/main/java/com/bweb/controller/HighDeviceController.java index 4b243b34..3c6a433d 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighDeviceController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighDeviceController.java @@ -6,14 +6,11 @@ import com.github.pagehelper.PageInfo; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; -import com.hai.common.security.SessionObject; import com.hai.common.security.UserCenter; -import com.hai.common.utils.DateUtil; import com.hai.common.utils.ResponseMsgUtil; +import com.hai.config.SpPrinterConfig; import com.hai.entity.*; import com.hai.enum_type.DeviceTypeEnum; -import com.hai.model.HighCouponHandselModel; -import com.hai.model.HighMerchantModel; import com.hai.model.ResponseData; import com.hai.model.UserInfoModel; import com.hai.service.BsCompanyService; @@ -22,7 +19,6 @@ import com.hai.service.HighMerchantService; import com.hai.service.HighMerchantStoreService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,7 +26,6 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; import java.util.HashMap; import java.util.Map; @@ -76,13 +71,12 @@ public class HighDeviceController { } if (body.getType().equals(DeviceTypeEnum.type1.getType()) - && (StringUtils.isBlank(body.getDeviceSn())) || StringUtils.isBlank(body.getDeviceKey())) { + && (StringUtils.isBlank(body.getDeviceSn()) || StringUtils.isBlank(body.getDeviceKey()))) { log.error("HighDeviceController -> editDevice() error!","参数错误"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); - } - if (body.getType().equals(DeviceTypeEnum.type2.getType()) - && (StringUtils.isBlank(body.getDeviceImei())) || StringUtils.isBlank(body.getDeviceIccid())) { + } else if (body.getType().equals(DeviceTypeEnum.type2.getType()) + && (StringUtils.isBlank(body.getDeviceImei()) || StringUtils.isBlank(body.getDeviceIccid()))) { log.error("HighDeviceController -> editDevice() error!","参数错误"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } @@ -114,12 +108,20 @@ public class HighDeviceController { } // 查询分公司 - BsCompany company = companyService.getCompanyById(store.getMerchantId()); + BsCompany company = companyService.getCompanyById(merchant.getCompanyId()); if (company == null) { log.error("HighDeviceController -> editDevice() error!","参数错误"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的分公司"); } + if (body.getType().equals(DeviceTypeEnum.type1.getType())) { + SpPrinterConfig sp = new SpPrinterConfig(); + JSONObject jsonObject = JSONObject.parseObject(sp.addPrinter(body.getDeviceSn(), body.getDeviceKey(), body.getDeviceName())); + if (!jsonObject.getInteger("errorcode").equals(0)) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("errormsg")); + } + } + device.setCompanyId(company.getId()); device.setCompanyName(company.getName()); device.setMerId(merchant.getId()); @@ -137,7 +139,7 @@ public class HighDeviceController { return ResponseMsgUtil.success("操作成功"); } catch (Exception e) { - log.error("HighDeviceController -> insertCoupon() error!",e); + log.error("HighDeviceController -> editDevice() error!",e); return ResponseMsgUtil.exception(e); } } @@ -160,6 +162,14 @@ public class HighDeviceController { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } + if (device.getType().equals(DeviceTypeEnum.type1.getType())) { + SpPrinterConfig sp = new SpPrinterConfig(); + JSONObject jsonObject = JSONObject.parseObject(sp.deletePrinter(device.getDeviceSn())); + if (!jsonObject.getInteger("errorcode").equals(0)) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("errormsg")); + } + } + device.setStatus(0); deviceService.editDevice(device); diff --git a/hai-service/src/main/java/com/hai/config/SpPrinterConfig.java b/hai-service/src/main/java/com/hai/config/SpPrinterConfig.java index f19929e0..f60790de 100644 --- a/hai-service/src/main/java/com/hai/config/SpPrinterConfig.java +++ b/hai-service/src/main/java/com/hai/config/SpPrinterConfig.java @@ -162,9 +162,9 @@ public class SpPrinterConfig { throw new ClientProtocolException(); } - if (response.getStatusLine().getStatusCode() != 200) { +/* if (response.getStatusLine().getStatusCode() != 200) { throw new ClientProtocolException(EntityUtils.toString(httpEntity)); - } + }*/ return EntityUtils.toString(httpEntity); } diff --git a/hai-service/src/main/java/com/hai/enum_type/DeviceTypeEnum.java b/hai-service/src/main/java/com/hai/enum_type/DeviceTypeEnum.java index e80beea9..b8dc1458 100644 --- a/hai-service/src/main/java/com/hai/enum_type/DeviceTypeEnum.java +++ b/hai-service/src/main/java/com/hai/enum_type/DeviceTypeEnum.java @@ -7,8 +7,8 @@ import java.util.Objects; * @author hurui */ public enum DeviceTypeEnum { - type1(0 , "商鹏-4G"), - type2(1, "ZKC-4G"), + type1(1 , "商鹏云打印"), + type2(2, "ZKC云打印"), ; private Integer type; diff --git a/hai-service/src/main/java/com/hai/service/HighDeviceService.java b/hai-service/src/main/java/com/hai/service/HighDeviceService.java index 72521ad7..98051910 100644 --- a/hai-service/src/main/java/com/hai/service/HighDeviceService.java +++ b/hai-service/src/main/java/com/hai/service/HighDeviceService.java @@ -31,5 +31,12 @@ public interface HighDeviceService { */ List getDeviceList(Map param); + /** + * 根据门店id,查询设备列表 + * @param storeId + * @return + */ + List getDeviceListByStoreId(Long storeId); + } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDeviceServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDeviceServiceImpl.java index 28dbdf92..81a1fc72 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighDeviceServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighDeviceServiceImpl.java @@ -21,7 +21,7 @@ public class HighDeviceServiceImpl implements HighDeviceService { @Override public void editDevice(HighDevice device) { - if (device.getId() != null) { + if (device.getId() == null) { device.setCreateTime(new Date()); device.setUpdateTime(new Date()); device.setStatus(1); @@ -47,15 +47,15 @@ public class HighDeviceServiceImpl implements HighDeviceService { } if (MapUtils.getLong(param, "companyId") != null) { - criteria.andCompanyIdEqualTo(MapUtils.getLong(param, "type")); + criteria.andCompanyIdEqualTo(MapUtils.getLong(param, "companyId")); } if (MapUtils.getLong(param, "merId") != null) { criteria.andMerIdEqualTo(MapUtils.getLong(param, "merId")); } - if (MapUtils.getLong(param, "merStoreId") != null) { - criteria.andMerStoreIdEqualTo(MapUtils.getLong(param, "merStoreId")); + if (MapUtils.getLong(param, "storeId") != null) { + criteria.andMerStoreIdEqualTo(MapUtils.getLong(param, "storeId")); } if (StringUtils.isNotBlank(MapUtils.getString(param, "deviceName"))) { @@ -65,4 +65,13 @@ public class HighDeviceServiceImpl implements HighDeviceService { example.setOrderByClause("create_time desc"); return deviceMapper.selectByExample(example); } + + @Override + public List getDeviceListByStoreId(Long storeId) { + HighDeviceExample example = new HighDeviceExample(); + example.createCriteria() + .andMerStoreIdEqualTo(storeId) + .andStatusNotEqualTo(0); + return deviceMapper.selectByExample(example); + } }