|
|
@@ -6,6 +6,7 @@ import com.github.pagehelper.PageInfo;
|
|
|
import com.usoftchina.saas.base.service.CommonBaseServiceImpl;
|
|
|
import com.usoftchina.saas.common.dto.BatchDealBaseDTO;
|
|
|
import com.usoftchina.saas.common.dto.DocBaseDTO;
|
|
|
+import com.usoftchina.saas.common.dto.DocSavedDTO;
|
|
|
import com.usoftchina.saas.document.api.ProductApi;
|
|
|
import com.usoftchina.saas.exception.BizException;
|
|
|
import com.usoftchina.saas.page.PageRequest;
|
|
|
@@ -17,9 +18,9 @@ import com.usoftchina.saas.purchase.po.*;
|
|
|
import com.usoftchina.saas.purchase.service.PurchaseService;
|
|
|
import com.usoftchina.saas.utils.BeanMapper;
|
|
|
|
|
|
-import com.usoftchina.saas.utils.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
@@ -43,7 +44,7 @@ public class PurchaseServiceImpl extends CommonBaseServiceImpl<PurchaseMapper, P
|
|
|
private ProductApi productApi;
|
|
|
|
|
|
@Override
|
|
|
- public PageInfo<PurchaseListDTO> getListData(PageRequest page, PurchaseReqDTO req) {
|
|
|
+ public PageInfo<PurchaseList> getListData(PageRequest page, PurchaseReqDTO req) {
|
|
|
//设置默认分页
|
|
|
if (null == page || page.getSize() == 0 || page.getNumber() == 0) {
|
|
|
page = new PageRequest();
|
|
|
@@ -53,14 +54,8 @@ public class PurchaseServiceImpl extends CommonBaseServiceImpl<PurchaseMapper, P
|
|
|
PageHelper.startPage(page.getNumber(), page.getSize());
|
|
|
//查询数据
|
|
|
List<PurchaseList> lists = getListByMode(req);
|
|
|
- //转换成传输对象
|
|
|
- List<PurchaseListDTO> purchaseListDTOS = new ArrayList<>();
|
|
|
- for (PurchaseList list : lists) {
|
|
|
- purchaseListDTOS.add(BeanMapper.map(list, PurchaseListDTO.class));
|
|
|
- }
|
|
|
//取分页信息
|
|
|
- PageInfo<PurchaseListDTO> pageInfo = new PageInfo<PurchaseListDTO>(purchaseListDTOS);
|
|
|
- pageInfo.getTotal();
|
|
|
+ PageInfo<PurchaseList> pageInfo = new PageInfo<PurchaseList>(lists);
|
|
|
return pageInfo;
|
|
|
}
|
|
|
|
|
|
@@ -84,24 +79,31 @@ public class PurchaseServiceImpl extends CommonBaseServiceImpl<PurchaseMapper, P
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Long saveFormData(PurchaseFormDTO formdata) {
|
|
|
+ public DocSavedDTO saveFormData(PurchaseFormDTO formdata) {
|
|
|
if (null == formdata || null == formdata.getMain()){
|
|
|
throw new BizException(500, "数据为空,请填写后再保存");
|
|
|
}
|
|
|
+
|
|
|
//获取主表信息
|
|
|
PurchaseDTO main = formdata.getMain();
|
|
|
List<PurchaseItemDTO> items = formdata.getItems();
|
|
|
+ //插入从表数据
|
|
|
List<PurchaseItem> insertDetails = new ArrayList<>();
|
|
|
+ //更新从表数据
|
|
|
List<PurchaseItem> updateDetails = new ArrayList<>();
|
|
|
+ DocSavedDTO saveDTO = new DocSavedDTO();
|
|
|
Long pu_id = main.getId();
|
|
|
String pu_code = main.getPu_code();
|
|
|
Purchase purchase = BeanMapper.map(main, Purchase.class);
|
|
|
+
|
|
|
//编号获取
|
|
|
- if (!StringUtils.hasText(pu_code)) {
|
|
|
+ if (StringUtils.isEmpty(pu_code)) {
|
|
|
pu_code = "PU" + Math.random() * 1000;
|
|
|
+ purchase.setPu_code(pu_code);
|
|
|
}
|
|
|
+ saveDTO.setCode(pu_code);
|
|
|
//判断更新与保存动作
|
|
|
- if (StringUtils.hasText(pu_id)) {
|
|
|
+ if (!StringUtils.isEmpty(pu_id)) {
|
|
|
//更新主表
|
|
|
purchaseMapper.updateByPrimaryKey(purchase);
|
|
|
//添加从表传输对象
|
|
|
@@ -109,7 +111,7 @@ public class PurchaseServiceImpl extends CommonBaseServiceImpl<PurchaseMapper, P
|
|
|
PurchaseItem detail = BeanMapper.map(item, PurchaseItem.class);
|
|
|
detail.setPd_puid(pu_id);
|
|
|
detail.setPd_code(pu_code);
|
|
|
- if (StringUtils.hasText(detail.getId())) {
|
|
|
+ if (!StringUtils.isEmpty(detail.getId())) {
|
|
|
updateDetails.add(detail);
|
|
|
} else {
|
|
|
insertDetails.add(detail);
|
|
|
@@ -123,8 +125,10 @@ public class PurchaseServiceImpl extends CommonBaseServiceImpl<PurchaseMapper, P
|
|
|
if (updateDetails.size() > 0) {
|
|
|
purchasedetailMapper.batchUpdate(updateDetails);
|
|
|
}
|
|
|
- return pu_id;
|
|
|
+ saveDTO.setId(pu_id);
|
|
|
+ return saveDTO;
|
|
|
}
|
|
|
+
|
|
|
//插入操作
|
|
|
purchaseMapper.insertSelective(purchase);
|
|
|
pu_id = purchase.getId();
|
|
|
@@ -139,7 +143,8 @@ public class PurchaseServiceImpl extends CommonBaseServiceImpl<PurchaseMapper, P
|
|
|
if (insertDetails.size() > 0) {
|
|
|
purchasedetailMapper.batchInsert(insertDetails);
|
|
|
}
|
|
|
- return pu_id;
|
|
|
+ saveDTO.setId(pu_id);
|
|
|
+ return saveDTO;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -157,8 +162,9 @@ public class PurchaseServiceImpl extends CommonBaseServiceImpl<PurchaseMapper, P
|
|
|
Long id = null;
|
|
|
if (null != formData) {
|
|
|
id = formData.getMain().getId();
|
|
|
- if (!StringUtils.hasText(id)) {
|
|
|
- id = saveFormData(formData);
|
|
|
+ if (StringUtils.isEmpty(id)) {
|
|
|
+ DocSavedDTO saveDTO = saveFormData(formData);
|
|
|
+ id = saveDTO.getId();
|
|
|
}
|
|
|
singleAudit(id);
|
|
|
}
|
|
|
@@ -171,7 +177,7 @@ public class PurchaseServiceImpl extends CommonBaseServiceImpl<PurchaseMapper, P
|
|
|
baseDTOs.getBaseDTOs().size() == 0)
|
|
|
return;
|
|
|
String validate = purchaseMapper.validateAudit(baseDTOs.getBaseDTOs());
|
|
|
- if (StringUtils.hasText(validate)) {
|
|
|
+ if (!StringUtils.isEmpty(validate)) {
|
|
|
throw new BizException(500, "存在已审核单据,单据编号:" + validate);
|
|
|
}
|
|
|
for (DocBaseDTO base : baseDTOs.getBaseDTOs()) {
|
|
|
@@ -213,7 +219,7 @@ public class PurchaseServiceImpl extends CommonBaseServiceImpl<PurchaseMapper, P
|
|
|
|
|
|
private List<PurchaseList> getListByMode(PurchaseReqDTO req) {
|
|
|
List<PurchaseList> list = null;
|
|
|
- if (null == req || !StringUtils.hasText(req.getMode()) || "Main".equals(req.getMode())) {
|
|
|
+ if (null == req || StringUtils.isEmpty(req.getMode()) || "Main".equals(req.getMode())) {
|
|
|
list = purchaseListMapper.selectPurchaseBycondition(req);
|
|
|
} else {
|
|
|
list = purchaseListMapper.selectPurchaseListByCondition(req);
|