package com.prolog.rdc.tms.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.rdc.tms.model.vo.IntfItemSaveVO;
import com.prolog.rdc.tms.service.ItemService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * 
 *
 * 商品资料接口控制层
 *
 * @className :ItemController
 * @author :fanzw
 * @creationTime :2022/11/08
 * @description :
 *
 * @modifier :fanzw
 * @modifyTime :2022/11/08
 * @reviseRemarks:
 *
 * @version :1.0.0
 *
 */
@Slf4j
@Api(tags = "商品资料接口控制层")
@RestController
@RequestMapping("/item")
public class ItemController {

	@Autowired
	private ItemService itemService;

	@UserLog("商品资料接口保存")
	@ApiOperation(value = "商品资料接口保存", notes = "商品资料接口保存")
	@PostMapping("/save")
	public RestMessage<Object> saveItemExecute(@RequestBody IntfItemSaveVO intfItemSaveVO) {
		try {
			log.info("======商品资料接口保存开始:{}", JSONObject.toJSONString(intfItemSaveVO));
			String results = itemService.saveItemData(intfItemSaveVO);
			log.info("======商品资料接口保存结束======");

			if (results == null) {
				return RestMessage.newInstance(true, "商品资料保存成功", null);
			} else {
				return RestMessage.newInstance(false, results, null);
			}
		} catch (Exception e) {
			e.printStackTrace();

			log.info("======商品资料接口保存异常:{}", e.getMessage());

			return RestMessage.newInstance(false, "商品资料保存失败:" + e.getMessage(), null);
		}
	}

}
