| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- package restcontroller.webmanage.saletool.sharematerial;
- import beans.datatag.DataTag;
- import beans.remind.Remind;
- import beans.user.User;
- 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.annotation.cm;
- import common.data.Row;
- import common.data.Rows;
- import common.data.RowsMap;
- import common.data.SQLFactory;
- import restcontroller.R;
- import java.util.ArrayList;
- import java.util.HashMap;
- @API(title = "推广素材管理")
- public class sharematerial extends Controller {
- public sharematerial(JSONObject content) throws YosException {
- super(content);
- }
- @API(title = "新增")
- @CACHEING_CLEAN(cms = {@cm(clazz = sharematerial.class, method = {"select"})})
- public String insertOrUpdate() throws YosException {
- Long sat_sharematerialid = content.getLong("sat_sharematerialid");
- String title = content.getString("title", "sat_sharematerial");
- Long sat_sharematerial_classid = content.getLong("sat_sharematerial_classid");
- String notes = content.getString("notes", "sat_sharematerial");
- JSONArray tagArray = content.getJSONArray("tag");
- boolean canfiledownload = content.getBoolean("canfiledownload");
- String text = content.getString("content", true);
- int type = content.getIntValue("type");
- SQLFactory sqlFactory;
- if (sat_sharematerialid <= 0) {
- //素材id
- sat_sharematerialid = createTableID("sat_sharematerial");
- sqlFactory = new SQLFactory(this, "素材-新增");
- sqlFactory.addParameter("createdepid", departmentid);
- sqlFactory.addParameter("createuserid", userid);
- sqlFactory.addParameter("createby", username);
- sqlFactory.addParameter("authuserid", userid);
- sqlFactory.addParameter("authdepid", departmentid);
- } else {
- sqlFactory = new SQLFactory(this, "素材-更新");
- }
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("sat_sharematerialid", sat_sharematerialid);
- sqlFactory.addParameter("changeuserid", userid);
- sqlFactory.addParameter("changeby", username);
- sqlFactory.addParameter("title", title);
- sqlFactory.addParameter("type", type);
- sqlFactory.addParameter("sat_sharematerial_classid", sat_sharematerial_classid);
- sqlFactory.addParameter("content", text);
- sqlFactory.addParameter("notes", notes);
- sqlFactory.addParameter("canfiledownload", canfiledownload);
- // sqlFactory.addParameter("tag", tagArray.toJSONString());
- sqlFactory.addParameter("sa_agentsid", userInfo.getAgentID());
- ArrayList<String> list = (ArrayList<String>) JSONObject.parseArray(tagArray.toJSONString(), String.class);
- DataTag.updateTag(this, "sat_sharematerial", sat_sharematerialid, list);
- dbConnect.runSqlUpdate(sqlFactory);
- content.put("sat_sharematerialid", sat_sharematerialid);
- return selectDetail();
- }
- @API(title = "删除", apiversion = R.ID20221102143602.v1.class)
- @CACHEING_CLEAN(cms = {@cm(clazz = sharematerial.class, method = {"select"})})
- public String delete() throws YosException {
- JSONArray array = content.getJSONArray("sat_sharematerialids");
- SQLFactory sqlFactory = new SQLFactory(this, "素材-删除");
- sqlFactory.addParameter_in("sat_sharematerialid", array.toArray());
- String sql = sqlFactory.getSQL();
- dbConnect.runSqlUpdate(sql);
- return getSucReturnObject().toString();
- }
- @API(title = "审核")
- @CACHEING_CLEAN(cms = {@cm(clazz = sharematerial.class, method = {"select"})})
- public String audit() throws YosException {
- Long sat_sharematerialid = content.getLong("sat_sharematerialid");
- int type = content.getIntValue("type");
- String status = "新建";
- if (type == 0) {
- status = "新建";
- } else {
- status = "审核";
- }
- SQLFactory sqlFactory = new SQLFactory(this, "素材-审核");
- sqlFactory.addParameter("sat_sharematerialid", sat_sharematerialid);
- sqlFactory.addParameter("checkby", username);
- sqlFactory.addParameter("status", status);
- dbConnect.runSqlUpdate(sqlFactory);
- //发送邮件和消息,发布时发送消息
- if (type != 0) {
- sendMsg(sat_sharematerialid);
- }
- return getSucReturnObject().toString();
- }
- /**
- * 发送消息:新素材发布,推广素材发布范围内的经销商/人员
- *
- * @param sat_sharematerialid
- * @throws YosException
- */
- public void sendMsg(Long sat_sharematerialid) throws YosException {
- SQLFactory sqlFactory = new SQLFactory(this, "查询范围内的账号");
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("sat_sharematerialid", sat_sharematerialid);
- Rows useridRows = dbConnect.runSqlQuery(sqlFactory.getSQL());
- if (useridRows.isNotEmpty()) {
- for (Row row : useridRows) {
- Long tempUserid = row.getLong("userid");
- if (tempUserid != 0) {
- Remind remind = new Remind(this);
- remind.setType("应用");
- remind.setTitle("新素材发布");
- remind.setContent("您有新的推广素材,请查看!");
- remind.setTouserid(tempUserid);
- remind.setObjectname("sat_sharematerial");
- remind.setObjectid(sat_sharematerialid);
- remind.sendByDialogMsg().createSys_message();
- //发邮件
- remind.setToemail(User.getUserMailAddress(this, tempUserid));
- remind.sendByMail();
- }
- }
- }
- }
- @API(title = "管理端-素材列表", apiversion = R.ID20221102143102.v1.class)
- @CACHEING
- public String select() throws YosException {
- /*
- 过滤条件设置
- */
- StringBuffer where = new StringBuffer(" 1=1 ");
- if (content.containsKey("where")) {
- JSONObject whereObject = content.getJSONObject("where");
- if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
- where.append(" and(");
- where.append("t1.title like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.content like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t2.classname like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.notes like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- if (whereObject.containsKey("type") && !"".equals(whereObject.getString("type"))) {
- where.append(" and(");
- where.append("t1.type = '").append(whereObject.getString("type")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("sat_sharematerial_classid") && !"".equals(whereObject.getString("sat_sharematerial_classid"))) {
- where.append(" and(");
- where.append("t1.sat_sharematerial_classid = '").append(whereObject.getString("sat_sharematerial_classid")).append("' ");
- where.append("or t3.sat_sharematerial_classid = '").append(whereObject.getString("sat_sharematerial_classid")).append("' ");
- where.append(")");
- }
- }
- SQLFactory sqlFactory = new SQLFactory(this, "素材-列表", pageSize, pageNumber, pageSorting);
- sqlFactory.addParameter_SQL("where", where);
- String sql = sqlFactory.getSQL();
- Rows rows = dbConnect.runSqlQuery(sql);
- ArrayList<Long> ids = rows.toArrayList("sat_sharematerialid", new ArrayList<>());
- HashMap<Long, ArrayList<String>> tagMap = DataTag.queryTag(this, "sat_sharematerial", ids, false);
- //封面cover
- RowsMap coverRowsMap = getAttachmentUrl("sat_sharematerial", ids, "cover");
- //附件
- RowsMap attRowsMap = getAttachmentUrl("sat_sharematerial", ids, "default");
- for (Row row : rows) {
- Rows coverRows = coverRowsMap.get(row.getString("sat_sharematerialid"));
- if (coverRows.isEmpty()) {
- row.put("cover", "");
- } else {
- row.put("cover", coverRows.get(0).getString("url"));
- }
- row.put("attinfos", attRowsMap.getOrDefault(row.getString("sat_sharematerialid"), new Rows()));
- row.put("tag", tagMap.get(row.getString("sat_sharematerialid")));
- }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "详细")
- public String selectDetail() throws YosException {
- Long sat_sharematerialid = content.getLong("sat_sharematerialid");
- SQLFactory sqlFactory = new SQLFactory(this, "素材-详细");
- sqlFactory.addParameter("sat_sharematerialid", sat_sharematerialid);
- Rows rows = dbConnect.runSqlQuery(sqlFactory);
- ArrayList<Long> ids = rows.toArrayList("sat_sharematerialid", new ArrayList<>());
- //封面cover
- RowsMap coverRowsMap = getAttachmentUrl("sat_sharematerial", ids, "cover");
- //附件
- RowsMap attRowsMap = getAttachmentUrl("sat_sharematerial", ids, "default");
- for (Row row : rows) {
- Rows coverRows = coverRowsMap.get(row.getString("sat_sharematerialid"));
- if (coverRows.isEmpty()) {
- row.put("cover", "");
- } else {
- row.put("cover", coverRows.get(0).getString("url"));
- }
- row.put("attinfos", attRowsMap.getOrDefault(row.getString("sat_sharematerialid"), new Rows()));
- row.put("tag", DataTag.queryTag(this, "sat_sharematerial", row.getLong("sat_sharematerialid"), false));
- }
- return getSucReturnObject().setData(rows.size() > 0 ? rows.get(0) : new Row()).toString();
- }
- }
|