package com.yiqi.core.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yiqi.common.core.domain.AuthHolder;
import com.yiqi.common.enums.UserStatus;
import com.yiqi.common.utils.DateUtils;
import com.yiqi.common.utils.SecurityUtils;
import com.yiqi.core.domain.vo.ClothFlawVo;
import org.springframework.stereotype.Service;
import com.yiqi.core.mapper.ClothFlawMapper;
import com.yiqi.core.domain.ClothFlaw;
import com.yiqi.core.service.IClothFlawService;

/**
 * 衣服瑕疵Service业务层处理
 *
 * @author ruoyi
 * @date 2023-08-03
 */
@Service
public class ClothFlawServiceImpl extends ServiceImpl<ClothFlawMapper, ClothFlaw> implements IClothFlawService {


    @Override
    public List<ClothFlaw> allClothFlaw() {
        return baseMapper.allClothFlaw(SecurityUtils.getLoginUser().getOrgId(),SecurityUtils.getLoginUser().getSourceType());
    }

    /**
     * 查询衣服瑕疵
     *
     * @param id 衣服瑕疵主键
     * @return 衣服瑕疵
     */
    @Override
    public ClothFlawVo selectClothFlawById(Long id) {
        return baseMapper.selectClothFlawById(id);
    }

    /**
     * 查询衣服瑕疵列表
     *
     * @param clothFlaw 衣服瑕疵
     * @return 衣服瑕疵
     */
    @Override
    public List<ClothFlawVo> selectClothFlawList(ClothFlaw clothFlaw) {
        return baseMapper.selectClothFlawList(clothFlaw);
    }

    /**
     * 新增衣服瑕疵
     *
     * @param clothFlaw 衣服瑕疵
     * @return 结果
     */
    @Override
    public int insertClothFlaw(ClothFlaw clothFlaw) {
        clothFlaw.setCreateTime(DateUtils.getNowDate());
        clothFlaw.setCreateBy(SecurityUtils.getUsername());
        clothFlaw.setCreateById(SecurityUtils.getUserId());
        clothFlaw.setDelFlag(UserStatus.OK.getCode());
        clothFlaw.setStatus(UserStatus.OK.getCode());
        return baseMapper.insertClothFlaw(clothFlaw);
    }

    /**
     * 修改衣服瑕疵
     *
     * @param clothFlaw 衣服瑕疵
     * @return 结果
     */
    @Override
    public int updateClothFlaw(ClothFlaw clothFlaw) {
        clothFlaw.setUpdateTime(DateUtils.getNowDate());
        clothFlaw.setUpdateBy(SecurityUtils.getUsername());
        clothFlaw.setUpdateById(SecurityUtils.getUserId());
        return baseMapper.updateClothFlaw(clothFlaw);
    }

    /**
     * 批量删除衣服瑕疵
     *
     * @param ids 需要删除的衣服瑕疵主键
     * @return 结果
     */
    @Override
    public int deleteClothFlawByIds(Long[] ids) {
        return baseMapper.deleteClothFlawByIds(ids);
    }

    /**
     * 删除衣服瑕疵信息
     *
     * @param id 衣服瑕疵主键
     * @return 结果
     */
    @Override
    public int deleteClothFlawById(Long id) {
        return baseMapper.deleteClothFlawById(id);
    }

    @Override
    public int updateFlawStatus(ClothFlaw clothFlaw) {
        clothFlaw.setUpdateTime(DateUtils.getNowDate());
        clothFlaw.setUpdateBy(SecurityUtils.getUsername());
        clothFlaw.setUpdateById(SecurityUtils.getUserId());
        return baseMapper.updateClothFlaw(clothFlaw);
    }
}
