Browse Source

销售出货转退货优化:ri'z

rainco 7 years ago
parent
commit
e408b38c41

+ 7 - 1
applications/commons/commons-dto/src/main/java/com/usoftchina/saas/commons/exception/BizExceptionCode.java

@@ -22,12 +22,17 @@ public enum BizExceptionCode implements BaseExceptionCode {
     CODE_EXISTS(79200, "单据编号已存在"),
     BIZ_CLOSE(79301, "只能关闭已审核的单据"),
     BIZ_OPEN(79302, "只能打开已关闭的单据"),
+    BIZ_AUDITED(79303,"只能审核未审核的单据"),
+    BIZ_UNAUDITED(79304,"只能反审核已审核的单据"),
+    BIZ_DELETE(79305,"只能删除未审核的单据"),
+    NO_OPRATIONDATA(79400,"无可操作单据"),
     BOM_SAVE(79401, "产品编号+版本号已存在"),
     REPEAT_NAME(79501, "名称重复"),
     NO_DATA(79998, "未找到数据"),
     ILLEGAL_ID(79999, "id不正确"),
 
 
+
     //采购
 
     //销售
@@ -36,7 +41,8 @@ public enum BizExceptionCode implements BaseExceptionCode {
     SALE_YQTYBEYONDQTY(72001, "明细行已转数量大于数量"),
     SALE_NULL_BILL(72002, "单据不存在或者明细为空"),
     SALEOUT_ALL_TURNIN(72003, "该销售出货单已全部转退货,无法转销售退货单"),
-    SALEOUT_POSTSTATUS_ERROR(72004,"单据状态异常,无法反审核"),
+    SALEOUT_POSTSTATUS_ERROR(72004,"当前单据状态无法进行此操作。"),
+    SALEOUT_POST_ERROR(72005,""),
     //资金
 
     //库存

+ 2 - 1
applications/sale/sale-dto/src/main/java/com/usoftchina/saas/sale/dto/ProdInOutDTO.java

@@ -1,6 +1,7 @@
 package com.usoftchina.saas.sale.dto;
 
 
+import com.usoftchina.saas.base.dto.CommonBaseDTO;
 import io.swagger.annotations.ApiModel;
 import lombok.Data;
 
@@ -12,7 +13,7 @@ import java.util.Date;
  * 2018-10-23
  */
 @Data
-public class ProdInOutDTO implements Serializable {
+public class ProdInOutDTO extends CommonBaseDTO implements Serializable {
 
     protected Long id;
 

+ 2 - 2
applications/sale/sale-dto/src/main/java/com/usoftchina/saas/sale/dto/ProdInOutListDTO.java

@@ -1,6 +1,6 @@
 package com.usoftchina.saas.sale.dto;
 
-import com.usoftchina.saas.base.entity.CommonBaseEntity;
+import com.usoftchina.saas.base.dto.CommonBaseDTO;
 import lombok.Data;
 
 import java.io.Serializable;
@@ -11,7 +11,7 @@ import java.util.Date;
  * 2018-10-23
  */
 @Data
-public class ProdInOutListDTO extends CommonBaseEntity implements Serializable {
+public class ProdInOutListDTO extends CommonBaseDTO implements Serializable {
 
     private String pi_inoutno;
 

+ 69 - 39
applications/sale/sale-server/src/main/java/com/usoftchina/saas/sale/controller/ProdInOutController.java

@@ -27,7 +27,6 @@ public class ProdInOutController {
     @Autowired
     ProdInOutService prodInOutService;
 
-
     /**
      * 出入库订单列表
      *
@@ -65,79 +64,77 @@ public class ProdInOutController {
     }
 
     /**
-     * 出入库单删除
+     * 出入库单审批
      *
-     * @param id
+     * @param formData
      * @return
      */
-    @GetMapping("/delete/{id}")
-    public Result delete(@PathVariable("id") Long id) {
-        prodInOutService.delete(id);
-        return Result.success();
+    @PostMapping("/audit")
+    public Result audit(@RequestBody ProdInOutFormDTO formData) {
+        DocBaseDTO auditDTO = prodInOutService.audit(formData);
+        return Result.success(auditDTO);
     }
 
     /**
-     * 出入库单明细删除
+     * 出入库单批量审核/反审核
      *
-     * @param id
+     * @param baseDTOs
      * @return
      */
-    @GetMapping("/deleteItem/{id}")
-    public Result deleteItem(@PathVariable("id") Long id) {
-        prodInOutService.deleteItem(id);
-        return Result.success();
+    @PostMapping("/batchAudit")
+    public Result batchAudit(@RequestBody BatchDealBaseDTO baseDTOs) {
+        String res = prodInOutService.batchAudit(baseDTOs);
+        return Result.success(res);
     }
 
-
     /**
      * 出入库单审批
      *
-     * @param formData
+     * @param id
      * @return
      */
-    @PostMapping("/audit")
-    public Result audit(@RequestBody ProdInOutFormDTO formData) {
-        DocBaseDTO audit = prodInOutService.audit(formData);
-        return Result.success(audit);
+    @PostMapping("/unAudit/{id}")
+    public Result unAudit(@PathVariable("id") Long id) {
+        prodInOutService.unAudit(id);
+        return Result.success();
     }
 
     /**
-     * 出入库单审批
+     * 出入库单批量反审核
      *
-     * @param id
+     * @param baseDTOs
      * @return
      */
-    @GetMapping("/unAudit/{id}")
-    public Result unAudit(@PathVariable("id") Long id) {
-        prodInOutService.unAudit(id);
-        return Result.success();
+    @PostMapping("/batchUnAudit")
+    public Result batchUnAudit(@RequestBody BatchDealBaseDTO baseDTOs) {
+        String res = prodInOutService.batchUnAudit(baseDTOs);
+        return Result.success(res);
     }
 
     /**
-     * 出入库单批量审核/反审核
+     * 出入库单删除
      *
-     * @param baseDTOs
+     * @param id
      * @return
      */
-    @PostMapping("/batchAudit")
-    public Result batchAudit(@RequestBody BatchDealBaseDTO baseDTOs) {
-        prodInOutService.batchAudit(baseDTOs);
+    @PostMapping("/delete/{id}")
+    public Result delete(@PathVariable("id") Long id) {
+        prodInOutService.delete(id);
         return Result.success();
     }
 
     /**
-     * 出入库单批量反审核
+     * 出入库单明细删除
      *
-     * @param baseDTOs
+     * @param id
      * @return
      */
-    @PostMapping("/batchUnAudit")
-    public Result batchUnAudit(@RequestBody BatchDealBaseDTO baseDTOs) {
-        prodInOutService.batchAudit(baseDTOs);
+    @PostMapping("/deleteItem/{id}")
+    public Result deleteItem(@PathVariable("id") Long id) {
+        prodInOutService.deleteItem(id);
         return Result.success();
     }
 
-
     /**
      * 出入库单批量删除
      *
@@ -146,17 +143,50 @@ public class ProdInOutController {
      */
     @PostMapping("/batchDelete")
     public Result batchDelete(@RequestBody BatchDealBaseDTO baseDTOs) {
-        prodInOutService.batchDelete(baseDTOs);
-        return Result.success();
+        String deleteDto = prodInOutService.batchDelete(baseDTOs);
+        return Result.success(deleteDto);
     }
 
-    @GetMapping("/turnProdIn/{id}")
+    @PostMapping("/turnProdIn/{id}")
     public Result turnProdin(@PathVariable("id") Long id){
         prodInOutService.turnProdin(id);
         return Result.success();
     };
 
+    @PostMapping("/close/{id}")
+    public Result close(@PathVariable(value = "id") long id) {
+        prodInOutService.close(id);
+        return Result.success();
+    }
 
+    @PostMapping("/open/{id}")
+    public Result open(@PathVariable(value = "id") long id) {
+        prodInOutService.open(id);
+        return Result.success();
+    }
 
+    /**
+     * 出入库单批量关闭
+     *
+     * @param baseDTOs
+     * @return
+     */
+    @PostMapping("/batchClose")
+    public Result batchClose(@RequestBody BatchDealBaseDTO baseDTOs) {
+        String res = prodInOutService.batchClose(baseDTOs);
+        return Result.success(res);
+    }
+
+    /**
+     * 出入库单批量开启
+     *
+     * @param baseDTOs
+     * @return
+     */
+    @PostMapping("/batchOpen")
+    public Result batchOpen(@RequestBody BatchDealBaseDTO baseDTOs) {
+        String res = prodInOutService.batchOpen(baseDTOs);
+        return Result.success(res);
+    }
 
 }

+ 8 - 8
applications/sale/sale-server/src/main/java/com/usoftchina/saas/sale/service/ProdInOutService.java

@@ -48,7 +48,7 @@ public interface ProdInOutService extends CommonBaseService<ProdInOutMapper, Pro
      * 批量删除出入库单
      * @param baseDTOs
      */
-    void batchDelete(BatchDealBaseDTO baseDTOs);
+    String batchDelete(BatchDealBaseDTO baseDTOs);
 
     /**
      * 删除明细
@@ -69,43 +69,43 @@ public interface ProdInOutService extends CommonBaseService<ProdInOutMapper, Pro
      * @param baseDTOs
      * @return
      */
-    void batchAudit(BatchDealBaseDTO baseDTOs);
+    String batchAudit(BatchDealBaseDTO baseDTOs);
 
     /**
      * 反审核出入库单
      * @param id
      */
-    Result unAudit(Long id);
+    void unAudit(Long id);
 
     /**
      * 批量反审核出入库单
      * @param baseDTOs
      */
-    void batchUnAudit(BatchDealBaseDTO baseDTOs);
+    String batchUnAudit(BatchDealBaseDTO baseDTOs);
 
     /**
      * 启用出入库单
      * @param id
      */
-    Result open(Long id);
+    DocBaseDTO open(Long id);
 
     /**
      * 关闭出入库单
      * @param
      */
-    Result close(Long id);
+    DocBaseDTO close(Long id);
 
     /**
      * 批量启用出入库单
      * @param baseDTOs
      */
-    void batchOpen(BatchDealBaseDTO baseDTOs);
+    String batchOpen(BatchDealBaseDTO baseDTOs);
 
     /**
      * 批量关闭出入库单
      * @param baseDTOs
      */
-    void batchClose(BatchDealBaseDTO baseDTOs);
+    String batchClose(BatchDealBaseDTO baseDTOs);
 
     /**
      * 获取列表信息

+ 117 - 142
applications/sale/sale-server/src/main/java/com/usoftchina/saas/sale/service/impl/ProdInOutServiceImpl.java

@@ -167,8 +167,13 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
     public void delete(Long id) {
         singleDelete(id);
     }
+
     private void singleDelete(Long id) {
         ProdInOut prodInOut = checkAndReturnOrder(id);
+        String pi_statuscode = prodInOut.getPi_statuscode();
+        if(StringUtils.isEmpty(pi_statuscode)||(!StringUtils.isEmpty(pi_statuscode)&&!pi_statuscode.equals(Status.UNAUDITED.name()))){
+            throw  new BizException(BizExceptionCode.BIZ_DELETE);
+        };
         //从表删除
         prodIODetailMapper.deleteByForeignKey(id);
         //主表删除
@@ -180,6 +185,36 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
        messageLogService.deleteDetail(docBaseDTO);
     }
 
+    @Override
+    public Integer deleteItem(Long id) {
+        ProdIODetail prodIODetail = prodIODetailMapper.selectByPrimaryKey(id);
+        ProdInOut prodInOut = checkAndReturnOrder(prodIODetail.getPd_piid());
+        Integer num = prodIODetailMapper.deleteByPrimaryKey(id);
+        //更新已转数
+        updateYqty(prodInOut);
+        DocBaseDTO docBaseDTO = getBaseDTOById(id,prodInOut.getPi_class(),prodInOut.getPi_inoutno());
+        //日志
+        messageLogService.deleteDetail(docBaseDTO);
+        return num;
+    }
+
+    @Override
+    public String batchDelete(BatchDealBaseDTO baseDTOs) {
+        if (null == baseDTOs || null == baseDTOs.getBaseDTOs() ||
+                baseDTOs.getBaseDTOs().size() == 0) {
+            return "无可删除的单据。";
+        }
+        StringBuffer errorMsg = new StringBuffer();
+        for (DocBaseDTO base : baseDTOs.getBaseDTOs()) {
+            try{
+                singleDelete(base.getId());
+            }catch (Exception e){
+                errorMsg.append("编号:" + base.getCode() + "处理失败," + e.getMessage());
+            }
+        }
+        return errorMsg.toString();
+    }
+
     @Override
     @Transactional
     public DocBaseDTO audit(ProdInOutFormDTO formData) {
@@ -187,21 +222,22 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
         DocBaseDTO baseDTO = new DocBaseDTO();
         if (null != formData) {
             id = formData.getMain().getId();
-            if (StringUtils.isEmpty(id)) {
+            if (StringUtils.isEmpty(id) || "0".equals(String.valueOf(id))) {
                 baseDTO = saveFormData(formData);
                 id = baseDTO.getId();
             }
-            String res = singleAudit(formData.getMain());
-            if(StringUtils.hasText(res)){
-                throw new BizException(501,res);
-            }
+            singleAudit( formData.getMain());
         }
         baseDTO.setId(id);
         return baseDTO;
     }
-    private String singleAudit(ProdInOutDTO prodInOutDTO) {
+    private void singleAudit(ProdInOutDTO prodInOutDTO) {
         String pi_class= prodInOutDTO.getPi_class();
         String pi_inoutno = prodInOutDTO.getPi_inoutno();
+        String pi_statuscode = prodInOutDTO.getPi_statuscode();
+        if(StringUtils.isEmpty(pi_statuscode)||(!StringUtils.isEmpty(pi_statuscode)&&!pi_statuscode.equals(Status.UNAUDITED.name()))){
+            throw  new BizException(BizExceptionCode.BIZ_AUDITED);
+        };
         Map<String, Object> map = new HashMap<String, Object>();
         map.put("inoutNo",pi_inoutno);
         map.put("class", pi_class);
@@ -210,35 +246,51 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
         map.put("result","");
         Result res = warehouseApi.post(map);
         Object result =  res.getData();
+        System.out.println("result:"+result);
         if(!StringUtils.isEmpty(result)){
-            return result.toString();
+            throw new BizException(BizExceptionCode.SALEOUT_POST_ERROR.getCode(),result.toString());
         }else{
             //记录日志
             DocBaseDTO docBaseDTO = getBaseDTOById(prodInOutDTO.getId(),pi_class,pi_inoutno);
             //日志
             messageLogService.audit(docBaseDTO);
-            return "";
         }
     }
+    @Override
+    public String batchAudit(BatchDealBaseDTO baseDTOs) {
+        if (null == baseDTOs || null == baseDTOs.getBaseDTOs() ||
+                baseDTOs.getBaseDTOs().size() == 0) {
+            return "没有可审核单据。";
+        }
+        StringBuffer errorMsg = new StringBuffer();
+        for (DocBaseDTO base : baseDTOs.getBaseDTOs()) {
+            try{
+                Long id =  base.getId();
+                ProdInOut prodInOut = prodInOutMapper.selectByPrimaryKey(id);
+                ProdInOutDTO prodInOutDTO = BeanMapper.map(prodInOut,ProdInOutDTO.class);
+                singleAudit(prodInOutDTO);
+            }catch (Exception e){
+                errorMsg.append("编号:" + base.getCode() + "处理失败," + e.getMessage());
+            }
+        }
+        return errorMsg.toString();
+    }
 
     @Override
-    public Result unAudit(Long id) {
+    public void unAudit(Long id) {
+        DocBaseDTO baseDTO = new DocBaseDTO();
         ProdInOut prodInOut = checkAndReturnOrder(id);
-        String code = prodInOutMapper.validateUnAudit(id);
-        if (!prodInOut.getPi_statuscode().equals(Status.AUDITED.name())) {
-            throw new BizException(BizExceptionCode.SALE_NULL_BILL);
-        }
         ProdInOutDTO prodInOutDTO = BeanMapper.map(prodInOut, ProdInOutDTO.class);
-        String res =  singleUnAudit(prodInOutDTO);
-        if(res!=null){
-            return Result.error(res);
-        }else{
-            return Result.success();
-        }
+        singleUnAudit(prodInOutDTO);
     }
-    private String singleUnAudit(ProdInOutDTO prodInOutDTO) {
+
+    private void singleUnAudit(ProdInOutDTO prodInOutDTO) {
         String pi_class = prodInOutDTO.getPi_class();
         String  pi_inoutno = prodInOutDTO.getPi_inoutno();
+        String pi_statuscode = prodInOutDTO.getPi_statuscode();
+        if(StringUtils.isEmpty(pi_statuscode)||(!StringUtils.isEmpty(pi_statuscode)&&!pi_statuscode.equals(Status.AUDITED.name()))){
+            throw  new BizException(BizExceptionCode.BIZ_UNAUDITED);
+        };
         Map<String, Object> map = new HashMap<String, Object>();
         map.put("inoutNo", pi_inoutno);
         map.put("class", pi_class);
@@ -248,90 +300,33 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
         Result res = warehouseApi.unPost(map);
         Object result =  res.getData();
         if(!StringUtils.isEmpty(result)){
-            return result.toString();
-        }else{
-            //更新状态为未审核
-            ProdInOut prodInOut = BeanMapper.map(prodInOutDTO, ProdInOut.class);
-            prodInOut.setPi_statuscode(Status.UNAUDITED.name());
-            prodInOut.setPi_status(Status.UNAUDITED.getDisplay());
-            prodInOut.setUpdateTime(new Date());
-            prodInOut.setUpdaterId(BaseContextHolder.getUserId());
-            getMapper().updateByPrimaryKeySelective(prodInOut);
+            throw new BizException(BizExceptionCode.SALEOUT_POST_ERROR.getCode(),result.toString());
+        }else {
             //记录日志
             DocBaseDTO docBaseDTO = getBaseDTOById(prodInOutDTO.getId(),pi_class,pi_inoutno);
             //日志
             messageLogService.unAudit(docBaseDTO);
-            return "";
         }
     }
 
     @Override
-    public void batchAudit(BatchDealBaseDTO baseDTOs) {
+    public String batchUnAudit(BatchDealBaseDTO baseDTOs) {
         if (null == baseDTOs || null == baseDTOs.getBaseDTOs() ||
                 baseDTOs.getBaseDTOs().size() == 0) {
-            return;
+            return "无可反审核单据。";
         }
-        String validate = prodInOutMapper.validateAudit(baseDTOs.getBaseDTOs());
-        if (!StringUtils.isEmpty(validate)) {
-            throw new BizException(500, "存在已审核单据,单据编号:" + validate);
-        }
-        String error = null;
+        StringBuffer errorMsg = new StringBuffer();
         for (DocBaseDTO base : baseDTOs.getBaseDTOs()) {
-            Long id =  base.getId();
-            ProdInOut prodInOut = prodInOutMapper.selectByPrimaryKey(id);
-            ProdInOutDTO prodInOutDTO = BeanMapper.map(prodInOut,ProdInOutDTO.class);
-            error+=singleAudit(prodInOutDTO);
-        }
-        if(!StringUtils.isEmpty(error)){
-            new BizException(501,error);
-        }
-    }
-
-    @Override
-    public void batchUnAudit(BatchDealBaseDTO baseDTOs) {
-        if (null == baseDTOs || null == baseDTOs.getBaseDTOs() ||
-                baseDTOs.getBaseDTOs().size() == 0) {
-            return;
-        }
-
-        String msg = prodInOutMapper.validateBatchUnAudit(baseDTOs.getBaseDTOs());
-        if (null != msg) {
-            throw new BizException(500, "存在未审核单据,单据编号:" + msg);
-        }
-        String error = null;
-        for (DocBaseDTO base : baseDTOs.getBaseDTOs()) {
-            Long id =  base.getId();
-            ProdInOut prodInOut = prodInOutMapper.selectByPrimaryKey(id);
-            ProdInOutDTO prodInOutDTO = BeanMapper.map(prodInOut,ProdInOutDTO.class);
-            error+=singleUnAudit(prodInOutDTO);
-        }
-        if(!StringUtils.isEmpty(error)){
-            throw new BizException(501,error);
-        }
-    }
-
-    @Override
-    public Integer deleteItem(Long id) {
-        ProdIODetail prodIODetail = prodIODetailMapper.selectByPrimaryKey(id);
-        ProdInOut prodInOut = checkAndReturnOrder(prodIODetail.getPd_piid());
-        Integer num = prodIODetailMapper.deleteByPrimaryKey(id);
-        //更新已转数
-        updateYqty(prodInOut);
-        DocBaseDTO docBaseDTO = getBaseDTOById(id,prodInOut.getPi_class(),prodInOut.getPi_inoutno());
-        //日志
-       messageLogService.deleteDetail(docBaseDTO);
-        return num;
-    }
-
-    @Override
-    public void batchDelete(BatchDealBaseDTO baseDTOs) {
-        if (null == baseDTOs || null == baseDTOs.getBaseDTOs() ||
-                baseDTOs.getBaseDTOs().size() == 0) {
-            return;
-        }
-        for (DocBaseDTO base : baseDTOs.getBaseDTOs()) {
-            singleDelete(base.getId());
+            try {
+                Long id =  base.getId();
+                ProdInOut prodInOut = prodInOutMapper.selectByPrimaryKey(id);
+                ProdInOutDTO prodInOutDTO = BeanMapper.map(prodInOut,ProdInOutDTO.class);
+                singleUnAudit(prodInOutDTO);
+            }catch (Exception e){
+                errorMsg.append("编号:" + base.getCode() + "处理失败," + e.getMessage());
+            }
         }
+        return errorMsg.toString();
     }
 
     @Override
@@ -378,7 +373,7 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
 
         //检查转单状态
         String statuscode = sourcePi.getPi_statuscode();
-        if(!Status.UNAUDITED.name().equals(statuscode)){
+        if(!Status.AUDITED.name().equals(statuscode)){
             throw new BizException(BizExceptionCode.SALEOUT_POSTSTATUS_ERROR);
         }
 
@@ -464,20 +459,12 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
 
     @Override
     @Transactional
-    public Result close(Long id) {
-        String res = singleClose(id);
-        if(StringUtils.hasText(res)){
-            return Result.error(res);
-        }else{
-            return Result.success();
-        }
-    }
-
-    private String singleClose(Long id){
+    public DocBaseDTO close(Long id) {
         ProdInOut prodInOut = checkAndReturnOrder(id);
+        String pi_statuscode = prodInOut.getPi_statuscode();
         //状态校验
-        if(Status.CLOSE.name().equals(prodInOut.getPi_status())){
-            return BizExceptionCode.BIZ_CLOSE.getMessage();
+        if(StringUtils.isEmpty(pi_statuscode)||(!StringUtils.isEmpty(pi_statuscode)&&!pi_statuscode.equals(Status.AUDITED.name()))){
+           throw  new BizException(BizExceptionCode.BIZ_CLOSE);
         }
         //更新状态
         prodInOut.setPi_status(Status.CLOSE.getDisplay());
@@ -486,72 +473,60 @@ public class ProdInOutServiceImpl extends CommonBaseServiceImpl<ProdInOutMapper,
         prodInOutMapper.updateByPrimaryKeySelective(prodInOut);
         //记录日志
         DocBaseDTO docBaseDTO = getBaseDTOById(prodInOut.getId(),prodInOut.getPi_class(),prodInOut.getPi_inoutno());
-       messageLogService.close(docBaseDTO);
-        return "";
+        messageLogService.close(docBaseDTO);
+        return docBaseDTO;
     }
 
+
     @Override
-    public  void batchClose(BatchDealBaseDTO baseDTOs){
+    public  String batchClose(BatchDealBaseDTO baseDTOs){
         if (null == baseDTOs || null == baseDTOs.getBaseDTOs() ||
                 baseDTOs.getBaseDTOs().size() == 0) {
-            return;
-        }
-        String validate = prodInOutMapper.validateBatchClose(baseDTOs.getBaseDTOs());
-        if (!StringUtils.isEmpty(validate)) {
-            throw new BizException(503, "存在非已审核单据,单据编号:" + validate);
+            return "没有可关闭单据。";
         }
-        String error = null;
+        StringBuffer errorMsg = new StringBuffer();
         for (DocBaseDTO base : baseDTOs.getBaseDTOs()) {
-            error+=singleClose(base.getId());
-        }
-        if(!StringUtils.isEmpty(error)){
-            new BizException(501,error);
+            try{
+                close(base.getId());
+            }catch (Exception e){
+                errorMsg.append("编号:" + base.getCode() + "处理失败," + e.getMessage());
+            }
         }
+        return errorMsg.toString();
     }
 
     @Override
     @Transactional
-    public Result open(Long id){
-        String res = singleOpen(id);
-        if(StringUtils.hasText(res)){
-            return Result.error(res);
-        }else{
-            return Result.success();
-        }
-    }
-
-    private String singleOpen(Long id){
+    public DocBaseDTO open(Long id){
         ProdInOut prodInOut = checkAndReturnOrder(id);
         String pi_statuscode = prodInOut.getPi_statuscode();
-        if(!StringUtils.isEmpty(pi_statuscode)&&!pi_statuscode.equals(Status.CLOSE.getDisplay())){
-            return BizExceptionCode.BIZ_OPEN.getMessage();
+        if(StringUtils.isEmpty(pi_statuscode)||(!StringUtils.isEmpty(pi_statuscode)&&!pi_statuscode.equals(Status.CLOSE.name()))){
+            throw  new BizException(BizExceptionCode.BIZ_OPEN);
         };
         prodInOut.setPi_status(Status.AUDITED.getDisplay());
-        prodInOut.setPi_statuscode(Status.AUDITED.getDisplay());
+        prodInOut.setPi_statuscode(Status.AUDITED.name());
         prodInOutMapper.updateByPrimaryKeySelective(prodInOut);
         //记录日志
         DocBaseDTO docBaseDTO = getBaseDTOById(prodInOut.getId(),prodInOut.getPi_class(),prodInOut.getPi_inoutno());
         messageLogService.open(docBaseDTO);
-        return "";
+        return docBaseDTO;
     }
 
     @Override
-    public void batchOpen(BatchDealBaseDTO baseDTOs){
+    public String batchOpen(BatchDealBaseDTO baseDTOs){
         if (null == baseDTOs || null == baseDTOs.getBaseDTOs() ||
                 baseDTOs.getBaseDTOs().size() == 0) {
-            return;
-        }
-        String validate = prodInOutMapper.validateBatchOpen(baseDTOs.getBaseDTOs());
-        if (!StringUtils.isEmpty(validate)) {
-            throw new BizException(503, "存在非已关闭单据,单据编号:" + validate);
+            return "没有可开启单据。";
         }
-        String error = null;
+        StringBuffer errorMsg = new StringBuffer();
         for (DocBaseDTO base : baseDTOs.getBaseDTOs()) {
-            error+=singleOpen(base.getId());
-        }
-        if(!StringUtils.isEmpty(error)){
-            new BizException(501,error);
+            try{
+                open(base.getId());
+            }catch (Exception e){
+                errorMsg.append("编号:" + base.getCode() + "处理失败," + e.getMessage());
+            }
         }
+        return errorMsg.toString();
     }
 
     /**

+ 94 - 94
applications/sale/sale-server/src/main/java/com/usoftchina/saas/sale/service/impl/SaleServiceImpl.java

@@ -185,6 +185,18 @@ public class SaleServiceImpl implements SaleService{
         singleDelete(id);
     }
 
+    @Override
+    public void batchDelete(BatchDealBaseDTO baseDTOs) {
+        if (null == baseDTOs || null == baseDTOs.getBaseDTOs() ||
+                baseDTOs.getBaseDTOs().size() == 0) {
+            return;
+        }
+
+        for (DocBaseDTO base : baseDTOs.getBaseDTOs()) {
+            singleDelete(base.getId());
+        }
+    }
+
     @Override
     public int deleteDetail(Long id) {
         Integer num = saledetailMapper.deleteByPrimaryKey(id);
@@ -210,16 +222,25 @@ public class SaleServiceImpl implements SaleService{
         return baseDTO;
     }
 
-    @Override
-    public void unAudit(Long id) {
-        if (null == id) {
-            return;
-        }
-        String code = saleMapper.validateUnAudit(id);
-        if (null != code) {
-            throw new BizException(BizExceptionCode.SALE_NULL_BILL);
-        }
-        singleUnAudit(id);
+    private void singleAudit(Long id) {
+        Sale sale = new Sale();
+        //生成更新对象
+        sale.setId(id);
+        sale.setSa_status(Status.AUDITED.getDisplay());
+        sale.setSa_statuscode(Status.AUDITED.name());
+        sale.setUpdateTime(new Date());
+        sale.setUpdaterId(BaseContextHolder.getUserId());
+        //更新存在字段
+        saleMapper.updateByPrimaryKeySelective(sale);
+        //更新销售金额
+        updateTotal(id);
+        //更新从表总额
+        updateTotalAndNetPrice(id);
+        //更新从表不含税金额
+        updateNetTotal(id);
+        DocBaseDTO docBaseDTO = getBaseDTOById(id);
+        //日志
+        messageLogService.audit(docBaseDTO);
     }
 
     @Override
@@ -239,36 +260,46 @@ public class SaleServiceImpl implements SaleService{
     }
 
     @Override
-    public void batchDelete(BatchDealBaseDTO baseDTOs) {
-        if (null == baseDTOs || null == baseDTOs.getBaseDTOs() ||
-                baseDTOs.getBaseDTOs().size() == 0) {
+    public void unAudit(Long id) {
+        if (null == id) {
             return;
         }
-
-        for (DocBaseDTO base : baseDTOs.getBaseDTOs()) {
-            singleDelete(base.getId());
+        String code = saleMapper.validateUnAudit(id);
+        if (null != code) {
+            throw new BizException(BizExceptionCode.SALE_NULL_BILL);
         }
+        singleUnAudit(id);
     }
 
-    private void singleAudit(Long id) {
+    private void singleUnAudit(Long id) {
         Sale sale = new Sale();
         //生成更新对象
         sale.setId(id);
-        sale.setSa_status(Status.AUDITED.getDisplay());
-        sale.setSa_statuscode(Status.AUDITED.name());
+        sale.setSa_status(Status.UNAUDITED.getDisplay());
+        sale.setSa_statuscode(Status.UNAUDITED.name());
         sale.setUpdateTime(new Date());
         sale.setUpdaterId(BaseContextHolder.getUserId());
         //更新存在字段
         saleMapper.updateByPrimaryKeySelective(sale);
-        //更新销售金额
-        updateTotal(id);
-        //更新从表总额
-        updateTotalAndNetPrice(id);
-        //更新从表不含税金额
-        updateNetTotal(id);
         DocBaseDTO docBaseDTO = getBaseDTOById(id);
         //日志
-        messageLogService.audit(docBaseDTO);
+        messageLogService.unAudit(docBaseDTO);
+    }
+
+    @Override
+    public void batchUnAudit(BatchDealBaseDTO baseDTOs) {
+        if (null == baseDTOs || null == baseDTOs.getBaseDTOs() ||
+                baseDTOs.getBaseDTOs().size() == 0) {
+            return;
+        }
+
+        String msg = saleMapper.validateBatchUnAudit(baseDTOs.getBaseDTOs());
+        if (null != msg) {
+            throw new BizException(500, "存在未审核单据,单据编号:" + msg);
+        }
+        for (DocBaseDTO base : baseDTOs.getBaseDTOs()) {
+            singleUnAudit(base.getId());
+        }
     }
 
     private void singleDelete(Long id) {
@@ -283,7 +314,6 @@ public class SaleServiceImpl implements SaleService{
         }
     }
 
-
     private List<SaleList> getListByMode(ListReqDTO req) {
         List<SaleList> list = null;
         Long companyId = BaseContextHolder.getCompanyId();
@@ -299,58 +329,6 @@ public class SaleServiceImpl implements SaleService{
         return list;
     }
 
-    /**
-     * @Description: 检验获取并更新单号
-     * @Param: [code, id]
-     * @return: java.lang.String
-     * @Author: guq
-     * @Date: 2018/10/19
-     */
-    private String pushMaxnubmer(String code, Long id) {
-        if (null == code) {
-            throw new BizException(BizExceptionCode.NULL_CODE);
-        }
-        Long companyId = BaseContextHolder.getCompanyId();
-        Integer count = "0".equals(String.valueOf(id)) ? saleMapper.validateCodeWhenInsert(code, companyId) :
-                saleMapper.validateCodeWhenUpdate(code, id, companyId);
-        return maxnumberService.pushMaxnubmer(count, code, BillCodeSeq.SALE.getCaller()).getData();
-    }
-
-    /**
-     * @Description
-     * @Param: [id]
-     * @return: com.usoftchina.saas.commons.dto.DocBaseDTO
-     * @Author: guq
-     * @Date: 2018/10/22
-     */
-    private DocBaseDTO getBaseDTOById(Long id) {
-        if (null == id) {
-            return null;
-        }
-        String code = saleMapper.selectCodeById(id);
-        DocBaseDTO baseDTO = new DocBaseDTO();
-        baseDTO.setId(id);
-        baseDTO.setCode(code);
-        baseDTO.setName("Sale");
-        return baseDTO;
-    }
-
-    @Override
-    public void batchUnAudit(BatchDealBaseDTO baseDTOs) {
-        if (null == baseDTOs || null == baseDTOs.getBaseDTOs() ||
-                baseDTOs.getBaseDTOs().size() == 0) {
-            return;
-        }
-
-        String msg = saleMapper.validateBatchUnAudit(baseDTOs.getBaseDTOs());
-        if (null != msg) {
-            throw new BizException(500, "存在未审核单据,单据编号:" + msg);
-        }
-        for (DocBaseDTO base : baseDTOs.getBaseDTOs()) {
-            singleUnAudit(base.getId());
-        }
-    }
-
     @Override
     public void close(long id) {
         Sale sale = new Sale();
@@ -486,21 +464,6 @@ public class SaleServiceImpl implements SaleService{
          saleMapper.updateByPrimaryKeySelective(sale);
     }
 
-    private void singleUnAudit(Long id) {
-        Sale sale = new Sale();
-        //生成更新对象
-        sale.setId(id);
-        sale.setSa_status(Status.UNAUDITED.getDisplay());
-        sale.setSa_statuscode(Status.UNAUDITED.name());
-        sale.setUpdateTime(new Date());
-        sale.setUpdaterId(BaseContextHolder.getUserId());
-        //更新存在字段
-        saleMapper.updateByPrimaryKeySelective(sale);
-        DocBaseDTO docBaseDTO = getBaseDTOById(id);
-        //日志
-        messageLogService.unAudit(docBaseDTO);
-    }
-
     //更新最新销售总额
     private void updateTotal(Long id) {
         if (null == id) {
@@ -529,4 +492,41 @@ public class SaleServiceImpl implements SaleService{
         }
         saleMapper.updateNetTotal(id);
     }
+
+    /**
+     * @Description: 检验获取并更新单号
+     * @Param: [code, id]
+     * @return: java.lang.String
+     * @Author: guq
+     * @Date: 2018/10/19
+     */
+    private String pushMaxnubmer(String code, Long id) {
+        if (null == code) {
+            throw new BizException(BizExceptionCode.NULL_CODE);
+        }
+        Long companyId = BaseContextHolder.getCompanyId();
+        Integer count = "0".equals(String.valueOf(id)) ? saleMapper.validateCodeWhenInsert(code, companyId) :
+                saleMapper.validateCodeWhenUpdate(code, id, companyId);
+        return maxnumberService.pushMaxnubmer(count, code, BillCodeSeq.SALE.getCaller()).getData();
+    }
+
+    /**
+     * @Description
+     * @Param: [id]
+     * @return: com.usoftchina.saas.commons.dto.DocBaseDTO
+     * @Author: guq
+     * @Date: 2018/10/22
+     */
+    private DocBaseDTO getBaseDTOById(Long id) {
+        if (null == id) {
+            return null;
+        }
+        String code = saleMapper.selectCodeById(id);
+        DocBaseDTO baseDTO = new DocBaseDTO();
+        baseDTO.setId(id);
+        baseDTO.setCode(code);
+        baseDTO.setName("Sale");
+        return baseDTO;
+    }
+
 }