package com.bonus.sgzb.base.service.impl;

import com.bonus.sgzb.base.api.domain.MaMachineLabel;
import com.bonus.sgzb.base.mapper.MaMachineLabelMapper;
import com.bonus.sgzb.base.service.IMaMachineLabelService;
import com.bonus.sgzb.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Service("IMaMachineLabelService")
public class MaMachineLabelServiceImpl implements IMaMachineLabelService
{
    @Autowired
    private MaMachineLabelMapper maMachineLabelMapper;



    /**
     * 查询机具设备标签ma_machine_label列表
     *
     * @param
     * @return 机具设备标签ma_machine_label
     */
    @Override
    public List<MaMachineLabel> selectMaMachineLabelList()
    {
        return maMachineLabelMapper.selectMaMachineLabelList();
    }

    /**
     * 新增机具设备标签ma_machine_label
     *
     * @param maMachineLabel 机具设备标签ma_machine_label
     * @return 结果
     */
    @Override
    public int insertMaMachineLabel(MaMachineLabel maMachineLabel)
    {
        int i;
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
        Date nowDate = DateUtils.getNowDate();
        String format = dateFormat.format(nowDate);
        int lableNum = maMachineLabelMapper.selectLableNumByMonth(nowDate) + 1;
        for (i = 0;i<maMachineLabel.getLabelNum();i++){
            String code="";
            if (lableNum>9 && lableNum<100){
                code = format + "-00" + lableNum;
            }else if (lableNum>99 && lableNum<1000){
                code = format + "-0" + lableNum;
            }else {
                code = format + "-000" + lableNum;
            }
            lableNum++;
            maMachineLabel.setIsBind("0");
            maMachineLabel.setLabelCode(code);
            maMachineLabelMapper.insertMaMachineLabel(maMachineLabel);
        }
        return i;
    }
}
