Ver Fonte

1.物料资料增加明细
2.供应商、仓库增加编号/名称重复性校验

chenw há 7 anos atrás
pai
commit
7818eda256
18 ficheiros alterados com 1412 adições e 11 exclusões
  1. 4 0
      applications/commons/commons-dto/src/main/java/com/usoftchina/saas/commons/exception/BizExceptionCode.java
  2. 11 0
      applications/document/document-dto/src/main/java/com.usoftchina.saas.document.dto/ProductListDTO.java
  3. 86 0
      applications/document/document-dto/src/main/java/com/usoftchina/saas/document/entities/ProdIODetail.java
  4. 72 0
      applications/document/document-dto/src/main/java/com/usoftchina/saas/document/entities/ProdInOut.java
  5. 148 0
      applications/document/document-dto/src/main/java/com/usoftchina/saas/document/entities/ProductDetail.java
  6. 7 1
      applications/document/document-server/src/main/java/com/usoftchina/saas/document/controller/ProductController.java
  7. 28 0
      applications/document/document-server/src/main/java/com/usoftchina/saas/document/mapper/ProductDetailMapper.java
  8. 16 1
      applications/document/document-server/src/main/java/com/usoftchina/saas/document/mapper/ProductMapper.java
  9. 4 0
      applications/document/document-server/src/main/java/com/usoftchina/saas/document/mapper/VendorMapper.java
  10. 3 0
      applications/document/document-server/src/main/java/com/usoftchina/saas/document/mapper/WarehouseMapper.java
  11. 10 2
      applications/document/document-server/src/main/java/com/usoftchina/saas/document/service/ProductService.java
  12. 220 6
      applications/document/document-server/src/main/java/com/usoftchina/saas/document/service/impl/ProductServiceImpl.java
  13. 23 0
      applications/document/document-server/src/main/java/com/usoftchina/saas/document/service/impl/VendorServiceImpl.java
  14. 18 0
      applications/document/document-server/src/main/java/com/usoftchina/saas/document/service/impl/WarehouseServiceImpl.java
  15. 332 0
      applications/document/document-server/src/main/resources/mapper/ProductDetailMapper.xml
  16. 409 1
      applications/document/document-server/src/main/resources/mapper/ProductMapper.xml
  17. 6 0
      applications/document/document-server/src/main/resources/mapper/VendorMapper.xml
  18. 15 0
      applications/document/document-server/src/main/resources/mapper/WarehouseMapper.xml

+ 4 - 0
applications/commons/commons-dto/src/main/java/com/usoftchina/saas/commons/exception/BizExceptionCode.java

@@ -26,9 +26,13 @@ public enum BizExceptionCode implements BaseExceptionCode {
     BIZ_UNAUDITED(79304,"只能反审核已审核的单据"),
     BIZ_DELETE(79305,"只能删除未审核的单据"),
     BIZ_RELDELETE(79305,"存在关联单据,不允许删除"),
+    BIZ_RELDELETE_UPDATE(79306,"存在关联单据,不允许更新编号"),
+    BIZ_RELDELETE_UPDATEPROD(79307,"存在关联单据,不允许更新"),
+    BIZ_RELDELETE_DELETEPROD(79308,"存在关联单据,不允许删除"),
     NO_OPRATIONDATA(79400,"无可操作单据"),
     BOM_SAVE(79401, "产品编号+版本号已存在"),
     REPEAT_NAME(79501, "名称重复"),
+    REPEAT_CODE(79502, "编号重复"),
     NO_DATA(79998, "未找到数据"),
     ILLEGAL_ID(79999, "id不正确"),
     PRODUCT_HAS_WAREHOUSE(79502, "存在物料默认仓库资料为该仓库资料,无法删除"),

+ 11 - 0
applications/document/document-dto/src/main/java/com.usoftchina.saas.document.dto/ProductListDTO.java

@@ -1,12 +1,23 @@
 package com.usoftchina.saas.document.dto;
 
 import com.usoftchina.saas.document.entities.Product;
+import com.usoftchina.saas.document.entities.ProductDetail;
 
 import java.io.Serializable;
+import java.util.List;
 
 public class ProductListDTO implements Serializable {
 
     private Product main;
+    private List<ProductDetail> items;
+
+    public List<ProductDetail> getItems() {
+        return items;
+    }
+
+    public void setItems(List<ProductDetail> items) {
+        this.items = items;
+    }
 
     public Product getMain() {
         return main;

+ 86 - 0
applications/document/document-dto/src/main/java/com/usoftchina/saas/document/entities/ProdIODetail.java

@@ -0,0 +1,86 @@
+package com.usoftchina.saas.document.entities;
+
+import com.usoftchina.saas.base.entity.CommonBaseEntity;
+import com.usoftchina.saas.document.dto.ProductDTO;
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class ProdIODetail extends CommonBaseEntity implements Serializable {
+
+    private Long pd_piid;
+
+    private String pd_inoutno;
+
+    private String pd_piclass;
+
+    private Integer pd_pdno;
+
+    private String pd_ordercode;
+
+    private Integer pd_orderdetno;
+
+    private Long pd_prodid;
+
+    private String pd_prodcode;
+
+    private String pd_unit;
+
+    private Double pd_inqty;
+
+    private Double pd_outqty;
+
+    private Double pd_orderprice;
+
+    private Double pd_sendprice;
+
+    private Double pd_price;
+
+    private Double pd_total;
+
+    private Double pd_taxrate;
+
+    private Double pd_netprice;
+
+    private Double pd_nettotal;
+
+    private Integer pd_whid;
+
+    private String pd_whcode;
+
+    private String pd_whname;
+
+    private Integer pd_inwhid;
+
+    private String pd_inwhcode;
+
+    private String pd_inwhname;
+
+    private Integer pd_orderid;
+
+    private Integer pd_sdid;
+
+    private Integer pd_status;
+
+    private String pd_text1;
+
+    private String pd_text2;
+
+    private String pd_text3;
+
+    private String pd_text4;
+
+    private String pd_text5;
+
+    private Integer pd_ym;
+
+    private Double pd_yqty;
+
+    private String pd_remark;
+
+    private Long pd_ioid;
+
+    private ProductDTO productDTO;
+
+}

+ 72 - 0
applications/document/document-dto/src/main/java/com/usoftchina/saas/document/entities/ProdInOut.java

@@ -0,0 +1,72 @@
+package com.usoftchina.saas.document.entities;
+
+import com.usoftchina.saas.base.entity.CommonBaseEntity;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+@Data
+public class ProdInOut extends CommonBaseEntity implements Serializable {
+
+    private String pi_inoutno;
+
+    private String pi_class;
+
+    private Date pi_date;
+
+    private Integer pi_vendid;
+
+    private String pi_vendcode;
+
+    private String pi_vendname;
+
+    private Integer pi_custid;
+
+    private String pi_custcode;
+
+    private String pi_custname;
+
+    private Integer pi_puid;
+
+    private String pi_pucode;
+
+    private Integer pi_said;
+
+    private String pi_sacode;
+
+    private Double pi_total;
+
+    private Long pi_recordmanid;
+
+    private String pi_recordman;
+
+    private Date pi_recorddate;
+
+    private String pi_status;
+
+    private String pi_statuscode;
+
+    private String pi_printstatus;
+
+    private String pi_printstatuscode;
+
+    private String pi_text1;
+
+    private String pi_text2;
+
+    private String pi_text3;
+
+    private String pi_text4;
+
+    private String pi_text5;
+
+    private String pi_address;
+
+    private Date pi_auditdate;
+
+    private String pi_auditman;
+
+    private String pi_remark;
+
+}

+ 148 - 0
applications/document/document-dto/src/main/java/com/usoftchina/saas/document/entities/ProductDetail.java

@@ -0,0 +1,148 @@
+package com.usoftchina.saas.document.entities;
+
+import com.usoftchina.saas.base.entity.CommonBaseEntity;
+
+import java.io.Serializable;
+import java.util.Date;
+
+public class ProductDetail extends CommonBaseEntity implements Serializable {
+    private Long pd_prodid;
+
+    private String pd_prodcode;
+
+    private Integer pd_detno;
+
+    private String pd_whcode;
+
+    private String pd_whname;
+
+    private Integer pd_whid;
+
+    private Double pd_price;
+
+    private Double pd_amount;
+
+    private String pd_text1;
+
+    private String pd_text2;
+
+    private String pd_text3;
+
+    private String pd_text4;
+
+    private String pd_text5;
+
+    private Double pd_num;
+
+    public Long getPd_prodid() {
+        return pd_prodid;
+    }
+
+    public void setPd_prodid(Long pd_prodid) {
+        this.pd_prodid = pd_prodid;
+    }
+
+    public String getPd_prodcode() {
+        return pd_prodcode;
+    }
+
+    public void setPd_prodcode(String pd_prodcode) {
+        this.pd_prodcode = pd_prodcode == null ? null : pd_prodcode.trim();
+    }
+
+    public Integer getPd_detno() {
+        return pd_detno;
+    }
+
+    public void setPd_detno(Integer pd_detno) {
+        this.pd_detno = pd_detno;
+    }
+
+    public String getPd_whcode() {
+        return pd_whcode;
+    }
+
+    public void setPd_whcode(String pd_whcode) {
+        this.pd_whcode = pd_whcode == null ? null : pd_whcode.trim();
+    }
+
+    public String getPd_whname() {
+        return pd_whname;
+    }
+
+    public void setPd_whname(String pd_whname) {
+        this.pd_whname = pd_whname == null ? null : pd_whname.trim();
+    }
+
+    public Integer getPd_whid() {
+        return pd_whid;
+    }
+
+    public void setPd_whid(Integer pd_whid) {
+        this.pd_whid = pd_whid;
+    }
+
+    public Double getPd_price() {
+        return pd_price;
+    }
+
+    public void setPd_price(Double pd_price) {
+        this.pd_price = pd_price;
+    }
+
+    public Double getPd_amount() {
+        return pd_amount;
+    }
+
+    public void setPd_amount(Double pd_amount) {
+        this.pd_amount = pd_amount;
+    }
+
+    public String getPd_text1() {
+        return pd_text1;
+    }
+
+    public void setPd_text1(String pd_text1) {
+        this.pd_text1 = pd_text1 == null ? null : pd_text1.trim();
+    }
+
+    public String getPd_text2() {
+        return pd_text2;
+    }
+
+    public void setPd_text2(String pd_text2) {
+        this.pd_text2 = pd_text2 == null ? null : pd_text2.trim();
+    }
+
+    public String getPd_text3() {
+        return pd_text3;
+    }
+
+    public void setPd_text3(String pd_text3) {
+        this.pd_text3 = pd_text3 == null ? null : pd_text3.trim();
+    }
+
+    public String getPd_text4() {
+        return pd_text4;
+    }
+
+    public void setPd_text4(String pd_text4) {
+        this.pd_text4 = pd_text4 == null ? null : pd_text4.trim();
+    }
+
+    public String getPd_text5() {
+        return pd_text5;
+    }
+
+    public void setPd_text5(String pd_text5) {
+        this.pd_text5 = pd_text5 == null ? null : pd_text5.trim();
+    }
+
+    public Double getPd_num() {
+        return pd_num;
+    }
+
+    public void setPd_num(Double pd_num) {
+        this.pd_num = pd_num;
+    }
+}

+ 7 - 1
applications/document/document-server/src/main/java/com/usoftchina/saas/document/controller/ProductController.java

@@ -51,7 +51,7 @@ public class ProductController {
 
     @PostMapping("/save")
     public Result save(@RequestBody ProductListDTO productListDTO){
-        DocBaseDTO docBaseDTO = productService.saveData(productListDTO.getMain());
+        DocBaseDTO docBaseDTO = productService.saveData(productListDTO);
         return Result.success(docBaseDTO);
     }
 
@@ -61,6 +61,12 @@ public class ProductController {
         return Result.success();
     }
 
+    @PostMapping("/deleteDetail/{id}")
+    public Result deleteDetail(@PathVariable("id") Long id){
+        productService.deleteDetailById(id);
+        return Result.success();
+    }
+
     @PostMapping("/close/{id}")
     public Result close(@PathVariable("id") Long id){
         DocBaseDTO docBaseDTO = productService.close(id);

+ 28 - 0
applications/document/document-server/src/main/java/com/usoftchina/saas/document/mapper/ProductDetailMapper.java

@@ -0,0 +1,28 @@
+package com.usoftchina.saas.document.mapper;
+
+import com.usoftchina.saas.base.mapper.CommonBaseMapper;
+import com.usoftchina.saas.document.entities.ProductDetail;
+
+import java.util.List;
+
+public interface ProductDetailMapper extends CommonBaseMapper<ProductDetail> {
+    int deleteByPrimaryKey(Integer id);
+
+    int insert(ProductDetail record);
+
+    int insertSelective(ProductDetail record);
+
+    ProductDetail selectByPrimaryKey(Integer id);
+
+    int updateByPrimaryKeySelective(ProductDetail record);
+
+    int updateByPrimaryKey(ProductDetail record);
+
+    void batchInsert(List<ProductDetail> productDetailList);
+
+    void batchUpdate(List<ProductDetail> productDetailList);
+
+    Long selectProdidByPrimaryKey(Long id);
+
+    List<ProductDetail> selectByProdId(Long id);
+}

+ 16 - 1
applications/document/document-server/src/main/java/com/usoftchina/saas/document/mapper/ProductMapper.java

@@ -4,6 +4,8 @@ import com.usoftchina.saas.base.mapper.CommonBaseMapper;
 import com.usoftchina.saas.commons.dto.ComboDTO;
 import com.usoftchina.saas.document.dto.ProductDTO;
 import com.usoftchina.saas.document.dto.ProductReserveCostDTO;
+import com.usoftchina.saas.document.entities.ProdIODetail;
+import com.usoftchina.saas.document.entities.ProdInOut;
 import com.usoftchina.saas.document.entities.Product;
 import org.apache.ibatis.annotations.Param;
 
@@ -13,7 +15,7 @@ public interface ProductMapper extends CommonBaseMapper<Product> {
 
     List<ProductDTO> getProductsByCondition(@Param("con") String con, @Param("companyId") Long companyId);
 
-    List<ComboDTO> getProdUnit();
+    List<ComboDTO> getProdUnit(@Param("companyId") Long companyId);
 
     void updateLatestPurchasePrice(Long pu_id);
 
@@ -33,4 +35,17 @@ public interface ProductMapper extends CommonBaseMapper<Product> {
 
     int getCountFromProdIO(@Param("id") Long id, @Param("companyId") Long companyId);
 
+    boolean saveProdInOut(ProdInOut prodInOut);
+
+    boolean batchInsertDetail(List<ProdIODetail> prodIODetailList);
+
+    boolean batchUpdateDetail(List<ProdIODetail> prodIODetailList);
+
+    String selectProdIOCode(@Param("code") String code, @Param("companyId") Long companyId, @Param("type") String type);
+
+    int selectOrderCountByProdCode(@Param("id") Long id, @Param("companyId") Long companyId);
+
+    boolean deleteProdIOByCode(@Param("code") String code, @Param("companyId") Long companyId);
+
+    boolean deleteProdIODetailByCode(@Param("code") String code, @Param("companyId") Long companyId);
 }

+ 4 - 0
applications/document/document-server/src/main/java/com/usoftchina/saas/document/mapper/VendorMapper.java

@@ -22,4 +22,8 @@ public interface VendorMapper extends CommonBaseMapper<Vendor> {
     int validateCodeWhenUpdate(@Param("code") String code, @Param("id") Long id, @Param("companyId") Long company);
 
     String getCodeById(@Param("id") Long id, @Param("companyId") Long companyId);
+
+    int getCountByCode(@Param("code") String code, @Param("companyId") Long companyId);
+
+    int getCountByName(@Param("name") String name, @Param("companyId") Long companyId);
 }

+ 3 - 0
applications/document/document-server/src/main/java/com/usoftchina/saas/document/mapper/WarehouseMapper.java

@@ -40,4 +40,7 @@ public interface WarehouseMapper extends CommonBaseMapper<Warehouse> {
     Integer deleteCheckProduct(@Param("id") Long id, @Param("companyId") Long companyId);
 
     Integer deleteCheckWH(@Param("id") Long id, @Param("companyId") Long companyId);
+
+    int selectCountByCode(@Param("code") String code, @Param("companyId") Long companyId, @Param("id") Long id);
+
 }

+ 10 - 2
applications/document/document-server/src/main/java/com/usoftchina/saas/document/service/ProductService.java

@@ -9,6 +9,7 @@ import com.usoftchina.saas.commons.dto.ComboDTO;
 import com.usoftchina.saas.commons.dto.DocBaseDTO;
 import com.usoftchina.saas.commons.dto.ListReqDTO;
 import com.usoftchina.saas.document.dto.ProductDTO;
+import com.usoftchina.saas.document.dto.ProductListDTO;
 import com.usoftchina.saas.document.dto.ProductReserveCostDTO;
 import com.usoftchina.saas.document.entities.Product;
 import com.usoftchina.saas.document.mapper.ProductMapper;
@@ -48,10 +49,10 @@ public interface ProductService extends CommonBaseService<ProductMapper, Product
 
     /**
      * 保存/更新
-     * @param product
+     * @param productListDTO
      * @return
      */
-    DocBaseDTO saveData(Product product);
+    DocBaseDTO saveData(ProductListDTO productListDTO);
 
     /**
      * 关闭
@@ -109,4 +110,11 @@ public interface ProductService extends CommonBaseService<ProductMapper, Product
      * @return
      */
     PageInfo<ProductReserveCostDTO> getReserveCost(PageRequest page, ListReqDTO listReqDTO);
+
+    /**
+     * 通过明细ID删除明细
+     * @param id
+     * @return
+     */
+    boolean deleteDetailById(Long id);
 }

+ 220 - 6
applications/document/document-server/src/main/java/com/usoftchina/saas/document/service/impl/ProductServiceImpl.java

@@ -14,18 +14,20 @@ import com.usoftchina.saas.commons.po.BillCodeSeq;
 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.dto.ProductListDTO;
 import com.usoftchina.saas.document.dto.ProductReserveCostDTO;
-import com.usoftchina.saas.document.entities.Product;
+import com.usoftchina.saas.document.entities.*;
+import com.usoftchina.saas.document.mapper.ProductDetailMapper;
 import com.usoftchina.saas.document.mapper.ProductMapper;
 import com.usoftchina.saas.document.service.ProductService;
+import com.usoftchina.saas.document.service.WarehouseService;
 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 org.springframework.util.StringUtils;
 
-import javax.print.Doc;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
 @Service
 public class ProductServiceImpl extends CommonBaseServiceImpl<ProductMapper, Product> implements ProductService {
@@ -34,6 +36,10 @@ public class ProductServiceImpl extends CommonBaseServiceImpl<ProductMapper, Pro
     private MessageLogService messageLogService;
     @Autowired
     private MaxnumberService maxnumberService;
+    @Autowired
+    private WarehouseService warehouseService;
+    @Autowired
+    private ProductDetailMapper productDetailMapper;
 
     @Override
     public PageInfo<ProductDTO> getProductsByCondition(PageRequest page, ListReqDTO listReqDTO) {
@@ -52,7 +58,7 @@ public class ProductServiceImpl extends CommonBaseServiceImpl<ProductMapper, Pro
 
     @Override
     public List<ComboDTO> getProdUnit() {
-        return getMapper().getProdUnit();
+        return getMapper().getProdUnit(BaseContextHolder.getCompanyId());
     }
 
     @Override
@@ -69,18 +75,65 @@ public class ProductServiceImpl extends CommonBaseServiceImpl<ProductMapper, Pro
     }
 
     @Override
-    public DocBaseDTO saveData(Product product){
+    public DocBaseDTO saveData(ProductListDTO productListDTO){
+        Product product = productListDTO.getMain();
+        List<ProductDetail> productDetailList = productListDTO.getItems();
         DocBaseDTO docBaseDTO = null;
         if(product.getId() == 0){
+            //保存
             String code = pushMaxnubmer(product.getPr_code(), product.getId());
             product.setCompanyId(BaseContextHolder.getCompanyId());
             product.setCreatorId(BaseContextHolder.getUserId());
             product.setCreateTime(new Date());
+            //保存主表
             getMapper().insertSelective(product);
+            //保存明细表数据
+            productDetailMapper.batchInsert(productDetailList);
+            //生成库存初始化数据并过账
+            generateProdIOPost(product, productDetailList);
+
             docBaseDTO = generateMsgObj(product.getId(), code);
             //记录LOG
             messageLogService.save(docBaseDTO);
         }else{
+            String oldCode = getMapper().getCodeById(product.getId());
+            if (!product.getPr_code().equals(oldCode)){
+                validEnableUpdate(product.getId());
+            }
+            //物料发生过除库存初始化外的出入库单时,不能新增,修改,删除
+            validProductOperation(product.getId(), BizExceptionCode.BIZ_RELDELETE_UPDATEPROD);
+
+            //明细数据有更新/插入动作
+            if (productDetailList.size() > 0){
+                //找到原始单据,反过账并删除
+                String inoutCode = getMapper().selectProdIOCode(product.getPr_code(), BaseContextHolder.getCompanyId(), "库存初始化");
+                post(inoutCode, "反过账");
+                getMapper().deleteProdIOByCode(inoutCode, BaseContextHolder.getCompanyId());
+                getMapper().deleteProdIODetailByCode(inoutCode, BaseContextHolder.getCompanyId());
+                //此种情况不可能发生明细行数量,只会发生明细行数据修改/新增明细行
+                //a.更新明细行数据
+                List<ProductDetail> insertItems = new ArrayList<ProductDetail>();
+                List<ProductDetail> updateItems = new ArrayList<ProductDetail>();
+                for(ProductDetail productDetail : productDetailList){
+                    if (productDetail.getId() == 0){
+                        insertItems.add(productDetail);
+                    }else{
+                        updateItems.add(productDetail);
+                    }
+                }
+                if (insertItems.size() > 0){
+                    productDetailMapper.batchInsert(insertItems);
+                }
+                if (updateItems.size() > 0){
+                    productDetailMapper.batchUpdate(updateItems);
+                }
+
+                //b.获取更新后的明细数据,生成库存初始化数据并过账
+                List<ProductDetail> productDetails = productDetailMapper.selectByProdId(product.getId());
+                generateProdIOPost(product, productDetails);
+
+            }
+
             product.setUpdaterId(BaseContextHolder.getUserId());
             product.setUpdateTime(new Date());
             getMapper().updateByPrimaryKeySelective(product);
@@ -91,8 +144,111 @@ public class ProductServiceImpl extends CommonBaseServiceImpl<ProductMapper, Pro
         return docBaseDTO;
     }
 
+    /**
+     * 物料发生过除库存初始化外的出入库单时,不能新增,修改,删除
+     * @param id
+     */
+    private void validProductOperation(Long id, BizExceptionCode bizExceptionCode) {
+        int count = getMapper().selectOrderCountByProdCode(id, BaseContextHolder.getCompanyId());
+        if (count > 0){
+            throw new BizException(bizExceptionCode);
+        }
+    }
+
+    /**
+     * 生成库存初始化数据并过账
+     * @param product
+     * @param productDetailList
+     */
+    private void generateProdIOPost(Product product, List<ProductDetail> productDetailList) {
+        Long companyId = BaseContextHolder.getCompanyId();
+        Long userId = BaseContextHolder.getUserId();
+        //1.有明细数据变更
+        if (productDetailList.size() > 0){
+            //生成库存初始化单据主表
+            ProdInOut prodInOut = new ProdInOut();
+            String inoutCode = maxnumberService.getMaxnumber("StorageInit", true).getData();
+            prodInOut.setPi_inoutno(inoutCode);     //出入库单号
+            prodInOut.setPi_class("库存初始化");
+            prodInOut.setPi_date(new Date());
+            //prodInOut.setPi_total();            //含税金额
+            prodInOut.setPi_recordman("");
+            prodInOut.setPi_recordmanid(userId);
+            prodInOut.setPi_recorddate(new Date());
+            prodInOut.setPi_status(Status.UNAUDITED.getDisplay());
+            prodInOut.setPi_statuscode(Status.UNAUDITED.name());
+            prodInOut.setPi_text1(product.getPr_code());
+            prodInOut.setCompanyId(companyId);
+
+            //主表插入
+            getMapper().saveProdInOut(prodInOut);
+            Long pi_id = prodInOut.getId();
+            List<ProdIODetail> insertItems = new ArrayList<ProdIODetail>();
+            //生成库存初始化单据明细表
+            for(ProductDetail productDetail : productDetailList){
+                ProdIODetail prodIODetail = generateProdIODetail(product, productDetail);
+                insertItems.add(prodIODetail);
+            }
+            //明细插入
+            getMapper().batchInsertDetail(insertItems);
+
+            //过账
+            post(inoutCode, "过账");
+        }
+    }
+
+    /**
+     * 过账
+     * @param code
+     */
+    private void post(String code, String type){
+        Map<String, Object> map = new HashMap<String, Object>();
+        map.put("inoutNo", code);
+        map.put("class", "库存初始化");
+        map.put("commitid", BaseContextHolder.getUserId());
+        map.put("companyId", BaseContextHolder.getCompanyId());
+        map.put("result", null);
+        if ("过账".equals(type)) {
+            warehouseService.post(map);
+        }else if ("反过账".equals(type)){
+            warehouseService.unPost(map);
+        }
+        if (StringUtils.isEmpty(map.get("result"))){
+            throw new BizException(76203, map.get("result").toString());
+        }
+    }
+
+    /**
+     * 生成库存初始化明细表
+     * @param product
+     * @param productDetail
+     * @return
+     */
+    private ProdIODetail generateProdIODetail(Product product, ProductDetail productDetail){
+        ProdIODetail prodIODetail = new ProdIODetail();
+        prodIODetail.setPd_piclass("库存初始化");
+        prodIODetail.setPd_inoutno(product.getPr_code());
+        prodIODetail.setPd_piid(product.getId());
+        prodIODetail.setPd_pdno(productDetail.getPd_detno());
+        prodIODetail.setPd_ordercode(product.getPr_code());         //订单号 -> 物料编号
+        prodIODetail.setPd_orderdetno(productDetail.getPd_detno()); //订单序号 -> 物料明细序号
+        prodIODetail.setPd_prodid(product.getId());                 //物料
+        prodIODetail.setPd_prodcode(product.getPr_code());          //物料编号
+        prodIODetail.setPd_unit(product.getPr_unit());              //单位
+        prodIODetail.setPd_inqty(productDetail.getPd_num());        //数量
+        prodIODetail.setPd_price(productDetail.getPd_price());      //成本单价
+        prodIODetail.setPd_total(productDetail.getPd_amount());     //成本金额
+        prodIODetail.setPd_whid(productDetail.getPd_whid());        //仓库库ID
+        prodIODetail.setPd_whcode(productDetail.getPd_whcode());    //仓库编号
+        prodIODetail.setPd_whname(productDetail.getPd_whname());    //仓库名称
+        prodIODetail.setPd_status(0);                               //状态
+        prodIODetail.setCompanyId(BaseContextHolder.getCompanyId());//公司ID
+        return prodIODetail;
+    }
+
     @Override
     public DocBaseDTO close(Long id) {
+        validEnableUpdate(id);
         DocBaseDTO docBaseDTO = null;
         if(id != null && id > 0){
             String code = getMapper().getCodeById(id);
@@ -169,7 +325,10 @@ public class ProductServiceImpl extends CommonBaseServiceImpl<ProductMapper, Pro
     @Override
     public boolean deleteByPrimaryKey(Long id) {
         //校验物料是否已经在使用状态(采购单、销售单、BOM、出入库单)
+        validProductOperation(id, BizExceptionCode.BIZ_RELDELETE_DELETEPROD);
+        //校验是否存在关联单据
         validEnableDel(id);
+
         String code = getMapper().getCodeById(id);
         getMapper().deleteByPrimaryKey(id);
         DocBaseDTO docBaseDTO = generateMsgObj(id, code);
@@ -178,6 +337,10 @@ public class ProductServiceImpl extends CommonBaseServiceImpl<ProductMapper, Pro
         return true;
     }
 
+    /**
+     * 校验是否存在关联单据
+     * @param id
+     */
     private void validEnableDel(Long id) {
         int count = 0;
         //采购
@@ -203,6 +366,34 @@ public class ProductServiceImpl extends CommonBaseServiceImpl<ProductMapper, Pro
         //batch
     }
 
+    /**
+     * 校验是否存在关联单据,不存在时才允许更新物料编号
+     * @param id
+     */
+    private void validEnableUpdate(Long id){
+        int count = 0;
+        //采购
+        count = getMapper().getCountFromPurc(id, BaseContextHolder.getCompanyId());
+        if (count > 0){
+            throw new BizException(BizExceptionCode.BIZ_RELDELETE_UPDATE);
+        }
+        //销售
+        count = getMapper().getCountFromSale(id, BaseContextHolder.getCompanyId());
+        if (count > 0){
+            throw new BizException(BizExceptionCode.BIZ_RELDELETE_UPDATE);
+        }
+        //BOM
+        count = getMapper().getCountFromBom(id, BaseContextHolder.getCompanyId());
+        if (count > 0){
+            throw new BizException(BizExceptionCode.BIZ_RELDELETE_UPDATE);
+        }
+        //出入库
+        count = getMapper().getCountFromProdIO(id, BaseContextHolder.getCompanyId());
+        if (count > 0){
+            throw new BizException(BizExceptionCode.BIZ_RELDELETE_UPDATE);
+        }
+    }
+
     @Override
     public boolean batchDelete(BatchDealBaseDTO baseDTOs) {
         for(DocBaseDTO docBaseDTO : baseDTOs.getBaseDTOs()){
@@ -231,6 +422,29 @@ public class ProductServiceImpl extends CommonBaseServiceImpl<ProductMapper, Pro
         return pageInfo;
     }
 
+    @Override
+    public boolean deleteDetailById(Long id) {
+        Long prodId = productDetailMapper.selectProdidByPrimaryKey(id);
+        validProductOperation(prodId, BizExceptionCode.BIZ_RELDELETE_DELETEPROD);
+        String prCode = getMapper().selectByPrimaryKey(id).getPr_code();
+        //找到原始单据,反过账并删除
+        String inoutCode = getMapper().selectProdIOCode(prCode, BaseContextHolder.getCompanyId(), "库存初始化");
+        if (!StringUtils.isEmpty(inoutCode)) {
+            post(inoutCode, "反过账");
+            getMapper().deleteProdIOByCode(inoutCode, BaseContextHolder.getCompanyId());
+            getMapper().deleteProdIODetailByCode(inoutCode, BaseContextHolder.getCompanyId());
+        }
+
+        productDetailMapper.deleteByPrimaryKey(id);
+
+        Product product = getMapper().selectByPrimaryKey(prodId);
+        List<ProductDetail> productDetailList = productDetailMapper.selectByProdId(prodId);
+
+        generateProdIOPost(product, productDetailList);
+
+        return true;
+    }
+
     private List<ProductReserveCostDTO> geReserveCost(ListReqDTO listReqDTO) {
         Long companyId = BaseContextHolder.getCompanyId();
         String condition = listReqDTO.getFinalCondition();

+ 23 - 0
applications/document/document-server/src/main/java/com/usoftchina/saas/document/service/impl/VendorServiceImpl.java

@@ -101,6 +101,7 @@ public class VendorServiceImpl extends CommonBaseServiceImpl<VendorMapper, Vendo
     @Override
     @Transactional
     public DocBaseDTO saveFormData(VendorListDTO vendorListDTO) {
+        Long companyId = BaseContextHolder.getCompanyId();
         if (null == vendorListDTO || null == vendorListDTO.getMain()){
             throw new BizException(500, "数据为空,请填写后再保存");
         }
@@ -110,6 +111,14 @@ public class VendorServiceImpl extends CommonBaseServiceImpl<VendorMapper, Vendo
         List<Vendorcontact> items = vendorListDTO.getItems();
         if(main.getId() == 0){
             code = pushMaxnubmer(main.getVe_code(), main.getId());
+            int count = getMapper().getCountByCode(code, companyId);
+            if(count > 0){
+                throw new BizException(500, "编号重复!");
+            }
+            count = getMapper().getCountByName(main.getVe_name(), companyId);
+            if (count > 0){
+                throw new BizException(500, "名称重复!");
+            }
             //保存主表信息
             main.setVe_code(code);
             getMapper().insertSelective(main);
@@ -129,6 +138,20 @@ public class VendorServiceImpl extends CommonBaseServiceImpl<VendorMapper, Vendo
             messageLogService.save(generateMsgObj(mainId, code));
         }else{
             code = main.getVe_code();
+            Vendor oldVendor = getMapper().selectByPrimaryKey(main.getId());
+            int count = getMapper().getCountByCode(code, companyId);
+            if (!code.equals(oldVendor.getVe_code())){
+                if (count > 0){
+                    throw new BizException(500, "编号重复!");
+                }
+            }
+            if (!main.getVe_name().equals(oldVendor.getVe_name())){
+                count = getMapper().getCountByName(main.getVe_name(), companyId);
+                if (count > 0){
+                    throw new BizException(500, "名称重复!");
+                }
+            }
+
             getMapper().updateByPrimaryKeySelective(main);
             if (items.size() > 0) {
                 List<Vendorcontact> updateItems = new ArrayList<Vendorcontact>();

+ 18 - 0
applications/document/document-server/src/main/java/com/usoftchina/saas/document/service/impl/WarehouseServiceImpl.java

@@ -104,6 +104,7 @@ public class WarehouseServiceImpl extends CommonBaseServiceImpl<WarehouseMapper,
     public DocBaseDTO insertSelective(Warehouse record) {
         int count = 0;
         DocBaseDTO docBaseDTO = null;
+        Long companyId = BaseContextHolder.getCompanyId();
         if(record.getId() == 0){
             String code = pushMaxnubmer(record.getWh_code(), record.getId());
             record.setCompanyId(BaseContextHolder.getCompanyId());
@@ -112,6 +113,9 @@ public class WarehouseServiceImpl extends CommonBaseServiceImpl<WarehouseMapper,
 
             //验证名称是否重复
             validName(record.getWh_description(), record.getId());
+            //验证编号是否重复
+            validCode(code, record.getId());
+
             count = getMapper().insertSelective(record);
             //记录LOG
             docBaseDTO = generateMsgObj(record.getId(), code);
@@ -121,6 +125,8 @@ public class WarehouseServiceImpl extends CommonBaseServiceImpl<WarehouseMapper,
             record.setUpdaterId(BaseContextHolder.getUserId());
             //验证名称是否重复
             validName(record.getWh_description(), record.getId());
+            //验证编号是否重复
+            validCode(record.getWh_code(), record.getId());
 
             getMapper().updateByPrimaryKeySelective(record);
             //记录LOG
@@ -130,6 +136,18 @@ public class WarehouseServiceImpl extends CommonBaseServiceImpl<WarehouseMapper,
         return docBaseDTO;
     }
 
+    /**
+     * 校验code是否存在
+     * @param code
+     * @param id
+     */
+    private void validCode(String code, Long id) {
+        int count = getMapper().selectCountByCode(code, BaseContextHolder.getCompanyId(), id);
+        if (count > 0){
+            throw new BizException(BizExceptionCode.REPEAT_CODE);
+        }
+    }
+
     /**
      * 反过账
      * @param map

+ 332 - 0
applications/document/document-server/src/main/resources/mapper/ProductDetailMapper.xml

@@ -0,0 +1,332 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.usoftchina.saas.document.mapper.ProductDetailMapper" >
+  <resultMap id="BaseResultMap" type="com.usoftchina.saas.document.entities.ProductDetail" >
+    <id column="id" property="id" jdbcType="INTEGER" />
+    <result column="pd_prodid" property="pd_prodid" jdbcType="INTEGER" />
+    <result column="pd_prodcode" property="pd_prodcode" jdbcType="VARCHAR" />
+    <result column="pd_detno" property="pd_detno" jdbcType="INTEGER" />
+    <result column="pd_whcode" property="pd_whcode" jdbcType="VARCHAR" />
+    <result column="pd_whname" property="pd_whname" jdbcType="VARCHAR" />
+    <result column="pd_whid" property="pd_whid" jdbcType="INTEGER" />
+    <result column="pd_price" property="pd_price" jdbcType="DOUBLE" />
+    <result column="pd_amount" property="pd_amount" jdbcType="DOUBLE" />
+    <result column="companyId" property="companyId" jdbcType="INTEGER" />
+    <result column="updaterId" property="updaterId" jdbcType="INTEGER" />
+    <result column="updateTime" property="updateTime" jdbcType="TIMESTAMP" />
+    <result column="pd_text1" property="pd_text1" jdbcType="VARCHAR" />
+    <result column="pd_text2" property="pd_text2" jdbcType="VARCHAR" />
+    <result column="pd_text3" property="pd_text3" jdbcType="VARCHAR" />
+    <result column="pd_text4" property="pd_text4" jdbcType="VARCHAR" />
+    <result column="pd_text5" property="pd_text5" jdbcType="VARCHAR" />
+    <result column="pd_num" property="pd_num" jdbcType="DOUBLE" />
+  </resultMap>
+  <sql id="Base_Column_List" >
+    id, pd_prodid, pd_prodcode, pd_detno, pd_whcode, pd_whname, pd_whid, pd_price, pd_amount, 
+    companyId, updaterId, updateTime, pd_text1, pd_text2, pd_text3, pd_text4, pd_text5, 
+    pd_num
+  </sql>
+  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
+    select 
+    <include refid="Base_Column_List" />
+    from productdetail
+    where id = #{id}
+  </select>
+  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
+    delete from productdetail
+    where id = #{id}
+  </delete>
+  <insert id="insert" parameterType="com.usoftchina.saas.document.entities.ProductDetail" >
+      <selectKey resultType="java.lang.Long" keyProperty="id">
+          SELECT LAST_INSERT_ID() AS ID
+      </selectKey>
+    insert into productdetail ( pd_prodid, pd_prodcode,
+      pd_detno, pd_whcode, pd_whname, 
+      pd_whid, pd_price, pd_amount, 
+      companyId, updaterId, updateTime, 
+      pd_text1, pd_text2, pd_text3, 
+      pd_text4, pd_text5, pd_num
+      )
+    values ( #{pd_prodid,jdbcType=INTEGER}, #{pd_prodcode,jdbcType=VARCHAR},
+      #{pd_detno,jdbcType=INTEGER}, #{pd_whcode,jdbcType=VARCHAR}, #{pd_whname,jdbcType=VARCHAR}, 
+      #{pd_whid,jdbcType=INTEGER}, #{pd_price,jdbcType=DOUBLE}, #{pd_amount,jdbcType=DOUBLE}, 
+      #{companyId,jdbcType=INTEGER}, #{updaterId,jdbcType=INTEGER}, #{updateTime,jdbcType=TIMESTAMP}, 
+      #{pd_text1,jdbcType=VARCHAR}, #{pd_text2,jdbcType=VARCHAR}, #{pd_text3,jdbcType=VARCHAR}, 
+      #{pd_text4,jdbcType=VARCHAR}, #{pd_text5,jdbcType=VARCHAR}, #{pd_num,jdbcType=DOUBLE}
+      )
+  </insert>
+  <insert id="insertSelective" parameterType="com.usoftchina.saas.document.entities.ProductDetail" >
+      <selectKey resultType="java.lang.Long" keyProperty="id">
+          SELECT LAST_INSERT_ID() AS ID
+      </selectKey>
+    insert into productdetail
+    <trim prefix="(" suffix=")" suffixOverrides="," >
+      <if test="pd_prodid != null" >
+        pd_prodid,
+      </if>
+      <if test="pd_prodcode != null" >
+        pd_prodcode,
+      </if>
+      <if test="pd_detno != null" >
+        pd_detno,
+      </if>
+      <if test="pd_whcode != null" >
+        pd_whcode,
+      </if>
+      <if test="pd_whname != null" >
+        pd_whname,
+      </if>
+      <if test="pd_whid != null" >
+        pd_whid,
+      </if>
+      <if test="pd_price != null" >
+        pd_price,
+      </if>
+      <if test="pd_amount != null" >
+        pd_amount,
+      </if>
+      <if test="companyId != null" >
+        companyId,
+      </if>
+      <if test="updaterId != null" >
+        updaterId,
+      </if>
+      <if test="updateTime != null" >
+        updateTime,
+      </if>
+      <if test="pd_text1 != null" >
+        pd_text1,
+      </if>
+      <if test="pd_text2 != null" >
+        pd_text2,
+      </if>
+      <if test="pd_text3 != null" >
+        pd_text3,
+      </if>
+      <if test="pd_text4 != null" >
+        pd_text4,
+      </if>
+      <if test="pd_text5 != null" >
+        pd_text5,
+      </if>
+      <if test="pd_num != null" >
+        pd_num,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides="," >
+      <if test="pd_prodid != null" >
+        #{pd_prodid,jdbcType=INTEGER},
+      </if>
+      <if test="pd_prodcode != null" >
+        #{pd_prodcode,jdbcType=VARCHAR},
+      </if>
+      <if test="pd_detno != null" >
+        #{pd_detno,jdbcType=INTEGER},
+      </if>
+      <if test="pd_whcode != null" >
+        #{pd_whcode,jdbcType=VARCHAR},
+      </if>
+      <if test="pd_whname != null" >
+        #{pd_whname,jdbcType=VARCHAR},
+      </if>
+      <if test="pd_whid != null" >
+        #{pd_whid,jdbcType=INTEGER},
+      </if>
+      <if test="pd_price != null" >
+        #{pd_price,jdbcType=DOUBLE},
+      </if>
+      <if test="pd_amount != null" >
+        #{pd_amount,jdbcType=DOUBLE},
+      </if>
+      <if test="companyId != null" >
+        #{companyId,jdbcType=INTEGER},
+      </if>
+      <if test="updaterId != null" >
+        #{updaterId,jdbcType=INTEGER},
+      </if>
+      <if test="updateTime != null" >
+        #{updateTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="pd_text1 != null" >
+        #{pd_text1,jdbcType=VARCHAR},
+      </if>
+      <if test="pd_text2 != null" >
+        #{pd_text2,jdbcType=VARCHAR},
+      </if>
+      <if test="pd_text3 != null" >
+        #{pd_text3,jdbcType=VARCHAR},
+      </if>
+      <if test="pd_text4 != null" >
+        #{pd_text4,jdbcType=VARCHAR},
+      </if>
+      <if test="pd_text5 != null" >
+        #{pd_text5,jdbcType=VARCHAR},
+      </if>
+      <if test="pd_num != null" >
+        #{pd_num,jdbcType=DOUBLE},
+      </if>
+    </trim>
+  </insert>
+  <update id="updateByPrimaryKeySelective" parameterType="com.usoftchina.saas.document.entities.ProductDetail" >
+    update productdetail
+    <set >
+      <if test="pd_prodid != null" >
+        pd_prodid = #{pd_prodid,jdbcType=INTEGER},
+      </if>
+      <if test="pd_prodcode != null" >
+        pd_prodcode = #{pd_prodcode,jdbcType=VARCHAR},
+      </if>
+      <if test="pd_detno != null" >
+        pd_detno = #{pd_detno,jdbcType=INTEGER},
+      </if>
+      <if test="pd_whcode != null" >
+        pd_whcode = #{pd_whcode,jdbcType=VARCHAR},
+      </if>
+      <if test="pd_whname != null" >
+        pd_whname = #{pd_whname,jdbcType=VARCHAR},
+      </if>
+      <if test="pd_whid != null" >
+        pd_whid = #{pd_whid,jdbcType=INTEGER},
+      </if>
+      <if test="pd_price != null" >
+        pd_price = #{pd_price,jdbcType=DOUBLE},
+      </if>
+      <if test="pd_amount != null" >
+        pd_amount = #{pd_amount,jdbcType=DOUBLE},
+      </if>
+      <if test="companyId != null" >
+        companyId = #{companyId,jdbcType=INTEGER},
+      </if>
+      <if test="updaterId != null" >
+        updaterId = #{updaterId,jdbcType=INTEGER},
+      </if>
+      <if test="updateTime != null" >
+        updateTime = #{updateTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="pd_text1 != null" >
+        pd_text1 = #{pd_text1,jdbcType=VARCHAR},
+      </if>
+      <if test="pd_text2 != null" >
+        pd_text2 = #{pd_text2,jdbcType=VARCHAR},
+      </if>
+      <if test="pd_text3 != null" >
+        pd_text3 = #{pd_text3,jdbcType=VARCHAR},
+      </if>
+      <if test="pd_text4 != null" >
+        pd_text4 = #{pd_text4,jdbcType=VARCHAR},
+      </if>
+      <if test="pd_text5 != null" >
+        pd_text5 = #{pd_text5,jdbcType=VARCHAR},
+      </if>
+      <if test="pd_num != null" >
+        pd_num = #{pd_num,jdbcType=DOUBLE},
+      </if>
+    </set>
+    where id = #{id,jdbcType=INTEGER}
+  </update>
+  <update id="updateByPrimaryKey" parameterType="com.usoftchina.saas.document.entities.ProductDetail" >
+    update productdetail
+    set pd_prodid = #{pd_prodid,jdbcType=INTEGER},
+      pd_prodcode = #{pd_prodcode,jdbcType=VARCHAR},
+      pd_detno = #{pd_detno,jdbcType=INTEGER},
+      pd_whcode = #{pd_whcode,jdbcType=VARCHAR},
+      pd_whname = #{pd_whname,jdbcType=VARCHAR},
+      pd_whid = #{pd_whid,jdbcType=INTEGER},
+      pd_price = #{pd_price,jdbcType=DOUBLE},
+      pd_amount = #{pd_amount,jdbcType=DOUBLE},
+      companyId = #{companyId,jdbcType=INTEGER},
+      updaterId = #{updaterId,jdbcType=INTEGER},
+      updateTime = #{updateTime,jdbcType=TIMESTAMP},
+      pd_text1 = #{pd_text1,jdbcType=VARCHAR},
+      pd_text2 = #{pd_text2,jdbcType=VARCHAR},
+      pd_text3 = #{pd_text3,jdbcType=VARCHAR},
+      pd_text4 = #{pd_text4,jdbcType=VARCHAR},
+      pd_text5 = #{pd_text5,jdbcType=VARCHAR},
+      pd_num = #{pd_num,jdbcType=DOUBLE}
+    where id = #{id,jdbcType=INTEGER}
+  </update>
+    <insert id="batchInsert" parameterType="java.util.List">
+        insert into productdetail ( pd_prodid, pd_prodcode,
+        pd_detno, pd_whcode, pd_whname,
+        pd_whid, pd_price, pd_amount,
+        companyId, updaterId, updateTime,
+        pd_text1, pd_text2, pd_text3,
+        pd_text4, pd_text5, pd_num
+        )
+        VALUES
+        <foreach collection="list" item="item" index="index" open="" close="" separator=",">
+            values ( #{item.pd_prodid,jdbcType=INTEGER}, #{item.pd_prodcode,jdbcType=VARCHAR},
+            #{item.pd_detno,jdbcType=INTEGER}, #{item.pd_whcode,jdbcType=VARCHAR}, #{item.pd_whname,jdbcType=VARCHAR},
+            #{item.pd_whid,jdbcType=INTEGER}, #{item.pd_price,jdbcType=DOUBLE}, #{item.pd_amount,jdbcType=DOUBLE},
+            #{item.companyId,jdbcType=INTEGER}, #{item.updaterId,jdbcType=INTEGER}, #{item.updateTime,jdbcType=TIMESTAMP},
+            #{item.pd_text1,jdbcType=VARCHAR}, #{item.pd_text2,jdbcType=VARCHAR}, #{item.pd_text3,jdbcType=VARCHAR},
+            #{item.pd_text4,jdbcType=VARCHAR}, #{item.pd_text5,jdbcType=VARCHAR}, #{item.pd_num,jdbcType=DOUBLE}
+            )
+        </foreach>
+    </insert>
+    <update id="batchUpdate" parameterType="com.usoftchina.saas.document.entities.ProductDetail">
+        <foreach collection="list" item="item" index="index" separator=";">
+            update productdetail
+            <set >
+                <if test="pd_prodid != null" >
+                    pd_prodid = #{pd_prodid,jdbcType=INTEGER},
+                </if>
+                <if test="pd_prodcode != null" >
+                    pd_prodcode = #{pd_prodcode,jdbcType=VARCHAR},
+                </if>
+                <if test="pd_detno != null" >
+                    pd_detno = #{pd_detno,jdbcType=INTEGER},
+                </if>
+                <if test="pd_whcode != null" >
+                    pd_whcode = #{pd_whcode,jdbcType=VARCHAR},
+                </if>
+                <if test="pd_whname != null" >
+                    pd_whname = #{pd_whname,jdbcType=VARCHAR},
+                </if>
+                <if test="pd_whid != null" >
+                    pd_whid = #{pd_whid,jdbcType=INTEGER},
+                </if>
+                <if test="pd_price != null" >
+                    pd_price = #{pd_price,jdbcType=DOUBLE},
+                </if>
+                <if test="pd_amount != null" >
+                    pd_amount = #{pd_amount,jdbcType=DOUBLE},
+                </if>
+                <if test="companyId != null" >
+                    companyId = #{companyId,jdbcType=INTEGER},
+                </if>
+                <if test="updaterId != null" >
+                    updaterId = #{updaterId,jdbcType=INTEGER},
+                </if>
+                <if test="updateTime != null" >
+                    updateTime = #{updateTime,jdbcType=TIMESTAMP},
+                </if>
+                <if test="pd_text1 != null" >
+                    pd_text1 = #{pd_text1,jdbcType=VARCHAR},
+                </if>
+                <if test="pd_text2 != null" >
+                    pd_text2 = #{pd_text2,jdbcType=VARCHAR},
+                </if>
+                <if test="pd_text3 != null" >
+                    pd_text3 = #{pd_text3,jdbcType=VARCHAR},
+                </if>
+                <if test="pd_text4 != null" >
+                    pd_text4 = #{pd_text4,jdbcType=VARCHAR},
+                </if>
+                <if test="pd_text5 != null" >
+                    pd_text5 = #{pd_text5,jdbcType=VARCHAR},
+                </if>
+                <if test="pd_num != null" >
+                    pd_num = #{pd_num,jdbcType=DOUBLE},
+                </if>
+            </set>
+            where id = #{id}
+        </foreach>
+    </update>
+    <select id="selectProdidByPrimaryKey" resultType="java.lang.Long">
+        SELECT PD_PRODID FROM PRODUCTDETAIL WHERE PD_ID=#{id}
+    </select>
+    <select id="selectByProdId" resultType="com.usoftchina.saas.document.entities.ProductDetail">
+        SELECT * FROM PRODUCTDETAIL WHERE PD_PRODID=#{id}
+    </select>
+</mapper>

+ 409 - 1
applications/document/document-server/src/main/resources/mapper/ProductMapper.xml

@@ -74,7 +74,7 @@
     </select>
 
     <select id="getProdUnit" resultType="com.usoftchina.saas.commons.dto.ComboDTO">
-        SELECT PR_UNIT as display, pr_unit as value FROM PRODUCT
+        SELECT PR_UNIT as display, pr_unit as value FROM PRODUCT where companyId=#{companyId}
     </select>
     <update id="updateLatestPurchasePrice" parameterType="long">
         update product a set pr_purcprice=(select pd_price from purchasedetail WHERE
@@ -506,5 +506,413 @@
     <select id="getCountFromProdIO" resultType="int">
         SELECT COUNT(*) FROM PRODIODETAIL WHERE PD_PRODID=#{id} AND COMPANYID=#{companyId}
     </select>
+
+    <insert id="saveProdInOut" parameterType="com.usoftchina.saas.document.entities.ProdInOut">
+        <selectKey resultType="java.lang.Long" keyProperty="id">
+            SELECT LAST_INSERT_ID() AS ID
+        </selectKey>
+        insert into prodinout
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+
+            <if test="pi_inoutno != null">
+                pi_inoutno,
+            </if>
+            <if test="pi_class != null">
+                pi_class,
+            </if>
+            <if test="pi_date != null">
+                pi_date,
+            </if>
+            <if test="pi_vendid != null">
+                pi_vendid,
+            </if>
+            <if test="pi_vendcode != null">
+                pi_vendcode,
+            </if>
+            <if test="pi_vendname != null">
+                pi_vendname,
+            </if>
+            <if test="pi_custid != null">
+                pi_custid,
+            </if>
+            <if test="pi_custcode != null">
+                pi_custcode,
+            </if>
+            <if test="pi_custname != null">
+                pi_custname,
+            </if>
+            <if test="pi_puid != null">
+                pi_puid,
+            </if>
+            <if test="pi_pucode != null">
+                pi_pucode,
+            </if>
+            <if test="pi_said != null">
+                pi_said,
+            </if>
+            <if test="pi_sacode != null">
+                pi_sacode,
+            </if>
+            <if test="pi_total != null">
+                pi_total,
+            </if>
+            <if test="pi_recordmanid != null">
+                pi_recordmanid,
+            </if>
+            <if test="pi_recordman != null">
+                pi_recordman,
+            </if>
+            <if test="createTime != null">
+                pi_recorddate,
+            </if>
+            <if test="pi_status != null">
+                pi_status,
+            </if>
+            <if test="pi_statuscode != null">
+                pi_statuscode,
+            </if>
+            <if test="pi_printstatus != null">
+                pi_printstatus,
+            </if>
+            <if test="pi_printstatuscode != null">
+                pi_printstatuscode,
+            </if>
+            <if test="companyId != null">
+                companyid,
+            </if>
+            <if test="updaterId != null">
+                updaterid,
+            </if>
+            <if test="updateTime != null">
+                updatetime,
+            </if>
+            <if test="pi_text1 != null">
+                pi_text1,
+            </if>
+            <if test="pi_text2 != null">
+                pi_text2,
+            </if>
+            <if test="pi_text3 != null">
+                pi_text3,
+            </if>
+            <if test="pi_text4 != null">
+                pi_text4,
+            </if>
+            <if test="pi_text5 != null">
+                pi_text5,
+            </if>
+            <if test="pi_address != null">
+                pi_address,
+            </if>
+            <if test="pi_auditdate != null">
+                pi_auditdate,
+            </if>
+            <if test="pi_auditman != null">
+                pi_auditman,
+            </if>
+            <if test="pi_remark != null">
+                pi_remark,
+            </if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+
+            <if test="pi_inoutno != null">
+                #{pi_inoutno,jdbcType=VARCHAR},
+            </if>
+            <if test="pi_class != null">
+                #{pi_class,jdbcType=VARCHAR},
+            </if>
+            <if test="pi_date != null">
+                #{pi_date,jdbcType=TIMESTAMP},
+            </if>
+            <if test="pi_vendid != null">
+                #{pi_vendid,jdbcType=INTEGER},
+            </if>
+            <if test="pi_vendcode != null">
+                #{pi_vendcode,jdbcType=VARCHAR},
+            </if>
+            <if test="pi_vendname != null">
+                #{pi_vendname,jdbcType=VARCHAR},
+            </if>
+            <if test="pi_custid != null">
+                #{pi_custid,jdbcType=INTEGER},
+            </if>
+            <if test="pi_custcode != null">
+                #{pi_custcode,jdbcType=VARCHAR},
+            </if>
+            <if test="pi_custname != null">
+                #{pi_custname,jdbcType=VARCHAR},
+            </if>
+            <if test="pi_puid != null">
+                #{pi_puid,jdbcType=INTEGER},
+            </if>
+            <if test="pi_pucode != null">
+                #{pi_pucode,jdbcType=VARCHAR},
+            </if>
+            <if test="pi_said != null">
+                #{pi_said,jdbcType=INTEGER},
+            </if>
+            <if test="pi_sacode != null">
+                #{pi_sacode,jdbcType=VARCHAR},
+            </if>
+            <if test="pi_total != null">
+                #{pi_total,jdbcType=DOUBLE},
+            </if>
+            <if test="pi_recordmanid != null">
+                #{pi_recordmanid,jdbcType=INTEGER},
+            </if>
+            <if test="pi_recordman != null">
+                #{pi_recordman,jdbcType=VARCHAR},
+            </if>
+            <if test="createTime != null">
+                #{createTime,jdbcType=TIMESTAMP},
+            </if>
+            <if test="pi_status != null">
+                #{pi_status,jdbcType=VARCHAR},
+            </if>
+            <if test="pi_statuscode != null">
+                #{pi_statuscode,jdbcType=VARCHAR},
+            </if>
+            <if test="pi_printstatus != null">
+                #{pi_printstatus,jdbcType=VARCHAR},
+            </if>
+            <if test="pi_printstatuscode != null">
+                #{pi_printstatuscode,jdbcType=VARCHAR},
+            </if>
+            <if test="companyId != null">
+                #{companyId,jdbcType=INTEGER},
+            </if>
+            <if test="updaterId != null">
+                #{updaterId,jdbcType=INTEGER},
+            </if>
+            <if test="updateTime != null">
+                #{updateTime,jdbcType=TIMESTAMP},
+            </if>
+            <if test="pi_text1 != null">
+                #{pi_text1,jdbcType=VARCHAR},
+            </if>
+            <if test="pi_text2 != null">
+                #{pi_text2,jdbcType=VARCHAR},
+            </if>
+            <if test="pi_text3 != null">
+                #{pi_text3,jdbcType=VARCHAR},
+            </if>
+            <if test="pi_text4 != null">
+                #{pi_text4,jdbcType=VARCHAR},
+            </if>
+            <if test="pi_text5 != null">
+                #{pi_text5,jdbcType=VARCHAR},
+            </if>
+            <if test="pi_address != null">
+                #{pi_address,jdbcType=LONGVARCHAR},
+            </if>
+            <if test="pi_auditdate != null">
+                #{pi_auditdate,jdbcType=TIMESTAMP},
+            </if>
+            <if test="pi_auditman != null">
+                #{pi_auditman,jdbcType=VARCHAR},
+            </if>
+            <if test="pi_remark != null">
+                #{pi_remark,jdbcType=VARCHAR},
+            </if>
+        </trim>
+    </insert>
+
+    <insert id="batchInsertDetail" parameterType="java.util.List" >
+        insert into prodiodetail (pd_piid, pd_inoutno,
+        pd_piclass, pd_pdno, pd_ordercode,
+        pd_orderdetno, pd_prodid, pd_prodcode,
+        pd_unit, pd_inqty, pd_outqty,
+        pd_orderprice, pd_sendprice, pd_price,
+        pd_total, pd_taxrate, pd_netprice,
+        pd_nettotal, pd_whid, pd_whcode,
+        pd_whname, pd_inwhid, pd_inwhcode,
+        pd_inwhname, pd_orderid, pd_sdid,
+        pd_status, companyid, updaterid,
+        updatetime, pd_text1, pd_text2,
+        pd_text3, pd_text4, pd_text5,
+        pd_ym, pd_yqty, pd_ioid,
+        pd_remark) VALUES
+        <foreach collection="list" item="item" index="index" open="" close="" separator=",">
+            (
+            #{item.pd_piid,jdbcType=INTEGER},
+            #{item.pd_inoutno,jdbcType=VARCHAR},
+            #{item.pd_piclass,jdbcType=VARCHAR},
+            #{item.pd_pdno,jdbcType=INTEGER},
+            #{item.pd_ordercode,jdbcType=VARCHAR},
+            #{item.pd_orderdetno,jdbcType=INTEGER},
+            #{item.pd_prodid,jdbcType=INTEGER},
+            #{item.pd_prodcode,jdbcType=VARCHAR},
+            #{item.pd_unit,jdbcType=VARCHAR},
+            #{item.pd_inqty,jdbcType=DOUBLE},
+            #{item.pd_outqty,jdbcType=DOUBLE},
+            #{item.pd_orderprice,jdbcType=DOUBLE},
+            #{item.pd_sendprice,jdbcType=DOUBLE},
+            #{item.pd_price,jdbcType=DOUBLE},
+            #{item.pd_total,jdbcType=DOUBLE},
+            #{item.pd_taxrate,jdbcType=DOUBLE},
+            #{item.pd_netprice,jdbcType=DOUBLE},
+            #{item.pd_nettotal,jdbcType=DOUBLE},
+            #{item.pd_whid,jdbcType=INTEGER},
+            #{item.pd_whcode,jdbcType=VARCHAR},
+            #{item.pd_whname,jdbcType=VARCHAR},
+            #{item.pd_inwhid,jdbcType=INTEGER},
+            #{item.pd_inwhcode,jdbcType=VARCHAR},
+            #{item.pd_inwhname,jdbcType=VARCHAR},
+            #{item.pd_orderid,jdbcType=INTEGER},
+            #{item.pd_sdid,jdbcType=INTEGER},
+            #{item.pd_status,jdbcType=INTEGER},
+            #{item.companyId,jdbcType=INTEGER},
+            #{item.updaterId,jdbcType=INTEGER},
+            #{item.updateTime,jdbcType=TIMESTAMP},
+            #{item.pd_text1,jdbcType=VARCHAR},
+            #{item.pd_text2,jdbcType=VARCHAR},
+            #{item.pd_text3,jdbcType=VARCHAR},
+            #{item.pd_text4,jdbcType=VARCHAR},
+            #{item.pd_text5,jdbcType=VARCHAR},
+            #{item.pd_ym,jdbcType=INTEGER},
+            #{item.pd_yqty,jdbcType=DOUBLE},
+            #{item.pd_remark,jdbcType=LONGVARCHAR},
+            #{item.pd_ioid,jdbcType=INTEGER})
+        </foreach>
+    </insert>
+
+    <update id="batchUpdateDetail" parameterType="com.usoftchina.saas.document.entities.ProdIODetail" >
+        <foreach collection="list" item="item" index="index" open="" close="" separator=";">
+            update prodiodetail <set>
+            <if test="item.pd_piid !=null">
+                pd_piid = #{item.pd_piid},
+            </if>
+            <if test="item.pd_inoutno !=null">
+                pd_inoutno = #{item.pd_inoutno},
+            </if>
+            <if test="item.pd_piclass !=null">
+                pd_piclass = #{item.pd_piclass},
+            </if>
+            <if test="item.pd_pdno !=null">
+                pd_pdno = #{item.pd_pdno},
+            </if>
+            <if test="item.pd_ordercode !=null">
+                pd_ordercode = #{item.pd_ordercode},
+            </if>
+            <if test="item.pd_orderdetno !=null">
+                pd_orderdetno = #{item.pd_orderdetno},
+            </if>
+            <if test="item.pd_prodid !=null">
+                pd_prodid = #{item.pd_prodid},
+            </if>
+            <if test="item.pd_prodcode !=null">
+                pd_prodcode = #{item.pd_prodcode},
+            </if>
+            <if test="item.pd_unit !=null">
+                pd_unit = #{item.pd_unit},
+            </if>
+            <if test="item.pd_inqty !=null">
+                pd_inqty = #{item.pd_inqty},
+            </if>
+            <if test="item.pd_outqty !=null">
+                pd_outqty = #{item.pd_outqty},
+            </if>
+            <if test="item.pd_orderprice !=null">
+                pd_orderprice = #{item.pd_orderprice},
+            </if>
+            <if test="item.pd_sendprice !=null">
+                pd_sendprice = #{item.pd_sendprice},
+            </if>
+            <if test="item.pd_price !=null">
+                pd_price = #{item.pd_price},
+            </if>
+            <if test="item.pd_total !=null">
+                pd_total = #{item.pd_total},
+            </if>
+            <if test="item.pd_taxrate !=null">
+                pd_taxrate = #{item.pd_taxrate},
+            </if>
+            <if test="item.pd_netprice !=null">
+                pd_netprice = #{item.pd_netprice},
+            </if>
+            <if test="item.pd_nettotal !=null">
+                pd_nettotal = #{item.pd_nettotal},
+            </if>
+            <if test="item.pd_whid !=null">
+                pd_whid = #{item.pd_whid},
+            </if>
+            <if test="item.pd_whcode !=null">
+                pd_whcode = #{item.pd_whcode},
+            </if>
+            <if test="item.pd_whname !=null">
+                pd_whname = #{item.pd_whname},
+            </if>
+            <if test="item.pd_inwhid !=null">
+                pd_inwhid = #{item.pd_inwhid},
+            </if>
+            <if test="item.pd_inwhcode !=null">
+                pd_inwhcode = #{item.pd_inwhcode},
+            </if>
+            <if test="item.pd_inwhname !=null">
+                pd_inwhname = #{item.pd_inwhname},
+            </if>
+            <if test="item.pd_orderid !=null">
+                pd_orderid = #{item.pd_orderid},
+            </if>
+            <if test="item.pd_sdid !=null">
+                pd_sdid = #{item.pd_sdid},
+            </if>
+            <if test="item.pd_status !=null">
+                pd_status = #{item.pd_status},
+            </if>
+            <if test="item.pd_remark !=null">
+                pd_remark = #{item.pd_remark},
+            </if>
+            <if test="item.companyId!=null">
+                companyId = #{item.companyId},
+            </if>
+            <if test="item.updaterId!=null">
+                updaterId = #{item.updaterId},
+            </if>
+            <if test="item.updateTime!=null">
+                updateTime = #{item.updateTime},
+            </if>
+            pd_text1 = #{item.pd_text1},
+            pd_text2 = #{item.pd_text2},
+            pd_text3 = #{item.pd_text3},
+            pd_text4 = #{item.pd_text4},
+            pd_text5 = #{item.pd_text5},
+            <if test="item.pd_ym!=null">
+                pd_ym = #{item.pd_ym},
+            </if>
+            <if test="item.pd_yqty!=null">
+                pd_yqty = #{item.pd_yqty},
+            </if>
+        </set>
+            where PD_ID = #{item.id,jdbcType=BIGINT}
+        </foreach>
+    </update>
+    <select id="selectProdIOCode" resultType="java.lang.String">
+        SELECT PI_INOUTNO FROM PRODINOUT
+        <where>
+            <if test="code!=null">
+                AND PI_TEXT1 = #{code}
+            </if>
+            <if test="type!=null">
+                AND PI_CLASS = #{type}
+            </if>
+            <if test="companyId!=null">
+                AND COMPANYID = #{companyId}
+            </if>
+        </where>
+    </select>
+
+    <select id="selectOrderCountByProdCode" resultType="java.lang.Long">
+        SELECT COUNT(*) FROM PRODINOUT LEFT JOIN PRODIODETAIL ON PI_ID=PD_PIID AND PRODINOUT.COMPANYID=PRODIODETAIL.COMPANYID
+        WHERE COMPANYID = #{companyId} AND PD_PRODID = #{id}
+    </select>
+
+    <delete id="deleteProdIOByCode" >
+        DELETE FROM PRODINOUT WHERE PI_TEXT1=#{code} AND COMPANYID = #{companyId}
+    </delete>
+    <delete id="deleteProdIODetailByCode">
+        DELETE FROM PRODIODETAIL WHERE PD_PIID IN (SELECT PI_ID FROM PRODINOUT WHERE PI_TEXT1=#{code} AND PRODINOUT.COMPANYID = #{companyId}) AND PRODIODETAIL.COMPANYID = #{companyId}
+    </delete>
 </mapper>
 

+ 6 - 0
applications/document/document-server/src/main/resources/mapper/VendorMapper.xml

@@ -465,5 +465,11 @@
     <select id="getCodeById" resultType="string">
         SELECT VE_CODE FROM VENDOR WHERE VE_ID = #{id} and COMPANYID = #{companyId}
     </select>
+    <select id="getCountByCode" resultType="int">
+        SELECT COUNT(*) FROM VENDOR WHERE COMPANYID = #{companyId} AND VE_CODE=#{code}
+    </select>
+    <select id="getCountByName" resultType="int">
+        SELECT COUNT(*) FROM VENDOR WHERE COMPANYID = #{companyId} AND VE_NAME=#{name}
+    </select>
 </mapper>
 

+ 15 - 0
applications/document/document-server/src/main/resources/mapper/WarehouseMapper.xml

@@ -344,6 +344,21 @@
         </where>
     </select>
 
+    <select id="selectCountByCode" resultType="int">
+        SELECT COUNT(*) FROM warehouse
+        <where>
+            <if test="name!=null">
+                and wh_code=#{code}
+            </if>
+            <if test="companyId!=0 and companyId!=null">
+                and COMPANYID=#{companyId}
+            </if>
+            <if test="id!=0 and id!=null">
+                and wh_id!=#{id}
+            </if>
+        </where>
+    </select>
+
     <select id="selectCodeById" resultType="string" parameterType="long">
         select wh_code from warehouse where wh_id=#{id}
     </select>