MaterialWarningController.java 6.45 KB
package com.huaheng.pc.config.materialWarnning.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.framework.web.page.PageDomain;
import com.huaheng.framework.web.page.TableDataInfo;
import com.huaheng.framework.web.page.TableSupport;
import com.huaheng.common.utils.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
import com.huaheng.pc.config.materialWarnning.domain.MaterialWarning;
import com.huaheng.pc.config.materialWarnning.service.IMaterialWarningService;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.common.support.Convert;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 物料报警 信息操作处理
 *
 * @author huaheng
 * @date 2020-07-17
 */
@Controller
@RequestMapping("/config/materialWarning")
public class MaterialWarningController extends BaseController {
    private String prefix = "config/materialWarning";

	@Resource
	private IMaterialWarningService materialWarningService;

	@RequiresPermissions("config:materialWarning:view")
	@GetMapping()
	public String materialWarning() {
	    return prefix + "/materialWarning";
	}

	/**
	 * 查询物料报警列表
	 */
	@RequiresPermissions("config:materialWarning:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(MaterialWarning materialWarning) {
		LambdaQueryWrapper<MaterialWarning> lambdaQueryWrapper = Wrappers.lambdaQuery();
		lambdaQueryWrapper
		.eq(StringUtils.isNotNull(materialWarning.getAlarmType()), MaterialWarning::getAlarmType, materialWarning.getAlarmType())
		.eq(StringUtils.isNotEmpty(materialWarning.getWarehouseCode()), MaterialWarning::getWarehouseCode, materialWarning.getWarehouseCode())
		.eq(StringUtils.isNotEmpty(materialWarning.getCompanyCode()), MaterialWarning::getCompanyCode, materialWarning.getCompanyCode())
		.eq(StringUtils.isNotEmpty(materialWarning.getMaterialCode()), MaterialWarning::getMaterialCode, materialWarning.getMaterialCode())
		.like(StringUtils.isNotEmpty(materialWarning.getMaterialName()), MaterialWarning::getMaterialName, materialWarning.getMaterialName())
		.eq(StringUtils.isNotEmpty(materialWarning.getMaterialSpec()), MaterialWarning::getMaterialSpec, materialWarning.getMaterialSpec())
		.eq(StringUtils.isNotEmpty(materialWarning.getMaterialUnit()), MaterialWarning::getMaterialUnit, materialWarning.getMaterialUnit())
		.eq(StringUtils.isNotNull(materialWarning.getMax()), MaterialWarning::getMax, materialWarning.getMax())
		.eq(StringUtils.isNotNull(materialWarning.getMin()), MaterialWarning::getMin, materialWarning.getMin())
		.eq(StringUtils.isNotNull(materialWarning.getUpper()), MaterialWarning::getUpper, materialWarning.getUpper())
		.eq(StringUtils.isNotNull(materialWarning.getLower()), MaterialWarning::getLower, materialWarning.getLower())
		.eq(StringUtils.isNotNull(materialWarning.getCreated()), MaterialWarning::getCreated, materialWarning.getCreated())
		.eq(StringUtils.isNotEmpty(materialWarning.getCreatedBy()), MaterialWarning::getCreatedBy, materialWarning.getCreatedBy())
		.eq(StringUtils.isNotNull(materialWarning.getLastUpdated()), MaterialWarning::getLastUpdated, materialWarning.getLastUpdated())
		.eq(StringUtils.isNotEmpty(materialWarning.getLastUpdatedBy()), MaterialWarning::getLastUpdatedBy, materialWarning.getLastUpdatedBy())
		.eq(StringUtils.isNotNull(materialWarning.getUserId()), MaterialWarning::getUserId, materialWarning.getUserId())
		.like(StringUtils.isNotEmpty(materialWarning.getUserName()), MaterialWarning::getUserName, materialWarning.getUserName())
		.eq(StringUtils.isNotEmpty(materialWarning.getEmail()), MaterialWarning::getEmail, materialWarning.getEmail())
		;
		PageDomain pageDomain = TableSupport.buildPageRequest();
		Integer pageNum = pageDomain.getPageNum();
		Integer pageSize = pageDomain.getPageSize();
		if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)){
			/*使用分页查询*/
			Page<MaterialWarning> page = new Page<>(pageNum, pageSize);
			IPage<MaterialWarning> iPage = materialWarningService.page(page, lambdaQueryWrapper);
			return getMpDataTable(iPage.getRecords(), iPage.getTotal());
		} else {
			List<MaterialWarning> list = materialWarningService.list(lambdaQueryWrapper);
			return getDataTable(list);
		}
	}

	/**
	 * 新增物料报警
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}

	/**
	 * 新增保存物料报警
	 */
	@RequiresPermissions("config:materialWarning:add")
	@Log(title = "物料报警", action = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(MaterialWarning materialWarning) {
		return toAjax(materialWarningService.save(materialWarning));
	}

	/**
	 * 修改物料报警
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
		MaterialWarning materialWarning = materialWarningService.getById(id);
		mmap.put("materialWarning", materialWarning);
	    return prefix + "/edit";
	}

	/**
	 * 修改保存物料报警
	 */
	@RequiresPermissions("config:materialWarning:edit")
	@Log(title = "物料报警", action = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(MaterialWarning materialWarning) {
		return toAjax(materialWarningService.updateById(materialWarning));
	}

	/**
	 * 删除物料报警
	 */
	@RequiresPermissions("config:materialWarning:remove")
	@Log(title = "物料报警", action = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		if (StringUtils.isEmpty(ids)){
			return AjaxResult.error("id不能为空");
		}
		return toAjax(materialWarningService.removeByIds(Arrays.asList(Convert.toIntArray(ids))));
	}

}