Java tutorial
/* * Copyright (c) 2013 ????www.hrbesd.com. All rights reserved. * * HRBESD PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package com.esd.cs.audit; import java.math.BigDecimal; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import com.esd.common.util.CalendarUtil; import com.esd.common.util.PaginationRecordsAndNumber; import com.esd.cs.Constants; import com.esd.hesf.model.Accounts; import com.esd.hesf.model.Audit; import com.esd.hesf.model.AuditParameter; import com.esd.hesf.model.AuditProcessStatus; import com.esd.hesf.model.Company; import com.esd.hesf.model.CompanyEconomyType; import com.esd.hesf.model.CompanyProperty; import com.esd.hesf.model.Reply; import com.esd.hesf.model.User; import com.esd.hesf.model.Worker; import com.esd.hesf.model.WorkerCalculator; import com.esd.hesf.service.AccountsService; import com.esd.hesf.service.AuditParameterService; import com.esd.hesf.service.AuditProcessStatusService; import com.esd.hesf.service.AuditService; import com.esd.hesf.service.CompanyEconomyTypeService; import com.esd.hesf.service.CompanyPropertyService; import com.esd.hesf.service.CompanyService; import com.esd.hesf.service.PaymentService; import com.esd.hesf.service.ReplyService; import com.esd.hesf.service.UserService; /** * ?? * * @author Administrator * */ @Controller @RequestMapping(value = "/security/audits") public class AuditsController { private static final Logger logger = LoggerFactory.getLogger(AuditsController.class); @Autowired private UserService userService; @Autowired private AuditService auditService; @Autowired private CompanyService companyService; @Autowired private AuditParameterService auditParameterService; @Autowired private PaymentService paymentService; @Autowired private AccountsService accountsService; @Autowired private AuditProcessStatusService auditProcessStatusService; @Autowired private CompanyPropertyService companyPropertyService; @Autowired private CompanyEconomyTypeService companyEconomyTypeService; @Autowired private ReplyService replyService; private static List<CompanyProperty> companyPropertys; private static List<CompanyEconomyType> companyEconomyTypes; private DecimalFormat df = new DecimalFormat("0.00"); private DecimalFormat df4 = new DecimalFormat("0.0000"); /** * ???? */ @RequestMapping(value = "/list/{process}", method = RequestMethod.GET) public ModelAndView initAudit_list(@PathVariable(value = "process") Integer process, HttpSession session, HttpServletRequest request) { String nowYear = (String) session.getAttribute(Constants.YEAR); request.setAttribute("nowYear", nowYear); request.setAttribute("process", process); return new ModelAndView("audit/audit_list"); } /** * ? * * @param audit * @return */ @RequestMapping(value = "/refusal", method = RequestMethod.POST) @ResponseBody public Boolean refusal(Audit audit, HttpSession session) { Integer id = audit.getId(); Audit getAudit = auditService.getByPrimaryKey(id); getAudit.setVerifyAuditComment(audit.getVerifyAuditComment()); getAudit.setVerifyAuditDate(new Date());// ? Integer userId = (Integer) session.getAttribute(Constants.USER_ID); User user = userService.getByPrimaryKey(userId); getAudit.setVerifyAuditUser(user);// ?ID AuditProcessStatus auditProcessStatus = auditProcessStatusService .getByPrimaryKey(Constants.PROCESS_STATIC_WTG); getAudit.setAuditProcessStatus(auditProcessStatus); logger.debug(getAudit.toString()); getAudit.setRefuseTimes(getAudit.getRefuseTimes() + 1); auditService.update(getAudit); return true; } /** * ? * * @param audit * @return */ @RequestMapping(value = "/verifyAudit", method = RequestMethod.POST) @ResponseBody public Boolean verifyAudit(Audit audit, HttpSession session) { Integer id = audit.getId(); Audit getAudit = auditService.getByPrimaryKey(id); getAudit.setVerifyAuditComment(audit.getVerifyAuditComment()); getAudit.setVerifyAuditDate(new Date());// ? Integer userId = (Integer) session.getAttribute(Constants.USER_ID); User user = userService.getByPrimaryKey(userId); getAudit.setVerifyAuditUser(user);// ?ID getAudit.setAmountPayable(audit.getAmountPayable());// ? getAudit.setReductionAmount(audit.getReductionAmount());// ?? getAudit.setActualAmount(audit.getActualAmount());// ? getAudit.setPayAmount(audit.getPayAmount());// ? getAudit.setRemainAmount(audit.getRemainAmount());// ? getAudit.setComplementAmount(audit.getComplementAmount());// ? getAudit.setDelayPayAmount(audit.getDelayPayAmount());// getAudit.setIsDelayPay(audit.getIsDelayPay());// ??? getAudit.setIsExempt(audit.getIsExempt());// ??0 AuditProcessStatus auditProcessStatus = null; if (getAudit.getPayAmount().signum() == 0) { auditProcessStatus = auditProcessStatusService.getByPrimaryKey(Constants.PROCESS_STATIC_OK); } else { auditProcessStatus = auditProcessStatusService.getByPrimaryKey(Constants.PROCESS_STATIC_WJK); } // ? Integer companyId = getAudit.getCompany().getId(); AuditProcessStatus auditProcessStatusOK = auditProcessStatusService .getByPrimaryKey(Constants.PROCESS_STATIC_OK);// String[] unAudits = companyService.getUnauditYearByCompany(companyId, audit.getYear()); if (unAudits != null) { for (String year : unAudits) { Audit a = auditService.getByPrimaryKey(year, companyId); a.setPayAmount(new BigDecimal(0));// ?0 a.setAuditProcessStatus(auditProcessStatusOK);// a.setSupplementYear(getAudit.getYear());// auditService.update(a); } } // ?? getAudit.setAuditProcessStatus(auditProcessStatus); logger.debug(getAudit.toString()); auditService.update(getAudit); // ?? Accounts accounts = new Accounts(); accounts.setYear(CalendarUtil.getNowYear()); // accounts.setAudit(getAudit); // accounts.setCompany(getAudit.getCompany()); // ?? accounts.setTotalMoney(getAudit.getPayAmount()); // ? accounts.setAuditProcessStatus(getAudit.getAuditProcessStatus()); accountsService.save(accounts); return true; } /** * ? * * @param audit * @return */ @RequestMapping(value = "/audit", method = RequestMethod.POST) @ResponseBody public Boolean audit(Audit audit, HttpSession session) { logger.debug(audit.toString()); Company company = audit.getCompany(); if (company != null) { logger.debug(company.toString()); boolean b = companyService.update(company); logger.debug("save Company:{}", b); if (b == true) { audit.setInitAuditDate(new Date()); // ? // Integer userId = (Integer) session.getAttribute(Constants.USER_ID); User user = userService.getByPrimaryKey(userId); audit.setInitAuditUser(user); // ? AuditProcessStatus auditProcessStatus = auditProcessStatusService .getByPrimaryKey(Constants.PROCESS_STATIC_WFS); audit.setAuditProcessStatus(auditProcessStatus);// ? auditService.update(audit); return true; } } return false; } /** * ? */ @RequestMapping(value = "/create", method = RequestMethod.GET) public ModelAndView createAudit() { return new ModelAndView("audit/audit_create"); } /** * * * @return */ @RequestMapping(value = "/create", method = RequestMethod.POST) @ResponseBody public Boolean createAudit(HttpServletRequest request) { String year = (String) request.getParameter("year"); String companyCode = (String) request.getParameter("companyCode"); Boolean b = auditService.save(year, companyCode); return b; } /** * ?? * * @return */ @RequestMapping(value = "/create/{companyCode}", method = RequestMethod.GET) @ResponseBody public List<Map<String, String>> findCompanyCode(@PathVariable(value = "companyCode") String companyCode) { List<Map<String, String>> list = new ArrayList<>(); Company company = new Company(); company.setCompanyCode(companyCode); PaginationRecordsAndNumber<Company, Number> query = companyService.getPaginationRecords(company, 1, 20); for (Company c : query.getRecords()) { Map<String, String> entity = new HashMap<>(); entity.put("id", c.getCompanyCode()); entity.put("text", c.getCompanyCode() + ":" + c.getCompanyName()); list.add(entity); } return list; } /** * ??? */ @RequestMapping(value = "/save", method = RequestMethod.POST) @ResponseBody public Boolean save(Audit audit) { logger.debug(audit.toString()); Company company = audit.getCompany(); if (company != null) { logger.debug(company.toString()); boolean b = companyService.update(company); logger.debug("save Company:{}", b); if (b == true) { // AuditProcessStatus auditProcessStatus = auditProcessStatusService // .getByPrimaryKey(Constants.PROCESS_STATIC_WCS); // audit.setAuditProcessStatus(auditProcessStatus); auditService.update(audit); return true; } } return false; } /** * ?? * * @param calculateModel * @return */ @RequestMapping(value = "/calculate", method = RequestMethod.POST) @ResponseBody public CalculateModel calculateModel(CalculateModel calculateModel) { logger.debug(calculateModel.toString()); Integer companyId = calculateModel.getCompanyId(); String year = calculateModel.getYear(); AuditParameter auditParameter = auditParameterService.getByYear(year); // ? Integer zaiZhiYuanGongZongShu = calculateModel.getZaiZhiYuanGongZongShu(); if (zaiZhiYuanGongZongShu == null) { zaiZhiYuanGongZongShu = 0; } // BigDecimal putScale = auditParameter.getPutScale(); // // =????* BigDecimal yingAnPaiCanJiRen = putScale.multiply(new BigDecimal(zaiZhiYuanGongZongShu)).setScale(2, BigDecimal.ROUND_HALF_UP); calculateModel.setYingAnPaiCanJiRen(yingAnPaiCanJiRen);// // ======================================================================================== // Integer yiLuRuCanJiRen = calculateModel.getYiLuRuCanJiRen(); // ??? List<WorkerCalculator> list = auditParameterService.getSpecialSetting(year); for (WorkerCalculator workerCalculator : list) { Integer per = workerCalculator.getPer().intValue(); Integer type = workerCalculator.getType(); Integer lvl = workerCalculator.getLvl(); Integer num = auditParameterService.getSpecialCount(companyId, year, type, lvl); logger.debug("type:{},lvl:{},per:{}", type, lvl, per); yiLuRuCanJiRen = ((yiLuRuCanJiRen - num) + (num * per)); } // Integer yuDingCanJiRen = calculateModel.getYuDingCanJiRen(); // Integer yiAnPaiCanJiRen = yiLuRuCanJiRen + yuDingCanJiRen; calculateModel.setYiAnPaiCanJiRen(yiAnPaiCanJiRen);// ; // ========================================================================================= // ?? BigDecimal averageSalary = auditParameter.getAverageSalary(); // ? // ??*() BigDecimal yingJiaoJinE = averageSalary .multiply(yingAnPaiCanJiRen.subtract(new BigDecimal(yiAnPaiCanJiRen))); if (yingJiaoJinE.signum() == 1) {// 0 calculateModel.setYingJiaoJinE(yingJiaoJinE); } else { yingJiaoJinE = Constants.ZERO; calculateModel.setYingJiaoJinE(yingJiaoJinE); } // ?? BigDecimal jianJiaoJinE = calculateModel.getJianJiaoJinE(); // ?=?-?? BigDecimal shiJiaoJinE = yingJiaoJinE.subtract(jianJiaoJinE); // ? --------? // ============================================================? List<AccountModel> qianJiaoMingXi = new ArrayList<AccountModel>(); BigDecimal qianJiao = getSectionPaid(year, companyId, qianJiaoMingXi); calculateModel.setQianJiaoMingXi(qianJiaoMingXi); // ============================================================ List<AccountModel> weiShenMingXi = new ArrayList<AccountModel>(); BigDecimal weiShen = getUnAudits(year, companyId, new BigDecimal(zaiZhiYuanGongZongShu), weiShenMingXi); calculateModel.setWeiShenMingXi(weiShenMingXi); // ============================================================= List<AccountModel> weiJiaoMingXi = new ArrayList<AccountModel>(); BigDecimal weiJiao = getUnpaid(year, companyId, weiJiaoMingXi); calculateModel.setWeiJiaoMingXi(weiJiaoMingXi); // ==================================================================? logger.debug("qianJiao:{} weiShen:{} weiJiao{}", qianJiao, weiShen, weiJiao); // ? =++ BigDecimal shangNianDuWeiJiaoBaoZhangJin = qianJiao.add(weiShen).add(weiJiao); calculateModel.setShangNianDuWeiJiaoBaoZhangJin(shangNianDuWeiJiaoBaoZhangJin); // ===================================================================================================== // ?=?-??+?+? BigDecimal real_yingJiaoJinE = shiJiaoJinE.add(shangNianDuWeiJiaoBaoZhangJin); // BigDecimal real_yingJiaoJinE = shiJiaoJinE; calculateModel.setShiJiaoJinE(real_yingJiaoJinE);// ? // ============================================================================================ // Date date = auditParameter.getAuditDelayDate(); // BigDecimal zhiNaJinBiLi = auditParameter.getAuditDelayRate(); // int zhiNanJinTianshu = CalendarUtil.getDaySub(date, new Date()); if (zhiNanJinTianshu < 0) { zhiNanJinTianshu = 0; } calculateModel.setZhiNaJinTianShu(zhiNanJinTianshu);// // BigDecimal zhiNaJin = real_yingJiaoJinE.multiply(zhiNaJinBiLi).multiply(new BigDecimal(zhiNanJinTianshu)); // ?? Boolean mian = calculateModel.getMianZhiNaJin(); if (mian) { zhiNaJin = new BigDecimal(0.00); } calculateModel.setZhiNaJin(zhiNaJin);// // =============================================================================================== // ?=?+ BigDecimal shiJiaoZongJinE = real_yingJiaoJinE.add(zhiNaJin); Boolean mianJiao = calculateModel.getMianJiao();// ??? if (mianJiao) { shiJiaoZongJinE = new BigDecimal(0.00); } calculateModel.setShiJiaoZongJinE(shiJiaoZongJinE); return calculateModel; } /** * ? * * @param year * @param companyCode * @param total * @return */ private BigDecimal getUnAudits(String year, Integer companyId, BigDecimal total, List<AccountModel> sb) { BigDecimal amount = new BigDecimal(0.00); // ?? AuditParameter auditParameter = auditParameterService.getByYear(year); BigDecimal averageSalary = auditParameter.getAverageSalary(); // ? // BigDecimal putScale = auditParameter.getPutScale(); // ??*(?*)?? BigDecimal payableAmount = averageSalary.multiply(total.multiply(putScale)); String[] unAudits = companyService.getUnauditYearByCompany(companyId, year); if (unAudits != null) { for (String unYear : unAudits) { AuditParameter oldAuditParameter = auditParameterService.getByYear(unYear); Date auditDelayDate = oldAuditParameter.getAuditDelayDate(); int days = CalendarUtil.getDaySub(auditDelayDate, new Date()); // =?** BigDecimal penalty = payableAmount.multiply(oldAuditParameter.getAuditDelayRate()) .multiply(new BigDecimal(days)); BigDecimal unYearTotal = payableAmount.add(penalty); logger.debug("payableAmount:{},year:{} date:{} penalty:{} unYearTotal:{}", payableAmount, unYear, days, penalty, unYearTotal); AccountModel am = new AccountModel(); am.setYear(unYear); am.setDays(String.valueOf(days)); am.setMoney(df.format(payableAmount)); am.setPenalty(df.format(penalty)); am.setProp(df4.format(oldAuditParameter.getAuditDelayRate())); am.setTotal(df.format(unYearTotal)); sb.add(am); amount = amount.add(unYearTotal); } } if (amount.compareTo(new BigDecimal(0.00)) != 0) { AccountModel am = new AccountModel(); am.setTotal(df.format(amount)); sb.add(am); } return amount; } /** * ?? * * @param companyCode * @return */ private BigDecimal getSectionPaid(String year, Integer companyId, List<AccountModel> sb) { BigDecimal amount = new BigDecimal(0.00); // List<Accounts> audits = // accountsService.getUnauditByCompany(companyId, year, // Constants.PROCESS_STATIC_BFJK); List<Accounts> accounts = accountsService.getByYearAndCompany(year, companyId, Constants.PROCESS_STATIC_BFJK); Map<String, Accounts> map = new HashMap<>(); for (Accounts group : accounts) { Object obj = map.get(group.getYear()); if (obj == null) { map.put(group.getYear(), group); } else { Accounts a = (Accounts) obj; a.setTotalMoney(a.getTotalMoney().add(group.getTotalMoney())); } } for (Accounts a : map.values()) { BigDecimal paymentTotal = paymentService.getEffPaid(null, a.getYear(), companyId);// BigDecimal qj = a.getTotalMoney().subtract(paymentTotal); AuditParameter auditParameter = auditParameterService.getByYear(a.getYear()); Date auditDelayDate = auditParameter.getAuditDelayDate(); int days = CalendarUtil.getDaySub(auditDelayDate, new Date()); BigDecimal penalty = qj.multiply(auditParameter.getAuditDelayRate()).multiply(new BigDecimal(days)); BigDecimal total = qj.add(penalty); AccountModel am = new AccountModel(); am.setYear(a.getYear()); am.setDays(String.valueOf(days)); am.setMoney(df.format(qj)); am.setPenalty(df.format(penalty)); am.setProp(df4.format(auditParameter.getAuditDelayRate())); am.setTotal(df.format(total)); sb.add(am); amount = amount.add(total); } if (amount.compareTo(new BigDecimal(0.00)) != 0) { AccountModel am = new AccountModel(); am.setTotal(df.format(amount)); sb.add(am); } return amount; } /** * * * @param companyId * @param sb * @return */ private BigDecimal getUnpaid(String year, Integer companyId, List<AccountModel> sb) { BigDecimal amount = new BigDecimal(0.00); List<Accounts> accounts = accountsService.getByYearAndCompany(year, companyId, Constants.PROCESS_STATIC_WJK); Map<String, Accounts> map = new HashMap<>(); for (Accounts group : accounts) { Object obj = map.get(group.getYear()); if (obj == null) { map.put(group.getYear(), group); } else { Accounts a = (Accounts) obj; a.setTotalMoney(a.getTotalMoney().add(group.getTotalMoney())); } } for (Accounts a : map.values()) { BigDecimal total = a.getTotalMoney(); AuditParameter auditParameter = auditParameterService.getByYear(a.getYear()); Date auditDelayDate = auditParameter.getAuditDelayDate(); int days = CalendarUtil.getDaySub(auditDelayDate, new Date()); BigDecimal penalty = total.multiply(auditParameter.getAuditDelayRate()).multiply(new BigDecimal(days)); AccountModel am = new AccountModel(); am.setYear(a.getYear()); am.setDays(String.valueOf(days)); am.setMoney(df.format(total)); am.setPenalty(df.format(penalty)); am.setProp(df4.format(auditParameter.getAuditDelayRate())); am.setTotal(df.format(total)); sb.add(am); amount = amount.add(total); } if (amount.compareTo(new BigDecimal(0.00)) != 0) { AccountModel am = new AccountModel(); am.setTotal(df.format(amount)); sb.add(am); } return amount; } /** * ?? * * @param page * @param rows * @param params * @param request * @return */ @RequestMapping(value = "/list", method = RequestMethod.POST) @ResponseBody public Map<String, Object> provincePost(HttpServletRequest request) { String year = request.getParameter("year"); Integer page = Integer.valueOf(request.getParameter("page")); Integer pageSize = Integer.valueOf(request.getParameter("rows")); Integer process = Integer.valueOf(request.getParameter("process")); String money = request.getParameter("money"); String companyCode = request.getParameter("companyCode"); String companyTaxCode = request.getParameter("companyTaxCode"); String companyName = request.getParameter("companyName"); Map<String, Object> params = new HashMap<String, Object>(); params.put("page", page); params.put("pageSize", pageSize); params.put("year", year); // params.put("auditProcessStatus", process); // ? params.put("companyCode", companyCode); // ?? params.put("companyTaxCode", companyTaxCode); // ?? params.put("companyName", companyName); // ?? if (StringUtils.isNotBlank(money)) { params.put("actualAmount", new BigDecimal(money)); // ? } logger.debug("years:{},page:{},rows:{},process{}", year, page, pageSize, process); Map<String, Object> entity = new HashMap<>(); try { PaginationRecordsAndNumber<Audit, Number> query = auditService.getByMultiCondition(params); Integer total = query.getNumber().intValue();// ?? List<Map<String, Object>> list = new ArrayList<>(); for (Iterator<Audit> iterator = query.getRecords().iterator(); iterator.hasNext();) { Audit it = iterator.next(); Map<String, Object> map = new HashMap<>(); map.put("id", it.getId());// id map.put("year", it.getYear()); // map.put("companyCode", it.getCompany().getCompanyCode());// ?? map.put("companyTaxCode", it.getCompany().getCompanyTaxCode());// ? map.put("companyId", it.getCompany().getId());// ??? map.put("companyName", it.getCompany().getCompanyName());// ??? Integer pId = it.getAuditProcessStatus().getId(); map.put("auditProcessStatusId", pId);// ?? String statusName = it.getAuditProcessStatus().getAuditProcessStatus(); if (it.getRefuseTimes() > 0) { statusName = statusName + "(" + it.getRefuseTimes() + ")"; } map.put("auditProcessStatus", statusName);// ?? list.add(map); } entity.put("total", total); entity.put("rows", list); logger.debug("total:{},rows:{}", total, list.toString()); } catch (Exception e) { logger.error("error{}", e); } return entity; } /** * ???? */ @RequestMapping(value = "/edit/{id}/{process}", method = RequestMethod.GET) public ModelAndView initAudit(@PathVariable(value = "id") int id, @PathVariable(value = "process") int process, HttpServletRequest request, HttpSession session) { Audit audit = auditService.getByPrimaryKey(id); if (audit.getInitAuditUser() == null) { Integer userId = (Integer) session.getAttribute(Constants.USER_ID); User user = userService.getByPrimaryKey(userId); audit.setInitAuditUser(user); } if (audit.getVerifyAuditUser() == null && process == 2) { Integer userId = (Integer) session.getAttribute(Constants.USER_ID); User user = userService.getByPrimaryKey(userId); audit.setVerifyAuditUser(user); } // ???, ??-?? if (process == 2) { BigDecimal alreadyPayment = paymentService.getEffPaid(audit.getYear(), null, audit.getCompany().getId()); audit.setPayAmount(audit.getPayAmount().subtract(alreadyPayment)); } String year = audit.getYear(); AuditParameter auditParameter = auditParameterService.getByYear(year); String areaName = auditParameter.getArea().getName(); request.setAttribute("areaName", areaName); request.setAttribute("params", auditParameter); if (companyPropertys == null) { companyPropertys = companyPropertyService.getAll(); } request.setAttribute("companyPropertys", companyPropertys); if (companyEconomyTypes == null) { companyEconomyTypes = companyEconomyTypeService.getAll(); } request.setAttribute("companyEconomyTypes", companyEconomyTypes); request.setAttribute("process", process); Integer companyId = audit.getCompany().getId(); // PaginationRecordsAndNumber<Worker, Number> workers = companyService.getOverproofAge(year, companyId, 1, Integer.MAX_VALUE); request.setAttribute("ageEx", workers.getNumber()); // String[] unAudits = companyService.getUnauditYearByCompany(companyId, year); StringBuilder sb = new StringBuilder(); for (String s : unAudits) { sb.append(s).append(","); } request.setAttribute("unAudityear", sb.toString()); request.setAttribute("unAudityearNum", unAudits.length); // ?? List<Reply> replys = replyService.getAll(); request.setAttribute("reasons", replys); return new ModelAndView("audit/audit_detail", "entity", audit); } }