package com.mortals.xhx.module.skin.service.impl;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.mortals.framework.common.Rest;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.pdu.device.DeviceMsgReqPdu;
import com.mortals.xhx.feign.device.IDeviceMessageFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.xhx.module.skin.dao.SkinDao;
import com.mortals.xhx.module.skin.model.SkinEntity;
import com.mortals.xhx.module.skin.service.SkinService;
/**
* SkinService
* 皮肤 service实现
*
* @author zxfei
* @date 2023-04-03
*/
@Service("skinService")
@Slf4j
public class SkinServiceImpl extends AbstractCRUDServiceImpl<SkinDao, SkinEntity, Long> implements SkinService {


    @Override
    protected void updateBefore(SkinEntity entity, Context context) throws AppException {
        super.updateBefore(entity, context);

        if(YesNoEnum.YES.getValue()==entity.getUsed()){
            //修改非当前皮肤都未未使用
            SkinEntity skinEntity = new SkinEntity();
            skinEntity.setUsed(YesNoEnum.NO.getValue());

            SkinEntity condition = new SkinEntity();
            condition.setUsed(YesNoEnum.YES.getValue());
            this.updateBatch(skinEntity,condition,context);
        }
    }

}