public void saveCompanyFollow(Supplies as_supplies, String as_followIds,Company as_company) throws Exception {
if (as_followIds.equals("")|| as_followIds==null) {
throw new Exception("跟進人不能為空:"+this.getClass().getName()+":save()");
}else{
//刪除之前所有跟進人
List<CompanyFollow> companyFollowList = this.getCompanyFollow(as_supplies);
for (CompanyFollow companyFollow : companyFollowList) {
this.delete(companyFollow);
}
//重新添加
String followIdsArray[] = as_followIds.split(",");
for (String string : followIdsArray) {
CompanyFollow cf = new CompanyFollow();
User u = userServiceImpl.get(string);
cf.setCompanyId(as_supplies.getId());
cf.setFollowId(string);
Set<Department> depSet = u.getDepartment();
if (depSet.size()>1) {
for (Department department : depSet) {
if(as_company.getDepartments().contains(department)){
cf.setGroupId(department.getId());
}
}
}else{
for (Department department : depSet) {
cf.setGroupId(department.getId());
}
}
this.save(cf);
this.flush(); //加上這個就可以了
}
}
}
for循環運行完後查看表,記錄只有一條,加上 this.flush(); //加上這個就可以了