TSpecdevFixedAssetController.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. package com.ruoyi.project.asset.controller;
  2. import com.alibaba.fastjson2.JSON;
  3. import com.ruoyi.common.annotation.Log;
  4. import com.ruoyi.common.core.controller.BaseController;
  5. import com.ruoyi.common.core.domain.AjaxResult;
  6. import com.ruoyi.common.core.domain.entity.SysDictData;
  7. import com.ruoyi.common.core.page.TableDataInfo;
  8. import com.ruoyi.common.enums.BusinessType;
  9. import com.ruoyi.common.utils.file.ExcelUtils;
  10. import com.ruoyi.common.utils.poi.ExcelUtil;
  11. import com.ruoyi.project.asset.domain.TSpecdevFixedAsset;
  12. import com.ruoyi.project.asset.service.ITSpecdevFixedAssetService;
  13. import com.ruoyi.system.service.ISysDictTypeService;
  14. import org.apache.poi.ss.usermodel.Cell;
  15. import org.apache.poi.ss.usermodel.Row;
  16. import org.apache.poi.ss.usermodel.Sheet;
  17. import org.apache.poi.ss.usermodel.Workbook;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.security.access.prepost.PreAuthorize;
  20. import org.springframework.web.bind.annotation.*;
  21. import org.springframework.web.multipart.MultipartFile;
  22. import java.io.IOException;
  23. import java.text.SimpleDateFormat;
  24. import java.util.ArrayList;
  25. import java.util.List;
  26. /**
  27. * 固定资产Controller
  28. *
  29. * @author ruoyi
  30. * @date 2022-10-18
  31. */
  32. @RestController
  33. @RequestMapping("/sems/fixedAsset")
  34. public class TSpecdevFixedAssetController extends BaseController
  35. {
  36. @Autowired
  37. private ITSpecdevFixedAssetService tSpecdevFixedAssetService;
  38. @Autowired
  39. private ISysDictTypeService iSysDictTypeService;
  40. /**
  41. * 查询固定资产列表
  42. */
  43. @PreAuthorize("@ss.hasPermi('sems:fixedAsset:list')")
  44. @GetMapping("/list")
  45. public TableDataInfo list(TSpecdevFixedAsset tSpecdevFixedAsset)
  46. {
  47. startPage();
  48. List<TSpecdevFixedAsset> list = tSpecdevFixedAssetService.selectTSpecdevFixedAssetList(tSpecdevFixedAsset);
  49. return getDataTable(list);
  50. }
  51. /**
  52. * 导出固定资产列表
  53. */
  54. @PreAuthorize("@ss.hasPermi('sems:fixedAsset:export')")
  55. @Log(title = "固定资产", businessType = BusinessType.EXPORT)
  56. @GetMapping("/export")
  57. public AjaxResult export(TSpecdevFixedAsset tSpecdevFixedAsset)
  58. {
  59. List<TSpecdevFixedAsset> list = tSpecdevFixedAssetService.selectTSpecdevFixedAssetList(tSpecdevFixedAsset);
  60. ExcelUtil<TSpecdevFixedAsset> util = new ExcelUtil<TSpecdevFixedAsset>(TSpecdevFixedAsset.class);
  61. return util.exportExcel(list, "asset");
  62. }
  63. /**
  64. * 获取固定资产详细信息
  65. */
  66. @PreAuthorize("@ss.hasPermi('sems:fixedAsset:query')")
  67. @GetMapping(value = "/{id}")
  68. public AjaxResult getInfo(@PathVariable("id") Long id)
  69. {
  70. return AjaxResult.success(tSpecdevFixedAssetService.selectTSpecdevFixedAssetById(id));
  71. }
  72. /**
  73. * 新增固定资产
  74. */
  75. @PreAuthorize("@ss.hasPermi('sems:fixedAsset:add')")
  76. @Log(title = "固定资产", businessType = BusinessType.INSERT)
  77. @PostMapping
  78. public AjaxResult add(@RequestBody TSpecdevFixedAsset tSpecdevFixedAsset)
  79. {
  80. return toAjax(tSpecdevFixedAssetService.insertTSpecdevFixedAsset(tSpecdevFixedAsset));
  81. }
  82. /**
  83. * 修改固定资产
  84. */
  85. @PreAuthorize("@ss.hasPermi('sems:fixedAsset:edit')")
  86. @Log(title = "固定资产", businessType = BusinessType.UPDATE)
  87. @PutMapping
  88. public AjaxResult edit(@RequestBody TSpecdevFixedAsset tSpecdevFixedAsset)
  89. {
  90. return toAjax(tSpecdevFixedAssetService.updateTSpecdevFixedAsset(tSpecdevFixedAsset));
  91. }
  92. /**
  93. * 删除固定资产
  94. */
  95. @PreAuthorize("@ss.hasPermi('sems:fixedAsset:remove')")
  96. @Log(title = "固定资产", businessType = BusinessType.DELETE)
  97. @DeleteMapping("/{ids}")
  98. public AjaxResult remove(@PathVariable Long[] ids)
  99. {
  100. return toAjax(tSpecdevFixedAssetService.deleteTSpecdevFixedAssetByIds(ids));
  101. }
  102. @Log(title = "固定资产清单批量导入", businessType = BusinessType.INSERT)
  103. @PostMapping("/importData")
  104. public AjaxResult importData(@RequestParam("file") MultipartFile file) throws IOException {
  105. //获取操作人员ID
  106. Long userId = getUserId();
  107. //报错行数统计
  108. List<Integer> failRow = new ArrayList<>();
  109. Workbook workbook = ExcelUtils.getWorkBook(file);
  110. Sheet sheet = workbook.getSheetAt(0);
  111. List<TSpecdevFixedAsset> list = new ArrayList<>();
  112. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  113. //字典查询
  114. List<SysDictData> usingStatus = iSysDictTypeService.selectDictDataByType("spec_dev_status");
  115. int rowNum = sheet.getPhysicalNumberOfRows();
  116. int failNumber = 0;
  117. for (int i = 2; i < rowNum; i++) {
  118. try {
  119. logger.info("读取行数:" + i);
  120. Row row = sheet.getRow(i);
  121. int cellNum = row.getLastCellNum();
  122. TSpecdevFixedAsset entity = new TSpecdevFixedAsset();
  123. for (int j = 0; j < cellNum; j++) {
  124. Cell cell = row.getCell(j);
  125. if (cell == null) {
  126. continue;
  127. }
  128. String cellValue = ExcelUtils.getCellValue(cell);
  129. logger.info("cellValue:" + cellValue);
  130. if (j == 0) {
  131. //资产类别
  132. entity.setAssetType(cellValue);
  133. } else if (j == 1) {
  134. //资产编号
  135. entity.setAssetNo(cellValue);
  136. } else if (j == 2) {
  137. //资产子编号
  138. entity.setAssetSubNo(cellValue);
  139. } else if (j == 3) {
  140. //资产描述(中文)
  141. entity.setDevName(cellValue);
  142. } else if (j == 4) {
  143. //资产描述(英文)
  144. entity.setDevEnname(cellValue);
  145. } else if (j == 5) {
  146. //成本中心名称
  147. entity.setCostCenter(cellValue);
  148. } else if (j == 6) {
  149. //成本中心代码
  150. entity.setCostCenterCode(cellValue);
  151. } else if (j == 7) {
  152. //资产类别ap003xxx
  153. entity.setAssetTypeAp(cellValue);
  154. } else if (j == 8) {
  155. //资本化日期
  156. entity.setCapitalizedDate(sdf.parse(cellValue));
  157. } else if (j == 9) {
  158. //数量
  159. entity.setQuantity(cellValue);
  160. } else if (j == 10) {
  161. //币种
  162. entity.setCurrency(cellValue);
  163. } else if (j == 11) {
  164. //原值
  165. entity.setCurrentApc(cellValue);
  166. } else if (j == 12) {
  167. //使用年限
  168. entity.setServiceLife(cellValue);
  169. } else if (j == 13) {
  170. //管理人
  171. entity.setAdministrator(cellValue);
  172. } else if (j == 14) {
  173. //位号
  174. entity.setDevNo(cellValue);
  175. } else if (j == 15) {
  176. //资产详细描述
  177. entity.setAssetDetail(cellValue);
  178. } else if (j == 16) {
  179. //工艺子单元
  180. entity.setProcessSubunit(cellValue);
  181. } else if (j == 17) {
  182. //pid图号/其他图号
  183. entity.setPidNo(cellValue);
  184. } else if (j == 18) {
  185. //安装位置
  186. entity.setInstallPosition(cellValue);
  187. } else if (j == 19) {
  188. //创建原由
  189. entity.setCreateReason(cellValue);
  190. } else if (j == 20) {
  191. //条形码位置
  192. entity.setBarcodePosition(cellValue);
  193. } else if (j == 21) {
  194. //报废原由
  195. entity.setScrapReason(cellValue);
  196. } else if (j == 22) {
  197. //报废提出日期
  198. entity.setScrapPoseDate(sdf.parse(cellValue));
  199. } else if (j == 23) {
  200. //报废完成时间
  201. entity.setScrapDoneDate(sdf.parse(cellValue));
  202. } else if (j == 24) {
  203. //报废人
  204. entity.setScraper(cellValue);
  205. } else if (j == 25) {
  206. //在用状态
  207. for (SysDictData dictData : usingStatus) {
  208. if (dictData.getDictLabel().equals(cellValue.trim())) {
  209. entity.setUsingStatus(dictData.getDictValue());
  210. }
  211. }
  212. } else if (j == 26) {
  213. //备注
  214. entity.setRemarks(cellValue);
  215. }
  216. }
  217. entity.setCreaterCode(userId);
  218. logger.info("entity:" + entity);
  219. list.add(entity);
  220. } catch (Exception e) {
  221. failNumber++;
  222. logger.info("e:" + JSON.toJSONString(e));
  223. failRow.add(i + 1);
  224. }
  225. }
  226. int successNumber = 0;
  227. int failNum = 0;
  228. for (TSpecdevFixedAsset t : list
  229. ) {
  230. failNum++;
  231. try {
  232. //根据使用证、注册编号、位号,进行数据更新
  233. add(t);
  234. successNumber++;
  235. } catch (Exception e) {
  236. failNumber++;
  237. logger.info("e:" + e);
  238. failRow.add(failNum + 1);
  239. }
  240. }
  241. logger.info("list:" + JSON.toJSONString(list));
  242. logger.info("successNumber:" + String.valueOf(successNumber));
  243. logger.info("failNumber:" + String.valueOf(failNumber));
  244. logger.info("failRow:" + String.valueOf(failRow));
  245. return AjaxResult.success(String.valueOf(successNumber), failRow);
  246. }
  247. }