|
|
@@ -0,0 +1,202 @@
|
|
|
+package restcontroller.webmanage.sale.period;
|
|
|
+
|
|
|
+import beans.data.BatchDeleteErr;
|
|
|
+import beans.datacontrllog.DataContrlLog;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import common.Controller;
|
|
|
+import common.YosException;
|
|
|
+import common.annotation.API;
|
|
|
+import common.annotation.CACHEING;
|
|
|
+import common.annotation.CACHEING_CLEAN;
|
|
|
+import common.data.*;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import restcontroller.R;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.YearMonth;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Calendar;
|
|
|
+
|
|
|
+@API(title = "会计期间")
|
|
|
+public class period extends Controller {
|
|
|
+ public period(JSONObject content) throws YosException {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @API(title = "新增会计期间", apiversion = R.ID2025072314205903.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiClass = {period.class})
|
|
|
+ public String insertormodify_period() throws YosException {
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+ // 表名
|
|
|
+
|
|
|
+ String tableName = "st_period";
|
|
|
+ Long st_periodid = content.getLong("st_periodid");
|
|
|
+ Long month = content.getLongValue("month");
|
|
|
+ long year= content.getLongValue("year");
|
|
|
+ String enddate = content.getStringValue("enddate");
|
|
|
+ String begdate = content.getStringValue("begdate");
|
|
|
+
|
|
|
+ if (st_periodid <= 0) {
|
|
|
+
|
|
|
+ st_periodid = createTableID(tableName);
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, tableName);
|
|
|
+ insertSQL.setUniqueid(st_periodid);
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setValue("month", month);
|
|
|
+ insertSQL.setValue("year", year);
|
|
|
+ insertSQL.setValue("enddate", StringUtils.isBlank(enddate) ?"null":enddate);
|
|
|
+ insertSQL.setValue("begdate", StringUtils.isBlank(begdate) ?"null":begdate);
|
|
|
+ sqlList.add(insertSQL.getSQL());
|
|
|
+
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "st_period", st_periodid, "新增", "会计期间新增成功").getSQL());
|
|
|
+ } else {
|
|
|
+ Rows rows = dbConnect.runSqlQuery(
|
|
|
+ "SELECT isclose from st_period WHERE st_periodid = "
|
|
|
+ + st_periodid);
|
|
|
+ if (rows.isNotEmpty()) {
|
|
|
+ if (!rows.get(0).getBoolean("isclose")) {
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, tableName);
|
|
|
+ updateSQL.setUniqueid(st_periodid);
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setValue("month", month);
|
|
|
+ updateSQL.setValue("year", year);
|
|
|
+ updateSQL.setValue("enddate", StringUtils.isBlank(enddate) ?"null":enddate);
|
|
|
+ updateSQL.setValue("begdate", StringUtils.isBlank(begdate) ?"null":begdate);
|
|
|
+ sqlList.add(updateSQL.getSQL());
|
|
|
+
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "st_period", st_periodid, "更新", "会计期间更新成功").getSQL());
|
|
|
+ } else {
|
|
|
+ return getErrReturnObject().setErrMsg("已结账的会计期间无法编辑").toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ return getErrReturnObject().setErrMsg("该会计期间不存在").toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+ content.put("st_periodid", st_periodid);
|
|
|
+
|
|
|
+ return queryperiodMain();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @API(title = "会计期间详情", apiversion = R.ID2025072314211003.v1.class)
|
|
|
+ @CACHEING
|
|
|
+ public String queryperiodMain() throws YosException {
|
|
|
+ Long st_periodid = content.getLong("st_periodid");
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "st_period","*");
|
|
|
+ querySQL.setTableAlias("t1");
|
|
|
+ querySQL.setWhere("t1.siteid", siteid);
|
|
|
+ querySQL.setWhere("t1.st_periodid", st_periodid);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ Row row = rows.isNotEmpty() ? rows.get(0) : new Row();
|
|
|
+ return getSucReturnObject().setData(row).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @API(title = "查询会计期间列表", apiversion = R.ID2025072314211703.v1.class)
|
|
|
+ @CACHEING
|
|
|
+ public String queryperiodList() throws YosException {
|
|
|
+ StringBuffer where = new StringBuffer(" 1=1 ");
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "st_period","*");
|
|
|
+ querySQL.setTableAlias("t1");
|
|
|
+ querySQL.setWhere("t1.siteid", siteid);
|
|
|
+ querySQL.setWhere(where);
|
|
|
+ querySQL.setPage(pageSize, pageNumber);
|
|
|
+ querySQL.setOrderBy(pageSorting);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @API(title = "删除", apiversion = R.ID2025072314212603.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiClass = {period.class})
|
|
|
+ public String delete() throws YosException {
|
|
|
+
|
|
|
+ JSONArray st_periodids = content.getJSONArray("st_periodids");
|
|
|
+ BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, st_periodids.size());
|
|
|
+ for (Object o : st_periodids) {
|
|
|
+ long st_periodid = Long.parseLong(o.toString());
|
|
|
+ Rows RowsStatus = dbConnect.runSqlQuery("select st_periodid,isclose from st_period where siteid='"
|
|
|
+ + siteid + "' and st_periodid='" + st_periodid + "'");
|
|
|
+
|
|
|
+ if (RowsStatus.isNotEmpty()) {
|
|
|
+ if (RowsStatus.get(0).getBoolean("isclose")) {
|
|
|
+ batchDeleteErr.addErr(st_periodid, "已结账的会计期间无法删除");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ dbConnect.runSqlUpdate(
|
|
|
+ "delete from st_period where siteid='" + siteid + "' and st_periodid=" + st_periodid);
|
|
|
+ }
|
|
|
+ return batchDeleteErr.getReturnObject().toString();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @API(title = "结账", apiversion = R.ID2025072314213503.v1.class)
|
|
|
+ @CACHEING_CLEAN( apiClass = {period.class})
|
|
|
+ public String close() throws YosException {
|
|
|
+ Long st_periodid = content.getLong("st_periodid");
|
|
|
+ boolean isclose = content.getBooleanValue("isclose");
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "st_period");
|
|
|
+ updateSQL.setUniqueid(st_periodid);
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setValue("isclose",isclose);
|
|
|
+ updateSQL.setValue("closeby", isclose?username:"null");
|
|
|
+ if(isclose){
|
|
|
+ updateSQL.setDateValue("closedate");
|
|
|
+ }else{
|
|
|
+ updateSQL.setValue("closedate","null");
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlList.add(updateSQL.getSQL());
|
|
|
+ if (isclose) {
|
|
|
+ sqlList.add(
|
|
|
+ DataContrlLog.createLog(this, "st_period", st_periodid, "结账", "会计期间结账成功").getSQL());
|
|
|
+ } else {
|
|
|
+ sqlList.add(
|
|
|
+ DataContrlLog.createLog(this, "st_period", st_periodid, "反结账", "会计期间反结账成功").getSQL());
|
|
|
+ }
|
|
|
+
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "生成下一年会计期间", apiversion = R.ID2025072314214503.v1.class)
|
|
|
+ @CACHEING_CLEAN( apiClass = {period.class})
|
|
|
+ public String createnewyearperiod() throws YosException {
|
|
|
+
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ int currentYear = calendar.get(Calendar.YEAR);
|
|
|
+ int nextYear = currentYear + 1;
|
|
|
+ for(int i=1;i<13;i++){
|
|
|
+ YearMonth yearMonth = YearMonth.of(nextYear, i);
|
|
|
+ LocalDate firstDayOfMonth = yearMonth.atDay(1);
|
|
|
+ LocalDate lastDayOfMonth = yearMonth.atEndOfMonth();
|
|
|
+
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_period");
|
|
|
+ insertSQL.setUniqueid(createTableID("st_period"));
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setValue("month", i);
|
|
|
+ insertSQL.setValue("year", nextYear);
|
|
|
+ insertSQL.setValue("enddate",firstDayOfMonth);
|
|
|
+ insertSQL.setValue("begdate", lastDayOfMonth);
|
|
|
+ sqlList.add(insertSQL.getSQL());
|
|
|
+ }
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|