EquipmnetController.java 5.95 KB
package com.huaheng.pc.plc.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.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.common.JasperPrint.Print;
import com.huaheng.pc.plc.domain.PlcEquipment;
import com.huaheng.pc.plc.service.EquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
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 java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @author:zhouhong
 * 设备管理
 * 202203
 */
@Api(tags={"设备管理类"})
@Controller
@RequestMapping("/plc/equipment")
public class EquipmnetController extends BaseController {

    @Resource
    private EquipmentService equipmentService;

    private String prefix = "plc/equipment";


    @Resource
    private Print print;
    @GetMapping()
    public String tolist() {
        return prefix + "/equipmentlist";
    }
    /**
     * 查询列表
     */
    @ApiOperation(value="查询列表",
            notes="根据名称查询信息",
            httpMethod = "POST")
    @RequiresPermissions("plc:equipment:list")
    @Log(title = "配置-plc-设备管理", operating = "查看列表", action = BusinessType.GRANT)
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(
            @ApiParam(name="equipmentName",value="设备名称") String equipmentName,
            @ApiParam(name = "status", value = "启用状态") String status) {
        LambdaQueryWrapper<PlcEquipment> lambdaQueryWrapper = Wrappers.lambdaQuery();
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        lambdaQueryWrapper.eq(StringUtils.isNotEmpty(equipmentName), PlcEquipment::getEquipmentName,equipmentName)
                .eq(StringUtils.isNotEmpty(status), PlcEquipment::getStatus, status)
                .orderByDesc(PlcEquipment::getId);
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)){
            /*使用分页查询*/
            Page<PlcEquipment> page = new Page<>(pageNum, pageSize);
            IPage<PlcEquipment> iPage = equipmentService.page(page, lambdaQueryWrapper);
            return getMpDataTable(iPage.getRecords(), iPage.getTotal());
        } else {
            List<PlcEquipment> list = equipmentService.list(lambdaQueryWrapper);
            return getDataTable(list);
        }

    }

    /**
     * 新增
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        return prefix + "/add";
    }

    /**
     * 新增保存
     */
    @RequiresPermissions("plc:equipment:add")
    @Log(title = "设备管理", operating = "新增", action = BusinessType.INSERT)
    @PostMapping("/addSave")
    @Transactional(rollbackFor = Exception.class)
    @ResponseBody
    public AjaxResult addSave(PlcEquipment plcEquipment)
    {
        plcEquipment.setCreateBy(ShiroUtils.getLoginName());
        plcEquipment.setCreateTime(new Date());
        //plcEquipment.seto
        AjaxResult ajaxResult = toAjax(equipmentService.save(plcEquipment));
        return  ajaxResult;
    }

    /**
     * 修改
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        mmap.put("equipment", equipmentService.getById(id));
        return prefix + "/edit";
    }

    /**
     * 修改保存
     */
    @RequiresPermissions("plc:equipment:edit")
    @Log(title = "修改保存", operating = "修改", action = BusinessType.UPDATE)
    @PostMapping("/edit")
    @Transactional(rollbackFor = Exception.class)
    @ResponseBody
    public AjaxResult editSave(PlcEquipment equipment)
    {
        equipment.setUpdateBy(ShiroUtils.getLoginName());
        equipment.setUpdateTime(new Date());
        AjaxResult ajaxResult = toAjax(equipmentService.updateById(equipment));
        return ajaxResult;
    }

    @RequiresPermissions("plc:equipment:remove")
    @Log(title = "删除", operating = "删除", action = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        try
        {
            return toAjax(equipmentService.removeByIds(Arrays.asList(Convert.toIntArray(ids))));
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
    }

    @Log(title = "修改启用停用状态", operating = "修改状态", action = BusinessType.FORCE)
    @PostMapping("/updateStatus")
    @ResponseBody
    public AjaxResult updateStatus(@RequestParam("ids[]") String[] ids,int status)
    {
        LambdaQueryWrapper<PlcEquipment> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.in(StringUtils.isNotEmpty(ids),PlcEquipment::getId,ids);
        PlcEquipment plcEquipment=new PlcEquipment();
        plcEquipment.setStatus(status);
        plcEquipment.setUpdateTime(new Date());
        plcEquipment.setUpdateBy(ShiroUtils.getLoginName());
        equipmentService.update(plcEquipment,lambdaQueryWrapper);
        return success();
    }
}