Commit b3b6294d by kangxiaoshan

分摊财务收入报表

parent 6887b5dc
......@@ -6,6 +6,7 @@ import dic.AuthMenuEnmm;
import dic.ContractStatusEnum;
import dic.OperateObjectTypeEnum;
import org.apache.commons.io.IOUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -16,7 +17,6 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import security.annotation.AuthKey;
import security.annotation.CurrentAccount;
import util.*;
......@@ -24,9 +24,10 @@ import util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -238,8 +239,7 @@ public class ContractController {
@RequestMapping(value = "find/rebat", method = RequestMethod.GET)
@ResponseBody
public ResultModel rebat(@CurrentAccount User loginAccount, @RequestParam String product,
@RequestParam Integer level, @RequestParam Long money) {
public ResultModel rebat(@CurrentAccount User loginAccount, @RequestParam String product, @RequestParam Integer level, @RequestParam Long money) {
return ResultModel.OK(service.getRebat(product, level, money));
}
......@@ -402,20 +402,87 @@ public class ContractController {
}
@RequestMapping(value = "/upload",method = RequestMethod.POST)
@RequestMapping(value = "/upload", method = RequestMethod.POST)
@ResponseBody
public ResultModel fileUpload2(@RequestParam("file") MultipartFile file, @PathVariable String platform) {
return service.uploadBatchInfo(file,platform);
return service.uploadBatchInfo(file, platform);
}
@RequestMapping(value = "/upload/tempurl",method = RequestMethod.GET)
@RequestMapping(value = "/upload/tempurl", method = RequestMethod.GET)
@ResponseBody
public ResultModel fileTempUrl() {
return ResultModel.OK(Constant.importTempUrl);
}
/**
* 分摊收入
*
* @param loginAccount
* @param platform
* @param startDate
* @param endDate
* @param serchName
* @return
*/
@RequestMapping(value = "/shareincome/list", method = RequestMethod.GET)
@ResponseBody
@AuthKey(AuthMenuEnmm.CONTRACTMNG_V)
public ResultModel shareIncome(@CurrentAccount User loginAccount, @PathVariable String platform,
@RequestParam String startDate, @RequestParam String endDate,
String bodyCode, String serchName) {
return ResultModel.OK(service.shareIncomeList(loginAccount, startDate, endDate, platform, bodyCode, serchName));
}
@RequestMapping(value = "/shareincome/export", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@ResponseBody
@AuthKey(AuthMenuEnmm.CONTRACTMNG_V)
public ResponseEntity<byte[]> shareIncomeExport(@CurrentAccount User loginAccount, @PathVariable String platform,
@RequestParam String startDate, @RequestParam String endDate,
String bodyCode, String serchName, HttpServletResponse response, HttpServletRequest request) {
List<Contract> contracts = service.shareIncomeList(loginAccount, startDate, endDate, platform, bodyCode, serchName);
byte[] content = new byte[0];
DecimalFormat df = new DecimalFormat("##,##0.00");
StringBuilder sb = new StringBuilder();
sb.append("我方签约主体,签约方,合同编号,合同金额,不含税收入,合同开始时间,合同截止时间,区间使用天数,区间分摊收入,调整额,分摊总收入\r\n");
if (ValidateUtil.isValid(contracts)) {
for (Contract c : contracts) {
sb.append(c.getMyBodyName())
.append(c.getCustomerBody())
.append(c.getContractCode())
.append(df.format(c.getMoney()))
.append(df.format(c.getIncomeExcludingTax() * 1.0 / 100))
.append(c.getStartDate())
.append(c.getEndDate())
.append(c.getIntervalUseDays())
.append(df.format(c.getIntervaIncomeShare() * 1.0 / 100))
.append(c.getAdjustmentFund())
.append(df.format(c.getIncomeShareAll() * 1.0 / 100))
.append("\r\n");
}
}
InputStream in = new ByteArrayInputStream(sb.toString().getBytes());
try {
content = IOUtils.toByteArray(in);
} catch (IOException e) {
e.printStackTrace();
}
String fileName = "contract_shareincome_" + new DateTime().toString("yyyy_MM_dd") + ".csv";
HttpHeaders headers = new HttpHeaders();
response.setHeader("filename", fileName);
response.setHeader("content-disposition", "attachment; filename=" + fileName);
response.setHeader("Content-Type", "text/csv");
response.setContentType("APPLICATION/OCTET-STREAM");
NewUserLogThread userlog = new NewUserLogThread(loginAccount.getEmail(), loginAccount.getName(), OperateObjectTypeEnum.INNERUSER.getKey(), platform, "导出分摊收入报表", startDate, endDate, request, platform);
userlog.start();
//返回文件字符串
return new ResponseEntity<byte[]>(content, headers, HttpStatus.CREATED);
}
}
......@@ -55,6 +55,12 @@ public class Contract {
private Long firstBackId;//先回款记录的id
private Long adjustmentFund;// 分摊收入调整金额
private Integer intervalUseDays;//区间使用天数
private Long incomeExcludingTax; //不含税收入 (*100的结果)
private Long intervaIncomeShare;//区间分摊收入(*100的结果)
private Long incomeShareAll;//分摊总收入(*100的结果)
/**
* 新增字段 20190427
......@@ -71,9 +77,7 @@ public class Contract {
private String hasDiscount;// 是否有优惠
private String typeId;// 合同类型 (保密协议、框架合同、结算单)
private String erroMessage;
private String tradeName;
......@@ -444,6 +448,52 @@ public class Contract {
this.tradeName = tradeName;
}
public Long getAdjustmentFund() {
return adjustmentFund;
}
public void setAdjustmentFund(Long adjustmentFund) {
this.adjustmentFund = adjustmentFund;
}
@Transient
public Integer getIntervalUseDays() {
return intervalUseDays;
}
public void setIntervalUseDays(Integer intervalUseDays) {
this.intervalUseDays = intervalUseDays;
}
@Transient
public Long getIncomeExcludingTax() {
return incomeExcludingTax;
}
@Transient
public void setIncomeExcludingTax(Long incomeExcludingTax) {
this.incomeExcludingTax = incomeExcludingTax;
}
public Long getIntervaIncomeShare() {
return intervaIncomeShare;
}
@Transient
public void setIntervaIncomeShare(Long intervaIncomeShare) {
this.intervaIncomeShare = intervaIncomeShare;
}
@Transient
public Long getIncomeShareAll() {
return incomeShareAll;
}
public void setIncomeShareAll(Long incomeShareAll) {
this.incomeShareAll = incomeShareAll;
}
// public String getCreaterName() {
// return createrName;
// }
......
package common.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
@Deprecated
public class IncomeShare {
private Long id;
private String myBodyName;
private String myBodyCode;
private String contractCode;
private String customerBody;
private Long money; //合同金额
private Long incomeExcludingTax; //不含税收入
private String startDate;
private String endDate;
private Integer intervalUseDays;//区间使用天数
private Long intervaIncomeShare;//区间分摊收入
public IncomeShare() {
}
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getMyBodyName() {
return myBodyName;
}
public void setMyBodyName(String myBodyName) {
this.myBodyName = myBodyName;
}
public String getMyBodyCode() {
return myBodyCode;
}
public void setMyBodyCode(String myBodyCode) {
this.myBodyCode = myBodyCode;
}
public String getContractCode() {
return contractCode;
}
public void setContractCode(String contractCode) {
this.contractCode = contractCode;
}
public String getCustomerBody() {
return customerBody;
}
public void setCustomerBody(String customerBody) {
this.customerBody = customerBody;
}
public Long getMoney() {
return money;
}
public void setMoney(Long money) {
this.money = money;
}
public Long getIncomeExcludingTax() {
return incomeExcludingTax;
}
public void setIncomeExcludingTax(Long incomeExcludingTax) {
this.incomeExcludingTax = incomeExcludingTax;
}
public String getStartDate() {
return startDate;
}
public void setStartDate(String startDate) {
this.startDate = startDate;
}
public String getEndDate() {
return endDate;
}
public void setEndDate(String endDate) {
this.endDate = endDate;
}
public Integer getIntervalUseDays() {
return intervalUseDays;
}
public void setIntervalUseDays(Integer intervalUseDays) {
this.intervalUseDays = intervalUseDays;
}
public Long getIntervaIncomeShare() {
return intervaIncomeShare;
}
public void setIntervaIncomeShare(Long intervaIncomeShare) {
this.intervaIncomeShare = intervaIncomeShare;
}
}
......@@ -97,4 +97,16 @@ public interface ContractRepository extends JpaRepository<Contract, Long> {
@Query(value = "select contract_code,my_body_code,sale,platform from contract where contract_code in ?1",nativeQuery = true)
List<Object[]> findByContractCode(List<String> codesList);
@Query(value="select * from contract where start_date >= ?1 and strat_date <=?2 and end_date >= ?2 and create_time >= ?2 and platform=?3",nativeQuery = true)
List<Contract> findShareContranctByDate(String startDate, String endDate, String platform);
@Query(value="select * from contract where start_date >= ?1 and strat_date <=?2 and end_date >= ?2 and create_time >= ?2 and platform=?3 and my_body_code = ?4",nativeQuery = true)
List<Contract> findShareContranctByDate(String startDate, String endDate, String platform, String bodyCode);
@Query(value="select * from contract where start_date >= ?1 and strat_date <=?2 and end_date >= ?2 and create_time >= ?2 and platform=?3 and (my_body_name like %?5% or customer_body like %?5% or contract_code like %?5%)",nativeQuery = true)
List<Contract> findShareContranctByDateSerche(String startDate, String endDate, String platform, String serchName);
@Query(value="select * from contract where start_date >= ?1 and strat_date <=?2 and end_date >= ?2 and create_time >= ?2 and platform=?3 and my_body_code = ?4 and (my_body_name like %?5% or customer_body like %?5% or contract_code like %?5%)",nativeQuery = true)
List<Contract> findShareContranctByDate(String startDate, String endDate, String platform, String bodyCode, String serchName);
}
......@@ -76,4 +76,6 @@ public interface ContractService {
List<ContractMoney> findPayAll(User loginAccount,String startDate, String endDate, String platform, String moneyType, String packageType, String money_ids);
ResultModel uploadBatchInfo(MultipartFile file, String platform);
List<Contract> shareIncomeList(User loginAccount, String startDate, String endDate, String platform, String bodyCode,String serchName);
}
\ No newline at end of file
......@@ -14,6 +14,7 @@ import dic.RoleEnum;
import net.sf.json.JSONArray;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.DateTime;
import org.joda.time.Days;
import org.joda.time.format.DateTimeFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -45,6 +46,7 @@ import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
......@@ -2252,7 +2254,7 @@ public class ContractServiceImpl implements ContractService {
} else if ("money".equals(sheetTitle)) {
s_data[w] = dataSTR.replace(",","");
s_data[w] = dataSTR.replace(",", "");
} else {
s_data[w] = dataSTR;
}
......@@ -2332,18 +2334,92 @@ public class ContractServiceImpl implements ContractService {
return true;
}
@Override
public List<Contract> shareIncomeList(User loginAccount, String startDate, String endDate, String platform, String bodyCode, String serchName) {
List<Contract> contracts = new ArrayList<>();
if (!StringUtils.isEmpty(bodyCode) && !StringUtils.isEmpty(serchName)) {
contracts = contractRepository.findShareContranctByDate(startDate, endDate, platform, bodyCode, serchName);
} else if (!StringUtils.isEmpty(bodyCode)) {
contracts = contractRepository.findShareContranctByDate(startDate, endDate, platform, bodyCode);
} else if (!StringUtils.isEmpty(serchName)) {
contracts = contractRepository.findShareContranctByDateSerche(startDate, endDate, platform, serchName);
} else {
contracts = contractRepository.findShareContranctByDate(startDate, endDate, platform);
}
DecimalFormat decimalFormat = new DecimalFormat("###,###.00");
contracts.forEach(v -> {
//以下结果统一 *100
//不含稅收入
// Long excludTax = v.getMoney() * 6 / 100;
Long excludTax = (long) (v.getMoney() * 100 * 0.06);
v.setIncomeExcludingTax(excludTax);
DateTime formStart = new DateTime(startDate);
DateTime formEnd = new DateTime(endDate);
DateTime contractStart = new DateTime(v.getStartDate());
DateTime contractEnd = new DateTime(v.getEndDate());
// 时间范围是否包含合同结束日期
boolean containEnd = formEnd.compareTo(contractEnd) > 0;
// 时间范围是否包含合同结束开始日期
boolean containStart = formStart.compareTo(contractStart) > 0;
//所选结束时间包含合同结束时间 取合同结束时间 反之 取所选结束时间
DateTime usedEnd = containEnd ? contractEnd : formEnd;
//所选开始时间包含合同开始时间 则取合同开始时间 反之 取所选开始时间
DateTime usedStart = containStart ? contractEnd : formEnd;
v.setIntervalUseDays(Days.daysBetween(contractStart, usedEnd).getDays() + 1);//区间使用天数
//合同总天数
int contracAllDays = Days.daysBetween(contractStart, contractEnd).getDays() + 1;
// 处理后的选择范围天数
int contractFormRange = Days.daysBetween(usedStart, usedEnd).getDays() + 1;
//区间分摊收入
Long intervalIncome = 0L;
if (containEnd) {
//时间范围合同结束时间时 分两部分计算
//第一部分
intervalIncome = (v.getMoney() * 100) / contracAllDays * (contractFormRange - 1);
//第二部分
Long intervalIncomePart2 = v.getMoney() * 100 - (v.getMoney() * 100 / contracAllDays * (contracAllDays - 1));
intervalIncome += intervalIncomePart2;
v.setIntervaIncomeShare(intervalIncome);
} else {
intervalIncome = v.getMoney() * 100 / contracAllDays * contractFormRange;
v.setIntervaIncomeShare(intervalIncome);
}
if (v.getAdjustmentFund() == null) {
v.setAdjustmentFund(0L);
}
//分摊总收入
v.setIncomeShareAll(intervalIncome + v.getAdjustmentFund() * 100);
});
return contracts;
}
public static void main(String[] args) {
String dateStr = "2019/4/31";
// //根据时间表达式生成DateTimeFormatter对象
// DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy/MM/dd");
// //2019-10-28T10:23:12.000+08:00
// DateTime dateTime = fmt.parseDateTime(dateStr);
// System.out.println(dateTime.getDayOfMonth());
// dateTime = dateTime.plusDays(-1);
// System.out.println(dateTime.toString("yyyy-MM-dd"));
String pattern = "yyyy/MM/dd";
DateTime dateTime2 = DateTime.parse(dateStr, DateTimeFormat.forPattern(pattern));
System.out.println(dateTime2.toString("yyyy-MM-dd"));
// String dateStr1 = "2019-04-30";
// String dateStr2 = "2019-04-01";
//
// System.out.println(new DateTime(dateStr2).compareTo(new DateTime(dateStr1)));
// System.out.println(Days.daysBetween(new DateTime(dateStr2), new DateTime(dateStr1)).getDays());
System.out.println(10023L * 1.0 / 100);
System.out.println((129 * 100 / 111)*1.0/100);
System.out.println();
}
}
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