Browse Source

销售订单新增sa_sellid字段,完善审核状态+关闭状态逻辑,完善审核反审核操作+客户关闭逻辑

rainco 7 years ago
parent
commit
467489b655

+ 6 - 3
applications/commons/commons-dto/src/main/java/com/usoftchina/saas/commons/exception/BizExceptionCode.java

@@ -74,19 +74,22 @@ public enum BizExceptionCode implements BaseExceptionCode {
 
     //销售
     SALE_ALL_TURNOUT(72000, "该销售单已全部转出货,无法转出货单"),
-    SALE_CLOSE(72001, "单据已关闭,无法进行操作"),
+    SALE_CLOSE(72001, "单据已关闭,无法%s"),
     SALE_YQTYBEYONDQTY(72001, "明细行已转数量大于数量"),
     SALE_NULL_BILL(72002, "单据不存在或者明细为空"),
     SALEOUT_ALL_TURNIN(72003, "该出货单已全部转退货,无法转销售退货单"),
-    SALEOUT_POSTSTATUS_ERROR(72004,"当前单据状态无法进行此操作"),
+    SALEOUT_POSTSTATUS_ERROR(72004,"当前单据状态无法进行此操作"),
     SALEOUT_POST_ERROR(72005,"编号:<u>%s</u>处理失败,%s"),
     SALEOUT_UNAUDIT_ERROR(72006,"销售订单已转出货单,无法反审核"),
     SALE_ORDER_HASAUDIT(72003, "存在已审核单据,单据编号:%s"),
     SALE_EXISTS_PURCHASE(72004, "存在已转的采购单据,单据编号:%s"),
-    SALE_ALREADY_UNAUDIT(72007, "单据状态为未审核,无法反审核"),
+    SALE_ALREADY_UNAUDIT(72007, "反审核失败!该单据非审核状态"),
     SALE_CUST_CLOSE(72008, "客户已关闭,无法审核"),
     SALE_ORDER_ISUNAUDIT(72009, "存在未审核单据,单据编号:%s"),
     SALE_ORDER_ISCOLSED(72010, "存在已关闭单据,单据编号:%s"),
+    SALE_ORDER_CUSTBANDED(72011, "存在已禁用客户,无法%s,单据编号:"),
+    SALE_CUSTBANDED(72013, "存在已禁用客户,无法%s"),
+    SALE_AUDITED(72014,"审核失败!该单据已审核"),
     //资金
     PAYBALANCE_OUTNOWBALANCE(74001,"本次核销金额不能大于未核销金额"),
     PAYBALANCE_UNIQUESOURCECODE(74002, "保存失败!不能选择重复的源单"),

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

@@ -59,4 +59,6 @@ public class SaleDTO extends CommonBaseDTO{
     private String sa_seller;
 
     private String sa_sellercode;
+
+    private Integer sa_sellerid;
 }

+ 6 - 0
applications/sale/sale-server/src/main/java/com/usoftchina/saas/sale/mapper/SaleMapper.java

@@ -31,8 +31,12 @@ public interface SaleMapper extends CommonBaseMapper<Sale> {
 
     String validateUnAudit(Long id);
 
+    String validateCloseStatus(Long id);
+
     String validateAudit(List<DocBaseDTO> baseDTOs);
 
+    String validateAuditStatus(Long id);
+
     Integer validateCodeWhenUpdate(@Param("code") String code, @Param("id") Long id, @Param("companyId") Long companyId);
 
     void updateTotal(Long id);
@@ -57,5 +61,7 @@ public interface SaleMapper extends CommonBaseMapper<Sale> {
 
     String validateCustAudit(List<DocBaseDTO> baseDTOs);
 
+    String validateCustStatus(Long id);
+
     String validateClose(List<DocBaseDTO> baseDTOs);
 }

+ 2 - 0
applications/sale/sale-server/src/main/java/com/usoftchina/saas/sale/po/Sale.java

@@ -58,4 +58,6 @@ public class Sale extends CommonBaseEntity{
     private String sa_seller;
 
     private String sa_sellercode;
+
+    private Integer sa_sellerid;
 }

+ 2 - 0
applications/sale/sale-server/src/main/java/com/usoftchina/saas/sale/po/SaleList.java

@@ -65,6 +65,8 @@ public class SaleList implements Serializable {
 
     private String sa_auditman;
 
+    private Integer sa_sellerid;
+
     private Integer sd_id;
 
     private Integer sd_said;

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

@@ -225,6 +225,21 @@ public class SaleServiceImpl implements SaleService{
                 baseDTO = saveFormData(formData);
                 id = baseDTO.getId();
             }
+            //审核失败!该单据已审核
+            String code = saleMapper.validateAuditStatus(id);
+            if (null != code) {
+                throw new BizException(BizExceptionCode.SALE_AUDITED);
+            }
+            //存在已禁用客户,无法审核:
+            code = saleMapper.validateCustStatus(id);
+            if (null != code) {
+                throw new BizException(BizExceptionCode.SALE_CUSTBANDED.getCode(),String.format(BizExceptionCode.SALE_CUSTBANDED.getMessage(),"审核"));
+            }
+            //单据状态为已关闭,无法审核
+            code = saleMapper.validateCloseStatus(id);
+            if (null != code) {
+                throw new BizException(BizExceptionCode.SALE_CLOSE.getCode(),String.format(BizExceptionCode.SALE_CLOSE.getMessage(),"审核"));
+            }
             singleAudit(id);
         }
         return baseDTO;
@@ -232,17 +247,6 @@ public class SaleServiceImpl implements SaleService{
 
     @Transactional
     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());
-        sale.setSa_auditman("TESTADMIN");
-        sale.setSa_auditdate(new Date());
-        //更新存在字段
-        saleMapper.updateByPrimaryKeySelective(sale);*/
         Integer integer = saleMapper.checkCustomer(id);
         if (integer > 0) {
             throw new BizException(BizExceptionCode.SALE_CUST_CLOSE);
@@ -266,17 +270,7 @@ public class SaleServiceImpl implements SaleService{
                 baseDTOs.getBaseDTOs().size() == 0) {
             return;
         }
-
-        String validate = saleMapper.validateAudit(baseDTOs.getBaseDTOs());
-        if (!StringUtils.isEmpty(validate)) {
-            String message = BizExceptionCode.SALE_ORDER_HASAUDIT.getMessage();
-            int code = BizExceptionCode.SALE_ORDER_HASAUDIT.getCode();
-            throw new BizException(code, String.format(message, validate));
-        }
-        String custAudit = saleMapper.validateCustAudit(baseDTOs.getBaseDTOs());
-        if (!StringUtils.isEmpty(custAudit)) {
-            throw new BizException(72009, "客户已关闭,无法审核, 单号:" + custAudit);
-        }
+        checkBatchAuditStatus(baseDTOs,"batchAudit");
         for (DocBaseDTO base : baseDTOs.getBaseDTOs()) {
             singleAudit(base.getId());
         }
@@ -287,6 +281,7 @@ public class SaleServiceImpl implements SaleService{
         if (null == id) {
             return;
         }
+        //单据状态为未审核,无法反审核
         String code = saleMapper.validateUnAudit(id);
         if (null != code) {
             throw new BizException(BizExceptionCode.SALE_ALREADY_UNAUDIT);
@@ -328,20 +323,7 @@ public class SaleServiceImpl implements SaleService{
                 baseDTOs.getBaseDTOs().size() == 0) {
             return;
         }
-        //存在未审核单据,单据编号:XXXX
-        String msg = saleMapper.validateBatchUnAudit(baseDTOs.getBaseDTOs());
-        if (null != msg) {
-            String message = BizExceptionCode.SALE_ORDER_ISUNAUDIT.getMessage();
-            int code = BizExceptionCode.SALE_ORDER_ISUNAUDIT.getCode();
-            throw new BizException(code, String.format(message, msg));
-        }
-        //存在已关闭单据,单据编号:XXXX
-        msg = saleMapper.validateClose(baseDTOs.getBaseDTOs());
-        if (null != msg) {
-            String message = BizExceptionCode.SALE_ORDER_ISCOLSED.getMessage();
-            int code = BizExceptionCode.SALE_ORDER_ISCOLSED.getCode();
-            throw new BizException(code, String.format(message, msg));
-        }
+        checkBatchAuditStatus(baseDTOs,"batchUnAudit");
         //saleMapper.BatchcheckSendStatus();
         for (DocBaseDTO base : baseDTOs.getBaseDTOs()) {
             unAudit(base.getId());
@@ -444,7 +426,7 @@ public class SaleServiceImpl implements SaleService{
             throw new BizException(BizExceptionCode.SALE_ALL_TURNOUT);
         }
         if (Status.CLOSE.name().equals(statuscode)){
-            throw new BizException(BizExceptionCode.SALE_CLOSE);
+            throw new BizException(BizExceptionCode.SALE_CLOSE.getCode(),String.format(BizExceptionCode.SALE_CLOSE.getMessage(),"转出货单"));
         }
 
         //检查从表
@@ -710,4 +692,54 @@ public class SaleServiceImpl implements SaleService{
         return null;
     }
 
+    /**
+     * 批量审核、反审核状态校验
+     * */
+    private void checkBatchAuditStatus(BatchDealBaseDTO baseDTOs,String opation){
+        if(opation.equals("batchAudit")){
+            //存在已审核单据,单据编号:XXX
+            String validate = saleMapper.validateAudit(baseDTOs.getBaseDTOs());
+            if (!StringUtils.isEmpty(validate)) {
+                String message = BizExceptionCode.SALE_ORDER_HASAUDIT.getMessage();
+                int code = BizExceptionCode.SALE_ORDER_HASAUDIT.getCode();
+                throw new BizException(code, String.format(message, validate));
+            }
+            //存在已关闭单据,单据编号:XXXX
+            validate = saleMapper.validateClose(baseDTOs.getBaseDTOs());
+            if (null != validate) {
+                String message = BizExceptionCode.SALE_ORDER_ISCOLSED.getMessage();
+                int code = BizExceptionCode.SALE_ORDER_ISCOLSED.getCode();
+                throw new BizException(code, String.format(message, validate));
+            }
+            //存在已禁用客户,无法审核,单据编号:XXX
+            String custAudit = saleMapper.validateCustAudit(baseDTOs.getBaseDTOs());
+            if (!StringUtils.isEmpty(custAudit)) {
+                String message = BizExceptionCode.SALE_ORDER_CUSTBANDED.getMessage();
+                int code = BizExceptionCode.SALE_ORDER_CUSTBANDED.getCode();
+                throw new BizException(code, String.format(message, "反审核")+custAudit);
+            }
+        }else{
+            //存在未审核单据,单据编号:XXXX
+            String msg = saleMapper.validateBatchUnAudit(baseDTOs.getBaseDTOs());
+            if (null != msg) {
+                String message = BizExceptionCode.SALE_ORDER_ISUNAUDIT.getMessage();
+                int code = BizExceptionCode.SALE_ORDER_ISUNAUDIT.getCode();
+                throw new BizException(code, String.format(message, msg));
+            }
+            //存在已关闭单据,单据编号:XXXX
+            msg = saleMapper.validateClose(baseDTOs.getBaseDTOs());
+            if (null != msg) {
+                String message = BizExceptionCode.SALE_ORDER_ISCOLSED.getMessage();
+                int code = BizExceptionCode.SALE_ORDER_ISCOLSED.getCode();
+                throw new BizException(code, String.format(message, msg));
+            }
+            //存在已禁用客户,无法审核,单据编号:XXX
+            msg = saleMapper.validateCustAudit(baseDTOs.getBaseDTOs());
+            if (!StringUtils.isEmpty(msg)) {
+                String message = BizExceptionCode.SALE_ORDER_CUSTBANDED.getMessage();
+                int code = BizExceptionCode.SALE_ORDER_CUSTBANDED.getCode();
+                throw new BizException(code, String.format(message, "反审核")+msg);
+            }
+        }
+    }
 }

+ 1 - 0
applications/sale/sale-server/src/main/resources/mapper/SaleListMapper.xml

@@ -28,6 +28,7 @@
         <result column="sa_text3" property="sa_text3" jdbcType="VARCHAR" />
         <result column="sa_text4" property="sa_text4" jdbcType="VARCHAR" />
         <result column="sa_text5" property="sa_text5" jdbcType="VARCHAR" />
+        <result column="sa_sellerid" property="sa_sellerid" jdbcType="INTEGER" />
         <result column="sd_id" property="sd_id" jdbcType="INTEGER" />
         <result column="sd_said" property="sd_said" jdbcType="INTEGER" />
         <result column="sd_detno" property="sd_detno" jdbcType="INTEGER" />

+ 26 - 6
applications/sale/sale-server/src/main/resources/mapper/SaleMapper.xml

@@ -33,13 +33,14 @@
     <result column="creatorName" property="creatorName" jdbcType="VARCHAR" />
     <result column="updaterName" property="updaterName" jdbcType="VARCHAR" />
     <result column="createTime" property="createTime" jdbcType="TIMESTAMP"/>
+    <result column="sa_sellerid" property="sa_sellerid" jdbcType="INTEGER" />
   </resultMap>
   <sql id="Base_Column_List" >
     sa_id, sa_code, sa_custid, sa_custcode, sa_custname, sa_toplace, sa_total, sa_totalupper, 
     sa_remark, sa_status, sa_statuscode, sa_sendstatuscode, sa_sendstatus, sa_printstatus, 
     sa_printstatuscode,companyId, updaterId,
     updateTime, sa_text1, sa_text2, sa_text3, sa_text4, sa_text5,sa_auditman,sa_auditdate,
-    sa_seller,sa_sellercode,sa_date
+    sa_seller,sa_sellercode,sa_date,sa_sellerid
   </sql>
   <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
     select * from sale where sa_id = #{id}
@@ -56,7 +57,7 @@
       sa_sendstatus, sa_printstatus, sa_printstatuscode, 
       companyId, updaterId, updateTime,
       sa_text1, sa_text2, sa_text3, 
-      sa_text4, sa_text5)
+      sa_text4, sa_text5,sa_sellerid)
     values (#{sa_id,jdbcType=INTEGER}, #{sa_code,jdbcType=VARCHAR}, #{sa_custid,jdbcType=INTEGER}, 
       #{sa_custcode,jdbcType=VARCHAR}, #{sa_custname,jdbcType=VARCHAR}, #{sa_toplace,jdbcType=VARCHAR}, 
       #{sa_total,jdbcType=DOUBLE}, #{sa_totalupper,jdbcType=VARCHAR}, #{sa_remark,jdbcType=VARCHAR}, 
@@ -64,7 +65,7 @@
       #{sa_sendstatus,jdbcType=VARCHAR}, #{sa_printstatus,jdbcType=VARCHAR}, #{sa_printstatuscode,jdbcType=VARCHAR}, 
       #{companyId,jdbcType=INTEGER}, #{updaterId,jdbcType=INTEGER}, #{updateTime,jdbcType=TIMESTAMP},
       #{sa_text1,jdbcType=VARCHAR}, #{sa_text2,jdbcType=VARCHAR}, #{sa_text3,jdbcType=VARCHAR}, 
-      #{sa_text4,jdbcType=VARCHAR}, #{sa_text5,jdbcType=VARCHAR})
+      #{sa_text4,jdbcType=VARCHAR}, #{sa_text5,jdbcType=VARCHAR},#{sa_sellerid,jdbcType=INTEGER})
   </insert>
   <insert id="insertSelective" parameterType="com.usoftchina.saas.sale.po.Sale" >
     <selectKey  resultType="java.lang.Long" keyProperty="id">
@@ -147,6 +148,9 @@
       <if test="sa_date != null" >
         sa_date,
       </if>
+      <if test="sa_sellerid != null">
+        sa_sellerid,
+      </if>
     </trim>
     <trim prefix="values (" suffix=")" suffixOverrides="," >
       <if test="sa_code != null" >
@@ -224,6 +228,9 @@
       <if test="sa_date != null" >
         #{sa_date,jdbcType=TIMESTAMP},
       </if>
+      <if test="sa_sellerid != null" >
+        #{sa_sellerid,jdbcType=INTEGER},
+      </if>
     </trim>
   </insert>
   <update id="updateByPrimaryKeySelective" parameterType="com.usoftchina.saas.sale.po.Sale" >
@@ -310,6 +317,9 @@
       <if test="sa_date != null" >
         sa_date = #{sa_date,jdbcType=TIMESTAMP},
       </if>
+      <if test="sa_sellerid != null" >
+        sa_sellerid = #{sa_sellerid,jdbcType=INTEGER},
+      </if>
     </set>
     where sa_id = #{id,jdbcType=INTEGER}
   </update>
@@ -336,7 +346,8 @@
       sa_text2 = #{sa_text2,jdbcType=VARCHAR},
       sa_text3 = #{sa_text3,jdbcType=VARCHAR},
       sa_text4 = #{sa_text4,jdbcType=VARCHAR},
-      sa_text5 = #{sa_text5,jdbcType=VARCHAR}
+      sa_text5 = #{sa_text5,jdbcType=VARCHAR},
+      sa_sellerid = #{sa_sellerid,jdbcType=INTEGER}
     where sa_id = #{id,jdbcType=INTEGER}
   </update>
 
@@ -356,20 +367,29 @@
       #{item.id}
     </foreach>
   </select>
+  <select id="validateAuditStatus" resultType="string" parameterType="long">
+    select sa_code from sale where IFNULL(sa_statuscode,' ')='AUDITED' and sa_id=#{id}
+  </select>
   <select id="validateClose" parameterType="com.usoftchina.saas.commons.dto.DocBaseDTO" resultType="java.lang.String">
       select GROUP_CONCAT(sa_code) from sale where IFNULL(sa_sendstatuscode,' ')='CLOSE' and sa_id in
     <foreach collection="list" item="item" open="(" close=")" separator=",">
       #{item.id}
     </foreach>
   </select>
+  <select id="validateCloseStatus" resultType="string" parameterType="long">
+    select sa_code from sale where IFNULL(sa_sendstatuscode,' ')='CLOSE' and sa_id=#{id}
+  </select>
   <select id="validateCustAudit" parameterType="com.usoftchina.saas.commons.dto.DocBaseDTO" resultType="java.lang.String">
-    select GROUP_CONCAT(sa_code) from sale left join customer on cu_id=sa_custid  where sa_statuscode='AUDITED' and sa_id in
+    select GROUP_CONCAT(sa_code) from sale left join customer on cu_id=sa_custid  where IFNULL(sa_statuscode,' ')='AUDITED' and IFNULL(cu_statuscode,' ')='BANNED' and sa_id in
     <foreach collection="list" item="item" open="(" close=")" separator=",">
       #{item.id}
     </foreach>
   </select>
+  <select id="validateCustStatus" resultType="string" parameterType="long">
+    select sa_code from sale left join customer on cu_id=sa_custid  where IFNULL(cu_statuscode,' ')='BANNED' and sa_id=#{id}
+  </select>
   <select id="validateBatchUnAudit" parameterType="com.usoftchina.saas.commons.dto.DocBaseDTO" resultType="java.lang.String">
-    select GROUP_CONCAT(sa_code) from sale where IFNULL(sa_statuscode,'UNAUDITED') = 'UNAUDITED' and sa_id in
+    select GROUP_CONCAT(sa_code) from sale where IFNULL(sa_statuscode,' ') = 'UNAUDITED' and sa_id in
     <foreach collection="list" item="item" open="(" close=")" separator=",">
       #{item.id}
     </foreach>