Prechádzať zdrojové kódy

新增固定资产菜单

Sun 3 rokov pred
rodič
commit
e61609741f

+ 110 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/anpin/TAssetsController.java

@@ -0,0 +1,110 @@
+package com.ruoyi.web.controller.anpin;
+
+import java.util.List;
+
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.anpin.domain.TAssets;
+import com.ruoyi.anpin.service.ITAssetsService;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.common.core.page.TableDataInfo;
+import org.springframework.web.multipart.MultipartFile;
+
+/**
+ * 资产管理Controller
+ *
+ * @author ruoyi
+ * @date 2022-01-24
+ */
+@RestController
+@RequestMapping("/anpin/assets")
+public class TAssetsController extends BaseController {
+    @Autowired
+    private ITAssetsService tAssetsService;
+
+    /**
+     * 查询资产管理列表
+     */
+    @PreAuthorize("@ss.hasPermi('warehouse:assets:list')")
+    @GetMapping("/list")
+    public TableDataInfo list(TAssets tAssets) {
+        startPage();
+        List<TAssets> list = tAssetsService.selectTAssetsList(tAssets);
+        return getDataTable(list);
+    }
+
+    /**
+     * 下载资产导入模板
+     */
+    @PreAuthorize("@ss.hasPermi('warehouse:assets:add')")
+    @GetMapping("/template")
+    public AjaxResult template() {
+        ExcelUtil<TAssets> util = new ExcelUtil<>(TAssets.class);
+        return util.importTemplateExcel("资产导入模板");
+    }
+
+    /**
+     * 导入资产管理列表
+     */
+    @PreAuthorize("@ss.hasPermi('warehouse:assets:add')")
+    @PostMapping(value = "/import")
+    public AjaxResult importAssets(@RequestParam("file") MultipartFile file) {
+        return tAssetsService.importAssets(file);
+    }
+
+    /**
+     * 导出资产管理列表
+     */
+    @PreAuthorize("@ss.hasPermi('warehouse:assets:export')")
+    @Log(title = "资产管理", businessType = BusinessType.EXPORT)
+    @GetMapping("/export")
+    public AjaxResult export(TAssets tAssets) {
+        List<TAssets> list = tAssetsService.selectTAssetsList(tAssets);
+        ExcelUtil<TAssets> util = new ExcelUtil<>(TAssets.class);
+        return util.exportExcel(list, "资产管理列表");
+    }
+
+    /**
+     * 获取资产管理详细信息
+     */
+    @PreAuthorize("@ss.hasPermi('warehouse:assets:query')")
+    @GetMapping(value = "/{fId}")
+    public AjaxResult getInfo(@PathVariable("fId") Long fId) {
+        return AjaxResult.success(tAssetsService.selectTAssetsById(fId));
+    }
+
+    /**
+     * 新增资产管理
+     */
+    @PreAuthorize("@ss.hasPermi('warehouse:assets:add')")
+    @Log(title = "资产管理", businessType = BusinessType.INSERT)
+    @PostMapping
+    public AjaxResult add(@RequestBody TAssets tAssets) {
+        return toAjax(tAssetsService.insertTAssets(tAssets));
+    }
+
+    /**
+     * 修改资产管理
+     */
+    @PreAuthorize("@ss.hasPermi('warehouse:assets:edit')")
+    @Log(title = "资产管理", businessType = BusinessType.UPDATE)
+    @PutMapping
+    public AjaxResult edit(@RequestBody TAssets tAssets) {
+        return toAjax(tAssetsService.updateTAssets(tAssets));
+    }
+
+    /**
+     * 删除资产管理
+     */
+    @PreAuthorize("@ss.hasPermi('warehouse:assets:remove')")
+    @Log(title = "资产管理", businessType = BusinessType.DELETE)
+    @DeleteMapping("/{fIds}")
+    public AjaxResult remove(@PathVariable Long[] fIds) {
+        return toAjax(tAssetsService.deleteTAssetsByIds(fIds));
+    }
+}

+ 162 - 0
ruoyi-anpin/src/main/java/com/ruoyi/anpin/domain/TAssets.java

@@ -0,0 +1,162 @@
+package com.ruoyi.anpin.domain;
+
+import java.math.BigDecimal;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+import com.ruoyi.common.annotation.Excel;
+import com.ruoyi.common.core.domain.BaseEntity;
+
+/**
+ * 资产管理对象 t_assets
+ *
+ * @author ruoyi
+ * @date 2022-01-24
+ */
+public class TAssets extends BaseEntity {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * $column.columnComment
+     */
+    private Long fId;
+
+    /**
+     * 部门
+     */
+    @Excel(name = "部门")
+    private String fDept;
+
+    /**
+     * 名称
+     */
+    @Excel(name = "名称")
+    private String fName;
+
+    /**
+     * 规格
+     */
+    @Excel(name = "规格")
+    private String fSpec;
+
+    /**
+     * 单位
+     */
+    @Excel(name = "单位")
+    private String fUnit;
+
+    /**
+     * 数量
+     */
+    @Excel(name = "数量")
+    private Long fNumber;
+
+    /**
+     * 金额
+     */
+    @Excel(name = "金额")
+    private BigDecimal fAmount;
+
+    /**
+     * 图片
+     */
+    private String fImage;
+
+    /**
+     * 资产编码
+     */
+    @Excel(name = "资产编码")
+    private String fCode;
+
+    public void setfId(Long fId) {
+        this.fId = fId;
+    }
+
+    public Long getfId() {
+        return fId;
+    }
+
+    public void setfDept(String fDept) {
+        this.fDept = fDept;
+    }
+
+    public String getfDept() {
+        return fDept;
+    }
+
+    public void setfName(String fName) {
+        this.fName = fName;
+    }
+
+    public String getfName() {
+        return fName;
+    }
+
+    public void setfSpec(String fSpec) {
+        this.fSpec = fSpec;
+    }
+
+    public String getfSpec() {
+        return fSpec;
+    }
+
+    public void setfUnit(String fUnit) {
+        this.fUnit = fUnit;
+    }
+
+    public String getfUnit() {
+        return fUnit;
+    }
+
+    public void setfNumber(Long fNumber) {
+        this.fNumber = fNumber;
+    }
+
+    public Long getfNumber() {
+        return fNumber;
+    }
+
+    public void setfAmount(BigDecimal fAmount) {
+        this.fAmount = fAmount;
+    }
+
+    public BigDecimal getfAmount() {
+        return fAmount;
+    }
+
+    public void setfImage(String fImage) {
+        this.fImage = fImage;
+    }
+
+    public String getfImage() {
+        return fImage;
+    }
+
+    public void setfCode(String fCode) {
+        this.fCode = fCode;
+    }
+
+    public String getfCode() {
+        return fCode;
+    }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
+                .append("fId", getfId())
+                .append("fDept", getfDept())
+                .append("fName", getfName())
+                .append("fSpec", getfSpec())
+                .append("fUnit", getfUnit())
+                .append("fNumber", getfNumber())
+                .append("fAmount", getfAmount())
+                .append("fImage", getfImage())
+                .append("remark", getRemark())
+                .append("fCode", getfCode())
+                .append("createBy", getCreateBy())
+                .append("createTime", getCreateTime())
+                .append("updateBy", getUpdateBy())
+                .append("updateTime", getUpdateTime())
+                .toString();
+    }
+}

+ 63 - 0
ruoyi-anpin/src/main/java/com/ruoyi/anpin/mapper/TAssetsMapper.java

@@ -0,0 +1,63 @@
+package com.ruoyi.anpin.mapper;
+
+import java.util.List;
+
+import com.ruoyi.anpin.domain.TAssets;
+import com.ruoyi.common.core.domain.AjaxResult;
+import org.springframework.web.multipart.MultipartFile;
+
+/**
+ * 资产管理Mapper接口
+ *
+ * @author ruoyi
+ * @date 2022-01-24
+ */
+public interface TAssetsMapper {
+    /**
+     * 查询资产管理
+     *
+     * @param fId 资产管理ID
+     * @return 资产管理
+     */
+    public TAssets selectTAssetsById(Long fId);
+
+    /**
+     * 查询资产管理列表
+     *
+     * @param tAssets 资产管理
+     * @return 资产管理集合
+     */
+    public List<TAssets> selectTAssetsList(TAssets tAssets);
+
+    /**
+     * 新增资产管理
+     *
+     * @param tAssets 资产管理
+     * @return 结果
+     */
+    public int insertTAssets(TAssets tAssets);
+
+    /**
+     * 修改资产管理
+     *
+     * @param tAssets 资产管理
+     * @return 结果
+     */
+    public int updateTAssets(TAssets tAssets);
+
+    /**
+     * 删除资产管理
+     *
+     * @param fId 资产管理ID
+     * @return 结果
+     */
+    public int deleteTAssetsById(Long fId);
+
+    /**
+     * 批量删除资产管理
+     *
+     * @param fIds 需要删除的数据ID
+     * @return 结果
+     */
+    public int deleteTAssetsByIds(Long[] fIds);
+}

+ 71 - 0
ruoyi-anpin/src/main/java/com/ruoyi/anpin/service/ITAssetsService.java

@@ -0,0 +1,71 @@
+package com.ruoyi.anpin.service;
+
+import java.util.List;
+
+import com.ruoyi.anpin.domain.TAssets;
+import com.ruoyi.common.core.domain.AjaxResult;
+import org.springframework.web.multipart.MultipartFile;
+
+/**
+ * 资产管理Service接口
+ *
+ * @author ruoyi
+ * @date 2022-01-24
+ */
+public interface ITAssetsService {
+    /**
+     * 查询资产管理
+     *
+     * @param fId 资产管理ID
+     * @return 资产管理
+     */
+    public TAssets selectTAssetsById(Long fId);
+
+    /**
+     * 查询资产管理列表
+     *
+     * @param tAssets 资产管理
+     * @return 资产管理集合
+     */
+    public List<TAssets> selectTAssetsList(TAssets tAssets);
+
+    /**
+     * 新增资产管理
+     *
+     * @param tAssets 资产管理
+     * @return 结果
+     */
+    public int insertTAssets(TAssets tAssets);
+
+    /**
+     * 修改资产管理
+     *
+     * @param tAssets 资产管理
+     * @return 结果
+     */
+    public int updateTAssets(TAssets tAssets);
+
+    /**
+     * 批量删除资产管理
+     *
+     * @param fIds 需要删除的资产管理ID
+     * @return 结果
+     */
+    public int deleteTAssetsByIds(Long[] fIds);
+
+    /**
+     * 删除资产管理信息
+     *
+     * @param fId 资产管理ID
+     * @return 结果
+     */
+    public int deleteTAssetsById(Long fId);
+
+    /**
+     * 导入资产管理列表
+     *
+     * @param file 文件
+     * @return 结果
+     */
+    public AjaxResult importAssets(MultipartFile file);
+}

+ 202 - 0
ruoyi-anpin/src/main/java/com/ruoyi/anpin/service/impl/TAssetsServiceImpl.java

@@ -0,0 +1,202 @@
+package com.ruoyi.anpin.service.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.warehouseBusiness.domain.TWarehousebillsitems;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.util.CellReference;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import com.ruoyi.anpin.mapper.TAssetsMapper;
+import com.ruoyi.anpin.domain.TAssets;
+import com.ruoyi.anpin.service.ITAssetsService;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
+
+import static com.ruoyi.common.utils.poi.Excel.filter;
+
+/**
+ * 资产管理Service业务层处理
+ *
+ * @author ruoyi
+ * @date 2022-01-24
+ */
+@Service
+public class TAssetsServiceImpl implements ITAssetsService {
+    @Autowired
+    private TAssetsMapper tAssetsMapper;
+
+    /**
+     * 查询资产管理
+     *
+     * @param fId 资产管理ID
+     * @return 资产管理
+     */
+    @Override
+    public TAssets selectTAssetsById(Long fId) {
+        return tAssetsMapper.selectTAssetsById(fId);
+    }
+
+    /**
+     * 查询资产管理列表
+     *
+     * @param tAssets 资产管理
+     * @return 资产管理
+     */
+    @Override
+    public List<TAssets> selectTAssetsList(TAssets tAssets) {
+        return tAssetsMapper.selectTAssetsList(tAssets);
+    }
+
+    /**
+     * 新增资产管理
+     *
+     * @param tAssets 资产管理
+     * @return 结果
+     */
+    @Override
+    public int insertTAssets(TAssets tAssets) {
+        tAssets.setCreateTime(DateUtils.getNowDate());
+        return tAssetsMapper.insertTAssets(tAssets);
+    }
+
+    /**
+     * 修改资产管理
+     *
+     * @param tAssets 资产管理
+     * @return 结果
+     */
+    @Override
+    public int updateTAssets(TAssets tAssets) {
+        tAssets.setUpdateTime(DateUtils.getNowDate());
+        return tAssetsMapper.updateTAssets(tAssets);
+    }
+
+    /**
+     * 批量删除资产管理
+     *
+     * @param fIds 需要删除的资产管理ID
+     * @return 结果
+     */
+    @Override
+    public int deleteTAssetsByIds(Long[] fIds) {
+        return tAssetsMapper.deleteTAssetsByIds(fIds);
+    }
+
+    /**
+     * 删除资产管理信息
+     *
+     * @param fId 资产管理ID
+     * @return 结果
+     */
+    @Override
+    public int deleteTAssetsById(Long fId) {
+        return tAssetsMapper.deleteTAssetsById(fId);
+    }
+
+    /**
+     * 导入资产管理列表
+     *
+     * @param file 文件
+     * @return 结果
+     */
+    @Transactional
+    @Override
+    public AjaxResult importAssets(MultipartFile file) {
+        InputStream inputStream;
+        try {
+            inputStream = file.getInputStream();
+            String originalFilename = file.getOriginalFilename();
+            Workbook workbook;
+            if (originalFilename.endsWith("xls")) {
+                workbook = WorkbookFactory.create(inputStream);
+            } else if (originalFilename.endsWith("xlsx")) {
+                workbook = new XSSFWorkbook(inputStream);
+            } else {
+                return AjaxResult.error("文件后缀异常");
+            }
+            Sheet sheet = workbook.getSheetAt(0);
+            for (Row rows : sheet) {
+                if (rows.getRowNum() == 0) {
+                    continue;
+                }
+                TAssets assets = new TAssets();
+                for (int a = 0; a < rows.getPhysicalNumberOfCells(); a++) {
+                    if (StringUtils.isNull(rows.getCell(a))) {
+                        continue;
+                    }
+                    Cell cell = rows.getCell(a);
+                    String value = filter(sheet.getRow(0), CellReference.convertNumToColString(cell.getColumnIndex()));
+                    switch (value) {
+                        case "部门":
+                            // 设置单元格类型
+                            cell.setCellType(CellType.STRING);
+                            if (StringUtils.isNotEmpty(cell.getStringCellValue())) {
+                                assets.setfDept(cell.getStringCellValue());
+                            }
+                            break;
+                        case "名称":
+                            // 设置单元格类型
+                            cell.setCellType(CellType.STRING);
+                            if (StringUtils.isNotEmpty(cell.getStringCellValue())) {
+                                assets.setfName(cell.getStringCellValue());
+                            }
+                            break;
+                        case "规格":
+                            // 设置单元格类型
+                            cell.setCellType(CellType.STRING);
+                            if (StringUtils.isNotEmpty(cell.getStringCellValue())) {
+                                assets.setfSpec(cell.getStringCellValue());
+                            }
+                            break;
+                        case "单位":
+                            // 设置单元格类型
+                            cell.setCellType(CellType.STRING);
+                            if (StringUtils.isNotEmpty(cell.getStringCellValue())) {
+                                assets.setfUnit(cell.getStringCellValue());
+                            }
+                            break;
+                        case "数量":
+                            // 设置单元格类型
+                            cell.setCellType(CellType.STRING);
+                            if (StringUtils.isNotEmpty(cell.getStringCellValue())) {
+                                assets.setfNumber(Long.valueOf(cell.getStringCellValue()));
+                            }
+                            break;
+                        case "金额":
+                            // 设置单元格类型
+                            cell.setCellType(CellType.STRING);
+                            if (StringUtils.isNotEmpty(cell.getStringCellValue())) {
+                                assets.setfAmount(new BigDecimal(cell.getStringCellValue()).setScale(2, RoundingMode.HALF_UP));
+                            }
+                            break;
+                        case "资产编码":
+                            // 设置单元格类型
+                            cell.setCellType(CellType.STRING);
+                            if (StringUtils.isNotEmpty(cell.getStringCellValue())) {
+                                assets.setfCode(cell.getStringCellValue());
+                            }
+                            break;
+                        default:
+                            break;
+                    }
+                }
+                assets.setfImage("[]");
+                tAssetsMapper.insertTAssets(assets);
+            }
+        } catch (IOException e) {
+            return AjaxResult.error("上传文件失败,请检查文件是否损坏");
+        }
+
+        return AjaxResult.success();
+    }
+}

+ 128 - 0
ruoyi-anpin/src/main/resources/mapper/anpin/TAssetsMapper.xml

@@ -0,0 +1,128 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ruoyi.anpin.mapper.TAssetsMapper">
+
+    <resultMap type="TAssets" id="TAssetsResult">
+        <result property="fId" column="f_id"/>
+        <result property="fDept" column="f_dept"/>
+        <result property="fName" column="f_name"/>
+        <result property="fSpec" column="f_spec"/>
+        <result property="fUnit" column="f_unit"/>
+        <result property="fNumber" column="f_number"/>
+        <result property="fAmount" column="f_amount"/>
+        <result property="fImage" column="f_image"/>
+        <result property="remark" column="remark"/>
+        <result property="fCode" column="f_code"/>
+        <result property="createBy" column="create_by"/>
+        <result property="createTime" column="create_time"/>
+        <result property="updateBy" column="update_by"/>
+        <result property="updateTime" column="update_time"/>
+    </resultMap>
+
+    <sql id="selectTAssetsVo">
+        select f_id,
+               f_dept,
+               f_name,
+               f_spec,
+               f_unit,
+               f_number,
+               f_amount,
+               f_image,
+               remark,
+               f_code,
+               create_by,
+               create_time,
+               update_by,
+               update_time
+        from t_assets
+    </sql>
+
+    <select id="selectTAssetsList" parameterType="TAssets" resultMap="TAssetsResult">
+        <include refid="selectTAssetsVo"/>
+        <where>
+            <if test="fDept != null  and fDept != ''">and f_dept = #{fDept}</if>
+            <if test="fName != null  and fName != ''">and f_name like concat('%', #{fName}, '%')</if>
+            <if test="fSpec != null  and fSpec != ''">and f_spec = #{fSpec}</if>
+            <if test="fUnit != null  and fUnit != ''">and f_unit = #{fUnit}</if>
+            <if test="fNumber != null ">and f_number = #{fNumber}</if>
+            <if test="fAmount != null ">and f_amount = #{fAmount}</if>
+            <if test="fImage != null  and fImage != ''">and f_image = #{fImage}</if>
+            <if test="fCode != null  and fCode != ''">and f_code = #{fCode}</if>
+        </where>
+    </select>
+
+    <select id="selectTAssetsById" parameterType="Long" resultMap="TAssetsResult">
+        <include refid="selectTAssetsVo"/>
+        where f_id = #{fId}
+    </select>
+
+    <insert id="insertTAssets" parameterType="TAssets" useGeneratedKeys="true" keyProperty="fId">
+        insert into t_assets
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="fDept != null">f_dept,</if>
+            <if test="fName != null">f_name,</if>
+            <if test="fSpec != null">f_spec,</if>
+            <if test="fUnit != null">f_unit,</if>
+            <if test="fNumber != null">f_number,</if>
+            <if test="fAmount != null">f_amount,</if>
+            <if test="fImage != null">f_image,</if>
+            <if test="remark != null">remark,</if>
+            <if test="fCode != null">f_code,</if>
+            <if test="createBy != null">create_by,</if>
+            <if test="createTime != null">create_time,</if>
+            <if test="updateBy != null">update_by,</if>
+            <if test="updateTime != null">update_time,</if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="fDept != null">#{fDept},</if>
+            <if test="fName != null">#{fName},</if>
+            <if test="fSpec != null">#{fSpec},</if>
+            <if test="fUnit != null">#{fUnit},</if>
+            <if test="fNumber != null">#{fNumber},</if>
+            <if test="fAmount != null">#{fAmount},</if>
+            <if test="fImage != null">#{fImage},</if>
+            <if test="remark != null">#{remark},</if>
+            <if test="fCode != null">#{fCode},</if>
+            <if test="createBy != null">#{createBy},</if>
+            <if test="createTime != null">#{createTime},</if>
+            <if test="updateBy != null">#{updateBy},</if>
+            <if test="updateTime != null">#{updateTime},</if>
+        </trim>
+    </insert>
+
+    <update id="updateTAssets" parameterType="TAssets">
+        update t_assets
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="fDept != null">f_dept = #{fDept},</if>
+            <if test="fName != null">f_name = #{fName},</if>
+            <if test="fSpec != null">f_spec = #{fSpec},</if>
+            <if test="fUnit != null">f_unit = #{fUnit},</if>
+            <if test="fNumber != null">f_number = #{fNumber},</if>
+            <if test="fAmount != null">f_amount = #{fAmount},</if>
+            <if test="fImage != null">f_image = #{fImage},</if>
+            <if test="remark != null">remark = #{remark},</if>
+            <if test="fCode != null">f_code = #{fCode},</if>
+            <if test="createBy != null">create_by = #{createBy},</if>
+            <if test="createTime != null">create_time = #{createTime},</if>
+            <if test="updateBy != null">update_by = #{updateBy},</if>
+            <if test="updateTime != null">update_time = #{updateTime},</if>
+        </trim>
+        where f_id = #{fId}
+    </update>
+
+    <delete id="deleteTAssetsById" parameterType="Long">
+        delete
+        from t_assets
+        where f_id = #{fId}
+    </delete>
+
+    <delete id="deleteTAssetsByIds" parameterType="String">
+        delete from t_assets where f_id in
+        <foreach item="fId" collection="array" open="(" separator="," close=")">
+            #{fId}
+        </foreach>
+    </delete>
+
+</mapper>