春风项目四线(合箱线、总装线)
yyt
2024-05-06 bbc5784cc34d65e64d639d949e75b978fe07bdb3
jcdm-main/src/main/java/com/jcdm/main/bs/orderScheduling/controller/BsOrderSchedulingController.java
@@ -1,31 +1,46 @@
package com.jcdm.main.bs.orderScheduling.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.hutool.core.collection.CollUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.jcdm.common.annotation.Log;
import com.jcdm.common.core.controller.BaseController;
import com.jcdm.common.core.domain.AjaxResult;
import com.jcdm.common.core.domain.R;
import com.jcdm.common.core.domain.entity.SysDictData;
import com.jcdm.common.core.page.TableDataInfo;
import com.jcdm.common.enums.BusinessType;
import com.jcdm.common.utils.StringUtils;
import com.jcdm.common.utils.poi.ExcelUtil;
import com.jcdm.main.bs.orderScheduling.domain.BsOrderScheduling;
import com.jcdm.main.bs.orderScheduling.service.IBsOrderSchedulingService;
import com.jcdm.common.utils.poi.ExcelUtil;
import com.jcdm.common.core.page.TableDataInfo;
import com.jcdm.main.bs.orderScheduling.vo.FollowReportVO;
import com.jcdm.main.bs.orderScheduling.vo.LineChartVO;
import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
import com.jcdm.main.plcserver.conf.OPCElement;
import com.jcdm.system.service.ISysDictDataService;
import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.service.MiloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
 * 订单排产Controller
 * 
 * @author jiang
 * @date 2024-01-09
 * @date 2024-01-13
 */
@RestController
@RequestMapping("/bs/orderScheduling")
@@ -33,6 +48,29 @@
{
    @Autowired
    private IBsOrderSchedulingService bsOrderSchedulingService;
    @Resource
    private ISysDictDataService iSysDictDataService;
    @Autowired
    MiloService miloService;
    @Value("${websocketUrl}")
    private String websocketUrl;
    @GetMapping("/forceUpload")
    public void forceUpload() throws Exception {
        ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP121_ZZ_CODE_CHECK, 1);
        miloService.writeToOpcByte(entity);
    }
    @GetMapping("/websocketUrl")
    public String websocketName() {
        return websocketUrl;
    }
    /**
     * 查询订单排产列表
@@ -43,6 +81,104 @@
    {
        startPage();
        List<BsOrderScheduling> list = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling);
        return getDataTable(list);
    }
    /**
     * 查询追溯列表
     */
    @PreAuthorize("@ss.hasPermi('bs:orderScheduling:list')")
    @GetMapping("/getFollowReportList")
    public R getFollowReportList(BsOrderScheduling bsOrderScheduling)
    {
        FollowReportVO followReportList = bsOrderSchedulingService.getFollowReportList(bsOrderScheduling);
        return R.ok(followReportList);
    }
    @PreAuthorize("@ss.hasPermi('bs:orderScheduling:export')")
    @Log(title = "追溯报表导出", businessType = BusinessType.EXPORT)
    @PostMapping("/exportFollow")
    public void exportFollow(HttpServletResponse response, BsOrderScheduling bsOrderScheduling)
    {
        FollowReportVO followReportList = bsOrderSchedulingService.getFollowReportList(bsOrderScheduling);
        List<SysDictData> allDict = iSysDictDataService.selectDictDataList(null);
        if (CollUtil.isNotEmpty(followReportList.getMainList())){
            List<SysDictData> dict1 = allDict.stream().filter(x -> "material_type".equals(x.getDictType())).collect(Collectors.toList());
            List<SysDictData> dict2 = allDict.stream().filter(x -> "order_scheduling_produce_status".equals(x.getDictType())).collect(Collectors.toList());
            for (BsOrderScheduling orderScheduling : followReportList.getMainList()) {
                if (CollUtil.isNotEmpty(dict1)){
                    List<SysDictData> collect = dict1.stream().filter(x -> x.getDictValue().equals(orderScheduling.getProductType())).collect(Collectors.toList());
                    if (CollUtil.isNotEmpty(collect)){
                        SysDictData sysDictData1 = collect.get(0);
                        orderScheduling.setProductTypeString(sysDictData1.getDictLabel());
                    }
                }
                if (CollUtil.isNotEmpty(dict2)){
                    List<SysDictData> collect = dict2.stream().filter(x -> x.getDictValue().equals(orderScheduling.getProductionStatus())).collect(Collectors.toList());
                    if (CollUtil.isNotEmpty(collect)){
                        SysDictData sysDictData1 = collect.get(0);
                        orderScheduling.setProductionStatusString(sysDictData1.getDictLabel());
                    }
                }
            }
        }
        String fileName = "追溯报表";
        try {
            ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build();
            WriteSheet mainSheet = EasyExcel.writerSheet(0, "订单排产")
                    .head(BsOrderScheduling.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
                    .build();
            WriteSheet sheet1 = EasyExcel.writerSheet(1, "拧紧数据")
                    .head(DaParamCollection.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
                    .build();
            WriteSheet sheet2 = EasyExcel.writerSheet(2, "相机检测")
                    .head(DaParamCollection.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
                    .build();
            WriteSheet sheet3 = EasyExcel.writerSheet(3, "外漏检测")
                    .head(DaParamCollection.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
                    .build();
            WriteSheet sheet4 = EasyExcel.writerSheet(4, "机油加注")
                    .head(DaParamCollection.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
                    .build();
            WriteSheet sheet5 = EasyExcel.writerSheet(5, "工位结果")
                    .head(DaPassingStationCollection.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
                    .build();
            excelWriter.write(followReportList.getMainList(),mainSheet);
            excelWriter.write(followReportList.getList1(),sheet1);
            excelWriter.write(followReportList.getList2(),sheet2);
            excelWriter.write(followReportList.getList3(),sheet3);
            excelWriter.write(followReportList.getList4(),sheet4);
            excelWriter.write(followReportList.getList5(),sheet5);
            response.setContentType("application/vnd.ms-excel;charset=utf-8");
            response.setCharacterEncoding("UTF-8");
            response.setHeader("Content-Disposition","attachment;filename="+fileName+".xlsx");
            excelWriter.finish();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    /**
     * 查询下线数量
     */
    @PreAuthorize("@ss.hasPermi('bs:orderScheduling:list')")
    @GetMapping("/getOffLineNum")
    public TableDataInfo getOffLineNum(BsOrderScheduling bsOrderScheduling)
    {
        List<LineChartVO> vo = bsOrderSchedulingService.getOffLineNum();
        return getDataTable(vo);
    }
    @PreAuthorize("@ss.hasPermi('bs:orderScheduling:list')")
    @GetMapping("/list2")
    public TableDataInfo list2(BsOrderScheduling bsOrderScheduling)
    {
//        startPage();
        List<BsOrderScheduling> list = new ArrayList<>();
        if (StringUtils.isNotEmpty(bsOrderScheduling.getOrderNo())){
            list = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling);
        }
        return getDataTable(list);
    }
@@ -63,10 +199,10 @@
     * 获取订单排产详细信息
     */
    @PreAuthorize("@ss.hasPermi('bs:orderScheduling:query')")
    @GetMapping(value = "/{orderNumber}")
    public AjaxResult getInfo(@PathVariable("orderNumber") String orderNumber)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bsOrderSchedulingService.selectBsOrderSchedulingByOrderNumber(orderNumber));
        return success(bsOrderSchedulingService.selectBsOrderSchedulingById(id));
    }
    /**
@@ -96,9 +232,9 @@
     */
    @PreAuthorize("@ss.hasPermi('bs:orderScheduling:remove')")
    @Log(title = "订单排产", businessType = BusinessType.DELETE)
   @DeleteMapping("/{orderNumbers}")
    public AjaxResult remove(@PathVariable String[] orderNumbers)
   @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bsOrderSchedulingService.deleteBsOrderSchedulingByOrderNumbers(orderNumbers));
        return toAjax(bsOrderSchedulingService.deleteBsOrderSchedulingByIds(ids));
    }
}