| | |
| | | import me.zhengjie.exception.BadRequestException; |
| | | import me.zhengjie.modules.capital.domain.CapitalAccountCompany; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.utils.ValidationUtil; |
| | | import me.zhengjie.utils.FileUtil; |
| | | import me.zhengjie.utils.*; |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.zhengjie.modules.capital.repository.CapitalAccountCompanyRepository; |
| | | import me.zhengjie.modules.capital.service.CapitalAccountCompanyService; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | import me.zhengjie.utils.PageUtil; |
| | | import me.zhengjie.utils.QueryHelp; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.io.IOException; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | |
| | | /** |
| | | * @website https://eladmin.vip |
| | |
| | | |
| | | @Override |
| | | public Map<String,Object> queryAll(CapitalAccountCompanyQueryCriteria criteria, Pageable pageable){ |
| | | if (criteria.getAccountYear() != null && !"".equals(criteria.getAccountYear())) { |
| | | criteria.setAccountYear(DateUtil.internationalTimeToChinaTime(criteria.getAccountYear()).substring(0,4)); |
| | | } |
| | | Page<CapitalAccountCompany> page = capitalAccountCompanyRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); |
| | | return PageUtil.toPage(page.map(capitalAccountCompanyMapper::toDto)); |
| | | } |
| | |
| | | List<CapitalAccountCompany> capitalAccountCompanyList = capitalAccountCompanyRepository.findByProjectDistinguishAndAccountTypeAndAccountYear(resources.getProjectDistinguish(), resources.getAccountType(), resources.getAccountYear()); |
| | | // 判断结果集长度 |
| | | if (capitalAccountCompanyList.size() > 1) { |
| | | throw new BadRequestException("每个年度同类型公司流账户只能有一个!"); |
| | | throw new BadRequestException("每个年度项目区分+账户类型组合公司流账户只能有一个!"); |
| | | } else if (capitalAccountCompanyList.size() == 1) { |
| | | if (resources.getId() == null || capitalAccountCompanyList.get(0).getId().longValue() != resources.getId().longValue()) { |
| | | throw new BadRequestException("每个年度同类型公司流账户只能有一个!"); |
| | | throw new BadRequestException("每个年度项目区分+账户类型组合公司流账户只能有一个!"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 关联年度资金公司流账户 |
| | | * @return |
| | | */ |
| | | public CapitalAccountCompanyDto relevanceCapitalAccountCompany(String accountType) { |
| | | // 当前系统时间 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | // 年度资金账户(公司流)检索类 |
| | | CapitalAccountCompanyQueryCriteria criteria = new CapitalAccountCompanyQueryCriteria(); |
| | | criteria.setAccountType(accountType); |
| | | criteria.setAccountYear(DateUtil.getYear(calendar)); |
| | | // 查询年度资金账户(公司流) |
| | | List<CapitalAccountCompanyDto> capitalAccountCompanyDtoList = capitalAccountCompanyMapper.toDto(capitalAccountCompanyRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); |
| | | // 判断年度资金账户(公司流) |
| | | if (capitalAccountCompanyDtoList.size() == 0) { |
| | | throw new BadRequestException("没有找到对应的年度资金公司流账户!"); |
| | | } else if (capitalAccountCompanyDtoList.size() > 1) { |
| | | throw new BadRequestException("找到多条对应的年度资金公司流账户!"); |
| | | } |
| | | return capitalAccountCompanyDtoList.get(0); |
| | | } |
| | | |
| | | /** |
| | | * 关联年度资金公司流账户(增加金额) |
| | | * @param capitalAccountCompanyDto |
| | | * @param amount |
| | | */ |
| | | public void relevanceCapitalAccountCompanyAdd(CapitalAccountCompanyDto capitalAccountCompanyDto, BigDecimal amount) { |
| | | // 账户金额 |
| | | BigDecimal accountAmount = capitalAccountCompanyDto.getAccountAmount(); |
| | | accountAmount = accountAmount.add(amount); |
| | | capitalAccountCompanyDto.setAccountAmount(accountAmount); |
| | | // 保存 |
| | | capitalAccountCompanyRepository.save(capitalAccountCompanyMapper.toEntity(capitalAccountCompanyDto)); |
| | | } |
| | | |
| | | /** |
| | | * 关联年度资金公司流账户(减少金额) |
| | | * @param capitalAccountCompanyDto |
| | | * @param amount |
| | | */ |
| | | public void relevanceCapitalAccountCompanySubtract(CapitalAccountCompanyDto capitalAccountCompanyDto, BigDecimal amount) { |
| | | // 账户金额 |
| | | BigDecimal accountAmount = capitalAccountCompanyDto.getAccountAmount(); |
| | | accountAmount = accountAmount.subtract(amount); |
| | | capitalAccountCompanyDto.setAccountAmount(accountAmount); |
| | | // 保存 |
| | | capitalAccountCompanyRepository.save(capitalAccountCompanyMapper.toEntity(capitalAccountCompanyDto)); |
| | | } |
| | | } |