Commit 52af2507 by kangxiaoshan

Merge branch '2580_fix2' into 2580_fix

parents 50f5e68c 065258b1
......@@ -38,17 +38,16 @@ public class DmpIncomeController {
}
@PostMapping("/delete")
public ResultModel deleteItem(Long id) {
public ResultModel deleteItem(@RequestBody DmpIncome dmpIncome) {
//删除数据
return ResultModel.OK(dmpIncomeService.delete(id));
return ResultModel.OK(dmpIncomeService.delete(dmpIncome));
}
@PostMapping("/upload")
public ResultModel uploadList(@RequestParam("file") MultipartFile file, @CurrentAccount User loginAccount) {
//上传收入数据
dmpIncomeService.uploadFile(file, "dmp", loginAccount);
return ResultModel.OK();
return dmpIncomeService.uploadFile(file, "dmp", loginAccount);
}
......
......@@ -198,6 +198,8 @@ public class Contract {
this.contractType = contractType;
}
public String getStartDate() {
return startDate;
}
......
......@@ -9,6 +9,7 @@ import java.util.Date;
@Entity
public class DmpIncome {
private Long id;// ID
private String contractCode;//合同编号
private String incomeMonth;//收入月份
......@@ -20,6 +21,7 @@ public class DmpIncome {
private Date createTime;
private Date modifyTime;
private String uploadUser;
private int index;
private String myBodyCode;
//contract_code, my_body_name, customer_body, customer_short, business_type, agreement_type
......@@ -166,6 +168,15 @@ public class DmpIncome {
this.agreementType = agreementType;
}
@Transient
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public String getMyBodyCode() {
return myBodyCode;
}
......
......@@ -165,4 +165,7 @@ public interface ContractRepository extends JpaRepository<Contract, Long> {
@Modifying
@Query(value = "delete from contract where contract_code = ?1 and platform=?2", nativeQuery = true)
void deleteByCode(String contractCode, String platform);
@Query(value = "select * from contract where platform=?1 and email =?2", nativeQuery = true)
List<Contract> findbyEmailAndPlatform(String cas, String originEmail);
}
......@@ -17,5 +17,4 @@ public interface DmpIncomeRepository extends JpaRepository<DmpIncome, Long> {
@Query(value = "select * from dmp_income where contract_code = ?1 and income_month =?2 limit 1 ", nativeQuery = true)
DmpIncome findByCodeMonth(String contractCode, String incomeMonth);
}
......@@ -22,7 +22,7 @@ public interface DmpIncomeService {
DmpIncome update(DmpIncome dmpIncome);
Long delete(Long id);
Long delete(DmpIncome dmpIncome);
ResultModel uploadFile(MultipartFile file, String platform, User loginAccount);
......@@ -45,4 +45,5 @@ public interface DmpIncomeService {
List pdListByDs(String startDate, String endDate);
HSSFWorkbook exportPdIncomeList(String startDate, String endDate, String bodyCode, String serchName);
}
......@@ -70,6 +70,7 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
PdAttachmentRepository pdAttachmentRepository;
public static final Map<String, String> SHEET_NAMES = new HashMap();
private static final Map<String, String> CONTRACT_TYPE_NAME = new HashMap();
private static final Map<String, String> BUSINESS_TYPE_NAME = new HashMap();
......@@ -89,6 +90,7 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
CONTRACT_TYPE_NAME.put("补充协议", "2");
BUSINESS_TYPE_NAME.put("VIP", "1");//业务类型 1 VIP 2 共管
BUSINESS_TYPE_NAME.put("共管", "2");
BUSINESS_TYPE_NAME.put("前置机", "3");
SETAGREEMENT_TYPE_NAME.put("普通协议", "1");//协议类型 1 普通协议 2 框架协议
SETAGREEMENT_TYPE_NAME.put("框架协议", "2");
}
......@@ -223,7 +225,8 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
row.createCell(i).setCellValue(title[i]);
}
String[] bussinesName = new String[]{"", "VIP", "共管"};
String[] bussinesName = new String[]{"", "VIP", "共管", "前置机"};
for (int j = 0; j < dmpIncomes.size(); j++) {
HSSFRow rowBody = sheet.createRow(j + 1);
DmpIncome income = dmpIncomes.get(j);
......@@ -261,12 +264,13 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
}
@Override
public Long delete(Long id) {
if (id == null) {
public Long delete(DmpIncome dmpIncome) {
if (dmpIncome.getId() == null) {
return null;
}
dmpIncomeRepository.delete(id);
return id;
dmpIncomeRepository.delete(dmpIncome.getId());
return dmpIncome.getId();
}
@Override
......@@ -285,27 +289,56 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
Sheet sheet = workbook.getSheetAt(0);
DecimalFormat df = new DecimalFormat("##,##0.00");
CompletableFuture.runAsync(() -> {
StringBuffer erroMessage = new StringBuffer();
StopWatch stopWatch = new StopWatch();
stopWatch.start();
Map<String, String> incomeMap = new HashMap<>();
List<DmpIncome> dmpIncomeList = Stream.iterate(1, n -> n + 1).limit(rowNumber - 1).map(index -> {
DmpIncome income = saveDmpIncomeItem(sheet, index, loginAccount);
String key = income.getIncomeMonth() + income.getContractCode();
if (incomeMap.containsKey(key)) {
return null;
}
incomeMap.put(key, "1");
return income;
}).filter(in -> in != null).collect(Collectors.toList());
if (dmpIncomeList.isEmpty()) {
return ResultModel.OK();
}
ExecutorService executorService = Executors.newFixedThreadPool(30);
CompletableFuture[] futures = Stream.iterate(1, n -> n + 1).limit(rowNumber - 1).map(index ->
final int[] indexLine = {0};
CompletableFuture[] futures = dmpIncomeList.stream().map(income ->
CompletableFuture.runAsync(
() -> {
DmpIncome income = saveDmpIncomeItem(sheet, index, loginAccount);
if (income != null) {
DmpIncome one = dmpIncomeRepository.findByCodeMonth(income.getContractCode(), income.getIncomeMonth());
if (one != null) {
// 同一合同同一月份不重复保存
return;
}
indexLine[0] = income.getIndex();
if ("erro".equals(income.getIncomeMonth())) {
erroMessage.append(income.getIndex()).append(" 行 收入月份错误").append(";\n");
} else {
income.setConfirmSettlement(new BigDecimal(income.getConfirmSettlement()).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
dmpIncomeRepository.save(income);
}
}, executorService)
.exceptionally((t) -> null)
.exceptionally((t) -> {
erroMessage.append(indexLine[0]).append(" 行 错误").append(t.getMessage()).append(";\n");
logger.error("the line " + indexLine[0], t);
return null;
})
).toArray(size -> new CompletableFuture[size]);
CompletableFuture.allOf(futures).join();
executorService.shutdownNow();
stopWatch.stop();
logger.info("dmp income upload {} line data use all {}s ", rowNumber - 1, stopWatch.getTotalTimeSeconds());
});
if (erroMessage.length() > 0) {
return ResultModel.ERROR(erroMessage.toString());
}
return ResultModel.OK();
}
......@@ -354,8 +387,20 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
contract.setDs(DateTime.now().toString("yyyy-MM-dd"));
String sysErro = null;
try {
//填充数据
fillDataByRow(contract, rowItem);
} catch (Exception e) {
logger.error("the line " + i, e);
sysErro = e.getMessage();
}
if (sysErro != null) {
return erroValueTip(i, sysErro);
}
//校验数据有效性
if ("erro".equals(contract.getStartDate()) || "erro".equals(contract.getEndDate())) {
return erroValueTip(i, "开始时间或结束时间");
......@@ -400,10 +445,14 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
}
}
if (!CONTRACT_TYPE_NAME.containsKey(contract.getContractType())) {
if (!CONTRACT_TYPE_NAME.containsKey(contract.getContractType()) && !"续签".equals(contract.getContractType())) {
return erroValueTip(i, "签约类型");
} else {
contract.setContractType(CONTRACT_TYPE_NAME.get(contract.getContractType()));
if ("续签".equals(contract.getContractType())) {
contract.setContractType("1");
}
}
if (!BUSINESS_TYPE_NAME.containsKey(contract.getBusinessTypeName())) {
......@@ -521,6 +570,7 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
Row rowItem = sheet.getRow(index);
//合同编号 收入月份 结算周期 系统结算 按月结算 税率 确认收入
DmpIncome income = new DmpIncome();
income.setIndex(index);
income.setContractCode(getCellStringValue(rowItem, 0));
income.setIncomeMonth(getCellDateValue(rowItem, 1, "yyyy-MM"));
income.setPeriod(getCellStringValue(rowItem, 2));
......@@ -545,6 +595,7 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
// 同一合同同一月份不重复保存
return null;
}
return income;
}
......@@ -729,4 +780,5 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
pdAttachmentRepository.delete(id);
return attachment;
}
}
......@@ -535,16 +535,16 @@ public class ShareIncomeServiceImpl implements ShareIncomeService {
//if(contract==null){
List<Contract> contractList = contractRepository.findByCreateTimeAndCodeNotOwn(groupContract.getRelationCode(), DateUtil.format(groupContract.getCreateTime(), DateUtil.C_TIME_PATTON_DEFAULT), groupContract.getId());
for (Contract contract1 : contractList) {
if(StringUtils.isEmpty(map.get(contract1.getContractCode()))){
if (StringUtils.isEmpty(map.get(contract1.getContractCode()))) {
map.put(contract1.getContractCode(), contract1);
}
}
groupContracts = map.values();//只要不加入传进来的那个list里面就不会影响查询的列表
break;
}else if((groupContracts.size()==1&&!StringUtils.isEmpty(groupContract.getNextSignedDate()))||(!"2".equals(groupContract.getContractType()) && map.get(groupContract.getNextSignedContractCode())==null)){
} else if ((groupContracts.size() == 1 && !StringUtils.isEmpty(groupContract.getNextSignedDate())) || (!"2".equals(groupContract.getContractType()) && map.get(groupContract.getNextSignedContractCode()) == null)) {
List<Contract> contractList = contractRepository.findByRelationCode(groupContract.getContractCode());
for (Contract contract1 : contractList) {
if(StringUtils.isEmpty(map.get(contract1.getContractCode()))){
if (StringUtils.isEmpty(map.get(contract1.getContractCode()))) {
map.put(contract1.getContractCode(), contract1);
}
}
......@@ -1895,7 +1895,9 @@ public class ShareIncomeServiceImpl implements ShareIncomeService {
@Override
public boolean checkLateContract(DateTime dateTime, DateTime creatTime) {
int aferDays = dateTime.monthOfYear().get() == 12 ? 29 : 9;
//int aferDays = dateTime.monthOfYear().get() == 12 ? 29 : 9;
//修改晚录判断逻辑
int aferDays = dateTime.monthOfYear().get() == 12 ? 29 : 1;
return dateTime.dayOfMonth().withMaximumValue().plusDays(aferDays).isBefore(creatTime);
}
......@@ -1962,12 +1964,14 @@ public class ShareIncomeServiceImpl implements ShareIncomeService {
public static void main(String[] args) {
DateTime dateTime = new DateTime("2020-10-30");
DateTime creatTime = new DateTime("2020-11-9");
int aferDays = dateTime.monthOfYear().get() == 12 ? 29 : 9;
System.out.println(dateTime.monthOfYear().get());
System.out.println(dateTime.dayOfMonth().withMaximumValue());
System.out.println(dateTime.dayOfMonth().withMaximumValue().plusDays(aferDays));
System.out.println(dateTime.dayOfMonth().withMaximumValue().plusDays(aferDays).isBefore(creatTime));
DateTime creatTime = new DateTime("2020-11-02");
int aferDays = dateTime.monthOfYear().get() == 12 ? 29 : 1;
System.out.println("合同开始时间" + dateTime);
System.out.println("合同录入时间" + creatTime);
System.out.println("合同开始时间在第" + dateTime.monthOfYear().get() + "月");
System.out.println("合同录入当月的最后一天日期:" + dateTime.dayOfMonth().withMaximumValue());
System.out.println("合同录入当月的最后一天日期后第" + aferDays + "天" + dateTime.dayOfMonth().withMaximumValue().plusDays(aferDays));
System.out.println("是否是晚录:" + dateTime.dayOfMonth().withMaximumValue().plusDays(aferDays).isBefore(creatTime));
dateTime.dayOfMonth().withMaximumValue().plusDays(aferDays).isBefore(creatTime);
}
......
......@@ -8,12 +8,17 @@ import common.repository.ContractRepository;
import common.repository.PackageBaseRepository;
import org.joda.time.DateTime;
import org.joda.time.Days;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import util.Constant;
import util.DateUtil;
import util.HttpClientUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -34,23 +39,23 @@ public class CASIPSendTimeTask {
PackageBaseRepository packageBaseRepository;
public void task(){
public void task() {
logger.info("CAS的IP定制发送日定时任务");
List<PackageBase> packageBases = packageBaseRepository.findByPlatAndStatus("cas", 1);
Map<Long, PackageBase> packageBaseMap = new HashMap<>();
for (PackageBase base : packageBases) {
packageBaseMap.put(base.getId(), base);
}
List<Contract> contracts = contractRepository.findByPlatformAndShareSign("cas",0);
List<Contract> contracts = contractRepository.findByPlatformAndShareSign("cas", 0);
for (Contract contract : contracts) {
PackageBase packageBase = packageBaseMap.get(contract.getPriceLevel());
ADIUser adiUser = adiAccountService.findOne(contract.getEmail(), packageBase==null?"":packageBase.getPackageName());
if(adiUser!=null&&!StringUtils.isEmpty(adiUser.getSendTime())){
ADIUser adiUser = adiAccountService.findOne(contract.getEmail(), packageBase == null ? "" : packageBase.getPackageName());
if (adiUser != null && !StringUtils.isEmpty(adiUser.getSendTime())) {
contract.setShareSign(1);
DateTime sendTime = new DateTime(DateUtil.parseDate(DateUtil.C_TIME_PATTON_DEFAULT,adiUser.getSendTime()));
DateTime sendTime = new DateTime(DateUtil.parseDate(DateUtil.C_TIME_PATTON_DEFAULT, adiUser.getSendTime()));
DateTime startDate = new DateTime(contract.getStartDate());
if(sendTime.isBefore(startDate)){
if (sendTime.isBefore(startDate)) {
sendTime = startDate;
}
DateTime endDate = new DateTime(contract.getEndDate());
......@@ -62,5 +67,66 @@ public class CASIPSendTimeTask {
contractRepository.save(contract);
}
}
//定时同步变更的账号到对应合同
syncChangedAccount(packageBaseMap);
}
//定时同步变更的账号到对应合同 (packType: 国内 海外)
public void syncChangedAccount(Map<Long, PackageBase> packageBaseMap) {
String ds = DateTime.now().plusDays(-1).toString("yyyy-MM-dd");
//国内
String url = Constant.adiUrl.split(",")[0] + "/adi/api/user/change/day?date=" + ds;
syncChangedAccount(packageBaseMap, url, "国内");
//海外
url = Constant.adiUrl.split(",")[1] + "/adi/api/user/overseas/change/day?date=" + ds;
syncChangedAccount(packageBaseMap, url, "海外");
}
//定时同步变更的账号到对应合同 (packType: 国内 海外)
public void syncChangedAccount(Map<Long, PackageBase> packageBaseMap, String url, String packType) {
String request = HttpClientUtil.doHttpGetRequest(url, "");
try {
JSONObject rs = new JSONObject(request);
if ("200".equals(rs.get("code") + "")) {
if (rs.get("content") != null && !rs.get("content").toString().startsWith("[")) {
return;
}
JSONArray array = (JSONArray) rs.get("content");
for (int i = 0; i < array.length(); i++) {
JSONObject object = (JSONObject) array.get(i);
String newEmail = object.getString("newEmail");
String originEmail = object.getString("originEmail");
if (StringUtils.isEmpty(newEmail) || StringUtils.isEmpty(originEmail)) {
continue;
}
List<Contract> contracts = contractRepository.findbyEmailAndPlatform("cas", originEmail);
if (contracts == null) {
continue;
}
List<Contract> updateList = new ArrayList<>();
for (Contract contract : contracts) {
PackageBase packageBase = packageBaseMap.get(contract.getPriceLevel());
if (packageBase.getPackageName().contains(packType)) {
contract.setEmail(newEmail);
updateList.add(contract);
}
}
if (!updateList.isEmpty()) {
//更新账号
contractRepository.save(contracts);
}
}
}
} catch (Exception e) {
logger.error("syncChangedAccount erro " + packType, e);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment