|
|
@@ -17,6 +17,7 @@ import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
@@ -34,8 +35,10 @@ import com.uas.platform.b2b.model.PurchaseApCheckEnd;
|
|
|
import com.uas.platform.b2b.model.PurchaseApCheckItem;
|
|
|
import com.uas.platform.b2b.model.PurchaseApCheckTodo;
|
|
|
import com.uas.platform.b2b.model.SearchFilter;
|
|
|
+import com.uas.platform.b2b.model.SourceForApcheck;
|
|
|
import com.uas.platform.b2b.service.PurchaseApCheckService;
|
|
|
import com.uas.platform.b2b.support.SystemSession;
|
|
|
+import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
import com.uas.platform.core.model.PageInfo;
|
|
|
import com.uas.platform.core.model.Status;
|
|
|
import com.uas.platform.core.persistence.criteria.PredicateUtils;
|
|
|
@@ -221,6 +224,7 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
|
|
|
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public PurchaseApCheck save(PurchaseApCheck purchaseApCheck) {
|
|
|
purchaseApCheck.setRecordDate(new Date());
|
|
|
Date d = new Date();
|
|
|
@@ -230,18 +234,60 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
|
|
|
purchaseApCheck.setRecorder(SystemSession.getUser().getUserName());
|
|
|
Short number = 0;
|
|
|
List<PurchaseApCheckItem> items = new ArrayList<PurchaseApCheckItem>();
|
|
|
+ //保存成功的同时来源单据更新一下
|
|
|
+ List<SourceForApcheck> sources = new ArrayList<>();
|
|
|
for (PurchaseApCheckItem item : purchaseApCheck.getItems()) {
|
|
|
+ SourceForApcheck source = new SourceForApcheck(item);
|
|
|
+ sources.add(source);
|
|
|
item.setNumber(++number);
|
|
|
item.setApCheck(purchaseApCheck);
|
|
|
items.add(item);
|
|
|
}
|
|
|
+ updateSourceInfo(sources);
|
|
|
items = purchaseApCheckItemDao.save(items);
|
|
|
- if( ! CollectionUtils.isEmpty(items)) {
|
|
|
+ if (!CollectionUtils.isEmpty(items)) {
|
|
|
ContextUtils.publishEvent(new PurchaseApCheckSaveEvent(PurchaseApCheckItem.distinct(items)));
|
|
|
}
|
|
|
// TODO 把items转成主记录的形式
|
|
|
return purchaseApCheck;
|
|
|
}
|
|
|
+
|
|
|
+ public boolean updateSourceInfo(List<SourceForApcheck> list) {
|
|
|
+ if(!CollectionUtils.isEmpty(list)) {
|
|
|
+ for(SourceForApcheck source : list) {
|
|
|
+ if(source.hasInfo()) {
|
|
|
+ String idName = null;
|
|
|
+ String yCheckQtyName = null;
|
|
|
+ if (source.getSourceTable().equals("purc$returnitem")) {
|
|
|
+ idName = "pai_id";
|
|
|
+ yCheckQtyName = "pri_ycheckqty";
|
|
|
+ } else if (source.getSourceTable().equals("purc$acceptitem")) {
|
|
|
+ idName = "pai_id";
|
|
|
+ yCheckQtyName = "pai_ycheckqty";
|
|
|
+ } else if (source.getSourceTable().equals("purc$badinitem")) {
|
|
|
+ idName = "pbi_id";
|
|
|
+ yCheckQtyName = "pbi_ycheckqty";
|
|
|
+ } else if (source.getSourceTable().equals( "purc$badoutitem")) {
|
|
|
+ idName = "poi_id";
|
|
|
+ yCheckQtyName = "poi_ycheckqty";
|
|
|
+ } else if (source.getSourceTable().equals( "make$acceptitem")) {
|
|
|
+ idName = "mai_id";
|
|
|
+ yCheckQtyName = "mai_ycheckqty";
|
|
|
+ } else if (source.getSourceTable().equals( "make$returnitem")) {
|
|
|
+ idName = "mri_id";
|
|
|
+ yCheckQtyName = "mri_ycheckqty";
|
|
|
+ }
|
|
|
+ String sql = "update " + source.getSourceTable() + " set " + yCheckQtyName + " = " + source.getNewYCheckQty() + " where "
|
|
|
+ + idName + " = " + source.getSourceId();
|
|
|
+ jdbcTemplate.execute(sql);
|
|
|
+ } else {
|
|
|
+ throw new IllegalOperatorException("保存失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ throw new IllegalOperatorException("保存失败!");
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public Page<PurchaseApCheck> findAllByPageInfo(final PageInfo pageInfo, final String keyword, SearchFilter searchFilter) {
|