Commit 7b330ab9 by tyfanchz

1、功能开发

2、细化统一异常处理方法
3、去除无用校验
1 parent a30e33e9
...@@ -3,15 +3,11 @@ package com.glsx.smart.controller; ...@@ -3,15 +3,11 @@ package com.glsx.smart.controller;
import java.util.List; import java.util.List;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.glsx.plat.common.utils.StringUtils;
import com.glsx.smart.dao.entity.SmartDeviceOrder; import com.glsx.smart.dao.entity.SmartDeviceOrder;
import com.glsx.smart.dao.entity.SmartProduct; import com.glsx.smart.dao.entity.SmartProduct;
import com.glsx.smart.exception.BusinessException;
import com.glsx.smart.exception.ResultEnum;
import com.glsx.smart.service.SmartProductService; import com.glsx.smart.service.SmartProductService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
...@@ -52,9 +48,6 @@ public class ProductController { ...@@ -52,9 +48,6 @@ public class ProductController {
@RequestMapping(value = "/getById", method = {RequestMethod.GET, RequestMethod.POST}) @RequestMapping(value = "/getById", method = {RequestMethod.GET, RequestMethod.POST})
public SmartProduct getById(Long id) { public SmartProduct getById(Long id) {
log.info("$$$$ /product/getById param: {}", id); log.info("$$$$ /product/getById param: {}", id);
if (id == null) {
throw new BusinessException(ResultEnum.PARAM_ERROR);
}
return productService.getById(id); return productService.getById(id);
} }
...@@ -64,7 +57,7 @@ public class ProductController { ...@@ -64,7 +57,7 @@ public class ProductController {
* @param product 产品 * @param product 产品
*/ */
@RequestMapping(value = "/save", method = {RequestMethod.POST}) @RequestMapping(value = "/save", method = {RequestMethod.POST})
public void save(@RequestBody @Validated SmartProduct product) { public void save(@RequestBody SmartProduct product) {
log.info("$$$$ /product/save param: {}", JSON.toJSONString(product)); log.info("$$$$ /product/save param: {}", JSON.toJSONString(product));
productService.save(product); productService.save(product);
} }
...@@ -75,11 +68,8 @@ public class ProductController { ...@@ -75,11 +68,8 @@ public class ProductController {
* @param id 产品 id * @param id 产品 id
*/ */
@RequestMapping(value = "/getCommandSetById", method = {RequestMethod.GET, RequestMethod.POST}) @RequestMapping(value = "/getCommandSetById", method = {RequestMethod.GET, RequestMethod.POST})
public List<SmartDeviceOrder> getCommandSetById(String id) { public List<SmartDeviceOrder> getCommandSetById(Long id) {
log.info("$$$$ /product/getCommandSetById param: {}", id); log.info("$$$$ /product/getCommandSetById param: {}", id);
if (StringUtils.isBlank(id)) {
throw new BusinessException(ResultEnum.PARAM_ERROR);
}
return productService.getCommandSetById(id); return productService.getCommandSetById(id);
} }
...@@ -91,9 +81,6 @@ public class ProductController { ...@@ -91,9 +81,6 @@ public class ProductController {
@RequestMapping(value = "/checkShopProductId", method = {RequestMethod.GET, RequestMethod.POST}) @RequestMapping(value = "/checkShopProductId", method = {RequestMethod.GET, RequestMethod.POST})
public Boolean checkShopProductId(String shopProductId) { public Boolean checkShopProductId(String shopProductId) {
log.info("$$$$ /product/checkShopProductId param: {}", shopProductId); log.info("$$$$ /product/checkShopProductId param: {}", shopProductId);
if (StringUtils.isBlank(shopProductId)) {
throw new BusinessException(ResultEnum.PARAM_ERROR);
}
return productService.checkShopProductId(shopProductId); return productService.checkShopProductId(shopProductId);
} }
...@@ -105,9 +92,6 @@ public class ProductController { ...@@ -105,9 +92,6 @@ public class ProductController {
@RequestMapping(value = "/putOnOff", method = {RequestMethod.GET, RequestMethod.POST}) @RequestMapping(value = "/putOnOff", method = {RequestMethod.GET, RequestMethod.POST})
public void putOnOff(Long id) { public void putOnOff(Long id) {
log.info("$$$$ /product/putOnOff param: {}", id); log.info("$$$$ /product/putOnOff param: {}", id);
if (id == null) {
throw new BusinessException(ResultEnum.PARAM_ERROR);
}
productService.putOnOff(id); productService.putOnOff(id);
} }
} }
...@@ -5,12 +5,9 @@ import com.alibaba.fastjson.JSON; ...@@ -5,12 +5,9 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.glsx.smart.dao.entity.SmartProductType; import com.glsx.smart.dao.entity.SmartProductType;
import com.glsx.smart.exception.BusinessException;
import com.glsx.smart.exception.ResultEnum;
import com.glsx.smart.service.SmartProductTypeService; import com.glsx.smart.service.SmartProductTypeService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
...@@ -50,9 +47,6 @@ public class ProductTypeController { ...@@ -50,9 +47,6 @@ public class ProductTypeController {
*/ */
@RequestMapping(value = "/getById", method = {RequestMethod.GET, RequestMethod.POST}) @RequestMapping(value = "/getById", method = {RequestMethod.GET, RequestMethod.POST})
public SmartProductType getById(Long id) { public SmartProductType getById(Long id) {
if (id == null) {
throw new BusinessException(ResultEnum.PARAM_ERROR);
}
return productTypeService.getById(id); return productTypeService.getById(id);
} }
...@@ -73,13 +67,13 @@ public class ProductTypeController { ...@@ -73,13 +67,13 @@ public class ProductTypeController {
* @param productType 产品类型 * @param productType 产品类型
*/ */
@RequestMapping(value = "/save", method = {RequestMethod.POST}) @RequestMapping(value = "/save", method = {RequestMethod.POST})
public void save(@RequestBody @Validated SmartProductType productType) { public void save(@RequestBody SmartProductType productType) {
log.info("$$$$ /productType/save param: {}", JSON.toJSONString(productType)); log.info("$$$$ /productType/save param: {}", JSON.toJSONString(productType));
productTypeService.save(productType); productTypeService.save(productType);
} }
/** /**
* 获取商城标签 * 获取商城标签。
* *
* @return 结果 * @return 结果
*/ */
......
...@@ -5,7 +5,6 @@ import javax.persistence.GenerationType; ...@@ -5,7 +5,6 @@ import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Transient; import javax.persistence.Transient;
import javax.validation.constraints.NotBlank;
import java.util.Date; import java.util.Date;
import com.glsx.smart.pojo.BaseDTO; import com.glsx.smart.pojo.BaseDTO;
import lombok.Data; import lombok.Data;
...@@ -48,7 +47,6 @@ public class SmartProduct extends BaseDTO { ...@@ -48,7 +47,6 @@ public class SmartProduct extends BaseDTO {
/** /**
* 产品名称 * 产品名称
*/ */
@NotBlank
private String productName; private String productName;
/** /**
......
...@@ -4,7 +4,6 @@ import javax.persistence.GeneratedValue; ...@@ -4,7 +4,6 @@ import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType; import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Table; import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import java.util.Date; import java.util.Date;
import com.glsx.smart.pojo.BaseDTO; import com.glsx.smart.pojo.BaseDTO;
import lombok.Data; import lombok.Data;
...@@ -34,7 +33,6 @@ public class SmartProductType extends BaseDTO { ...@@ -34,7 +33,6 @@ public class SmartProductType extends BaseDTO {
/** /**
* 类型名称 * 类型名称
*/ */
@NotBlank
private String typeName; private String typeName;
/** /**
......
...@@ -20,7 +20,7 @@ public interface SmartProductService { ...@@ -20,7 +20,7 @@ public interface SmartProductService {
void save(SmartProduct product); void save(SmartProduct product);
List<SmartDeviceOrder> getCommandSetById(String productId); List<SmartDeviceOrder> getCommandSetById(Long id);
Boolean checkShopProductId(String shopProductId); Boolean checkShopProductId(String shopProductId);
......
...@@ -57,6 +57,9 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct ...@@ -57,6 +57,9 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
@Override @Override
public SmartProduct getById(Long id) { public SmartProduct getById(Long id) {
SmartProduct product = productMapper.selectByPrimaryKey(id); SmartProduct product = productMapper.selectByPrimaryKey(id);
if (product == null) {
throw new BusinessException(ResultEnum.PRODUCT_NOT_FOUND);
}
return product; return product;
} }
...@@ -91,13 +94,13 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct ...@@ -91,13 +94,13 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
/** /**
* 根据产品 id 获取指令集。 * 根据产品 id 获取指令集。
* *
* @param productId 产品 id *
* @return 结果 * @param id@return 结果
*/ */
@Override @Override
public List<SmartDeviceOrder> getCommandSetById(String productId) { public List<SmartDeviceOrder> getCommandSetById(Long id) {
SmartDeviceOrder example = new SmartDeviceOrder(); SmartDeviceOrder example = new SmartDeviceOrder();
example.setProductId(productId); example.setProductId(String.valueOf(id));
return deviceOrderMapper.select(example); return deviceOrderMapper.select(example);
} }
......
...@@ -55,7 +55,11 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro ...@@ -55,7 +55,11 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro
*/ */
@Override @Override
public SmartProductType getById(Long id) { public SmartProductType getById(Long id) {
return productTypeMapper.selectByPrimaryKey(id); SmartProductType productType = productTypeMapper.selectByPrimaryKey(id);
if (productType == null) {
throw new BusinessException(ResultEnum.PRODUCT_TYPE_NOT_FOUND);
}
return productType;
} }
/** /**
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!