package com.sqx.modules.artificerselfgoods.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.modules.artificerselfgoods.dao.BlArtificerSelfGoodsEntryExitRecordsDao;
import com.sqx.modules.artificerselfgoods.entity.BlArtificerSelfGoods;
import com.sqx.modules.artificerselfgoods.entity.BlArtificerSelfGoodsEntryExitRecords;
import com.sqx.modules.artificerselfgoods.enums.ArtificerSelfGoodsEnum;
import com.sqx.modules.artificerselfgoods.service.BlArtificerSelfGoodsEntryExitRecordsService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * 消息
 */
@Service
public class BlArtificerSelfGoodsEntryExitRecordsServiceImpl extends ServiceImpl<BlArtificerSelfGoodsEntryExitRecordsDao, BlArtificerSelfGoodsEntryExitRecords> implements BlArtificerSelfGoodsEntryExitRecordsService {

	@Override
	public boolean addLog(BlArtificerSelfGoods e,Integer operationType, String createAt, Integer afterTheChangeNum, Integer beforeTheChangeNum, Integer changeNum, BigDecimal purchasePrice, String userId, String remark) {
		BlArtificerSelfGoodsEntryExitRecords log = new BlArtificerSelfGoodsEntryExitRecords();
		log.setCreateTime(DateUtil.now());
		log.setCreateAt(createAt);
		log.setSelfGoodsId(e.getSelfGoodsId());
		log.setSelfGoodsTitle(e.getSelfGoodsTitle());
		log.setSelfGoodsTypeId(e.getSelfGoodsTypeId());
		log.setSelfGoodsTypeParentId(e.getSelfGoodsTypeParentId());
		log.setArtificerId(e.getArtificerId());
		log.setAfterTheChangeNum(afterTheChangeNum);
		log.setBeforeTheChangeNum(beforeTheChangeNum);
		log.setChangeNum(changeNum);
		log.setOperationType(operationType);
		log.setPurchasePrice(purchasePrice);
		log.setUserId(userId);
		log.setRemark(remark);

		save(log);
		return true;
	}

	@Override
	public boolean addInLog(BlArtificerSelfGoods e, String createAt, Integer afterTheChangeNum, Integer beforeTheChangeNum, Integer changeNum, BigDecimal purchasePrice) {
		addLog(e, ArtificerSelfGoodsEnum.OperationType.IN.getValue(), createAt, afterTheChangeNum, beforeTheChangeNum, changeNum, purchasePrice, null, null);
		return true;
	}

	@Override
	public boolean addOutLog(BlArtificerSelfGoods e, String createAt, Integer afterTheChangeNum, Integer beforeTheChangeNum, Integer changeNum, String userId) {
		addLog(e, ArtificerSelfGoodsEnum.OperationType.OUT.getValue(), createAt, afterTheChangeNum, beforeTheChangeNum, changeNum, null, userId, null);
		return true;
	}

	@Override
	public boolean editLog(BlArtificerSelfGoods e, String createAt, Integer afterTheChangeNum, Integer beforeTheChangeNum, Integer changeNum, String remark) {
		addLog(e, ArtificerSelfGoodsEnum.OperationType.EDIT.getValue(), createAt, afterTheChangeNum, beforeTheChangeNum, changeNum, null, null, remark);
		return true;
	}
}
