Browse Source

月末结账

lazhaoqian 4 years ago
parent
commit
b7bf10d066

+ 20 - 8
ruoyi-admin/src/main/java/com/ruoyi/web/controller/anpin/TMonthEndingClosingController.java

@@ -29,7 +29,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
  * @date 2021-06-04
  */
 @RestController
-@RequestMapping("/warehouse/closing")
+@RequestMapping("/anpin/closing")
 public class TMonthEndingClosingController extends BaseController
 {
     @Autowired
@@ -38,7 +38,7 @@ public class TMonthEndingClosingController extends BaseController
     /**
      * 查询月末结账列表
      */
-    @PreAuthorize("@ss.hasPermi('warehouse:closing:list')")
+    @PreAuthorize("@ss.hasPermi('anpin:closing:list')")
     @GetMapping("/list")
     public TableDataInfo list(TMonthEndingClosing tMonthEndingClosing)
     {
@@ -50,7 +50,7 @@ public class TMonthEndingClosingController extends BaseController
     /**
      * 导出月末结账列表
      */
-    @PreAuthorize("@ss.hasPermi('warehouse:closing:export')")
+    @PreAuthorize("@ss.hasPermi('anpin:closing:export')")
     @Log(title = "月末结账", businessType = BusinessType.EXPORT)
     @GetMapping("/export")
     public AjaxResult export(TMonthEndingClosing tMonthEndingClosing)
@@ -63,7 +63,7 @@ public class TMonthEndingClosingController extends BaseController
     /**
      * 获取月末结账详细信息
      */
-    @PreAuthorize("@ss.hasPermi('warehouse:closing:query')")
+    @PreAuthorize("@ss.hasPermi('anpin:closing:query')")
     @GetMapping(value = "/{fId}")
     public AjaxResult getInfo(@PathVariable("fId") Long fId)
     {
@@ -73,7 +73,7 @@ public class TMonthEndingClosingController extends BaseController
     /**
      * 新增月末结账
      */
-    @PreAuthorize("@ss.hasPermi('warehouse:closing:add')")
+    @PreAuthorize("@ss.hasPermi('anpin:closing:add')")
     @Log(title = "月末结账", businessType = BusinessType.INSERT)
     @PostMapping
     public AjaxResult add(@RequestBody TMonthEndingClosing tMonthEndingClosing)
@@ -84,18 +84,30 @@ public class TMonthEndingClosingController extends BaseController
     /**
      * 修改月末结账
      */
-    @PreAuthorize("@ss.hasPermi('warehouse:closing:edit')")
+    @PreAuthorize("@ss.hasPermi('anpin:closing:edit')")
     @Log(title = "月末结账", businessType = BusinessType.UPDATE)
     @PutMapping
     public AjaxResult edit(@RequestBody TMonthEndingClosing tMonthEndingClosing)
     {
-        return toAjax(tMonthEndingClosingService.updateTMonthEndingClosing(tMonthEndingClosing));
+        if (tMonthEndingClosing.getfId() == null){
+            return AjaxResult.error("请选择结账单后操作");
+        }
+        if (tMonthEndingClosing.getfYear() == 0){
+            return AjaxResult.error("参数缺失,请找管理员");
+        }
+        if (tMonthEndingClosing.getfMonth() == 0){
+            return AjaxResult.error("参数缺失,请找管理员");
+        }
+        if (StringUtils.isNull(tMonthEndingClosing.getfStatus())){
+            return AjaxResult.error("操作类型不能为空");
+        }
+        return tMonthEndingClosingService.updateTMonthEndingClosing(tMonthEndingClosing);
     }
 
     /**
      * 删除月末结账
      */
-    @PreAuthorize("@ss.hasPermi('warehouse:closing:remove')")
+    @PreAuthorize("@ss.hasPermi('anpin:closing:remove')")
     @Log(title = "月末结账", businessType = BusinessType.DELETE)
 	@DeleteMapping("/{fIds}")
     public AjaxResult remove(@PathVariable Long[] fIds)

+ 21 - 9
ruoyi-anpin/src/main/java/com/ruoyi/anpin/domain/TMonthEndingClosing.java

@@ -22,11 +22,11 @@ public class TMonthEndingClosing extends BaseEntity
 
     /** 年 */
     @Excel(name = "年")
-    private String fYear;
+    private int fYear;
 
     /** 月 */
     @Excel(name = "月")
-    private String fMonth;
+    private int fMonth;
 
     /** 开始时间 */
     @JsonFormat(pattern = "yyyy-MM-dd")
@@ -39,33 +39,44 @@ public class TMonthEndingClosing extends BaseEntity
     private Date fEnf;
 
     /** 是否结账 T 是 F 否 */
-    @Excel(name = "是否结账 T 是 F 否")
+
     private String fStatus;
+    //是否结账
+    @Excel(name = "是否结账")
+    private String fStatusName;
+
+    public String getfStatusName() {
+        return fStatusName;
+    }
+
+    public void setfStatusName(String fStatusName) {
+        this.fStatusName = fStatusName;
+    }
 
-    public void setfId(Long fId) 
+    public void setfId(Long fId)
     {
         this.fId = fId;
     }
 
-    public Long getfId() 
+    public Long getfId()
     {
         return fId;
     }
-    public void setfYear(String fYear) 
+    public void setfYear(int fYear)
     {
         this.fYear = fYear;
     }
 
-    public String getfYear() 
+    public int getfYear()
     {
         return fYear;
     }
-    public void setfMonth(String fMonth) 
+    public void setfMonth(int fMonth)
     {
         this.fMonth = fMonth;
     }
 
-    public String getfMonth() 
+    public int getfMonth()
     {
         return fMonth;
     }
@@ -106,6 +117,7 @@ public class TMonthEndingClosing extends BaseEntity
             .append("fStart", getfStart())
             .append("fEnf", getfEnf())
             .append("fStatus", getfStatus())
+            .append("fStatusName",getfStatusName())
             .toString();
     }
 }

+ 7 - 0
ruoyi-anpin/src/main/java/com/ruoyi/anpin/mapper/TMonthEndingClosingMapper.java

@@ -59,4 +59,11 @@ public interface TMonthEndingClosingMapper
      * @return 结果
      */
     public int deleteTMonthEndingClosingByIds(Long[] fIds);
+    /**
+     * 查询月末结账列表
+     *
+     * @param tMonthEndingClosing 月末结账
+     * @return 月末结账集合
+     */
+    public TMonthEndingClosing selectTMonthEndingClosing(TMonthEndingClosing tMonthEndingClosing);
 }

+ 2 - 1
ruoyi-anpin/src/main/java/com/ruoyi/anpin/service/ITMonthEndingClosingService.java

@@ -1,6 +1,7 @@
 package com.ruoyi.anpin.service;
 
 import com.ruoyi.anpin.domain.TMonthEndingClosing;
+import com.ruoyi.common.core.domain.AjaxResult;
 
 import java.util.List;
 
@@ -42,7 +43,7 @@ public interface ITMonthEndingClosingService
      * @param tMonthEndingClosing 月末结账
      * @return 结果
      */
-    public int updateTMonthEndingClosing(TMonthEndingClosing tMonthEndingClosing);
+    public AjaxResult updateTMonthEndingClosing(TMonthEndingClosing tMonthEndingClosing);
 
     /**
      * 批量删除月末结账

+ 109 - 29
ruoyi-anpin/src/main/java/com/ruoyi/anpin/service/impl/TMonthEndingClosingServiceImpl.java

@@ -1,6 +1,8 @@
 package com.ruoyi.anpin.service.impl;
 
+import java.text.SimpleDateFormat;
 import java.time.*;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
@@ -8,51 +10,55 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.ruoyi.anpin.domain.TMonthEndingClosing;
 import com.ruoyi.anpin.mapper.TMonthEndingClosingMapper;
 import com.ruoyi.anpin.service.ITMonthEndingClosingService;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.warehouseBusiness.domain.TWarehouseBills;
+import com.ruoyi.warehouseBusiness.mapper.TWarehouseBillsMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
 /**
  * 月末结账Service业务层处理
- * 
+ *
  * @author ruoyi
  * @date 2021-06-04
  */
 @Service
-public class TMonthEndingClosingServiceImpl implements ITMonthEndingClosingService
-{
+public class TMonthEndingClosingServiceImpl implements ITMonthEndingClosingService {
     @Autowired
     private TMonthEndingClosingMapper tMonthEndingClosingMapper;
+    @Autowired
+    private TWarehouseBillsMapper tWarehouseBillsMapper;
 
     /**
      * 查询月末结账
-     * 
+     *
      * @param fId 月末结账ID
      * @return 月末结账
      */
     @Override
-    public TMonthEndingClosing selectTMonthEndingClosingById(Long fId)
-    {
+    public TMonthEndingClosing selectTMonthEndingClosingById(Long fId) {
         return tMonthEndingClosingMapper.selectTMonthEndingClosingById(fId);
     }
 
     /**
      * 查询月末结账列表
-     * 
+     *
      * @param tMonthEndingClosing 月末结账
      * @return 月末结账
      */
     @Override
-    public List<TMonthEndingClosing> selectTMonthEndingClosingList(TMonthEndingClosing tMonthEndingClosing)
-    {
+    public List<TMonthEndingClosing> selectTMonthEndingClosingList(TMonthEndingClosing tMonthEndingClosing) {
         List<TMonthEndingClosing> tMonthEndingClosings = tMonthEndingClosingMapper.selectTMonthEndingClosingList(tMonthEndingClosing);
-        if (CollectionUtils.isEmpty(tMonthEndingClosings)){
-            for (int i=1; i<= 12; i++){
+        if (CollectionUtils.isEmpty(tMonthEndingClosings)) {
+            for (int i = 1; i <= 12; i++) {
                 TMonthEndingClosing monthEndingClosing = new TMonthEndingClosing();
                 monthEndingClosing.setfYear(tMonthEndingClosing.getfYear());
-                monthEndingClosing.setfMonth(i+"");
-                monthEndingClosing.setfStart(this.getBeginTime(Integer.valueOf(tMonthEndingClosing.getfYear()),i));
-                monthEndingClosing.setfEnf(this.getEndTime(Integer.valueOf(tMonthEndingClosing.getfYear()),i));
-                monthEndingClosing.setfStatus("T");
+                monthEndingClosing.setfMonth(i);
+                monthEndingClosing.setfStart(this.getBeginTime(tMonthEndingClosing.getfYear(), i));
+                monthEndingClosing.setfEnf(this.getEndTime(tMonthEndingClosing.getfYear(), i));
+                monthEndingClosing.setfStatus("F");
                 tMonthEndingClosingMapper.insertTMonthEndingClosing(monthEndingClosing);
 
             }
@@ -62,55 +68,129 @@ public class TMonthEndingClosingServiceImpl implements ITMonthEndingClosingServi
 
     /**
      * 新增月末结账
-     * 
+     *
      * @param tMonthEndingClosing 月末结账
      * @return 结果
      */
     @Override
-    public int insertTMonthEndingClosing(TMonthEndingClosing tMonthEndingClosing)
-    {
+    public int insertTMonthEndingClosing(TMonthEndingClosing tMonthEndingClosing) {
         return tMonthEndingClosingMapper.insertTMonthEndingClosing(tMonthEndingClosing);
     }
 
     /**
      * 修改月末结账
-     * 
+     *
      * @param tMonthEndingClosing 月末结账
      * @return 结果
      */
     @Override
-    public int updateTMonthEndingClosing(TMonthEndingClosing tMonthEndingClosing)
-    {
-        return tMonthEndingClosingMapper.updateTMonthEndingClosing(tMonthEndingClosing);
+    @Transactional
+    public AjaxResult updateTMonthEndingClosing(TMonthEndingClosing tMonthEndingClosing) {
+        TMonthEndingClosing closing = tMonthEndingClosingMapper.selectTMonthEndingClosingById(tMonthEndingClosing.getfId());
+        if (closing == null) {
+            return AjaxResult.error("请先生成结账单再结账!");
+        }
+        if (tMonthEndingClosing.getfStatus().equals("T") && closing.getfStatus().equals("T")) {
+            return AjaxResult.error("当前月已结账,请勿重复结账");
+        } else if (tMonthEndingClosing.getfStatus().equals("F") && closing.getfStatus().equals("F")) {
+            return AjaxResult.error("当前月未结账,请先结账");
+        }
+        TMonthEndingClosing monthEndingClosing = new TMonthEndingClosing();
+        if ("T".equals(tMonthEndingClosing.getfStatus())) {
+            //如果是结账判断上一个月是否结账
+            if (tMonthEndingClosing.getfMonth() == 1) {
+                monthEndingClosing.setfYear(tMonthEndingClosing.getfYear() - 1);
+                monthEndingClosing.setfMonth(12);
+            } else {
+                monthEndingClosing.setfMonth(tMonthEndingClosing.getfMonth() - 1);
+                monthEndingClosing.setfYear(tMonthEndingClosing.getfYear());
+            }
+        } else if ("F".equals(tMonthEndingClosing.getfStatus())) {
+            //如果是反结账判断下一个月是否为未结账
+            if (tMonthEndingClosing.getfMonth() == 12) {
+                monthEndingClosing.setfYear(tMonthEndingClosing.getfYear());
+                monthEndingClosing.setfMonth(tMonthEndingClosing.getfMonth());
+            } else {
+                monthEndingClosing.setfMonth(tMonthEndingClosing.getfMonth() + 1);
+                monthEndingClosing.setfYear(tMonthEndingClosing.getfYear());
+            }
+        }
+        Integer i = null;
+        TMonthEndingClosing endingClosing = tMonthEndingClosingMapper.selectTMonthEndingClosing(monthEndingClosing);
+        if (tMonthEndingClosing.getfStatus().equals("T")) {
+            if (endingClosing != null && endingClosing.getfStatus().equals("F")) {
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                return AjaxResult.error("上月未结账,请先结算上月结账单");
+            }
+            List<String> list = new ArrayList<>();
+            String pattern = "yyyy-MM-dd HH:mm:ss";
+            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
+            String start = simpleDateFormat.format(closing.getfStart());
+            String end = simpleDateFormat.format(closing.getfEnf());
+            list.add(start);
+            list.add(end);
+            //查询入库数据
+            TWarehouseBills tWarehouseBills = new TWarehouseBills();
+            tWarehouseBills.setfBilltype("RK");
+            tWarehouseBills.settimeInterval(list);
+            List<TWarehouseBills> Rk = tWarehouseBillsMapper.selectAnPinList(tWarehouseBills);
+            tWarehouseBills.setfBilltype("CK");
+            List<TWarehouseBills> Ck = tWarehouseBillsMapper.selectAnPinList(tWarehouseBills);
+            StringBuffer stringBuffer = new StringBuffer("当前月存在未入账信息:");
+            if (CollectionUtils.isNotEmpty(Rk)) {
+                stringBuffer.append("未入库的有" + Rk.size() + "条,");
+            }
+            if (CollectionUtils.isNotEmpty(Ck)) {
+                stringBuffer.append("未出库的有" + Ck.size() + "条,");
+            }
+            if (CollectionUtils.isNotEmpty(Rk) || CollectionUtils.isNotEmpty(Ck)) {
+                StringBuffer replace = stringBuffer.replace(stringBuffer.length() - 1, stringBuffer.length(), "!");
+                return AjaxResult.error(replace.toString());
+            }
+            i = tMonthEndingClosingMapper.updateTMonthEndingClosing(tMonthEndingClosing);
+
+        } else if (tMonthEndingClosing.getfStatus().equals("F")) {
+            if (endingClosing != null && endingClosing.getfStatus().equals("T")) {
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                return AjaxResult.error("下月已结账,当前月不允许反结账");
+            } else {
+                i = tMonthEndingClosingMapper.updateTMonthEndingClosing(tMonthEndingClosing);
+            }
+        }
+        if (i != null && i >= 0) {
+            return AjaxResult.success();
+        } else {
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+            return AjaxResult.error("结账出错请找管理员");
+        }
     }
 
     /**
      * 批量删除月末结账
-     * 
+     *
      * @param fIds 需要删除的月末结账ID
      * @return 结果
      */
     @Override
-    public int deleteTMonthEndingClosingByIds(Long[] fIds)
-    {
+    public int deleteTMonthEndingClosingByIds(Long[] fIds) {
         return tMonthEndingClosingMapper.deleteTMonthEndingClosingByIds(fIds);
     }
 
     /**
      * 删除月末结账信息
-     * 
+     *
      * @param fId 月末结账ID
      * @return 结果
      */
     @Override
-    public int deleteTMonthEndingClosingById(Long fId)
-    {
+    public int deleteTMonthEndingClosingById(Long fId) {
         return tMonthEndingClosingMapper.deleteTMonthEndingClosingById(fId);
     }
 
 
     /**
      * 根据年月获取月的开始时间结束时间
+     *
      * @param year
      * @param month
      * @return
@@ -124,7 +204,7 @@ public class TMonthEndingClosingServiceImpl implements ITMonthEndingClosingServi
         return Date.from(zonedDateTime.toInstant());
     }
 
-    public  Date getEndTime(int year, int month) {
+    public Date getEndTime(int year, int month) {
         YearMonth yearMonth = YearMonth.of(year, month);
         LocalDate endOfMonth = yearMonth.atEndOfMonth();
         LocalDateTime localDateTime = endOfMonth.atTime(23, 59, 59, 999);

+ 46 - 26
ruoyi-anpin/src/main/resources/mapper/anpin/TMonthEndingClosingMapper.xml

@@ -1,39 +1,47 @@
 <?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">
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ruoyi.anpin.mapper.TMonthEndingClosingMapper">
-    
+
     <resultMap type="TMonthEndingClosing" id="TMonthEndingClosingResult">
-        <result property="fId"    column="f_id"    />
-        <result property="fYear"    column="f_year"    />
-        <result property="fMonth"    column="f_month"    />
-        <result property="fStart"    column="f_start"    />
-        <result property="fEnf"    column="f_enf"    />
-        <result property="fStatus"    column="f_status"    />
+        <result property="fId" column="f_id"/>
+        <result property="fYear" column="f_year"/>
+        <result property="fMonth" column="f_month"/>
+        <result property="fStart" column="f_start"/>
+        <result property="fEnf" column="f_enf"/>
+        <result property="fStatus" column="f_status"/>
     </resultMap>
 
     <sql id="selectTMonthEndingClosingVo">
-        select f_id, f_year, f_month, f_start, f_enf, f_status from t_month_ending_closing
+        select f_id, f_year, f_month, f_start, f_enf, f_status
+        from t_month_ending_closing
     </sql>
 
-    <select id="selectTMonthEndingClosingList" parameterType="TMonthEndingClosing" resultMap="TMonthEndingClosingResult">
-        <include refid="selectTMonthEndingClosingVo"/>
-        <where>  
-            <if test="fYear != null  and fYear != ''"> and f_year = #{fYear}</if>
-            <if test="fMonth != null  and fMonth != ''"> and f_month = #{fMonth}</if>
-            <if test="fStart != null "> and f_start = #{fStart}</if>
-            <if test="fEnf != null "> and f_enf = #{fEnf}</if>
-            <if test="fStatus != null  and fStatus != ''"> and f_status = #{fStatus}</if>
+    <select id="selectTMonthEndingClosingList" parameterType="TMonthEndingClosing"
+            resultMap="TMonthEndingClosingResult">
+        select f_id, f_year, f_month, f_start, f_enf, f_status,CASE
+        WHEN f_status = 'T' THEN '是'
+        WHEN f_status = 'F' THEN '否'
+        END
+        AS fStatusName from t_month_ending_closing
+        <where>
+            <if test="fYear != null  and fYear != ''">and f_year = #{fYear}</if>
+            <if test="fMonth != null  and fMonth != ''">and f_month = #{fMonth}</if>
+            <if test="fStart != null ">and f_start = #{fStart}</if>
+            <if test="fEnf != null ">and f_enf = #{fEnf}</if>
+            <if test="fStatus != null  and fStatus != ''">and f_status = #{fStatus}</if>
         </where>
+        ORDER BY f_year,f_month
     </select>
-    
+
     <select id="selectTMonthEndingClosingById" parameterType="Long" resultMap="TMonthEndingClosingResult">
         <include refid="selectTMonthEndingClosingVo"/>
         where f_id = #{fId}
     </select>
-        
-    <insert id="insertTMonthEndingClosing" parameterType="TMonthEndingClosing" useGeneratedKeys="true" keyProperty="fId">
+
+    <insert id="insertTMonthEndingClosing" parameterType="TMonthEndingClosing" useGeneratedKeys="true"
+            keyProperty="fId">
         insert into t_month_ending_closing
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="fYear != null">f_year,</if>
@@ -41,14 +49,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="fStart != null">f_start,</if>
             <if test="fEnf != null">f_enf,</if>
             <if test="fStatus != null">f_status,</if>
-         </trim>
+        </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="fYear != null">#{fYear},</if>
             <if test="fMonth != null">#{fMonth},</if>
             <if test="fStart != null">#{fStart},</if>
             <if test="fEnf != null">#{fEnf},</if>
             <if test="fStatus != null">#{fStatus},</if>
-         </trim>
+        </trim>
     </insert>
 
     <update id="updateTMonthEndingClosing" parameterType="TMonthEndingClosing">
@@ -64,14 +72,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </update>
 
     <delete id="deleteTMonthEndingClosingById" parameterType="Long">
-        delete from t_month_ending_closing where f_id = #{fId}
+        delete
+        from t_month_ending_closing
+        where f_id = #{fId}
     </delete>
 
     <delete id="deleteTMonthEndingClosingByIds" parameterType="String">
-        delete from t_month_ending_closing where f_id in 
+        delete from t_month_ending_closing where f_id in
         <foreach item="fId" collection="array" open="(" separator="," close=")">
             #{fId}
         </foreach>
     </delete>
-    
+    <select id="selectTMonthEndingClosing" parameterType="TMonthEndingClosing" resultMap="TMonthEndingClosingResult">
+        <include refid="selectTMonthEndingClosingVo"/>
+        <where>
+            <if test="fYear != null  and fYear != ''">and f_year = #{fYear}</if>
+            <if test="fMonth != null  and fMonth != ''">and f_month = #{fMonth}</if>
+            <if test="fStart != null ">and f_start = #{fStart}</if>
+            <if test="fEnf != null ">and f_enf = #{fEnf}</if>
+            <if test="fStatus != null  and fStatus != ''">and f_status = #{fStatus}</if>
+        </where>
+    </select>
+
 </mapper>