12 changed files with 769 additions and 235 deletions
@ -0,0 +1,245 @@ |
|||||
|
package com.dreamchaser.depository_manage; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import com.dreamchaser.depository_manage.entity.UserByPort; |
||||
|
import com.dreamchaser.depository_manage.service.DepositoryRecordService; |
||||
|
import com.dreamchaser.depository_manage.service.DepositoryService; |
||||
|
import com.dreamchaser.depository_manage.service.MaterialService; |
||||
|
import com.dreamchaser.depository_manage.service.MaterialTypeService; |
||||
|
import com.dreamchaser.depository_manage.utils.DateUtil; |
||||
|
import com.dreamchaser.depository_manage.utils.LinkInterfaceUtil; |
||||
|
import lombok.Data; |
||||
|
import org.junit.Test; |
||||
|
import org.junit.runner.RunWith; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||
|
import org.springframework.test.context.junit4.SpringRunner; |
||||
|
|
||||
|
import java.text.SimpleDateFormat; |
||||
|
import java.util.*; |
||||
|
import java.util.concurrent.*; |
||||
|
|
||||
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
||||
|
@RunWith(SpringRunner.class) |
||||
|
public class BarChartTest { |
||||
|
|
||||
|
|
||||
|
@Autowired |
||||
|
MaterialTypeService materialTypeService; |
||||
|
|
||||
|
@Autowired |
||||
|
DepositoryRecordService depositoryRecordService; |
||||
|
|
||||
|
@Autowired |
||||
|
MaterialService materialService; |
||||
|
|
||||
|
@Autowired |
||||
|
DepositoryService depositoryService; |
||||
|
|
||||
|
/** |
||||
|
* 获取本月之前的月份 |
||||
|
* |
||||
|
* @return |
||||
|
*/ |
||||
|
public static Map<String, Object> getPreviousMonth() { |
||||
|
Calendar instance = Calendar.getInstance(); |
||||
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM"); |
||||
|
Map<String, Object> source = new HashMap<>(); |
||||
|
List<Object> sourceList = new ArrayList<>(); |
||||
|
int month = instance.get(Calendar.MONTH) + 1; |
||||
|
// 获取下个月
|
||||
|
instance.add(Calendar.MONTH, 1); |
||||
|
Long nextMonth = DateUtil.DateTimeByMonthToTimeStamp(formatter.format(instance.getTime())); |
||||
|
ArrayList<Object> months = new ArrayList<>(); |
||||
|
months.add(nextMonth); |
||||
|
instance.add(Calendar.MONTH, -1); |
||||
|
|
||||
|
while (month > 0) { |
||||
|
instance.set(Calendar.MONTH, month); |
||||
|
instance.set(Calendar.DAY_OF_MONTH, -1); |
||||
|
source.put("month", month + "月"); |
||||
|
months.add(DateUtil.DateTimeByMonthToTimeStamp(formatter.format(instance.getTime()))); |
||||
|
month--; |
||||
|
sourceList.add(((HashMap<String, Object>) source).clone()); |
||||
|
} |
||||
|
instance.set(Calendar.MONTH, month); |
||||
|
instance.add(Calendar.MONTH, 1); |
||||
|
Map<String, Object> map = new HashMap<>(); |
||||
|
map.put("months", months); |
||||
|
map.put("sourceList", sourceList); |
||||
|
return map; |
||||
|
} |
||||
|
|
||||
|
@Test |
||||
|
public void main() { |
||||
|
UserByPort userByPort = LinkInterfaceUtil.FindUserById(87, null); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 用于获取出入库对照柱状图 |
||||
|
* @param userByPort 待获取的当前用户 |
||||
|
* @return |
||||
|
*/ |
||||
|
List<Object> getBarChartData( UserByPort userByPort){ |
||||
|
Map<String, Integer> depositoryAllNameAndId = depositoryService.findDepositoryAllNameAndId(userByPort); |
||||
|
ExecutorService exs = Executors.newFixedThreadPool(2); |
||||
|
// 结果集
|
||||
|
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
||||
|
// 定义CompletionService
|
||||
|
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
||||
|
Future<Object> submitForIn = completionService.submit(new GetBarChartData(depositoryAllNameAndId, "1")); |
||||
|
Future<Object> submitForOut = completionService.submit(new GetBarChartData(depositoryAllNameAndId, "2")); |
||||
|
futureList.add(submitForOut); |
||||
|
futureList.add(submitForIn); |
||||
|
List<Object> result = new ArrayList<>(); |
||||
|
for (int i = 0; i < 2; i++) { |
||||
|
Object obj = null; |
||||
|
try { |
||||
|
obj = completionService.take().get(); |
||||
|
} catch (InterruptedException | ExecutionException e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
result.add(obj); |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 用于执行柱状图线程 |
||||
|
*/ |
||||
|
class GetBarChartData implements Callable<Object> { |
||||
|
|
||||
|
// 仓库名称与id对应
|
||||
|
Map<String, Integer> depositoryAllNameAndId; |
||||
|
// 要查询的类型
|
||||
|
String type; |
||||
|
|
||||
|
public GetBarChartData(Map<String, Integer> depositoryAllNameAndId, String type) { |
||||
|
this.depositoryAllNameAndId = depositoryAllNameAndId; |
||||
|
this.type = type; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Object call() throws Exception { |
||||
|
Map<Object, Object> lineChartData = getLineChartData(depositoryAllNameAndId, type); |
||||
|
Map<String,Object> result = new HashMap<>(); |
||||
|
if("1".equals(type)){ |
||||
|
// 如果是入库
|
||||
|
result.put("in",lineChartData); |
||||
|
}else if("2".equals(type)){ |
||||
|
// 如果是出库
|
||||
|
result.put("out",lineChartData); |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 获取入库或出库数据 |
||||
|
* @param depositoryAllNameAndId 仓库名称与id对应 |
||||
|
* @param type 类型(1入库2出库) |
||||
|
* @return |
||||
|
*/ |
||||
|
public Map<Object,Object> getLineChartData(Map<String, Integer> depositoryAllNameAndId, String type) { |
||||
|
|
||||
|
// 获取遍历器
|
||||
|
Iterator it = depositoryAllNameAndId.keySet().iterator(); |
||||
|
//获取获取系统的当前日历对象
|
||||
|
Calendar instance = Calendar.getInstance(); |
||||
|
// 获取日期
|
||||
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); |
||||
|
int now = instance.get(Calendar.DAY_OF_WEEK) - 1 == 0 ? 7 : instance.get(Calendar.DAY_OF_WEEK) - 1; |
||||
|
List<Long> days = new ArrayList<>(); // 周一至今的每天
|
||||
|
instance.add(Calendar.DATE, 1); |
||||
|
days.add(DateUtil.DateTimeByDayToTimeStamp(formatter.format(instance.getTime()))); |
||||
|
instance.add(Calendar.DATE, -1); |
||||
|
days.add(DateUtil.DateTimeByDayToTimeStamp(formatter.format(instance.getTime()))); |
||||
|
while (now - 1 > 0) { |
||||
|
now--; |
||||
|
instance.add(Calendar.DATE, -1); |
||||
|
Long format = DateUtil.DateTimeByDayToTimeStamp(formatter.format(instance.getTime())); |
||||
|
days.add(format); |
||||
|
} |
||||
|
// 定义线程
|
||||
|
ExecutorService exs = Executors.newFixedThreadPool(depositoryAllNameAndId.size()); |
||||
|
// 结果集
|
||||
|
List<Future<Object>> futureList = new ArrayList<Future<Object>>(); |
||||
|
// 1.定义CompletionService
|
||||
|
CompletionService<Object> completionService = new ExecutorCompletionService<Object>(exs); |
||||
|
|
||||
|
// 每天各仓库入库数目
|
||||
|
Map<Object,Object> show_data = new HashMap<>(); |
||||
|
while (it.hasNext()) { |
||||
|
Object next = it.next(); |
||||
|
getBarChartDataForApplicationRecord getApplicationRecordByDate = new getBarChartDataForApplicationRecord(type, next.toString(), days, depositoryAllNameAndId); |
||||
|
Future<Object> future = completionService.submit(getApplicationRecordByDate); |
||||
|
futureList.add(future); |
||||
|
} |
||||
|
|
||||
|
for (int i = 0; i < depositoryAllNameAndId.size(); i++) { |
||||
|
Object result = null; |
||||
|
try { |
||||
|
result = completionService.take().get(); |
||||
|
} catch (InterruptedException | ExecutionException e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
show_data.putAll((Map<?, ?>) result); |
||||
|
} |
||||
|
|
||||
|
return show_data; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 根据日期获取出入库的数量(用于柱状图) |
||||
|
*/ |
||||
|
@Data |
||||
|
class getBarChartDataForApplicationRecord implements Callable<Object> { |
||||
|
String key; |
||||
|
List<Long> days; |
||||
|
Map<String, Integer> depositoryAllNameAndId; |
||||
|
|
||||
|
|
||||
|
String type; |
||||
|
|
||||
|
|
||||
|
getBarChartDataForApplicationRecord(String type, String key, List<Long> days, Map<String, Integer> depositoryAllNameAndId) { |
||||
|
this.key = key; |
||||
|
this.depositoryAllNameAndId = depositoryAllNameAndId; |
||||
|
this.days = days; |
||||
|
this.type = type; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Object call() throws Exception { |
||||
|
Map<Integer, Object> result = new HashMap<>(); |
||||
|
Map<String, Object> map = new HashMap<>(); |
||||
|
map.put("type", "bar"); |
||||
|
Map<String, Object> emphasisItem = new HashMap<>(); |
||||
|
emphasisItem.put("focus","series"); |
||||
|
map.put("emphasis", emphasisItem); |
||||
|
Map<String, Object> labelItem = new HashMap<>(); |
||||
|
labelItem.put("show",true); |
||||
|
labelItem.put("position","inside"); |
||||
|
map.put("label", labelItem); |
||||
|
int i; |
||||
|
List<Double> drCountbyDrName = new ArrayList<>(); |
||||
|
|
||||
|
Integer val = depositoryAllNameAndId.get(key); |
||||
|
for (i = days.size() - 1; i > 0; i--) { |
||||
|
// 遍历 Map并计算各仓库的入库数
|
||||
|
// 获取一段时间内的库存额度
|
||||
|
Double depositoryRecordByDate1 = depositoryRecordService.findApplicationRecordByDate(days.get(i - 1), days.get(i), Integer.parseInt(type), val); |
||||
|
if("2".equals(type)){ |
||||
|
depositoryRecordByDate1 = -depositoryRecordByDate1; |
||||
|
} |
||||
|
drCountbyDrName.add(depositoryRecordByDate1); |
||||
|
} |
||||
|
map.put("data", drCountbyDrName); |
||||
|
result.put(val,map); |
||||
|
return result; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,44 @@ |
|||||
|
package com.dreamchaser.depository_manage; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import com.dreamchaser.depository_manage.config.QyWx_approval_template.Approval_template_approver; |
||||
|
import com.dreamchaser.depository_manage.entity.UserByPort; |
||||
|
import com.dreamchaser.depository_manage.pojo.callBackXml.approvalCallBackXml.ApprovalInfo_Details; |
||||
|
import com.dreamchaser.depository_manage.pojo.callBackXml.approvalCallBackXml.ApprovalInfo_Details_Approver; |
||||
|
import com.dreamchaser.depository_manage.service.DepositoryRecordService; |
||||
|
import com.dreamchaser.depository_manage.service.DepositoryService; |
||||
|
import com.dreamchaser.depository_manage.service.MaterialService; |
||||
|
import com.dreamchaser.depository_manage.service.MaterialTypeService; |
||||
|
import com.dreamchaser.depository_manage.utils.DateUtil; |
||||
|
import com.dreamchaser.depository_manage.utils.LinkInterfaceUtil; |
||||
|
import lombok.Data; |
||||
|
import org.junit.Test; |
||||
|
import org.junit.runner.RunWith; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||
|
import org.springframework.test.context.junit4.SpringRunner; |
||||
|
|
||||
|
import java.text.SimpleDateFormat; |
||||
|
import java.util.*; |
||||
|
import java.util.concurrent.*; |
||||
|
|
||||
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
||||
|
@RunWith(SpringRunner.class) |
||||
|
public class OtherTest { |
||||
|
|
||||
|
@Autowired |
||||
|
DepositoryRecordService depositoryRecordService; |
||||
|
|
||||
|
|
||||
|
|
||||
|
@Test |
||||
|
public void main() { |
||||
|
UserByPort userByPort = LinkInterfaceUtil.FindUserById(87, null); |
||||
|
ApprovalInfo_Details approvalInfo = new ApprovalInfo_Details(); |
||||
|
ApprovalInfo_Details_Approver approver = new ApprovalInfo_Details_Approver(); |
||||
|
approver.setUserId("PangFuZhen"); |
||||
|
approvalInfo.setApprover(approver); |
||||
|
depositoryRecordService.reviewByQyWxApprovalIn("[8]",approvalInfo,"42156e781cdc727e7d5deac872be45a9","2","202304240010"); |
||||
|
} |
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue