package com.dk.mdm.service.mst;

import com.dk.common.infrastructure.annotaiton.Pagination;
import com.dk.common.infrastructure.constant.Constant;
import com.dk.common.model.pojo.PageList;
import com.dk.common.response.ResponseResultUtil;
import com.dk.common.response.ResponseResultVO;
import com.dk.mdm.infrastructure.convert.mst.GoodsSkuConvert;
import com.dk.mdm.model.pojo.mst.GoodsSku;
import com.dk.mdm.mapper.mst.GoodsSkuMapper;
import com.dk.common.service.BaseService;
import com.dk.common.mapper.BaseMapper;
import com.dk.mdm.model.pojo.mst.Role;
import com.dk.mdm.model.query.mst.GoodsSkuQuery;
import com.dk.mdm.model.query.mst.RoleQuery;
import com.dk.mdm.model.response.mst.GoodsSkuResponse;
import com.dk.mdm.model.response.mst.RoleResponse;
import com.dk.mdm.model.vo.mst.GoodsSkuVO;
import com.dk.mdm.model.vo.mst.RoleVo;
import com.dk.mdm.service.common.CommonService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

@Service
@Transactional
public class GoodsSkuService extends BaseService<GoodsSku> {

	@Override
	public BaseMapper<GoodsSku> getRepository() {
		return goodsSkuMapper;
	}

	@Autowired
	private GoodsSkuMapper goodsSkuMapper;


	@Autowired
	private GoodsSkuConvert goodsSkuConvert;
 /**
     * @desc   : 重写组件
     * @author : 王英杰
     * @date   : 2024/3/4 14:51
     */
	@Override
	public String getPrimaryKey() {
		return "sku_id";
	}
	@Autowired
	private CommonService commonService;
	/**
	 * @desc : 查询
	 * @author : 王英杰
	 * @date : 2023/1/5 9:39
	 */
	@Pagination
	public ResponseResultVO<PageList<GoodsSkuResponse>> selectByCond(GoodsSkuQuery goodsSkuQuery) {
		return super.mergeListWithCount(goodsSkuQuery, goodsSkuMapper.selectByCond(goodsSkuQuery),
				goodsSkuMapper.countByCond(goodsSkuQuery));
	}



	/**
	 * @desc : 新建
	 * @author : 王英杰
	 * @date : 2023/1/5 9:39
	 */
	@Transactional(
			rollbackFor = {Exception.class}
	)
	public ResponseResultVO<?> insert(GoodsSkuVO goodsSkuVO) {
		GoodsSku goodsSku = goodsSkuConvert.convertToPo(goodsSkuVO);
		// 获取编码和主键UuId
		Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.GOODSSKU.getName(), true);
		goodsSku.setSkuId(codeMap.get("outId").toString());
		goodsSku.setSkuCode(codeMap.get("outNote").toString());
		super.insert(goodsSku);
		return ResponseResultUtil.success();
	}
	/**
	 * @desc : 新建
	 * @author : 王英杰
	 * @date : 2023/1/5 9:39
	 */
	@Transactional(
			rollbackFor = {Exception.class}
	)
	public ResponseResultVO<?> update(GoodsSkuVO goodsSkuVO) {
		GoodsSku goodsSku = goodsSkuConvert.convertToPo(goodsSkuVO);
		// 获取编码和主键UuId
		super.updateByUuid(goodsSku);
		return ResponseResultUtil.success();
	}

}
