ReceiptHeaderController.java 19.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
package com.huaheng.pc.receipt.receiptHeader.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huaheng.common.utils.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huaheng.common.constant.QuantityConstant;
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.config.receiptType.service.ReceiptTypeService;
import com.huaheng.pc.config.supplier.service.SupplierService;
import com.huaheng.pc.config.warehouse.domain.WarehouseU8;
import com.huaheng.pc.config.warehouse.service.WarehouseService;
import com.huaheng.pc.config.warehouse.service.WarehouseU8Service;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
import com.huaheng.pc.receipt.receiptDetailHistory.domain.ReceiptDetailHistory;
import com.huaheng.pc.receipt.receiptDetailHistory.service.ReceiptDetailHistoryService;
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 com.huaheng.pc.srm.service.FinishedProductService;
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.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
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.Arrays;
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;
    @Resource
    private ReceiptDetailHistoryService receiptDetailHistoryService;
    @Resource
    private ReceiptHeaderHistoryService receiptheaderhistoryService;
    @Resource
    private WarehouseService warehouseService;
    @Resource
    private WarehouseU8Service warehouseU8Service;
    @Resource
    private SupplierService supplierService;
    @Resource
    private ReceiptTypeService receiptTypeService;
    @Resource
    private FinishedProductService finishedProductService;


    @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();
        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())
//                .like(StringUtils.isNotEmpty(receiptHeader.getSupplierName()), ReceiptHeader::getCode, receiptHeader.getCode())
                .eq(StringUtils.isNotEmpty(receiptHeader.getCreatedBy()), ReceiptHeader::getCreatedBy, receiptHeader.getCreatedBy())
                .eq(StringUtils.isNotEmpty(receiptHeader.getReferCode()), ReceiptHeader::getReferCode, receiptHeader.getReferCode())
                .eq( ReceiptHeader::getDeleted,false)
                .notIn(ReceiptHeader::getReceiptType,QuantityConstant.U8_RECEIPT_TYPE_PCI)
                .eq(StringUtils.isNotNull(receiptHeader.getFirstStatus()),
                 ReceiptHeader::getFirstStatus, receiptHeader.getFirstStatus())
                .eq(StringUtils.isNotNull(receiptHeader.getLastStatus()),
                        ReceiptHeader::getLastStatus, receiptHeader.getLastStatus());
        if(StringUtils.isNotEmpty(receiptHeader.getSupplierCode())){
            lambdaQueryWrapper.apply(" supplierCode in(select code from supplier where name like '%"+receiptHeader.getSupplierCode()+"%' )");
        }
        lambdaQueryWrapper.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 (!QuantityConstant.RECEIPT_TYPE_PPI.equals(receiptHeader.getReceiptType())){
            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")
    @Transactional(rollbackFor = Exception.class)
    @ResponseBody
    public AjaxResult remove(@ApiParam(name = "id", value = "入库头表id字符串")String ids){
        if (StringUtils.isNull(ids)){
            return AjaxResult.error("id为空");
        }

        return receiptHeaderService.deleteHeaderAndDetail(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);
        String warehouseName=warehouseService.getWarehouseNameByCode(receiptHeader.getWarehouseCode());
        receiptHeader.setWarehouseName(warehouseName);
        String supplierName=supplierService.getSuppierNameByCode(receiptHeader.getSupplierCode());
        receiptHeader.setSupplierName(supplierName);
        String receiptTypeName=receiptTypeService.getReceiptTypeNameByCode(receiptHeader.getReceiptType());
        receiptHeader.setReceiptTypeName(receiptTypeName);
        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+"/reportV";
    }

    /**
     * 查询入库单
     */
    @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));
    }

    /**
     * 越货
     */
    @Log(title = "入库-入库单", operating = "越库", action = BusinessType.OTHER)
    @PostMapping( "/yueku")
    @ResponseBody
    public synchronized AjaxResult yueku(String ids) throws Exception {
        return receiptHeaderService.yueku(ids);
    }


    /**
     *  回传
     */
    @ApiOperation(value="回传 ", notes="回传 ", httpMethod = "POST")
    @Log(title = "入库-入库单",operating = "回传 ", action = BusinessType.OTHER)
    @PostMapping("/backERP")
    @ResponseBody
    public AjaxResult backERP(String id) {
        if (StringUtils.isEmpty(id)){
            return AjaxResult.error("id不能为空");
        }
        ReceiptHeader receiptHeader = receiptHeaderService.getById(id);
        if(receiptHeader == null) {
            return AjaxResult.error("没有找到入库单");
        }

        receiptHeader.setFirstStatus(QuantityConstant.RECEIPT_HEADER_RETURN);
        receiptHeader.setLastStatus(QuantityConstant.RECEIPT_HEADER_RETURN);
        receiptHeaderService.updateById(receiptHeader);
        return AjaxResult.success("回传成功");
    }
    /*@RequiresPermissions("receipt:bill:add")
    @Log(title = "ruku-入库单", operating="入库回传", action = BusinessType.OTHER)
    @PostMapping("/huichuan")
    @ResponseBody
    //@ApiLogger(from = "WMS",to = "U8",apiName = "入库单手动回传")
    public AjaxResult huichuan(String ids) {
        if (StringUtils.isEmpty(ids)){
            return AjaxResult.error("id不能为空");
        }

        String receiptUrl = addressService.getUrl("U8")+"InStorage/u";
        List<Integer> idList = Arrays.asList(Convert.toIntArray(ids));
        for (Integer id : idList) {
            return receiptHeaderService.huichuan(id,receiptUrl);
        }
        return AjaxResult.success("成功");
    }*/
    /**
     * 获取产成品入库单据
     */
    @GetMapping("/getReceiptSI")
    public String getReceiptSI() {
        return prefix + "/getReceiptSI";
    }


    /**
     * 获取产成品入库单据
     */
    @RequiresPermissions("receipt:receiptHeader:cross")
    @Log(title = "入库-入库单", operating = "产成品入库单获取", action = BusinessType.OTHER)
    @PostMapping("/getReceiptSI")
    @ResponseBody
    public synchronized AjaxResult getReceiptSI(String code,String companyCode) {
        if(StringUtils.isEmpty(code) || StringUtils.isEmpty(companyCode)){
            return AjaxResult.error("编码为空");
        }
        return finishedProductService.getReceipt(code,companyCode,ShiroUtils.getWarehouseCode());
    }

    @PostMapping("/getwarehouse")
    @ResponseBody
    public TableDataInfo WarehouseList(String code) {
        WarehouseU8 warehouseWu = new WarehouseU8();
        LambdaQueryWrapper<WarehouseU8> lambdaQueryWrapper=Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(WarehouseU8::getWarehouseCode,ShiroUtils.getWarehouseCode());
        if (!code.equals("")) {
            lambdaQueryWrapper.eq(WarehouseU8::getCompanyCode,code);
        }
        List<WarehouseU8> list = warehouseU8Service.list(lambdaQueryWrapper);
        return getDataTable(list);
    }
}