Java tutorial
package gnete.card.service.impl; import flink.util.AmountUtil; import flink.util.IOUtil; import flink.util.StringUtil; import gnete.card.dao.AreaDAO; import gnete.card.dao.BankInfoDAO; import gnete.card.dao.BranchInfoDAO; import gnete.card.dao.CardMerchGroupDAO; import gnete.card.dao.CardMerchToGroupDAO; import gnete.card.dao.CardToMerchDAO; import gnete.card.dao.CardissuerFreeNumDAO; import gnete.card.dao.CardissuerPlanFeeDAO; import gnete.card.dao.CardissuerPlanFeeRuleDAO; import gnete.card.dao.CostRecordDAO; import gnete.card.dao.MerchGroupDAO; import gnete.card.dao.MerchInfoDAO; import gnete.card.dao.MerchInfoRegDAO; import gnete.card.dao.MerchToGroupDAO; import gnete.card.dao.MerchTypeDAO; import gnete.card.dao.RiskMerchDAO; import gnete.card.dao.TerminalDAO; import gnete.card.dao.UserInfoDAO; import gnete.card.entity.BankInfo; import gnete.card.entity.BranchInfo; import gnete.card.entity.CardMerchGroup; import gnete.card.entity.CardMerchGroupKey; import gnete.card.entity.CardMerchToGroup; import gnete.card.entity.CardMerchToGroupKey; import gnete.card.entity.CardToMerch; import gnete.card.entity.CardToMerchKey; import gnete.card.entity.CardissuerFreeNum; import gnete.card.entity.CardissuerPlanFee; import gnete.card.entity.CardissuerPlanFeeRule; import gnete.card.entity.CardissuerPlanFeeRuleKey; import gnete.card.entity.CostRecord; import gnete.card.entity.MerchGroup; import gnete.card.entity.MerchInfo; import gnete.card.entity.MerchInfoReg; import gnete.card.entity.MerchToGroup; import gnete.card.entity.MerchType; import gnete.card.entity.RiskMerch; import gnete.card.entity.Terminal; import gnete.card.entity.UserInfo; import gnete.card.entity.flag.SetCycleFlag; import gnete.card.entity.flag.TrueOrFalseFlag; import gnete.card.entity.flag.UsePwdFlag; import gnete.card.entity.flag.YesOrNoFlag; import gnete.card.entity.state.CardFreeNumState; import gnete.card.entity.state.CardMerchGroupState; import gnete.card.entity.state.CardMerchState; import gnete.card.entity.state.CommonState; import gnete.card.entity.state.CostRecordState; import gnete.card.entity.state.MerchState; import gnete.card.entity.state.MerchTypeState; import gnete.card.entity.state.TerminalState; import gnete.card.entity.type.AcctType; import gnete.card.entity.type.ChargeType; import gnete.card.entity.type.CostRecordType; import gnete.card.entity.type.RiskLevelType; import gnete.card.entity.type.RoleType; import gnete.card.service.MerchService; import gnete.card.service.RoleService; import gnete.card.service.UserService; import gnete.card.service.mgr.SysparamCache; import gnete.card.workflow.service.WorkflowService; import gnete.etc.Assert; import gnete.etc.BizException; import gnete.etc.Symbol; import gnete.etc.WorkflowConstants; import gnete.util.DateUtil; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang3.tuple.MutablePair; import org.apache.commons.lang3.tuple.Pair; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service("merchService") public class MerchServiceImpl implements MerchService { @Autowired private MerchInfoDAO merchInfoDAO; @Autowired private MerchTypeDAO merchTypeDAO; @Autowired private MerchGroupDAO merchGroupDAO; @Autowired private MerchToGroupDAO merchToGroupDAO; @Autowired private TerminalDAO terminalDAO; @Autowired private BranchInfoDAO branchInfoDAO; @Autowired private UserService userService; @Autowired private RoleService roleService; @Autowired private CardMerchGroupDAO cardMerchGroupDAO; @Autowired private CardMerchToGroupDAO cardMerchToGroupDAO; @Autowired private CardToMerchDAO cardToMerchDAO; @Autowired private RiskMerchDAO riskMerchDAO; @Autowired private WorkflowService workflowService; @Autowired private MerchInfoRegDAO merchInfoRegDAO; @Autowired private AreaDAO areaDAO; @Autowired private BankInfoDAO bankInfoDAO; @Autowired private UserInfoDAO userInfoDAO; @Autowired private CardissuerPlanFeeDAO cardissuerPlanFeeDAO; @Autowired private CardissuerPlanFeeRuleDAO cardissuerPlanFeeRuleDAO; @Autowired private CostRecordDAO costRecordDAO; @Autowired private CardissuerFreeNumDAO cardissuerFreeNumDAO; /** * ?? */ private static final String DEFAULT_ENCODING = "GBK"; /** * ??? */ private static final int DETAIL_SUM = 25; /** * */ private static final String DEFAULT_SEQ = ","; private static Logger logger = Logger.getLogger(MerchServiceImpl.class); public void addMerch(MerchInfoReg merchInfoReg, UserInfo userInfo) throws BizException { Assert.notNull(merchInfoReg, "?"); // merchInfoReg.setSetCycle(SetCycleFlag.DAY.getValue()); String manageBranch = merchInfoReg.getManageBranch(); Assert.notTrue(!this.branchInfoDAO.isExist(manageBranch), "?[" + manageBranch + "]"); merchInfoReg.setStatus(MerchState.WAITED.getValue()); merchInfoReg.setUpdateBy(userInfo.getUserId()); merchInfoReg.setUpdateTime(new Date()); this.merchInfoRegDAO.insert(merchInfoReg); // 5.?? startMerchWorkFlow(merchInfoReg, userInfo); } public void checkMerchPass(MerchInfoReg merchInfoReg, String userId) throws BizException { Assert.notNull(merchInfoReg, "?"); Assert.notEmpty(userId, "ID?"); //1. ???? merchInfoReg.setStatus(MerchState.NORMAL.getValue()); String merchId = getMerchIdStr(merchInfoReg); MerchInfo old = (MerchInfo) this.merchInfoDAO.findByPk(merchId); Assert.isNull(old, "?[" + merchId + "]?????"); merchInfoReg.setMerchId(merchId); merchInfoReg.setStatus(MerchState.NORMAL.getValue()); merchInfoReg.setUpdateBy(userId); merchInfoReg.setUpdateTime(new Date()); this.merchInfoRegDAO.update(merchInfoReg); MerchInfo merchInfo = new MerchInfo(); copyMerchInfoRegToMerchInfo(merchInfoReg, merchInfo); this.merchInfoDAO.insert(merchInfo); // 2. String adminUserId = merchInfoReg.getAdminId(); Assert.notEmpty(adminUserId, "ID?"); Assert.notTrue(this.userService.getUser(adminUserId) != null, "[" + adminUserId + "]"); UserInfo admin = new UserInfo(); admin.setUserId(adminUserId); admin.setUserName(merchInfoReg.getMerchName() + "?"); admin.setMerchantNo(merchId); admin.setUpdateTime(new Date()); admin.setUpdateUser(userId); this.userService.addUser(admin, SysparamCache.getInstance().getSysUser()); // 3. ?? String roleId = this.roleService.addDefaultAdmin(merchId, merchInfoReg.getMerchName(), false, RoleType.MERCHANT.getValue(), userId); this.roleService.bindUserRole(admin.getUserId(), roleId); // 4.???? if (StringUtils.isNotBlank(merchInfoReg.getCardBranch())) { String branchCode = merchInfoReg.getCardBranch(); CardToMerch oldCardMerch = (CardToMerch) this.cardToMerchDAO .findByPk(new CardToMerchKey(branchCode, merchId)); Assert.isNull(oldCardMerch, "????[" + branchCode + ", " + merchId + "]"); CardToMerch cardToMerch = new CardToMerch(); cardToMerch.setMerchId(merchId); cardToMerch.setBranchCode(branchCode); cardToMerch.setProxyId(branchCode); cardToMerch.setStatus(CardMerchState.NORMAL.getValue()); cardToMerch.setUpdateBy(userId); cardToMerch.setUpdateTime(new Date()); this.cardToMerchDAO.insert(cardToMerch); } } public void addOldMerch(MerchInfoReg merchInfoReg, UserInfo userInfo) throws BizException { Assert.notNull(merchInfoReg, "??"); // merchInfoReg.setSetCycle(SetCycleFlag.DAY.getValue()); String manageBranch = merchInfoReg.getManageBranch(); Assert.notTrue(!this.branchInfoDAO.isExist(manageBranch), "?[" + manageBranch + "]?"); MerchInfo old = (MerchInfo) this.merchInfoDAO.findByPk(merchInfoReg.getMerchId()); Assert.isNull(old, "??[" + merchInfoReg.getMerchId() + "]"); merchInfoReg.setStatus(MerchState.WAITED.getValue()); merchInfoReg.setUpdateBy(userInfo.getUserId()); merchInfoReg.setUpdateTime(new Date()); this.merchInfoRegDAO.insert(merchInfoReg); startMerchWorkFlow(merchInfoReg, userInfo); } public String[] addMerchFile(File file, MerchInfoReg merchInfoReg, UserInfo userInfo) throws BizException { Assert.notNull(merchInfoReg, "?"); Assert.notEmpty(merchInfoReg.getManageBranch(), "???"); Assert.notEmpty(merchInfoReg.getOpenFlag(), "?"); Assert.notEmpty(merchInfoReg.getCurrCode(), "???"); Assert.notNull(file, "?"); Assert.notNull(userInfo, "??"); String manageBranch = merchInfoReg.getManageBranch(); Assert.isTrue(this.branchInfoDAO.isExist(manageBranch), "?[" + manageBranch + "]?"); List<MerchInfoReg> list = resolveFile(file); // ????? String[] regs = insertToMerchInfoReg(list, merchInfoReg, userInfo); return regs; } public void modifyMerch(MerchInfo merchInfo, String userCode) throws BizException { Assert.notNull(merchInfo, "?"); String merchId = merchInfo.getMerchId(); String manageBranch = merchInfo.getManageBranch(); Assert.notTrue(!this.branchInfoDAO.isExist(manageBranch), "?[" + manageBranch + "]?"); MerchInfo old = (MerchInfo) this.merchInfoDAO.findByPk(merchId); Assert.notNull(old, "?[" + merchId + "]"); merchInfo.setStatus(old.getStatus()); merchInfo.setUpdateBy(userCode); merchInfo.setUpdateTime(new Date()); this.merchInfoDAO.update(merchInfo); } public void modifyMerchReg(MerchInfoReg merchInfoReg, UserInfo userInfo) throws BizException { Assert.notNull(merchInfoReg, "?"); Assert.notEmpty(merchInfoReg.getId(), "ID?"); String manageBranch = merchInfoReg.getManageBranch(); Assert.notTrue(!this.branchInfoDAO.isExist(manageBranch), "?[" + manageBranch + "]?"); MerchInfoReg old = (MerchInfoReg) this.merchInfoRegDAO.findByPk(merchInfoReg.getId()); Assert.notNull(old, "?[" + merchInfoReg.getId() + "]"); merchInfoReg.setStatus(old.getStatus()); merchInfoReg.setUpdateBy(userInfo.getUserId()); merchInfoReg.setUpdateTime(new Date()); this.merchInfoRegDAO.update(merchInfoReg); } public void cancelMerch(String merchId, String userCode) throws BizException { Assert.notEmpty(merchId, "?"); MerchInfo old = (MerchInfo) this.merchInfoDAO.findByPk(merchId); Assert.notNull(old, "?[" + merchId + "]"); old.setStatus(MerchState.CANCEL.getValue()); old.setUpdateBy(userCode); old.setUpdateTime(new Date()); this.merchInfoDAO.update(old); } public void activeMerch(String merchId, String userCode) throws BizException { Assert.notEmpty(merchId, "?"); MerchInfo old = (MerchInfo) this.merchInfoDAO.findByPk(merchId); Assert.notNull(old, "?[" + merchId + "]"); old.setStatus(MerchState.NORMAL.getValue()); old.setUpdateBy(userCode); old.setUpdateTime(new Date()); this.merchInfoDAO.update(old); } public void submitCheck(UserInfo user) throws BizException { Map<String, Object> params = new HashMap<String, Object>(); params.put("status", MerchState.PRESUB.getValue()); List<MerchInfoReg> merchInfoList = this.merchInfoRegDAO.find(params); if (CollectionUtils.isEmpty(merchInfoList)) { throw new BizException("???"); } for (MerchInfoReg merchInfoReg : merchInfoList) { Assert.notEmpty(merchInfoReg.getId(), "???id?"); // ? merchInfoReg.setStatus(MerchState.WAITED.getValue()); merchInfoReg.setUpdateBy(user.getUserId()); merchInfoReg.setUpdateTime(new Date()); this.merchInfoRegDAO.update(merchInfoReg); this.startMerchWorkFlow(merchInfoReg, user); } } public boolean deleteMerch(String merchId) throws BizException { Assert.notEmpty(merchId, "?ID?"); MerchInfo old = (MerchInfo) this.merchInfoDAO.findByPk(merchId); Assert.notNull(old, "[" + merchId + "]?"); Assert.isTrue(MerchState.UNPASS.getValue().equals(old.getStatus()), "????"); // ?? boolean delMerch = this.merchInfoDAO.delete(merchId) > 0; // ????? try { workflowService.deleteFlow(WorkflowConstants.WORKFLOW_ADD_MERCH, merchId); } catch (Exception e) { throw new BizException("??" + e.getMessage()); } return delMerch; } public void addMerchType(MerchType merchType, String userCode) throws BizException { Assert.notNull(merchType, "?"); String type = merchType.getMerchType(); MerchType old = (MerchType) this.merchTypeDAO.findByPk(type); Assert.isNull(old, "?[" + type + "]"); merchType.setStatus(MerchTypeState.NORMAL.getValue()); merchType.setUpdateBy(userCode); merchType.setUpdateTime(new Date()); this.merchTypeDAO.insert(merchType); } public void modifyMerchType(MerchType merchType, String userCode) throws BizException { Assert.notNull(merchType, "?"); String type = merchType.getMerchType(); MerchType old = (MerchType) this.merchTypeDAO.findByPk(type); Assert.notNull(old, "?[" + type + "]"); merchType.setStatus(old.getStatus()); merchType.setUpdateBy(userCode); merchType.setUpdateTime(new Date()); this.merchTypeDAO.update(merchType); } public void cancelMerchType(String merchType, String userCode) throws BizException { Assert.notNull(merchType, "?"); MerchType old = (MerchType) this.merchTypeDAO.findByPk(merchType); Assert.notNull(old, "?[" + merchType + "]"); old.setStatus(MerchTypeState.CANCEL.getValue()); old.setUpdateBy(userCode); old.setUpdateTime(new Date()); this.merchTypeDAO.update(old); } public void activeMerchType(String merchType, String userCode) throws BizException { Assert.notNull(merchType, "?"); MerchType old = (MerchType) this.merchTypeDAO.findByPk(merchType); Assert.notNull(old, "?[" + merchType + "]"); old.setStatus(MerchTypeState.NORMAL.getValue()); old.setUpdateBy(userCode); old.setUpdateTime(new Date()); this.merchTypeDAO.update(old); } public void addMerchGroup(MerchGroup merchGroup, String merchs, UserInfo userInfo) throws BizException { Assert.notNull(merchGroup, "?"); String groupId = generateMerchGroupId(); String[] merchArray = merchs.split(","); if (!ArrayUtils.isEmpty(merchArray)) { for (String merchId : merchArray) { MerchToGroup toGroup = new MerchToGroup(); toGroup.setGroupId(groupId); toGroup.setMerchId(merchId); toGroup.setUpdateBy(userInfo.getUserId()); toGroup.setUpdateTime(new Date()); this.merchToGroupDAO.insert(toGroup); } } merchGroup.setGroupId(groupId); merchGroup.setManageBranch(userInfo.getBranchNo()); merchGroup.setStatus(CommonState.NORMAL.getValue()); merchGroup.setUpdateBy(userInfo.getUserId()); merchGroup.setInsertTime(new Date()); this.merchGroupDAO.insert(merchGroup); } public void modifyMerchGroup(MerchGroup merchGroup, String merchs, String userCode) throws BizException { Assert.notNull(merchGroup, "?"); Assert.notEmpty(merchs, "?"); String groupId = merchGroup.getGroupId(); MerchGroup old = (MerchGroup) this.merchGroupDAO.findByPk(merchGroup); Assert.notNull(old, "?[" + groupId + "]"); // ? this.merchToGroupDAO.deleteByGroupId(groupId); String[] merchArray = merchs.split(","); for (String merchId : merchArray) { MerchToGroup toGroup = new MerchToGroup(); toGroup.setGroupId(groupId); toGroup.setMerchId(merchId); toGroup.setUpdateBy(userCode); toGroup.setUpdateTime(new Date()); this.merchToGroupDAO.insert(toGroup); } old.setGroupName(merchGroup.getGroupName()); old.setCardIssuer(merchGroup.getCardIssuer()); old.setUpdateBy(userCode); old.setUpdateTime(new Date()); this.merchGroupDAO.update(old); } public void deleteMerchGroup(String groupId, String userCode) throws BizException { Assert.notEmpty(groupId, "?"); MerchGroup old = (MerchGroup) this.merchGroupDAO.findByPk(groupId); Assert.notNull(old, "?[" + groupId + "]"); // ? this.merchToGroupDAO.deleteByGroupId(groupId); this.merchGroupDAO.delete(groupId); } public void addTerminal(Terminal terminal, String cardBranchCode, String userCode) throws BizException { Assert.notNull(terminal, "?"); Assert.notEmpty(terminal.getMerchId(), "??"); String merchId = terminal.getMerchId(); String termId = this.terminalDAO.getNextNewTermId(); terminal.setTermId(termId); String manageBranch = terminal.getManageBranch(); String maintenance = terminal.getMaintenance(); MerchInfo merchInfo = (MerchInfo) this.merchInfoDAO.findByPk(merchId); Assert.notNull(merchInfo, "[" + merchId + "]?"); if (Symbol.YES.equals(terminal.getSingleProduct())) { Assert.notEmpty(cardBranchCode, "????"); BranchInfo branchInfo = this.branchInfoDAO.findBranchInfo(cardBranchCode); Assert.notNull(branchInfo, "??[" + cardBranchCode + "]?"); Assert.isTrue(Symbol.YES.equals(branchInfo.getSingleProduct()), "??[" + cardBranchCode + "]???"); // ??? this.recordCost(cardBranchCode, userCode, termId); } Assert.notTrue(StringUtils.isNotEmpty(manageBranch) && !this.branchInfoDAO.isExist(manageBranch), "?[" + manageBranch + "]"); Assert.notTrue(StringUtils.isNotEmpty(maintenance) && !this.branchInfoDAO.isExist(maintenance), "?[" + maintenance + "]"); Terminal old = (Terminal) this.terminalDAO.findByPk(termId); Assert.isNull(old, "?[" + termId + "]"); terminal.setPosStatus(TerminalState.NORMAL.getValue()); terminal.setUpdateBy(userCode); terminal.setUpdateTime(new Date()); terminal.setCreateTime(new Date()); this.terminalDAO.insert(terminal); } public void addOldTerminal(Terminal terminal, String userCode) throws BizException { Assert.notNull(terminal, "?"); String manageBranch = terminal.getManageBranch(); String maintenance = terminal.getMaintenance(); Assert.notTrue(!this.merchInfoDAO.isExist(terminal.getMerchId()), "?[" + terminal.getMerchId() + "]"); Assert.notTrue(StringUtils.isNotEmpty(manageBranch) && !this.branchInfoDAO.isExist(manageBranch), "?[" + manageBranch + "]"); Assert.notTrue(StringUtils.isNotEmpty(maintenance) && !this.branchInfoDAO.isExist(maintenance), "?[" + maintenance + "]"); Terminal old = (Terminal) this.terminalDAO.findByPk(terminal.getTermId()); Assert.isNull(old, "??[" + terminal.getTermId() + "]"); terminal.setPosStatus(TerminalState.NORMAL.getValue()); terminal.setUpdateBy(userCode); terminal.setUpdateTime(new Date()); terminal.setCreateTime(new Date()); this.terminalDAO.insert(terminal); } public String[] addTerminalBatch(Terminal terminal, String cardBranchCode, int count, String userCode) throws BizException { Assert.notNull(terminal, "?"); Assert.notEmpty(terminal.getMerchId(), "??"); String[] terminalIdArray = new String[count]; for (int i = 0; i < count; i++) { String merchId = terminal.getMerchId(); String termId = this.terminalDAO.getNextNewTermId(); terminalIdArray[i] = termId; terminal.setTermId(termId); String manageBranch = terminal.getManageBranch(); String maintenance = terminal.getMaintenance(); Assert.notTrue(!this.merchInfoDAO.isExist(merchId), "?[" + merchId + "]"); Assert.notTrue(StringUtils.isNotEmpty(manageBranch) && !this.branchInfoDAO.isExist(manageBranch), "?[" + manageBranch + "]"); Assert.notTrue(StringUtils.isNotEmpty(maintenance) && !this.branchInfoDAO.isExist(maintenance), "?[" + maintenance + "]"); Terminal old = (Terminal) this.terminalDAO.findByPk(termId); Assert.isNull(old, "?[" + termId + "]"); terminal.setPosStatus(TerminalState.NORMAL.getValue()); terminal.setUpdateBy(userCode); terminal.setUpdateTime(new Date()); terminal.setCreateTime(new Date()); this.terminalDAO.insert(terminal); } if (Symbol.YES.equals(terminal.getSingleProduct())) { Assert.notEmpty(cardBranchCode, "????"); BranchInfo branchInfo = this.branchInfoDAO.findBranchInfo(cardBranchCode); Assert.notNull(branchInfo, "??[" + cardBranchCode + "]?"); Assert.isTrue(Symbol.YES.equals(branchInfo.getSingleProduct()), "??[" + cardBranchCode + "]???"); // ??? this.recordCost(cardBranchCode, userCode, terminalIdArray); } return terminalIdArray; } @Override public int addTermBatchFile(File upload, UserInfo sessionUser) throws BizException { List<Pair<Terminal, Integer>> termList = buildTermsFromFile(upload); int termTotalCnt = 0;// for (Pair<Terminal, Integer> pair : termList) { Terminal term = pair.getLeft(); Integer termCnt = pair.getRight(); termTotalCnt += termCnt; term.setSingleProduct(YesOrNoFlag.NO.getValue()); term.setPosStatus(TerminalState.NORMAL.getValue()); term.setCreateTime(new Date()); term.setUpdateBy(sessionUser.getUserId()); term.setUpdateTime(new Date()); for (int i = 0; i < termCnt; i++) { term.setTermId(this.terminalDAO.getNextNewTermId()); this.terminalDAO.insert(term); } } return termTotalCnt; } public void modifyTerminal(Terminal terminal, String userCode) throws BizException { Assert.notNull(terminal, "?"); String termId = terminal.getTermId(); String merchId = terminal.getMerchId(); String manageBranch = terminal.getManageBranch(); String maintenance = terminal.getMaintenance(); Assert.notTrue(!this.merchInfoDAO.isExist(merchId), "?[" + merchId + "]"); Assert.notTrue(StringUtils.isNotEmpty(manageBranch) && !this.branchInfoDAO.isExist(manageBranch), "?[" + manageBranch + "]"); Assert.notTrue(StringUtils.isNotEmpty(maintenance) && !this.branchInfoDAO.isExist(maintenance), "?[" + maintenance + "]"); Terminal old = (Terminal) this.terminalDAO.findByPk(termId); Assert.notNull(old, "?[" + termId + "]"); terminal.setPosStatus(old.getPosStatus()); terminal.setUpdateBy(userCode); terminal.setUpdateTime(new Date()); terminal.setCreateTime(old.getCreateTime()); this.terminalDAO.update(terminal); } public void startTerminal(String termId, String userCode) throws BizException { Assert.notEmpty(termId, "?"); Terminal old = (Terminal) this.terminalDAO.findByPk(termId); Assert.notNull(old, "?[" + termId + "]"); old.setPosStatus(TerminalState.NORMAL.getValue()); old.setUpdateBy(userCode); old.setUpdateTime(new Date()); this.terminalDAO.update(old); } public void stopTerminal(String termId, String userCode) throws BizException { Assert.notEmpty(termId, "?"); Terminal old = (Terminal) this.terminalDAO.findByPk(termId); Assert.notNull(old, "?[" + termId + "]"); old.setPosStatus(TerminalState.STOP.getValue()); old.setUpdateBy(userCode); old.setUpdateTime(new Date()); this.terminalDAO.update(old); } public void addCardMerchGroup(CardMerchGroup cardMerchGroup, String merchants, String userId) throws BizException { Assert.notNull(cardMerchGroup, "????"); Assert.notEmpty(cardMerchGroup.getBranchCode(), "???"); // Assert.notEmpty(merchants, "??"); Assert.notEmpty(userId, "ID?"); cardMerchGroup.setStatus(CardMerchGroupState.NORMAL.getValue()); cardMerchGroup.setUpdateBy(userId); cardMerchGroup.setUpdateTime(new Date()); cardMerchGroupDAO.insert(cardMerchGroup); if (StringUtils.isEmpty(merchants)) { return; } CardMerchToGroup group = new CardMerchToGroup(); String[] merchantId = merchants.split(","); for (int i = 0; i < merchantId.length; i++) { group.setBranchCode(cardMerchGroup.getBranchCode()); group.setGroupName(cardMerchGroup.getGroupName()); group.setGroupId(cardMerchGroup.getGroupId()); group.setMerchId(merchantId[i]); group.setStatus(CardMerchGroupState.NORMAL.getValue()); group.setUpdateBy(userId); group.setUpdateTime(new Date()); cardMerchToGroupDAO.insert(group); } } public void modifyCardMerchGroup(CardMerchGroup cardMerchGroup, String merchants, String userId) throws BizException { Assert.notNull(cardMerchGroup, "????"); Assert.notEmpty(cardMerchGroup.getBranchCode(), "???"); // Assert.notEmpty(merchants, "??"); Assert.notEmpty(userId, "ID?"); CardMerchGroupKey key = new CardMerchGroupKey(); key.setBranchCode(cardMerchGroup.getBranchCode()); key.setGroupId(cardMerchGroup.getGroupId()); CardMerchGroup his = (CardMerchGroup) cardMerchGroupDAO.findByPk(key); cardMerchGroup.setStatus(his.getStatus()); cardMerchGroup.setUpdateBy(userId); cardMerchGroup.setUpdateTime(new Date()); cardMerchGroupDAO.update(cardMerchGroup); // ?? CardMerchToGroupKey groupKey = new CardMerchToGroupKey(); groupKey.setBranchCode(his.getBranchCode()); groupKey.setGroupId(his.getGroupId()); cardMerchToGroupDAO.deleteByBranchAndGroupId(groupKey); if (StringUtils.isEmpty(merchants)) { return; } // ??? CardMerchToGroup group = new CardMerchToGroup(); group.setBranchCode(groupKey.getBranchCode()); group.setGroupId(groupKey.getGroupId()); String[] merchantId = merchants.split(","); for (int i = 0; i < merchantId.length; i++) { group.setMerchId(merchantId[i]); group.setGroupName(his.getGroupName()); group.setStatus(his.getStatus()); group.setUpdateBy(userId); group.setUpdateTime(new Date()); cardMerchToGroupDAO.insert(group); } } public void cancelCardMerchGroup(String branchCode, String groupId) throws BizException { Assert.notEmpty(branchCode, "????"); Assert.notEmpty(groupId, "??"); CardMerchGroupKey key = new CardMerchGroupKey(); key.setBranchCode(branchCode); key.setGroupId(groupId); CardMerchGroup group = (CardMerchGroup) cardMerchGroupDAO.findByPkWithLock(key); group.setStatus(CardMerchGroupState.CANCEL.getValue()); group.setUpdateTime(new Date()); cardMerchGroupDAO.update(group); } public void startCardMerchGroup(String branchCode, String groupId) throws BizException { Assert.notEmpty(branchCode, "????"); Assert.notEmpty(groupId, "??"); CardMerchGroupKey key = new CardMerchGroupKey(); key.setBranchCode(branchCode); key.setGroupId(groupId); CardMerchGroup group = (CardMerchGroup) cardMerchGroupDAO.findByPkWithLock(key); group.setStatus(CardMerchGroupState.NORMAL.getValue()); group.setUpdateTime(new Date()); cardMerchGroupDAO.update(group); } public boolean addRiskMerch(RiskMerch riskMerch, String userCode) throws BizException { Assert.notNull(riskMerch, "?"); RiskMerch oldRiskMerch = (RiskMerch) this.riskMerchDAO.findByPk(riskMerch.getMerchId()); Assert.isNull(oldRiskMerch, "?,????"); riskMerch.setUpdateBy(userCode); riskMerch.setUpdateTime(new Date()); return this.riskMerchDAO.insert(riskMerch) != null; } public boolean deleteRiskMerch(String merchId) throws BizException { Assert.notNull(merchId, "?"); int count = this.riskMerchDAO.delete(merchId); return count > 0; } /* * ----------------------------- private methods followed ------------------------------ */ /** * ?? */ private void startMerchWorkFlow(MerchInfoReg merchInfoReg, UserInfo userInfo) throws BizException { try { String roleType = userInfo.getRole().getRoleType(); // ??????? if (RoleType.CARD.getValue().equals(roleType) || RoleType.CARD_DEPT.getValue().equals(roleType)) { this.workflowService.startFlow(merchInfoReg, WorkflowConstants.MERCH_CARD_ADAPTER, merchInfoReg.getId(), userInfo); } // ?? ??? else if (RoleType.CENTER.getValue().equals(roleType) || RoleType.CENTER_DEPT.getValue().equals(roleType) || RoleType.FENZHI.getValue().equals(roleType) || RoleType.AGENT.getValue().equals(roleType)) { this.workflowService.startFlow(merchInfoReg, WorkflowConstants.MERCH_ADAPTER, merchInfoReg.getId(), userInfo); } } catch (Exception e) { throw new BizException("???" + e.getMessage()); } } /** * ?? */ private void startAddMerchFileWorkFlow(MerchInfoReg merchInfoReg, UserInfo userInfo) throws BizException { try { String roleType = userInfo.getRole().getRoleType(); // ?????????? if (RoleType.CARD.getValue().equals(roleType) || RoleType.CARD_DEPT.getValue().equals(roleType) || RoleType.AGENT.getValue().equals(roleType)) { this.workflowService.startFlow(merchInfoReg, WorkflowConstants.MERCH_CARD_ADAPTER, merchInfoReg.getId(), userInfo); } // ?? else if (RoleType.CENTER.getValue().equals(roleType) || RoleType.CENTER_DEPT.getValue().equals(roleType) || RoleType.FENZHI.getValue().equals(roleType)) { this.workflowService.startFlow(merchInfoReg, WorkflowConstants.MERCH_ADAPTER, merchInfoReg.getId(), userInfo); } } catch (Exception e) { throw new BizException("???" + e.getMessage()); } } /** * ?? * @throws BizException */ private String getMerchIdStr(MerchInfoReg merchInfoReg) throws BizException { // ? if (StringUtils.isEmpty(merchInfoReg.getMerchId())) { String merchId_prev = ""; if (merchInfoReg.isMerch898()) { // ?898+?4?+MCC?4?0003+??(4?) merchId_prev = "898" + merchInfoReg.getAreaCode() + "0003"; } else { // ?208+?4?+?(4?)+??(4?) merchId_prev = SysparamCache.getInstance().getSysNo() + merchInfoReg.getAreaCode() + merchInfoReg.getMerchType(); } String merchId_suf = this.merchInfoDAO.getMerchId(merchId_prev); if (StringUtils.isEmpty(merchId_suf)) { merchId_suf = "1000"; } else if (merchId_suf.length() < 4) { merchId_suf = StringUtils.leftPad(merchId_suf, 4, '0'); } return merchId_prev + merchId_suf; } else { // ?? return merchInfoReg.getMerchId(); } } /** * ??? */ private void copyMerchInfoRegToMerchInfo(MerchInfoReg merchInfoReg, MerchInfo merchInfo) throws BizException { try { BeanUtils.copyProperties(merchInfo, merchInfoReg); } catch (Exception e) { throw new BizException("??"); } } /** * ? * @param file * @throws BizException */ private List<MerchInfoReg> resolveFile(File file) throws BizException { byte[] fileData = getFileByte(file); List lines = getLines(fileData); Assert.isTrue(CollectionUtils.isNotEmpty(lines) && lines.size() > 1, "?"); return resolveDepositDetail(lines); } /** * ? */ private List<MerchInfoReg> resolveDepositDetail(List lines) throws BizException { List<MerchInfoReg> list = new ArrayList<MerchInfoReg>(); // ? int fieldNum = 0; if (lines.size() != 0) { fieldNum = ((String) lines.get(0)).split(DEFAULT_SEQ, -1).length; } // ??, ???. Set<String> merchNameSet = new HashSet<String>(); // ? ? for (int i = 1, n = lines.size(); i < n; i++) { String depositLine = (String) lines.get(i); // . if (StringUtils.isEmpty(depositLine)) { continue; } String[] arr = depositLine.split(DEFAULT_SEQ, -1); // ?????? checkMerchName(arr, i, fieldNum, merchNameSet); // ? MerchInfoReg merchInfoReg = getMerchInfoRegFromDetail(arr); list.add(merchInfoReg); } return list; } /** * ?? * @param file * @return * @throws BizException */ private byte[] getFileByte(File file) throws BizException { byte[] fileData; try { fileData = IOUtils.toByteArray(new FileInputStream(file)); } catch (FileNotFoundException e) { logger.error(e, e); throw new BizException("?FileNotFoundException"); } catch (IOException e) { logger.error(e, e); throw new BizException("?IOException"); } return fileData; } /** * ? * @param fileData * @return * @throws BizException */ private List getLines(byte[] fileData) throws BizException { // ?. List lines = null; try { lines = IOUtils.readLines(new ByteArrayInputStream(fileData), DEFAULT_ENCODING); } catch (IOException e) { logger.error(e, e); throw new BizException("?, ?"); } return lines; } /** * ?? * @param arr ?? * @param count ??? * @param fieldNum ? * @param merchNameSet ?? * @throws BizException */ private void checkMerchName(String[] arr, int count, int fieldNum, Set<String> merchNameSet) throws BizException { // ???. if (arr.length != fieldNum) { String msg = "[" + count + "]?,?[" + fieldNum + "]"; logger.error(msg); throw new BizException(msg); } if (ArrayUtils.isEmpty(arr)) { throw new BizException("?"); } //???, String merchName = arr[0]; if (StringUtils.isBlank(merchName)) { throw new BizException("[" + count + " ]????"); } //????? if (merchNameSet.contains(merchName)) { throw new BizException("[" + merchName + "]??"); } merchNameSet.add(merchName); } /** * ? * @param arr * @return */ private MerchInfoReg getMerchInfoRegFromDetail(String[] arr) throws BizException { Assert.isTrue(arr.length == DETAIL_SUM, "[" + DETAIL_SUM + "]"); MerchInfoReg merchInfoReg = new MerchInfoReg(); // ??200 Assert.isTrue(arr[0].length() <= 100, "??[" + arr[0] + "]"); merchInfoReg.setMerchName(arr[0]); // Assert.isTrue(arr[1].length() <= 15, "[" + arr[1] + "]"); merchInfoReg.setMerchAbb(arr[1]); Assert.isTrue(arr[2].length() == 4, "?[" + arr[2] + "]4?"); Assert.isTrue(this.merchTypeDAO.isExist(arr[2]), "[" + arr[2] + "]?"); merchInfoReg.setMerchType(arr[2]); Assert.isTrue(arr[3].length() == 4, "?[" + arr[3] + "]4?"); Assert.isTrue(this.areaDAO.isExist(arr[3]), "?[" + arr[3] + "]?"); merchInfoReg.setAreaCode(arr[3]); Assert.isTrue(arr[4].length() <= 30, "?[" + arr[4] + "]"); merchInfoReg.setLinkMan(arr[4]); Assert.isTrue(arr[5].length() <= 30, "??[" + arr[5] + "]"); merchInfoReg.setTelNo(arr[5]); Assert.isTrue(arr[6].length() <= 120, "??[" + arr[6] + "]"); merchInfoReg.setMerchAddress(arr[6]); Assert.notNull(AcctType.ALL.get(arr[7]), "?[" + arr[7] + "]?"); merchInfoReg.setAcctType(arr[7]); BankInfo bankInfo = (BankInfo) this.bankInfoDAO.findByPk(arr[8]); Assert.notNull(bankInfo, "?[" + arr[8] + "]?"); merchInfoReg.setBankNo(bankInfo.getBankNo()); merchInfoReg.setBankName(bankInfo.getBankName()); merchInfoReg.setAccAreaCode(bankInfo.getAddrNo()); Assert.isTrue(arr[9].length() <= 30, "??[" + arr[9] + "]"); merchInfoReg.setAccName(arr[9]); Assert.isTrue(arr[10].length() <= 32, "?[" + arr[10] + "]"); Assert.isTrue(StringUtil.isCorrectAccNo(arr[10]), "???-?"); merchInfoReg.setAccNo(arr[10]); Assert.notNull(UsePwdFlag.ALL.get(arr[11]), "???[" + arr[11] + "]?"); merchInfoReg.setUsePwdFlag(arr[11]); Assert.notNull(TrueOrFalseFlag.ALL.get(arr[12]), "??[" + arr[12] + "]?"); merchInfoReg.setIsNetting(arr[12]); Assert.isTrue(arr[13].length() <= 30, "???[" + arr[13] + "]"); Assert.notTrue(this.userInfoDAO.isExist(arr[13]), "[" + arr[13] + "]?"); merchInfoReg.setAdminId(arr[13]); String riskLevel = arr[14]; if (RiskLevelType.ALL.get(riskLevel) != null) { merchInfoReg.setRiskLevel(riskLevel); } String license = arr[15]; Assert.isTrue(license.length() <= 60, "??[" + license + "]"); merchInfoReg.setMerchCode(license); String licenseExpireDate = arr[16]; Assert.notTrue(licenseExpireDate.trim().length() > 0 && !DateUtil.isValidDate(licenseExpireDate), "?[" + licenseExpireDate + "]??"); merchInfoReg.setLicenseExpDate(DateUtil.parseDate(licenseExpireDate)); String organization = arr[17]; Assert.isTrue(organization.length() <= 32, "?[" + organization + "]"); merchInfoReg.setOrganization(organization); String organizationExpireDate = arr[18]; Assert.notTrue(organizationExpireDate.trim().length() > 0 && !DateUtil.isValidDate(organizationExpireDate), "?[" + organizationExpireDate + "]??"); merchInfoReg.setOrganizationExpireDate(organizationExpireDate); String taxRegCode = arr[19]; Assert.isTrue(taxRegCode.length() <= 32, "?[" + taxRegCode + "]"); merchInfoReg.setTaxRegCode(taxRegCode); String legalPersonName = arr[20]; Assert.isTrue(legalPersonName.length() <= 64, "??[" + legalPersonName + "]"); merchInfoReg.setLegalPersonName(legalPersonName); String legalPersonIdcard = arr[21]; Assert.isTrue(legalPersonIdcard.length() <= 32, "?[" + legalPersonIdcard + "]"); merchInfoReg.setLegalPersonIdcard(legalPersonIdcard); String legalPersonIdcardExpDate = arr[22]; Assert.notTrue( legalPersonIdcardExpDate.trim().length() > 0 && !DateUtil.isValidDate(legalPersonIdcardExpDate), "?[" + legalPersonIdcardExpDate + "]??"); merchInfoReg.setLegalPersonIdcardExpDate(DateUtil.parseDate(legalPersonIdcardExpDate)); String companyBusinessScope = arr[23]; Assert.isTrue(companyBusinessScope.length() <= 128, "????[" + companyBusinessScope + "]"); merchInfoReg.setCompanyBusinessScope(companyBusinessScope); String remark = arr[24]; Assert.isTrue(remark.length() <= 128, "[" + remark + "]"); merchInfoReg.setRemark(remark); return merchInfoReg; } /** * ????? * @param list * @param merchInfoReg * @return * @throws BizException */ private String[] insertToMerchInfoReg(List<MerchInfoReg> list, MerchInfoReg merchInfoReg, UserInfo userInfo) throws BizException { List<String> regList = new ArrayList<String>(); // list for (MerchInfoReg reg : list) { reg.setManageBranch(merchInfoReg.getManageBranch()); reg.setOpenFlag(merchInfoReg.getOpenFlag()); reg.setCurrCode(merchInfoReg.getCurrCode()); reg.setStatus(MerchState.WAITED.getValue()); reg.setSetCycle(SetCycleFlag.DAY.getValue()); reg.setUpdateBy(userInfo.getUserId()); reg.setUpdateTime(new Date()); reg.setCardBranch(merchInfoReg.getCardBranch()); reg.setSingleProduct(YesOrNoFlag.NO.getValue()); reg.setMerch898(merchInfoReg.isMerch898()); this.merchInfoRegDAO.insert(reg); startAddMerchFileWorkFlow(reg, userInfo); regList.add(reg.getId()); } return regList.toArray(new String[list.size()]); } /** * ID * @Date 2013-2-20?4:57:27 * @return String */ private String generateMerchGroupId() { return "SQ".concat(StringUtils.leftPad(merchGroupDAO.selectMerchGroupSEQ(), 6, '0')); } /** * ????? * @param cardBranchCode * @param termId * @throws BizException */ private void recordCost(String cardBranchCode, String userCode, String... termIdArrays) throws BizException { CardissuerPlanFee planFee = (CardissuerPlanFee) this.cardissuerPlanFeeDAO.findByPk(cardBranchCode); Assert.notNull(planFee, "??[" + cardBranchCode + "]???"); // ?? CardissuerPlanFeeRuleKey key = new CardissuerPlanFeeRuleKey(); key.setPlanId(planFee.getPlanId()); key.setBranchCode(cardBranchCode); key.setPeriod(1); // CardissuerPlanFeeRule rule = (CardissuerPlanFeeRule) this.cardissuerPlanFeeRuleDAO.findByPk(key); Assert.notNull(rule, "??[" + cardBranchCode + "]?[" + planFee.getPlanId() + "]?"); BigDecimal amt = BigDecimal.ZERO; // ???100 if (ChargeType.PRECENTED.getValue().equals(planFee.getChargeType())) { amt = AmountUtil.multiply(planFee.getChargeAmt(), AmountUtil.divide(rule.getRuleParam(), new BigDecimal(100))); } else { amt = rule.getRuleParam(); } // ???? CostRecord record = null; List<CostRecord> recordList = new ArrayList<CostRecord>(); // ??? CardissuerFreeNum cardissuerFreeNum = null; List<CardissuerFreeNum> freeNumList = new ArrayList<CardissuerFreeNum>(); for (String termId : termIdArrays) { record = new CostRecord(); record.setAmt(amt); record.setBranchCode(cardBranchCode); record.setType(CostRecordType.PLAN_AMT.getValue()); record.setStatus(CostRecordState.UNPAY.getValue()); record.setGenTime(new Date()); record.setInvoiceStatus(Symbol.NO); record.setPeriod(1); Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); calendar.add(Calendar.YEAR, 1); record.setNextPayTime(calendar.getTime()); record.setTermId(termId); recordList.add(record); cardissuerFreeNum = new CardissuerFreeNum(); // ??? cardissuerFreeNum.setPeriod(1); cardissuerFreeNum.setIssId(cardBranchCode); cardissuerFreeNum.setSendNum(rule.getSendNum()); cardissuerFreeNum.setUsedNum(0); cardissuerFreeNum.setStatus(CardFreeNumState.UN_SEND.getValue()); cardissuerFreeNum.setUpdateBy(userCode); cardissuerFreeNum.setUpdateTime(new Date()); cardissuerFreeNum.setTermId(termId); freeNumList.add(cardissuerFreeNum); } this.costRecordDAO.insertBatch(recordList); this.cardissuerFreeNumDAO.insertBatch(freeNumList); } /** * ? ? */ private List<Pair<Terminal, Integer>> buildTermsFromFile(File file) throws BizException { List<String> lines = null; try { lines = IOUtil.readLines(file, DEFAULT_ENCODING); Assert.isTrue(lines.size() >= 2 && lines.size() <= 101, "?100?"); } catch (IOException e) { logger.warn(e, e); throw new BizException("???"); } List<Pair<Terminal, Integer>> termList = new ArrayList<Pair<Terminal, Integer>>(lines.size() - 1); int termTotalCnt = 0;// for (int i = 1; i < lines.size(); i++) { String errMsgPrefix = String.format("%s", i); String detailLine = (String) lines.get(i); Assert.isTrue(!StringUtils.isBlank(detailLine), errMsgPrefix + "??"); String[] lineArr = detailLine.split(",", -1); Assert.isTrue(!ArrayUtils.isEmpty(lineArr), errMsgPrefix + "??"); Assert.isTrue(lineArr.length == 8, errMsgPrefix + "8"); Integer termCnt = Integer.valueOf(lineArr[7].trim()); termTotalCnt = termTotalCnt + termCnt; Assert.isTrue(termTotalCnt <= 1000, "???1000?"); Terminal term = new Terminal(); term.setMerchId(lineArr[0].trim()); term.setManageBranch(lineArr[1].trim()); term.setMaintenance(lineArr[2].trim()); term.setMerchAddress(lineArr[3].trim()); term.setPosContact(lineArr[4].trim()); term.setPosContactPhone(lineArr[5].trim()); term.setEntryMode(lineArr[6].trim()); Assert.notBlank(term.getMerchId(), errMsgPrefix + "??"); Assert.isTrue(this.merchInfoDAO.isExist(term.getMerchId()), errMsgPrefix + "?[" + term.getMerchId() + "]"); Assert.notTrue( StringUtils.isNotEmpty(term.getManageBranch()) && !this.branchInfoDAO.isExist(term.getManageBranch()), errMsgPrefix + "?[" + term.getManageBranch() + "]"); Assert.notBlank(term.getMaintenance(), errMsgPrefix + "?"); Assert.notTrue( StringUtils.isNotEmpty(term.getMaintenance()) && !this.branchInfoDAO.isExist(term.getMaintenance()), errMsgPrefix + "?[" + term.getMaintenance() + "]"); Assert.isTrue(Arrays.asList("0", "1").contains(term.getEntryMode()), errMsgPrefix + "?01"); termList.add(new MutablePair<Terminal, Integer>(term, termCnt)); } return termList; } }