package cn.stylefeng.guns.modular.zsx.pm.salesOrder.controller; import cn.afterturn.easypoi.entity.vo.MapExcelConstants; import cn.afterturn.easypoi.excel.entity.ExportParams; import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; import cn.afterturn.easypoi.view.PoiBaseView; import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo; import cn.stylefeng.guns.modular.zsx.pm.salesOrder.entity.SalesOrder; import cn.stylefeng.guns.modular.zsx.pm.salesOrder.model.params.SalesOrderParam; import cn.stylefeng.guns.modular.zsx.pm.salesOrder.service.SalesOrderService; import cn.stylefeng.roses.core.base.controller.BaseController; import cn.stylefeng.roses.kernel.model.response.ResponseData; import cn.stylefeng.roses.core.mutidatasource.annotion.DataSource; import com.baomidou.mybatisplus.extension.api.R; import lombok.SneakyThrows; import org.apache.poi.hssf.usermodel.HSSFDateUtil; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Objects; /** * 生产订单控制器 * * @author ruimin * @Date 2023-08-26 15:55:23 */ @Controller @RequestMapping("/salesOrder") public class SalesOrderController extends BaseController { private String PREFIX = "/modular/pm/salesOrder"; @Autowired private SalesOrderService salesOrderService; /** * 跳转到主页面 * * @author ruimin * @Date 2023-08-26 */ @RequestMapping("") public String index() { return PREFIX + "/salesOrder.html"; } /** * 新增页面 * * @author ruimin * @Date 2023-08-26 */ @RequestMapping("/add") public String add() { return PREFIX + "/salesOrder_add.html"; } /** * 编辑页面 * * @author ruimin * @Date 2023-08-26 */ @RequestMapping("/edit") public String edit() { return PREFIX + "/salesOrder_edit.html"; } /** * 拆分页面 * * @author ruimin * @Date 2023-08-26 */ @RequestMapping("/split") public String split() { return PREFIX + "/split.html"; } /** * 下发页面 * * @author ruimin * @Date 2023-08-26 */ @RequestMapping("/bindParam") public String bindParam() { return PREFIX + "/bindParam.html"; } /** * 新增接口 * * @author ruimin * @Date 2023-08-26 */ @RequestMapping("/addItem") @ResponseBody @DataSource(name = "self") public ResponseData addItem(SalesOrderParam salesOrderParam) { this.salesOrderService.add(salesOrderParam); return ResponseData.success(); } /** * 编辑接口 * * @author ruimin * @Date 2023-08-26 */ @RequestMapping("/editItem") @ResponseBody @DataSource(name = "self") public ResponseData editItem(SalesOrderParam salesOrderParam) { this.salesOrderService.update(salesOrderParam); return ResponseData.success(); } /** * 编辑接口 * * @author ruimin * @Date 2023-08-26 */ @RequestMapping("/updateBySalesOrderId") @ResponseBody @DataSource(name = "self") public ResponseData updateBySalesOrderId(SalesOrderParam salesOrderParam) { SalesOrder byId = this.salesOrderService.getById(salesOrderParam.getId()); byId.setState("2"); this.salesOrderService.saveOrUpdate(byId); return ResponseData.success(); } /** * 删除接口 * * @author ruimin * @Date 2023-08-26 */ @RequestMapping("/delete") @ResponseBody @DataSource(name = "self") public ResponseData delete(SalesOrderParam salesOrderParam) { this.salesOrderService.delete(salesOrderParam); return ResponseData.success(); } /** * 查看详情接口 * * @author ruimin * @Date 2023-08-26 */ @RequestMapping("/detail") @ResponseBody @DataSource(name = "self") public ResponseData detail(SalesOrderParam salesOrderParam) { SalesOrder detail = this.salesOrderService.getById(salesOrderParam.getId()); return ResponseData.success(detail); } /** * 查询列表 * * @author ruimin * @Date 2023-08-26 */ @ResponseBody @RequestMapping("/list") @DataSource(name = "self") public LayuiPageInfo list(SalesOrderParam salesOrderParam) { return this.salesOrderService.findPageBySpec(salesOrderParam); } /** * 拆分订单方法 * * @author ruimin * @Date 2023-08-26 */ @ResponseBody @RequestMapping("/breakDownOrders") @DataSource(name = "self") public LayuiPageInfo breakDownOrders(SalesOrderParam salesOrderParam) { return this.salesOrderService.breakDownOrders(salesOrderParam); } /** * 拆分绑定下发方法 * * @author ruimin * @Date 2023-08-26 */ @ResponseBody @RequestMapping("/DistributeSalesOrder") @DataSource(name = "self") public ResponseData DistributeSalesOrder(SalesOrderParam salesOrderParam) { this.salesOrderService.DistributeSalesOrder(salesOrderParam); return ResponseData.success(); } /** * 导入excel * * @author liwenya * @Date 2021-07-09 */ @SneakyThrows @RequestMapping(value = "/importIn") @ResponseBody @DataSource(name = "self") public ResponseData importIn(@RequestPart("file") MultipartFile file, HttpServletRequest request) throws IOException { List list = new ArrayList<>(); XSSFWorkbook sheets = new XSSFWorkbook(file.getInputStream()); //获取sheet XSSFSheet sheet = sheets.getSheet(sheets.getSheetName(0)); int rows = sheet.getPhysicalNumberOfRows(); for(int i = 2; i < rows; i++){ //获取列数 XSSFRow row = sheet.getRow(i); SalesOrder salesOrder = new SalesOrder(); salesOrder.setSalesOrderCode(String.valueOf(row.getCell(0)).replace(".0", "")); salesOrder.setCustomerNo(String.valueOf(row.getCell(1)).replace(".0", "")); salesOrder.setCargoNo(row.getCell(2).toString().replace(".0", "")); salesOrder.setProductCode(row.getCell(3).toString().replace(".0", "")); salesOrder.setProductName(row.getCell(4).toString().replace(".0", "")); Cell planNumber = row.getCell(5); if(!Objects.equals(planNumber, null) && !Objects.equals(planNumber.toString(),"")){ double d = planNumber.getNumericCellValue(); salesOrder.setPlanNumber((int) d); } Cell planStartTime = row.getCell(6); if(HSSFDateUtil.isCellDateFormatted(planStartTime)){ Date d = planStartTime.getDateCellValue(); salesOrder.setPlanStartTime(d); } Cell planEndTime = row.getCell(7); if(HSSFDateUtil.isCellDateFormatted(planEndTime)){ Date d = planEndTime.getDateCellValue(); salesOrder.setPlanEndTime(d); } salesOrder.setWorkshopCode(row.getCell(8).toString().replace(".0", "")); salesOrder.setLineCode(row.getCell(9).toString().replace(".0", "")); Cell deliveryTime = row.getCell(10); if(HSSFDateUtil.isCellDateFormatted(deliveryTime)){ Date d = deliveryTime.getDateCellValue(); salesOrder.setDeliveryTime(d); } salesOrder.setOrderSource(row.getCell(11).toString().replace(".0", "")); salesOrder.setRemark(row.getCell(12).toString().replace(".0", "")); salesOrder.setState("1"); list.add(salesOrder); } for(SalesOrder salesOrder : list){ salesOrderService.save(salesOrder); } return ResponseData.success("上传成功"); } /** * excel导出模板 * * @author liwenya * @Date 2021年7月9日 17点01分 */ @RequestMapping("/exportOut") public void exportOut(ModelMap modelMap, HttpServletRequest request, HttpServletResponse response) { List entity = new ArrayList<>(); entity.add(new ExcelExportEntity("订单编号", "salesOrderCode")); entity.add(new ExcelExportEntity("客户编号", "customerNo")); entity.add(new ExcelExportEntity("货号", "cargoNo")); entity.add(new ExcelExportEntity("产品编号", "productCode")); entity.add(new ExcelExportEntity("产品名称", "productName")); entity.add(new ExcelExportEntity("计划数量", "planNumber")); entity.add(new ExcelExportEntity("计划开始时间", "planStartTime")); entity.add(new ExcelExportEntity("计划结束时间", "planEndTime")); entity.add(new ExcelExportEntity("车间编码", "workshopCode")); entity.add(new ExcelExportEntity("产线编码", "lineCode")); entity.add(new ExcelExportEntity("交货时间", "deliveryTime")); entity.add(new ExcelExportEntity("订单来源", "orderSource")); entity.add(new ExcelExportEntity("备注", "remark")); ExportParams params = new ExportParams("生产订单", "生产订单", ExcelType.XSSF); modelMap.put(MapExcelConstants.MAP_LIST, new ArrayList<>()); modelMap.put(MapExcelConstants.ENTITY_LIST, entity); modelMap.put(MapExcelConstants.PARAMS, params); modelMap.put(MapExcelConstants.FILE_NAME, "生产订单"); PoiBaseView.render(modelMap, request, response, MapExcelConstants.EASYPOI_MAP_EXCEL_VIEW); } }