TSpecdevFixedAssetController.java 10 KB

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