|
@@ -1,174 +0,0 @@
|
|
|
-package com.medipath.cif.dubbo.impl;
|
|
|
-
|
|
|
-import cn.hutool.core.bean.BeanUtil;
|
|
|
-import cn.hutool.core.collection.CollUtil;
|
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
-import com.medipath.cif.core.ResultCode;
|
|
|
-import com.medipath.cif.core.ResultGenerator;
|
|
|
-import com.medipath.cif.core.ServiceException;
|
|
|
-import com.medipath.cif.dto.OrgDTO;
|
|
|
-import com.medipath.cif.dto.SettleDTO;
|
|
|
-import com.medipath.cif.model.*;
|
|
|
-import com.medipath.cif.service.*;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.dubbo.config.annotation.Service;
|
|
|
-import tk.mybatis.mapper.entity.Condition;
|
|
|
-import tk.mybatis.mapper.entity.Example;
|
|
|
-
|
|
|
-import javax.annotation.Resource;
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-@Slf4j
|
|
|
-@Service
|
|
|
-public class SettleDubboServiceImpl implements SettleDubboService {
|
|
|
-
|
|
|
- @Resource
|
|
|
- private SettleInventoryService settleInventoryService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private SettleService settleService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private OrgService orgService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private OrgUserService orgUserService;
|
|
|
-
|
|
|
- @Override
|
|
|
- public BigDecimal getAmount(Long planId, Integer size, Integer sysType,
|
|
|
- Integer bizType) {
|
|
|
- Condition c = new Condition(SettleInventory.class);
|
|
|
- c.createCriteria().andEqualTo("planId",planId).andEqualTo("sysType",sysType)
|
|
|
- .andEqualTo("bizType",bizType)
|
|
|
- .andLessThanOrEqualTo("startSize",size)
|
|
|
- .andGreaterThanOrEqualTo("endSize",size);
|
|
|
- List<SettleInventory> inventories = settleInventoryService.findByCondition(c);
|
|
|
- if (CollUtil.isEmpty(inventories)){
|
|
|
- return null;
|
|
|
- }
|
|
|
- return inventories.get(0).getAmount();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void saveSettle(String month,List<SettleDTO> settles) {
|
|
|
- Condition c = new Condition(Settle.class);
|
|
|
- c.createCriteria().andEqualTo("month",month);
|
|
|
- List<Settle> settleList = settleService.findByCondition(c);
|
|
|
- if (CollUtil.isNotEmpty(settleList)){
|
|
|
- throw new ServiceException(ResultCode.SETTLE_HAVE_DATA);
|
|
|
- }
|
|
|
- c = new Condition(Org.class);
|
|
|
- c.createCriteria().andEqualTo("status",1);
|
|
|
- List<Org> orgs = orgService.findByCondition(c);
|
|
|
- if (CollUtil.isEmpty(orgs)){
|
|
|
- return;
|
|
|
- }
|
|
|
- Date now = DateUtil.date();
|
|
|
- List<Settle> save = new ArrayList<>();
|
|
|
- for (Org org:orgs) {
|
|
|
- if (org.getType() == 1){
|
|
|
- c = new Condition(OrgUser.class);
|
|
|
- c.createCriteria().andEqualTo("orgId",org.getId());
|
|
|
- List<OrgUser> orgUsers =orgUserService.findByCondition(c);
|
|
|
- if (CollUtil.isEmpty(orgUsers)){
|
|
|
- continue;
|
|
|
- }
|
|
|
- for (OrgUser orgUser:orgUsers) {
|
|
|
- //请求获取结算数据
|
|
|
- //flag = 已有数据
|
|
|
- Boolean flag = false;
|
|
|
- if (CollUtil.isNotEmpty(settles)){
|
|
|
- for (SettleDTO temp:settles ) {
|
|
|
- if (temp.getOrgId().compareTo(orgUser.getOrgId())== 0
|
|
|
- && temp.getUserId().compareTo(orgUser.getUserId())==0){
|
|
|
- save.add(Settle.builder().createTime(now)
|
|
|
- .finishAmount(temp.getFinishAmount())
|
|
|
- .finishSize(temp.getFinishSize())
|
|
|
- .month(month)
|
|
|
- .orgId(orgUser.getOrgId())
|
|
|
- .userId(orgUser.getUserId())
|
|
|
- .updateTime(now)
|
|
|
- .status(1)
|
|
|
- .build());
|
|
|
- flag = true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (!flag){
|
|
|
- save.add(Settle.builder().createTime(now)
|
|
|
- .finishAmount(BigDecimal.ZERO)
|
|
|
- .finishSize(0)
|
|
|
- .month(month)
|
|
|
- .orgId(orgUser.getOrgId())
|
|
|
- .userId(orgUser.getUserId())
|
|
|
- .updateTime(now)
|
|
|
- .status(2)
|
|
|
- .build());
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- //请求获取结算数据
|
|
|
- Boolean flag = false;
|
|
|
- for (SettleDTO temp:settles ) {
|
|
|
- if (temp.getOrgId().compareTo(org.getId())== 0
|
|
|
- && temp.getUserId().compareTo(org.getUserId())==0){
|
|
|
- save.add(Settle.builder().createTime(now)
|
|
|
- .finishAmount(temp.getFinishAmount())
|
|
|
- .finishSize(temp.getFinishSize())
|
|
|
- .month(month)
|
|
|
- .orgId(org.getId())
|
|
|
- .userId(org.getUserId())
|
|
|
- .updateTime(now)
|
|
|
- .status(1)
|
|
|
- .build());
|
|
|
- flag = true;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!flag){
|
|
|
- save.add(Settle.builder().createTime(now)
|
|
|
- .finishAmount(BigDecimal.ZERO)
|
|
|
- .finishSize(0)
|
|
|
- .month(month)
|
|
|
- .orgId(org.getId())
|
|
|
- .userId(org.getUserId())
|
|
|
- .updateTime(now)
|
|
|
- .status(2)
|
|
|
- .build());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (CollUtil.isNotEmpty(save)){
|
|
|
- settleService.save(save);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<SettleDTO> settleList(Long orgId, Long userId, String year, String orderby) {
|
|
|
-
|
|
|
- Condition condition = new Condition(Settle.class);
|
|
|
- Example.Criteria criteria = condition.createCriteria();
|
|
|
- if (orgId!= null){
|
|
|
- criteria.andEqualTo("orgId", orgId);
|
|
|
- }
|
|
|
- if (userId!= null){
|
|
|
- criteria.andEqualTo("userId", userId);
|
|
|
- }
|
|
|
- if (StrUtil.isNotBlank(year)){
|
|
|
- criteria.andGreaterThanOrEqualTo("month",year+"-01-01 00:00:00");
|
|
|
- criteria.andLessThanOrEqualTo("month",year+"-12-31 23:59:59");
|
|
|
- }
|
|
|
- if (StrUtil.isNotBlank(orderby)){
|
|
|
- condition.setOrderByClause(orderby);
|
|
|
- }
|
|
|
- List<Settle> list = settleService.findByCondition(condition);
|
|
|
- if (CollUtil.isEmpty(list)){
|
|
|
- return null;
|
|
|
- }
|
|
|
- return list.stream().map(temp -> BeanUtil.toBean(temp,SettleDTO.class)).collect(Collectors.toList());
|
|
|
- }
|
|
|
-}
|