package com.steerinfo.baseinfo.meterbasevoicerelation.service.impl;

import com.steerinfo.baseinfo.meterbasetare.model.MeterBaseTare;
import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.baseinfo.meterbasevoicerelation.model.MeterBaseVoiceRelation;
import com.steerinfo.baseinfo.meterbasevoicerelation.mapper.MeterBaseVoiceRelationMapper;
import com.steerinfo.baseinfo.meterbasevoicerelation.service.IMeterBaseVoiceRelationService;
import com.steerinfo.framework.service.pagehelper.PageHelper;
import com.steerinfo.framework.service.pagehelper.PageList;
import com.steerinfo.framework.user.UserPayload;
import com.steerinfo.framework.utils.base.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * MeterBaseVoiceRelation服务实现：
 * @author generator
 * @version 1.0-SNAPSHORT 2022-01-05 05:34
 * 类描述
 * 修订历史：
 * 日期：2022-01-05
 * 作者：generator
 * 参考：
 * 描述：MeterBaseVoiceRelation服务实现
 * @see null
 * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
 */
@Service(value = "meterBaseVoiceRelationService")
public class MeterBaseVoiceRelationServiceImpl extends BaseServiceImpl<MeterBaseVoiceRelation, String> implements IMeterBaseVoiceRelationService {

    @Autowired
    private MeterBaseVoiceRelationMapper meterBaseVoiceRelationMapper;

    @Override
    protected IBaseMapper<MeterBaseVoiceRelation, String> getMapper() {
        return meterBaseVoiceRelationMapper;
    }

    @Override
    public String checkandadd(MeterBaseVoiceRelation model)
    {
        String msg=check(model);
        if (StringUtils.isNotEmpty(msg)){
            return msg;
        }

        String no=meterBaseVoiceRelationMapper.GetNewID();
        model.setRelationId(new SimpleDateFormat("yyyyMMdd").format(new Date()) +no);
        meterBaseVoiceRelationMapper.insertSelective(model);
        return "";
    }

    @Override
    public PageList<T> queryForRelationPage(Map<String, Object> parameters, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List rows = meterBaseVoiceRelationMapper.selectRelationByParameters(parameters);
        PageList pageInfo = new PageList(rows);
        return pageInfo;
    }

    private String check(MeterBaseVoiceRelation model)
    {
        if( model == null){
            return "参数为空！！";
        }
        if (StringUtils.isEmpty(model.getVoiceId())){
            return "声音编号不能为空！！";
        }
        if (StringUtils.isEmpty(model.getBaseSpotId())){
            return "秤点编号不能为空！！";
        }

        UserPayload payload = UserPayload.getCurrUser();
        String userId = payload.getUserCode();
        String userName = payload.getUserName();
        if (model.getRelationId() == null) {
            model.setCreateTime(new Date());
            model.setCreateManNo(userId);
            model.setCreateManName(userName);
        }

        return "";
    }

}
