package com.bealead.server.mvc.dao.impl;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.bealead.server.mvc.dao.Inner_WeixinDao;
import com.bealead.server.mvc.dataobject.BusinessInfoList;
import com.bealead.server.mvc.dataobject.DailyRecordInfoList;
import com.bealead.server.mvc.dataobject.ErrorInfoList;
import com.bealead.server.mvc.dataobject.GetKQDateList;
import com.bealead.server.mvc.dataobject.HolidayInfoList;
import com.bealead.server.mvc.dataobject.HolidayTypeList;
import com.bealead.server.mvc.dataobject.KQ_GetKQBusinessInfoList;
import com.bealead.server.mvc.dataobject.KqdTempList;
import com.bealead.server.mvc.dataobject.KqhTempList;
import com.bealead.server.mvc.dataobject.ManagerInfoList;
import com.bealead.server.mvc.dataobject.NameList;
import com.bealead.server.mvc.dataobject.OpenIdList;
import com.bealead.server.mvc.dataobject.ParentBusinessInfoList;
import com.bealead.server.mvc.dataobject.ParentBusinessSumList;
import com.bealead.server.mvc.dataobject.PersonnelInfo;
import com.bealead.server.mvc.dataobject.PidList;
import com.bealead.server.mvc.dataobject.RzInfoList;
import com.bealead.server.mvc.dataobject.StepInfoList_1List;
import com.bealead.server.mvc.dataobject.StructureBusinessInfoList;
import com.bealead.server.mvc.dataobject.StructureList;
import com.bealead.server.mvc.funref.ref_GetHolidayList;
import com.bealead.server.mvc.funref.ref_GetStepInfoListList;
import com.bealead.server.mvc.funref.ref_KQ_SaveDailyRecord;
import com.bealead.server.mvc.funref.ref_Save_KQHD_Business;
import com.bealead.server.mvc.funref.ref_StructureBusinessInfoList;
import com.bealead.server.mvc.utils.Tools;
@SuppressWarnings("unchecked")
@Repository
public class Inner_WeixinDaoImpl implements Inner_WeixinDao {
@Autowired
private SqlSessionTemplate sqlSessionTemplate;
/**
* 根据openid获取pid
*/
@Override
public int Get_PId_ByOpenId(String OpenId) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put("OpenId", OpenId);
List<PidList> list = (List<PidList>) sqlSessionTemplate.selectList(
Inner_WeixinDao.SYSTEMFRAME_NAME_SPACE
+ ".Get_KQ_GetPersonnelId", map);
int pid = -1;
if (list.size() != 0) {
pid = list.get(0).getPersonnelId();
}
return pid;
}
/**
* ͨ获取人员信息,模糊查询
*/
@Override
public List<PersonnelInfo> Search_User(String keytxt) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put("KeyText", keytxt);
List<PersonnelInfo> list = (List<PersonnelInfo>) sqlSessionTemplate
.selectList(Inner_WeixinDao.SYSTEMFRAME_NAME_SPACE
+ ".search_User", map);
return list;
}
/**
* 删除步骤表
*
* @param OpenId
*/
@Override
public void KQ_DeleteStep(String OpenId) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("OpenId", OpenId);
// sqlSessionTemplate.delete(Inner_WeixinDao.SYSTEMFRAME_NAME_SPACE
// + ".KQ_DeleteStep", map);
sqlSessionTemplate.selectList(Inner_WeixinDao.SYSTEMFRAME_NAME_SPACE
+ ".KQ_DeleteStep", map);
}
/**
* 删除kqd或者kqh对应临时表
*
* @param DataType.1是kqd,,2是kqh
* @param OpenId
*/
@Override
public void KQ_DeleteKQ(int DataType, String OpenId) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("DataType", DataType);
map.put("OpenId", OpenId);
sqlSessionTemplate.delete(Inner_WeixinDao.SYSTEMFRAME_NAME_SPACE
+ ".KQ_DeleteKQ", map);
}
/**
* 定时删除用...清空kqd临时表,kqh临时表,和step表,对应DataType分别是1,2,3
*
* @param CurrentDate当前日期
* @param DataType操作类型
*/
@Override
public void KQ_ClearKQInstruc(String CurrentDate, int DataType) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("CurrentDate", CurrentDate);
map.put("DataType", DataType);
sqlSessionTemplate.delete(Inner_WeixinDao.SYSTEMFRAME_NAME_SPACE
+ ".KQ_ClearKQInstruc", map);
}
/**
* 用户信息绑定,把bind数据写入bind业务表...获取SQL返回ID
*
* @param OpenId
* @param IDCardNo
* @return
*/
@Override
public int KQ_SavePersonelRelation(String OpenId, String IDCardNo) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("OpenId", OpenId);
map.put("IDCard", IDCardNo);
map.put("ErrorId", 0);
sqlSessionTemplate.selectList(Inner_WeixinDao.SYSTEMFRAME_NAME_SPACE
+ ".KQ_SavePersonelRelation", map);
return Integer.parseInt(map.get("ErrorId").toString());// 返回SQL处理的结果
}
/**
* 初始化或者更新步骤表
*
* @param OpenId
* @param CmdNo
* @param EndStep
* @param EndTime
* @param tmpstr
* @throws ParseException
*/
@Override
public void KQ_SaveStep(String OpenId, String CmdNo, int EndStep,
Date EndTime, String tmpstr) throws ParseException {
Map<String, Object> map = new HashMap<String, Object>();
map.put("StepId", 0);
map.put("OpenId", OpenId);
map.put("CmdNo", CmdNo);
map.put("EndStep", EndStep);
map.put("EndTime", EndTime);
map.put("Xmlstr", tmpstr);
sqlSessionTemplate.selectList(Inner_WeixinDao.SYSTEMFRAME_NAME_SPACE
+ ".KQ_SaveStep", map);
}
/**
* 根据pid获取上级pid,如果取不到则返回-1
*
* @param MyPId
* @return
*/
@Override
public int Get_HighPId(int MyPId) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("PersonnelId", MyPId);
map.put("ParentId", 0);
sqlSessionTemplate.selectList(Inner_WeixinDao.SYSTEMFRAME_NAME_SPACE
+ ".KQ_GetParentId", map);
return Integer.parseInt(map.get("ParentId").toString());
}
/**
* 根据PId获取OpenId
*
* @param MyPId
* @return
*/
@Override
public String Get_OpenId_ByPId(int MyPId) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("PersonnelId", MyPId);
map.put("DataType", 2);
List<OpenIdList> list = (List<OpenIdList>) sqlSessionTemplate
.selectList(Inner_WeixinDao.SYSTEMFRAME_NAME_SPACE
+ ".KQ_PidTOOpenId", map);
if (list.size() == 0) {
return "";
}
return list.get(0).getOpenId();
}
/**
* 根据PId获取姓名
*
* @param MyPId
* @return
*/
@Override
public String PID_to_Name(int MyPId) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("PersonnelId", MyPId);
map.put("DataType", 1);
List<NameList> list = (List<NameList>) sqlSessionTemplate.selectList(
Inner_WeixinDao.SYSTEMFRAME_NAME_SPACE + ".KQ_PidToName", map);
if (list.size() == 0) {
return "";
}
return list.get(0).getPersonnelName();
}
/**
* 保存日志信息到数据库
*
* @param DataType..1=微信录入,2=网页录入
* @param RecordDate
* @param Content
* @param PersonnelId
* @param State
* @return
*/
@Override
public ref_KQ_SaveDailyRecord KQ_SaveDailyRecord(int DataType,
int RecordDate, String Content, int PersonnelId, int State) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("DataType", DataType);
map.put("RecordDate", RecordDate);
map.put("Content", Content);
map.put("PersonnelId", PersonnelId);
map.put("State", State);
map.put("return_value", 0);// 返回值
List<RzInfoList> list = (List<RzInfoList>) sqlSessionTemplate
.selectList(Inner_WeixinDao.SYSTEMFRAME_NAME_SPACE
+ ".KQ_SaveDailyRecord", map);
ref_KQ_SaveDailyRecord ref = new ref_KQ_SaveDailyRecord();
ref.setList(list);
ref.setReturn_value(Integer
.parseInt(map.get("return_value").toString()));
return ref;
}
/*