package com.steerinfo.meterwork.meterworkimage.service.impl;

import com.steerinfo.framework.controller.RESTfulResult;
import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.meterwork.except.MarkerMetException;
import com.steerinfo.meterwork.meterworkimage.mapper.MeterWorkImageMapper;
import com.steerinfo.meterwork.meterworkimage.model.MeterWorkImage;
import com.steerinfo.meterwork.meterworkimage.service.IMeterWorkImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * MeterWorkImage服务实现：
 * @author generator
 * @version 1.0-SNAPSHORT 2020-09-19 04:48
 * 类描述
 * 修订历史：
 * 日期：2020-09-19
 * 作者：generator
 * 参考：
 * 描述：MeterWorkImage服务实现
 * @see null
 * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
 */
@Service(value = "meterWorkImageService")
public class MeterWorkImageServiceImpl extends BaseServiceImpl<MeterWorkImage, String> implements IMeterWorkImageService {

    @Resource
    private MeterWorkImageMapper meterWorkImageMapper;

    @Override
    protected IBaseMapper<MeterWorkImage, String> getMapper() {
        return meterWorkImageMapper;
    }
    public ArrayList<String> queryUrl(String actualFirstNo)
    {
        try {
            if (actualFirstNo == null || "".equals(actualFirstNo)) {
                throw  new MarkerMetException(0,"计量作业编号为空!!");
            }
            MeterWorkImage mwi = meterWorkImageMapper.selectByPrimaryKey(actualFirstNo);
            if(mwi==null) {
                throw  new MarkerMetException(0,"该计量作业编号不存在图片!!");
            }
            ArrayList<String> urls=new ArrayList<>();
            if (mwi.getImageFile1() != null && !mwi.getImageFile1().equals("")) {
                String no = mwi.getImageFile1();
                urls.add(no);
            }
            if (mwi.getImageFile2() != null && !mwi.getImageFile2().equals("")) {
                String no = mwi.getImageFile2();
                urls.add(no);
            }
            if (mwi.getImageFile3() != null && !mwi.getImageFile3().equals("")) {
                String no = mwi.getImageFile3();
                urls.add(no);
            }
            if (mwi.getImageFile4() != null && !mwi.getImageFile4().equals("")) {
                String no = mwi.getImageFile4();
                urls.add(no);
            }
            if (mwi.getImageFile5() != null && !mwi.getImageFile5().equals("")) {
                String no = mwi.getImageFile5();
                urls.add(no);
            }
            if (mwi.getImageFile6() != null && !mwi.getImageFile6().equals("")) {
                String no = mwi.getImageFile6();
                urls.add(no);
            }
            if (mwi.getImageFile7() != null && !mwi.getImageFile7().equals("")) {
                String no = mwi.getImageFile7();
                urls.add(no);
            }
            if (mwi.getImageFile8() != null && !mwi.getImageFile8().equals("")) {
                String no = mwi.getImageFile8();
                urls.add(no);
            }
            return urls;
        } catch (MarkerMetException e){
             throw  e;
        }

    }

    /**
     * 图片新增操作
     * @param mwi
     * @return
     */
    public RESTfulResult doSaveWf(MeterWorkImage mwi){
        RESTfulResult rm = new RESTfulResult();
        try{
            rm.setCode("200");
            MeterWorkImage mw= meterWorkImageMapper.selectByPrimaryKey(mwi.getActualFirstNo());
            if(mw != null){
                meterWorkImageMapper.updateByPrimaryKeySelective(mwi);
            }else{
                meterWorkImageMapper.insertSelective(mwi);
            }
        }catch(Exception ex){
            rm.setCode("500");
            rm.setMessage("图片信息写入表异常："+ex.getMessage());
        }
        return rm;
    }

}
