TSpecdevFixedAssetController.java 10 KB

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