diff --git a/nladmin-system/src/main/java/org/nl/acs/order/rest/OrderDetailController.java b/nladmin-system/src/main/java/org/nl/acs/order/rest/OrderDetailController.java new file mode 100644 index 0000000..af55cca --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/order/rest/OrderDetailController.java @@ -0,0 +1,87 @@ +package org.nl.acs.order.rest; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.order.service.OrderDetailService; +import org.nl.acs.order.service.dto.OrderDetailDto; +import org.nl.annotation.Log; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.text.ParseException; +import java.util.Map; + +/** + * @author tuq + * @date 2023-10-24 + **/ +@RestController +@RequiredArgsConstructor +@Api(tags = "订单详细") +@RequestMapping("/api/orderdetail") +@Slf4j +public class OrderDetailController { + private final OrderDetailService orderDetailService; + + @GetMapping + @Log("查询订单") + @ApiOperation("查询订单") + //@PreAuthorize("@el.check('orderDetail:list')") + public ResponseEntity query(@RequestParam Map whereJson, Pageable page){ + return new ResponseEntity<>(orderDetailService.queryAll(whereJson,page), HttpStatus.OK); + } + + @PostMapping + @Log("新增order") + @ApiOperation("新增order") + //@PreAuthorize("@el.check('orderDetail:add')") + public ResponseEntity create(@Validated @RequestBody OrderDetailDto dto){ + orderDetailService.create(dto); + return new ResponseEntity<>(HttpStatus.CREATED); + } + + @PutMapping + @Log("修改order") + @ApiOperation("修改order") + //@PreAuthorize("@el.check('orderDetail:edit')") + public ResponseEntity update(@Validated @RequestBody OrderDetailDto dto){ + orderDetailService.update(dto); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Log("删除order") + @ApiOperation("删除order") + //@PreAuthorize("@el.check('orderDetail:del')") + @DeleteMapping + public ResponseEntity delete(@RequestBody String[] ids) { + orderDetailService.deleteAll(ids); + return new ResponseEntity<>(HttpStatus.OK); + } + + @Log("导出order") + @ApiOperation("导出order") + @GetMapping(value = "/download") + //@PreAuthorize("@el.check('orderDetail:list')") + public void download(HttpServletResponse response, @RequestParam Map whereJson) throws IOException { + orderDetailService.download(orderDetailService.queryAll(whereJson), response); + } + + @PostMapping("/excelImport") + @Log("excel导入") + @ApiOperation("excel导入") + public ResponseEntity excelImport(@RequestParam("file") MultipartFile file, HttpServletRequest request) throws IOException, ParseException { + orderDetailService.excelImport(file, request); + return new ResponseEntity<>(HttpStatus.OK); + } + + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/order/service/OrderDetailService.java b/nladmin-system/src/main/java/org/nl/acs/order/service/OrderDetailService.java new file mode 100644 index 0000000..e269534 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/order/service/OrderDetailService.java @@ -0,0 +1,85 @@ +package org.nl.acs.order.service; + +import org.nl.acs.order.service.dto.OrderDetailDto; +import org.springframework.data.domain.Pageable; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.text.ParseException; +import java.util.List; +import java.util.Map; + +/** + * @description 服务接口 + * @author tuq + * @date 2023-10-24 + **/ +public interface OrderDetailService { + /** + * 查询数据分页 + * @param whereJson 条件 + * @param page 分页参数 + * @return Map + */ + Map queryAll(Map whereJson, Pageable page); + + /** + * 查询所有数据不分页 + * @param whereJson 条件参数 + * @return List + */ + List queryAll(Map whereJson); + + List queryAll(); + + /** + * 根据ID查询 + * @param order_id ID + * @return OrderDetail + */ + OrderDetailDto findById(String order_id); + + /** + * 根据编码查询 + * @param code code + * @return OrderDetail + */ + OrderDetailDto findByCode(String code); + + + /** + * 创建 + * @param dto / + */ + void create(OrderDetailDto dto); + + /** + * 编辑 + * @param dto / + */ + void update(OrderDetailDto dto); + + /** + * 多选删除 + * @param ids / + */ + void deleteAll(String[] ids); + + /** + * 导出数据 + * @param dtos 待导出的数据 + * @param response / + * @throws IOException / + */ + void download(List dtos, HttpServletResponse response) throws IOException; + + + /** + * excel导入 + * @param file + * @param request + */ + void excelImport(MultipartFile file, HttpServletRequest request) throws ParseException, IOException; +} diff --git a/nladmin-system/src/main/java/org/nl/acs/order/service/dto/OrderDetailDto.java b/nladmin-system/src/main/java/org/nl/acs/order/service/dto/OrderDetailDto.java new file mode 100644 index 0000000..be81081 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/order/service/dto/OrderDetailDto.java @@ -0,0 +1,48 @@ +package org.nl.acs.order.service.dto; + +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; + +/** + * @description / + * @author tuq + * @date 2023-10-24 + **/ +@Data +public class OrderDetailDto implements Serializable { + + /** 订单标识 */ + private String order_id; + + /** 订单号 */ + private String order_no; + + /** 管长 */ + private BigDecimal tube_len; + + /** 管径 */ + private BigDecimal tube_width; + + /** 起始时间 */ + private String start_time; + + /** 结束时间 */ + private String end_time; + + /** 间隔时间*/ + private String interval_time; + + /** 平均时间 */ + private String avg_time; + + /** 修改者 */ + private String update_by; + + /** 修改时间 */ + private String update_time; + + /** 数量 */ + private String qty; +} diff --git a/nladmin-system/src/main/java/org/nl/acs/order/service/impl/OrderDetailServiceImpl.java b/nladmin-system/src/main/java/org/nl/acs/order/service/impl/OrderDetailServiceImpl.java new file mode 100644 index 0000000..847fab1 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/order/service/impl/OrderDetailServiceImpl.java @@ -0,0 +1,268 @@ +package org.nl.acs.order.service.impl; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.text.csv.*; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.poi.excel.ExcelReader; +import cn.hutool.poi.excel.ExcelUtil; +import cn.hutool.poi.excel.WorkbookUtil; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.order.service.OrderDetailService; +import org.nl.acs.order.service.dto.OrderDetailDto; +import org.nl.exception.BadRequestException; +import org.nl.utils.FileUtil; +import org.nl.utils.SecurityUtils; +import org.nl.wql.core.bean.ResultBean; +import org.nl.wql.core.bean.WQLObject; +import org.nl.wql.util.WqlUtil; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.Charset; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; + +/** + * @author tuq + * @description 服务实现 + * @date 2023-10-24 + **/ +@Service +@RequiredArgsConstructor +@Slf4j +public class OrderDetailServiceImpl implements OrderDetailService { + + @Override + public Map queryAll(Map whereJson, Pageable page) { + WQLObject wo = WQLObject.getWQLObject("order_detail"); + ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "", "update_time desc"); + final JSONObject json = rb.pageResult(); + return json; + } + + @Override + public List queryAll(Map whereJson) { + WQLObject wo = WQLObject.getWQLObject("order_detail"); + JSONArray arr = wo.query().getResultJSONArray(0); + List list = arr.toJavaList(OrderDetailDto.class); + return list; + } + + @Override + public List queryAll() { + WQLObject wo = WQLObject.getWQLObject("order_detail"); + JSONArray arr = wo.query().getResultJSONArray(0); + List list = arr.toJavaList(OrderDetailDto.class); + return list; + } + + @Override + public OrderDetailDto findById(String order_id) { + WQLObject wo = WQLObject.getWQLObject("order_detail"); + JSONObject json = wo.query("order_id ='" + order_id + "'").uniqueResult(0); + final OrderDetailDto obj = (OrderDetailDto) JSONObject.toJavaObject(json, OrderDetailDto.class); + return obj; + } + + @Override + public OrderDetailDto findByCode(String code) { + WQLObject wo = WQLObject.getWQLObject("order_detail"); + JSONObject json = wo.query("code ='" + code + "'").uniqueResult(0); + final OrderDetailDto obj = (OrderDetailDto) JSONObject.toJavaObject(json, OrderDetailDto.class); + return obj; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void create(OrderDetailDto dto) { + String currentUsername = SecurityUtils.getCurrentUsername(); + dto.setOrder_id(IdUtil.simpleUUID()); + dto.setUpdate_time(DateUtil.now()); + dto.setUpdate_by(currentUsername); + + WQLObject wo = WQLObject.getWQLObject("order_detail"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + wo.insert(json); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(OrderDetailDto dto) { + OrderDetailDto entity = this.findById(dto.getOrder_id()); + if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!"); + + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + dto.setUpdate_time(now); + dto.setUpdate_by(currentUsername); + + WQLObject wo = WQLObject.getWQLObject("order_detail"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + wo.update(json); + } + + @Override + public void deleteAll(String[] ids) { + WQLObject wo = WQLObject.getWQLObject("order_detail"); + for (String order_id : ids) { + wo.delete("order_id = '" + order_id + "'"); + } + } + + @Override + public void download(List dtos, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (OrderDetailDto orderDetailDto : dtos) { + Map map = new LinkedHashMap<>(); + map.put("订单号", orderDetailDto.getOrder_no()); + map.put("管长", orderDetailDto.getTube_len()); + map.put("管径", orderDetailDto.getTube_width()); + map.put("起始时间", orderDetailDto.getStart_time()); + map.put("结束时间", orderDetailDto.getEnd_time()); + map.put("间隔时间", orderDetailDto.getInterval_time()); + map.put("平均时间", orderDetailDto.getAvg_time()); + map.put("修改者", orderDetailDto.getUpdate_by()); + map.put("修改时间", orderDetailDto.getUpdate_time()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void excelImport(MultipartFile file, HttpServletRequest request) throws ParseException, IOException { + if (file.isEmpty()) { + throw new BadRequestException("文件为空,请添加数据后重新导入"); + } + Long currentUserId = SecurityUtils.getCurrentUserId(); + String nickName = SecurityUtils.getCurrentUser().getUsername(); + String now = DateUtil.now(); + // 1.获取上传文件输入流 + InputStream inputStream = null; + try { + inputStream = file.getInputStream(); + } catch (Exception e) { + e.printStackTrace(); + } + WQLObject wo = WQLObject.getWQLObject("order_detail"); + + // 调用用 hutool 方法读取数据 默认调用第一个sheet + ExcelReader excelReader = ExcelUtil.getReader(inputStream); + // 从第二行开始获取数据 excelReader.read的结果是一个2纬的list,外层是行,内层是行对应的所有列 + List> read = excelReader.read(1, excelReader.getPhysicalRowCount()); + List readline = new ArrayList<>(); + // 循环获取每一行的数据 + for (int i = 0; i < read.size(); i++) { + readline.add(read.get(i)); + } + ArrayList list = new ArrayList<>(); + // 循环获取每一行的订单号数据 + for (int j = 0; j < readline.size(); j++) { + Object o = read.get(j).get(2); + list.add(o); + } + + for (int i = 0; i < read.size(); i++) { + List list1 = read.get(i); + JSONObject param = new JSONObject(); + int i1 = list.indexOf(list1.get(2));//订单号第一次出现的位置 + int i2 = list.lastIndexOf(list1.get(2));//订单号最后一次出现的位置 + if (read.get(i2).equals(list1)) { + //得到相同订单的第一条数据 + List list2 = getFirstOrder(i1, read); + //得到相同订单的最后一条数据 + List list3 = getLastOrder(i2, read); + + + //相同订单的第一条数据的时间 + String time1 = list2.get(0).toString(); + String substring1 = time1.substring(11); + String date1 = list2.get(1).toString(); + String[] split1 = date1.split("/"); + String year = split1[2]; + String month = split1[0]; + String day = split1[1]; + String start_time = year + "-" + month + "-" + day + " " + substring1; + + //相同订单的最后一条数据的时间 + String time2 = list3.get(0).toString(); + String substring2 = time2.substring(11); + String date2 = list3.get(1).toString(); + String[] split2 = date2.split("/"); + String year1 = split2[2]; + String month1 = split2[0]; + String day1 = split2[1]; + String end_time = year1 + "-" + month1 + "-" + day1 + " " + substring2; + + String order_no = list2.get(2).toString();//订单号 + String tube_len = list2.get(3).toString();//管长 + String tube_width = list2.get(4).toString();//管径 + + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + Date d1 = format.parse(start_time); + Date d2 = format.parse(end_time); + long l = (d2.getTime() - d1.getTime())/ 1000; //秒 + String interval_time = Long.toString(l);//间隔时间 + + long l1 = l / (i2 - i1 + 1);//平均时间 + String avg_time = Long.toString(l1); + + String qty = Integer.toString(i2 - i1 + 1);//数量 + + //按照列获取 + param.put("order_id", IdUtil.getSnowflake(1, 1).nextId()); + param.put("order_no", order_no); + param.put("tube_len", tube_len); + param.put("tube_width", tube_width); + param.put("start_time", start_time); + param.put("end_time", end_time); + param.put("interval_time", interval_time); + param.put("avg_time", avg_time); + param.put("update_by", nickName); + param.put("update_time", now); + param.put("qty", qty); + + wo.insert(param); + } + continue; + } + } + + private List getLastOrder(int i2, List> read) { + List list = new ArrayList(); + for (int i = 0; i < read.size(); i++) { + if (!read.get(i2).equals(read.get(i))) { + continue; + }else { + list = read.get(i); + } + } + return list; + } + + private List getFirstOrder(int i1, List> read) { + List list = new ArrayList(); + for (int i = 0; i < read.size(); i++) { + if (!read.get(i1).equals(read.get(i))) { + continue; + }else { + list = read.get(i); + } + } + return list; + } +} + diff --git a/nladmin-system/src/main/java/org/nl/acs/order/service/wql/order.xls b/nladmin-system/src/main/java/org/nl/acs/order/service/wql/order.xls index 895b4a3..f7d746f 100644 Binary files a/nladmin-system/src/main/java/org/nl/acs/order/service/wql/order.xls and b/nladmin-system/src/main/java/org/nl/acs/order/service/wql/order.xls differ diff --git a/qd/src/api/acs/order/orderDetail.js b/qd/src/api/acs/order/orderDetail.js new file mode 100644 index 0000000..336d33e --- /dev/null +++ b/qd/src/api/acs/order/orderDetail.js @@ -0,0 +1,43 @@ +import request from '@/utils/request' + +export function add(data) { + return request({ + url: 'api/orderdetail', + method: 'post', + data + }) +} + +export function del(ids) { + return request({ + url: 'api/orderdetail/', + method: 'delete', + data: ids + }) +} + +export function edit(data) { + return request({ + url: 'api/orderdetail', + method: 'put', + data + }) +} + +export function queryOrderdetail(data) { + return request({ + url: 'api/orderdetail', + method: 'get', + data + }) +} + +export function excelImport(data) { + return request({ + url: 'api/orderdetail/excelImport', + method: 'post', + data + }) +} + +export default { add, edit, del, queryOrderdetail, excelImport } diff --git a/qd/src/views/acs/order/OrderDetailDialog.vue b/qd/src/views/acs/order/OrderDetailDialog.vue new file mode 100644 index 0000000..3c9c4d7 --- /dev/null +++ b/qd/src/views/acs/order/OrderDetailDialog.vue @@ -0,0 +1,182 @@ + + + + + diff --git a/qd/src/views/acs/order/UploadDialog.vue b/qd/src/views/acs/order/UploadDialog.vue new file mode 100644 index 0000000..5023a19 --- /dev/null +++ b/qd/src/views/acs/order/UploadDialog.vue @@ -0,0 +1,117 @@ + + + + diff --git a/qd/src/views/acs/order/orderDetail/index.vue b/qd/src/views/acs/order/orderDetail/index.vue new file mode 100644 index 0000000..70b0f9e --- /dev/null +++ b/qd/src/views/acs/order/orderDetail/index.vue @@ -0,0 +1,137 @@ + + + + +