import java.sql.Timestamp;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import cn.itcast.bos.dao.IDecidedzoneDao;
import cn.itcast.bos.dao.INoticebillDao;
import cn.itcast.bos.dao.IWorkbillDao;
import cn.itcast.bos.domain.Decidedzone;
import cn.itcast.bos.domain.Noticebill;
import cn.itcast.bos.domain.Staff;
import cn.itcast.bos.domain.Workbill;
import cn.itcast.bos.service.INoticebillService;
import cn.itcast.bos.utils.BOSContext;
import cn.itcast.crm.CustomerService;
@Service
@Transactional
public class NoticebillServiceImpl implements INoticebillService{
@Autowired
private INoticebillDao noticebillDao;
@Autowired
private IDecidedzoneDao decidedzoneDao;
@Autowired
private IWorkbillDao workbillDao;
//注入hessian代理对象
@Autowired
private CustomerService customerService;
/**
* 保存业务通知单,并尝试自动分单
*/
public void save(Noticebill model) {
model.setUser(BOSContext.getLoginUser());
noticebillDao.save(model);//持久
String pickaddress = model.getPickaddress();//客户的取件地址
//远程调用crm服务,根据取件地址查询客户关联的定区id
String decidedzoneId = customerService.findDecidedzoneidByAddress(pickaddress);
if(decidedzoneId != null){
//查询到定区id,可以完成自动分单
model.setOrdertype("自动");
Decidedzone decidedzone = decidedzoneDao.findById(decidedzoneId);
Staff staff = decidedzone.getStaff();
model.setStaff(staff);//建立业务通知单和取派员的关系
//为取派员创建一个工单
Workbill workbill = new Workbill();
workbill.setAttachbilltimes(0);//追单次数
workbill.setBuildtime(new Timestamp(System.currentTimeMillis()));//创建工单时间---系统时间
workbill.setNoticebill(model);//工单关联业务通知单
workbill.setPickstate("未取件");//取件状态
workbill.setRemark(model.getRemark());//备注
workbill.setStaff(staff);//工单关联取派员
workbill.setType("新");//工单类型
//保存工单
workbillDao.save(workbill);
//通过webservice调用短信平台给取派员发短信
}else{
//没有查询到定区id,需要转入人工分单
model.setOrdertype("人工");
}
}
}