|
@@ -25,6 +25,10 @@ import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.MathContext;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -394,8 +398,11 @@ public class OrderServiceImpl implements IOrderService {
|
|
|
dataSource.setPassword(detail.getEnterpriseDatabasePassword());
|
|
|
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
|
|
try {
|
|
|
- List<Device> deviceList = jdbcTemplate.query("SELECT ie.* ,it.tsl_name as tslName, '" + detail.getEnterpriseDatabaseUrl() + "' as url" + " FROM iot_equipment ie " +
|
|
|
- "LEFT JOIN iot_tsl it ON ie.tsl_id = it.id ;",
|
|
|
+ List<Device> deviceList = jdbcTemplate.query("SELECT ie.* ,it.tsl_name as tslName," +
|
|
|
+ "ird.update_time as deviceTime, ird.val as deviceStatus, '" + detail.getEnterpriseDatabaseUrl() + "' as url"
|
|
|
+ + " FROM iot_equipment ie " +
|
|
|
+ "LEFT JOIN iot_tsl it ON ie.tsl_id = it.id " +
|
|
|
+ "LEFT JOIN iot_real_data ird ON ie.equipment_code = ird.device_code ;",
|
|
|
new BeanPropertyRowMapper<Device>(Device.class));
|
|
|
detail.setDeviceList(deviceList);
|
|
|
} catch (Exception e) {
|
|
@@ -420,6 +427,225 @@ public class OrderServiceImpl implements IOrderService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public List<ProductionScheduleDto> productionScheduleList(Order order) {
|
|
|
+ List<ProductionScheduleDto> orderList = new ArrayList<>();
|
|
|
+ String condition = "";
|
|
|
+
|
|
|
+ if (!ObjectUtils.isEmpty(order.getStartTime())) {
|
|
|
+ condition += "and fo.start_time >= '" + order.getStartTime() + "'";
|
|
|
+ }
|
|
|
+ if (!ObjectUtils.isEmpty(order.getEndTime())) {
|
|
|
+ condition += "and fo.end_time <= '" + order.getEndTime() + "'";
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Map<String, JdbcTemplate> jdbcTemplateMap = databaseConnectionMap.getJdbcTemplate();
|
|
|
+ Set<String> key = jdbcTemplateMap.keySet();
|
|
|
+
|
|
|
+ for (String keyUrl : key) {
|
|
|
+ JdbcTemplate template = jdbcTemplateMap.get(keyUrl);
|
|
|
+ List<ProductionScheduleDto> orders = template.query("SELECT fo.order_num as orderNum,fo.delivery_time as deliveryTime,"
|
|
|
+ + "fo.order_name as orderName,fo.customer_name as customerName,pg.group_name as groupName," +
|
|
|
+ "IF(tpo.production_num,tpo.production_num,0) as productionNum," +
|
|
|
+ "IF(tpo.order_finish_num,tpo.order_finish_num,0) as orderFinishNum," +
|
|
|
+ "tpo.delivery_cycle as deliveryCycle," +
|
|
|
+ "IF(IF(tpo.production_num,tpo.production_num,0)/IF(tpo.order_finish_num,tpo.order_finish_num,0)," +
|
|
|
+ "IF(tpo.production_num,tpo.production_num,0)/IF(tpo.order_finish_num,tpo.order_finish_num,0)," +
|
|
|
+ "0) as productionSchedule" +
|
|
|
+ " FROM t_factory_order fo LEFT JOIN t_product_order tpo ON fo.id = tpo.task_id " +
|
|
|
+ "LEFT JOIN t_process_group pg ON tpo.process_group_id = pg.id " +
|
|
|
+ "where 1=1 " + (ObjectUtils.isEmpty(condition) ? "" : condition) + ";",
|
|
|
+ new BeanPropertyRowMapper<ProductionScheduleDto>(ProductionScheduleDto.class));
|
|
|
+ orderList.addAll(orders);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e.getMessage());
|
|
|
+ }
|
|
|
+ return orderList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ProductionScheduleDto> orderStatus(Order order) {
|
|
|
+ List<ProductionScheduleDto> orderList = new ArrayList<>();
|
|
|
+ String condition = "";
|
|
|
+
|
|
|
+ if (!ObjectUtils.isEmpty(order.getStartTime())) {
|
|
|
+ condition += "and fo.start_time >= '" + order.getStartTime() + "'";
|
|
|
+ }
|
|
|
+ if (!ObjectUtils.isEmpty(order.getEndTime())) {
|
|
|
+ condition += "and fo.end_time <= '" + order.getEndTime() + "'";
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Map<String, JdbcTemplate> jdbcTemplateMap = databaseConnectionMap.getJdbcTemplate();
|
|
|
+ Set<String> key = jdbcTemplateMap.keySet();
|
|
|
+
|
|
|
+ for (String keyUrl : key) {
|
|
|
+ JdbcTemplate template = jdbcTemplateMap.get(keyUrl);
|
|
|
+ List<ProductionScheduleDto> orders = template.query("SELECT fo.order_num as orderNum,fo.delivery_time as deliveryTime,"
|
|
|
+ + "fo.order_name as orderName,fo.customer_name as customerName,pg.group_name as groupName," +
|
|
|
+ "tto.shipping_status as shippingStatus," +
|
|
|
+ "IF(tto.number,tto.number,0) as number," +
|
|
|
+ "IF(tto.delivery_num,tto.delivery_num,0) as deliveryNum" +
|
|
|
+ " FROM t_factory_order fo LEFT JOIN t_product_order tpo ON fo.id = tpo.task_id " +
|
|
|
+ " LEFT JOIN t_transport_order tto ON fo.order_num = tto.order_num " +
|
|
|
+ "LEFT JOIN t_process_group pg ON tpo.process_group_id = pg.id " +
|
|
|
+ "where 1=1 " + (ObjectUtils.isEmpty(condition) ? "" : condition) + ";",
|
|
|
+ new BeanPropertyRowMapper<ProductionScheduleDto>(ProductionScheduleDto.class));
|
|
|
+ orderList.addAll(orders);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e.getMessage());
|
|
|
+ }
|
|
|
+ return orderList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TableDataInfo reportList(String status, String enterpriseName, String startTime, String endTime) {
|
|
|
+ PageDomain pageDomain = TableSupport.buildPageRequest();
|
|
|
+ Integer pageNum = pageDomain.getPageNum();
|
|
|
+ Integer pageSize = pageDomain.getPageSize();
|
|
|
+ String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
|
|
|
+ Boolean reasonable = pageDomain.getReasonable();
|
|
|
+ PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(reasonable);
|
|
|
+ List<capacityReportDto> orderList = new ArrayList<>();
|
|
|
+ String condition = "";
|
|
|
+ if (!ObjectUtils.isEmpty(enterpriseName)) {
|
|
|
+ condition += "and tfo.customer_name = '" + enterpriseName + "'";
|
|
|
+ }
|
|
|
+ if (!ObjectUtils.isEmpty(status)) {
|
|
|
+ condition += "and fo.start_time = '" + status + "'";
|
|
|
+ }
|
|
|
+ if (!ObjectUtils.isEmpty(startTime)) {
|
|
|
+ condition += "and tpo.complete_time >= '" + startTime + "'";
|
|
|
+ }
|
|
|
+ if (!ObjectUtils.isEmpty(endTime)) {
|
|
|
+ condition += "and tpo.complete_time <= '" + endTime + "'";
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Map<String, JdbcTemplate> jdbcTemplateMap = databaseConnectionMap.getJdbcTemplate();
|
|
|
+ Set<String> key = jdbcTemplateMap.keySet();
|
|
|
+
|
|
|
+ for (String keyUrl : key) {
|
|
|
+ JdbcTemplate template = jdbcTemplateMap.get(keyUrl);
|
|
|
+ List<capacityReportDto> orders = template.query("SELECT tfo.order_num AS orderNumD,tfo.customer_name AS customerName,"
|
|
|
+ + "tfo.order_name AS orderName,tpo.order_num AS orderNumG,tpo.production_num AS reportingNum, " +
|
|
|
+ "(SELECT count(report_num) FROM t_work_report where order_id = tpo.id and process_id =" +
|
|
|
+ "(SELECT process_id FROM t_process_group_detail where group_id = tpo.process_group_id ORDER BY sort_num desc LIMIT 1)" +
|
|
|
+ "and defect_cause is null)as qualifiedNum," +
|
|
|
+ "(SELECT count(waste_num) FROM t_work_report where order_id = tpo.id and process_id =" +
|
|
|
+ "(SELECT process_id FROM t_process_group_detail where group_id = tpo.process_group_id ORDER BY sort_num desc LIMIT 1)" +
|
|
|
+ "and defect_cause is not null) as unqualifiedNum," +
|
|
|
+ "(SELECT count(product_num) FROM t_work_report where order_id = tpo.id and process_id =" +
|
|
|
+ "(SELECT process_id FROM t_process_group_detail where group_id = tpo.process_group_id ORDER BY sort_num desc LIMIT 1))" +
|
|
|
+ "as dailyProduction," +
|
|
|
+ "(SELECT report_time FROM t_work_report where order_id = tpo.id and process_id =" +
|
|
|
+ "(SELECT process_id FROM t_process_group_detail where group_id = tpo.process_group_id ORDER BY sort_num desc LIMIT 1)" +
|
|
|
+ "ORDER BY report_time LIMIT 1) as reportTime" +
|
|
|
+ " FROM t_product_order tpo " +
|
|
|
+ " LEFT JOIN t_factory_order tfo ON tpo.task_id = tfo.id " +
|
|
|
+ "where 1=1 " + (ObjectUtils.isEmpty(condition) ? "" : condition) + ";",
|
|
|
+ new BeanPropertyRowMapper<capacityReportDto>(capacityReportDto.class));
|
|
|
+ for (capacityReportDto item : orders) {
|
|
|
+ if ("0".equals(item.getQualifiedNum()) || "0".equals(item.getUnqualifiedNum())) {
|
|
|
+ item.setPassRate("0");
|
|
|
+ } else {
|
|
|
+ BigDecimal sum = new BigDecimal(item.getQualifiedNum()).add(new BigDecimal(item.getUnqualifiedNum()));
|
|
|
+ item.setPassRate(new BigDecimal(item.getQualifiedNum()).divide(sum, MathContext.DECIMAL32).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ orderList.addAll(orders);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e.getMessage());
|
|
|
+ }
|
|
|
+ TableDataInfo tableDataInfo = new TableDataInfo();
|
|
|
+ tableDataInfo.setCode(HttpStatus.SUCCESS);
|
|
|
+ tableDataInfo.setMsg("查询成功");
|
|
|
+ tableDataInfo.setRows(orderList.stream().skip(pageNum).limit(pageSize).collect(Collectors.toList()));
|
|
|
+ tableDataInfo.setTotal(orderList.size());
|
|
|
+ return tableDataInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult reportHistogram(String status, String enterpriseName, String startTime, String endTime) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ List<String> yearList = new ArrayList<>();
|
|
|
+ List<String> reportingNumList = new ArrayList<>();
|
|
|
+ List<String> qualifiedNumList = new ArrayList<>();
|
|
|
+ List<String> unqualifiedNumList = new ArrayList<>();
|
|
|
+ List<String> passRateList = new ArrayList<>();
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ try {
|
|
|
+ Map<String, JdbcTemplate> jdbcTemplateMap = databaseConnectionMap.getJdbcTemplate();
|
|
|
+ Set<String> key = jdbcTemplateMap.keySet();
|
|
|
+
|
|
|
+ for (String keyUrl : key) {
|
|
|
+ if (ObjectUtils.isEmpty(startTime) || ObjectUtils.isEmpty(endTime)) {
|
|
|
+ endTime = LocalDate.now().toString();
|
|
|
+ startTime = LocalDate.parse(endTime).minusDays(7).toString();
|
|
|
+ }
|
|
|
+ LocalDate start = LocalDate.parse(startTime);
|
|
|
+ LocalDate end = LocalDate.parse(endTime);
|
|
|
+ // 判断是否到达结束日期
|
|
|
+ while (!start.isAfter(end)) {
|
|
|
+ String condition = "";
|
|
|
+ if (!ObjectUtils.isEmpty(enterpriseName)) {
|
|
|
+ condition += "and tfo.customer_name = '" + enterpriseName + "'";
|
|
|
+ }
|
|
|
+ if (!ObjectUtils.isEmpty(status)) {
|
|
|
+ condition += "and fo.start_time = '" + status + "'";
|
|
|
+ }
|
|
|
+ condition += "and DATE_FORMAT(tpo.complete_time, '%Y-%m-%d') >= '" + start.format(formatter) + "'";
|
|
|
+ condition += "and DATE_FORMAT(tpo.complete_time, '%Y-%m-%d') <= '" + start.format(formatter) + "'";
|
|
|
+ JdbcTemplate template = jdbcTemplateMap.get(keyUrl);
|
|
|
+ List<capacityReportDto> orders = template.query("SELECT tfo.order_num AS orderNumD,tfo.customer_name AS customerName,"
|
|
|
+ + "tfo.order_name AS orderName,tpo.order_num AS orderNumG,tpo.production_num AS reportingNum, " +
|
|
|
+ "(SELECT count(report_num) FROM t_work_report where order_id = tpo.id and process_id =" +
|
|
|
+ "(SELECT process_id FROM t_process_group_detail where group_id = tpo.process_group_id ORDER BY sort_num desc LIMIT 1)" +
|
|
|
+ "and defect_cause is null)as qualifiedNum," +
|
|
|
+ "(SELECT count(waste_num) FROM t_work_report where order_id = tpo.id and process_id =" +
|
|
|
+ "(SELECT process_id FROM t_process_group_detail where group_id = tpo.process_group_id ORDER BY sort_num desc LIMIT 1)" +
|
|
|
+ "and defect_cause is not null) as unqualifiedNum," +
|
|
|
+ "(SELECT count(product_num) FROM t_work_report where order_id = tpo.id and process_id =" +
|
|
|
+ "(SELECT process_id FROM t_process_group_detail where group_id = tpo.process_group_id ORDER BY sort_num desc LIMIT 1))" +
|
|
|
+ "as dailyProduction," +
|
|
|
+ "(SELECT report_time FROM t_work_report where order_id = tpo.id and process_id =" +
|
|
|
+ "(SELECT process_id FROM t_process_group_detail where group_id = tpo.process_group_id ORDER BY sort_num desc LIMIT 1)" +
|
|
|
+ "ORDER BY report_time LIMIT 1) as reportTime" +
|
|
|
+ " FROM t_product_order tpo " +
|
|
|
+ " LEFT JOIN t_factory_order tfo ON tpo.task_id = tfo.id " +
|
|
|
+ "where 1=1 " + (ObjectUtils.isEmpty(condition) ? "" : condition) + ";",
|
|
|
+ new BeanPropertyRowMapper<capacityReportDto>(capacityReportDto.class));
|
|
|
+ for (capacityReportDto item : orders) {
|
|
|
+ if (!ObjectUtils.isEmpty(item.getQualifiedNum()) && !ObjectUtils.isEmpty(item.getUnqualifiedNum())
|
|
|
+ && !ObjectUtils.isEmpty(item.getReportingNum())) {
|
|
|
+ if ("0".equals(item.getQualifiedNum()) || "0".equals(item.getUnqualifiedNum())) {
|
|
|
+ passRateList.add("0");
|
|
|
+ } else {
|
|
|
+ BigDecimal sum = new BigDecimal(item.getQualifiedNum()).add(new BigDecimal(item.getUnqualifiedNum()));
|
|
|
+ passRateList.add(new BigDecimal(item.getQualifiedNum()).divide(sum, MathContext.DECIMAL32).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
|
|
|
+ }
|
|
|
+ yearList.add(start.format(formatter));
|
|
|
+ reportingNumList.add(item.getReportingNum());
|
|
|
+ qualifiedNumList.add(item.getQualifiedNum());
|
|
|
+ unqualifiedNumList.add(item.getUnqualifiedNum());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 日期加一天
|
|
|
+ start = start.plusDays(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e.getMessage());
|
|
|
+ }
|
|
|
+ map.put("passRateList", passRateList);
|
|
|
+ map.put("yearList", yearList);
|
|
|
+ map.put("reportingNumList", reportingNumList);
|
|
|
+ map.put("qualifiedNumList", qualifiedNumList);
|
|
|
+ map.put("unqualifiedNumList", unqualifiedNumList);
|
|
|
+ return AjaxResult.success(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public AjaxResult deviceDetails(Device device) {
|
|
|
List<IotRealData> iotRealDataList = new ArrayList<>();
|
|
|
try {
|