|
|
@@ -1510,6 +1510,194 @@ public class TimerServiceImpl implements TimerService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> testProjectAnalysisGroupSalary(Map<String, Object> data) {
|
|
|
+
|
|
|
+
|
|
|
+ final String[] sql = {"","","","","",""};
|
|
|
+ /*分页*/
|
|
|
+ int pageStart = (parseInt(data.get("page").toString()) - 1) * (parseInt(data.get("num").toString())-1);
|
|
|
+ int pageSize = parseInt(data.get("num").toString()) - 1;
|
|
|
+ log.info("pageStart:{}",pageStart);
|
|
|
+ log.info("pageEnd:{}",pageSize);
|
|
|
+ data.remove("page");
|
|
|
+ data.remove("num");
|
|
|
+ if (!data.containsKey("month")){
|
|
|
+ /*sql获取第一层按月求和数据*/
|
|
|
+ sql[0] = "SELECT " +
|
|
|
+ " `month`, " +
|
|
|
+ " sum( predict_income ) predict_income," +
|
|
|
+ " NULL as project_name, " +
|
|
|
+ " SUM( `open` ) `open`, " +
|
|
|
+ " SUM( income ) income, " +
|
|
|
+ " SUM( person ) person, " +
|
|
|
+ " SUM( person_cost ) person_cost, " +
|
|
|
+ " SUM( folding_repair ) folding_repair, " +
|
|
|
+ " SUM( material ) material, " +
|
|
|
+ " SUM( other_cost ) other_cost, " +
|
|
|
+ " SUM( cost_sum ) cost_sum, " +
|
|
|
+ " SUM( taxes ) taxes, " +
|
|
|
+ " SUM( gross_profit ) gross_profit, " +
|
|
|
+ " CONCAT(ROUND(SUM( gross_profit )/ SUM( income )*100,2),'%') gross_margin, " +
|
|
|
+ " SUM( overhead ) overhead, " +
|
|
|
+ " SUM( corporate_income_tax ) corporate_income_tax, " +
|
|
|
+ " SUM( net_profit ) net_profit, " +
|
|
|
+ " CONCAT(ROUND(SUM( net_profit )/ SUM( income )*100,2),'%') net_margin " +
|
|
|
+ "FROM " +
|
|
|
+ " lanyun_project_analysis_salary " +
|
|
|
+ " WHERE 1=1 " ;
|
|
|
+ /*sql获取第一层合计数据*/
|
|
|
+ sql[1]= "SELECT " +
|
|
|
+ " '总合计' as `month` , " +
|
|
|
+ " sum( predict_income ) predict_income," +
|
|
|
+ " NULL as project_name, " +
|
|
|
+ " SUM( `open` ) `open`, " +
|
|
|
+ " SUM( income ) income, " +
|
|
|
+ " SUM( person ) person, " +
|
|
|
+ " SUM( person_cost ) person_cost, " +
|
|
|
+ " SUM( folding_repair ) folding_repair, " +
|
|
|
+ " SUM( material ) material, " +
|
|
|
+ " SUM( other_cost ) other_cost, " +
|
|
|
+ " SUM( cost_sum ) cost_sum, " +
|
|
|
+ " SUM( taxes ) taxes, " +
|
|
|
+ " SUM( gross_profit ) gross_profit, " +
|
|
|
+ " CONCAT(ROUND(SUM( gross_profit )/ SUM( income )*100,2),'%') gross_margin, " +
|
|
|
+ " SUM( overhead ) overhead, " +
|
|
|
+ " SUM( corporate_income_tax ) corporate_income_tax, " +
|
|
|
+ " SUM( net_profit ) net_profit, " +
|
|
|
+ " CONCAT(ROUND(SUM( net_profit )/ SUM( income )*100,2),'%') net_margin " +
|
|
|
+ "FROM " +
|
|
|
+ " lanyun_project_analysis_salary " +
|
|
|
+ "WHERE 1=1 " ;
|
|
|
+ /*sql获取第一层数据总数*/
|
|
|
+ sql[2] = "SELECT " +
|
|
|
+ " COUNT(*) total_count " +
|
|
|
+ "FROM " +
|
|
|
+ " ( SELECT `month` FROM lanyun_project_analysis_salary WHERE 1 = 1 " ;
|
|
|
+ if (ObjectUtil.isNotNull(data.get("startDate"))) {
|
|
|
+ sql[0] = sql[0] + " AND `month` >= \"" + data.get("startDate") +"\" " ;
|
|
|
+ sql[1] = sql[1] + " AND `month` >= \"" + data.get("startDate") +"\" " ;
|
|
|
+ sql[2] = sql[2] + " AND `month` >= \"" + data.get("startDate") +"\" " ;
|
|
|
+ } else if (ObjectUtil.isNotNull(data.get("endDate"))) {
|
|
|
+ sql[0] = sql[0] + " AND `month` <= \"" + data.get("endDate") +"\" " ;
|
|
|
+ sql[1] = sql[1] + " AND `month` <= \"" + data.get("endDate") +"\" " ;
|
|
|
+ sql[2] = sql[2] + " AND `month` <= \"" + data.get("endDate") +"\" " ;
|
|
|
+ }
|
|
|
+ sql[0] = sql[0] +
|
|
|
+ " GROUP BY " +
|
|
|
+ " `month`" +
|
|
|
+ " order by `month` DESC LIMIT " + pageStart + "," + pageSize;
|
|
|
+ sql[2] = sql[2] +
|
|
|
+ " GROUP BY `month` ) t1 ";
|
|
|
+ log.info("sql[0]:{}",sql[0]);
|
|
|
+ log.info("sql[1]:{}",sql[1]);
|
|
|
+ }else {
|
|
|
+ /*sql获取第二层月明细数据*/
|
|
|
+ sql[0] = "SELECT " +
|
|
|
+ " `month`," +
|
|
|
+ " project_name, " +
|
|
|
+ " predict_income, " +
|
|
|
+ " folding_repair, " +
|
|
|
+ " `open`, " +
|
|
|
+ " income, " +
|
|
|
+ " person, " +
|
|
|
+ " person_cost, " +
|
|
|
+ " material, " +
|
|
|
+ " other_cost, " +
|
|
|
+ " cost_sum, " +
|
|
|
+ " taxes, " +
|
|
|
+ " gross_profit, " +
|
|
|
+ " CONCAT(ROUND(gross_margin*100,2),'%') gross_margin, " +
|
|
|
+ " overhead, " +
|
|
|
+ " corporate_income_tax, " +
|
|
|
+ " net_profit, " +
|
|
|
+ " CONCAT(ROUND(net_margin*100,2),'%') net_margin " +
|
|
|
+ "FROM " +
|
|
|
+ " lanyun_project_analysis_salary " +
|
|
|
+ " WHERE 1=1";
|
|
|
+ /*sql获取第二层合计数据*/
|
|
|
+ sql[1] = "SELECT " +
|
|
|
+ " '总合计' as `month`, " +
|
|
|
+ " sum( predict_income ) predict_income," +
|
|
|
+ " NULL as project_name, " +
|
|
|
+ " SUM( `open` ) `open`, " +
|
|
|
+ " SUM( income ) income, " +
|
|
|
+ " SUM( person ) person, " +
|
|
|
+ " SUM( folding_repair ) folding_repair, " +
|
|
|
+ " SUM( person_cost ) person_cost, " +
|
|
|
+ " SUM( material ) material, " +
|
|
|
+ " SUM( other_cost ) other_cost, " +
|
|
|
+ " SUM( cost_sum ) cost_sum, " +
|
|
|
+ " SUM( taxes ) taxes, " +
|
|
|
+ " SUM( gross_profit ) gross_profit, " +
|
|
|
+ " CONCAT(ROUND(SUM( gross_profit )/ SUM( income )*100,2),'%') gross_margin, " +
|
|
|
+ " SUM( overhead ) overhead, " +
|
|
|
+ " SUM( corporate_income_tax ) corporate_income_tax, " +
|
|
|
+ " SUM( net_profit ) net_profit, " +
|
|
|
+ " CONCAT(ROUND(SUM( net_profit )/ SUM( income )*100,2),'%') net_margin " +
|
|
|
+ " FROM " +
|
|
|
+ " lanyun_project_analysis_salary " +
|
|
|
+ " WHERE 1=1 ";
|
|
|
+ /*sql获取第二层数据总数*/
|
|
|
+ sql[2] = "SELECT " +
|
|
|
+ " COUNT(*) total_count " +
|
|
|
+ " FROM " +
|
|
|
+ " lanyun_project_analysis_salary " +
|
|
|
+ " WHERE 1=1 ";
|
|
|
+ if (data.containsKey("startDate") || data.containsKey("endDate")){
|
|
|
+ data.remove("month");
|
|
|
+ }
|
|
|
+ data.forEach((k,v)->{
|
|
|
+ if (k.equals("low") && ObjectUtil.isNotNull(v)){
|
|
|
+ sql[0] = sql[0] + " AND `net_margin` < 0.05" ;
|
|
|
+ sql[1] = sql[1] + " AND `net_margin` < 0.05" ;
|
|
|
+ sql[2] = sql[2] + " AND `net_margin` < 0.05" ;
|
|
|
+ } else if (ObjectUtil.isNotNull(v) && k.equals("startDate")) {
|
|
|
+ sql[0] = sql[0] + " AND `month` >= \"" + v +"\"" ;
|
|
|
+ sql[1] = sql[1] + " AND `month` >= \"" + v +"\"" ;
|
|
|
+ sql[2] = sql[2] + " AND `month` >= \"" + v +"\"" ;
|
|
|
+ } else if (ObjectUtil.isNotNull(v) && k.equals("endDate")) {
|
|
|
+ sql[0] = sql[0] + " AND `month` <= \"" + v +"\"" ;
|
|
|
+ sql[1] = sql[1] + " AND `month` <= \"" + v +"\"" ;
|
|
|
+ sql[2] = sql[2] + " AND `month` <= \"" + v +"\"" ;
|
|
|
+ } else if (ObjectUtil.isNotNull(v) && !k.equals("low")){
|
|
|
+ sql[0] = sql[0] + " AND `" + k +"` = \"" + v +"\"" ;
|
|
|
+ sql[1] = sql[1] + " AND `" + k +"` = \"" + v +"\"" ;
|
|
|
+ sql[2] = sql[2] + " AND `" + k +"` = \"" + v +"\"" ;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ sql[0] = sql[0] + " order by `month` DESC LIMIT " + pageStart + "," + pageSize;
|
|
|
+ log.info("sql[0]:{}",sql[0]);
|
|
|
+ log.info("sql[2]:{}",sql[2]);
|
|
|
+ }
|
|
|
+ sql[3]="SELECT DISTINCT project_name FROM lanyun_project_analysis_salary;";
|
|
|
+ sql[4]="SELECT DISTINCT format FROM lanyun_project_analysis_salary;";
|
|
|
+ sql[5]="SELECT DISTINCT customer_system FROM lanyun_project_analysis_salary;";
|
|
|
+
|
|
|
+ List<ProjectAnalysis> analysisList = jdbcTemplate.query(sql[0], new ProjectAnalysisMapper());
|
|
|
+ List<ProjectAnalysis> analysisSum= jdbcTemplate.query(sql[1], new ProjectAnalysisMapper());
|
|
|
+ List<Map<String, Object>> result = jdbcTemplate.queryForList(sql[2]);
|
|
|
+ int totalCount = 0;
|
|
|
+ if (result.size() >0) {
|
|
|
+ totalCount = parseInt(result.get(0).get("total_count").toString());
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> projects = jdbcTemplate.queryForList(sql[3]);
|
|
|
+ projects.get(0).forEach((k,v)->{
|
|
|
+
|
|
|
+ });
|
|
|
+ List<Map<String, Object>> formats = jdbcTemplate.queryForList(sql[4]);
|
|
|
+ List<Map<String, Object>> customers = jdbcTemplate.queryForList(sql[5]);
|
|
|
+ analysisList.add(analysisSum.get(0));
|
|
|
+ log.info("results:{}",analysisList);
|
|
|
+ Map<String, Object> map = UtilMap.map("totalCount, data, projects, formats, customers", totalCount, analysisList,projects,formats,customers);
|
|
|
+ if (ObjectUtil.isNotNull(analysisList)&&analysisList.size()>0){
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void getProject(String formInstId, String projectCode, String monthAmount) {
|
|
|
List<Map> dataList = ydService.queryFormData_all(YDParam.builder()
|
|
|
@@ -1565,20 +1753,35 @@ public class TimerServiceImpl implements TimerService {
|
|
|
dataList.forEach(formData -> {
|
|
|
Long withdrawalTime = formData.get("dateField_lzaqu26p")==null?null:DateUtil.beginOfMonth(DateUtil.date(Long.parseLong(formData.get("dateField_lzaqu26p").toString()))).getTime();
|
|
|
List<Map> details = UtilMap.getList(formData, "tableField_lrru2tnq");
|
|
|
+ //标准月金额
|
|
|
+ Float bzyje = UtilMap.getFloat(formData, "numberField_lt590fke");
|
|
|
for (int i = 0; i < allTimestamp.size(); i++) {
|
|
|
int finalI = i;
|
|
|
+ Date date = new Date(allTimestamp.get(finalI));
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(date);
|
|
|
+ // 设置日期为当月第一天
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ // 调整为下月第一天
|
|
|
+ calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) + 1);
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
+
|
|
|
+ // 返回最后一天的时间戳
|
|
|
+ long lastTime = calendar.getTimeInMillis();
|
|
|
//获取撤场时间
|
|
|
if (UtilMap.getString(formData, "selectField_lrn2oy4a").equals("进行中") || (ObjectUtil.isNotNull(withdrawalTime) && Objects.equals(allTimestamp.get(finalI), withdrawalTime))){
|
|
|
|
|
|
try {
|
|
|
- Optional optional = details.stream().filter(item -> allTimestamp.get(finalI) == UtilMap.getLong(item, "dateField_lrru2tnr")).findAny();
|
|
|
+ Optional optional = details.stream().filter(item -> allTimestamp.get(finalI) <= UtilMap.getLong(item, "dateField_lrru2tnr") && UtilMap.getLong(item, "dateField_lrru2tnr") < lastTime).findAny();
|
|
|
if (!optional.isPresent()) {
|
|
|
- return;
|
|
|
+ continue;
|
|
|
}
|
|
|
Map currentRow = (Map) optional.get();
|
|
|
- float open = UtilMap.getFloat(currentRow, "numberField_lryopn7o_value");
|
|
|
+ float open = bzyje;
|
|
|
if (ObjectUtil.isNotNull(currentRow.get("numberField_lrru2to2_value")) && UtilMap.getFloat(currentRow, "numberField_lrru2to2_value") > 0){
|
|
|
open = UtilMap.getFloat(currentRow, "numberField_lrru2to2_value");
|
|
|
+ } else if (ObjectUtil.isNotNull(currentRow.get("numberField_lryopn7o_value")) && UtilMap.getFloat(currentRow, "numberField_lryopn7o_value") > 0) {
|
|
|
+ open = UtilMap.getFloat(currentRow, "numberField_lryopn7o_value");
|
|
|
}
|
|
|
//明细合计
|
|
|
currentRow.put("numberField_m1hhyqiv", open + UtilMap.getFloat(currentRow, "numberField_m5uf580r_value"));
|
|
|
@@ -1647,6 +1850,17 @@ public class TimerServiceImpl implements TimerService {
|
|
|
|
|
|
for (int i = 0; i < allTimestamp.size(); i++) {
|
|
|
int finalI = i;
|
|
|
+ Date date = new Date(allTimestamp.get(finalI));
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(date);
|
|
|
+ // 设置日期为当月第一天
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ // 调整为下月第一天
|
|
|
+ calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) + 1);
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
+
|
|
|
+ // 返回最后一天的时间戳
|
|
|
+ long lastTime = calendar.getTimeInMillis();
|
|
|
// 获取撤场时间
|
|
|
if (UtilMap.getString(formData, "selectField_lrn2oy4a").equals("进行中")
|
|
|
|| (ObjectUtil.isNotNull(withdrawalTime) && Objects.equals(allTimestamp.get(finalI), withdrawalTime))) {
|
|
|
@@ -1655,8 +1869,7 @@ public class TimerServiceImpl implements TimerService {
|
|
|
details.stream()
|
|
|
.filter(
|
|
|
item ->
|
|
|
- allTimestamp.get(finalI)
|
|
|
- == UtilMap.getLong(item, "dateField_lrru2tnr"))
|
|
|
+ allTimestamp.get(finalI) <= UtilMap.getLong(item, "dateField_lrru2tnr") && UtilMap.getLong(item, "dateField_lrru2tnr") < lastTime)
|
|
|
.findAny();
|
|
|
log.info("上个月数据, {}, {}", allTimestamp.get(finalI), optional);
|
|
|
|
|
|
@@ -1667,9 +1880,7 @@ public class TimerServiceImpl implements TimerService {
|
|
|
open = UtilMap.getFloat(currentRow, "numberField_m1hhyqiv_value");
|
|
|
}
|
|
|
// 明细合计
|
|
|
- currentRow.put(
|
|
|
- "numberField_m8gn1uof",
|
|
|
- open + UtilMap.getFloat(currentRow, "numberField_m5uf580r_value"));
|
|
|
+ currentRow.put("numberField_m8gn1uof", open);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
@@ -1787,6 +1998,73 @@ public class TimerServiceImpl implements TimerService {
|
|
|
|
|
|
UtilExcel.exportMapAndListByTemplate(response, null, analysisList, ProjectAnalysis.class, fileName, "NC.xlsx");
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getProjectAnalysisForContract(Map<String, Object> data) {
|
|
|
+
|
|
|
+ List<Map> dataList = ydService.queryFormData_all(YDParam.builder()
|
|
|
+ .appType("APP_ERBDTFS82HOVBPL3NFH0")
|
|
|
+ .systemToken("RRB66F91T97H1WN89QZYC47PKLZO2ZQOUMOQLP")
|
|
|
+ .formUuid("FORM-97BA6C6C8C50416A9E5854F2F4B5C3F3R4WC")
|
|
|
+ .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lrr3rg6h",data.get("xmcode"))))
|
|
|
+ .build());
|
|
|
+ String names = "('";
|
|
|
+ for (int i = 0; i < dataList.size(); i++) {
|
|
|
+ names = names + dataList.get(i).get("textField_ltxrn8h1") + "','";
|
|
|
+ }
|
|
|
+ names = names + "')";
|
|
|
+
|
|
|
+ List<Long> lastTimestamp = getLastTimestamp();
|
|
|
+ Date date = new Date(lastTimestamp.get(lastTimestamp.size()-1));
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(date);
|
|
|
+ // 设置日期为当月第一天
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ // 调整为下月第一天
|
|
|
+ calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) + 1);
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ long lastTime = calendar.getTimeInMillis();
|
|
|
+
|
|
|
+ String sql = "SELECT\n" +
|
|
|
+ "\tsum( predict_income )/12 predict_income,\n" +
|
|
|
+ "\tSUM( `open` )/12 `open`,\n" +
|
|
|
+ "\tSUM( income )/12 income,\n" +
|
|
|
+ "\tSUM( person )/12 person,\n" +
|
|
|
+ "\tSUM( folding_repair )/12 folding_repair,\n" +
|
|
|
+ "\tSUM( person_cost )/12 person_cost,\n" +
|
|
|
+ "\tSUM( material )/12 material,\n" +
|
|
|
+ "\tSUM( other_cost )/12 other_cost,\n" +
|
|
|
+ "\tSUM( cost_sum )/12 cost_sum,\n" +
|
|
|
+ "\tSUM( taxes )/12 taxes,\n" +
|
|
|
+ "\tSUM( gross_profit )/12 gross_profit,\n" +
|
|
|
+ "\tCONCAT( ROUND( SUM( gross_profit )/ SUM( income )* 100, 2 ), '%' ) gross_margin,\n" +
|
|
|
+ "\tSUM( overhead )/12 overhead,\n" +
|
|
|
+ "\tSUM( corporate_income_tax )/12 corporate_income_tax,\n" +
|
|
|
+ "\tSUM( net_profit )/12 net_profit,\n" +
|
|
|
+ "\tCONCAT( ROUND( SUM( net_profit )/ SUM( income )* 100, 2 ), '%' ) net_margin \n" +
|
|
|
+ "FROM\n" +
|
|
|
+ "\tlanyun_project_analysis\n" +
|
|
|
+ "\tWHERE 1=1 \n" +
|
|
|
+ "\tAND CAST(`month` AS CHAR) < '"+lastTime+"'\n" +
|
|
|
+ "\tAND CAST(`month` AS CHAR) >= '"+lastTimestamp.get(0)+"'\n" +
|
|
|
+ "\tAND project_code in "+names+"";
|
|
|
+
|
|
|
+ List<ProjectAnalysis> analysisList = jdbcTemplate.query(sql, new ProjectAnalysisMapper());
|
|
|
+
|
|
|
+ System.out.println(sql);
|
|
|
+
|
|
|
+ ydClient.operateData(YDParam.builder()
|
|
|
+ .appType("APP_ERBDTFS82HOVBPL3NFH0")
|
|
|
+ .systemToken("RRB66F91T97H1WN89QZYC47PKLZO2ZQOUMOQLP")
|
|
|
+ .formInstanceId(data.get("formInstanceId").toString())
|
|
|
+ .useLatestVersion(true)
|
|
|
+ .updateFormDataJson(JSON.toJSONString(UtilMap.map("numberField_ly418zpc, numberField_ly418zq9, numberField_m60tn0xu",
|
|
|
+ analysisList.get(0).getPersonCost(),analysisList.get(0).getMaterial(),analysisList.get(0).getFoldingRepair())))
|
|
|
+ .build(), YDConf.FORM_OPERATION.update);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+// 获取本年所有月时间戳
|
|
|
public List<Long> getAllTimestamp(){
|
|
|
LocalDate now = LocalDate.now();
|
|
|
int currentYear = now.getYear();
|
|
|
@@ -1802,4 +2080,18 @@ public class TimerServiceImpl implements TimerService {
|
|
|
}
|
|
|
return timestamps;
|
|
|
}
|
|
|
+
|
|
|
+// 获取前12个月时间戳
|
|
|
+ public List<Long> getLastTimestamp(){
|
|
|
+ LocalDate currentDate = LocalDate.now();
|
|
|
+ List<Long> timestamps = new ArrayList<>();
|
|
|
+
|
|
|
+ for (int i = 0; i < 12; i++) {
|
|
|
+ LocalDate date = currentDate.minusMonths(i + 1).withDayOfMonth(1);
|
|
|
+ long timestamp = date.atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
|
|
+ timestamps.add(timestamp);
|
|
|
+ }
|
|
|
+ Collections.reverse(timestamps); // 反转列表以按时间顺序排列
|
|
|
+ return timestamps;
|
|
|
+ }
|
|
|
}
|