22 changed files with 1439 additions and 92 deletions
@ -0,0 +1,157 @@ |
|||||
|
package com.qs.serve.common.util; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.TableField; |
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
import com.microsoft.sqlserver.jdbc.SQLServerBulkCopy; |
||||
|
import com.microsoft.sqlserver.jdbc.SQLServerBulkCopyOptions; |
||||
|
import com.sun.rowset.CachedRowSetImpl; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.apache.ibatis.type.JdbcType; |
||||
|
import org.springframework.beans.factory.annotation.Value; |
||||
|
|
||||
|
import java.lang.reflect.Field; |
||||
|
import java.math.BigDecimal; |
||||
|
import java.sql.*; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* SQL Server工具类 |
||||
|
* @author Trouble |
||||
|
* @version 1.0 |
||||
|
* @since 2024-04-25 15:00 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
public class SqlServerUtil { |
||||
|
|
||||
|
/** |
||||
|
* 批量插入数据库 |
||||
|
* |
||||
|
* @param connectionUrl 数据库连接地址 |
||||
|
* @param list 要保存的对象集 |
||||
|
* @throws SQLException 插入对象失败 |
||||
|
*/ |
||||
|
public static <T> void batchInsert(String connectionUrl, List<T> list) throws SQLException, IllegalAccessException { |
||||
|
long start = System.currentTimeMillis(); |
||||
|
String tableName = null; |
||||
|
//获取表名
|
||||
|
for (T t : list) { |
||||
|
TableName tableNameAnnotation = t.getClass().getAnnotation(TableName.class); |
||||
|
tableName = tableNameAnnotation.value(); |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
CachedRowSetImpl crs = getCachedRowSet(connectionUrl, tableName); |
||||
|
// 将对象转化为行数据
|
||||
|
for (Object obj : list) { |
||||
|
// 以动指针到插入行(虚拟行)
|
||||
|
crs.moveToInsertRow(); |
||||
|
// 设置虚拟行相应的字段与数值;注意:字符串中的字段名与类型要与数据表中的一致
|
||||
|
Field[] declaredFields = obj.getClass().getDeclaredFields(); |
||||
|
for (Field field : declaredFields) { |
||||
|
|
||||
|
if(field.getName().equals("serialVersionUID")){ |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
field.setAccessible(true); |
||||
|
|
||||
|
TableField tableField = field.getAnnotation(TableField.class); |
||||
|
String fieldName; |
||||
|
// 如果字段名不存在,则跳过
|
||||
|
// 如果字段名为空,则使用默认字段名称
|
||||
|
if (tableField != null) { |
||||
|
if (!tableField.exist()) { |
||||
|
continue; |
||||
|
} |
||||
|
fieldName = tableField.value(); |
||||
|
} else { |
||||
|
fieldName = field.getName(); |
||||
|
} |
||||
|
Object fieldValue = field.get(obj); |
||||
|
|
||||
|
if (tableField != null && tableField.jdbcType().equals(JdbcType.FLOAT)) { |
||||
|
crs.updateBigDecimal(fieldName, (BigDecimal) fieldValue); |
||||
|
} |
||||
|
else { |
||||
|
crs.updateObject(fieldName, fieldValue); |
||||
|
} |
||||
|
} |
||||
|
// 将虚拟行插入缓存
|
||||
|
crs.insertRow(); |
||||
|
// 将指针移动到当前行
|
||||
|
crs.moveToCurrentRow(); |
||||
|
} |
||||
|
saveRows(connectionUrl, tableName, crs, list.size()); |
||||
|
long end = System.currentTimeMillis(); |
||||
|
log.info("批量插入数据表{}成功,数量:{}条,耗时:{}ms", tableName, list.size(), end - start); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取数据表的结构 |
||||
|
* |
||||
|
* @param url 链接对象 |
||||
|
* @param tableName 表名字 |
||||
|
* @return 数据表字段初始化的数据对象 |
||||
|
* @throws SQLException 数据表字段初始化失败 |
||||
|
*/ |
||||
|
public static CachedRowSetImpl getCachedRowSet(String url, String tableName) throws SQLException { |
||||
|
// 链接方式固定(配置)
|
||||
|
Connection con = connection(url); |
||||
|
String sql = String.format("select * from %s where 1 = 0", tableName); |
||||
|
// 执行sql语句封装
|
||||
|
PreparedStatement ps = con.prepareStatement(sql); |
||||
|
// 执行语句
|
||||
|
ResultSet rs = ps.executeQuery(); |
||||
|
// 创建行操作对象
|
||||
|
CachedRowSetImpl crs = new CachedRowSetImpl(); |
||||
|
// 设置表字段
|
||||
|
crs.populate(rs); |
||||
|
// 关闭流资源
|
||||
|
rs.close(); |
||||
|
// 关闭数据库链接
|
||||
|
con.close(); |
||||
|
// 返回含有表字段的行操作对象
|
||||
|
return crs; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 连接数据库 |
||||
|
* |
||||
|
* @param connectionUrl 链接URL |
||||
|
* @return 链接对象 |
||||
|
* @throws SQLException 建立链接失败异常 |
||||
|
*/ |
||||
|
public static Connection connection(String connectionUrl) throws SQLException { |
||||
|
return DriverManager.getConnection(connectionUrl); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 将数据插入数据库 |
||||
|
* |
||||
|
* @param connectionUrl 数据库连接地址 |
||||
|
* @param tableName 数据表名称 |
||||
|
* @param crs 数据行操作对象 |
||||
|
* @param size 数据量 |
||||
|
* @throws SQLException 插入数据失败异常 |
||||
|
*/ |
||||
|
public static void saveRows(String connectionUrl, String tableName, CachedRowSetImpl crs, int size) throws SQLException { |
||||
|
SQLServerBulkCopyOptions copyOptions = new SQLServerBulkCopyOptions(); |
||||
|
copyOptions.setKeepIdentity(true); |
||||
|
// 设置批量插入的数量
|
||||
|
copyOptions.setBatchSize(size); |
||||
|
// 开启事务
|
||||
|
copyOptions.setUseInternalTransaction(true); |
||||
|
// 配置url
|
||||
|
SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(connectionUrl); |
||||
|
// 设置批量操作参数
|
||||
|
bulkCopy.setBulkCopyOptions(copyOptions); |
||||
|
// 设置要操作的表名
|
||||
|
bulkCopy.setDestinationTableName(tableName); |
||||
|
// 将数据保存到数据库
|
||||
|
bulkCopy.writeToServer(crs); |
||||
|
// 释放资源
|
||||
|
crs.close(); |
||||
|
// 释放资源
|
||||
|
bulkCopy.close(); |
||||
|
} |
||||
|
} |
@ -0,0 +1,42 @@ |
|||||
|
package com.qs.serve.modules.base; |
||||
|
|
||||
|
import cn.hutool.crypto.digest.DigestUtil; |
||||
|
import com.qs.serve.common.util.HttpUtil; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.beans.factory.annotation.Value; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import javax.annotation.PostConstruct; |
||||
|
import java.io.UnsupportedEncodingException; |
||||
|
import java.net.URLEncoder; |
||||
|
|
||||
|
/** |
||||
|
* @author YenHex |
||||
|
* @since 2024/1/26 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Service |
||||
|
public class ErpDataBaseService { |
||||
|
|
||||
|
@Value("${spring.datasource.dynamic.datasource.qisheng.url}") |
||||
|
private String erpJslGroupDbUrl; |
||||
|
|
||||
|
@Value("${spring.datasource.dynamic.datasource.qisheng.username}") |
||||
|
private String erpJslGroupDbUsername; |
||||
|
|
||||
|
@Value("${spring.datasource.dynamic.datasource.qisheng.password}") |
||||
|
private String erpJslGroupDbPassword; |
||||
|
|
||||
|
|
||||
|
public static String erpJslGroupDbConnectionUrl; |
||||
|
|
||||
|
public static String getErpJslGroupDbConnectionUrl(){ |
||||
|
return erpJslGroupDbConnectionUrl; |
||||
|
} |
||||
|
|
||||
|
@PostConstruct |
||||
|
public void initErpJslGroupDbConnectionUrl() { |
||||
|
erpJslGroupDbConnectionUrl = this.erpJslGroupDbUrl + ";user=" + this.erpJslGroupDbUsername + ";password=" + this.erpJslGroupDbPassword; |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,227 @@ |
|||||
|
package com.qs.serve.modules.bir.entity; |
||||
|
|
||||
|
import java.time.LocalDate; |
||||
|
import java.io.Serializable; |
||||
|
import java.math.BigDecimal; |
||||
|
import java.time.LocalDateTime; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.*; |
||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
|
import com.fasterxml.jackson.annotation.JsonIgnore; |
||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
|
import lombok.Data; |
||||
|
import org.hibernate.validator.constraints.Length; |
||||
|
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
|
||||
|
import javax.validation.constraints.NotNull; |
||||
|
import javax.validation.constraints.NotBlank; |
||||
|
|
||||
|
/** |
||||
|
* 实体类 |
||||
|
* @author YenHex |
||||
|
* @since 2024-06-14 |
||||
|
*/ |
||||
|
@Data |
||||
|
@TableName("bir_city_target_view") |
||||
|
public class BirCityTargetView implements Serializable { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** */ |
||||
|
@TableId(type = IdType.AUTO) |
||||
|
private Long id; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String region; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String regionProvince; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String regionCity; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String regionUser; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String regionUserId; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String regionProvinceUser; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String regionSales2Id; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String brand; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String category; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String m1; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String m2; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String m3; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String q1Target; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String m4; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String m5; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String m6; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String q2Target; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String m7; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String m8; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String m9; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String q3Target; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String m10; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String m11; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String m12; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String q4Target; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String yearTarget; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String q1Budget; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String q2Budget; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String q3Budget; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String q4Budget; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String yearBudget; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String yearRate; |
||||
|
|
||||
|
/** */ |
||||
|
private Long brandId; |
||||
|
|
||||
|
/** */ |
||||
|
private Long categoryId; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String regionId; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String cityId; |
||||
|
|
||||
|
/** */ |
||||
|
@Length(max = 255,message = "长度不能超过255字") |
||||
|
private String regionProvinceId; |
||||
|
|
||||
|
//0 city 1 省 2大区
|
||||
|
private Integer type; |
||||
|
|
||||
|
public static BirCityTargetView toNewObject(BirCityTargetView source){ |
||||
|
BirCityTargetView cityTargetView = new BirCityTargetView(); |
||||
|
cityTargetView.setId(source.getId()); |
||||
|
cityTargetView.setRegion(source.getRegion()); |
||||
|
cityTargetView.setRegionProvince(source.getRegionProvince()); |
||||
|
cityTargetView.setRegionCity(source.getRegionCity()); |
||||
|
cityTargetView.setRegionUser(source.getRegionUser()); |
||||
|
cityTargetView.setRegionUserId(source.getRegionUserId()); |
||||
|
cityTargetView.setRegionProvinceUser(source.getRegionProvinceUser()); |
||||
|
cityTargetView.setRegionSales2Id(source.getRegionSales2Id()); |
||||
|
cityTargetView.setBrand(source.getBrand()); |
||||
|
cityTargetView.setCategory(source.getCategory()); |
||||
|
cityTargetView.setM1(source.getM1()); |
||||
|
cityTargetView.setM2(source.getM2()); |
||||
|
cityTargetView.setM3(source.getM3()); |
||||
|
cityTargetView.setQ1Target(source.getQ1Target()); |
||||
|
cityTargetView.setM4(source.getM4()); |
||||
|
cityTargetView.setM5(source.getM5()); |
||||
|
cityTargetView.setM6(source.getM6()); |
||||
|
cityTargetView.setQ2Target(source.getQ2Target()); |
||||
|
cityTargetView.setM7(source.getM7()); |
||||
|
cityTargetView.setM8(source.getM8()); |
||||
|
cityTargetView.setM9(source.getM9()); |
||||
|
cityTargetView.setQ3Target(source.getQ3Target()); |
||||
|
cityTargetView.setM10(source.getM10()); |
||||
|
cityTargetView.setM11(source.getM11()); |
||||
|
cityTargetView.setM12(source.getM12()); |
||||
|
cityTargetView.setQ4Target(source.getQ4Target()); |
||||
|
cityTargetView.setYearTarget(source.getYearTarget()); |
||||
|
cityTargetView.setQ1Budget(source.getQ1Budget()); |
||||
|
cityTargetView.setQ2Budget(source.getQ2Budget()); |
||||
|
cityTargetView.setQ3Budget(source.getQ3Budget()); |
||||
|
cityTargetView.setQ4Budget(source.getQ4Budget()); |
||||
|
cityTargetView.setYearBudget(source.getYearBudget()); |
||||
|
cityTargetView.setYearRate(source.getYearRate()); |
||||
|
cityTargetView.setBrandId(source.getBrandId()); |
||||
|
cityTargetView.setCategoryId(source.getCategoryId()); |
||||
|
cityTargetView.setRegionId(source.getRegionId()); |
||||
|
cityTargetView.setCityId(source.getCityId()); |
||||
|
cityTargetView.setRegionProvinceId(source.getRegionProvinceId()); |
||||
|
return cityTargetView; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,14 @@ |
|||||
|
package com.qs.serve.modules.bir.mapper; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.qs.serve.modules.bir.entity.BirCityTargetView; |
||||
|
|
||||
|
/** |
||||
|
* Mapper |
||||
|
* @author YenHex |
||||
|
* @date 2024-06-14 |
||||
|
*/ |
||||
|
public interface BirCityTargetViewMapper extends BaseMapper<BirCityTargetView> { |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,24 @@ |
|||||
|
package com.qs.serve.modules.bir.service; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
import com.qs.serve.modules.bir.entity.BirBudgetTarget; |
||||
|
import com.qs.serve.modules.bir.entity.so.BirBudgetTargetSo; |
||||
|
import com.qs.serve.modules.bir.entity.vo.BirBudgetTargetVo; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 服务接口 |
||||
|
* @author YenHex |
||||
|
* @date 2024-06-04 |
||||
|
*/ |
||||
|
public interface BirBudgetTargetImportService extends IService<BirBudgetTarget> { |
||||
|
|
||||
|
void buildCustomerCost(); |
||||
|
void buildCityCost(); |
||||
|
void buildProCost(); |
||||
|
void buildAreaCost(); |
||||
|
void deleteAll(); |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,14 @@ |
|||||
|
package com.qs.serve.modules.bir.service; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
import com.qs.serve.modules.bir.entity.BirCityTargetView; |
||||
|
|
||||
|
/** |
||||
|
* 服务接口 |
||||
|
* @author YenHex |
||||
|
* @date 2024-06-14 |
||||
|
*/ |
||||
|
public interface BirCityTargetViewService extends IService<BirCityTargetView> { |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,586 @@ |
|||||
|
package com.qs.serve.modules.bir.service.impl; |
||||
|
|
||||
|
import cn.hutool.core.collection.CollUtil; |
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import com.qs.serve.common.util.*; |
||||
|
import com.qs.serve.modules.base.ErpDataBaseService; |
||||
|
import com.qs.serve.modules.bir.entity.BirActivityCenterGoods; |
||||
|
import com.qs.serve.modules.bir.entity.BirBudgetTarget; |
||||
|
import com.qs.serve.modules.bir.entity.BirCityTargetView; |
||||
|
import com.qs.serve.modules.bir.entity.so.BirBudgetTargetSo; |
||||
|
import com.qs.serve.modules.bir.entity.vo.BirBudgetTargetVo; |
||||
|
import com.qs.serve.modules.bir.mapper.BirActivityCenterGoodsMapper; |
||||
|
import com.qs.serve.modules.bir.mapper.BirBudgetTargetMapper; |
||||
|
import com.qs.serve.modules.bir.service.BirBudgetTargetImportService; |
||||
|
import com.qs.serve.modules.bir.service.BirBudgetTargetService; |
||||
|
import com.qs.serve.modules.bir.service.BirCityTargetViewService; |
||||
|
import com.qs.serve.modules.bms.entity.BmsRegion2; |
||||
|
import com.qs.serve.modules.bms.entity.BmsSupplier; |
||||
|
import com.qs.serve.modules.bms.service.BmsRegion2Service; |
||||
|
import com.qs.serve.modules.bms.service.BmsSupplierService; |
||||
|
import com.qs.serve.modules.erp.entity.dto.ErpDispatchSumVo; |
||||
|
import com.qs.serve.modules.erp.mapper.ErpDispatchDataMapper; |
||||
|
import com.qs.serve.modules.goods.entity.GoodsCategory; |
||||
|
import com.qs.serve.modules.goods.entity.GoodsSku; |
||||
|
import com.qs.serve.modules.goods.entity.GoodsSpu; |
||||
|
import com.qs.serve.modules.goods.service.GoodsCategoryService; |
||||
|
import com.qs.serve.modules.goods.service.GoodsSkuService; |
||||
|
import com.qs.serve.modules.goods.service.GoodsSpuService; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.lang.reflect.Field; |
||||
|
import java.math.BigDecimal; |
||||
|
import java.math.RoundingMode; |
||||
|
import java.sql.SQLException; |
||||
|
import java.time.LocalDateTime; |
||||
|
import java.time.temporal.TemporalAdjusters; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.Collection; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
/** |
||||
|
* 服务实现类 |
||||
|
* @author YenHex |
||||
|
* @since 2024-06-04 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Service |
||||
|
@AllArgsConstructor |
||||
|
public class BirBudgetTargetImportServiceImpl extends ServiceImpl<BirBudgetTargetMapper,BirBudgetTarget> implements BirBudgetTargetImportService { |
||||
|
|
||||
|
private BirActivityCenterGoodsMapper birActivityCenterGoodsMapper; |
||||
|
private GoodsSpuService goodsSpuService; |
||||
|
private GoodsSkuService goodsSkuService; |
||||
|
private GoodsCategoryService goodsCategoryService; |
||||
|
private ErpDispatchDataMapper erpDispatchDataMapper; |
||||
|
private BmsRegion2Service region2Service; |
||||
|
private BmsSupplierService bmsSupplierService; |
||||
|
private BirCityTargetViewService birCityTargetViewService; |
||||
|
|
||||
|
private BirBudgetTarget initTargetByBirCenterGoods(BirActivityCenterGoods item){ |
||||
|
BirBudgetTarget target = new BirBudgetTarget(); |
||||
|
target.setSearchType(0); |
||||
|
Integer keyNum = item.getKeyNum(); |
||||
|
initTargetDate(target,keyNum); |
||||
|
|
||||
|
//成本中心
|
||||
|
target.setCenterType(item.getCenterType()); |
||||
|
target.setCenterId(item.getCenterId()); |
||||
|
target.setCenterCode(item.getCenterCode()); |
||||
|
target.setCenterName(item.getCenterName()); |
||||
|
|
||||
|
//客户
|
||||
|
target.setCustomerId(item.getSupplierId()+""); |
||||
|
target.setCustomerCode(item.getSupplierCode()); |
||||
|
target.setCustomerName(item.getSupplierName()); |
||||
|
|
||||
|
|
||||
|
target.setTotalRealAmt(item.getSplitUsedAmount()); |
||||
|
|
||||
|
//品牌
|
||||
|
target.setBrandId(item.getTargetLevelPathIds()); |
||||
|
target.setBrandName(item.getTargetLevelPathNames()); |
||||
|
|
||||
|
target.setId(IdUtil.getSnowflakeNextId()); |
||||
|
|
||||
|
return target; |
||||
|
} |
||||
|
|
||||
|
private void initTargetDate(BirBudgetTarget target,Integer keyNum ){ |
||||
|
target.setYearNum(keyNum / 100); |
||||
|
target.setMonthNum(keyNum % 100); |
||||
|
target.setQuarterNum(DateUtils.getQuarter(target.getMonthNum())); |
||||
|
} |
||||
|
|
||||
|
public void buildCustomerCost() { |
||||
|
|
||||
|
List<BirActivityCenterGoods> birActivityCenterGoodsList = birActivityCenterGoodsMapper.list4BirBudgetTarget(); |
||||
|
List<BirBudgetTarget> targetList = birActivityCenterGoodsList.stream() |
||||
|
.map(item->initTargetByBirCenterGoods(item)).collect(Collectors.toList()); |
||||
|
|
||||
|
List<String> brandIds = targetList.stream().map(a->a.getBrandId()).distinct().collect(Collectors.toList()); |
||||
|
|
||||
|
brandIds.stream().forEach(brandId->{ |
||||
|
LambdaQueryWrapper<GoodsSpu> spuQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
spuQueryWrapper.select(GoodsSpu::getId); |
||||
|
spuQueryWrapper.eq(GoodsSpu::getCategoryFirst,brandId); |
||||
|
List<GoodsSpu> goodsSpuList = goodsSpuService.list(spuQueryWrapper); |
||||
|
List<Long> spuIds = goodsSpuList.stream().map(a->a.getId()).collect(Collectors.toList()); |
||||
|
if(spuIds.size()==0){ |
||||
|
return; |
||||
|
} |
||||
|
LambdaQueryWrapper<GoodsSku> skuQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
skuQueryWrapper.in(GoodsSku::getSpuId,spuIds); |
||||
|
List<GoodsSku> goodsSkuList = goodsSkuService.list(skuQueryWrapper); |
||||
|
List<String> skuCodes = goodsSkuList.stream().map(a->a.getSkuCode()).distinct().collect(Collectors.toList()); |
||||
|
List<ErpDispatchSumVo> erpDispatchSumVos = erpDispatchDataMapper.querySumCost4BudgetTarger(skuCodes); |
||||
|
|
||||
|
Map<String, BigDecimal> erpDispatchSumMap = erpDispatchSumVos.stream() |
||||
|
.collect(Collectors.toMap( |
||||
|
vo -> vo.getYearMonth() + "_" + vo.getCustomerCode(), |
||||
|
ErpDispatchSumVo::getDispatchSumCost)); |
||||
|
|
||||
|
targetList.stream().forEach(item->{ |
||||
|
if(item.getBrandId().equals(brandId)){ |
||||
|
String key = (item.getYearNum()*100 + item.getMonthNum()) + "_" + item.getCustomerCode(); |
||||
|
if(erpDispatchSumMap.containsKey(key)){ |
||||
|
item.setDispatchAmt(erpDispatchSumMap.get(key)); |
||||
|
} |
||||
|
|
||||
|
String lastkey = ((item.getYearNum()-1)*100 + item.getMonthNum()) + "_" + item.getCustomerCode(); |
||||
|
if(erpDispatchSumMap.containsKey(lastkey)){ |
||||
|
item.setLastYearDispatchAmt(erpDispatchSumMap.get(lastkey)); |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
try { |
||||
|
SqlServerUtil.batchInsert(ErpDataBaseService.getErpJslGroupDbConnectionUrl(),targetList); |
||||
|
} catch (SQLException throwables) { |
||||
|
throwables.printStackTrace(); |
||||
|
} catch (IllegalAccessException e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void buildCityCost() { |
||||
|
|
||||
|
LambdaQueryWrapper<BmsSupplier> supplierLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
supplierLambdaQueryWrapper.eq(BmsSupplier::getBookCode,"001"); |
||||
|
List<BmsSupplier> bmsSupplierList = bmsSupplierService.list(supplierLambdaQueryWrapper); |
||||
|
|
||||
|
Map<String, List<BmsSupplier>> supplierByRegionSec = bmsSupplierList.stream().filter(a->a.getRegion2Second()!=null) |
||||
|
.collect(Collectors.groupingBy(BmsSupplier::getRegion2Second)); |
||||
|
|
||||
|
List<BirBudgetTarget> insertList = new ArrayList<>(); |
||||
|
|
||||
|
supplierByRegionSec.keySet().stream().forEach(region2Id->{ |
||||
|
|
||||
|
List<BmsSupplier> supplierList = supplierByRegionSec.get(region2Id); |
||||
|
List<String> customerIds = supplierList.stream().map(a->a.getId()).collect(Collectors.toList()); |
||||
|
//城市ID查目标 和 预算
|
||||
|
LambdaQueryWrapper<BirCityTargetView> cityTargetLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
cityTargetLambdaQueryWrapper.eq(BirCityTargetView::getCityId,region2Id); |
||||
|
cityTargetLambdaQueryWrapper.eq(BirCityTargetView::getType,0); |
||||
|
List<BirCityTargetView> birCityTagetList = birCityTargetViewService.list(cityTargetLambdaQueryWrapper); |
||||
|
if(birCityTagetList.size()==0){ |
||||
|
log.warn("没有找到城市,ID为"+region2Id); |
||||
|
return; |
||||
|
} |
||||
|
Map<Long, List<BirCityTargetView>> cityTargetByBrand = |
||||
|
birCityTagetList.stream().collect(Collectors.groupingBy(BirCityTargetView::getBrandId)); |
||||
|
|
||||
|
cityTargetByBrand.keySet().stream().forEach(brandId->{ |
||||
|
List<BirCityTargetView> targetList = cityTargetByBrand.get(brandId); |
||||
|
// BigDecimal m1 = sumTargetData(targetList,"m1");
|
||||
|
// BigDecimal m2 = sumTargetData(targetList,"m2");
|
||||
|
// BigDecimal m3 = sumTargetData(targetList,"m3");
|
||||
|
// BigDecimal m4 = sumTargetData(targetList,"m4");
|
||||
|
// BigDecimal m5 = sumTargetData(targetList,"m5");
|
||||
|
// BigDecimal m6 = sumTargetData(targetList,"m6");
|
||||
|
// BigDecimal m7 = sumTargetData(targetList,"m7");
|
||||
|
// BigDecimal m8 = sumTargetData(targetList,"m8");
|
||||
|
// BigDecimal m9 = sumTargetData(targetList,"m9");
|
||||
|
// BigDecimal m10 = sumTargetData(targetList,"m10");
|
||||
|
// BigDecimal m11 = sumTargetData(targetList,"m11");
|
||||
|
// BigDecimal m12 = sumTargetData(targetList,"m12");
|
||||
|
// BigDecimal q1Budget = sumTargetData(targetList,"q1Budget");
|
||||
|
// BigDecimal q2Budget = sumTargetData(targetList,"q2Budget");
|
||||
|
// BigDecimal q3Budget = sumTargetData(targetList,"q3Budget");
|
||||
|
// BigDecimal q4Budget = sumTargetData(targetList,"q4Budget");
|
||||
|
BigDecimal yearTarget = sumTargetData(targetList,"yearTarget"); |
||||
|
BigDecimal yearBudget = sumTargetData(targetList,"yearBudget"); |
||||
|
BigDecimal yearRate; |
||||
|
if(yearTarget.compareTo(BigDecimal.ZERO)==0){ |
||||
|
yearRate = BigDecimal.ZERO; |
||||
|
}else{ |
||||
|
yearRate = yearBudget.divide(yearTarget, 4, BigDecimal.ROUND_HALF_UP); |
||||
|
} |
||||
|
|
||||
|
LambdaQueryWrapper<BirBudgetTarget> birDataLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
birDataLambdaQueryWrapper.in(BirBudgetTarget::getCustomerId, customerIds); |
||||
|
birDataLambdaQueryWrapper.eq(BirBudgetTarget::getBrandId, brandId); |
||||
|
birDataLambdaQueryWrapper.eq(BirBudgetTarget::getYearNum, 2024); |
||||
|
birDataLambdaQueryWrapper.eq(BirBudgetTarget::getSearchType, 0); |
||||
|
|
||||
|
List<BirBudgetTarget> data2024List = this.list(birDataLambdaQueryWrapper); |
||||
|
|
||||
|
Map<Integer, List<BirBudgetTarget>> data2024MonMap = |
||||
|
data2024List.stream().collect(Collectors.groupingBy(BirBudgetTarget::getMonthNum)); |
||||
|
|
||||
|
data2024MonMap.keySet().stream().forEach(mon->{ |
||||
|
// for(int mon= 1;mon<=12;mon++) {
|
||||
|
|
||||
|
// List<BirBudgetTarget> dataList = this.list(birDataLambdaQueryWrapper);
|
||||
|
List<BirBudgetTarget> dataMonList = data2024MonMap.get(mon); |
||||
|
|
||||
|
Map<String, List<BirBudgetTarget>> dataCenterMap = |
||||
|
dataMonList.stream().collect(Collectors.groupingBy(g->g.getCenterType()+"_"+g.getCenterId())); |
||||
|
|
||||
|
dataCenterMap.keySet().stream().forEach(centerKey->{ |
||||
|
List<BirBudgetTarget> dataList = dataCenterMap.get(centerKey); |
||||
|
|
||||
|
BigDecimal dispatchAmt = dataList.stream().map(a -> a.getDispatchAmt()==null?BigDecimal.ZERO:a.getDispatchAmt()).reduce(BigDecimal.ZERO, BigDecimal::add); |
||||
|
BigDecimal lastYearDispatchAmt = dataList.stream().map(a -> a.getLastYearDispatchAmt()==null?BigDecimal.ZERO:a.getLastYearDispatchAmt()).reduce(BigDecimal.ZERO, BigDecimal::add); |
||||
|
BigDecimal totalRealAmt = dataList.stream().map(a -> a.getTotalRealAmt()==null?BigDecimal.ZERO:a.getTotalRealAmt()).reduce(BigDecimal.ZERO, BigDecimal::add); |
||||
|
BirBudgetTarget targetData = new BirBudgetTarget(); |
||||
|
|
||||
|
String[] centerType = centerKey.split("_"); |
||||
|
targetData.setCenterType(centerType[0]); |
||||
|
targetData.setCenterId(centerType[1]); |
||||
|
|
||||
|
targetData.setSearchType(1); |
||||
|
targetData.setId(IdUtil.getSnowflakeNextId()); |
||||
|
targetData.setBrandId(brandId + ""); |
||||
|
targetData.setYearNum(2024); |
||||
|
targetData.setMonthNum(mon); |
||||
|
targetData.setQuarterNum(DateUtils.getQuarter(mon)); |
||||
|
targetData.setDispatchAmt(dispatchAmt.setScale(2, RoundingMode.HALF_UP)); |
||||
|
targetData.setLastYearDispatchAmt(lastYearDispatchAmt.setScale(2, RoundingMode.HALF_UP)); |
||||
|
targetData.setTotalRealAmt(totalRealAmt.setScale(2, RoundingMode.HALF_UP)); |
||||
|
targetData.setTargetAmt(sumTargetData(targetList,"m"+mon).multiply(new BigDecimal(10000)).setScale(2, RoundingMode.HALF_UP)); |
||||
|
targetData.setBudgetAmt(sumTargetData(targetList,"q"+DateUtils.getQuarter(mon)+"Budget").multiply(new BigDecimal(10000)).setScale(2, RoundingMode.HALF_UP)); |
||||
|
targetData.setRate(yearRate); |
||||
|
targetData.setCustomerId(region2Id); |
||||
|
insertList.add(targetData); |
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
|
//得到品牌IDs 和 时间
|
||||
|
|
||||
|
//客户IDs和品牌IDs和 时间查实际费
|
||||
|
|
||||
|
}); |
||||
|
|
||||
|
try { |
||||
|
SqlServerUtil.batchInsert(ErpDataBaseService.getErpJslGroupDbConnectionUrl(),insertList); |
||||
|
} catch (SQLException throwables) { |
||||
|
throwables.printStackTrace(); |
||||
|
} catch (IllegalAccessException e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private BigDecimal sumTargetData(List<BirCityTargetView> targetList,String fieldName) { |
||||
|
if(targetList.size()==0){ |
||||
|
return BigDecimal.ZERO; |
||||
|
} |
||||
|
try { |
||||
|
Class<?> clazz = targetList.get(0).getClass(); |
||||
|
Field field = clazz.getDeclaredField(fieldName); |
||||
|
field.setAccessible(true); |
||||
|
|
||||
|
BigDecimal target = targetList.stream().map(transaction -> { |
||||
|
try { |
||||
|
String fieldNameValue = (String) field.get(transaction); |
||||
|
if(fieldNameValue==null || !StringUtils.hasText(fieldNameValue)){ |
||||
|
return BigDecimal.ZERO; |
||||
|
} |
||||
|
return new BigDecimal(fieldNameValue); |
||||
|
} catch (NumberFormatException | IllegalAccessException e) { |
||||
|
e.printStackTrace(); |
||||
|
return BigDecimal.ZERO; |
||||
|
} |
||||
|
}).reduce(BigDecimal.ZERO, BigDecimal::add); |
||||
|
return target; |
||||
|
|
||||
|
} catch (NoSuchFieldException e) { |
||||
|
e.printStackTrace(); |
||||
|
return BigDecimal.ZERO; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public void buildProCost() { |
||||
|
|
||||
|
LambdaQueryWrapper<BmsSupplier> supplierLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
supplierLambdaQueryWrapper.eq(BmsSupplier::getBookCode,"001"); |
||||
|
List<BmsSupplier> bmsSupplierList = bmsSupplierService.list(supplierLambdaQueryWrapper); |
||||
|
|
||||
|
Map<String, List<BmsSupplier>> supplierByRegionSec = bmsSupplierList.stream().filter(a->a.getRegionSecond()!=null) |
||||
|
.collect(Collectors.groupingBy(BmsSupplier::getRegionSecond)); |
||||
|
|
||||
|
List<BirBudgetTarget> insertList = new ArrayList<>(); |
||||
|
|
||||
|
supplierByRegionSec.keySet().stream().forEach(region2Id->{ |
||||
|
|
||||
|
List<BmsSupplier> supplierList = supplierByRegionSec.get(region2Id); |
||||
|
List<String> customerIds = supplierList.stream().map(a->a.getId()).collect(Collectors.toList()); |
||||
|
//城市ID查目标 和 预算
|
||||
|
LambdaQueryWrapper<BirCityTargetView> cityTargetLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
cityTargetLambdaQueryWrapper.eq(BirCityTargetView::getRegionSales2Id,region2Id); |
||||
|
cityTargetLambdaQueryWrapper.eq(BirCityTargetView::getType,1); |
||||
|
List<BirCityTargetView> birCityTagetList = birCityTargetViewService.list(cityTargetLambdaQueryWrapper); |
||||
|
if(birCityTagetList.size()==0){ |
||||
|
log.warn("没有找到二级销售区域,ID为"+region2Id); |
||||
|
return; |
||||
|
} |
||||
|
Map<Long, List<BirCityTargetView>> cityTargetByBrand = |
||||
|
birCityTagetList.stream().collect(Collectors.groupingBy(BirCityTargetView::getBrandId)); |
||||
|
|
||||
|
cityTargetByBrand.keySet().stream().forEach(brandId->{ |
||||
|
List<BirCityTargetView> targetList = cityTargetByBrand.get(brandId); |
||||
|
// BigDecimal m1 = sumTargetData(targetList,"m1");
|
||||
|
// BigDecimal m2 = sumTargetData(targetList,"m2");
|
||||
|
// BigDecimal m3 = sumTargetData(targetList,"m3");
|
||||
|
// BigDecimal m4 = sumTargetData(targetList,"m4");
|
||||
|
// BigDecimal m5 = sumTargetData(targetList,"m5");
|
||||
|
// BigDecimal m6 = sumTargetData(targetList,"m6");
|
||||
|
// BigDecimal m7 = sumTargetData(targetList,"m7");
|
||||
|
// BigDecimal m8 = sumTargetData(targetList,"m8");
|
||||
|
// BigDecimal m9 = sumTargetData(targetList,"m9");
|
||||
|
// BigDecimal m10 = sumTargetData(targetList,"m10");
|
||||
|
// BigDecimal m11 = sumTargetData(targetList,"m11");
|
||||
|
// BigDecimal m12 = sumTargetData(targetList,"m12");
|
||||
|
// BigDecimal q1Budget = sumTargetData(targetList,"q1Budget");
|
||||
|
// BigDecimal q2Budget = sumTargetData(targetList,"q2Budget");
|
||||
|
// BigDecimal q3Budget = sumTargetData(targetList,"q3Budget");
|
||||
|
// BigDecimal q4Budget = sumTargetData(targetList,"q4Budget");
|
||||
|
BigDecimal yearTarget = sumTargetData(targetList,"yearTarget"); |
||||
|
BigDecimal yearBudget = sumTargetData(targetList,"yearBudget"); |
||||
|
BigDecimal yearRate; |
||||
|
if(yearTarget.compareTo(BigDecimal.ZERO)==0){ |
||||
|
yearRate = BigDecimal.ZERO; |
||||
|
}else{ |
||||
|
yearRate = yearBudget.divide(yearTarget, 4, BigDecimal.ROUND_HALF_UP); |
||||
|
} |
||||
|
|
||||
|
LambdaQueryWrapper<BirBudgetTarget> birDataLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
birDataLambdaQueryWrapper.in(BirBudgetTarget::getCustomerId, customerIds); |
||||
|
birDataLambdaQueryWrapper.eq(BirBudgetTarget::getBrandId, brandId); |
||||
|
birDataLambdaQueryWrapper.eq(BirBudgetTarget::getYearNum, 2024); |
||||
|
birDataLambdaQueryWrapper.eq(BirBudgetTarget::getSearchType, 0); |
||||
|
|
||||
|
List<BirBudgetTarget> data2024List = this.list(birDataLambdaQueryWrapper); |
||||
|
|
||||
|
Map<Integer, List<BirBudgetTarget>> data2024MonMap = |
||||
|
data2024List.stream().collect(Collectors.groupingBy(BirBudgetTarget::getMonthNum)); |
||||
|
|
||||
|
data2024MonMap.keySet().stream().forEach(mon->{ |
||||
|
// for(int mon= 1;mon<=12;mon++) {
|
||||
|
|
||||
|
// List<BirBudgetTarget> dataList = this.list(birDataLambdaQueryWrapper);
|
||||
|
List<BirBudgetTarget> dataMonList = data2024MonMap.get(mon); |
||||
|
|
||||
|
Map<String, List<BirBudgetTarget>> dataCenterMap = |
||||
|
dataMonList.stream().collect(Collectors.groupingBy(g->g.getCenterType()+"_"+g.getCenterId())); |
||||
|
|
||||
|
dataCenterMap.keySet().stream().forEach(centerKey->{ |
||||
|
List<BirBudgetTarget> dataList = dataCenterMap.get(centerKey); |
||||
|
|
||||
|
BigDecimal dispatchAmt = dataList.stream().map(a -> a.getDispatchAmt()==null?BigDecimal.ZERO:a.getDispatchAmt()).reduce(BigDecimal.ZERO, BigDecimal::add); |
||||
|
BigDecimal lastYearDispatchAmt = dataList.stream().map(a -> a.getLastYearDispatchAmt()==null?BigDecimal.ZERO:a.getLastYearDispatchAmt()).reduce(BigDecimal.ZERO, BigDecimal::add); |
||||
|
BigDecimal totalRealAmt = dataList.stream().map(a -> a.getTotalRealAmt()==null?BigDecimal.ZERO:a.getTotalRealAmt()).reduce(BigDecimal.ZERO, BigDecimal::add); |
||||
|
BirBudgetTarget targetData = new BirBudgetTarget(); |
||||
|
|
||||
|
String[] centerType = centerKey.split("_"); |
||||
|
targetData.setCenterType(centerType[0]); |
||||
|
targetData.setCenterId(centerType[1]); |
||||
|
|
||||
|
targetData.setSearchType(2); |
||||
|
targetData.setId(IdUtil.getSnowflakeNextId()); |
||||
|
targetData.setBrandId(brandId + ""); |
||||
|
targetData.setYearNum(2024); |
||||
|
targetData.setMonthNum(mon); |
||||
|
targetData.setQuarterNum(DateUtils.getQuarter(mon)); |
||||
|
targetData.setDispatchAmt(dispatchAmt.setScale(2, RoundingMode.HALF_UP)); |
||||
|
targetData.setLastYearDispatchAmt(lastYearDispatchAmt.setScale(2, RoundingMode.HALF_UP)); |
||||
|
targetData.setTotalRealAmt(totalRealAmt.setScale(2, RoundingMode.HALF_UP)); |
||||
|
targetData.setTargetAmt(sumTargetData(targetList,"m"+mon).multiply(new BigDecimal(10000)).setScale(2, RoundingMode.HALF_UP)); |
||||
|
targetData.setBudgetAmt(sumTargetData(targetList,"q"+DateUtils.getQuarter(mon)+"Budget").multiply(new BigDecimal(10000)).setScale(2, RoundingMode.HALF_UP)); |
||||
|
targetData.setRate(yearRate); |
||||
|
targetData.setCustomerId(region2Id); |
||||
|
insertList.add(targetData); |
||||
|
|
||||
|
LambdaUpdateWrapper<BirBudgetTarget> birCustomerUpdateLambdaQueryWrapper = new LambdaUpdateWrapper<>(); |
||||
|
birCustomerUpdateLambdaQueryWrapper.set(BirBudgetTarget::getProvinceCityAmt,targetData.getTotalRealAmt()); |
||||
|
birCustomerUpdateLambdaQueryWrapper.eq(BirBudgetTarget::getYearNum,2024); |
||||
|
birCustomerUpdateLambdaQueryWrapper.eq(BirBudgetTarget::getMonthNum,mon); |
||||
|
birCustomerUpdateLambdaQueryWrapper.eq(BirBudgetTarget::getCenterType,centerType[0]); |
||||
|
birCustomerUpdateLambdaQueryWrapper.eq(BirBudgetTarget::getCenterId,centerType[1]); |
||||
|
birCustomerUpdateLambdaQueryWrapper.eq(BirBudgetTarget::getBrandId,brandId); |
||||
|
birCustomerUpdateLambdaQueryWrapper.eq(BirBudgetTarget::getSearchType,0); |
||||
|
birCustomerUpdateLambdaQueryWrapper.in(BirBudgetTarget::getCustomerId,customerIds); |
||||
|
this.update(birCustomerUpdateLambdaQueryWrapper); |
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
|
//得到品牌IDs 和 时间
|
||||
|
|
||||
|
//客户IDs和品牌IDs和 时间查实际费
|
||||
|
|
||||
|
}); |
||||
|
|
||||
|
try { |
||||
|
SqlServerUtil.batchInsert(ErpDataBaseService.getErpJslGroupDbConnectionUrl(),insertList); |
||||
|
} catch (SQLException throwables) { |
||||
|
throwables.printStackTrace(); |
||||
|
} catch (IllegalAccessException e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public void buildAreaCost() { |
||||
|
|
||||
|
LambdaQueryWrapper<BmsSupplier> supplierLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
supplierLambdaQueryWrapper.eq(BmsSupplier::getBookCode,"001"); |
||||
|
List<BmsSupplier> bmsSupplierList = bmsSupplierService.list(supplierLambdaQueryWrapper); |
||||
|
|
||||
|
Map<String, List<BmsSupplier>> supplierByRegionSec = bmsSupplierList.stream().filter(a->a.getRegionFirst()!=null) |
||||
|
.collect(Collectors.groupingBy(BmsSupplier::getRegionFirst)); |
||||
|
|
||||
|
List<BirBudgetTarget> insertList = new ArrayList<>(); |
||||
|
|
||||
|
supplierByRegionSec.keySet().stream().forEach(region2Id->{ |
||||
|
|
||||
|
List<BmsSupplier> supplierList = supplierByRegionSec.get(region2Id); |
||||
|
List<String> customerIds = supplierList.stream().map(a->a.getId()).collect(Collectors.toList()); |
||||
|
//城市ID查目标 和 预算
|
||||
|
LambdaQueryWrapper<BirCityTargetView> cityTargetLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
cityTargetLambdaQueryWrapper.eq(BirCityTargetView::getRegionId,region2Id); |
||||
|
cityTargetLambdaQueryWrapper.eq(BirCityTargetView::getType,2); |
||||
|
List<BirCityTargetView> birCityTagetList = birCityTargetViewService.list(cityTargetLambdaQueryWrapper); |
||||
|
if(birCityTagetList.size()==0){ |
||||
|
log.warn("没有找到一级销售区域,ID为"+region2Id); |
||||
|
return; |
||||
|
} |
||||
|
Map<Long, List<BirCityTargetView>> cityTargetByBrand = |
||||
|
birCityTagetList.stream().collect(Collectors.groupingBy(BirCityTargetView::getBrandId)); |
||||
|
|
||||
|
cityTargetByBrand.keySet().stream().forEach(brandId->{ |
||||
|
List<BirCityTargetView> targetList = cityTargetByBrand.get(brandId); |
||||
|
// BigDecimal m1 = sumTargetData(targetList,"m1");
|
||||
|
// BigDecimal m2 = sumTargetData(targetList,"m2");
|
||||
|
// BigDecimal m3 = sumTargetData(targetList,"m3");
|
||||
|
// BigDecimal m4 = sumTargetData(targetList,"m4");
|
||||
|
// BigDecimal m5 = sumTargetData(targetList,"m5");
|
||||
|
// BigDecimal m6 = sumTargetData(targetList,"m6");
|
||||
|
// BigDecimal m7 = sumTargetData(targetList,"m7");
|
||||
|
// BigDecimal m8 = sumTargetData(targetList,"m8");
|
||||
|
// BigDecimal m9 = sumTargetData(targetList,"m9");
|
||||
|
// BigDecimal m10 = sumTargetData(targetList,"m10");
|
||||
|
// BigDecimal m11 = sumTargetData(targetList,"m11");
|
||||
|
// BigDecimal m12 = sumTargetData(targetList,"m12");
|
||||
|
// BigDecimal q1Budget = sumTargetData(targetList,"q1Budget");
|
||||
|
// BigDecimal q2Budget = sumTargetData(targetList,"q2Budget");
|
||||
|
// BigDecimal q3Budget = sumTargetData(targetList,"q3Budget");
|
||||
|
// BigDecimal q4Budget = sumTargetData(targetList,"q4Budget");
|
||||
|
BigDecimal yearTarget = sumTargetData(targetList,"yearTarget"); |
||||
|
BigDecimal yearBudget = sumTargetData(targetList,"yearBudget"); |
||||
|
BigDecimal yearRate; |
||||
|
if(yearTarget.compareTo(BigDecimal.ZERO)==0){ |
||||
|
yearRate = BigDecimal.ZERO; |
||||
|
}else{ |
||||
|
yearRate = yearBudget.divide(yearTarget, 4, BigDecimal.ROUND_HALF_UP); |
||||
|
} |
||||
|
|
||||
|
LambdaQueryWrapper<BirBudgetTarget> birDataLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
birDataLambdaQueryWrapper.in(BirBudgetTarget::getCustomerId, customerIds); |
||||
|
birDataLambdaQueryWrapper.eq(BirBudgetTarget::getBrandId, brandId); |
||||
|
birDataLambdaQueryWrapper.eq(BirBudgetTarget::getYearNum, 2024); |
||||
|
birDataLambdaQueryWrapper.eq(BirBudgetTarget::getSearchType, 0); |
||||
|
|
||||
|
List<BirBudgetTarget> data2024List = this.list(birDataLambdaQueryWrapper); |
||||
|
|
||||
|
Map<Integer, List<BirBudgetTarget>> data2024MonMap = |
||||
|
data2024List.stream().collect(Collectors.groupingBy(BirBudgetTarget::getMonthNum)); |
||||
|
|
||||
|
data2024MonMap.keySet().stream().forEach(mon->{ |
||||
|
// for(int mon= 1;mon<=12;mon++) {
|
||||
|
|
||||
|
// List<BirBudgetTarget> dataList = this.list(birDataLambdaQueryWrapper);
|
||||
|
List<BirBudgetTarget> dataMonList = data2024MonMap.get(mon); |
||||
|
|
||||
|
Map<String, List<BirBudgetTarget>> dataCenterMap = |
||||
|
dataMonList.stream().collect(Collectors.groupingBy(g->g.getCenterType()+"_"+g.getCenterId())); |
||||
|
|
||||
|
dataCenterMap.keySet().stream().forEach(centerKey-> { |
||||
|
List<BirBudgetTarget> dataList = dataCenterMap.get(centerKey); |
||||
|
|
||||
|
BigDecimal dispatchAmt = dataList.stream().map(a -> a.getDispatchAmt() == null ? BigDecimal.ZERO : a.getDispatchAmt()).reduce(BigDecimal.ZERO, BigDecimal::add); |
||||
|
BigDecimal lastYearDispatchAmt = dataList.stream().map(a -> a.getLastYearDispatchAmt() == null ? BigDecimal.ZERO : a.getLastYearDispatchAmt()).reduce(BigDecimal.ZERO, BigDecimal::add); |
||||
|
BigDecimal totalRealAmt = dataList.stream().map(a -> a.getTotalRealAmt() == null ? BigDecimal.ZERO : a.getTotalRealAmt()).reduce(BigDecimal.ZERO, BigDecimal::add); |
||||
|
BirBudgetTarget targetData = new BirBudgetTarget(); |
||||
|
|
||||
|
String[] centerType = centerKey.split("_"); |
||||
|
targetData.setCenterType(centerType[0]); |
||||
|
targetData.setCenterId(centerType[1]); |
||||
|
targetData.setSearchType(3); |
||||
|
targetData.setId(IdUtil.getSnowflakeNextId()); |
||||
|
targetData.setBrandId(brandId + ""); |
||||
|
targetData.setYearNum(2024); |
||||
|
targetData.setMonthNum(mon); |
||||
|
targetData.setQuarterNum(DateUtils.getQuarter(mon)); |
||||
|
targetData.setDispatchAmt(dispatchAmt.setScale(2, RoundingMode.HALF_UP)); |
||||
|
targetData.setLastYearDispatchAmt(lastYearDispatchAmt.setScale(2, RoundingMode.HALF_UP)); |
||||
|
targetData.setTotalRealAmt(totalRealAmt.setScale(2, RoundingMode.HALF_UP)); |
||||
|
targetData.setTargetAmt(sumTargetData(targetList, "m" + mon).multiply(new BigDecimal(10000)).setScale(2, RoundingMode.HALF_UP)); |
||||
|
targetData.setBudgetAmt(sumTargetData(targetList, "q" + DateUtils.getQuarter(mon) + "Budget").multiply(new BigDecimal(10000)).setScale(2, RoundingMode.HALF_UP)); |
||||
|
targetData.setRate(yearRate); |
||||
|
targetData.setCustomerId(region2Id); |
||||
|
insertList.add(targetData); |
||||
|
|
||||
|
LambdaUpdateWrapper<BirBudgetTarget> birCustomerUpdateLambdaQueryWrapper = new LambdaUpdateWrapper<>(); |
||||
|
birCustomerUpdateLambdaQueryWrapper.set(BirBudgetTarget::getProvinceCityRegionAmt,targetData.getTotalRealAmt()); |
||||
|
birCustomerUpdateLambdaQueryWrapper.eq(BirBudgetTarget::getYearNum,2024); |
||||
|
birCustomerUpdateLambdaQueryWrapper.eq(BirBudgetTarget::getMonthNum,mon); |
||||
|
birCustomerUpdateLambdaQueryWrapper.eq(BirBudgetTarget::getCenterType,centerType[0]); |
||||
|
birCustomerUpdateLambdaQueryWrapper.eq(BirBudgetTarget::getCenterId,centerType[1]); |
||||
|
birCustomerUpdateLambdaQueryWrapper.eq(BirBudgetTarget::getBrandId,brandId); |
||||
|
birCustomerUpdateLambdaQueryWrapper.eq(BirBudgetTarget::getSearchType,0); |
||||
|
birCustomerUpdateLambdaQueryWrapper.in(BirBudgetTarget::getCustomerId,customerIds); |
||||
|
this.update(birCustomerUpdateLambdaQueryWrapper); |
||||
|
|
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
|
//得到品牌IDs 和 时间
|
||||
|
|
||||
|
//客户IDs和品牌IDs和 时间查实际费
|
||||
|
|
||||
|
}); |
||||
|
|
||||
|
try { |
||||
|
SqlServerUtil.batchInsert(ErpDataBaseService.getErpJslGroupDbConnectionUrl(),insertList); |
||||
|
} catch (SQLException throwables) { |
||||
|
throwables.printStackTrace(); |
||||
|
} catch (IllegalAccessException e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void deleteAll(){ |
||||
|
// LambdaQueryWrapper<BirBudgetTarget> birDataLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
|
// this.remove(birDataLambdaQueryWrapper);
|
||||
|
this.getBaseMapper().deleteAllData(); |
||||
|
} |
||||
|
|
||||
|
public void setProviceCityAmt(){ |
||||
|
LambdaQueryWrapper<BirBudgetTarget> birDataLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
birDataLambdaQueryWrapper.eq(BirBudgetTarget::getSearchType,2); |
||||
|
List<BirBudgetTarget> proList = this.list(birDataLambdaQueryWrapper); |
||||
|
|
||||
|
Map<String, List<BirBudgetTarget>> proMap = |
||||
|
proList.stream().collect(Collectors.groupingBy(BirBudgetTarget::getCustomerId)); |
||||
|
|
||||
|
proMap.keySet().stream().forEach(proCustomeId->{ |
||||
|
LambdaQueryWrapper<BirCityTargetView> cityTargetLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
cityTargetLambdaQueryWrapper.eq(BirCityTargetView::getRegionSales2Id,proCustomeId); |
||||
|
cityTargetLambdaQueryWrapper.eq(BirCityTargetView::getType,0); |
||||
|
List<BirCityTargetView> birCityTagetList = birCityTargetViewService.list(cityTargetLambdaQueryWrapper); |
||||
|
List<String> cityIds = birCityTagetList.stream().map(a->a.getCityId()).distinct().collect(Collectors.toList()); |
||||
|
LambdaQueryWrapper<BirBudgetTarget> birCityLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
||||
|
birCityLambdaQueryWrapper.eq(BirBudgetTarget::getSearchType,1); |
||||
|
List<BirBudgetTarget> cityList = this.list(birCityLambdaQueryWrapper); |
||||
|
}); |
||||
|
} |
||||
|
} |
@ -0,0 +1,22 @@ |
|||||
|
package com.qs.serve.modules.bir.service.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import com.qs.serve.modules.bir.entity.BirCityTargetView; |
||||
|
import com.qs.serve.modules.bir.service.BirCityTargetViewService; |
||||
|
import com.qs.serve.modules.bir.mapper.BirCityTargetViewMapper; |
||||
|
|
||||
|
/** |
||||
|
* 服务实现类 |
||||
|
* @author YenHex |
||||
|
* @since 2024-06-14 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Service |
||||
|
@AllArgsConstructor |
||||
|
public class BirCityTargetViewServiceImpl extends ServiceImpl<BirCityTargetViewMapper,BirCityTargetView> implements BirCityTargetViewService { |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,29 @@ |
|||||
|
package com.qs.serve.task; |
||||
|
|
||||
|
import com.qs.serve.common.util.AuthContextUtils; |
||||
|
import com.qs.serve.modules.bir.mapper.BirReportAccountBookMapper; |
||||
|
import com.qs.serve.modules.bir.service.BirBudgetTargetImportService; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
||||
|
import org.springframework.scheduling.annotation.Scheduled; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
/** |
||||
|
* @author YenHex |
||||
|
* @since 2023/7/14 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Component |
||||
|
@AllArgsConstructor |
||||
|
@ConditionalOnProperty(value = "project.task", havingValue = "true") |
||||
|
public class BirRateTask { |
||||
|
|
||||
|
private final BirBudgetTargetImportService birBudgetTargetImportService; |
||||
|
|
||||
|
@Scheduled(cron="0 0 1 * * ?") |
||||
|
public void buildTempTable(){ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue