- 将日期设置为当天的开始时间 00:00:00 - 使用Calendar类精确设置小时、分钟、秒和毫秒为零值 - 确保计划日期查询使用正确的日期范围 - 避免因时间戳差异导致的数据查询不准确问题
161 lines
5.5 KiB
Java
161 lines
5.5 KiB
Java
package com.klp.crm.controller;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Arrays;
|
|
import java.util.Date;
|
|
|
|
import com.klp.aps.domain.bo.ApsPlanDetailBo;
|
|
import com.klp.aps.domain.bo.ApsPlanSheetBo;
|
|
import lombok.RequiredArgsConstructor;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.validation.constraints.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.format.annotation.DateTimeFormat;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import com.klp.common.annotation.RepeatSubmit;
|
|
import com.klp.common.annotation.Log;
|
|
import com.klp.common.core.controller.BaseController;
|
|
import com.klp.common.core.domain.PageQuery;
|
|
import com.klp.common.core.domain.R;
|
|
import com.klp.common.core.validate.AddGroup;
|
|
import com.klp.common.core.validate.EditGroup;
|
|
import com.klp.common.enums.BusinessType;
|
|
import com.klp.common.utils.poi.ExcelUtil;
|
|
import com.klp.crm.domain.vo.CrmOrderVo;
|
|
import com.klp.crm.domain.bo.CrmOrderBo;
|
|
import com.klp.crm.service.ICrmOrderService;
|
|
import com.klp.common.core.page.TableDataInfo;
|
|
import com.klp.aps.domain.vo.ApsPlanSheetVo;
|
|
import com.klp.aps.domain.vo.ApsPlanDetailVo;
|
|
import com.klp.aps.service.IApsPlanSheetService;
|
|
import com.klp.aps.service.IApsPlanDetailService;
|
|
|
|
/**
|
|
* 正式订单主
|
|
*
|
|
* @author klp
|
|
* @date 2025-12-15
|
|
*/
|
|
@Validated
|
|
@RequiredArgsConstructor
|
|
@RestController
|
|
@RequestMapping("/crm/order")
|
|
public class CrmOrderController extends BaseController {
|
|
|
|
private final ICrmOrderService iCrmOrderService;
|
|
private final IApsPlanSheetService iApsPlanSheetService;
|
|
private final IApsPlanDetailService iApsPlanDetailService;
|
|
|
|
/**
|
|
* 查询正式订单主列表
|
|
*/
|
|
@GetMapping("/list")
|
|
public TableDataInfo<CrmOrderVo> list(CrmOrderBo bo, PageQuery pageQuery) {
|
|
return iCrmOrderService.queryPageList(bo, pageQuery);
|
|
}
|
|
|
|
/**
|
|
* 导出正式订单主列表
|
|
*/
|
|
@Log(title = "正式订单主", businessType = BusinessType.EXPORT)
|
|
@PostMapping("/export")
|
|
public void export(CrmOrderBo bo, HttpServletResponse response) {
|
|
List<CrmOrderVo> list = iCrmOrderService.queryList(bo);
|
|
ExcelUtil.exportExcel(list, "正式订单主", CrmOrderVo.class, response);
|
|
}
|
|
|
|
/**
|
|
* 获取正式订单主详细信息
|
|
*
|
|
* @param orderId 主键
|
|
*/
|
|
@GetMapping("/{orderId}")
|
|
public R<CrmOrderVo> getInfo(@NotNull(message = "主键不能为空")
|
|
@PathVariable String orderId) {
|
|
return R.ok(iCrmOrderService.queryById(orderId));
|
|
}
|
|
|
|
/**
|
|
* 新增正式订单主
|
|
*/
|
|
@Log(title = "正式订单主", businessType = BusinessType.INSERT)
|
|
@RepeatSubmit()
|
|
@PostMapping()
|
|
public R<CrmOrderVo> add(@Validated(AddGroup.class) @RequestBody CrmOrderBo bo) {
|
|
return R.ok(iCrmOrderService.insertByBo(bo));
|
|
}
|
|
|
|
/**
|
|
* 修改正式订单主
|
|
*/
|
|
@Log(title = "正式订单主", businessType = BusinessType.UPDATE)
|
|
@RepeatSubmit()
|
|
@PutMapping()
|
|
public R<Void> edit(@Validated(EditGroup.class) @RequestBody CrmOrderBo bo) {
|
|
return toAjax(iCrmOrderService.updateByBo(bo));
|
|
}
|
|
|
|
/**
|
|
* 删除正式订单主
|
|
*
|
|
* @param orderIds 主键串
|
|
*/
|
|
@Log(title = "正式订单主", businessType = BusinessType.DELETE)
|
|
@DeleteMapping("/{orderIds}")
|
|
public R<Void> remove(@NotEmpty(message = "主键不能为空")
|
|
@PathVariable String[] orderIds) {
|
|
return toAjax(iCrmOrderService.deleteWithValidByIds(Arrays.asList(orderIds), true));
|
|
}
|
|
|
|
/**
|
|
* 查询每日订单(根据排产计划获取今天的订单)
|
|
*
|
|
* @param planDate 排产日期,默认今天
|
|
*/
|
|
@GetMapping("/daily")
|
|
public R<List<CrmOrderVo>> getDailyOrders(
|
|
@RequestParam(value = "planDate", required = false)
|
|
@DateTimeFormat(pattern = "yyyy-MM-dd") Date planDate) {
|
|
if (planDate == null) {
|
|
planDate = new Date();
|
|
}
|
|
// 将日期设置为当天的开始时间 00:00:00
|
|
java.util.Calendar calendar = java.util.Calendar.getInstance();
|
|
calendar.setTime(planDate);
|
|
calendar.set(java.util.Calendar.HOUR_OF_DAY, 0);
|
|
calendar.set(java.util.Calendar.MINUTE, 0);
|
|
calendar.set(java.util.Calendar.SECOND, 0);
|
|
calendar.set(java.util.Calendar.MILLISECOND, 0);
|
|
planDate = calendar.getTime();
|
|
|
|
ApsPlanSheetBo bo = new ApsPlanSheetBo();
|
|
bo.setPlanDate(planDate);
|
|
List<ApsPlanSheetVo> planSheetList = iApsPlanSheetService.queryList(bo);
|
|
if (planSheetList == null || planSheetList.isEmpty()) {
|
|
return R.ok(new ArrayList<>());
|
|
}
|
|
List<Long> planSheetIds = new ArrayList<>();
|
|
for (ApsPlanSheetVo sheet : planSheetList) {
|
|
planSheetIds.add(sheet.getPlanSheetId());
|
|
}
|
|
ApsPlanDetailBo detailBo = new ApsPlanDetailBo();
|
|
detailBo.setPlanSheetIds(planSheetIds);
|
|
List<ApsPlanDetailVo> detailList = iApsPlanDetailService.queryListByPlanSheetIds(planSheetIds);
|
|
if (detailList == null || detailList.isEmpty()) {
|
|
return R.ok(new ArrayList<>());
|
|
}
|
|
List<Long> orderIds = new ArrayList<>();
|
|
for (ApsPlanDetailVo detail : detailList) {
|
|
if (detail.getOrderId() != null) {
|
|
orderIds.add(detail.getOrderId());
|
|
}
|
|
}
|
|
if (orderIds.isEmpty()) {
|
|
return R.ok(new ArrayList<>());
|
|
}
|
|
List<CrmOrderVo> orders = iCrmOrderService.queryByIds(orderIds);
|
|
return R.ok(orders);
|
|
}
|
|
}
|