ReceiptHeaderController.java 14.5 KB
package com.huaheng.pc.receipt.receiptHeader.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.page.PageDomain;
import com.huaheng.framework.web.page.TableDataInfo;
import com.huaheng.framework.web.page.TableSupport;
import com.huaheng.pc.config.company.service.CompanyService;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
import com.huaheng.pc.receipt.receiptHeaderHistory.domain.ReceiptHeaderHistory;
import com.huaheng.pc.receipt.receiptHeaderHistory.service.ReceiptHeaderHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.apache.ibatis.javassist.compiler.ast.ASTree;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.swing.text.Keymap;
import java.util.ArrayList;
import java.util.List;

@Api(tags = "入库单")
@Controller
@RequestMapping("/receipt/receiptHeader")
public class ReceiptHeaderController extends BaseController {

    private String prefix="receipt/receiptHeader";

    @Resource
    private ReceiptHeaderService receiptHeaderService;
    @Resource
    private ReceiptHeaderHistoryService receiptHeaderHistoryService;
    @Resource
    private ReceiptDetailService receiptDetailService;

    @RequiresPermissions("receipt:receiptHeader:view")
    @GetMapping("/{statusFirst}/{statusLast}")
    public String receiptHeader(ModelMap modelMap,
                                @PathVariable("statusFirst") Integer statusFirst,
                                @PathVariable("statusLast") Integer statusLast) {
        modelMap.put("statusFirst",statusFirst);
        modelMap.put("statusLast",statusLast);
        return prefix + "/receiptHeader";
    }

    /**
     * 查询入库单
     */
    @RequiresPermissions("receipt:receiptHeader:list")
    @Log(title = "入库-入库单头表", operating = "查看入库单列表", action = BusinessType.GRANT)
    @PostMapping("/list")
    @ResponseBody
    @ApiOperation("入库单查询接口")
    public TableDataInfo list(@ApiParam(name="receiptHeader",value="入库头表")ReceiptHeader receiptHeader,
                              @ApiParam(name = "createdBegin", value = "起止时间") String createdBegin,
                              @ApiParam(name = "createdEnd", value = "结束时间") String createdEnd,
                              Integer statusFirst, Integer statusLast) {
        LambdaQueryWrapper<ReceiptHeader> lambdaQueryWrapper = Wrappers.lambdaQuery();
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        String warehouCode = ShiroUtils.getWarehouseCode();
        lambdaQueryWrapper.ge(StringUtils.isNotEmpty(createdBegin), ReceiptHeader::getCreated, createdBegin)
                .le(StringUtils.isNotEmpty(createdEnd), ReceiptHeader::getCreated, createdEnd)
                .in(StringUtils.isNotEmpty(receiptHeader.getCompanyCode()),ReceiptHeader::getCompanyCode, receiptHeader.getCompanyCode())
                .in(StringUtils.isEmpty(receiptHeader.getCompanyCode()), ReceiptHeader::getCompanyCode, ShiroUtils.getCompanyCodeList())
                .eq(ReceiptHeader::getWarehouseCode, ShiroUtils.getWarehouseCode())
                .eq(StringUtils.isNotEmpty(receiptHeader.getReceiptType()),
                        ReceiptHeader::getReceiptType, receiptHeader.getReceiptType())
                .eq(StringUtils.isNotEmpty(receiptHeader.getCode()), ReceiptHeader::getCode, receiptHeader.getCode())
                .eq(StringUtils.isNotEmpty(receiptHeader.getReferCode()), ReceiptHeader::getReferCode, receiptHeader.getReferCode())
                .le(StringUtils.isNotNull(receiptHeader.getFirstStatus()),
                ReceiptHeader::getFirstStatus, receiptHeader.getFirstStatus())
                .ge(StringUtils.isNotNull(receiptHeader.getLastStatus()),
                        ReceiptHeader::getLastStatus, receiptHeader.getLastStatus())
                .orderByDesc(ReceiptHeader::getCreated);

        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)){
            /**
             * 使用分页查询
             */
            Page<ReceiptHeader> page = new Page<>(pageNum, pageSize);
            IPage<ReceiptHeader> iPage = receiptHeaderService.page(page, lambdaQueryWrapper);
            return getMpDataTable(iPage.getRecords(),iPage.getTotal());
        } else {
            List<ReceiptHeader> list = receiptHeaderService.list(lambdaQueryWrapper);
            return getDataTable(list);
        }
    }

    /**
     * 新增入库单
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存入库单
     */
    @ApiOperation(value="新增入库单 ", notes="新增入库单 ", httpMethod = "POST")
    @RequiresPermissions("receipt:receiptHeader:add")
    @Log(title = "入库-入库单 ",operating = "新增入库单 ", action = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ReceiptHeader receiptHeader) {
        return receiptHeaderService.saveReceiptHeader(receiptHeader);
    }

    /**
     * 修改入库单
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        ReceiptHeader receiptHeader = receiptHeaderService.getById(id);
        mmap.put("receiptHeader", receiptHeader);
        return prefix + "/edit";
    }

    /**
     * 修改保存入库单
     */
    @ApiOperation(value="修改入库单", notes="修改入库单", httpMethod = "POST")
    @RequiresPermissions("receipt:receiptHeader:edit")
    @Log(title = "入库-入库单 ",operating = "修改入库单 ", action = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ReceiptHeader receiptHeader) {
        ReceiptHeader receiptHeader1 = receiptHeaderService.getById(receiptHeader.getId());
        if (receiptHeader1.getFirstStatus() >100 | receiptHeader1.getLastStatus()>100){
            return AjaxResult.error("已进入订单池,不允许修改");
        }
        receiptHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
        return toAjax(receiptHeaderService.updateById(receiptHeader));
    }

    /**
     * 入库单提交审核
     */
    @ApiOperation(value="提交审核入库单", notes="提交审核入库单", httpMethod = "POST")
    @RequiresPermissions("receipt:receiptHeader:approval")
    @Log(title = "入库-入库单 ",operating = "提交审核入库单 ", action = BusinessType.UPDATE)
    @PostMapping("/submitReview")
    @ResponseBody
    public AjaxResult submitReview(@ApiParam(name="id",value="入库头表id") String ids) {
        return receiptHeaderService.submitReview(ids);
    }

    /**
     * 审核入库单
     */
    @ApiOperation(value="审核入库单", notes="审核入库单", httpMethod = "POST")
    @RequiresPermissions("receipt:receiptHeader:review")
    @Log(title = "入库-入库单 ",operating = "审核入库单 ", action = BusinessType.UPDATE)
    @PostMapping("/approval")
    @ResponseBody
    public AjaxResult approval(@ApiParam(name="id",value="入库头表id") String ids,
                               @ApiParam(name="approval",value="审核结果值,10审核驳回,20作废,100审核成功") Integer approval) {

        return receiptDetailService.approval(ids, approval);
    }

//    /**
//     * 提交审核入库单
//     */
//    @ApiOperation(value="提交审核入库单", notes="提交审核入库单", httpMethod = "POST")
//    @RequiresPermissions("receipt:receiptHeader:approval")
//    @Log(title = "入库-入库单 ",operating = "提交审核入库单 ", action = BusinessType.UPDATE)
//    @PostMapping("/submitReview")
//    @ResponseBody
//    public AjaxResult submitReview(@ApiParam(name="id",value="入库头表id") Integer id) {
//        ReceiptHeader receiptHeader = new ReceiptHeader();
//        receiptHeader.setId(id);
//        receiptHeader.setFirstStatus(5);
//        receiptHeader.setLastStatus(5);
//        return toAjax(receiptHeaderService.updateById(receiptHeader));
//    }

    /**
     * 删除入库单
     */
    @ApiOperation(value="删除入库单", notes="删除入库单", httpMethod = "POST")
    @RequiresPermissions("receipt:receiptHeader:remove")
    @Log(title = "入库-入库单 ",operating = "入库单删除", action = BusinessType.UPDATE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(@ApiParam(name = "id", value = "入库头表id字符串")String ids){
        if (StringUtils.isNull(ids)){
            return AjaxResult.error("id为空");
        }
        return receiptHeaderHistoryService.add(ids);
    }

    /**
     * 入库预约
     */
    @GetMapping("/arrival/{id}")
    public String reservation(@PathVariable("id")Integer id, ModelMap map) {
        LambdaQueryWrapper<ReceiptDetail> receiptDetailLambda = Wrappers.lambdaQuery();
        receiptDetailLambda.eq(ReceiptDetail::getReceiptId, id)
                .eq(ReceiptDetail::getProcessStamp, "120");
        List<ReceiptDetail> list = receiptDetailService.list(receiptDetailLambda);
        if (list == null){
            throw new ServiceException("没有需要预约入库的单据");
        }
        ReceiptHeader receiptHeader = receiptHeaderService.getById(id);
        map.put("receiptHeader", receiptHeader);
        return prefix + "/reservation";
    }

    /**
     * 保存入库预约
     */
    @ApiOperation(value="保存入库预约", notes="保存入库预约", httpMethod = "POST")
    @RequiresPermissions("receipt:receiptHeader:reservation")
    @Log(title = "入库-入库单 ",operating = "入库单预约", action = BusinessType.UPDATE)
    @PostMapping("/arrival")
    @ResponseBody
    public AjaxResult reservation(ReceiptHeader receiptHeader) {
        return receiptHeaderService.reservation(receiptHeader);
    }

    @RequiresPermissions("receipt:receiptHeader:view")
    @GetMapping("/receiving")
    public String receiving()
    {
        return prefix + "/receiving";
    }

    /**
     * 入库质检
     */
    @ApiOperation(value="入库质检", notes="入库质检", httpMethod = "POST")
    @RequiresPermissions("receipt:receiptHeader:check")
    @Log(title = "入库-入库单质检",operating = "入库质检", action = BusinessType.OTHER)
    @PostMapping("/check")
    @ResponseBody
    public AjaxResult check(@ApiParam(name = "id", value = "入库头表id")Integer id){
        if (StringUtils.isNull(id)){
            return AjaxResult.error("id为空");
        }
        return receiptHeaderService.check(id);
    }

    /**
     * 入库单打印
     */
    @ApiOperation(value="打印入库单报表", notes="打印入库单报表", httpMethod = "POST")
    @RequiresPermissions("receipt:receiptHeader:report")
    @Log(title = "入库-入库单",operating = "打印入库单报表", action = BusinessType.OTHER)
    @GetMapping("/report/{id}")
    public String report(@ApiParam(name = "id", value = "入库头表id")
                                         @PathVariable("id") Integer id, ModelMap mmap){
        ReceiptHeader receiptHeader = receiptHeaderService.getById(id);
        mmap.put("receiptHeader", receiptHeader);

        //查询对应入库明细
        LambdaQueryWrapper<ReceiptDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(ReceiptDetail::getReceiptId, id);
        List<ReceiptDetail> details = receiptDetailService.list(lambdaQueryWrapper);
        mmap.put("details", details);

        return prefix+"/report";
    }

    /**
     * 查询入库单
     */
    @ApiOperation(value="查询入库单 ", notes="查询入库单 ", httpMethod = "POST")
    @RequiresPermissions("receipt:receiptDetail:add")
    @Log(title = "入库-入库单 ",operating = "查询入库单 ", action = BusinessType.OTHER)
    @PostMapping("/getReceiptHeader")
    @ResponseBody
    public AjaxResult<ReceiptHeader> getReceiptHeader(String id) {
        if (StringUtils.isEmpty(id)){
            return AjaxResult.success("");
        }
        return AjaxResult.success(receiptHeaderService.getById(id));
    }

    /**
     * 到货通知
     */
    @ApiOperation(value="到货通知 ", notes="到货通知 ", httpMethod = "POST")
    @RequiresPermissions("receipt:receiptDetail:add")
    @Log(title = "入库-入库单 ",operating = "到货通知 ", action = BusinessType.OTHER)
    @PostMapping("/arrivalNotice")
    @ResponseBody
    public AjaxResult arrivalNotice(String id) {
        if (StringUtils.isEmpty(id)){
            return AjaxResult.success("");
        }
        return AjaxResult.success(receiptHeaderService.arrivalNotice(id));
    }

    /**
     * 加入订单池
     */
    @ApiOperation(value="加入订单池 ", notes="加入订单池 ", httpMethod = "POST")
    @RequiresPermissions("receipt:receiptHeader:addPool")
    @Log(title = "入库-入库单",operating = "加入订单池 ", action = BusinessType.OTHER)
    @PostMapping("/addPool")
    @ResponseBody
    public AjaxResult addPool(String ids) {
        if (StringUtils.isEmpty(ids)){
            return AjaxResult.error("id不能为空");
        }
        return AjaxResult.success(receiptHeaderService.addPool(ids));
    }

    @ApiOperation(value = "越库", notes = "越库", httpMethod = "POST")
    @RequiresPermissions("receipt:receiptHeader:cross")
    @Log(title = "入库-入库单", operating = "越库", action = BusinessType.OTHER)
    @PostMapping("/crossLocation")
    @ResponseBody
    public AjaxResult crossLocation(String ids) {
        return AjaxResult.success(receiptHeaderService.crossLocation(ids));
    }
}