浏览代码

Merge remote-tracking branch 'origin/master'

caozj 1 年之前
父节点
当前提交
0d8f30d708

+ 103 - 12
hx-account/src/main/java/com/fjhx/account/service/account/impl/AccountRunningWaterServiceImpl.java

@@ -259,25 +259,116 @@ public class AccountRunningWaterServiceImpl extends ServiceImpl<AccountRunningWa
      * 账户资金流水表编辑
      */
     @Override
-    @Transactional(rollbackFor = {Exception.class})
+    @DSTransactional
     public void edit(AccountRunningWater accountRunningWaterDto) {
-        //        //查询资金流水表的数据
-        //        AccountRunningWater accountRunningWater = this.getById(accountRunningWaterDto.getId());
-        //
-        //        //修改账户余额表的余额
-        //        AccountRemainder accountRemainder = accountRemainderService.getOne(Wrappers.<AccountRemainder>lambdaQuery()
-        //                .eq(AccountRemainder::getAccountManagementId,accountRunningWater.getAccountManagementId())
-        //                .eq(AccountRemainder::getCurrency,accountRunningWater.getCurrency())
-        //        );
-        //        if (accountRemainder.getStatus().equals("10")){
-        //            if (accountRemainder.getRemainder().compareTo(accountRunningWater.getAmount())==1)
-        //        }
+        //先回滚历史数据
+        //获取历史的流水信息信息
+        AccountRunningWater oldAccountRunningWater = getById(accountRunningWaterDto.getId());
+        //获取余额
+        AccountRemainder accountRemainder = accountRemainderService.getOne(q -> q
+                .eq(AccountRemainder::getAccountManagementId, oldAccountRunningWater.getAccountManagementId())
+                .eq(AccountRemainder::getCurrency, oldAccountRunningWater.getCurrency())
+        );
+        if (ObjectUtil.isEmpty(accountRemainder)) {
+            throw new ServiceException("历史数据 该账户不存在此币种,请前往资金账户添加");
+        }
+        boolean update = false;
+        if ("10".equals(oldAccountRunningWater.getStatus())) {
+            BigDecimal subtract = accountRemainder.getRemainder().subtract(oldAccountRunningWater.getAmount());
+            if (subtract.compareTo(BigDecimal.ZERO) < 0) {
+                throw new ServiceException("修改前数据 账户余额不足");
+            }
+            update = accountRemainderService.update(q -> q
+                    .setSql("remainder = remainder - " + oldAccountRunningWater.getAmount())
+                    .setSql("change_remainder = " + oldAccountRunningWater.getAmount())
+                    .eq(AccountRemainder::getId, accountRemainder.getId())
+                    .apply("remainder - {0} >= 0", oldAccountRunningWater.getAmount())
+            );
+        } else {
+            update = accountRemainderService.update(q -> q
+                    .setSql("remainder = remainder + " + oldAccountRunningWater.getAmount())
+                    .setSql("change_remainder = " + oldAccountRunningWater.getAmount())
+                    .eq(AccountRemainder::getId, accountRemainder.getId())
+            );
+        }
+        Assert.eqTrue(update, "余额回滚操作失败");
+        //再操作修改后数据
+        //获取余额
+        AccountRemainder accountRemainder1 = accountRemainderService.getOne(q -> q
+                .eq(AccountRemainder::getAccountManagementId, accountRunningWaterDto.getAccountManagementId())
+                .eq(AccountRemainder::getCurrency, accountRunningWaterDto.getCurrency())
+        );
+        if (ObjectUtil.isEmpty(accountRemainder)) {
+            throw new ServiceException("修改后数据 该账户不存在此币种,请前往资金账户添加");
+        }
+        boolean update1 = false;
+        if ("10".equals(accountRunningWaterDto.getStatus())) {
+            update1 = accountRemainderService.update(q -> q
+                    .setSql("remainder = remainder + " + accountRunningWaterDto.getAmount())
+                    .setSql("change_remainder = " + accountRunningWaterDto.getAmount())
+                    .eq(AccountRemainder::getId, accountRemainder1.getId())
+            );
+        } else {
+            BigDecimal subtract = accountRemainder1.getRemainder().subtract(accountRunningWaterDto.getAmount());
+            if (subtract.compareTo(BigDecimal.ZERO) < 0) {
+                throw new ServiceException("修改后数据 账户余额不足");
+            }
+            update1 = accountRemainderService.update(q -> q
+                    .setSql("remainder = remainder - " + accountRunningWaterDto.getAmount())
+                    .setSql("change_remainder = " + accountRunningWaterDto.getAmount())
+                    .eq(AccountRemainder::getId, accountRemainder1.getId())
+                    .apply("remainder - {0} >= 0", accountRunningWaterDto.getAmount())
+            );
+        }
+        Assert.eqTrue(update1, "余额修改操作失败");
 
         this.updateById(accountRunningWaterDto);
     }
 
+    @DSTransactional
     @Override
     public void delete(Long id) {
+        AccountRunningWater accountRunningWater = getById(id);
+        Assert.notEmpty(accountRunningWater, "获取不到该流水信息");
+
+
+        // 修改账户余额表的余额
+        AccountRemainder accountRemainder = accountRemainderService.getOne(q -> q
+                .eq(AccountRemainder::getAccountManagementId, accountRunningWater.getAccountManagementId())
+                .eq(AccountRemainder::getCurrency, accountRunningWater.getCurrency())
+        );
+        if (ObjectUtil.isEmpty(accountRemainder)) {
+            throw new ServiceException("该账户不存在此币种,请前往资金账户添加");
+        }
+        BigDecimal amount = accountRunningWater.getAmount();
+        String status = accountRunningWater.getStatus();
+        BigDecimal remainder = accountRemainder.getRemainder();
+
+        accountRemainder.setStatus(status);
+        accountRemainder.setChangeRemainder(amount);
+
+        boolean update = false;
+        if ("10".equals(accountRunningWater.getStatus())) {
+            BigDecimal subtract = remainder.subtract(amount);
+            if (subtract.compareTo(BigDecimal.ZERO) < 0) {
+                throw new ServiceException("账户余额不足");
+            }
+
+            update = accountRemainderService.update(q -> q
+                    .setSql("remainder = remainder - " + accountRunningWater.getAmount())
+                    .setSql("change_remainder = " + accountRunningWater.getAmount())
+                    .eq(AccountRemainder::getId, accountRemainder.getId())
+                    .apply("remainder - {0} >= 0", accountRunningWater.getAmount())
+            );
+        } else {
+            update = accountRemainderService.update(q -> q
+                    .setSql("remainder = remainder + " + accountRunningWater.getAmount())
+                    .setSql("change_remainder = " + accountRunningWater.getAmount())
+                    .eq(AccountRemainder::getId, accountRemainder.getId())
+            );
+        }
+        Assert.eqTrue(update, "余额操作失败操作失败");
+
         this.removeById(id);
     }
 

+ 2 - 2
hx-admin/src/main/resources/application-dev.yml

@@ -103,8 +103,8 @@ spring:
 
 mail:
     # 调用邮箱服务url前缀
-    urlPrefix: http://localhost:8088/mailService/
-    abroadUrlPrefix: http://localhost:8088/mailService/
+    urlPrefix:
+    abroadUrlPrefix:
 
 hx:
     httpUrl: http://localhost:9898/

+ 2 - 1
hx-admin/src/main/resources/application-prod.yml

@@ -104,7 +104,8 @@ server:
 mail:
     # 调用邮箱服务url前缀
     urlPrefix: http://localhost:8088/mailService/
-    abroadUrlPrefix: http://159.138.54.234:8088/mailService/
+    abroadUrlPrefix:
+    #abroadUrlPrefix: http://159.138.54.234:8088/mailService/
 
 hx:
     httpUrl: http://139.159.251.109:81/prod-api/

+ 1 - 1
hx-admin/src/main/resources/application-test.yml

@@ -104,7 +104,7 @@ server:
 
 mail:
     # 调用邮箱服务url前缀
-    urlPrefix: http://localhost:8088/mailService/
+    urlPrefix:
     abroadUrlPrefix:
 
 hx:

+ 36 - 31
hx-item/src/main/java/com/fjhx/item/service/product/impl/ProductInfoServiceImpl.java

@@ -181,7 +181,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
             //将部门id转为字符串(帮助解决前端问题)
             json.put("deptId", json.getString("deptId"));
 
-            record.setVictoriatouristJson(JSONObject.toJSONString(json,JSONWriter.Feature.WriteLongAsString));
+            record.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
         }
 
         return page;
@@ -231,7 +231,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         List<Long> customerIds = new ArrayList<>();
         for (ProductInfoVo record : records) {
             ProductInfoEhsdJson productInfoEhsdJson = JSONObject.parseObject(record.getEhsdJson(), ProductInfoEhsdJson.class);
-            if(ObjectUtil.isNotEmpty(productInfoEhsdJson.getCustomerId())) {
+            if (ObjectUtil.isNotEmpty(productInfoEhsdJson.getCustomerId())) {
                 customerIds.add(Long.parseLong(productInfoEhsdJson.getCustomerId()));
             }
         }
@@ -239,9 +239,13 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
             Map<Long, String> customerMap = customerService.mapKV(Customer::getId, Customer::getName, q -> q.in(Customer::getId, customerIds));
             for (ProductInfoVo record : records) {
                 ProductInfoEhsdJson productInfoEhsdJson = JSONObject.parseObject(record.getEhsdJson(), ProductInfoEhsdJson.class);
-                String customerName = customerMap.get(Long.parseLong(productInfoEhsdJson.getCustomerId()));
-                productInfoEhsdJson.setCustomerName(customerName);
-                record.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson,JSONWriter.Feature.WriteLongAsString));
+
+                String customerId = productInfoEhsdJson.getCustomerId();
+                if (ObjectUtil.isNotEmpty(customerId)) {
+                    String customerName = customerMap.get(Long.parseLong(customerId));
+                    productInfoEhsdJson.setCustomerName(customerName);
+                }
+                record.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson, JSONWriter.Feature.WriteLongAsString));
             }
         }
         //赋值创建人名称
@@ -262,27 +266,27 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         //赋值维多利亚组合产品信息
         JSONObject json = JSONObject.parseObject(result.getVictoriatouristJson());
         List<Long> ids = new ArrayList<>();
-        if(ObjectUtil.isNotEmpty(json) && ObjectUtil.isNotEmpty(json.getJSONArray("productCombinationList"))){
+        if (ObjectUtil.isNotEmpty(json) && ObjectUtil.isNotEmpty(json.getJSONArray("productCombinationList"))) {
             JSONArray productCombinationList = json.getJSONArray("productCombinationList");
-            for (int i=0;i<productCombinationList.size();i++) {
+            for (int i = 0; i < productCombinationList.size(); i++) {
                 JSONObject item = productCombinationList.getJSONObject(i);
                 ids.add(item.getLong("linkProductId"));
             }
-            if(ObjectUtil.isNotEmpty(ids)){
+            if (ObjectUtil.isNotEmpty(ids)) {
                 List<ProductInfo> productInfoList = this.listByIds(ids);
                 Map<Long, ProductInfo> productInfoMap = productInfoList.stream().collect(Collectors.toMap(ProductInfo::getId, Function.identity()));
                 JSONArray jsonArray = new JSONArray();
-                for (int i=0;i<productCombinationList.size();i++) {
+                for (int i = 0; i < productCombinationList.size(); i++) {
                     JSONObject item = productCombinationList.getJSONObject(i);
                     ProductInfo productInfo1 = productInfoMap.get(item.getLong("linkProductId"));
-                    if(ObjectUtil.isNotEmpty(productInfo1)) {
-                        item.put("code",productInfo1.getCode());
-                        item.put("customCode",productInfo1.getCustomCode());
-                        item.put("name",productInfo1.getName());
+                    if (ObjectUtil.isNotEmpty(productInfo1)) {
+                        item.put("code", productInfo1.getCode());
+                        item.put("customCode", productInfo1.getCustomCode());
+                        item.put("name", productInfo1.getName());
                     }
                     jsonArray.add(item);
                 }
-                json.put("productCombinationList",jsonArray);
+                json.put("productCombinationList", jsonArray);
                 result.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
             }
         }
@@ -328,7 +332,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
             productInfoEhsdJson.setCustomerId("0");
             productInfoEhsdJson.setType("1");//默认公司产品
         }
-        productInfoDto.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson,JSONWriter.Feature.WriteLongAsString));
+        productInfoDto.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson, JSONWriter.Feature.WriteLongAsString));
 
         // 赋值产品编号
         productInfoDto.setCode(CodeEnum.PRODUCT.getCode());
@@ -357,7 +361,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         productInfoEhsdJson.setNetWeight(newProductInfoEhsdJson.getNetWeight());//净重
 
         productInfo.setRemark(productInfoDto.getRemark());//备注
-        productInfo.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson,JSONWriter.Feature.WriteLongAsString));
+        productInfo.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson, JSONWriter.Feature.WriteLongAsString));
         this.updateById(productInfo);
         //修改图片
         ObsFileUtil.editFile(productInfoDto.getFileList(), productInfoDto.getId());
@@ -375,7 +379,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
             Customer customer = customerService.getById(productInfoEhsdJson.getCustomerId());
             if (ObjectUtil.isNotEmpty(customer)) {
                 productInfoEhsdJson.setCustomerName(customer.getName());
-                result.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson,JSONWriter.Feature.WriteLongAsString));
+                result.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson, JSONWriter.Feature.WriteLongAsString));
             }
         }
         //赋值创建人名称
@@ -446,7 +450,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
                 }
                 productInfoEhsdJson.setOuterPackMethod(String.join(",", split));
             }
-            productInfo.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson,JSONWriter.Feature.WriteLongAsString));
+            productInfo.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson, JSONWriter.Feature.WriteLongAsString));
             productInfoList.add(productInfo);
         }
         saveBatch(productInfoList);
@@ -460,7 +464,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         if (ObjectUtil.isNotEmpty(victoriatouristJson)) {
             JSONObject json = JSONObject.parseObject(victoriatouristJson);
             json.put("deptId", SecurityUtils.getDeptId());
-            productInfoDto.setVictoriatouristJson(JSONObject.toJSONString(json,JSONWriter.Feature.WriteLongAsString));
+            productInfoDto.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
         }
         add(productInfoDto);
     }
@@ -516,8 +520,8 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
      * @return
      */
     @Override
-    public List<ProductInfoVo> getListByProductType(Integer productType, Integer definition,String productName,String productCode) {
-        return baseMapper.getListByProductType(productType, definition,productName,productCode);
+    public List<ProductInfoVo> getListByProductType(Integer productType, Integer definition, String productName, String productCode) {
+        return baseMapper.getListByProductType(productType, definition, productName, productCode);
     }
 
     @Override
@@ -531,7 +535,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         String victoriatouristJson = productInfo.getVictoriatouristJson();
         JSONObject json = ObjectUtil.isNotEmpty(victoriatouristJson) ? JSONObject.parseObject(victoriatouristJson) : new JSONObject();
         json.put("deptId", productInfoDto.getDeptId());
-        productInfo.setVictoriatouristJson(JSONObject.toJSONString(json,JSONWriter.Feature.WriteLongAsString));
+        productInfo.setVictoriatouristJson(JSONObject.toJSONString(json, JSONWriter.Feature.WriteLongAsString));
         updateById(productInfo);
     }
 
@@ -734,6 +738,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
 
     /**
      * 产品统计
+     *
      * @return
      */
     @Override
@@ -745,9 +750,9 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
      * 产品库统计(根据产品库类型进行分类统计)
      */
     @Override
-    public  Map<String,Object> productInfoStatistics(ProductInfoSelectDto dto) {
+    public Map<String, Object> productInfoStatistics(ProductInfoSelectDto dto) {
         //存放产品库统计数据
-        Map<String,Object> map = new HashMap<>();
+        Map<String, Object> map = new HashMap<>();
 
         //存放产品分类统计数据
         List<Map<String, Object>> list = new ArrayList<>();
@@ -760,30 +765,30 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         //计算统计合计
         Integer amount = productInfos.stream().map(productInfo -> productInfo.getCount()).reduce(Integer::sum).orElse(0);
 
-        map.put("amount",amount);
+        map.put("amount", amount);
         //获取产品类型统计数据
         DynamicDataSourceContextHolder.push(SourceConstant.BASE);
         List<DictTenantDataVo> dictTenantDataVoList = getDict("product_type");
         DynamicDataSourceContextHolder.poll();
-        if (dictTenantDataVoList.size()==0){
+        if (dictTenantDataVoList.size() == 0) {
             throw new ServiceException("数据异常:产品没有设置产品类型字典,请先添加");
         }
 
         for (DictTenantDataVo dictTenantDataVo : dictTenantDataVoList) {
             Map typeMap = new HashMap();
             //设置初始值
-            typeMap.put("type",dictTenantDataVo.getDictValue());
-            typeMap.put("count",0);
+            typeMap.put("type", dictTenantDataVo.getDictValue());
+            typeMap.put("count", 0);
 
             //赋值
             List<ProductInfo> productInfoList = productInfoMap.get(dictTenantDataVo.getDictKey());
-            if (CollectionUtils.isNotEmpty(productInfoList)){
-                typeMap.put("count",productInfoList.get(0).getCount());
+            if (CollectionUtils.isNotEmpty(productInfoList)) {
+                typeMap.put("count", productInfoList.get(0).getCount());
             }
             list.add(typeMap);
 
         }
-        map.put("typeList",list);
+        map.put("typeList", list);
         return map;
     }
 

+ 1 - 1
hx-mail/src/main/java/com/fjhx/mail/listener/LoginEventListeners.java

@@ -43,7 +43,7 @@ public class LoginEventListeners {
                     MailHttpUtil.abroadUserLogin(userId);
                     num = 3;
                 } catch (Exception e) {
-                    log.error("同步邮件服务用户登录失败", e);
+                    log.error("同步海外邮件服务用户登录失败", e);
                     num++;
                 }
             }

+ 3 - 1
hx-sale/src/main/java/com/fjhx/sale/flow/ContractFlow.java

@@ -71,6 +71,9 @@ public class ContractFlow extends FlowDelegate {
         if(StringUtils.isEmpty(contract.getCurrency())){
             throw new ServiceException("币种不能为空");
         }
+
+        contract.setCode(codingRuleService.createCode(CodingRuleEnum.CONTRACT.getKey(), contract.getBuyCorporationId()));
+
         // 保存合同产品
         List<ContractProduct> contractProductList = contract.getContractProductList();
 
@@ -118,7 +121,6 @@ public class ContractFlow extends FlowDelegate {
         CustomizeAreaUtil.setAreaId(contract);
 
         contract.setId(contractId);
-        contract.setCode(codingRuleService.createCode(CodingRuleEnum.CONTRACT.getKey(), contract.getBuyCorporationId()));
         contract.setUserName(SecurityUtils.getUsername());
         contract.setStatus(FlowStatusEnum.UNDER_REVIEW.getKey());
         contract.setBuyCityId(contract.getCityId());

+ 20 - 9
hx-sale/src/main/java/com/fjhx/sale/flow/ContractUpdateFlow.java

@@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.fjhx.common.enums.FlowStatusEnum;
+import com.fjhx.common.utils.Assert;
 import com.fjhx.flow.core.FlowDelegate;
 import com.fjhx.sale.entity.contract.dto.ContractDto;
 import com.fjhx.sale.entity.contract.po.Contract;
@@ -19,6 +20,8 @@ import java.math.BigDecimal;
 import java.util.List;
 import java.util.Map;
 import java.util.function.Function;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 /**
@@ -59,6 +62,19 @@ public class ContractUpdateFlow extends FlowDelegate {
             throw new ServiceException("原合同id不能为空");
         }
 
+        //变更 用原来合同号加后缀
+        Contract oldContract = contractService.getById(contract.getOldContractId());
+        Assert.notEmpty(oldContract, "查询不到原合同信息");
+        String code = oldContract.getCode();
+        Matcher matcher = Pattern.compile(".*\\((.*?)\\)$").matcher(code);
+        int index = 2;
+        if (matcher.find()) {
+            index = (Integer.parseInt(matcher.group(1)) + 1);
+            code = code.substring(0, code.lastIndexOf("("));
+        }
+        contract.setCode(code + "(" + index + ")");
+
+
         List<ContractProduct> list = contractProductService.list(q -> q.eq(ContractProduct::getContractId, oldContractId));
 
         // 赋值待处理数量
@@ -72,21 +88,16 @@ public class ContractUpdateFlow extends FlowDelegate {
 
             Map<Long, ContractProduct> contractProductMap = contractProductList
                     .stream()
-                    .peek(item -> {
-                        if (item.getId() == null) {
-                            throw new ServiceException("合同产品id不能为空");
-                        }
-                    })
+                    .filter(item -> ObjectUtil.isNotEmpty(item.getId()))
                     .collect(Collectors.toMap(BaseIdPo::getId, Function.identity()));
 
 
             for (ContractProduct item : list) {
                 ContractProduct contractProduct = contractProductMap.get(item.getId());
-                if (contractProduct == null) {
-                    throw new ServiceException("产品id为" + item.getId() + "未上传");
+                if (ObjectUtil.isNotEmpty(contractProduct)) {
+                    BigDecimal expendQuantity = item.getExpendQuantity().subtract(item.getQuantity().subtract(contractProduct.getQuantity()));
+                    contractProduct.setExpendQuantity(expendQuantity);
                 }
-                BigDecimal expendQuantity = item.getExpendQuantity().subtract(item.getQuantity().subtract(contractProduct.getQuantity()));
-                contractProduct.setExpendQuantity(expendQuantity);
             }
 
         }