package com.ytpm.lemonios.service.impl;

import com.ytpm.agent.model.YtApp;
import com.ytpm.agent.model.YtDitch;
import com.ytpm.agent.param.DitchListParam;
import com.ytpm.agent.view.AgentDitchView;
import com.ytpm.lemonios.dao.DitchMapper;
import com.ytpm.lemonios.service.DitchService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class DitchServiceImpl implements DitchService {

    @Resource
    private DitchMapper agentDitchMapper;


    @Override
    public List<AgentDitchView> ditchList(DitchListParam param) {
        return agentDitchMapper.ditchListByAppId(param.getAppId());
    }

    @Override
    public Integer save(YtApp app) {
        YtDitch ytDitch = new YtDitch();
        ytDitch.setDitchId(app.getDitchId());
        ytDitch.setDitchName(app.getDitchName());
        ytDitch.setUserId(app.getUserId());
        ytDitch.setAppId(app.getAppId());
        ytDitch.setAppType(app.getAppType().toString());
        ytDitch.setIsDelete(0);
        ytDitch.setCreateTime(new Date());
        return agentDitchMapper.insertOne(ytDitch);
    }

    @Override
    public void deleteByAppId(String appId) {
        // 逻辑删除
        agentDitchMapper.deleteByAppId(appId);
    }
}
