package com.zbooksoft.gdmis.operate; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ruili.wcp.common.SpringContextUtil; import com.ruili.wcp.data.entity.config.Module; import com.ruili.wcp.data.entity.config.View; import com.ruili.wcp.data.entity.management.User; import com.ruili.wcp.engine.form.IFormData; import com.ruili.wcp.service.config.ModuleService; import com.ruili.wcp.service.config.ViewService; import com.ruili.wcp.web.model.AjaxResponse; import com.ruili.wcp.web.model.ErrorInfo; import com.zbooksoft.gdmis.data.entity.BorrowDetail; import com.zbooksoft.gdmis.data.entity.CatAjjxx; import com.zbooksoft.gdmis.data.entity.PhysicalDetail; import com.zbooksoft.gdmis.service.*; import org.apache.shiro.SecurityUtils; import org.apache.shiro.session.Session; import org.apache.shiro.subject.Subject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.jdbc.core.BatchPreparedStatementSetter; import org.springframework.jdbc.core.JdbcTemplate; import java.sql.PreparedStatement; import java.sql.SQLException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; /** * @Description:地质资料基本信息操作方法 * @Author: zhai * @Date: 2024/8/15 **/ public class CatAjjxxOperate { private static final Logger logger = LoggerFactory.getLogger(CatAjjxxOperate.class); ViewService viewService = (ViewService) SpringContextUtil.getBean("viewServiceImpl"); BorrowDetailService borrowDetailService = (BorrowDetailService) SpringContextUtil.getBean("borrowDetailServiceImpl"); CatAjjxxService catAjjxxService = (CatAjjxxService) SpringContextUtil.getBean("catAjjxxServiceImpl"); PhysicalDetailService physicalDetailService = (PhysicalDetailService) SpringContextUtil.getBean("physicalDetailServiceImpl"); ModuleService moduleService = (ModuleService) SpringContextUtil.getBean("moduleServiceImpl"); JdbcTemplate jdbcTemplate = (JdbcTemplate) SpringContextUtil.getBean("jdbcTemplate"); IFormData iform = (IFormData) SpringContextUtil.getBean("iFormData"); /** * 发布 * * @param viewId * @param idList * @return */ public AjaxResponse release(Long viewId, ArrayList idList) { try { LocalDateTime now = LocalDateTime.now(); // 创建 DateTimeFormatter 对象,指定日期格式 blankTape DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); // 格式化日期 String formattedDate = now.format(formatter); View view = viewService.getViewById(viewId); String strSql = "update " + view.getMainTableName() + " set fbzt = 1 "; jdbcTemplate.batchUpdate(strSql + " where " + view.getIdField() + "=?", new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setLong(1, idList.get(i));// 下标从1开始 } @Override public int getBatchSize() { return idList.size(); } }); return new AjaxResponse(true); } catch (Exception e) { logger.error(e.getMessage(), e); return new AjaxResponse(new ErrorInfo(e.getMessage()), false); } } /** * 取消发布 * * @param viewId * @param idList * @return */ public AjaxResponse cancelRelease(Long viewId, ArrayList idList) { try { int state = 0; String columnName = "fbzt"; updateState(viewId, idList, state, columnName); return new AjaxResponse(true); } catch (Exception e) { logger.error(e.getMessage(), e); return new AjaxResponse(new ErrorInfo(e.getMessage()), false); } } /** * 取消发布 * * @param viewId * @param idList * @return */ public AjaxResponse warehousing(Long viewId, ArrayList idList) { try { int state = 1; String columnName = "zlzt"; updateState(viewId, idList, state, columnName); return new AjaxResponse(true); } catch (Exception e) { logger.error(e.getMessage(), e); return new AjaxResponse(new ErrorInfo(e.getMessage()), false); } } public void updateState(Long viewId, ArrayList idList, Integer state, String columnName) { View view = viewService.getViewById(viewId); String strSql = "update " + view.getMainTableName() + " set " + columnName + " = " + state; jdbcTemplate.batchUpdate(strSql + " where " + view.getIdField() + "=?", new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setLong(1, idList.get(i));// 下标从1开始 } @Override public int getBatchSize() { return idList.size(); } }); } /** * 添加档案利用 * * @param viewId * @param idList * @return */ public AjaxResponse addUtilization(Long viewId, ArrayList idList) { try { View view = viewService.getViewById(viewId); AjaxResponse ajaxResponse = addUtilizationByModuleId(view.getModuleId(), idList); return ajaxResponse; } catch (Exception e) { logger.error(e.getMessage(), e); return new AjaxResponse(new ErrorInfo(e.getMessage()), false); } } /** * 添加档案利用 * * @param viewId * @param idList * @return */ public AjaxResponse addUtilizationAll(Long viewId, ArrayList idList) { try { AjaxResponse ajaxResponse = addUtilizationByAll(idList); return ajaxResponse; } catch (Exception e) { logger.error(e.getMessage(), e); return new AjaxResponse(new ErrorInfo(e.getMessage()), false); } } /** * 通过moduleid添加档案利用 */ public AjaxResponse addUtilizationByModuleId(Long moduleId, List idList) { try { Module module = moduleService.getByIdModule(moduleId); QueryWrapper moduleQueryWrapper = new QueryWrapper<>(); moduleQueryWrapper.eq("module_id", module.getParentId()); moduleQueryWrapper.ne("parent_id", 0); List moduleList = moduleService.list(moduleQueryWrapper); AjaxResponse ajaxResponse = new AjaxResponse(true); Map resultMap = new HashMap(); if (moduleList.size() == 0) { // 案卷级利用 resultMap = addUtilizationForFile(idList); } else if (moduleList.size() > 0) { // 文件级利用,需要反查案卷级信息 resultMap = addUtilizationForItem(module, idList); } // String unit = resultMap.get("unit").toString().equals("卷") ? "0" : "1"; String unit = "0"; if (resultMap != null) { StringBuilder sb = new StringBuilder(); sb.append("top.layer.open({"); sb.append(" title : '提示',"); sb.append(" type : 2,"); sb.append(" area : [ '700px', '220px' ],"); sb.append(" fixed : true, "); sb.append(" content : 'common/commonTips?addNum=" + resultMap.get("addNum") + "&type=借阅&repeatNum=" + resultMap.get("repeatNum") + "&existFileNum=" + resultMap.get("existFileNum") + "&existItemNum=" + resultMap.get("existItemNum") + "&urlPath=borrow'"); sb.append("});"); Map result = new HashMap(); result.put("jsExpression", sb.toString()); result.put("totalNum", resultMap.get("existFileNum").toString()); ajaxResponse.setResult(result); } return ajaxResponse; } catch (Exception ex) { logger.error(ex.getMessage(), ex); return new AjaxResponse(new ErrorInfo(ex.getMessage()), false); } } /** * 通过moduleid添加档案利用 */ public AjaxResponse addUtilizationByAll(List idList) { try { String strSql = "select * from view_all_utlization where id = " + idList.get(0); Map map = jdbcTemplate.queryForMap(strSql); Long moduleId = Long.parseLong(map.get("module_id").toString()); Module module = moduleService.getByIdModule(moduleId); QueryWrapper moduleQueryWrapper = new QueryWrapper<>(); moduleQueryWrapper.eq("module_id", module.getParentId()); moduleQueryWrapper.ne("parent_id", 0); List moduleList = moduleService.list(moduleQueryWrapper); AjaxResponse ajaxResponse = new AjaxResponse(true); Map resultMap = new HashMap(); if (moduleList.size() == 0) { // 案卷级利用 resultMap = addUtilizationForFile(idList); } else if (moduleList.size() > 0) { // 文件级利用,需要反查案卷级信息 resultMap = addUtilizationForItem(module, idList); } // String unit = resultMap.get("unit").toString().equals("卷") ? "0" : "1"; String unit = "0"; if (resultMap != null) { StringBuilder sb = new StringBuilder(); sb.append("top.layer.open({"); sb.append(" title : '提示',"); sb.append(" type : 2,"); sb.append(" area : [ '700px', '220px' ],"); sb.append(" fixed : true, "); sb.append(" content : 'common/commonTips?addNum=" + resultMap.get("addNum") + "&type=借阅&repeatNum=" + resultMap.get("repeatNum") + "&existFileNum=" + resultMap.get("existFileNum") + "&existItemNum=" + resultMap.get("existItemNum") + "&urlPath=borrow'"); sb.append("});"); Map result = new HashMap(); result.put("jsExpression", sb.toString()); result.put("totalNum", resultMap.get("existFileNum").toString()); ajaxResponse.setResult(result); } return ajaxResponse; } catch (Exception ex) { logger.error(ex.getMessage(), ex); return new AjaxResponse(new ErrorInfo(ex.getMessage()), false); } } public Map addUtilizationForFile(List idList) { Subject currentUser = SecurityUtils.getSubject(); Session session = currentUser.getSession(); User user = (User) session.getAttribute("user"); Map resultMap = new HashMap<>(); int addNum = 0; int repeatNum = 0; int existItemNum = 0; for (int i = 0; i < idList.size(); i++) { Long keyId = idList.get(i); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("form_id", 0); queryWrapper.eq("create_user_id", user.getUserId()); int itemCount = borrowDetailService.count(queryWrapper); existItemNum += itemCount; queryWrapper.eq("file_id", keyId); List borrowDetailList = borrowDetailService.list(queryWrapper); if (borrowDetailList.size() == 0) { CatAjjxx catAjjxx = catAjjxxService.getById(keyId); Integer cgwjxxCount = borrowDetailService.setCgwjxx(catAjjxx); Integer yswjxxCount = borrowDetailService.setYswjxx(catAjjxx); addNum++; existItemNum += cgwjxxCount + yswjxxCount; } else { repeatNum++; } } String strSql = "select distinct file_id from UTL_BORROW_DETAIL where form_id=0 and create_user_id=" + user.getUserId(); List> parentMapList = jdbcTemplate.queryForList(strSql); resultMap.put("existFileNum", parentMapList.size()); resultMap.put("existItemNum", existItemNum); resultMap.put("addNum", addNum); resultMap.put("repeatNum", repeatNum); return resultMap; } public Map addUtilizationForItem(Module module, List idList) { Subject currentUser = SecurityUtils.getSubject(); Session session = currentUser.getSession(); User user = (User) session.getAttribute("user"); int addNum = 0; int repeatNum = 0; int existItemNum = 0; Map resultMap = new HashMap<>(); for (int i = 0; i < idList.size(); i++) { Long keyId = idList.get(i); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("form_id", 0); queryWrapper.eq("create_user_id", user.getUserId()); int itemCount = borrowDetailService.count(queryWrapper); existItemNum += itemCount; queryWrapper.eq("item_id", keyId); List borrowDetailList = borrowDetailService.list(queryWrapper); if (borrowDetailList.size() == 0) { String mainTableName = module.getMainTableName(); if (mainTableName.equals("CAT_ITEM_CGWJXX")) { Integer cgwjxxCount = borrowDetailService.setCgwjxxByIds(idList); existItemNum += cgwjxxCount; } else if (mainTableName.equals("CAT_ITEM_YSWJXX")) { Integer cgwjxxCount = borrowDetailService.setYswjxxByIds(idList); existItemNum += cgwjxxCount; } } } resultMap.put("addNum", 1); resultMap.put("repeatNum", 0); resultMap.put("existItemNum", existItemNum); String strSql = "select distinct file_id from UTL_BORROW_DETAIL where form_id=0 and create_user_id=" + user.getUserId(); List> parentMapList = jdbcTemplate.queryForList(strSql); resultMap.put("existFileNum", parentMapList.size()); return resultMap; } //添加实物样品 public Map addPhysicalForItem( Long viewId, ArrayList idList) { Subject currentUser = SecurityUtils.getSubject(); Session session = currentUser.getSession(); User user = (User) session.getAttribute("user"); int addNum = 0; int repeatNum = 0; int existItemNum = 0; Map resultMap = new HashMap<>(); for (int i = 0; i < idList.size(); i++) { Long keyId = idList.get(i); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("form_id", 0); queryWrapper.eq("create_user_id", user.getUserId()); int itemCount = physicalDetailService.count(queryWrapper); existItemNum += itemCount; queryWrapper.eq("item_id", keyId); List physicalDetailList = physicalDetailService.list(queryWrapper); if (physicalDetailList.size() == 0) { Integer cgwjxxCount = physicalDetailService.setCgwjxxByIds(idList); existItemNum += cgwjxxCount; } } resultMap.put("addNum", 1); resultMap.put("repeatNum", 0); resultMap.put("existItemNum", existItemNum); String strSql = "select distinct file_id from UTL_PHYSICAL_DETAIL where form_id=0 and create_user_id=" + user.getUserId(); List> parentMapList = jdbcTemplate.queryForList(strSql); resultMap.put("existFileNum", parentMapList.size()); return resultMap; } /** * 添加成果 * * @param viewId * @param idList * @return */ public AjaxResponse addCg(Long viewId, ArrayList idList) { try { String cgSql = "select NVL(max(BGBH), 0) BGBH FROM CAT_ITEM_CGWJXX"; Map stringMap = jdbcTemplate.queryForMap(cgSql); int maxDH = Integer.parseInt(stringMap.get("BGBH").toString()); for (int i = 0; i < idList.size(); i++) { int newDH = maxDH + 1 + i; String newDhString = String.format("%04d", newDH); String sql = "select * from CAT_ITEM_YSWJXX where id = " + idList.get(i); Map stringObjectMap = jdbcTemplate.queryForMap(sql); stringObjectMap.put("BGBH", newDhString); LocalDateTime currentDate = LocalDateTime.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); String formattedDate = currentDate.format(formatter); stringObjectMap.put("CREATE_TIME", formattedDate); stringObjectMap.put("MODIFY_TIME", formattedDate); stringObjectMap.put("CDDZWJLJ", stringObjectMap.get("WJLJ")); stringObjectMap.put("CDDZWJLJ", stringObjectMap.get("WJLJ")); iform.insert(1823017354756390913L, stringObjectMap); } return null; } catch (Exception e) { logger.error(e.getMessage(), e); return new AjaxResponse(new ErrorInfo(e.getMessage()), false); } } /** * 取消发布 * * @param viewId * @param idList * @return */ public AjaxResponse createArchiveCode(Long viewId, ArrayList idList) { try { String sql = "select NVL(max(DH), 0) DH FROM CAT_FILE_AJJXX"; Map stringObjectMap = jdbcTemplate.queryForMap(sql); int maxDH = Integer.parseInt(stringObjectMap.get("DH").toString()); for (int i = 0; i < idList.size(); i++) { int newDH = maxDH + 1 + i; String newDhString = String.format("%04d", newDH); String updateSql = "update CAT_FILE_AJJXX set DH = '" + newDhString + "' where ID = " + idList.get(i); jdbcTemplate.update(updateSql); } return new AjaxResponse(true); } catch (Exception e) { logger.error(e.getMessage(), e); return new AjaxResponse(new ErrorInfo(e.getMessage()), false); } } }