|
|
@@ -3,13 +3,20 @@ package com.usoftchina.saas.document.service.impl;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.usoftchina.saas.base.service.CommonBaseServiceImpl;
|
|
|
+import com.usoftchina.saas.commons.api.MessageLogService;
|
|
|
import com.usoftchina.saas.commons.dto.ComboDTO;
|
|
|
-import com.usoftchina.saas.commons.dto.DocReqDTO;
|
|
|
+import com.usoftchina.saas.commons.dto.DocBaseDTO;
|
|
|
+import com.usoftchina.saas.commons.dto.ListReqDTO;
|
|
|
+import com.usoftchina.saas.commons.exception.BizExceptionCode;
|
|
|
+import com.usoftchina.saas.commons.po.Status;
|
|
|
+import com.usoftchina.saas.context.BaseContextHolder;
|
|
|
import com.usoftchina.saas.document.dto.ProductDTO;
|
|
|
import com.usoftchina.saas.document.entities.Product;
|
|
|
import com.usoftchina.saas.document.mapper.ProductMapper;
|
|
|
import com.usoftchina.saas.document.service.ProductService;
|
|
|
+import com.usoftchina.saas.exception.BizException;
|
|
|
import com.usoftchina.saas.page.PageRequest;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
|
@@ -17,8 +24,11 @@ import java.util.List;
|
|
|
@Service
|
|
|
public class ProductServiceImpl extends CommonBaseServiceImpl<ProductMapper, Product> implements ProductService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private MessageLogService messageLogService;
|
|
|
+
|
|
|
@Override
|
|
|
- public PageInfo<ProductDTO> getProductsByCondition(PageRequest page, DocReqDTO docReqDTO) {
|
|
|
+ public PageInfo<ProductDTO> getProductsByCondition(PageRequest page, ListReqDTO listReqDTO) {
|
|
|
//设置分页
|
|
|
if (null == page || page.getSize() == 0 || page.getNumber() == 0) {
|
|
|
page = new PageRequest();
|
|
|
@@ -26,7 +36,7 @@ public class ProductServiceImpl extends CommonBaseServiceImpl<ProductMapper, Pro
|
|
|
page.setSize(10);
|
|
|
}
|
|
|
PageHelper.startPage(page.getNumber(), page.getSize());
|
|
|
- List<ProductDTO> productList = getMapper().getProductsByCondition(docReqDTO);
|
|
|
+ List<ProductDTO> productList = getList(listReqDTO);
|
|
|
//取分页信息
|
|
|
PageInfo<ProductDTO> pageInfo = new PageInfo<ProductDTO>(productList);
|
|
|
return pageInfo;
|
|
|
@@ -40,13 +50,90 @@ public class ProductServiceImpl extends CommonBaseServiceImpl<ProductMapper, Pro
|
|
|
@Override
|
|
|
public void updateLatestPurchasePrice(Long pu_id) {
|
|
|
getMapper().updateLatestPurchasePrice(pu_id);
|
|
|
+ messageLogService.update(generateMsgObj(pu_id));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Product getProductsByPK(Long id) {
|
|
|
- if (null == id) {
|
|
|
+ if (null != id) {
|
|
|
return getMapper().selectByPrimaryKey(id);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public DocBaseDTO saveData(Product product){
|
|
|
+ DocBaseDTO docBaseDTO = null;
|
|
|
+ if(product.getId() == 0){
|
|
|
+ product.setCompanyId(BaseContextHolder.getCompanyId());
|
|
|
+ getMapper().insertSelective(product);
|
|
|
+ docBaseDTO = generateMsgObj(product.getId());
|
|
|
+ //记录LOG
|
|
|
+ messageLogService.save(docBaseDTO);
|
|
|
+ }else{
|
|
|
+ getMapper().updateByPrimaryKeySelective(product);
|
|
|
+ docBaseDTO = generateMsgObj(product.getId());
|
|
|
+ //记录LOG
|
|
|
+ messageLogService.update(docBaseDTO);
|
|
|
+ }
|
|
|
+ return docBaseDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean close(Long id) {
|
|
|
+ if(id != null && id > 0){
|
|
|
+ Product product = new Product();
|
|
|
+ product.setId(id);
|
|
|
+ product.setPr_status(Status.CLOSE.getDisplay());
|
|
|
+ product.setPr_statuscode(Status.CLOSE.name());
|
|
|
+ getMapper().updateByPrimaryKeySelective(product);
|
|
|
+ //记录LOG
|
|
|
+ messageLogService.close(generateMsgObj(id));
|
|
|
+ return true;
|
|
|
+ }else{
|
|
|
+ throw new BizException(BizExceptionCode.ILLEGAL_ID);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean open(Long id) {
|
|
|
+ if(id != null && id > 0){
|
|
|
+ Product product = getMapper().selectByPrimaryKey(id);
|
|
|
+ if (product == null) {
|
|
|
+ throw new BizException(BizExceptionCode.NO_DATA);
|
|
|
+ }
|
|
|
+ if (!Status.CLOSE.getDisplay().equals(product.getPr_status())){
|
|
|
+ throw new BizException(BizExceptionCode.BIZ_OPEN);
|
|
|
+ }else{
|
|
|
+ product.setId(id);
|
|
|
+ product.setPr_statuscode(Status.OPEN.name());
|
|
|
+ product.setPr_status(Status.OPEN.getDisplay());
|
|
|
+ getMapper().updateByPrimaryKeySelective(product);
|
|
|
+ //记录LOG
|
|
|
+ messageLogService.open(generateMsgObj(id));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ throw new BizException(BizExceptionCode.ILLEGAL_ID);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<ProductDTO> getList(ListReqDTO listReqDTO){
|
|
|
+ Long companyId = BaseContextHolder.getCompanyId();
|
|
|
+ String condition = listReqDTO.getFinalCondition();
|
|
|
+ if(condition == null){
|
|
|
+ condition = "1=1";
|
|
|
+ }
|
|
|
+ List<ProductDTO> productDTOList = getMapper().getProductsByCondition(condition, companyId);
|
|
|
+ return productDTOList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构造日记记录对象
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private DocBaseDTO generateMsgObj(Long id){
|
|
|
+ return new DocBaseDTO(id, "", "Product");
|
|
|
+ }
|
|
|
}
|