|
@@ -6,11 +6,9 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import com.txz.cif.dao.DayCutMapper;
|
|
import com.txz.cif.dao.DayCutMapper;
|
|
|
import com.txz.cif.model.DayCut;
|
|
import com.txz.cif.model.DayCut;
|
|
|
import com.txz.cif.model.Subject;
|
|
import com.txz.cif.model.Subject;
|
|
|
-import com.txz.cif.service.AccountFlowService;
|
|
|
|
|
-import com.txz.cif.service.AccountService;
|
|
|
|
|
-import com.txz.cif.service.DayCutService;
|
|
|
|
|
|
|
+import com.txz.cif.model.User;
|
|
|
|
|
+import com.txz.cif.service.*;
|
|
|
import com.txz.cif.core.AbstractService;
|
|
import com.txz.cif.core.AbstractService;
|
|
|
-import com.txz.cif.service.SubjectService;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -33,132 +31,137 @@ import java.util.Map;
|
|
|
public class DayCutServiceImpl extends AbstractService<DayCut> implements DayCutService {
|
|
public class DayCutServiceImpl extends AbstractService<DayCut> implements DayCutService {
|
|
|
@Resource
|
|
@Resource
|
|
|
private DayCutMapper cDayCutMapper;
|
|
private DayCutMapper cDayCutMapper;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Resource
|
|
@Resource
|
|
|
private SubjectService subjectService;
|
|
private SubjectService subjectService;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Resource
|
|
@Resource
|
|
|
private AccountService accountService;
|
|
private AccountService accountService;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Resource
|
|
@Resource
|
|
|
private AccountFlowService accountFlowService;
|
|
private AccountFlowService accountFlowService;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private UserService userService;
|
|
|
|
|
+
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
|
System.out.println(DateUtil.thisDayOfMonth());
|
|
System.out.println(DateUtil.thisDayOfMonth());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void dayCut() {
|
|
public void dayCut() {
|
|
|
- //判断是否已日切
|
|
|
|
|
|
|
+ // 判断是否已日切
|
|
|
Condition c = new Condition(DayCut.class);
|
|
Condition c = new Condition(DayCut.class);
|
|
|
- c.createCriteria().andEqualTo("day",DateUtil.format(DateUtil.yesterday(),"yyyy-MM-dd"));
|
|
|
|
|
|
|
+ c.createCriteria().andEqualTo("day", DateUtil.format(DateUtil.yesterday(), "yyyy-MM-dd"));
|
|
|
List<DayCut> dayCuts = findByCondition(c);
|
|
List<DayCut> dayCuts = findByCondition(c);
|
|
|
- if (CollUtil.isNotEmpty(dayCuts)){
|
|
|
|
|
|
|
+ if (CollUtil.isNotEmpty(dayCuts)) {
|
|
|
log.error("[日切]已日切");
|
|
log.error("[日切]已日切");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- //查询叶子科目
|
|
|
|
|
|
|
+ // 查询叶子科目
|
|
|
c = new Condition(Subject.class);
|
|
c = new Condition(Subject.class);
|
|
|
- c.createCriteria().andEqualTo("leaf",1);
|
|
|
|
|
|
|
+ c.createCriteria().andEqualTo("leaf", 1);
|
|
|
List<Subject> subjects = subjectService.findByCondition(c);
|
|
List<Subject> subjects = subjectService.findByCondition(c);
|
|
|
- if (CollUtil.isEmpty(subjects)){
|
|
|
|
|
|
|
+ if (CollUtil.isEmpty(subjects)) {
|
|
|
log.error("[日切]叶子科目为空");
|
|
log.error("[日切]叶子科目为空");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
// 判断是否为月初 进行月结
|
|
// 判断是否为月初 进行月结
|
|
|
- if (DateUtil.thisDayOfMonth() == 1){
|
|
|
|
|
|
|
+ if (DateUtil.thisDayOfMonth() == 1) {
|
|
|
accountService.innerCarry();
|
|
accountService.innerCarry();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- Date yesterday = DateUtil.yesterday();
|
|
|
|
|
- //借方余额汇总
|
|
|
|
|
|
|
+
|
|
|
|
|
+ List<User> all = userService.findAll();
|
|
|
|
|
+
|
|
|
|
|
+ Date yesterday = DateUtil.yesterday();
|
|
|
|
|
+ // 借方余额汇总
|
|
|
BigDecimal totalDebit = BigDecimal.ZERO;
|
|
BigDecimal totalDebit = BigDecimal.ZERO;
|
|
|
- //贷方余额汇总
|
|
|
|
|
|
|
+ // 贷方余额汇总
|
|
|
BigDecimal totalCredit = BigDecimal.ZERO;
|
|
BigDecimal totalCredit = BigDecimal.ZERO;
|
|
|
- //资产类余额汇总
|
|
|
|
|
|
|
+ // 资产类余额汇总
|
|
|
BigDecimal asset = BigDecimal.ZERO;
|
|
BigDecimal asset = BigDecimal.ZERO;
|
|
|
- //负债类余额 + 损益类余额 + 所有者权益余额汇总
|
|
|
|
|
|
|
+ // 负债类余额 + 损益类余额 + 所有者权益余额汇总
|
|
|
BigDecimal unAsset = BigDecimal.ZERO;
|
|
BigDecimal unAsset = BigDecimal.ZERO;
|
|
|
-
|
|
|
|
|
- for (Subject subject:subjects ) {
|
|
|
|
|
- //初始日余额
|
|
|
|
|
|
|
+
|
|
|
|
|
+ for (Subject subject : subjects) {
|
|
|
|
|
+ // 初始日余额
|
|
|
BigDecimal initAmount = accountService.sumInit(subject.getAliases());
|
|
BigDecimal initAmount = accountService.sumInit(subject.getAliases());
|
|
|
- if (initAmount == null){
|
|
|
|
|
|
|
+ if (initAmount == null) {
|
|
|
initAmount = BigDecimal.ZERO;
|
|
initAmount = BigDecimal.ZERO;
|
|
|
}
|
|
}
|
|
|
- //日余额
|
|
|
|
|
|
|
+ // 日余额
|
|
|
BigDecimal endAmount = accountService.sumEnd(subject.getAliases());
|
|
BigDecimal endAmount = accountService.sumEnd(subject.getAliases());
|
|
|
- if (endAmount == null){
|
|
|
|
|
|
|
+ if (endAmount == null) {
|
|
|
endAmount = BigDecimal.ZERO;
|
|
endAmount = BigDecimal.ZERO;
|
|
|
}
|
|
}
|
|
|
- //类型 1出金 2入金
|
|
|
|
|
- //借方发生额
|
|
|
|
|
- BigDecimal debitAmount = accountFlowService.sumOccur(subject.getAliases(),
|
|
|
|
|
- StrUtil.equals("D",subject.getDirection())? 2 : 1,
|
|
|
|
|
- DateUtil.format(yesterday,"yyyy-MM-dd")+" 00:00:00",DateUtil.today()+" 00:00:00");
|
|
|
|
|
- if (debitAmount == null){
|
|
|
|
|
- debitAmount = BigDecimal.ZERO;
|
|
|
|
|
- }
|
|
|
|
|
- //贷方发生额
|
|
|
|
|
- BigDecimal creditAmount = accountFlowService.sumOccur(subject.getAliases(),
|
|
|
|
|
- StrUtil.equals("C",subject.getDirection())? 2 : 1,
|
|
|
|
|
- DateUtil.format(yesterday,"yyyy-MM-dd")+" 00:00:00",DateUtil.today()+" 00:00:00");
|
|
|
|
|
- if (creditAmount == null){
|
|
|
|
|
- creditAmount = BigDecimal.ZERO;
|
|
|
|
|
|
|
+ // 类型 1出金 2入金
|
|
|
|
|
+ // 借方发生额
|
|
|
|
|
+ BigDecimal debitAmount = BigDecimal.ZERO;
|
|
|
|
|
+ BigDecimal creditAmount = BigDecimal.ZERO;
|
|
|
|
|
+ for (User user : all) {
|
|
|
|
|
+ debitAmount.add(accountFlowService.sumOccur(subject.getAliases(),
|
|
|
|
|
+ StrUtil.equals("D", subject.getDirection()) ? 2 : 1,
|
|
|
|
|
+ DateUtil.format(yesterday, "yyyy-MM-dd") + " 00:00:00", DateUtil.today() + " 00:00:00", user.getId()));
|
|
|
|
|
+
|
|
|
|
|
+ // 贷方发生额
|
|
|
|
|
+ creditAmount.add(accountFlowService.sumOccur(subject.getAliases(),
|
|
|
|
|
+ StrUtil.equals("C", subject.getDirection()) ? 2 : 1,
|
|
|
|
|
+ DateUtil.format(yesterday, "yyyy-MM-dd") + " 00:00:00", DateUtil.today() + " 00:00:00", user.getId()));
|
|
|
}
|
|
}
|
|
|
- //保存日切数据
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 保存日切数据
|
|
|
DayCut dayCut = DayCut.builder().subjectId(subject.getId()).day(yesterday)
|
|
DayCut dayCut = DayCut.builder().subjectId(subject.getId()).day(yesterday)
|
|
|
.creditAmount(creditAmount)
|
|
.creditAmount(creditAmount)
|
|
|
.debitAmount(debitAmount)
|
|
.debitAmount(debitAmount)
|
|
|
.createTime(DateUtil.date()).endAmount(endAmount)
|
|
.createTime(DateUtil.date()).endAmount(endAmount)
|
|
|
.initAmount(initAmount).build();
|
|
.initAmount(initAmount).build();
|
|
|
save(dayCut);
|
|
save(dayCut);
|
|
|
- if (StrUtil.equals("D",subject.getDirection())){
|
|
|
|
|
|
|
+ if (StrUtil.equals("D", subject.getDirection())) {
|
|
|
totalDebit = totalDebit.add(endAmount);
|
|
totalDebit = totalDebit.add(endAmount);
|
|
|
- } else if (StrUtil.equals("C",subject.getDirection())){
|
|
|
|
|
|
|
+ } else if (StrUtil.equals("C", subject.getDirection())) {
|
|
|
totalCredit = totalCredit.add(endAmount);
|
|
totalCredit = totalCredit.add(endAmount);
|
|
|
}
|
|
}
|
|
|
- if (StrUtil.startWith(subject.getAliases(),"1")){
|
|
|
|
|
|
|
+ if (StrUtil.startWith(subject.getAliases(), "1")) {
|
|
|
asset = asset.add(endAmount);
|
|
asset = asset.add(endAmount);
|
|
|
} else {
|
|
} else {
|
|
|
- if (StrUtil.equals("D",subject.getDirection())){
|
|
|
|
|
|
|
+ if (StrUtil.equals("D", subject.getDirection())) {
|
|
|
unAsset = unAsset.subtract(endAmount);
|
|
unAsset = unAsset.subtract(endAmount);
|
|
|
- } else if (StrUtil.equals("C",subject.getDirection())){
|
|
|
|
|
|
|
+ } else if (StrUtil.equals("C", subject.getDirection())) {
|
|
|
unAsset = unAsset.add(endAmount);
|
|
unAsset = unAsset.add(endAmount);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- //借贷平衡检查
|
|
|
|
|
- if (totalDebit.compareTo(totalCredit) != 0){
|
|
|
|
|
- log.error("[日切]借贷平衡检查,借贷平衡检查失败:totalDebit:"+totalDebit+",totalCredit:"+totalCredit);
|
|
|
|
|
|
|
+ // 借贷平衡检查
|
|
|
|
|
+ if (totalDebit.compareTo(totalCredit) != 0) {
|
|
|
|
|
+ log.error("[日切]借贷平衡检查,借贷平衡检查失败:totalDebit:" + totalDebit + ",totalCredit:" + totalCredit);
|
|
|
}
|
|
}
|
|
|
- //资产类=负责类+所有者权益+损益类 平衡检查
|
|
|
|
|
- if (asset.compareTo(unAsset) > 0){
|
|
|
|
|
- log.error("[日切]借贷平衡检查,资产类=负责类+所有者权益+损益类 平衡检查失败:asset:"+asset+",unAsset:"+unAsset);
|
|
|
|
|
|
|
+ // 资产类=负责类+所有者权益+损益类 平衡检查
|
|
|
|
|
+ if (asset.compareTo(unAsset) > 0) {
|
|
|
|
|
+ log.error("[日切]借贷平衡检查,资产类=负责类+所有者权益+损益类 平衡检查失败:asset:" + asset + ",unAsset:" + unAsset);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public DayCut findByDayAndSubjectId(String time, Integer subjectId) {
|
|
public DayCut findByDayAndSubjectId(String time, Integer subjectId) {
|
|
|
Condition condition = new Condition(DayCut.class);
|
|
Condition condition = new Condition(DayCut.class);
|
|
|
Example.Criteria criteria = condition.createCriteria();
|
|
Example.Criteria criteria = condition.createCriteria();
|
|
|
- criteria.andEqualTo("day",time);
|
|
|
|
|
- criteria.andEqualTo("subjectId",subjectId);
|
|
|
|
|
|
|
+ criteria.andEqualTo("day", time);
|
|
|
|
|
+ criteria.andEqualTo("subjectId", subjectId);
|
|
|
List<DayCut> dayCuts = findByCondition(condition);
|
|
List<DayCut> dayCuts = findByCondition(condition);
|
|
|
- if (CollUtil.isEmpty(dayCuts)){
|
|
|
|
|
|
|
+ if (CollUtil.isEmpty(dayCuts)) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
return dayCuts.get(0);
|
|
return dayCuts.get(0);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public BigDecimal sumAmount(Integer subjectId, String direction, String startTime,
|
|
public BigDecimal sumAmount(Integer subjectId, String direction, String startTime,
|
|
|
- String endTime) {
|
|
|
|
|
- Map<String,Object> map = new HashMap<>();
|
|
|
|
|
- map.put("subjectId",subjectId);
|
|
|
|
|
- map.put("direction",direction);
|
|
|
|
|
- map.put("startTime",startTime);
|
|
|
|
|
- map.put("endTime",endTime);
|
|
|
|
|
|
|
+ String endTime) {
|
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
|
+ map.put("subjectId", subjectId);
|
|
|
|
|
+ map.put("direction", direction);
|
|
|
|
|
+ map.put("startTime", startTime);
|
|
|
|
|
+ map.put("endTime", endTime);
|
|
|
return cDayCutMapper.sumAmount(map);
|
|
return cDayCutMapper.sumAmount(map);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|