Commit a68c0e66 by tyfanchz

调整部分逻辑

1 parent 1490ee43
...@@ -55,11 +55,12 @@ public class ProductController { ...@@ -55,11 +55,12 @@ public class ProductController {
* 保存产品。无则插入,有则更新。 * 保存产品。无则插入,有则更新。
* *
* @param product 产品 * @param product 产品
* @return 是否成功
*/ */
@RequestMapping(value = "/save", method = {RequestMethod.POST}) @RequestMapping(value = "/save", method = {RequestMethod.POST})
public void save(@RequestBody SmartProduct product) { public Boolean save(@RequestBody SmartProduct product) {
log.info("$$$$ /product/save param: {}", JSON.toJSONString(product)); log.info("$$$$ /product/save param: {}", JSON.toJSONString(product));
productService.save(product); return productService.save(product);
} }
/** /**
...@@ -77,6 +78,7 @@ public class ProductController { ...@@ -77,6 +78,7 @@ public class ProductController {
* 校验商城商品 id。 * 校验商城商品 id。
* *
* @param shopProductId 商品 id * @param shopProductId 商品 id
* @return 商品 id 是否合法
*/ */
@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) {
...@@ -88,10 +90,11 @@ public class ProductController { ...@@ -88,10 +90,11 @@ public class ProductController {
* 上下架产品。 * 上下架产品。
* *
* @param id 产品 id * @param id 产品 id
* @return 是否成功
*/ */
@RequestMapping(value = "/putOnOff", method = {RequestMethod.GET, RequestMethod.POST}) @RequestMapping(value = "/putOnOff", method = {RequestMethod.GET, RequestMethod.POST})
public void putOnOff(Long id) { public Boolean putOnOff(Long id) {
log.info("$$$$ /product/putOnOff param: {}", id); log.info("$$$$ /product/putOnOff param: {}", id);
productService.putOnOff(id); return productService.putOnOff(id);
} }
} }
...@@ -65,11 +65,12 @@ public class ProductTypeController { ...@@ -65,11 +65,12 @@ public class ProductTypeController {
* 保存产品类型。 * 保存产品类型。
* *
* @param productType 产品类型 * @param productType 产品类型
* @return 是否成功
*/ */
@RequestMapping(value = "/save", method = {RequestMethod.POST}) @RequestMapping(value = "/save", method = {RequestMethod.POST})
public void save(@RequestBody SmartProductType productType) { public Boolean save(@RequestBody SmartProductType productType) {
log.info("$$$$ /productType/save param: {}", JSON.toJSONString(productType)); log.info("$$$$ /productType/save param: {}", JSON.toJSONString(productType));
productTypeService.save(productType); return productTypeService.save(productType);
} }
/** /**
......
...@@ -18,11 +18,11 @@ public interface SmartProductService { ...@@ -18,11 +18,11 @@ public interface SmartProductService {
SmartProduct getById(Long id); SmartProduct getById(Long id);
void save(SmartProduct product); Boolean save(SmartProduct product);
List<SmartDeviceOrder> getCommandSetById(Long id); List<SmartDeviceOrder> getCommandSetById(Long id);
Boolean checkShopProductId(String shopProductId); Boolean checkShopProductId(String shopProductId);
void putOnOff(Long id); Boolean putOnOff(Long id);
} }
...@@ -20,7 +20,7 @@ public interface SmartProductTypeService { ...@@ -20,7 +20,7 @@ public interface SmartProductTypeService {
JSONObject getTypeAndCategory(); JSONObject getTypeAndCategory();
void save(SmartProductType productType); Boolean save(SmartProductType productType);
List<String> getShopTagList(); List<String> getShopTagList();
} }
...@@ -67,10 +67,12 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct ...@@ -67,10 +67,12 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
* 保存产品。无则插入,有则更新。 * 保存产品。无则插入,有则更新。
* *
* @param product 产品 * @param product 产品
* @return 是否成功
*/ */
@Override @Override
@Transactional @Transactional
public void save(SmartProduct product) { public Boolean save(SmartProduct product) {
boolean success;
Date now = new Date(); Date now = new Date();
product.setUpdateTime(now); product.setUpdateTime(now);
product.setUpdateBy(0L); product.setUpdateBy(0L);
...@@ -82,22 +84,24 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct ...@@ -82,22 +84,24 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
} }
product.setCreateTime(now); product.setCreateTime(now);
product.setCreateBy(0L); product.setCreateBy(0L);
productMapper.insertSelective(product); success = productMapper.insertSelective(product) > 0;
} else { } else {
SmartProduct record = productMapper.selectByPrimaryKey(product.getId()); SmartProduct record = productMapper.selectByPrimaryKey(product.getId());
if (record != null) { if (record != null) {
productMapper.updateByPrimaryKeySelective(product); success = productMapper.updateByPrimaryKeySelective(product) > 0;
} else { } else {
throw new BusinessException(ResultEnum.PRODUCT_NOT_FOUND); throw new BusinessException(ResultEnum.PRODUCT_NOT_FOUND);
} }
} }
return success;
} }
/** /**
* 根据产品 id 获取指令集。 * 根据产品 id 获取指令集。
* *
* * @param id 产品 id
* @param id@return 结果 * @return 结果
*/ */
@Override @Override
public List<SmartDeviceOrder> getCommandSetById(Long id) { public List<SmartDeviceOrder> getCommandSetById(Long id) {
...@@ -121,14 +125,18 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct ...@@ -121,14 +125,18 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
* 上下架产品。 * 上下架产品。
* *
* @param id 产品 id * @param id 产品 id
* @return 是否成功
*/ */
@Override @Override
public void putOnOff(Long id) { @Transactional
public Boolean putOnOff(Long id) {
boolean success;
SmartProduct product = productMapper.selectByPrimaryKey(id); SmartProduct product = productMapper.selectByPrimaryKey(id);
if (product == null) { if (product == null) {
throw new BusinessException(ResultEnum.PRODUCT_NOT_FOUND); throw new BusinessException(ResultEnum.PRODUCT_NOT_FOUND);
} }
product.setStatus((byte) (product.getStatus() ^ 0b00000001)); product.setStatus((byte) (product.getStatus() ^ 0b00000001));
productMapper.updateByPrimaryKeySelective(product); success = productMapper.updateByPrimaryKeySelective(product) > 0;
return success;
} }
} }
...@@ -107,10 +107,12 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro ...@@ -107,10 +107,12 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro
* 保存产品类型。 * 保存产品类型。
* *
* @param productType 产品类型 * @param productType 产品类型
* @return 是否成功
*/ */
@Override @Override
@Transactional @Transactional
public void save(SmartProductType productType) { public Boolean save(SmartProductType productType) {
boolean success;
Date now = new Date(); Date now = new Date();
productType.setUpdateTime(now); productType.setUpdateTime(now);
productType.setUpdateBy(0L); productType.setUpdateBy(0L);
...@@ -122,15 +124,17 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro ...@@ -122,15 +124,17 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro
} }
productType.setCreateTime(now); productType.setCreateTime(now);
productType.setCreateBy(0L); productType.setCreateBy(0L);
productTypeMapper.insertSelective(productType); success = productTypeMapper.insertSelective(productType) > 0;
} else { } else {
SmartProductType record = productTypeMapper.selectByPrimaryKey(productType.getId()); SmartProductType record = productTypeMapper.selectByPrimaryKey(productType.getId());
if (record != null) { if (record != null) {
productTypeMapper.updateByPrimaryKeySelective(productType); success = productTypeMapper.updateByPrimaryKeySelective(productType) > 0;
} else { } else {
throw new BusinessException(ResultEnum.PRODUCT_TYPE_NOT_FOUND); throw new BusinessException(ResultEnum.PRODUCT_TYPE_NOT_FOUND);
} }
} }
return success;
} }
/** /**
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!