日程保存接口,
主要是对日程的按周按天和自主选择三个模式进行保存日程
多选保存会用~进行隔开
//日程编辑模块业务方法
@Override
public RestMessage getEditSchedule(JSONObject jsonObject) {
RestMessage restMessage = null;
try {
logger.info("日程模块:日程编辑接口请求json:" + jsonObject.toJSONString());
restMessage = new RestMessage();
String errorCode = "0";
String errorMessage = "成功";
boolean success = true;
//解析报文头
RequestHead requestHead = jsonObject.getObject("head" , RequestHead.class);
String loginCode = requestHead.getLoginCode();//登录用户代码
String userCode = requestHead.getUserCode();//子公司用户代码
String comCode = requestHead.getComCode();//机构代码
String comId = requestHead.getComId();//省级机构代码
String comPath = requestHead.getComPath();//机构路径
String toKen = requestHead.getToKen();//通信令牌
String uuid = requestHead.getUuid();//微服务唯一码
String userType = requestHead.getUserType();//用户权限
String teamCode = requestHead.getTeamCode();//团队号
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
Date parse = null;
//解析报文体
try{
ScheduleListBody scheduleListBody = jsonObject.getObject("body" , ScheduleListBody.class);
if(scheduleListBody != null){
List<ScheduleTime> scheduleTimeList = scheduleListBody.getScheduleList();
boolean canSaveflag = getCanSaveflag(scheduleTimeList, userCode);
if(canSaveflag){
for(ScheduleTime scheduleTime : scheduleTimeList){
String storeCode = scheduleTime.getStoreCode();
String storeName = scheduleTime.getStoreName();
int storeNo = scheduleTime.getStoreNo();
String storeAddR = scheduleTime.getStoreAddR();
String scheduleTimeStr = scheduleTime.getScheduleTime();
int editSchedulType = scheduleTime.getEditSchedulType();
String scheduleNo = scheduleTime.getScheduleNo(); //日程序号
String operationType = scheduleTime.getOperationType(); //操作
String scheduledate = scheduleTime.getScheduledate();
String alreadychecknum = scheduleTime.getAlreadyCheckNum();
String shouldchecknum = scheduleTime.getShouldCheckNum();
String storeType = scheduleTime.getStoreType();
String tempString = scheduleTime.getTempString(); //拼接的数据(如果是星期的重复就要多加个这个)
try {
parse = sdf.parse(scheduledate);
}catch (Exception e){
logger.info("日程转换异常");
}
if("0".equals(operationType)){
if(scheduleTimeStr.contains("~")){
String[] split = scheduleTimeStr.split("~");
List<String> strings = Arrays.asList(split);
int i = 0;
for(String str : strings){
if(getweeks().contains(str)){//包含星期
String[] temp0 = tempString.split("~");
CDEditSchedul cdEditSchedul = new CDEditSchedul();
cdEditSchedul.setUsercode(userCode);
cdEditSchedul.setStorecode(storeCode);
cdEditSchedul.setStorename(storeName);
cdEditSchedul.setStoreno(storeNo);
cdEditSchedul.setStoreaddr(storeAddR);
cdEditSchedul.setSchedyleno(scheduleNo);
cdEditSchedul.setEditstchedultype(editSchedulType);
cdEditSchedul.setInserttimeforhis(new Date());
cdEditSchedul.setRemark("");
cdEditSchedul.setFlag("");
cdEditSchedul.setAlreadychecknum(alreadychecknum);
cdEditSchedul.setShouldchecknum(shouldchecknum);
cdEditSchedul.setScheduletime(str);
cdEditSchedul.setScheduledate(sdf.parse(temp0[i]));
cdEditSchedul.setStoretype(storeType);
cdEditSchedulMapper.insert(cdEditSchedul);
i++ ;
}else{
CDEditSchedul cdEditSchedul = new CDEditSchedul();
cdEditSchedul.setUsercode(userCode);
cdEditSchedul.setStorecode(storeCode);
cdEditSchedul.setStorename(storeName);
cdEditSchedul.setStoreno(storeNo);
cdEditSchedul.setStoreaddr(storeAddR);
cdEditSchedul.setSchedyleno(scheduleNo);
cdEditSchedul.setEditstchedultype(editSchedulType);
cdEditSchedul.setInserttimeforhis(new Date());
cdEditSchedul.setRemark("");
cdEditSchedul.setFlag("");
cdEditSchedul.setAlreadychecknum(alreadychecknum);
cdEditSchedul.setShouldchecknum(shouldchecknum);
cdEditSchedul.setScheduletime(str);
cdEditSchedul.setScheduledate(sdf.parse(str));
cdEditSchedul.setStoretype(storeType);
cdEditSchedulMapper.insert(cdEditSchedul);
}
}
}else{
CDEditSchedul cdEditSchedul = new CDEditSchedul();
cdEditSchedul.setUsercode(userCode);
cdEditSchedul.setStorecode(storeCode);
cdEditSchedul.setStorename(storeName);
cdEditSchedul.setStoreno(storeNo);
cdEditSchedul.setStoreaddr(storeAddR);
cdEditSchedul.setScheduletime(scheduleTimeStr);
cdEditSchedul.setSchedyleno(scheduleNo);
cdEditSchedul.setEditstchedultype(editSchedulType);
cdEditSchedul.setInserttimeforhis(new Date());
cdEditSchedul.setRemark("");
cdEditSchedul.setFlag("");
cdEditSchedul.setAlreadychecknum(alreadychecknum);
cdEditSchedul.setShouldchecknum(shouldchecknum);
cdEditSchedul.setScheduledate(parse);
cdEditSchedul.setStoretype(storeType);
cdEditSchedulMapper.insert(cdEditSchedul);
}
}else if("1".equals(operationType)){
CDEditSchedul cdEditSchedul = new CDEditSchedul();
cdEditSchedul.setUsercode(userCode);
cdEditSchedul.setStorecode(storeCode);
cdEditSchedul.setScheduletime(scheduleTimeStr);
cdEditSchedul.setSchedyleno(scheduleNo);
cdEditSchedulMapper.delete(cdEditSchedul);
}
}
}else{
errorCode = "1";
errorMessage = "您选择的日期已经存在3个日程,请重新编辑";
success = false;
}
}
}catch (Exception e){
errorCode = "1";
errorMessage = "日程编辑失败";
success = false;
}
ResponseHead responseHead = new ResponseHead();
responseHead.setLoginCode(loginCode);
responseHead.setUserCode(userCode);
responseHead.setComCode(comCode);
responseHead.setComId(comId);
responseHead.setComPath(comPath);
responseHead.setToKen(toKen);
responseHead.setUuid(uuid);
responseHead.setErrorCode(errorCode);
responseHead.setErrorMessage(errorMessage);
responseHead.setUserType(userType);
responseHead.setTeamCode(teamCode);
Map<String, Object> map = new HashMap<>();
map.put("head" , responseHead);
String json =JSON.toJSONString(map , SerializerFeature.DisableCircularReferenceDetect);
restMessage.setData(AESUtilTools.encrypt(json));
restMessage.setErrCode(Integer.parseInt(errorCode));
restMessage.setMessage(errorMessage);
restMessage.setSuccess(success);
logger.info("日程模块:日程编辑接口返回json:" + JSON.toJSONString(map));
} catch (Exception e) {
logger.error(e.toString());
}
return restMessage;
}