自动评价及判断订单表是否已经写入

来源:互联网 发布:手写识别软件 编辑:程序博客网 时间:2024/05/18 03:06


在一般情况下,评价低的需要回访。如果为评价的也要回访(即全部要回访)。下面的dao里的sql语句是非常妙需要判断订单表是否已经写入回访表了

package com.tianjian.property.management.scheduled;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled; 定时器
import org.springframework.stereotype.Component;


import com.tianjian.property.service.ReturningService;


/**
 * 自动把未评价的单添加到回访表里
 */
@Component
public class AutoReturn {

@Autowired
private ReturningService returningService;


@Scheduled(cron = "0 02/38 * * * ?")    //定时器
public void importData() {
returningService.autoReturnIng();
}

}



package com.tianjian.property.service;


import java.beans.IntrospectionException;


import java.lang.reflect.InvocationTargetException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import com.tianjian.property.constant.Constant;
import com.tianjian.property.dao.ReturningDao;
import com.tianjian.property.dao.WorkOrderDao;
import com.tianjian.property.dao.system.EUsersDao;
import com.tianjian.property.entity.Returning;
import com.tianjian.property.entity.WorkOrder;
import com.tianjian.property.entity.common.Pagination;
import com.tianjian.property.entity.system.Admin;
import com.tianjian.property.entity.system.EUsers;
import com.tianjian.property.util.CommonUtil;


@Service
@Transactional
public class ReturningService {


@Autowired
private ReturningDao returningDao;
@Autowired
private EUsersDao eUsersDao;
@Autowired
private WorkOrderDao workOrderDao;

private Log log = LogFactory.getLog(ReturningService.class);

public void addReturning(Returning returning){
try {
this.returningDao.addReturing(returning);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
| IntrospectionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


public Pagination<Returning> getAll(Integer cityId, Integer countyId, Integer propertyId, Integer page,
Integer limit, String workOrderType, String startTime, String endTime) {
Admin admin = CommonUtil.currentAdminDetails();
EUsers euser = eUsersDao.getByEUserId(admin.geteUserId());
if (null == euser)
return null;
return returningDao.getAll(cityId, countyId, propertyId, page, limit, workOrderType, startTime, endTime, euser);
}


/**
* 自动评价
*auth lxl
*/
public void autoReturnIng(){
log.warn("自动评价 定时器启动 ");
List<WorkOrder>  workOrderArray =workOrderDao.getNotComment();
log.warn("未评论数据 " + workOrderArray.size());
Timestamp nowTime = new Timestamp(new Date().getTime()); // 当前时间
for(WorkOrder w:workOrderArray){
log.warn("开始自动 添加回访单 订单号 " + w.getWorkOrderNo());
Long dd = nowTime.getTime() - w.getAddtime().getTime();
int dd2=(int) Math.floor(dd);
int ddValue = dd2/(1000*60*60);//小时
int ddIntValue = ddValue;//计算相差多少小时

String kk3="3";
if(w.getWorkOrderType().toString().equals(kk3)){//投诉实时

log.warn(w.getWorkOrderType()+"---Returning:"+buildReturning(w));
addReturning(buildReturning(w));
}
String kk4="4";String kk5="5";String kk6="6";String kk7="7";
String kk1="1";String kk2="2";int s4=4;
if(w.getStatus().toString().equals(kk4)||w.getStatus().toString().equals(kk5)||w.getStatus().toString().equals(kk6)||w.getStatus().toString().equals(kk7)){
if(ddIntValue>=s4){//居家和公共4小时后未评价进入回访表
if(w.getWorkOrderType().toString().equals(kk1)||w.getWorkOrderType().toString().equals(kk2)){
log.warn(w.getWorkOrderType()+"---Returning:"+buildReturning(w));
addReturning(buildReturning(w));
}}
}
}
log.warn("自动评价 定时器结束 ");
}

private Returning buildReturning(WorkOrder order){
Returning returning=new Returning();
returning.setWorkOrderNo(order.getWorkOrderNo());
returning.setWorkOrderId(order.getId());
returning.setType(order.getWorkOrderType());
returning.setContPhone(order.getPhone());
returning.setStatus(Constant.WAITING_VISIT);
returning.setReasonType(Constant.NOT_COMMENT);
returning.setAddTime(new Timestamp(new Date().getTime()));
returning.setExtension(0);   //延期时间
returning.setAskName(order.getUserName());
returning.setAskId(String.valueOf(order.getUserId()));
return returning;
}

}


//Dao

public List<WorkOrder> getNotComment() {
String sql = "select R.* from t_WorkOrder R "
+ "left join t_Returning t on t.WorkOrderId = R.Id "
+ "where "
+ "t.Id is null "
+ "and (R.IsComment = 0 or R.IsComment is null) "
+ "and R.status = :Status ";


Map<String, Object> paramMap = new HashMap<>();
paramMap.put("Status", 4);

List<WorkOrder> workOrderArray = this.namedJdbcTemplate.query(sql, paramMap , table.getRowMapper());

return workOrderArray;
}

public void addReturing(Returning returning) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException{
Map<String,Object> map=BeanUtils.transBean2Map(returning);
String sql="INSERT INTO t_Returning(Type,WorkOrderId,WorkOrderNo,Status,ContPhone,ReasonType,Extension,AddTime) "
+ " VALUES(:type,:workOrderId,:workOrderNo,:status,:contPhone,:reasonType,:extension,:addTime)";
if (!StringUtils.isEmpty(returning.getType())) {
map.put("type",returning.getType());
}
if (!StringUtils.isEmpty(String.valueOf(returning.getWorkOrderId()))) {
map.put("workOrderId",returning.getWorkOrderId());
}
if (!StringUtils.isEmpty(returning.getWorkOrderNo())) {
map.put("workOrderNo",returning.getWorkOrderNo());
}
if (!StringUtils.isEmpty(returning.getContPhone())) {
map.put("status",returning.getStatus());
}
if (!StringUtils.isEmpty(returning.getContPhone())) {
map.put("contPhone",returning.getContPhone());
}
if (!StringUtils.isEmpty(String.valueOf(returning.getReasonType()))) {
map.put("reasonType",returning.getReasonType());
}
if (!StringUtils.isEmpty(returning.getExtension().toString())) {
map.put("extension",returning.getExtension());
}
if (!StringUtils.isEmpty(returning.getAddTime().toString())) {
map.put("addTime",returning.getAddTime());
}

this.namedJdbcTemplate.update(sql, map);
}


  public static Map<String, Object> transBean2Map(Object obj) {
       if(obj == null){  
           return null;  
       }          
       Map<String, Object> map = new HashMap<>();


          try {
              BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
              PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
              for (PropertyDescriptor property : propertyDescriptors) {
                  String key = property.getName();
                  // 过滤class属性
                  if (!key.equals("class")) {
                      // 得到property对应的getter方法
                      Method getter = property.getReadMethod();
                      Object value = getter.invoke(obj);


                      map.put(key, value);
                  }
              }
          } catch (IntrospectionException | InvocationTargetException | IllegalAccessException e) {
              e.printStackTrace();
          }
          return map;
   }  

0 0
原创粉丝点击