Commit a68c0e66 by tyfanchz

调整部分逻辑

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