|
@@ -8,7 +8,9 @@ import java.util.stream.Collectors;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.fs.common.constant.FsConstants;
|
|
|
import com.fs.common.core.domain.R;
|
|
import com.fs.common.core.domain.R;
|
|
|
|
|
+import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.common.utils.SecurityUtils;
|
|
import com.fs.common.utils.SecurityUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
import com.fs.common.utils.StringUtils;
|
|
@@ -46,6 +48,7 @@ import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.fs.company.service.ICompanyService;
|
|
import com.fs.company.service.ICompanyService;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+import org.springframework.transaction.support.TransactionTemplate;
|
|
|
|
|
|
|
|
import static com.fs.company.service.impl.CompanyMiniappServiceImpl.GET_MINI_APP_STR;
|
|
import static com.fs.company.service.impl.CompanyMiniappServiceImpl.GET_MINI_APP_STR;
|
|
|
|
|
|
|
@@ -97,6 +100,12 @@ public class CompanyServiceImpl implements ICompanyService
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private CompanyUserMapper companyUserMapper;
|
|
private CompanyUserMapper companyUserMapper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private RedisCache redisCache;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TransactionTemplate transactionTemplate;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public List<OptionsVO> selectAllCompanyList(Long deptId) {
|
|
public List<OptionsVO> selectAllCompanyList(Long deptId) {
|
|
|
return companyMapper.selectAllCompanyList(deptId);
|
|
return companyMapper.selectAllCompanyList(deptId);
|
|
@@ -1285,4 +1294,61 @@ public class CompanyServiceImpl implements ICompanyService
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @Description: 同步公司余额到数据库中
|
|
|
|
|
+ * @Param:
|
|
|
|
|
+ * @Return:
|
|
|
|
|
+ * @Author xgb
|
|
|
|
|
+ * @Date 2025/10/24 16:49
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void syncCompanyBalance() {
|
|
|
|
|
+ Company query = new Company();
|
|
|
|
|
+ query.setIsDel(0);
|
|
|
|
|
+ // 查询公司列表 同步公司余额
|
|
|
|
|
+ List<Company> companyList = companyMapper.selectCompanyList(query);
|
|
|
|
|
+ Optional.ofNullable(companyList)
|
|
|
|
|
+ .ifPresent(list -> list.forEach(company -> {
|
|
|
|
|
+ try {
|
|
|
|
|
+ transactionTemplate.execute(status -> {
|
|
|
|
|
+ String moneyStr = redisCache.getCacheObject(FsConstants.COMPANY_MONEY_KEY + company.getCompanyId());
|
|
|
|
|
+ if (StringUtils.isNotEmpty(moneyStr)) {
|
|
|
|
|
+ BigDecimal redisMoney = new BigDecimal(moneyStr);
|
|
|
|
|
+ BigDecimal dbMoney = company.getMoney();
|
|
|
|
|
+ BigDecimal amount = redisMoney.subtract(dbMoney); // 计算差额
|
|
|
|
|
+
|
|
|
|
|
+ // 只有当余额不一致时才更新
|
|
|
|
|
+ if (amount.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
|
|
+ company.setMoney(redisMoney);
|
|
|
|
|
+ int updateResult = companyMapper.updateCompany(company);
|
|
|
|
|
+ if(updateResult != 1){
|
|
|
|
|
+ logger.error("更新公司余额失败,公司ID: {}", company.getCompanyId());
|
|
|
|
|
+ throw new RuntimeException("更新公司余额失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 记录余额变更日志
|
|
|
|
|
+ CompanyMoneyLogs log = new CompanyMoneyLogs();
|
|
|
|
|
+ log.setCompanyId(company.getCompanyId());
|
|
|
|
|
+ log.setRemark("同步公司余额,差额: " + amount);
|
|
|
|
|
+ log.setMoney(amount);
|
|
|
|
|
+ log.setLogsType(15);
|
|
|
|
|
+ log.setBalance(redisMoney);
|
|
|
|
|
+ log.setCreateTime(new Date());
|
|
|
|
|
+
|
|
|
|
|
+ int logResult = moneyLogsMapper.insertCompanyMoneyLogs(log);
|
|
|
|
|
+ if(logResult != 1){
|
|
|
|
|
+ logger.error("添加公司余额日志失败,公司ID: {}", company.getCompanyId());
|
|
|
|
|
+ throw new RuntimeException("添加公司余额日志失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ });
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("同步公司余额失败,公司ID: {}", company.getCompanyId(), e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|