package com.jeeww.web.demo.service.test.impl;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.hibernate.Criteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.jeeww.core.dao.QueryDAO;
import com.jeeww.core.syspojo.AgtbMenuInfo;
import com.jeeww.core.syspojo.AgtbUserInfo;
import com.jeeww.web.demo.dto.ActivitiTestDTO;
import com.jeeww.web.demo.dto.TestDTO;
import com.jeeww.web.demo.service.test.TestService;
import com.alibaba.fastjson.JSONObject;

/**
 * 类描述：接口.
 * @author 蒋文武
 */
@Service("TestServiceImpl")
public class TestServiceImpl implements TestService {
    /**
     * logger.
     */
    private Logger logger = Logger.getLogger(TestServiceImpl.class);
    /**
     * queryDAO.
     */
    @Autowired
    private QueryDAO queryDAO;
    /**
     * activitiCoreService.
     */
//    @Autowired
//    private ActivitiCoreService activitiCoreService;

    // extends baseService 实现复杂查询，sql,hql操作等
    // 针对每个表的增删改，简单查询操作只用自己对应的dao，清晰便于维护。
    // 基础dao自动生成，考虑联合主键情况
    @Override
    public String insertA() throws Exception {
        for (int i = 1; i < 2; i++) {
            AgtbMenuInfo newEntity = new AgtbMenuInfo();
            newEntity.setMenuId("21112");
            newEntity.setMenuName("xfaaax");
            // agtbMenuInfoDAO.save(newEntity);
        }
        // agtbMenuInfoDAO.deleteByKey("1111");
        // AgtbMenuInfo test1 = agtbMenuInfoDAO.get("2112");
        // test1.setMenuName("ddfffad");
        // agtbMenuInfoDAO.update(test1);
        AgtbUserInfo serachModel = new AgtbUserInfo();
        // serachModel.setUserId("");
        Criteria criteria = queryDAO.createCriteria(AgtbUserInfo.class);
        List<?> list1 = criteria.list();
        List<TestDTO> list3 = queryDAO.queryBySQLNamedQuery("dynamicQueryTest3", serachModel, TestDTO.class);
        List<Map<String, Object>> list4 = queryDAO.queryBySQLNamedQuery("dynamicQueryTest3", serachModel);
        List<?> list5 = queryDAO.queryByHQLNamedQuery("dynamicQueryTest2", serachModel);
        List<?> list6 = queryDAO.queryByHQLNamedQuery("dynamicQueryTest4", serachModel);
        // logger.debug(test1.getMenuName());
        logger.debug(list1.size());
        logger.debug(list3.size());
        logger.debug(list4.size());
        logger.debug(list5.size());
        logger.debug(list6.size());
        return "xx";
    }

    @Override
    public String vacationApply(final Map<String, Object> variables) throws Exception {
//        return activitiCoreService.startProcess("vacationRequest", variables);
        return null;
    }

    @Override
    public String vacationApprove(final ActivitiTestDTO activitiTestDTO) throws Exception {
        // 启动一个流程
//        Map<String, Object> variables = new HashMap<String, Object>();
//        variables.put("vacationApproved", activitiTestDTO.getVacationApproved());
//        variables.put("managerMotivation", activitiTestDTO.getManagerMotivation());
//        activitiCoreService.completeTask(activitiTestDTO.getTaskId(), variables);
        return "1";
    }

    @Override
    public String loadFormData() throws Exception {
        JSONObject formData = new JSONObject();
        formData.put("name1", "小图标式录");
        formData.put("name2", "邮箱测试值@neu.com.cn");
        formData.put("name3", "90018");
        formData.put("name4", "文本录入框");
        formData.put("name5", "90017,90018");
        formData.put("name6", "99");
        formData.put("name7", "99.99");
        formData.put("name8", "99669977");
        formData.put("name9", "10:21");
        formData.put("name10", "2012-10-10");
        formData.put("name11", "11,12");
        formData.put("name12", "2");
        formData.put("name13", "2012-12-12 09:20");
        formData.put("name14", "12");
        formData.put("name15", "2,3");
        formData.put("name16", "12");
        formData.put("name17", "23");
        formData.put("name18", "34");
        formData.put("name19", "备注备注备注备注备注备注备注");
        formData.put("namea1", "1");
        formData.put("namea2", "1,2,3");
        formData.put("namea3", "1,2,3,4,5");
        formData.put("name_cgrid1", "2,3");
        formData.put("name_cgrid2", "3");
        formData.put("name_cgrid3", "3");
        return formData.toJSONString();
    }
}
