package com.engine.htsc.coworkreport.service.impl;

import com.engine.core.impl.Service;
import com.engine.htsc.coworkreport.service.TaskListService;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;
import java.util.*;

public class TaskListServiceImpl extends Service implements TaskListService {

    @Override
    public Map<String, Object> delteTask(Map<String, Object> params, User user) {

        int flag = 0;
        String billid = Util.null2String(params.get("billid"));
        RecordSet rs = new RecordSet();
        if(!"".equals(billid)){
            String sql = "delete from uf_rw where id="+billid;
            boolean bool = rs.executeUpdate(sql);
            if(bool){
                flag = 1;
            }else{
                flag = -1;
            }
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("data",flag+"");
        return map;
    }

    @Override
    public Map<String, Object> delteCowork(Map<String, Object> params, User user) {
        int flag = 0;
        String billid = Util.null2String(params.get("billid"));
        RecordSet rs = new RecordSet();
        if(!"".equals(billid)){
            String sql = "delete from uf_xzsy where id="+billid;
            boolean bool = rs.executeUpdate(sql);
            if(bool){
                flag = 1;
            }else{
                flag = -1;
            }
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("data",flag+"");
        return map;
    }


    @Override
    public Map<String, Object> deleteCowork4Task(Map<String, Object> params, User user) {
        int flag = 0;
        String billid = Util.null2String(params.get("billid"));
        RecordSet rs = new RecordSet();
        if(!"".equals(billid))
        {
            int count = 0;
            String sql = " select id from uf_rw where xzsy = "+billid +" and cjzt = 1";
            rs.execute(sql);
            if(rs.next()){
                count++;
            }
            if(count > 0){
                flag = -2;
            }else{
                sql = "delete from uf_xzsy where id="+billid;
                boolean bool = rs.executeUpdate(sql);
                if(bool){
                    flag = 1;
                }else{
                    flag = -1;
                }
            }
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("data",flag+"");
        return map;
    }
}
