|
@@ -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);
|